Skip to content

Commit

Permalink
added __typeof expression type_specifier, it is another alias for __t…
Browse files Browse the repository at this point in the history
…ypeof__; test added too
  • Loading branch information
retif authored and inducer committed May 30, 2024
1 parent 1c5ca53 commit 2cf018f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pycparserext/ext_c_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def add_lexer_keywords(cls, keywords):
'__asm__', '__asm', 'asm']

_GNU_KEYWORDS = [
'__typeof__', 'typeof',
'__typeof__', 'typeof', '__typeof',
'__real__', '__imag__',
'__builtin_types_compatible_p',
'__const',
Expand Down
2 changes: 2 additions & 0 deletions pycparserext/ext_c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ def p_type_qualifier_gnu(self, p):
def p_type_specifier_gnu_typeof_expr(self, p):
""" type_specifier : __TYPEOF__ LPAREN expression RPAREN
| TYPEOF LPAREN expression RPAREN
| __TYPEOF LPAREN expression RPAREN
"""
if isinstance(p[3], c_ast.TypeDecl):
pass
Expand All @@ -521,6 +522,7 @@ def p_type_specifier_gnu_typeof_expr(self, p):
def p_type_specifier_gnu_typeof_decl(self, p):
""" type_specifier : __TYPEOF__ LPAREN parameter_declaration RPAREN
| TYPEOF LPAREN parameter_declaration RPAREN
| __TYPEOF LPAREN parameter_declaration RPAREN
"""
p[0] = TypeOfDeclaration(p[1], p[3])

Expand Down
13 changes: 9 additions & 4 deletions test/test_pycparserext.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def test_node_visitor():
"Asm": [0, 1],
# PreprocessorLine is OpenCL, not GNU
"PreprocessorLine": [0, 0],
"TypeOfDeclaration": [0, 4],
"TypeOfDeclaration": [0, 6],
"TypeOfExpression": [0, 1],
"FuncDeclExt": [0, 1],
}
Expand Down Expand Up @@ -548,6 +548,7 @@ def visit_FuncDeclExt(self, node):
__typeof__(a) _a = __builtin_types_compatible_p(long char, short int);
__typeof__ (__typeof__ (char *)[4]) y;
typeof (typeof (char *)[4]) z;
__typeof (__typeof (char *)[4]) g;
asm("rdtsc" : "=A" (val));
__attribute__((unused)) static int c;
}
Expand All @@ -569,9 +570,11 @@ def test_typeof_reproduction():
int func(int a, int b) {
__typeof__(a) _a = a;
typeof(b) _b = b;
__typeof(c) _c = c;
__typeof__ (__typeof__ (char *)[4]) y;
typeof (typeof (char *)[4]) z;
__typeof (__typeof (char *)[4]) g;
}
"""
assert _round_trip_matches(src)
Expand All @@ -581,10 +584,12 @@ def test_typeof_reproduction():

# key is type of visit, value is
# [actual # __typeof__, expected # __typeof__,
# actual # typeof, expected # typeof]
# actual # typeof, expected # typeof,
# actual # __typeof, expected # __typeof
# ]
visits = {
"TypeOfDeclaration": [0, 2, 0, 2],
"TypeOfExpression": [0, 1, 0, 1],
"TypeOfDeclaration": [0, 2, 0, 4],
"TypeOfExpression": [0, 1, 0, 2],
}

class TestVisitor(NodeVisitor):
Expand Down

0 comments on commit 2cf018f

Please sign in to comment.