• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DIAGNOSTICS_H_
16 #define COMPILER_PREPROCESSOR_DIAGNOSTICS_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 	enum Severity
31 	{
32 		PP_ERROR,
33 		PP_WARNING
34 	};
35 	enum ID
36 	{
37 		ERROR_BEGIN,
38 		INTERNAL_ERROR,
39 		OUT_OF_MEMORY,
40 		INVALID_CHARACTER,
41 		INVALID_NUMBER,
42 		INTEGER_OVERFLOW,
43 		FLOAT_OVERFLOW,
44 		TOKEN_TOO_LONG,
45 		INVALID_EXPRESSION,
46 		DIVISION_BY_ZERO,
47 		EOF_IN_COMMENT,
48 		UNEXPECTED_TOKEN,
49 		DIRECTIVE_INVALID_NAME,
50 		MACRO_NAME_RESERVED,
51 		MACRO_REDEFINED,
52 		MACRO_PREDEFINED_REDEFINED,
53 		MACRO_PREDEFINED_UNDEFINED,
54 		MACRO_UNTERMINATED_INVOCATION,
55 		MACRO_TOO_FEW_ARGS,
56 		MACRO_TOO_MANY_ARGS,
57 		MACRO_DUPLICATE_PARAMETER_NAMES,
58 		CONDITIONAL_ENDIF_WITHOUT_IF,
59 		CONDITIONAL_ELSE_WITHOUT_IF,
60 		CONDITIONAL_ELSE_AFTER_ELSE,
61 		CONDITIONAL_ELIF_WITHOUT_IF,
62 		CONDITIONAL_ELIF_AFTER_ELSE,
63 		CONDITIONAL_UNTERMINATED,
64 		CONDITIONAL_UNEXPECTED_TOKEN,
65 		INVALID_EXTENSION_NAME,
66 		INVALID_EXTENSION_BEHAVIOR,
67 		INVALID_EXTENSION_DIRECTIVE,
68 		INVALID_VERSION_NUMBER,
69 		INVALID_VERSION_DIRECTIVE,
70 		VERSION_NOT_FIRST_STATEMENT,
71 		INVALID_LINE_NUMBER,
72 		INVALID_FILE_NUMBER,
73 		INVALID_LINE_DIRECTIVE,
74 		UNDEFINED_IDENTIFIER,
75 		ERROR_END,
76 
77 		WARNING_BEGIN,
78 		EOF_IN_DIRECTIVE,
79 		UNRECOGNIZED_PRAGMA,
80 		WARNING_END
81 	};
82 
83 	virtual ~Diagnostics();
84 
85 	void report(ID id, const SourceLocation& loc, const std::string& text);
86 
87 protected:
88 	Severity severity(ID id);
89 	std::string message(ID id);
90 
91 	virtual void print(ID id,
92 	                   const SourceLocation& loc,
93 	                   const std::string& text) = 0;
94 };
95 
96 }  // namespace pp
97 #endif  // COMPILER_PREPROCESSOR_DIAGNOSTICS_H_
98