1// Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15#include "Diagnostics.h" 16 17#include <cassert> 18 19namespace pp 20{ 21 22Diagnostics::~Diagnostics() 23{ 24} 25 26void Diagnostics::report(ID id, 27 const SourceLocation& loc, 28 const std::string& text) 29{ 30 // TODO(alokp): Keep a count of errors and warnings. 31 print(id, loc, text); 32} 33 34Diagnostics::Severity Diagnostics::severity(ID id) 35{ 36 if ((id > ERROR_BEGIN) && (id < ERROR_END)) 37 return PP_ERROR; 38 39 if ((id > WARNING_BEGIN) && (id < WARNING_END)) 40 return PP_WARNING; 41 42 assert(false); 43 return PP_ERROR; 44} 45 46std::string Diagnostics::message(ID id) 47{ 48 switch (id) 49 { 50 // Errors begin. 51 case INTERNAL_ERROR: 52 return "internal error"; 53 case OUT_OF_MEMORY: 54 return "out of memory"; 55 case INVALID_CHARACTER: 56 return "invalid character"; 57 case INVALID_NUMBER: 58 return "invalid number"; 59 case INTEGER_OVERFLOW: 60 return "integer overflow"; 61 case FLOAT_OVERFLOW: 62 return "float overflow"; 63 case TOKEN_TOO_LONG: 64 return "token too long"; 65 case INVALID_EXPRESSION: 66 return "invalid expression"; 67 case DIVISION_BY_ZERO: 68 return "division by zero"; 69 case EOF_IN_COMMENT: 70 return "unexpected end of file found in comment"; 71 case UNEXPECTED_TOKEN: 72 return "unexpected token"; 73 case DIRECTIVE_INVALID_NAME: 74 return "invalid directive name"; 75 case MACRO_NAME_RESERVED: 76 return "macro name is reserved"; 77 case MACRO_REDEFINED: 78 return "macro redefined"; 79 case MACRO_PREDEFINED_REDEFINED: 80 return "predefined macro redefined"; 81 case MACRO_PREDEFINED_UNDEFINED: 82 return "predefined macro undefined"; 83 case MACRO_UNTERMINATED_INVOCATION: 84 return "unterminated macro invocation"; 85 case MACRO_TOO_FEW_ARGS: 86 return "Not enough arguments for macro"; 87 case MACRO_TOO_MANY_ARGS: 88 return "Too many arguments for macro"; 89 case MACRO_DUPLICATE_PARAMETER_NAMES: 90 return "duplicate macro parameter name"; 91 case CONDITIONAL_ENDIF_WITHOUT_IF: 92 return "unexpected #endif found without a matching #if"; 93 case CONDITIONAL_ELSE_WITHOUT_IF: 94 return "unexpected #else found without a matching #if"; 95 case CONDITIONAL_ELSE_AFTER_ELSE: 96 return "unexpected #else found after another #else"; 97 case CONDITIONAL_ELIF_WITHOUT_IF: 98 return "unexpected #elif found without a matching #if"; 99 case CONDITIONAL_ELIF_AFTER_ELSE: 100 return "unexpected #elif found after #else"; 101 case CONDITIONAL_UNTERMINATED: 102 return "unexpected end of file found in conditional block"; 103 case INVALID_EXTENSION_NAME: 104 return "invalid extension name"; 105 case INVALID_EXTENSION_BEHAVIOR: 106 return "invalid extension behavior"; 107 case INVALID_EXTENSION_DIRECTIVE: 108 return "invalid extension directive"; 109 case INVALID_VERSION_NUMBER: 110 return "invalid version number"; 111 case INVALID_VERSION_DIRECTIVE: 112 return "invalid version directive"; 113 case VERSION_NOT_FIRST_STATEMENT: 114 return "#version directive must occur before anything else, " 115 "except for comments and white space"; 116 case INVALID_LINE_NUMBER: 117 return "invalid line number"; 118 case INVALID_FILE_NUMBER: 119 return "invalid file number"; 120 case INVALID_LINE_DIRECTIVE: 121 return "invalid line directive"; 122 case UNDEFINED_IDENTIFIER: 123 return "undefined identifier"; 124 // Errors end. 125 // Warnings begin. 126 case EOF_IN_DIRECTIVE: 127 return "unexpected end of file found in directive"; 128 case CONDITIONAL_UNEXPECTED_TOKEN: 129 return "unexpected token after conditional expression"; 130 case UNRECOGNIZED_PRAGMA: 131 return "unrecognized pragma"; 132 // Warnings end. 133 default: 134 assert(false); 135 return ""; 136 } 137} 138 139} // namespace pp 140