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