blob: 2b5e57c59c42adc83348ba819cb2b69c646432ca [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
alokp@chromium.org2c958ee2012-05-17 20:35:42 +000018void Diagnostics::report(ID id,
Zhenyao Mod526f982014-05-13 14:51:19 -070019 const SourceLocation &loc,
20 const std::string &text)
alokp@chromium.org2c958ee2012-05-17 20:35:42 +000021{
22 // TODO(alokp): Keep a count of errors and warnings.
23 print(id, loc, text);
24}
25
26Diagnostics::Severity Diagnostics::severity(ID id)
27{
Shannon Woods7f2d7942013-11-19 15:07:58 -050028 if ((id > PP_ERROR_BEGIN) && (id < PP_ERROR_END))
29 return PP_ERROR;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +000030
Shannon Woods7f2d7942013-11-19 15:07:58 -050031 if ((id > PP_WARNING_BEGIN) && (id < PP_WARNING_END))
32 return PP_WARNING;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +000033
Corentin Wallez054f7ed2016-09-20 17:15:59 -040034 UNREACHABLE();
Shannon Woods7f2d7942013-11-19 15:07:58 -050035 return PP_ERROR;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +000036}
37
alokp@chromium.org6b495712012-06-29 00:06:58 +000038std::string Diagnostics::message(ID id)
39{
40 switch (id)
41 {
42 // Errors begin.
Shannon Woods7f2d7942013-11-19 15:07:58 -050043 case PP_INTERNAL_ERROR:
Zhenyao Mod526f982014-05-13 14:51:19 -070044 return "internal error";
Shannon Woods7f2d7942013-11-19 15:07:58 -050045 case PP_OUT_OF_MEMORY:
Zhenyao Mod526f982014-05-13 14:51:19 -070046 return "out of memory";
Shannon Woods7f2d7942013-11-19 15:07:58 -050047 case PP_INVALID_CHARACTER:
Zhenyao Mod526f982014-05-13 14:51:19 -070048 return "invalid character";
Shannon Woods7f2d7942013-11-19 15:07:58 -050049 case PP_INVALID_NUMBER:
Zhenyao Mod526f982014-05-13 14:51:19 -070050 return "invalid number";
Shannon Woods7f2d7942013-11-19 15:07:58 -050051 case PP_INTEGER_OVERFLOW:
Zhenyao Mod526f982014-05-13 14:51:19 -070052 return "integer overflow";
Shannon Woods7f2d7942013-11-19 15:07:58 -050053 case PP_FLOAT_OVERFLOW:
Zhenyao Mod526f982014-05-13 14:51:19 -070054 return "float overflow";
Shannon Woods7f2d7942013-11-19 15:07:58 -050055 case PP_TOKEN_TOO_LONG:
Zhenyao Mod526f982014-05-13 14:51:19 -070056 return "token too long";
Shannon Woods7f2d7942013-11-19 15:07:58 -050057 case PP_INVALID_EXPRESSION:
Zhenyao Mod526f982014-05-13 14:51:19 -070058 return "invalid expression";
Shannon Woods7f2d7942013-11-19 15:07:58 -050059 case PP_DIVISION_BY_ZERO:
Zhenyao Mod526f982014-05-13 14:51:19 -070060 return "division by zero";
Shannon Woods7f2d7942013-11-19 15:07:58 -050061 case PP_EOF_IN_COMMENT:
Zhenyao Mod526f982014-05-13 14:51:19 -070062 return "unexpected end of file found in comment";
Shannon Woods7f2d7942013-11-19 15:07:58 -050063 case PP_UNEXPECTED_TOKEN:
Zhenyao Mod526f982014-05-13 14:51:19 -070064 return "unexpected token";
Shannon Woods7f2d7942013-11-19 15:07:58 -050065 case PP_DIRECTIVE_INVALID_NAME:
Zhenyao Mod526f982014-05-13 14:51:19 -070066 return "invalid directive name";
Shannon Woods7f2d7942013-11-19 15:07:58 -050067 case PP_MACRO_NAME_RESERVED:
Zhenyao Mod526f982014-05-13 14:51:19 -070068 return "macro name is reserved";
Shannon Woods7f2d7942013-11-19 15:07:58 -050069 case PP_MACRO_REDEFINED:
Zhenyao Mod526f982014-05-13 14:51:19 -070070 return "macro redefined";
Shannon Woods7f2d7942013-11-19 15:07:58 -050071 case PP_MACRO_PREDEFINED_REDEFINED:
Zhenyao Mod526f982014-05-13 14:51:19 -070072 return "predefined macro redefined";
Shannon Woods7f2d7942013-11-19 15:07:58 -050073 case PP_MACRO_PREDEFINED_UNDEFINED:
Zhenyao Mod526f982014-05-13 14:51:19 -070074 return "predefined macro undefined";
Shannon Woods7f2d7942013-11-19 15:07:58 -050075 case PP_MACRO_UNTERMINATED_INVOCATION:
Zhenyao Mod526f982014-05-13 14:51:19 -070076 return "unterminated macro invocation";
Corentin Wallezd2f195b2016-09-19 15:53:33 -040077 case PP_MACRO_UNDEFINED_WHILE_INVOKED:
78 return "macro undefined while being invoked";
Shannon Woods7f2d7942013-11-19 15:07:58 -050079 case PP_MACRO_TOO_FEW_ARGS:
Zhenyao Mod526f982014-05-13 14:51:19 -070080 return "Not enough arguments for macro";
Shannon Woods7f2d7942013-11-19 15:07:58 -050081 case PP_MACRO_TOO_MANY_ARGS:
Zhenyao Mod526f982014-05-13 14:51:19 -070082 return "Too many arguments for macro";
Geoff Lang26be18d2015-04-27 14:05:57 -040083 case PP_MACRO_DUPLICATE_PARAMETER_NAMES:
84 return "duplicate macro parameter name";
Olli Etuahof1cf5e62016-11-22 17:36:49 +000085 case PP_MACRO_INVOCATION_CHAIN_TOO_DEEP:
86 return "macro invocation chain too deep";
Shannon Woods7f2d7942013-11-19 15:07:58 -050087 case PP_CONDITIONAL_ENDIF_WITHOUT_IF:
Zhenyao Mod526f982014-05-13 14:51:19 -070088 return "unexpected #endif found without a matching #if";
Shannon Woods7f2d7942013-11-19 15:07:58 -050089 case PP_CONDITIONAL_ELSE_WITHOUT_IF:
Zhenyao Mod526f982014-05-13 14:51:19 -070090 return "unexpected #else found without a matching #if";
Shannon Woods7f2d7942013-11-19 15:07:58 -050091 case PP_CONDITIONAL_ELSE_AFTER_ELSE:
Zhenyao Mod526f982014-05-13 14:51:19 -070092 return "unexpected #else found after another #else";
Shannon Woods7f2d7942013-11-19 15:07:58 -050093 case PP_CONDITIONAL_ELIF_WITHOUT_IF:
Zhenyao Mod526f982014-05-13 14:51:19 -070094 return "unexpected #elif found without a matching #if";
Shannon Woods7f2d7942013-11-19 15:07:58 -050095 case PP_CONDITIONAL_ELIF_AFTER_ELSE:
Zhenyao Mod526f982014-05-13 14:51:19 -070096 return "unexpected #elif found after #else";
Shannon Woods7f2d7942013-11-19 15:07:58 -050097 case PP_CONDITIONAL_UNTERMINATED:
Zhenyao Mod526f982014-05-13 14:51:19 -070098 return "unexpected end of file found in conditional block";
Shannon Woods7f2d7942013-11-19 15:07:58 -050099 case PP_INVALID_EXTENSION_NAME:
Zhenyao Mod526f982014-05-13 14:51:19 -0700100 return "invalid extension name";
Shannon Woods7f2d7942013-11-19 15:07:58 -0500101 case PP_INVALID_EXTENSION_BEHAVIOR:
Zhenyao Mod526f982014-05-13 14:51:19 -0700102 return "invalid extension behavior";
Shannon Woods7f2d7942013-11-19 15:07:58 -0500103 case PP_INVALID_EXTENSION_DIRECTIVE:
Zhenyao Mod526f982014-05-13 14:51:19 -0700104 return "invalid extension directive";
Shannon Woods7f2d7942013-11-19 15:07:58 -0500105 case PP_INVALID_VERSION_NUMBER:
Zhenyao Mod526f982014-05-13 14:51:19 -0700106 return "invalid version number";
Shannon Woods7f2d7942013-11-19 15:07:58 -0500107 case PP_INVALID_VERSION_DIRECTIVE:
Zhenyao Mod526f982014-05-13 14:51:19 -0700108 return "invalid version directive";
Shannon Woods7f2d7942013-11-19 15:07:58 -0500109 case PP_VERSION_NOT_FIRST_STATEMENT:
alokp@chromium.orgd0d9f872012-07-03 16:06:40 +0000110 return "#version directive must occur before anything else, "
111 "except for comments and white space";
Olli Etuahoc378cd82015-05-25 15:21:44 +0300112 case PP_VERSION_NOT_FIRST_LINE_ESSL3:
113 return "#version directive must occur on the first line of the shader";
Shannon Woods7f2d7942013-11-19 15:07:58 -0500114 case PP_INVALID_LINE_NUMBER:
Zhenyao Mod526f982014-05-13 14:51:19 -0700115 return "invalid line number";
Shannon Woods7f2d7942013-11-19 15:07:58 -0500116 case PP_INVALID_FILE_NUMBER:
Zhenyao Mod526f982014-05-13 14:51:19 -0700117 return "invalid file number";
Shannon Woods7f2d7942013-11-19 15:07:58 -0500118 case PP_INVALID_LINE_DIRECTIVE:
Zhenyao Mod526f982014-05-13 14:51:19 -0700119 return "invalid line directive";
Geoff Langb3a6a8f2015-06-23 16:10:14 -0400120 case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL3:
121 return "extension directive must occur before any non-preprocessor tokens in ESSL3";
Jamie Madill461e3af2016-07-21 18:15:34 -0400122 case PP_UNDEFINED_SHIFT:
123 return "shift exponent is negative or undefined";
alokp@chromium.org6b495712012-06-29 00:06:58 +0000124 // Errors end.
125 // Warnings begin.
Shannon Woods7f2d7942013-11-19 15:07:58 -0500126 case PP_EOF_IN_DIRECTIVE:
Zhenyao Mod526f982014-05-13 14:51:19 -0700127 return "unexpected end of file found in directive";
Shannon Woods7f2d7942013-11-19 15:07:58 -0500128 case PP_CONDITIONAL_UNEXPECTED_TOKEN:
Zhenyao Mod526f982014-05-13 14:51:19 -0700129 return "unexpected token after conditional expression";
Shannon Woods7f2d7942013-11-19 15:07:58 -0500130 case PP_UNRECOGNIZED_PRAGMA:
Zhenyao Mod526f982014-05-13 14:51:19 -0700131 return "unrecognized pragma";
Geoff Langb3a6a8f2015-06-23 16:10:14 -0400132 case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1:
133 return "extension directive should occur before any non-preprocessor tokens";
Olli Etuaho2f6ddf32015-09-22 16:10:07 +0300134 case PP_WARNING_MACRO_NAME_RESERVED:
135 return "macro name with a double underscore is reserved - unintented behavior is possible";
alokp@chromium.org6b495712012-06-29 00:06:58 +0000136 // Warnings end.
137 default:
Corentin Wallez054f7ed2016-09-20 17:15:59 -0400138 UNREACHABLE();
139 return "";
alokp@chromium.org6b495712012-06-29 00:06:58 +0000140 }
141}
142
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000143} // namespace pp