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