1// 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_PREPROCESSOR_H_
16#define COMPILER_PREPROCESSOR_PREPROCESSOR_H_
17
18#include "pp_utils.h"
19
20#include <cstddef>
21
22namespace pp
23{
24
25class Diagnostics;
26class DirectiveHandler;
27struct PreprocessorImpl;
28struct Token;
29
30struct PreprocessorSettings
31{
32	PreprocessorSettings() : maxMacroExpansionDepth(1000) {}
33	int maxMacroExpansionDepth;
34};
35
36class Preprocessor
37{
38public:
39	Preprocessor(Diagnostics *diagnostics,
40	             DirectiveHandler *directiveHandler,
41	             const PreprocessorSettings &settings);
42	~Preprocessor();
43
44	// count: specifies the number of elements in the string and length arrays.
45	// string: specifies an array of pointers to strings.
46	// length: specifies an array of string lengths.
47	// If length is NULL, each string is assumed to be null terminated.
48	// If length is a value other than NULL, it points to an array containing
49	// a string length for each of the corresponding elements of string.
50	// Each element in the length array may contain the length of the
51	// corresponding string or a value less than 0 to indicate that the string
52	// is null terminated.
53	bool init(size_t count, const char *const string[], const int length[]);
54	// Adds a pre-defined macro.
55	void predefineMacro(const char *name, int value);
56
57	void lex(Token *token);
58
59	// Set maximum preprocessor token size
60	void setMaxTokenSize(size_t maxTokenSize);
61
62private:
63	PP_DISALLOW_COPY_AND_ASSIGN(Preprocessor);
64
65	PreprocessorImpl *mImpl;
66};
67
68}  // namespace pp
69#endif  // COMPILER_PREPROCESSOR_PREPROCESSOR_H_
70
71