1#ifndef DEVICE_TOOLS_AIDL_AIDL_LANGUAGE_H
2#define DEVICE_TOOLS_AIDL_AIDL_LANGUAGE_H
3
4
5typedef enum {
6    NO_EXTRA_TEXT = 0,
7    SHORT_COMMENT,
8    LONG_COMMENT,
9    COPY_TEXT,
10    WHITESPACE
11} which_extra_text;
12
13typedef struct extra_text_type {
14    unsigned lineno;
15    which_extra_text which;
16    char* data;
17    unsigned len;
18    struct extra_text_type* next;
19} extra_text_type;
20
21typedef struct buffer_type {
22    unsigned lineno;
23    unsigned token;
24    char *data;
25    extra_text_type* extra;
26} buffer_type;
27
28typedef struct type_type {
29    buffer_type type;
30    buffer_type array_token;
31    int dimension;
32} type_type;
33
34typedef struct arg_type {
35    buffer_type comma_token; // empty in the first one in the list
36    buffer_type direction;
37    type_type type;
38    buffer_type name;
39    struct arg_type *next;
40} arg_type;
41
42enum {
43    METHOD_TYPE
44};
45
46typedef struct interface_item_type {
47    unsigned item_type;
48    struct interface_item_type* next;
49} interface_item_type;
50
51typedef struct method_type {
52    interface_item_type interface_item;
53    type_type type;
54    bool oneway;
55    buffer_type oneway_token;
56    buffer_type name;
57    buffer_type open_paren_token;
58    arg_type* args;
59    buffer_type close_paren_token;
60    // XXX missing comments/copy text here
61    buffer_type semicolon_token;
62    buffer_type* comments_token; // points into this structure, DO NOT DELETE
63} method_type;
64
65enum {
66    USER_DATA_TYPE = 12,
67    INTERFACE_TYPE_BINDER,
68    INTERFACE_TYPE_RPC
69};
70
71typedef struct document_item_type {
72    unsigned item_type;
73    struct document_item_type* next;
74} document_item_type;
75
76
77// for user_data_type.flattening_methods
78enum {
79    PARCELABLE_DATA = 0x1,
80    RPC_DATA = 0x2
81};
82
83typedef struct user_data_type {
84    document_item_type document_item;
85    buffer_type keyword_token; // only the first one
86    char* package;
87    buffer_type name;
88    buffer_type semicolon_token;
89    int flattening_methods;
90} user_data_type;
91
92typedef struct interface_type {
93    document_item_type document_item;
94    buffer_type interface_token;
95    bool oneway;
96    buffer_type oneway_token;
97    char* package;
98    buffer_type name;
99    buffer_type open_brace_token;
100    interface_item_type* interface_items;
101    buffer_type close_brace_token;
102    buffer_type* comments_token; // points into this structure, DO NOT DELETE
103} interface_type;
104
105typedef union lexer_type {
106    buffer_type buffer;
107    type_type type;
108    arg_type *arg;
109    method_type* method;
110    interface_item_type* interface_item;
111    interface_type* interface_obj;
112    user_data_type* user_data;
113    document_item_type* document_item;
114} lexer_type;
115
116
117#define YYSTYPE lexer_type
118
119#if __cplusplus
120extern "C" {
121#endif
122
123int parse_aidl(char const *);
124
125// strips off the leading whitespace, the "import" text
126// also returns whether it's a local or system import
127// we rely on the input matching the import regex from below
128char* parse_import_statement(const char* text);
129
130// in, out or inout
131enum {
132    IN_PARAMETER = 1,
133    OUT_PARAMETER = 2,
134    INOUT_PARAMETER = 3
135};
136int convert_direction(const char* direction);
137
138// callbacks from within the parser
139// these functions all take ownership of the strings
140typedef struct ParserCallbacks {
141    void (*document)(document_item_type* items);
142    void (*import)(buffer_type* statement);
143} ParserCallbacks;
144
145extern ParserCallbacks* g_callbacks;
146
147// true if there was an error parsing, false otherwise
148extern int g_error;
149
150// the name of the file we're currently parsing
151extern char const* g_currentFilename;
152
153// the package name for our current file
154extern char const* g_currentPackage;
155
156typedef enum {
157    STATEMENT_INSIDE_INTERFACE
158} error_type;
159
160void init_buffer_type(buffer_type* buf, int lineno);
161
162
163#if __cplusplus
164}
165#endif
166
167
168#endif // DEVICE_TOOLS_AIDL_AIDL_LANGUAGE_H
169