• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_DIAGNOSTICSBASE_H_
16 #define COMPILER_PREPROCESSOR_DIAGNOSTICSBASE_H_
17 
18 #include <string>
19 
20 namespace pp
21 {
22 
23 struct SourceLocation;
24 
25 // Base class for reporting diagnostic messages.
26 // Derived classes are responsible for formatting and printing the messages.
27 class Diagnostics
28 {
29 public:
30 	// Severity is used to classify info log messages.
31 	enum Severity
32 	{
33 		PP_INFO,
34 		PP_WARNING,
35 		PP_ERROR
36 	};
37 
38 	enum ID
39 	{
40 		PP_ERROR_BEGIN,
41 		PP_INTERNAL_ERROR,
42 		PP_OUT_OF_MEMORY,
43 		PP_INVALID_CHARACTER,
44 		PP_INVALID_NUMBER,
45 		PP_INTEGER_OVERFLOW,
46 		PP_FLOAT_OVERFLOW,
47 		PP_TOKEN_TOO_LONG,
48 		PP_INVALID_EXPRESSION,
49 		PP_DIVISION_BY_ZERO,
50 		PP_EOF_IN_COMMENT,
51 		PP_UNEXPECTED_TOKEN,
52 		PP_DIRECTIVE_INVALID_NAME,
53 		PP_MACRO_NAME_RESERVED,
54 		PP_MACRO_REDEFINED,
55 		PP_MACRO_PREDEFINED_REDEFINED,
56 		PP_MACRO_PREDEFINED_UNDEFINED,
57 		PP_MACRO_UNTERMINATED_INVOCATION,
58 		PP_MACRO_UNDEFINED_WHILE_INVOKED,
59 		PP_MACRO_TOO_FEW_ARGS,
60 		PP_MACRO_TOO_MANY_ARGS,
61 		PP_MACRO_DUPLICATE_PARAMETER_NAMES,
62 		PP_MACRO_INVOCATION_CHAIN_TOO_DEEP,
63 		PP_CONDITIONAL_ENDIF_WITHOUT_IF,
64 		PP_CONDITIONAL_ELSE_WITHOUT_IF,
65 		PP_CONDITIONAL_ELSE_AFTER_ELSE,
66 		PP_CONDITIONAL_ELIF_WITHOUT_IF,
67 		PP_CONDITIONAL_ELIF_AFTER_ELSE,
68 		PP_CONDITIONAL_UNTERMINATED,
69 		PP_CONDITIONAL_UNEXPECTED_TOKEN,
70 		PP_INVALID_EXTENSION_NAME,
71 		PP_INVALID_EXTENSION_BEHAVIOR,
72 		PP_INVALID_EXTENSION_DIRECTIVE,
73 		PP_INVALID_VERSION_NUMBER,
74 		PP_INVALID_VERSION_DIRECTIVE,
75 		PP_VERSION_NOT_FIRST_STATEMENT,
76 		PP_VERSION_NOT_FIRST_LINE_ESSL3,
77 		PP_INVALID_LINE_NUMBER,
78 		PP_INVALID_FILE_NUMBER,
79 		PP_INVALID_LINE_DIRECTIVE,
80 		PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL3,
81 		PP_UNDEFINED_SHIFT,
82 		PP_TOKENIZER_ERROR,
83 		PP_ERROR_END,
84 
85 		PP_WARNING_BEGIN,
86 		PP_EOF_IN_DIRECTIVE,
87 		PP_UNRECOGNIZED_PRAGMA,
88 		PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1,
89 		PP_WARNING_MACRO_NAME_RESERVED,
90 		PP_WARNING_END
91 	};
92 
93 	virtual ~Diagnostics();
94 
95 	void report(ID id, const SourceLocation &loc, const std::string &text);
96 
97 protected:
98 	bool isError(ID id);
99 	const char *message(ID id);
100 	Severity severity(ID id);
101 
102 	virtual void print(ID id, const SourceLocation &loc, const std::string &text) = 0;
103 };
104 
105 }  // namespace pp
106 
107 #endif  // COMPILER_PREPROCESSOR_DIAGNOSTICSBASE_H_
108