• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     CSTRING,  // "const char *"
33     STRING,  // "std::string"
34     STRING16, // "std::string16"
35     U16STRING, // "std::u16string"
36     FLOAT,   // "float"
37     DOUBLE,  // "double"
38     FD,      // "FileDescriptor"
39     FDSAN,      // "FileDescriptorSan"
40     ASHMEM,  // "Ashmem"
41     NATIVE_BUFFER, // "NativeBuffer"
42     POINTER, // "Pointer"
43     LIST,    // "List"
44     SET,    // "Set"
45     MAP,     // "Map"
46     ORDEREDMAP,     // "OrderedMap"
47     SMQ,     // "SharedMemQueue"
48     CHAR,    // "char"
49     UNSIGNED, // "unsigned"
50     SHAREDPTR,    // "sharedptr"
51     UNIQUEPTR,    // "uniqueptr"
52     SPTR,         // "sptr"
53     NULL_SHAREDPTR,    // "null_sharedptr"
54     NULL_UNIQUEPTR,    // "null_uniqueptr"
55     NULL_SPTR,         // "null_sptr"
56     // qualifier
57     // custom types
58     ENUM,   // "enum"
59     STRUCT, // "struct"
60     UNION,  // "union"
61     // keywords
62     PACKAGE,              // "package"
63     INTERFACE_TOKEN,      // "interface_token"
64     SUPPORT_DELEGATOR,    // "support_delegator"
65     OPTION_STUB_HOOKS,    // "option_stub_hooks"
66     OPTION_PARCEL_HOOKS,    // "option_parcel_hooks"
67     SEQ,                  // "sequenceable"
68     RAWDATA,              // "rawdata"
69     IMPORT,               // "import"
70     INTERFACE,            // "interface"
71     EXTENDS,              // "extends"
72     ONEWAY,               // "oneway"
73     CUSTOM_MSG_OPTION,    // "customMsgOption"
74     CALLBACK,             // "callback"
75     FREEZECONTROL,        // "freezecontrol"
76     FULL,                 // "full"
77     LITE,                 // "lite"
78     MINI,                 // "mini"
79     CACHEABLE,            // "cacheable"
80     IPCCODE,              // "ipccode"
81     IPC_IN_CAPACITY,      // "ipcincapacity"
82     IPC_OUT_CAPACITY,     // "ipcoutcapacity"
83     MACRODEF,             // "macrodef"
84     MACRONDEF,            // "macrondef"
85     IN,                   // "in"
86     OUT,                  // "out"
87     INOUT,                // "inout"
88     DOT,                  // "."
89     COMMA,                // ","
90     COLON,                // ":"
91     ASSIGN,               // "="
92     SEMICOLON,            // ";"
93     BRACES_LEFT,          // "{"
94     BRACES_RIGHT,         // "}"
95     BRACKETS_LEFT,        // "["
96     BRACKETS_RIGHT,       // "]"
97     PARENTHESES_LEFT,     // "("
98     PARENTHESES_RIGHT,    // ")"
99     ANGLE_BRACKETS_LEFT,  // "<"
100     ANGLE_BRACKETS_RIGHT, // ">"
101     ADD,                  // "+"
102     SUB,                  // "-"
103     STAR,                 // "*"
104     SLASH,                // "/"
105     PERCENT_SIGN,         // "%""
106     LEFT_SHIFT,           // "<<"
107     RIGHT_SHIFT,          // ">>"
108     AND,                  // "&"
109     XOR,                  // "^"
110     OR,                   // "|"
111     TILDE,                // "~"
112     PPLUS,                // "++"
113     MMINUS,               // "--"
114 
115     // others
116     ID,
117     NUM,
118     COMMENT_BLOCK,
119     COMMENT_LINE,
120     END_OF_FILE,
121 };
122 
123 struct Location {
124     std::string filePath;
125     size_t row;
126     size_t col;
127 };
128 
129 struct Token {
130     TokenType kind;
131     Location location;
132     std::string value;
133 
134     std::string Dump();
135 };
136 
137 struct TokenTypeCompare {
operatorTokenTypeCompare138     bool operator()(const Token &lhs, const Token &rhs) const
139     {
140         return lhs.kind > rhs.kind;
141     }
142 };
143 
144 std::string LocInfo(const Token &token);
145 } // namespace Idl
146 } // namespace OHOS
147 
148 #endif // OHOS_IDL_TOKEN_H