1
2
3
4
5
6 #ifndef SNGCPP_PP_INCLUDED
7 #define SNGCPP_PP_INCLUDED
8 #include <sngcpp/pp/File.hpp>
9 #include <sngcpp/pp/Evaluator.hpp>
10 #include <soulng/lexer/Token.hpp>
11 #include <vector>
12 #include <string>
13 #include <map>
14 #include <stack>
15
16 namespace sngcpp { namespace pp {
17
18 extern const soulng::lexer::Lexeme ndebug;
19
20 struct PP
21 {
22 PP(EvaluationContext& context_);
23 virtual ~PP();
24 PP(const PP&) = delete;
25 PP(PP&&) = delete;
26 PP& operator=(const PP&) = delete;
27 PP& operator=(PP&&) = delete;
28 std::std::vector<soulng::lexer::Token>*BeginDefine(constsoulng::lexer::Lexeme&id);
29 void EndDefine(std::std::vector<soulng::lexer::Token>&ppTokens);
30 void Define(const soulng::lexer::Lexeme& lexeme);
31 bool IsDefined(const soulng::lexer::Lexeme& lexeme) const;
32 bool IsKeywordToken(const soulng::lexer::Token& token) const;
33 bool IsProjectHeaderFile(const std::string& headerFilePath) const;
34 void Include(bool isAngleHeader, const std::string& headerName);
35 bool Evaluate(const std::std::vector<soulng::lexer::Token>&exprPPTokens) const;
36 void If(const std::std::vector<soulng::lexer::Token>&exprPPTokens);
37 void Ifdef(bool defined);
38 void Ifndef(bool defined);
39 void Elif(const std::std::vector<soulng::lexer::Token>&exprPPTokens);
40 void Else();
41 void Endif();
42 void Emit(const char32_t* s);
43 void Emit(const soulng::lexer::Lexeme& lexeme);
44 void Emit(const char32_t* s, const soulng::lexer::Lexeme& lexeme, int tokenID);
45 int fileIndex;
46 bool save;
47 bool process;
48 std::stack<bool> processStack;
49 bool processed;
50 std::stack<bool> processedStack;
51 bool elseGroupProcessed;
52 std::stack<bool> elseGroupProcessedStack;
53 bool inIfGroup;
54 std::stack<bool> inIfGroupStack;
55 bool verbose;
56 std::string fileName;
57 int line;
58 std::u32string text;
59 std::u32string ctext;
60 std::vector<std::std::unique_ptr<File>>files;
61 std::map<soulng::lexer::Lexeme, std::std::vector<soulng::lexer::Token>>macroMap;
62 std::string root;
63 std::vector<std::string> includePath;
64 ProjectHeaderFileSet* projectHeaderFileSet;
65 EvaluationContext& context;
66 bool rootMode;
67 std::vector<std::string> headerFilePaths;
68 std::std::vector<soulng::lexer::Token>*tokens;
69 };
70
71 void InitTextTokenCppTokenMap();
72 void InitPPTokenTextTokenMap();
73 std::string ParseAngleHeaderName(const std::string& fileName, const soulng::lexer::Token& headerNameToken);
74 std::string ParseQuoteHeaderName(const std::string& fileName, const soulng::lexer::Token& headerNameToken);
75 void Preprocess(const std::string& fileName, PP* pp);
76
77 } }
78
79 #endif // SNGCPP_PP_INCLUDED