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 ~Diagnostics()14Diagnostics::~Diagnostics() 15 { 16 } 17 report(ID id,const SourceLocation & loc,const std::string & text)18void Diagnostics::report(ID id, const SourceLocation &loc, const std::string &text) 19 { 20 print(id, loc, text); 21 } 22 isError(ID id)23bool Diagnostics::isError(ID id) 24 { 25 if ((id > PP_ERROR_BEGIN) && (id < PP_ERROR_END)) 26 return true; 27 28 if ((id > PP_WARNING_BEGIN) && (id < PP_WARNING_END)) 29 return false; 30 31 UNREACHABLE(); 32 return true; 33 } 34 message(ID id)35const char *Diagnostics::message(ID id) 36 { 37 switch (id) 38 { 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"; 121 case PP_TOKENIZER_ERROR: 122 return "internal tokenizer error"; 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 ""; 140 } 141 } 142 143 } // namespace pp 144