|
31 | 31 | from .prepro import DefinesTable, ID, MacroCall, Arg, ArgList |
32 | 32 | from .prepro.exceptions import PreprocError |
33 | 33 | from .prepro.operators import Concatenation |
| 34 | +from .prepro.operators import Stringizing |
34 | 35 |
|
35 | 36 | from src import arch |
36 | 37 |
|
@@ -64,7 +65,7 @@ class IfDef(NamedTuple): |
64 | 65 | ('nonassoc', 'DUMMY'), |
65 | 66 | ('left', 'EQ', 'NE', 'LT', 'LE', 'GT', 'GE'), |
66 | 67 | ('right', 'LLP'), |
67 | | - ('left', 'PASTE'), |
| 68 | + ('left', 'PASTE', 'STRINGIZING'), |
68 | 69 | ) |
69 | 70 |
|
70 | 71 |
|
@@ -423,14 +424,18 @@ def p_warningmsg(p): |
423 | 424 | def p_define(p): |
424 | 425 | """ define : DEFINE ID params defs |
425 | 426 | """ |
| 427 | + id_ = p[2] |
| 428 | + params = p[3] |
| 429 | + defs = p[4] |
| 430 | + |
426 | 431 | if ENABLED: |
427 | | - if p[4]: |
428 | | - if p[4][0] in ' \t': # remove leading whitespaces |
429 | | - p[4][0] = p[4][0].lstrip(' \t') |
| 432 | + if defs: |
| 433 | + if isinstance(defs[0], str) and defs[0] in ' \t': # remove leading whitespaces |
| 434 | + defs[0] = defs[0].lstrip(' \t') |
430 | 435 | else: |
431 | 436 | warning(p.lineno(1), "missing whitespace after macro name") |
432 | 437 |
|
433 | | - ID_TABLE.define(p[2], args=p[3], value=p[4], lineno=p.lineno(2), |
| 438 | + ID_TABLE.define(id_, args=params, value=defs, lineno=p.lineno(2), |
434 | 439 | fname=output.CURRENT_FILE[-1]) |
435 | 440 | p[0] = [] |
436 | 441 |
|
@@ -692,6 +697,12 @@ def p_macrocall_paste(p): |
692 | 697 | p[0] = Concatenation(p[1].lineno, ID_TABLE, p[1], p[3]) |
693 | 698 |
|
694 | 699 |
|
| 700 | +def p_macrocall_stringizing(p): |
| 701 | + """ macrocall : STRINGIZING macrocall |
| 702 | + """ |
| 703 | + p[0] = Stringizing(p[2].lineno, ID_TABLE, p[2]) |
| 704 | + |
| 705 | + |
695 | 706 | def p_args(p): |
696 | 707 | """ args : LLP arglist RRP |
697 | 708 | """ |
|
0 commit comments