blob: dcd4435963c06ac3b97dbea14d391cb7e2ff9ff7 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001%option stack
2
3%x comment
4%x api_entry
5%x api_entry2
6%x api_entry_param
7%x var_type
8
9DIGIT [0-9]
10ID [a-zA-Z_][a-zA-Z0-9_]*
11
Joe Onorato84614dd2009-08-10 15:01:51 -070012 #include "spec.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070013
14 int num_lines = 0;
15
Jason Sams326e0dd2009-05-22 14:03:28 -070016 VarType *currType = 0;
17
Jason Sams326e0dd2009-05-22 14:03:28 -070018 ApiEntry apis[128];
19 int apiCount = 0;
20
21 int typeNextState;
22
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -070023 void checkPointerType() {
24 VarType *lastType = currType;
25 if (lastType->ptrLevel) {
26 currType = &apis[apiCount].params[apis[apiCount].paramCount];
27 currType->type = 4;
28 sprintf(currType->typeName, "%s", "size_t");
29 if (lastType->name[0]) {
30 sprintf(currType->name, "%s_length", lastType->name);
31 }
32 apis[apiCount].paramCount++;
33 }
34 }
35
Joe Onorato84614dd2009-08-10 15:01:51 -070036 extern "C" int yylex();
37
Jason Sams326e0dd2009-05-22 14:03:28 -070038%%
39
40"/*" BEGIN(comment);
41<comment>[^*\n]* /* eat anything that's not a '*' */
42<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
43<comment>\n ++num_lines;
44<comment>"*"+"/" BEGIN(INITIAL);
45
46<*>" " //printf("found ' '\n");
Jason Sams186e5912011-04-26 14:50:00 -070047<*>"\t" //printf("found ' '\n");
Jason Sams326e0dd2009-05-22 14:03:28 -070048<*>"\n" ++num_lines; //printf("found lf \n");
49
50{ID} {
51 memset(&apis[apiCount], 0, sizeof(ApiEntry));
52 memcpy(apis[apiCount].name, yytext, yyleng);
53 BEGIN(api_entry);
54 }
55
56<api_entry>"{" {
57 BEGIN(api_entry2);
58 }
59
60<api_entry2>"sync" {
61 apis[apiCount].sync = 1;
62 }
63
Jason Sams9397e302009-08-27 20:23:34 -070064<api_entry2>"handcodeApi" {
65 apis[apiCount].handcodeApi = 1;
66 }
67
Jason Sams186e5912011-04-26 14:50:00 -070068<api_entry2>"direct" {
69 apis[apiCount].direct = 1;
70 }
71
72<api_entry2>"nocontext" {
73 apis[apiCount].nocontext = 1;
Jason Sams9397e302009-08-27 20:23:34 -070074 }
75
Jason Sams326e0dd2009-05-22 14:03:28 -070076<api_entry2>"ret" {
77 currType = &apis[apiCount].ret;
78 typeNextState = api_entry2;
79 BEGIN(var_type);
80 }
81
82<api_entry2>"param" {
83 currType = &apis[apiCount].params[apis[apiCount].paramCount];
84 apis[apiCount].paramCount++;
85 typeNextState = api_entry_param;
86 BEGIN(var_type);
87 }
88
89<var_type>"const" {
90 currType->isConst = 1;
91 }
92
93<var_type>"i8" {
94 currType->type = 1;
95 currType->bits = 8;
96 BEGIN(typeNextState);
97 }
98
99<var_type>"i16" {
100 currType->type = 1;
101 currType->bits = 16;
102 BEGIN(typeNextState);
103 }
104
105<var_type>"i32" {
106 currType->type = 1;
107 currType->bits = 32;
108 BEGIN(typeNextState);
109 }
110
111<var_type>"i64" {
112 currType->type = 1;
113 currType->bits = 64;
114 BEGIN(typeNextState);
115 }
116
117<var_type>"u8" {
118 currType->type = 2;
119 currType->bits = 8;
120 BEGIN(typeNextState);
121 }
122
123<var_type>"u16" {
124 currType->type = 2;
125 currType->bits = 16;
126 BEGIN(typeNextState);
127 }
128
129<var_type>"u32" {
130 currType->type = 2;
131 currType->bits = 32;
132 BEGIN(typeNextState);
133 }
134
135<var_type>"u64" {
136 currType->type = 2;
137 currType->bits = 64;
138 BEGIN(typeNextState);
139 }
140
141<var_type>"f" {
142 currType->type = 3;
143 currType->bits = 32;
144 BEGIN(typeNextState);
145 }
146
147<var_type>"d" {
148 currType->type = 3;
149 currType->bits = 64;
150 BEGIN(typeNextState);
151 }
152
153<var_type>{ID} {
154 currType->type = 4;
155 currType->bits = 32;
Joe Onorato84614dd2009-08-10 15:01:51 -0700156 memcpy(currType->typeName, yytext, yyleng);
Jason Sams326e0dd2009-05-22 14:03:28 -0700157 BEGIN(typeNextState);
158 }
159
160<api_entry_param>"*" {
161 currType->ptrLevel ++;
162 }
163
164<api_entry_param>{ID} {
165 memcpy(currType->name, yytext, yyleng);
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700166 checkPointerType();
Jason Sams326e0dd2009-05-22 14:03:28 -0700167 BEGIN(api_entry2);
168 }
169
Jason Samsa2cf7552010-03-03 13:03:18 -0800170<api_entry2>"*" {
171 currType->ptrLevel ++;
172 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700173
174<api_entry2>"}" {
175 apiCount++;
176 BEGIN(INITIAL);
177 }
178
179
180%%
181
182
183int yywrap()
184{
185 return 1;
186}
187