Skip to content

Commit 2cf018f

Browse files
retifinducer
authored andcommitted
added __typeof expression type_specifier, it is another alias for __typeof__; test added too
1 parent 1c5ca53 commit 2cf018f

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

pycparserext/ext_c_lexer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def add_lexer_keywords(cls, keywords):
6565
'__asm__', '__asm', 'asm']
6666

6767
_GNU_KEYWORDS = [
68-
'__typeof__', 'typeof',
68+
'__typeof__', 'typeof', '__typeof',
6969
'__real__', '__imag__',
7070
'__builtin_types_compatible_p',
7171
'__const',

pycparserext/ext_c_parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ def p_type_qualifier_gnu(self, p):
512512
def p_type_specifier_gnu_typeof_expr(self, p):
513513
""" type_specifier : __TYPEOF__ LPAREN expression RPAREN
514514
| TYPEOF LPAREN expression RPAREN
515+
| __TYPEOF LPAREN expression RPAREN
515516
"""
516517
if isinstance(p[3], c_ast.TypeDecl):
517518
pass
@@ -521,6 +522,7 @@ def p_type_specifier_gnu_typeof_expr(self, p):
521522
def p_type_specifier_gnu_typeof_decl(self, p):
522523
""" type_specifier : __TYPEOF__ LPAREN parameter_declaration RPAREN
523524
| TYPEOF LPAREN parameter_declaration RPAREN
525+
| __TYPEOF LPAREN parameter_declaration RPAREN
524526
"""
525527
p[0] = TypeOfDeclaration(p[1], p[3])
526528

test/test_pycparserext.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def test_node_visitor():
509509
"Asm": [0, 1],
510510
# PreprocessorLine is OpenCL, not GNU
511511
"PreprocessorLine": [0, 0],
512-
"TypeOfDeclaration": [0, 4],
512+
"TypeOfDeclaration": [0, 6],
513513
"TypeOfExpression": [0, 1],
514514
"FuncDeclExt": [0, 1],
515515
}
@@ -548,6 +548,7 @@ def visit_FuncDeclExt(self, node):
548548
__typeof__(a) _a = __builtin_types_compatible_p(long char, short int);
549549
__typeof__ (__typeof__ (char *)[4]) y;
550550
typeof (typeof (char *)[4]) z;
551+
__typeof (__typeof (char *)[4]) g;
551552
asm("rdtsc" : "=A" (val));
552553
__attribute__((unused)) static int c;
553554
}
@@ -569,9 +570,11 @@ def test_typeof_reproduction():
569570
int func(int a, int b) {
570571
__typeof__(a) _a = a;
571572
typeof(b) _b = b;
573+
__typeof(c) _c = c;
572574
573575
__typeof__ (__typeof__ (char *)[4]) y;
574576
typeof (typeof (char *)[4]) z;
577+
__typeof (__typeof (char *)[4]) g;
575578
}
576579
"""
577580
assert _round_trip_matches(src)
@@ -581,10 +584,12 @@ def test_typeof_reproduction():
581584

582585
# key is type of visit, value is
583586
# [actual # __typeof__, expected # __typeof__,
584-
# actual # typeof, expected # typeof]
587+
# actual # typeof, expected # typeof,
588+
# actual # __typeof, expected # __typeof
589+
# ]
585590
visits = {
586-
"TypeOfDeclaration": [0, 2, 0, 2],
587-
"TypeOfExpression": [0, 1, 0, 1],
591+
"TypeOfDeclaration": [0, 2, 0, 4],
592+
"TypeOfExpression": [0, 1, 0, 2],
588593
}
589594

590595
class TestVisitor(NodeVisitor):

0 commit comments

Comments
 (0)