1 /* 2 * Copyright (c) 2024 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 OHOS_IDL_TOKEN_H 17 #define OHOS_IDL_TOKEN_H 18 19 #include <string> 20 21 namespace OHOS { 22 namespace Idl { 23 enum class TokenType { 24 UNKNOWN = 0, 25 // types 26 VOID, // "void" 27 BOOLEAN, // "boolean" 28 BYTE, // "byte" 29 SHORT, // "short" 30 INT, // "int" 31 LONG, // "long" 32 STRING, // "std::string" 33 STRING16, // "std::string16" 34 FLOAT, // "float" 35 DOUBLE, // "double" 36 FD, // "FileDescriptor" 37 ASHMEM, // "Ashmem" 38 NATIVE_BUFFER, // "NativeBuffer" 39 POINTER, // "Pointer" 40 LIST, // "List" 41 MAP, // "Map" 42 ORDEREDMAP, // "OrderedMap" 43 SMQ, // "SharedMemQueue" 44 CHAR, // "char" 45 // qualifier 46 UNSIGNED, // "unsigned" 47 // custom types 48 ENUM, // "enum" 49 STRUCT, // "struct" 50 UNION, // "union" 51 // keywords 52 PACKAGE, // "package" 53 INTERFACE_TOKEN, // "interface_token" 54 SUPPORT_DELEGATOR, // "support_delegator" 55 OPTION_STUB_HOOKS, // "option_stub_hooks" 56 OPTION_PARCEL_HOOKS, // "option_parcel_hooks" 57 SEQ, // "sequenceable" 58 RAWDATA, // "rawdata" 59 IMPORT, // "import" 60 INTERFACE, // "interface" 61 EXTENDS, // "extends" 62 ONEWAY, // "oneway" 63 CUSTOM_MSG_OPTION, // "customMsgOption" 64 CALLBACK, // "callback" 65 FREEZECONTROL, // "freezecontrol" 66 FULL, // "full" 67 LITE, // "lite" 68 MINI, // "mini" 69 CACHEABLE, // "cacheable" 70 IPCCODE, // "ipccode" 71 IPC_IN_CAPACITY, // "ipcincapacity" 72 IPC_OUT_CAPACITY, // "ipcoutcapacity" 73 MACRODEF, // "macrodef" 74 MACRONDEF, // "macrondef" 75 IN, // "in" 76 OUT, // "out" 77 INOUT, // "inout" 78 DOT, // "." 79 COMMA, // "," 80 COLON, // ":" 81 ASSIGN, // "=" 82 SEMICOLON, // ";" 83 BRACES_LEFT, // "{" 84 BRACES_RIGHT, // "}" 85 BRACKETS_LEFT, // "[" 86 BRACKETS_RIGHT, // "]" 87 PARENTHESES_LEFT, // "(" 88 PARENTHESES_RIGHT, // ")" 89 ANGLE_BRACKETS_LEFT, // "<" 90 ANGLE_BRACKETS_RIGHT, // ">" 91 ADD, // "+" 92 SUB, // "-" 93 STAR, // "*" 94 SLASH, // "/" 95 PERCENT_SIGN, // "%"" 96 LEFT_SHIFT, // "<<" 97 RIGHT_SHIFT, // ">>" 98 AND, // "&" 99 XOR, // "^" 100 OR, // "|" 101 TILDE, // "~" 102 PPLUS, // "++" 103 MMINUS, // "--" 104 105 // others 106 ID, 107 NUM, 108 COMMENT_BLOCK, 109 COMMENT_LINE, 110 END_OF_FILE, 111 }; 112 113 struct Location { 114 std::string filePath; 115 size_t row; 116 size_t col; 117 }; 118 119 struct Token { 120 TokenType kind; 121 Location location; 122 std::string value; 123 124 std::string Dump(); 125 }; 126 127 struct TokenTypeCompare { operatorTokenTypeCompare128 bool operator()(const Token &lhs, const Token &rhs) const 129 { 130 return lhs.kind > rhs.kind; 131 } 132 }; 133 134 std::string LocInfo(const Token &token); 135 } // namespace Idl 136 } // namespace OHOS 137 138 #endif // OHOS_IDL_TOKEN_H