|
1 // |
|
2 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. |
|
3 // Use of this source code is governed by a BSD-style license that can be |
|
4 // found in the LICENSE file. |
|
5 // |
|
6 |
|
7 #ifndef COMPILER_PREPROCESSOR_DIRECTIVE_PARSER_H_ |
|
8 #define COMPILER_PREPROCESSOR_DIRECTIVE_PARSER_H_ |
|
9 |
|
10 #include "Lexer.h" |
|
11 #include "Macro.h" |
|
12 #include "pp_utils.h" |
|
13 #include "SourceLocation.h" |
|
14 |
|
15 namespace pp |
|
16 { |
|
17 |
|
18 class Diagnostics; |
|
19 class DirectiveHandler; |
|
20 class Tokenizer; |
|
21 |
|
22 class DirectiveParser : public Lexer |
|
23 { |
|
24 public: |
|
25 DirectiveParser(Tokenizer* tokenizer, |
|
26 MacroSet* macroSet, |
|
27 Diagnostics* diagnostics, |
|
28 DirectiveHandler* directiveHandler); |
|
29 |
|
30 virtual void lex(Token* token); |
|
31 |
|
32 private: |
|
33 PP_DISALLOW_COPY_AND_ASSIGN(DirectiveParser); |
|
34 |
|
35 void parseDirective(Token* token); |
|
36 void parseDefine(Token* token); |
|
37 void parseUndef(Token* token); |
|
38 void parseIf(Token* token); |
|
39 void parseIfdef(Token* token); |
|
40 void parseIfndef(Token* token); |
|
41 void parseElse(Token* token); |
|
42 void parseElif(Token* token); |
|
43 void parseEndif(Token* token); |
|
44 void parseError(Token* token); |
|
45 void parsePragma(Token* token); |
|
46 void parseExtension(Token* token); |
|
47 void parseVersion(Token* token); |
|
48 void parseLine(Token* token); |
|
49 |
|
50 bool skipping() const; |
|
51 void parseConditionalIf(Token* token); |
|
52 int parseExpressionIf(Token* token); |
|
53 int parseExpressionIfdef(Token* token); |
|
54 |
|
55 struct ConditionalBlock |
|
56 { |
|
57 std::string type; |
|
58 SourceLocation location; |
|
59 bool skipBlock; |
|
60 bool skipGroup; |
|
61 bool foundValidGroup; |
|
62 bool foundElseGroup; |
|
63 |
|
64 ConditionalBlock() : |
|
65 skipBlock(false), |
|
66 skipGroup(false), |
|
67 foundValidGroup(false), |
|
68 foundElseGroup(false) |
|
69 { |
|
70 } |
|
71 }; |
|
72 bool mPastFirstStatement; |
|
73 std::vector<ConditionalBlock> mConditionalStack; |
|
74 Tokenizer* mTokenizer; |
|
75 MacroSet* mMacroSet; |
|
76 Diagnostics* mDiagnostics; |
|
77 DirectiveHandler* mDirectiveHandler; |
|
78 }; |
|
79 |
|
80 } // namespace pp |
|
81 #endif // COMPILER_PREPROCESSOR_DIRECTIVE_PARSER_H_ |
|
82 |