History

fixed macro bug and dummy float constant parsing

bellard committed 24 years ago

Commit cb448351 parent 25618c01 file · +27 −8Browse files

Unified · Split

tcc.c+27−8
@@ -316,6 +316,10 @@ enum { · 315 unmodified lines
316316 TOK_MAIN,
317317 };
318318
319+/* XXX: need to define this to use them in non ISOC99 context */
320+extern float strtof (const char *__nptr, char **__endptr);
321+extern long double strtold (const char *__nptr, char **__endptr);
322+
319323 void sum(int l);
320324 void next(void);
321325 void next_nomacro(void);
@@ -894,7 +898,7 @@ int expr_preprocess(void) · 572 unmodified lines
894898 return c != 0;
895899 }
896900
897−#ifdef DEBUG
901+#if defined(DEBUG)
898902 void tok_print(int *str)
899903 {
900904 int t;
@@ -1007,6 +1011,11 @@ void preprocess() · 106 unmodified lines
10071011 strcpy(buf, get_tok_str(tok, &tokc));
10081012 c = '\"';
10091013 }
1014+ /* eat all spaces and comments after include */
1015+ /* XXX: slightly incorrect */
1016+ while (ch1 != '\n' && ch1 != -1)
1017+ inp();
1018+
10101019 if (include_stack_ptr >= include_stack + INCLUDE_STACK_SIZE)
10111020 error("memory full");
10121021 if (c == '\"') {
@@ -1389,12 +1398,10 @@ void parse_number(void) · 376 unmodified lines
13891398 if (t == 'F') {
13901399 cinp();
13911400 tok = TOK_CFLOAT;
1392− /* XXX: this is an ISOC99 function */
13931401 cval.f = strtof(token_buf, NULL);
13941402 } else if (t == 'L') {
13951403 cinp();
13961404 tok = TOK_CLDOUBLE;
1397− /* XXX: this is an ISOC99 function */
13981405 cval.ld = strtold(token_buf, NULL);
13991406 } else {
14001407 tok = TOK_CDOUBLE;
@@ -1638,7 +1645,7 @@ int *macro_twosharps(int *macro_str) · 237 unmodified lines
16381645 next_nomacro();
16391646 if (tok == 0)
16401647 break;
1641− if (*macro_ptr == TOK_TWOSHARPS) {
1648+ while (*macro_ptr == TOK_TWOSHARPS) {
16421649 macro_ptr++;
16431650 macro_ptr1 = macro_ptr;
16441651 t = *macro_ptr;
@@ -1654,15 +1661,15 @@ int *macro_twosharps(int *macro_str) · 9 unmodified lines
16541661 p = get_tok_str(t, &cval);
16551662 strcat(token_buf, p);
16561663 ts = tok_alloc(token_buf, 0);
1657− tok_add(&macro_str1, &macro_str1_len, ts->tok);
1664+ tok = ts->tok; /* modify current token */
16581665 } else {
16591666 /* cannot merge tokens: skip '##' */
16601667 macro_ptr = macro_ptr1;
1668+ break;
16611669 }
16621670 }
1663− } else {
1664− tok_add2(&macro_str1, &macro_str1_len, tok, &tokc);
16651671 }
1672+ tok_add2(&macro_str1, &macro_str1_len, tok, &tokc);
16661673 }
16671674 tok_add(&macro_str1, &macro_str1_len, 0);
16681675 return macro_str1;
@@ -2842,7 +2849,19 @@ void unary(void) · 1173 unmodified lines
28422849 GFuncContext gf;
28432850
28442851 if (tok == TOK_NUM || tok == TOK_CCHAR || tok == TOK_LCHAR) {
2845− vset(VT_CONST, tokc.i);
2852+ vset(VT_CONST | VT_INT, tokc.i);
2853+ next();
2854+ } else if (tok == TOK_CFLOAT) {
2855+ /* currently, cannot do more */
2856+ vset(VT_CONST | VT_FLOAT, 0);
2857+ next();
2858+ } else if (tok == TOK_CDOUBLE) {
2859+ /* currently, cannot do more */
2860+ vset(VT_CONST | VT_DOUBLE, 0);
2861+ next();
2862+ } else if (tok == TOK_CLDOUBLE) {
2863+ /* currently, cannot do more */
2864+ vset(VT_CONST | VT_LDOUBLE, 0);
28462865 next();
28472866 } else if (tok == TOK___FUNC__) {
28482867 /* special function name identifier */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t