blob: a24bfd33add580c5cdf198d466d510635bd80366 [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() {
Jason Sams20087472011-05-06 14:14:30 -070024 VarType *baseType = currType;
25 int curPtrLevel = 0;
26 while (curPtrLevel < baseType->ptrLevel) {
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -070027 currType = &apis[apiCount].params[apis[apiCount].paramCount];
28 currType->type = 4;
Jason Sams20087472011-05-06 14:14:30 -070029 currType->ptrLevel = curPtrLevel;
30 if (currType->ptrLevel > 0) {
31 currType->isConst = 1;
32 }
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -070033 sprintf(currType->typeName, "%s", "size_t");
Jason Sams20087472011-05-06 14:14:30 -070034 switch(baseType->ptrLevel - curPtrLevel) {
35 case 1:
36 sprintf(currType->name, "%s_length", baseType->name);
37 break;
38 case 2:
39 sprintf(currType->name, "%s_length_length", baseType->name);
40 break;
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -070041 }
42 apis[apiCount].paramCount++;
Jason Sams20087472011-05-06 14:14:30 -070043 curPtrLevel ++;
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -070044 }
45 }
46
Joe Onorato84614dd2009-08-10 15:01:51 -070047 extern "C" int yylex();
48
Jason Sams326e0dd2009-05-22 14:03:28 -070049%%
50
51"/*" BEGIN(comment);
52<comment>[^*\n]* /* eat anything that's not a '*' */
53<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
54<comment>\n ++num_lines;
55<comment>"*"+"/" BEGIN(INITIAL);
56
57<*>" " //printf("found ' '\n");
Jason Sams186e5912011-04-26 14:50:00 -070058<*>"\t" //printf("found ' '\n");
Jason Sams326e0dd2009-05-22 14:03:28 -070059<*>"\n" ++num_lines; //printf("found lf \n");
60
61{ID} {
62 memset(&apis[apiCount], 0, sizeof(ApiEntry));
63 memcpy(apis[apiCount].name, yytext, yyleng);
64 BEGIN(api_entry);
65 }
66
67<api_entry>"{" {
68 BEGIN(api_entry2);
69 }
70
71<api_entry2>"sync" {
72 apis[apiCount].sync = 1;
73 }
74
Jason Sams9397e302009-08-27 20:23:34 -070075<api_entry2>"handcodeApi" {
76 apis[apiCount].handcodeApi = 1;
77 }
78
Jason Sams186e5912011-04-26 14:50:00 -070079<api_entry2>"direct" {
80 apis[apiCount].direct = 1;
81 }
82
83<api_entry2>"nocontext" {
84 apis[apiCount].nocontext = 1;
Jason Sams9397e302009-08-27 20:23:34 -070085 }
86
Jason Sams326e0dd2009-05-22 14:03:28 -070087<api_entry2>"ret" {
88 currType = &apis[apiCount].ret;
89 typeNextState = api_entry2;
90 BEGIN(var_type);
91 }
92
93<api_entry2>"param" {
94 currType = &apis[apiCount].params[apis[apiCount].paramCount];
95 apis[apiCount].paramCount++;
96 typeNextState = api_entry_param;
97 BEGIN(var_type);
98 }
99
100<var_type>"const" {
101 currType->isConst = 1;
102 }
103
104<var_type>"i8" {
105 currType->type = 1;
106 currType->bits = 8;
107 BEGIN(typeNextState);
108 }
109
110<var_type>"i16" {
111 currType->type = 1;
112 currType->bits = 16;
113 BEGIN(typeNextState);
114 }
115
116<var_type>"i32" {
117 currType->type = 1;
118 currType->bits = 32;
119 BEGIN(typeNextState);
120 }
121
122<var_type>"i64" {
123 currType->type = 1;
124 currType->bits = 64;
125 BEGIN(typeNextState);
126 }
127
128<var_type>"u8" {
129 currType->type = 2;
130 currType->bits = 8;
131 BEGIN(typeNextState);
132 }
133
134<var_type>"u16" {
135 currType->type = 2;
136 currType->bits = 16;
137 BEGIN(typeNextState);
138 }
139
140<var_type>"u32" {
141 currType->type = 2;
142 currType->bits = 32;
143 BEGIN(typeNextState);
144 }
145
146<var_type>"u64" {
147 currType->type = 2;
148 currType->bits = 64;
149 BEGIN(typeNextState);
150 }
151
152<var_type>"f" {
153 currType->type = 3;
154 currType->bits = 32;
155 BEGIN(typeNextState);
156 }
157
158<var_type>"d" {
159 currType->type = 3;
160 currType->bits = 64;
161 BEGIN(typeNextState);
162 }
163
164<var_type>{ID} {
165 currType->type = 4;
166 currType->bits = 32;
Joe Onorato84614dd2009-08-10 15:01:51 -0700167 memcpy(currType->typeName, yytext, yyleng);
Jason Sams326e0dd2009-05-22 14:03:28 -0700168 BEGIN(typeNextState);
169 }
170
171<api_entry_param>"*" {
172 currType->ptrLevel ++;
173 }
174
175<api_entry_param>{ID} {
176 memcpy(currType->name, yytext, yyleng);
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700177 checkPointerType();
Jason Sams326e0dd2009-05-22 14:03:28 -0700178 BEGIN(api_entry2);
179 }
180
Jason Samsa2cf7552010-03-03 13:03:18 -0800181<api_entry2>"*" {
182 currType->ptrLevel ++;
183 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700184
185<api_entry2>"}" {
186 apiCount++;
187 BEGIN(INITIAL);
188 }
189
190
191%%
192
193
194int yywrap()
195{
196 return 1;
197}
198