1 /** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 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 16 #ifndef ASSEMBLER_ERROR_H 17 #define ASSEMBLER_ERROR_H 18 19 #include <string> 20 21 namespace panda::pandasm { 22 23 struct Error { 24 enum class ErrorClass { WARNING = 0, ERROR }; 25 enum class ErrorType { 26 ERR_NONE = 0, 27 28 // Lexer 29 ERR_STRING_MISSING_TERMINATING_CHARACTER, 30 31 // Parser 32 ERR_BAD_LABEL, 33 ERR_BAD_LABEL_EXT, 34 ERR_BAD_NAME_ID, 35 ERR_BAD_NAME_REG, 36 ERR_BAD_INTEGER_NAME, 37 ERR_BAD_INTEGER_WIDTH, 38 ERR_BAD_FLOAT_NAME, 39 ERR_BAD_FLOAT_WIDTH, 40 ERR_BAD_NUMBER_OPERANDS, 41 ERR_BAD_OPERAND, 42 ERR_BAD_OPERATION_NAME, 43 ERR_BAD_NONEXISTING_OPERATION, 44 ERR_BAD_ID_FUNCTION, 45 ERR_BAD_ID_RECORD, 46 ERR_BAD_ID_ARRAY, 47 ERR_BAD_ID_FIELD, 48 ERR_BAD_FUNCTION_NAME, 49 ERR_BAD_RECORD_NAME, 50 ERR_BAD_ARRAY_NAME, 51 ERR_BAD_DEFINITION_METADATA, 52 ERR_BAD_DEFINITION_FUNCTION, 53 ERR_BAD_DEFINITION_RECORD, 54 ERR_BAD_METADATA_BOUND, 55 ERR_BAD_METADATA_UNKNOWN_ATTRIBUTE, 56 ERR_BAD_METADATA_INVALID_VALUE, 57 ERR_BAD_METADATA_MISSING_ATTRIBUTE, 58 ERR_BAD_METADATA_MISSING_VALUE, 59 ERR_BAD_METADATA_UNEXPECTED_ATTRIBUTE, 60 ERR_BAD_METADATA_UNEXPECTED_VALUE, 61 ERR_BAD_METADATA_MULTIPLE_ATTRIBUTE, 62 ERR_BAD_FUNCTION_PARAMETERS, 63 ERR_BAD_FUNCTION_RETURN_VALUE, 64 ERR_FUNCTION_ARGUMENT_MISMATCH, 65 ERR_BAD_FIELD_MISSING_NAME, 66 ERR_BAD_FIELD_VALUE_TYPE, 67 ERR_BAD_ARRAY_TYPE, 68 ERR_BAD_ARRAY_SIZE, 69 ERR_BAD_ARRAY_SIZE_VALUE, 70 ERR_BAD_ARRAY_ELEMENT_MISSING_VALUE, 71 ERR_BAD_ARRAY_ELEMENT_VALUE_TYPE, 72 ERR_BAD_ARRAY_ELEMENT_VALUE, 73 ERR_BAD_ARRAY_ELEMENT_VALUE_INTEGER, 74 ERR_BAD_ARRAY_ELEMENT_VALUE_FLOAT, 75 ERR_BAD_ARRAY_ELEMENT_VALUE_STRING, 76 ERR_BAD_CHARACTER, 77 ERR_BAD_KEYWORD, 78 ERR_BAD_DEFINITION, 79 ERR_BAD_BOUND, 80 ERR_BAD_END, 81 ERR_BAD_CLOSE, 82 ERR_BAD_ARGS_BOUND, 83 ERR_BAD_TYPE, 84 ERR_BAD_PARAM_NAME, 85 ERR_BAD_NOEXP_DELIM, 86 ERR_BAD_STRING_INVALID_HEX_ESCAPE_SEQUENCE, 87 ERR_BAD_STRING_UNKNOWN_ESCAPE_SEQUENCE, 88 ERR_BAD_ARRAY_TYPE_BOUND, 89 ERR_UNDEFINED_TYPE, 90 ERR_MULTIPLE_DIRECTIVES, 91 ERR_INCORRECT_DIRECTIVE_LOCATION, 92 ERR_BAD_DIRECTIVE_DECLARATION, 93 ERR_UNKNOWN_LANGUAGE, 94 ERR_BAD_MNEMONIC_NAME, 95 ERR_REPEATING_FIELD_NAME, 96 ERR_FUNCTION_MULTIPLE_ALTERNATIVES, 97 ERR_BAD_SIGNATURE, 98 ERR_BAD_SIGNATURE_PARAMETERS, 99 100 // Warnings 101 WAR_UNEXPECTED_RETURN_TYPE, 102 WAR_UNEXPECTED_TYPE_ID, 103 }; 104 105 ErrorClass type; 106 std::string whole_line; 107 size_t pos; /* positions to highlight the word */ 108 size_t end; 109 ErrorType err; 110 std::string message; 111 std::string verbose; 112 size_t line_number; 113 ErrorError114 inline Error() : Error("No messages", 0, ErrorType::ERR_NONE, "", 0, 0, "") {} 115 116 inline Error(std::string s, size_t line, ErrorType error_type, std::string overinfo, size_t p, size_t e, 117 std::string buff, ErrorClass class_type = ErrorClass::ERROR) typeError118 : type(class_type), 119 whole_line(std::move(buff)), 120 pos(p), 121 end(e), 122 err(error_type), 123 message(std::move(s)), 124 verbose(std::move(overinfo)), 125 line_number(line) 126 { 127 } 128 }; 129 130 using ErrorList = std::vector<Error>; 131 } // namespace panda::pandasm 132 133 #endif // ASSEMBLER_ERROR_H 134