History

Fake __has_include handling

cctools for MacOS 10.14 (at least) unconditionally uses the __has_include preprocessor directive (i.e. without checking if defined __has_include as normally suggested for portable code). So we need to handle it a little bit. For now we simply say "nope" aka evaluate to 0.

Michael Matz committed 6 years ago

Commit c16f5d21 parent 34a56582 files · +19 −1Browse files

Unified · Split

2 files
  1. tccpp.c +18 −1
  2. tcctok.h +1 −0
tccpp.c+18−1
@@ -1450,6 +1450,7 @@ static int expr_preprocess(void) · 1449 unmodified lines
14501450 pp_expr = 1;
14511451 while (tok != TOK_LINEFEED && tok != TOK_EOF) {
14521452 next(); /* do macro subst */
1453+ redo:
14531454 if (tok == TOK_DEFINED) {
14541455 next_nomacro();
14551456 t = tok;
@@ -1467,10 +1468,26 @@ static int expr_preprocess(void) · 11 unmodified lines
14671468 }
14681469 tok = TOK_CINT;
14691470 tokc.i = c;
1471+ } else if (1 && tok == TOK___HAS_INCLUDE) {
1472+ next(); /* XXX check if correct to use expansion */
1473+ skip('(');
1474+ while (tok != ')' && tok != TOK_EOF)
1475+ next();
1476+ if (tok != ')')
1477+ expect("')'");
1478+ tok = TOK_CINT;
1479+ tokc.i = 0;
14701480 } else if (tok >= TOK_IDENT) {
1471− /* if undefined macro */
1481+ /* if undefined macro, replace with zero, check for func-like */
1482+ t = tok;
14721483 tok = TOK_CINT;
14731484 tokc.i = 0;
1485+ tok_str_add_tok(str);
1486+ next();
1487+ if (tok == '(')
1488+ tcc_error("function-like macro '%s' is not defined",
1489+ get_tok_str(t, NULL));
1490+ goto redo;
14741491 }
14751492 tok_str_add_tok(str);
14761493 }
tcctok.h+1−0
@@ -91,6 +91,7 @@ · 90 unmodified lines
9191 DEF(TOK___FUNCTION__, "__FUNCTION__")
9292 DEF(TOK___VA_ARGS__, "__VA_ARGS__")
9393 DEF(TOK___COUNTER__, "__COUNTER__")
94+ DEF(TOK___HAS_INCLUDE, "__has_include")
9495
9596 /* special identifiers */
9697 DEF(TOK___FUNC__, "__func__")

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