Home | History | Annotate | Download | only in aidl
      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     // 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 
     65 enum {
     66     PARCELABLE_TYPE = 12,
     67     INTERFACE_TYPE
     68 };
     69 
     70 typedef struct document_item_type {
     71     unsigned item_type;
     72     struct document_item_type* next;
     73 } document_item_type;
     74 
     75 typedef struct parcelable_type {
     76     document_item_type document_item;
     77     buffer_type parcelable_token;
     78     char* package;
     79     buffer_type name;
     80     buffer_type semicolon_token;
     81 } parcelable_type;
     82 
     83 typedef struct interface_type {
     84     document_item_type document_item;
     85     buffer_type interface_token;
     86     bool oneway;
     87     buffer_type oneway_token;
     88     char* package;
     89     buffer_type name;
     90     buffer_type open_brace_token;
     91     interface_item_type* interface_items;
     92     buffer_type close_brace_token;
     93     buffer_type* comments_token; // points into this structure, DO NOT DELETE
     94 } interface_type;
     95 
     96 typedef union lexer_type {
     97     buffer_type buffer;
     98     type_type type;
     99     arg_type *arg;
    100     method_type* method;
    101     interface_item_type* interface_item;
    102     interface_type* interface_obj;
    103     parcelable_type* parcelable;
    104     document_item_type* document_item;
    105 } lexer_type;
    106 
    107 
    108 #define YYSTYPE lexer_type
    109 
    110 #if __cplusplus
    111 extern "C" {
    112 #endif
    113 
    114 int parse_aidl(char const *);
    115 
    116 // strips off the leading whitespace, the "import" text
    117 // also returns whether it's a local or system import
    118 // we rely on the input matching the import regex from below
    119 char* parse_import_statement(const char* text);
    120 
    121 // in, out or inout
    122 enum {
    123     IN_PARAMETER = 1,
    124     OUT_PARAMETER = 2,
    125     INOUT_PARAMETER = 3
    126 };
    127 int convert_direction(const char* direction);
    128 
    129 // callbacks from within the parser
    130 // these functions all take ownership of the strings
    131 typedef struct ParserCallbacks {
    132     void (*document)(document_item_type* items);
    133     void (*import)(buffer_type* statement);
    134 } ParserCallbacks;
    135 
    136 extern ParserCallbacks* g_callbacks;
    137 
    138 // true if there was an error parsing, false otherwise
    139 extern int g_error;
    140 
    141 // the name of the file we're currently parsing
    142 extern char const* g_currentFilename;
    143 
    144 // the package name for our current file
    145 extern char const* g_currentPackage;
    146 
    147 typedef enum {
    148     STATEMENT_INSIDE_INTERFACE
    149 } error_type;
    150 
    151 void init_buffer_type(buffer_type* buf, int lineno);
    152 
    153 
    154 #if __cplusplus
    155 }
    156 #endif
    157 
    158 
    159 #endif // DEVICE_TOOLS_AIDL_AIDL_LANGUAGE_H
    160