|
24 | 24 | import argparse |
25 | 25 | import errno |
26 | 26 |
|
| 27 | +tokTypes = { |
| 28 | + '+': ['eArithmeticalOp'], |
| 29 | + '-': ['eArithmeticalOp'], |
| 30 | + '*': ['eArithmeticalOp'], |
| 31 | + '/': ['eArithmeticalOp'], |
| 32 | + '%': ['eArithmeticalOp'], |
| 33 | + '>>': ['eArithmeticalOp'], |
| 34 | + '<<': ['eArithmeticalOp'], |
| 35 | + '=': ['eAssignmentOp'], |
| 36 | + '+=': ['eAssignmentOp'], |
| 37 | + '-=': ['eAssignmentOp'], |
| 38 | + '*=': ['eAssignmentOp'], |
| 39 | + '/=': ['eAssignmentOp'], |
| 40 | + '%=': ['eAssignmentOp'], |
| 41 | + '&=': ['eAssignmentOp'], |
| 42 | + '|=': ['eAssignmentOp'], |
| 43 | + '^=': ['eAssignmentOp'], |
| 44 | + '&': ['eBitOp'], |
| 45 | + '^': ['eBitOp'], |
| 46 | + '~': ['eBitOp'], |
| 47 | + 'true': ['eBoolean'], |
| 48 | + 'false': ['eBoolean'], |
| 49 | + '{': ['eBracket'], |
| 50 | + '}': ['eBracket'], |
| 51 | + '<': ['eBracket', 'eComparisonOp'], |
| 52 | + '>': ['eBracket', 'eComparisonOp'], |
| 53 | + '==': ['eComparisonOp'], |
| 54 | + '!=': ['eComparisonOp'], |
| 55 | + '<=': ['eComparisonOp'], |
| 56 | + '>=': ['eComparisonOp'], |
| 57 | + '<=>': ['eComparisonOp'], |
| 58 | + '...': ['eEllipsis'], |
| 59 | + ',': ['eExtendedOp'], |
| 60 | + '?': ['eExtendedOp'], |
| 61 | + ':': ['eExtendedOp'], |
| 62 | + '(': ['eExtendedOp'], |
| 63 | + ')': ['eExtendedOp'], |
| 64 | + '[': ['eExtendedOp', 'eLambda'], |
| 65 | + ']': ['eExtendedOp', 'eLambda'], |
| 66 | + '++': ['eIncDecOp'], |
| 67 | + '--': ['eIncDecOp'], |
| 68 | + 'asm': ['eKeyword'], |
| 69 | + 'auto': ['eKeyword', 'eType'], |
| 70 | + 'break': ['eKeyword'], |
| 71 | + 'case': ['eKeyword'], |
| 72 | + 'const': ['eKeyword'], |
| 73 | + 'continue': ['eKeyword'], |
| 74 | + 'default': ['eKeyword'], |
| 75 | + 'do': ['eKeyword'], |
| 76 | + 'else': ['eKeyword'], |
| 77 | + 'enum': ['eKeyword'], |
| 78 | + 'extern': ['eKeyword'], |
| 79 | + 'for': ['eKeyword'], |
| 80 | + 'goto': ['eKeyword'], |
| 81 | + 'if': ['eKeyword'], |
| 82 | + 'inline': ['eKeyword'], |
| 83 | + 'register': ['eKeyword'], |
| 84 | + 'restrict': ['eKeyword'], |
| 85 | + 'return': ['eKeyword'], |
| 86 | + 'sizeof': ['eKeyword'], |
| 87 | + 'static': ['eKeyword'], |
| 88 | + 'struct': ['eKeyword'], |
| 89 | + 'switch': ['eKeyword'], |
| 90 | + 'typedef': ['eKeyword'], |
| 91 | + 'union': ['eKeyword'], |
| 92 | + 'volatile': ['eKeyword'], |
| 93 | + 'while': ['eKeyword'], |
| 94 | + 'void': ['eKeyword', 'eType'], |
| 95 | + '&&': ['eLogicalOp'], |
| 96 | + '!': ['eLogicalOp'] |
| 97 | +} |
27 | 98 |
|
28 | 99 | class MatchCompiler: |
29 | 100 |
|
@@ -117,7 +188,9 @@ def _compileCmd(tok): |
117 | 188 | return '(tok->isName() && tok->varId() == varid)' |
118 | 189 | elif (len(tok) > 2) and (tok[0] == "%"): |
119 | 190 | print("unhandled:" + tok) |
120 | | - |
| 191 | + elif tok in tokTypes: |
| 192 | + cond = ' || '.join(['tok->tokType() == Token::{}'.format(tokType) for tokType in tokTypes[tok]]) |
| 193 | + return '(({cond}) && tok->str() == MatchCompiler::makeConstString("{tok}"))'.format(cond=cond, tok=tok) |
121 | 194 | return ( |
122 | 195 | '(tok->str() == MatchCompiler::makeConstString("' + tok + '"))' |
123 | 196 | ) |
|
0 commit comments