Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added __typeof expression type_specifier, it is another alias for __typeof__; also test added too #80

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading