1aa4115a47c554a936fdf5e6679e72a9329fecf45Theodore Ts'o// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef COMPILER_PREPROCESSOR_DIRECTIVE_PARSER_H_
16#define COMPILER_PREPROCESSOR_DIRECTIVE_PARSER_H_
17
18#include "Lexer.h"
19#include "Macro.h"
20#include "pp_utils.h"
21#include "SourceLocation.h"
22
23namespace pp
24{
25
26class Diagnostics;
27class DirectiveHandler;
28class Tokenizer;
29
30class DirectiveParser : public Lexer
31{
32public:
33	DirectiveParser(Tokenizer* tokenizer,
34	                MacroSet* macroSet,
35	                Diagnostics* diagnostics,
36	                DirectiveHandler* directiveHandler);
37
38	virtual void lex(Token* token);
39
40private:
41	PP_DISALLOW_COPY_AND_ASSIGN(DirectiveParser);
42
43	void parseDirective(Token* token);
44	void parseDefine(Token* token);
45	void parseUndef(Token* token);
46	void parseIf(Token* token);
47	void parseIfdef(Token* token);
48	void parseIfndef(Token* token);
49	void parseElse(Token* token);
50	void parseElif(Token* token);
51	void parseEndif(Token* token);
52	void parseError(Token* token);
53	void parsePragma(Token* token);
54	void parseExtension(Token* token);
55	void parseVersion(Token* token);
56	void parseLine(Token* token);
57
58	bool skipping() const;
59	void parseConditionalIf(Token* token);
60	int parseExpressionIf(Token* token);
61	int parseExpressionIfdef(Token* token);
62
63	struct ConditionalBlock
64	{
65		std::string type;
66		SourceLocation location;
67		bool skipBlock;
68		bool skipGroup;
69		bool foundValidGroup;
70		bool foundElseGroup;
71
72		ConditionalBlock() :
73			skipBlock(false),
74			skipGroup(false),
75			foundValidGroup(false),
76			foundElseGroup(false)
77		{
78		}
79	};
80	bool mPastFirstStatement;
81	std::vector<ConditionalBlock> mConditionalStack;
82	Tokenizer* mTokenizer;
83	MacroSet* mMacroSet;
84	Diagnostics* mDiagnostics;
85	DirectiveHandler* mDirectiveHandler;
86};
87
88}  // namespace pp
89#endif  // COMPILER_PREPROCESSOR_DIRECTIVE_PARSER_H_
90
91