1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef OHOS_HDI_TOKEN_H 10 #define OHOS_HDI_TOKEN_H 11 12 #include <string> 13 14 namespace OHOS { 15 namespace HDI { 16 enum class TokenType { 17 UNKNOWN = 0, 18 // types 19 VOID, 20 BOOLEAN, // "boolean" 21 BYTE, // "byte" 22 SHORT, // "short" 23 INT, // "int" 24 LONG, // "long" 25 STRING, // "std::string" 26 FLOAT, // "float" 27 DOUBLE, // "double" 28 FD, // "FileDescriptor" 29 ASHMEM, // "Ashmem" 30 NATIVE_BUFFER, // "NativeBuffer" 31 POINTER, // "Pointer" 32 LIST, // "List" 33 MAP, // "Map" 34 SMQ, // "SharedMemQueue" 35 CHAR, // "char" 36 // qualifier 37 UNSIGNED, // "unsigned" 38 // custom types 39 ENUM, // "enum" 40 STRUCT, // "struct" 41 UNION, // "union" 42 // keywords 43 PACKAGE, // "package" 44 SEQ, // "sequenceable" 45 IMPORT, // "import" 46 INTERFACE, // "interface" 47 EXTENDS, // "extends" 48 ONEWAY, // "oneway" 49 CALLBACK, // "callback" 50 FULL, // "full" 51 LITE, // "lite" 52 MINI, // "mini" 53 IN, // "in" 54 OUT, // "out" 55 DOT, // "." 56 COMMA, // "," 57 COLON, // ":" 58 ASSIGN, // "=" 59 SEMICOLON, // ";" 60 BRACES_LEFT, // "{" 61 BRACES_RIGHT, // "}" 62 BRACKETS_LEFT, // "[" 63 BRACKETS_RIGHT, // "]" 64 PARENTHESES_LEFT, // "(" 65 PARENTHESES_RIGHT, // ")" 66 ANGLE_BRACKETS_LEFT, // "<" 67 ANGLE_BRACKETS_RIGHT, // ">" 68 ADD, // "+" 69 SUB, // "-" 70 STAR, // "*" 71 SLASH, // "/" 72 PERCENT_SIGN, // "%"" 73 LEFT_SHIFT, // "<<" 74 RIGHT_SHIFT, // ">>" 75 AND, // "&" 76 XOR, // "^" 77 OR, // "|" 78 TILDE, // "~" 79 PPLUS, // "++" 80 MMINUS, // "--" 81 82 // others 83 ID, 84 NUM, 85 COMMENT_BLOCK, 86 COMMENT_LINE, 87 END_OF_FILE, 88 }; 89 90 struct Location { 91 std::string filePath; 92 size_t row; 93 size_t col; 94 }; 95 96 struct Token { 97 TokenType kind; 98 Location location; 99 std::string value; 100 101 std::string Dump(); 102 }; 103 104 struct TokenTypeCompare { operatorTokenTypeCompare105 bool operator()(const Token &lhs, const Token &rhs) const 106 { 107 return lhs.kind > rhs.kind; 108 } 109 }; 110 111 std::string LocInfo(const Token &token); 112 } // namespace HDI 113 } // namespace OHOS 114 115 #endif // OHOS_HDI_TOKEN_H