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