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 | #include "DiagnosticsBase.h" |
16 | |
17 | #include <cassert> |
18 | |
19 | namespace pp |
20 | { |
21 | |
22 | Diagnostics::~Diagnostics() |
23 | { |
24 | } |
25 | |
26 | void Diagnostics::report(ID id, const SourceLocation &loc, const std::string &text) |
27 | { |
28 | print(id, loc, text); |
29 | } |
30 | |
31 | bool Diagnostics::isError(ID id) |
32 | { |
33 | if ((id > PP_ERROR_BEGIN) && (id < PP_ERROR_END)) |
34 | return true; |
35 | |
36 | if ((id > PP_WARNING_BEGIN) && (id < PP_WARNING_END)) |
37 | return false; |
38 | |
39 | assert(false); |
40 | return true; |
41 | } |
42 | |
43 | Diagnostics::Severity Diagnostics::severity(ID id) |
44 | { |
45 | if((id > PP_ERROR_BEGIN) && (id < PP_ERROR_END)) |
46 | return PP_ERROR; |
47 | |
48 | if((id > PP_WARNING_BEGIN) && (id < PP_WARNING_END)) |
49 | return PP_WARNING; |
50 | |
51 | assert(false); |
52 | return PP_ERROR; |
53 | } |
54 | |
55 | const char *Diagnostics::message(ID id) |
56 | { |
57 | switch (id) |
58 | { |
59 | // Errors begin. |
60 | case PP_INTERNAL_ERROR: |
61 | return "internal error"; |
62 | case PP_OUT_OF_MEMORY: |
63 | return "out of memory"; |
64 | case PP_INVALID_CHARACTER: |
65 | return "invalid character"; |
66 | case PP_INVALID_NUMBER: |
67 | return "invalid number"; |
68 | case PP_INTEGER_OVERFLOW: |
69 | return "integer overflow"; |
70 | case PP_FLOAT_OVERFLOW: |
71 | return "float overflow"; |
72 | case PP_TOKEN_TOO_LONG: |
73 | return "token too long"; |
74 | case PP_INVALID_EXPRESSION: |
75 | return "invalid expression"; |
76 | case PP_DIVISION_BY_ZERO: |
77 | return "division by zero"; |
78 | case PP_EOF_IN_COMMENT: |
79 | return "unexpected end of file found in comment"; |
80 | case PP_UNEXPECTED_TOKEN: |
81 | return "unexpected token"; |
82 | case PP_DIRECTIVE_INVALID_NAME: |
83 | return "invalid directive name"; |
84 | case PP_MACRO_NAME_RESERVED: |
85 | return "macro name is reserved"; |
86 | case PP_MACRO_REDEFINED: |
87 | return "macro redefined"; |
88 | case PP_MACRO_PREDEFINED_REDEFINED: |
89 | return "predefined macro redefined"; |
90 | case PP_MACRO_PREDEFINED_UNDEFINED: |
91 | return "predefined macro undefined"; |
92 | case PP_MACRO_UNTERMINATED_INVOCATION: |
93 | return "unterminated macro invocation"; |
94 | case PP_MACRO_UNDEFINED_WHILE_INVOKED: |
95 | return "macro undefined while being invoked"; |
96 | case PP_MACRO_TOO_FEW_ARGS: |
97 | return "Not enough arguments for macro"; |
98 | case PP_MACRO_TOO_MANY_ARGS: |
99 | return "Too many arguments for macro"; |
100 | case PP_MACRO_DUPLICATE_PARAMETER_NAMES: |
101 | return "duplicate macro parameter name"; |
102 | case PP_MACRO_INVOCATION_CHAIN_TOO_DEEP: |
103 | return "macro invocation chain too deep"; |
104 | case PP_CONDITIONAL_ENDIF_WITHOUT_IF: |
105 | return "unexpected #endif found without a matching #if"; |
106 | case PP_CONDITIONAL_ELSE_WITHOUT_IF: |
107 | return "unexpected #else found without a matching #if"; |
108 | case PP_CONDITIONAL_ELSE_AFTER_ELSE: |
109 | return "unexpected #else found after another #else"; |
110 | case PP_CONDITIONAL_ELIF_WITHOUT_IF: |
111 | return "unexpected #elif found without a matching #if"; |
112 | case PP_CONDITIONAL_ELIF_AFTER_ELSE: |
113 | return "unexpected #elif found after #else"; |
114 | case PP_CONDITIONAL_UNTERMINATED: |
115 | return "unexpected end of file found in conditional block"; |
116 | case PP_INVALID_EXTENSION_NAME: |
117 | return "invalid extension name"; |
118 | case PP_INVALID_EXTENSION_BEHAVIOR: |
119 | return "invalid extension behavior"; |
120 | case PP_INVALID_EXTENSION_DIRECTIVE: |
121 | return "invalid extension directive"; |
122 | case PP_INVALID_VERSION_NUMBER: |
123 | return "invalid version number"; |
124 | case PP_INVALID_VERSION_DIRECTIVE: |
125 | return "invalid version directive"; |
126 | case PP_VERSION_NOT_FIRST_STATEMENT: |
127 | return "#version directive must occur before anything else, " |
128 | "except for comments and white space"; |
129 | case PP_VERSION_NOT_FIRST_LINE_ESSL3: |
130 | return "#version directive must occur on the first line of the shader"; |
131 | case PP_INVALID_LINE_NUMBER: |
132 | return "invalid line number"; |
133 | case PP_INVALID_FILE_NUMBER: |
134 | return "invalid file number"; |
135 | case PP_INVALID_LINE_DIRECTIVE: |
136 | return "invalid line directive"; |
137 | case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL3: |
138 | return "extension directive must occur before any non-preprocessor tokens in ESSL3"; |
139 | case PP_UNDEFINED_SHIFT: |
140 | return "shift exponent is negative or undefined"; |
141 | case PP_TOKENIZER_ERROR: |
142 | return "internal tokenizer error"; |
143 | // Errors end. |
144 | // Warnings begin. |
145 | case PP_EOF_IN_DIRECTIVE: |
146 | return "unexpected end of file found in directive"; |
147 | case PP_CONDITIONAL_UNEXPECTED_TOKEN: |
148 | return "unexpected token after conditional expression"; |
149 | case PP_UNRECOGNIZED_PRAGMA: |
150 | return "unrecognized pragma"; |
151 | case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1: |
152 | return "extension directive should occur before any non-preprocessor tokens"; |
153 | case PP_WARNING_MACRO_NAME_RESERVED: |
154 | return "macro name with a double underscore is reserved - unintented behavior is " |
155 | "possible"; |
156 | // Warnings end. |
157 | default: |
158 | assert(false); |
159 | return ""; |
160 | } |
161 | } |
162 | |
163 | } // namespace pp |
164 |