Skip to content

Commit 0c614e0

Browse files
author
Noam Preil
committed
fin
1 parent 2d74e3d commit 0c614e0

68 files changed

Lines changed: 16028 additions & 9212 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/SDCC.lex

Lines changed: 49 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ UTF8IDF {UTF8IDF1ST}|\xcc[\x80-\xbf]|\xcd[\x80-\xaf]|\xe2\x83[\x90-\xbf]
7171
# include <io.h>
7272
#endif
7373

74-
#define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\
74+
#define TKEYWORD(token) return (isTargetKeyword(yytext) ? (token) :\
7575
check_type())
7676

77-
#define TKEYWORD99(token) return (options.std_c99 ? token : check_type())
77+
#define TKEYWORD99(token) return (options.std_c99 ? (token) : check_type())
78+
79+
#define TKEYWORD2X(token) return (options.std_c2x ? (token) : check_type())
7880

7981
int column = 0; /* current column */
8082

@@ -92,7 +94,6 @@ static void count (void);
9294
static void count_char (int);
9395
static int process_pragma (const char *);
9496
static int check_type (void);
95-
static int isTargetKeyword (const char *s);
9697
static void checkCurrFile (const char *s);
9798
%}
9899

@@ -124,6 +125,7 @@ static void checkCurrFile (const char *s);
124125
"__at" { count (); TKEYWORD (AT); }
125126
"auto" { count (); return AUTO; }
126127
"__bit" { count (); TKEYWORD (BIT); }
128+
"bool" { count (); TKEYWORD2X (SD_BOOL); }
127129
"_Bool" { count (); TKEYWORD99 (SD_BOOL); }
128130
"break" { count (); return BREAK; }
129131
"case" { count (); return CASE; }
@@ -152,10 +154,10 @@ static void checkCurrFile (const char *s);
152154
"__interrupt" { count (); TKEYWORD (INTERRUPT); }
153155
"__nonbanked" { count (); TKEYWORD (NONBANKED); }
154156
"__banked" { count (); TKEYWORD (BANKED); }
157+
"__trap" { count (); TKEYWORD (TRAP); }
155158
"long" { count (); return SD_LONG; }
156159
"__near" { count (); TKEYWORD (DATA); }
157160
"__pdata" { count (); TKEYWORD (PDATA); }
158-
"__reentrant" { count (); TKEYWORD (REENTRANT); }
159161
"__shadowregs" { count (); TKEYWORD (SHADOWREGS); }
160162
"__wparam" { count (); TKEYWORD (SD_WPARAM); }
161163
"register" { count (); return REGISTER; }
@@ -167,12 +169,14 @@ static void checkCurrFile (const char *s);
167169
"short" { count (); return SD_SHORT; }
168170
"signed" { count (); return SIGNED; }
169171
"sizeof" { count (); return SIZEOF; }
172+
"alignof" { count (); TKEYWORD2X (ALIGNOF); }
170173
"_Alignof" { count (); return ALIGNOF; }
171174
"__builtin_offsetof" { count (); return OFFSETOF; }
172175
"__sram" { count (); TKEYWORD (XDATA); }
173176
"static" { count (); return STATIC; }
174177
"struct" { count (); return STRUCT; }
175178
"switch" { count (); return SWITCH; }
179+
"_Thread_local" { count (); return THREAD_LOCAL; }
176180
"typedef" { count (); return TYPEDEF; }
177181
"union" { count (); return UNION; }
178182
"unsigned" { count (); return UNSIGNED; }
@@ -189,10 +193,18 @@ static void checkCurrFile (const char *s);
189193
"inline" { count (); TKEYWORD99 (INLINE); }
190194
"_Noreturn" { count (); return NORETURN;}
191195
"restrict" { count (); TKEYWORD99 (RESTRICT); }
192-
"__smallc" { count (); return SMALLC; }
196+
"__smallc" { count (); TKEYWORD (SMALLC); }
197+
"__preserves_regs" { count (); return PRESERVES_REGS; }
198+
"__z88dk_fastcall" { count (); TKEYWORD (Z88DK_FASTCALL); }
199+
"__z88dk_callee" { count (); TKEYWORD (Z88DK_CALLEE); }
200+
"__z88dk_shortcall" { count (); return Z88DK_SHORTCALL; }
201+
"__z88dk_params_offset" { count (); return Z88DK_PARAMS_OFFSET; }
193202
"__addressmod" { count (); return ADDRESSMOD; }
203+
"static_assert" { count (); TKEYWORD2X (STATIC_ASSERT); }
194204
"_Static_assert" { count (); return STATIC_ASSERT; }
205+
"alignas" { count (); TKEYWORD2X (ALIGNAS); }
195206
"_Alignas" { count (); return ALIGNAS; }
207+
"_Generic" { count (); return GENERIC; }
196208
({L}|{UCN}|{UTF8IDF1ST})({L}|{D}|{UCN}|{UTF8IDF})* {
197209
if (!options.dollars_in_ident && strchr (yytext, '$'))
198210
{
@@ -213,21 +225,22 @@ static void checkCurrFile (const char *s);
213225
return check_type();
214226
}
215227
0[bB]{B}+{IS}? {
216-
if (!options.std_sdcc)
217-
{
218-
yyerror ("binary (0b) constants are not allowed in ISO C");
219-
}
228+
if (!options.std_sdcc && !options.std_c2x)
229+
werror (W_BINARY_INTEGER_CONSTANT_C23);
220230
count ();
221-
yylval.val = constVal (yytext);
231+
yylval.val = constIntVal (yytext);
222232
return CONSTANT;
223233
}
224-
0[xX]{H}+{IS}? { count (); yylval.val = constVal (yytext); return CONSTANT; }
225-
0[0-7]*{IS}? { count (); yylval.val = constVal (yytext); return CONSTANT; }
226-
[1-9]{D}*{IS}? { count (); yylval.val = constVal (yytext); return CONSTANT; }
234+
0[xX]{H}+{IS}? { count (); yylval.val = constIntVal (yytext); return CONSTANT; }
235+
0[0-7]*{IS}? { count (); yylval.val = constIntVal (yytext); return CONSTANT; }
236+
[1-9]{D}*{IS}? { count (); yylval.val = constIntVal (yytext); return CONSTANT; }
227237
{CP}?'(\\.|[^\\'])+' { count (); yylval.val = charVal (yytext); return CONSTANT; /* ' make syntax highlighter happy */ }
228238
{D}+{E}{FS}? { count (); yylval.val = constFloatVal (yytext); return CONSTANT; }
229239
{D}*"."{D}+({E})?{FS}? { count (); yylval.val = constFloatVal (yytext); return CONSTANT; }
230240
{D}+"."{D}*({E})?{FS}? { count (); yylval.val = constFloatVal (yytext); return CONSTANT; }
241+
0[xX]{H}+{BE}{FS}? { count (); if (!options.std_c99) werror(E_HEXFLOAT_C99); yylval.val = constFloatVal (yytext); return CONSTANT; }
242+
0[xX]{H}*"."{H}+({BE})?{FS}? { count (); if (!options.std_c99) werror(E_HEXFLOAT_C99); yylval.val = constFloatVal (yytext); return CONSTANT; }
243+
0[xX]{H}+"."{H}*({BE})?{FS}? { count (); if (!options.std_c99) werror(E_HEXFLOAT_C99); yylval.val = constFloatVal (yytext); return CONSTANT; }
231244
\" { count (); yylval.yystr = stringLiteral (0); return STRING_LITERAL; }
232245
"L\"" { count (); if (!options.std_c95) werror(E_WCHAR_STRING_C95); yylval.yystr = stringLiteral ('L'); return STRING_LITERAL; }
233246
"u8\"" { count (); if (!options.std_c11) werror(E_WCHAR_STRING_C11); yylval.yystr = stringLiteral (0); return STRING_LITERAL; }
@@ -278,6 +291,7 @@ static void checkCurrFile (const char *s);
278291
"^" { count (); return '^'; }
279292
"|" { count (); return '|'; }
280293
"?" { count (); return '?'; }
294+
"::" { count (); return ATTRIBCOLON; }
281295
^{HASH}pragma.* { count (); process_pragma (yytext); }
282296
^{HASH}.* { count (); checkCurrFile (yytext); }
283297

@@ -731,7 +745,6 @@ enum {
731745
P_NOINDUCTION,
732746
P_NOINVARIANT,
733747
P_STACKAUTO,
734-
P_NOJTBOUND,
735748
P_OVERLAY_, /* I had a strange conflict with P_OVERLAY while */
736749
/* cross-compiling for MINGW32 with gcc 3.2 */
737750
P_NOOVERLAY,
@@ -748,6 +761,7 @@ enum {
748761
P_STD_C89,
749762
P_STD_C99,
750763
P_STD_C11,
764+
P_STD_C2X,
751765
P_STD_SDCC89,
752766
P_STD_SDCC99,
753767
P_CODESEG,
@@ -932,17 +946,6 @@ doPragma (int id, const char *name, const char *cp)
932946
options.stackAuto = 1;
933947
break;
934948

935-
case P_NOJTBOUND:
936-
cp = get_pragma_token(cp, &token);
937-
if (TOKEN_EOL != token.type)
938-
{
939-
err = 1;
940-
break;
941-
}
942-
943-
optimize.noJTabBoundary = 1;
944-
break;
945-
946949
case P_NOGCSE:
947950
cp = get_pragma_token(cp, &token);
948951
if (TOKEN_EOL != token.type)
@@ -1093,6 +1096,7 @@ doPragma (int id, const char *name, const char *cp)
10931096

10941097
options.std_c99 = 0;
10951098
options.std_c11 = 0;
1099+
options.std_c2x = 0;
10961100
options.std_sdcc = 0;
10971101
break;
10981102

@@ -1105,6 +1109,8 @@ doPragma (int id, const char *name, const char *cp)
11051109
}
11061110

11071111
options.std_c99 = 1;
1112+
options.std_c11 = 0;
1113+
options.std_c2x = 0;
11081114
options.std_sdcc = 0;
11091115
break;
11101116

@@ -1118,6 +1124,21 @@ doPragma (int id, const char *name, const char *cp)
11181124

11191125
options.std_c99 = 1;
11201126
options.std_c11 = 1;
1127+
options.std_c2x = 0;
1128+
options.std_sdcc = 0;
1129+
break;
1130+
1131+
case P_STD_C2X:
1132+
cp = get_pragma_token(cp, &token);
1133+
if (TOKEN_EOL != token.type)
1134+
{
1135+
err = 1;
1136+
break;
1137+
}
1138+
1139+
options.std_c99 = 1;
1140+
options.std_c11 = 1;
1141+
options.std_c2x = 1;
11211142
options.std_sdcc = 0;
11221143
break;
11231144

@@ -1131,6 +1152,7 @@ doPragma (int id, const char *name, const char *cp)
11311152

11321153
options.std_c99 = 0;
11331154
options.std_c11 = 0;
1155+
options.std_c2x = 0;
11341156
options.std_sdcc = 1;
11351157
break;
11361158

@@ -1144,6 +1166,7 @@ doPragma (int id, const char *name, const char *cp)
11441166

11451167
options.std_c99 = 1;
11461168
options.std_c11 = 0;
1169+
options.std_c2x = 0;
11471170
options.std_sdcc = 1;
11481171
break;
11491172

@@ -1199,7 +1222,6 @@ static struct pragma_s pragma_tbl[] = {
11991222
{ "noinvariant", P_NOINVARIANT, 0, doPragma },
12001223
{ "noloopreverse", P_LOOPREV, 0, doPragma },
12011224
{ "stackauto", P_STACKAUTO, 0, doPragma },
1202-
{ "nojtbound", P_NOJTBOUND, 0, doPragma },
12031225
{ "nogcse", P_NOGCSE, 0, doPragma },
12041226
{ "overlay", P_OVERLAY_, 0, doPragma },
12051227
{ "nooverlay", P_NOOVERLAY, 0, doPragma },
@@ -1214,6 +1236,7 @@ static struct pragma_s pragma_tbl[] = {
12141236
{ "std_c89", P_STD_C89, 0, doPragma },
12151237
{ "std_c99", P_STD_C99, 0, doPragma },
12161238
{ "std_c11", P_STD_C11, 0, doPragma },
1239+
{ "std_c2x", P_STD_C2X, 0, doPragma },
12171240
{ "std_sdcc89", P_STD_SDCC89, 0, doPragma },
12181241
{ "std_sdcc99", P_STD_SDCC99, 0, doPragma },
12191242
{ "codeseg", P_CODESEG, 0, doPragma },
@@ -1289,41 +1312,6 @@ process_pragma (const char *s)
12891312
}
12901313
}
12911314

1292-
/* will return 1 if the string is a part
1293-
of a target specific keyword */
1294-
static int
1295-
isTargetKeyword (const char *s)
1296-
{
1297-
int i;
1298-
1299-
if (port->keywords == NULL)
1300-
return 0;
1301-
1302-
if (s[0] == '_' && s[1] == '_')
1303-
{
1304-
/* Keywords in the port's array have either 0 or 1 underscore, */
1305-
/* so skip over the appropriate number of chars when comparing */
1306-
for (i = 0 ; port->keywords[i] ; i++ )
1307-
{
1308-
if (port->keywords[i][0] == '_' &&
1309-
strcmp(port->keywords[i],s+1) == 0)
1310-
return 1;
1311-
else if (strcmp(port->keywords[i],s+2) == 0)
1312-
return 1;
1313-
}
1314-
}
1315-
else
1316-
{
1317-
for (i = 0 ; port->keywords[i] ; i++ )
1318-
{
1319-
if (strcmp(port->keywords[i],s) == 0)
1320-
return 1;
1321-
}
1322-
}
1323-
1324-
return 0;
1325-
}
1326-
13271315
int
13281316
yywrap (void)
13291317
{

0 commit comments

Comments
 (0)