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