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 | |
daniel@transgaming.com | b3077d0 | 2013-01-11 04:12:09 +0000 | [diff] [blame] | 7 | #include "DiagnosticsBase.h" |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 8 | |
| 9 | #include <cassert> |
| 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 | |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 18 | void Diagnostics::report(ID id, |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 19 | const SourceLocation &loc, |
| 20 | const std::string &text) |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 21 | { |
| 22 | // TODO(alokp): Keep a count of errors and warnings. |
| 23 | print(id, loc, text); |
| 24 | } |
| 25 | |
| 26 | Diagnostics::Severity Diagnostics::severity(ID id) |
| 27 | { |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 28 | if ((id > PP_ERROR_BEGIN) && (id < PP_ERROR_END)) |
| 29 | return PP_ERROR; |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 30 | |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 31 | if ((id > PP_WARNING_BEGIN) && (id < PP_WARNING_END)) |
| 32 | return PP_WARNING; |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 33 | |
| 34 | assert(false); |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 35 | return PP_ERROR; |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 36 | } |
| 37 | |
alokp@chromium.org | 6b49571 | 2012-06-29 00:06:58 +0000 | [diff] [blame] | 38 | std::string Diagnostics::message(ID id) |
| 39 | { |
| 40 | switch (id) |
| 41 | { |
| 42 | // Errors begin. |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 43 | case PP_INTERNAL_ERROR: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 44 | return "internal error"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 45 | case PP_OUT_OF_MEMORY: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 46 | return "out of memory"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 47 | case PP_INVALID_CHARACTER: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 48 | return "invalid character"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 49 | case PP_INVALID_NUMBER: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 50 | return "invalid number"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 51 | case PP_INTEGER_OVERFLOW: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 52 | return "integer overflow"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 53 | case PP_FLOAT_OVERFLOW: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 54 | return "float overflow"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 55 | case PP_TOKEN_TOO_LONG: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 56 | return "token too long"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 57 | case PP_INVALID_EXPRESSION: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 58 | return "invalid expression"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 59 | case PP_DIVISION_BY_ZERO: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 60 | return "division by zero"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 61 | case PP_EOF_IN_COMMENT: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 62 | return "unexpected end of file found in comment"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 63 | case PP_UNEXPECTED_TOKEN: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 64 | return "unexpected token"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 65 | case PP_DIRECTIVE_INVALID_NAME: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 66 | return "invalid directive name"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 67 | case PP_MACRO_NAME_RESERVED: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 68 | return "macro name is reserved"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 69 | case PP_MACRO_REDEFINED: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 70 | return "macro redefined"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 71 | case PP_MACRO_PREDEFINED_REDEFINED: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 72 | return "predefined macro redefined"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 73 | case PP_MACRO_PREDEFINED_UNDEFINED: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 74 | return "predefined macro undefined"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 75 | case PP_MACRO_UNTERMINATED_INVOCATION: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 76 | return "unterminated macro invocation"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 77 | case PP_MACRO_TOO_FEW_ARGS: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 78 | return "Not enough arguments for macro"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 79 | case PP_MACRO_TOO_MANY_ARGS: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 80 | return "Too many arguments for macro"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 81 | case PP_CONDITIONAL_ENDIF_WITHOUT_IF: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 82 | return "unexpected #endif found without a matching #if"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 83 | case PP_CONDITIONAL_ELSE_WITHOUT_IF: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 84 | return "unexpected #else found without a matching #if"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 85 | case PP_CONDITIONAL_ELSE_AFTER_ELSE: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 86 | return "unexpected #else found after another #else"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 87 | case PP_CONDITIONAL_ELIF_WITHOUT_IF: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 88 | return "unexpected #elif found without a matching #if"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 89 | case PP_CONDITIONAL_ELIF_AFTER_ELSE: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 90 | return "unexpected #elif found after #else"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 91 | case PP_CONDITIONAL_UNTERMINATED: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 92 | return "unexpected end of file found in conditional block"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 93 | case PP_INVALID_EXTENSION_NAME: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 94 | return "invalid extension name"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 95 | case PP_INVALID_EXTENSION_BEHAVIOR: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 96 | return "invalid extension behavior"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 97 | case PP_INVALID_EXTENSION_DIRECTIVE: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 98 | return "invalid extension directive"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 99 | case PP_INVALID_VERSION_NUMBER: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 100 | return "invalid version number"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 101 | case PP_INVALID_VERSION_DIRECTIVE: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 102 | return "invalid version directive"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 103 | case PP_VERSION_NOT_FIRST_STATEMENT: |
alokp@chromium.org | d0d9f87 | 2012-07-03 16:06:40 +0000 | [diff] [blame] | 104 | return "#version directive must occur before anything else, " |
| 105 | "except for comments and white space"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 106 | case PP_INVALID_LINE_NUMBER: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 107 | return "invalid line number"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 108 | case PP_INVALID_FILE_NUMBER: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 109 | return "invalid file number"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 110 | case PP_INVALID_LINE_DIRECTIVE: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 111 | return "invalid line directive"; |
alokp@chromium.org | 6b49571 | 2012-06-29 00:06:58 +0000 | [diff] [blame] | 112 | // Errors end. |
| 113 | // Warnings begin. |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 114 | case PP_EOF_IN_DIRECTIVE: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 115 | return "unexpected end of file found in directive"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 116 | case PP_CONDITIONAL_UNEXPECTED_TOKEN: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 117 | return "unexpected token after conditional expression"; |
Shannon Woods | 7f2d794 | 2013-11-19 15:07:58 -0500 | [diff] [blame] | 118 | case PP_UNRECOGNIZED_PRAGMA: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 119 | return "unrecognized pragma"; |
alokp@chromium.org | 6b49571 | 2012-06-29 00:06:58 +0000 | [diff] [blame] | 120 | // Warnings end. |
| 121 | default: |
Zhenyao Mo | d526f98 | 2014-05-13 14:51:19 -0700 | [diff] [blame^] | 122 | assert(false); |
| 123 | return ""; |
alokp@chromium.org | 6b49571 | 2012-06-29 00:06:58 +0000 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
alokp@chromium.org | 2c958ee | 2012-05-17 20:35:42 +0000 | [diff] [blame] | 127 | } // namespace pp |