1b1994897Sopenharmony_ci/**
2b1994897Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3b1994897Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b1994897Sopenharmony_ci * you may not use this file except in compliance with the License.
5b1994897Sopenharmony_ci * You may obtain a copy of the License at
6b1994897Sopenharmony_ci *
7b1994897Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8b1994897Sopenharmony_ci *
9b1994897Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b1994897Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b1994897Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b1994897Sopenharmony_ci * See the License for the specific language governing permissions and
13b1994897Sopenharmony_ci * limitations under the License.
14b1994897Sopenharmony_ci */
15b1994897Sopenharmony_ci
16b1994897Sopenharmony_ci#ifndef ASSEMBLER_ERROR_H
17b1994897Sopenharmony_ci#define ASSEMBLER_ERROR_H
18b1994897Sopenharmony_ci
19b1994897Sopenharmony_ci#include <string>
20b1994897Sopenharmony_ci
21b1994897Sopenharmony_cinamespace panda::pandasm {
22b1994897Sopenharmony_ci
23b1994897Sopenharmony_cistruct Error {
24b1994897Sopenharmony_ci    enum class ErrorClass { WARNING = 0, ERROR };
25b1994897Sopenharmony_ci    enum class ErrorType {
26b1994897Sopenharmony_ci        ERR_NONE = 0,
27b1994897Sopenharmony_ci
28b1994897Sopenharmony_ci        // Lexer
29b1994897Sopenharmony_ci        ERR_STRING_MISSING_TERMINATING_CHARACTER,
30b1994897Sopenharmony_ci
31b1994897Sopenharmony_ci        // Parser
32b1994897Sopenharmony_ci        ERR_BAD_LABEL,
33b1994897Sopenharmony_ci        ERR_BAD_LABEL_EXT,
34b1994897Sopenharmony_ci        ERR_BAD_NAME_ID,
35b1994897Sopenharmony_ci        ERR_BAD_NAME_REG,
36b1994897Sopenharmony_ci        ERR_BAD_INTEGER_NAME,
37b1994897Sopenharmony_ci        ERR_BAD_INTEGER_WIDTH,
38b1994897Sopenharmony_ci        ERR_BAD_FLOAT_NAME,
39b1994897Sopenharmony_ci        ERR_BAD_FLOAT_WIDTH,
40b1994897Sopenharmony_ci        ERR_BAD_NUMBER_OPERANDS,
41b1994897Sopenharmony_ci        ERR_BAD_OPERAND,
42b1994897Sopenharmony_ci        ERR_BAD_OPERATION_NAME,
43b1994897Sopenharmony_ci        ERR_BAD_NONEXISTING_OPERATION,
44b1994897Sopenharmony_ci        ERR_BAD_ID_FUNCTION,
45b1994897Sopenharmony_ci        ERR_BAD_ID_RECORD,
46b1994897Sopenharmony_ci        ERR_BAD_ID_ARRAY,
47b1994897Sopenharmony_ci        ERR_BAD_ID_FIELD,
48b1994897Sopenharmony_ci        ERR_BAD_FUNCTION_NAME,
49b1994897Sopenharmony_ci        ERR_BAD_RECORD_NAME,
50b1994897Sopenharmony_ci        ERR_BAD_ARRAY_NAME,
51b1994897Sopenharmony_ci        ERR_BAD_DEFINITION_METADATA,
52b1994897Sopenharmony_ci        ERR_BAD_DEFINITION_FUNCTION,
53b1994897Sopenharmony_ci        ERR_BAD_DEFINITION_RECORD,
54b1994897Sopenharmony_ci        ERR_BAD_METADATA_BOUND,
55b1994897Sopenharmony_ci        ERR_BAD_METADATA_UNKNOWN_ATTRIBUTE,
56b1994897Sopenharmony_ci        ERR_BAD_METADATA_INVALID_VALUE,
57b1994897Sopenharmony_ci        ERR_BAD_METADATA_MISSING_ATTRIBUTE,
58b1994897Sopenharmony_ci        ERR_BAD_METADATA_MISSING_VALUE,
59b1994897Sopenharmony_ci        ERR_BAD_METADATA_UNEXPECTED_ATTRIBUTE,
60b1994897Sopenharmony_ci        ERR_BAD_METADATA_UNEXPECTED_VALUE,
61b1994897Sopenharmony_ci        ERR_BAD_METADATA_MULTIPLE_ATTRIBUTE,
62b1994897Sopenharmony_ci        ERR_BAD_FUNCTION_PARAMETERS,
63b1994897Sopenharmony_ci        ERR_BAD_FUNCTION_RETURN_VALUE,
64b1994897Sopenharmony_ci        ERR_FUNCTION_ARGUMENT_MISMATCH,
65b1994897Sopenharmony_ci        ERR_BAD_FIELD_MISSING_NAME,
66b1994897Sopenharmony_ci        ERR_BAD_FIELD_VALUE_TYPE,
67b1994897Sopenharmony_ci        ERR_BAD_ARRAY_TYPE,
68b1994897Sopenharmony_ci        ERR_BAD_ARRAY_SIZE,
69b1994897Sopenharmony_ci        ERR_BAD_ARRAY_SIZE_VALUE,
70b1994897Sopenharmony_ci        ERR_BAD_ARRAY_ELEMENT_MISSING_VALUE,
71b1994897Sopenharmony_ci        ERR_BAD_ARRAY_ELEMENT_VALUE_TYPE,
72b1994897Sopenharmony_ci        ERR_BAD_ARRAY_ELEMENT_VALUE,
73b1994897Sopenharmony_ci        ERR_BAD_ARRAY_ELEMENT_VALUE_INTEGER,
74b1994897Sopenharmony_ci        ERR_BAD_ARRAY_ELEMENT_VALUE_FLOAT,
75b1994897Sopenharmony_ci        ERR_BAD_ARRAY_ELEMENT_VALUE_STRING,
76b1994897Sopenharmony_ci        ERR_BAD_CHARACTER,
77b1994897Sopenharmony_ci        ERR_BAD_KEYWORD,
78b1994897Sopenharmony_ci        ERR_BAD_DEFINITION,
79b1994897Sopenharmony_ci        ERR_BAD_BOUND,
80b1994897Sopenharmony_ci        ERR_BAD_END,
81b1994897Sopenharmony_ci        ERR_BAD_CLOSE,
82b1994897Sopenharmony_ci        ERR_BAD_ARGS_BOUND,
83b1994897Sopenharmony_ci        ERR_BAD_TYPE,
84b1994897Sopenharmony_ci        ERR_BAD_PARAM_NAME,
85b1994897Sopenharmony_ci        ERR_BAD_NOEXP_DELIM,
86b1994897Sopenharmony_ci        ERR_BAD_STRING_INVALID_HEX_ESCAPE_SEQUENCE,
87b1994897Sopenharmony_ci        ERR_BAD_STRING_UNKNOWN_ESCAPE_SEQUENCE,
88b1994897Sopenharmony_ci        ERR_BAD_ARRAY_TYPE_BOUND,
89b1994897Sopenharmony_ci        ERR_UNDEFINED_TYPE,
90b1994897Sopenharmony_ci        ERR_MULTIPLE_DIRECTIVES,
91b1994897Sopenharmony_ci        ERR_INCORRECT_DIRECTIVE_LOCATION,
92b1994897Sopenharmony_ci        ERR_BAD_DIRECTIVE_DECLARATION,
93b1994897Sopenharmony_ci        ERR_UNKNOWN_LANGUAGE,
94b1994897Sopenharmony_ci        ERR_BAD_MNEMONIC_NAME,
95b1994897Sopenharmony_ci        ERR_REPEATING_FIELD_NAME,
96b1994897Sopenharmony_ci        ERR_FUNCTION_MULTIPLE_ALTERNATIVES,
97b1994897Sopenharmony_ci        ERR_BAD_SIGNATURE,
98b1994897Sopenharmony_ci        ERR_BAD_SIGNATURE_PARAMETERS,
99b1994897Sopenharmony_ci
100b1994897Sopenharmony_ci        // Warnings
101b1994897Sopenharmony_ci        WAR_UNEXPECTED_RETURN_TYPE,
102b1994897Sopenharmony_ci        WAR_UNEXPECTED_TYPE_ID,
103b1994897Sopenharmony_ci    };
104b1994897Sopenharmony_ci
105b1994897Sopenharmony_ci    ErrorClass type;
106b1994897Sopenharmony_ci    std::string whole_line;
107b1994897Sopenharmony_ci    size_t pos; /* positions to highlight the word */
108b1994897Sopenharmony_ci    size_t end;
109b1994897Sopenharmony_ci    ErrorType err;
110b1994897Sopenharmony_ci    std::string message;
111b1994897Sopenharmony_ci    std::string verbose;
112b1994897Sopenharmony_ci    size_t line_number;
113b1994897Sopenharmony_ci
114b1994897Sopenharmony_ci    inline Error() : Error("No messages", 0, ErrorType::ERR_NONE, "", 0, 0, "") {}
115b1994897Sopenharmony_ci
116b1994897Sopenharmony_ci    inline Error(std::string s, size_t line, ErrorType error_type, std::string overinfo, size_t p, size_t e,
117b1994897Sopenharmony_ci                 std::string buff, ErrorClass class_type = ErrorClass::ERROR)
118b1994897Sopenharmony_ci        : type(class_type),
119b1994897Sopenharmony_ci          whole_line(std::move(buff)),
120b1994897Sopenharmony_ci          pos(p),
121b1994897Sopenharmony_ci          end(e),
122b1994897Sopenharmony_ci          err(error_type),
123b1994897Sopenharmony_ci          message(std::move(s)),
124b1994897Sopenharmony_ci          verbose(std::move(overinfo)),
125b1994897Sopenharmony_ci          line_number(line)
126b1994897Sopenharmony_ci    {
127b1994897Sopenharmony_ci    }
128b1994897Sopenharmony_ci};
129b1994897Sopenharmony_ci
130b1994897Sopenharmony_ciusing ErrorList = std::vector<Error>;
131b1994897Sopenharmony_ci}  // namespace panda::pandasm
132b1994897Sopenharmony_ci
133b1994897Sopenharmony_ci#endif  // ASSEMBLER_ERROR_H
134