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_DIRECTIVEPARSER_H_
8#define COMPILER_PREPROCESSOR_DIRECTIVEPARSER_H_
9
10#include "compiler/preprocessor/Lexer.h"
11#include "compiler/preprocessor/Macro.h"
12#include "compiler/preprocessor/Preprocessor.h"
13#include "compiler/preprocessor/SourceLocation.h"
14
15namespace angle
16{
17
18namespace pp
19{
20
21class Diagnostics;
22class DirectiveHandler;
23class Tokenizer;
24
25class DirectiveParser : public Lexer
26{
27 public:
28 DirectiveParser(Tokenizer *tokenizer,
29 MacroSet *macroSet,
30 Diagnostics *diagnostics,
31 DirectiveHandler *directiveHandler,
32 const PreprocessorSettings &settings);
33 ~DirectiveParser() override;
34
35 void lex(Token *token) override;
36
37 private:
38 void parseDirective(Token *token);
39 void parseDefine(Token *token);
40 void parseUndef(Token *token);
41 void parseIf(Token *token);
42 void parseIfdef(Token *token);
43 void parseIfndef(Token *token);
44 void parseElse(Token *token);
45 void parseElif(Token *token);
46 void parseEndif(Token *token);
47 void parseError(Token *token);
48 void parsePragma(Token *token);
49 void parseExtension(Token *token);
50 void parseVersion(Token *token);
51 void parseLine(Token *token);
52
53 bool skipping() const;
54 void parseConditionalIf(Token *token);
55 int parseExpressionIf(Token *token);
56 int parseExpressionIfdef(Token *token);
57
58 struct ConditionalBlock
59 {
60 std::string type;
61 SourceLocation location;
62 bool skipBlock;
63 bool skipGroup;
64 bool foundValidGroup;
65 bool foundElseGroup;
66
67 ConditionalBlock()
68 : skipBlock(false), skipGroup(false), foundValidGroup(false), foundElseGroup(false)
69 {}
70 };
71 bool mPastFirstStatement;
72 bool mSeenNonPreprocessorToken; // Tracks if a non-preprocessor token has been seen yet. Some
73 // macros, such as
74 // #extension must be declared before all shader code.
75 std::vector<ConditionalBlock> mConditionalStack;
76 Tokenizer *mTokenizer;
77 MacroSet *mMacroSet;
78 Diagnostics *mDiagnostics;
79 DirectiveHandler *mDirectiveHandler;
80 int mShaderVersion;
81 const PreprocessorSettings mSettings;
82};
83
84} // namespace pp
85
86} // namespace angle
87
88#endif // COMPILER_PREPROCESSOR_DIRECTIVEPARSER_H_
89