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     SMQ,     // "SharedMemQueue"
43     CHAR,    // "char"
44     // qualifier
45     UNSIGNED, // "unsigned"
46     // custom types
47     ENUM,   // "enum"
48     STRUCT, // "struct"
49     UNION,  // "union"
50     // keywords
51     PACKAGE,              // "package"
52     INTERFACE_TOKEN,      // "interface_token"
53     SUPPORT_DELEGATOR,    // "support_delegator"
54     SEQ,                  // "sequenceable"
55     IMPORT,               // "import"
56     INTERFACE,            // "interface"
57     EXTENDS,              // "extends"
58     ONEWAY,               // "oneway"
59     CALLBACK,             // "callback"
60     FREEZECONTROL,        // "freezecontrol"
61     FULL,                 // "full"
62     LITE,                 // "lite"
63     MINI,                 // "mini"
64     CACHEABLE,            // "cacheable"
65     IN,                   // "in"
66     OUT,                  // "out"
67     INOUT,                // "inout"
68     DOT,                  // "."
69     COMMA,                // ","
70     COLON,                // ":"
71     ASSIGN,               // "="
72     SEMICOLON,            // ";"
73     BRACES_LEFT,          // "{"
74     BRACES_RIGHT,         // "}"
75     BRACKETS_LEFT,        // "["
76     BRACKETS_RIGHT,       // "]"
77     PARENTHESES_LEFT,     // "("
78     PARENTHESES_RIGHT,    // ")"
79     ANGLE_BRACKETS_LEFT,  // "<"
80     ANGLE_BRACKETS_RIGHT, // ">"
81     ADD,                  // "+"
82     SUB,                  // "-"
83     STAR,                 // "*"
84     SLASH,                // "/"
85     PERCENT_SIGN,         // "%""
86     LEFT_SHIFT,           // "<<"
87     RIGHT_SHIFT,          // ">>"
88     AND,                  // "&"
89     XOR,                  // "^"
90     OR,                   // "|"
91     TILDE,                // "~"
92     PPLUS,                // "++"
93     MMINUS,               // "--"
94 
95     // others
96     ID,
97     NUM,
98     COMMENT_BLOCK,
99     COMMENT_LINE,
100     END_OF_FILE,
101 };
102 
103 struct Location {
104     std::string filePath;
105     size_t row;
106     size_t col;
107 };
108 
109 struct Token {
110     TokenType kind;
111     Location location;
112     std::string value;
113 
114     std::string Dump();
115 };
116 
117 struct TokenTypeCompare {
operatorTokenTypeCompare118     bool operator()(const Token &lhs, const Token &rhs) const
119     {
120         return lhs.kind > rhs.kind;
121     }
122 };
123 
124 std::string LocInfo(const Token &token);
125 } // namespace Idl
126 } // namespace OHOS
127 
128 #endif // OHOS_IDL_TOKEN_H