hidl-gen_l.ll revision 3179b22facb8720726e98ae70968df47e2a115d7
1D			[0-9]
2L			[a-zA-Z_]
3H			[a-fA-F0-9]
4E			[Ee][+-]?{D}+
5FS			(f|F|l|L)
6IS			(u|U|l|L)*
7
8COMPONENT               {L}({L}|{D})*
9DOT                     [.]
10PATH                    {COMPONENT}({DOT}{COMPONENT})*
11AT                      [@]
12VERSION                 {AT}{D}+{DOT}{D}+
13
14%{
15
16#include "Annotation.h"
17#include "AST.h"
18#include "CompoundType.h"
19#include "EnumType.h"
20#include "HandleType.h"
21#include "Method.h"
22#include "ScalarType.h"
23#include "StringType.h"
24
25#include "hidl-gen_y.h"
26
27#include <assert.h>
28
29using namespace android;
30
31void count(struct yyguts_t *yyg);
32void comment(yyscan_t yyscanner, struct yyguts_t *yyg);
33int check_type(yyscan_t yyscanner, struct yyguts_t *yyg);
34
35#define SCALAR_TYPE(kind)                                       \
36    do {                                                        \
37        count(yyg);                                             \
38        yylval->type = new ScalarType(ScalarType::kind);        \
39        return SCALAR;                                        \
40    } while (0)
41
42%}
43
44%option reentrant
45%option bison-bridge
46%option extra-type="android::AST *"
47
48%%
49
50"/*"			{ comment(yyscanner, yyg); }
51"//"[^\r\n]*            { /* skip C++ style comment */ }
52
53"const"			{ count(yyg); return(CONST); }
54"enum"			{ count(yyg); return(ENUM); }
55"extends"		{ count(yyg); return(EXTENDS); }
56"generates"		{ count(yyg); return(GENERATES); }
57"import"		{ count(yyg); return(IMPORT); }
58"interface"		{ count(yyg); return(INTERFACE); }
59"package"		{ count(yyg); return(PACKAGE); }
60"struct"		{ count(yyg); return(STRUCT); }
61"typedef"		{ count(yyg); return(TYPEDEF); }
62"union"			{ count(yyg); return(UNION); }
63"vec"			{ count(yyg); return(VEC); }
64"oneway"		{ count(yyg); return(ONEWAY); }
65
66"bool"			{ SCALAR_TYPE(KIND_BOOL); }
67"opaque"		{ SCALAR_TYPE(KIND_OPAQUE); }
68"int8_t"		{ SCALAR_TYPE(KIND_INT8); }
69"uint8_t"		{ SCALAR_TYPE(KIND_UINT8); }
70"int16_t"		{ SCALAR_TYPE(KIND_INT16); }
71"uint16_t"		{ SCALAR_TYPE(KIND_UINT16); }
72"int32_t"		{ SCALAR_TYPE(KIND_INT32); }
73"uint32_t"		{ SCALAR_TYPE(KIND_UINT32); }
74"int64_t"		{ SCALAR_TYPE(KIND_INT64); }
75"uint64_t"		{ SCALAR_TYPE(KIND_UINT64); }
76"float"			{ SCALAR_TYPE(KIND_FLOAT); }
77"double"		{ SCALAR_TYPE(KIND_DOUBLE); }
78
79"handle"		{ count(yyg); yylval->type = new HandleType; return SCALAR; }
80"string"		{ count(yyg); yylval->type = new StringType; return SCALAR; }
81
82"("			{ count(yyg); return('('); }
83")"			{ count(yyg); return(')'); }
84"<"			{ count(yyg); return('<'); }
85">"			{ count(yyg); return('>'); }
86"{"			{ count(yyg); return('{'); }
87"}"			{ count(yyg); return('}'); }
88"["			{ count(yyg); return('['); }
89"]"			{ count(yyg); return(']'); }
90":"			{ count(yyg); return(':'); }
91";"			{ count(yyg); return(';'); }
92","			{ count(yyg); return(','); }
93"."			{ count(yyg); return('.'); }
94"="			{ count(yyg); return('='); }
95"+"			{ count(yyg); return('+'); }
96"@"			{ count(yyg); return('@'); }
97
98{PATH}{VERSION}?"::"{PATH}      { count(yyg); yylval->str = strdup(yytext); return FQNAME; }
99{VERSION}"::"{PATH}             { count(yyg); yylval->str = strdup(yytext); return FQNAME; }
100{PATH}{VERSION}                 { count(yyg); yylval->str = strdup(yytext); return FQNAME; }
101{COMPONENT}({DOT}{COMPONENT})+  { count(yyg); yylval->str = strdup(yytext); return FQNAME; }
102{COMPONENT}                     { count(yyg); yylval->str = strdup(yytext); return IDENTIFIER; }
103
1040[xX]{H}+{IS}?		{ count(yyg); yylval->str = strdup(yytext); return(INTEGER); }
1050{D}+{IS}?		{ count(yyg); yylval->str = strdup(yytext); return(INTEGER); }
106{D}+{IS}?		{ count(yyg); yylval->str = strdup(yytext); return(INTEGER); }
107L?\"(\\.|[^\\"])*\"	{ count(yyg); yylval->str = strdup(yytext); return(STRING_LITERAL); }
108
109[ \t\v\n\f]		{ count(yyg); }
110.			{ /* ignore bad characters */ }
111
112%%
113
114int yywrap(yyscan_t) {
115    return 1;
116}
117
118void comment(yyscan_t yyscanner, yyguts_t *yyg) {
119    char c, c1;
120
121loop:
122    while ((c = yyinput(yyscanner)) != '*' && c != 0)
123        putchar(c);
124
125    if ((c1 = yyinput(yyscanner)) != '/' && c != 0)
126    {
127        unput(c1);
128        goto loop;
129    }
130
131    if (c != 0) {
132        putchar(c1);
133    }
134}
135
136
137int column = 0;
138
139void count(yyguts_t *yyg) {
140    int i;
141
142    for (i = 0; yytext[i] != '\0'; i++)
143        if (yytext[i] == '\n')
144            column = 0;
145        else if (yytext[i] == '\t')
146            column += 8 - (column % 8);
147        else
148            column++;
149
150    ECHO;
151}
152
153status_t parseFile(AST *ast, const char *path) {
154    FILE *file = fopen(path, "rb");
155
156    if (file == NULL) {
157        return -errno;
158    }
159
160    yyscan_t scanner;
161    yylex_init_extra(ast, &scanner);
162    ast->setScanner(scanner);
163
164    yyset_in(file, scanner);
165    int res = yyparse(ast);
166
167    yylex_destroy(scanner);
168    ast->setScanner(NULL);
169
170    fclose(file);
171    file = NULL;
172
173    if (res != 0) {
174        return UNKNOWN_ERROR;
175    }
176
177    return OK;
178}
179