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