Commit bbef76bb authored by Sergio Costas's avatar Sergio Costas

Added support for __typeof__ and __builtin_offsetof

parent 3bc808cb
......@@ -228,7 +228,7 @@ doesn't fail if they are present in the code):
* __restrict
* __inline
It also recognizes the following syntax extensions:
It also recognizes the following syntax extensions (but are managed as stubs):
* statements inside parentheses
* ellipsis syntax in CASE statements ( CASE n1 ... n2: )
......@@ -236,6 +236,8 @@ It also recognizes the following syntax extensions:
* __asm__ [XXXX] (...)
* asm [XXXXX] (...)
* __alignof__(...)
* __typeof__(...)
* __builtin_offsetof(...)
# CONTACTING THE AUTHOR
......
......@@ -1780,13 +1780,13 @@ def get_parameters():
continue
if parameter.startswith("--debug1="):
try:
parameters["debug1"] = int(parameter[8:])
parameters["debug1"] = int(parameter[9:])
except:
pass
continue
if parameter.startswith("--debug2="):
try:
parameters["debug2"] = int(parameter[8:])
parameters["debug2"] = int(parameter[9:])
except:
pass
continue
......
......@@ -91,6 +91,7 @@ class tokens(object):
344:'END_BLOCK',
345:'TYPECAST',
346:'TYPENAME_IDENTIFIER',
347:'T_TYPEOF',
'IDENTIFIER':258,
'CONSTANT':259,
'STRING_LITERAL':260,
......@@ -180,6 +181,7 @@ class tokens(object):
'END_BLOCK':344,
'TYPECAST':345,
'TYPENAME_IDENTIFIER':346,
'T_TYPEOF':347,
}
@staticmethod
......
......@@ -423,7 +423,7 @@ void show_error(int line,struct AST *element) {
void show_debug(int line, struct AST *element, char *node) {
if ((current_line >= debug_line1) && (current_line <= debug_line2)) {
printf("Changed to type %s at line %d (code line: %d; code data: %s)\n",node,line,current_line,element->data);
printf("Changed to type %s at line %d (code line: %d, file: %s; code data: %s)\n",node,line,current_line,current_file,element->data);
}
}
......
......@@ -96,7 +96,10 @@ void find_close_parentheses(int);
"volatile" { return prepare_leaf(0,0.0,VOLATILE); }
"while" { return prepare_leaf(0,0.0,WHILE); }
"NULL" { return prepare_leaf(0,0.0,T_NULL); }
"__typeof__" { return prepare_leaf(0,0.0,T_TYPEOF); }
"typeof" { return prepare_leaf(0,0.0,T_TYPEOF); }
"__builtin_va_list" { return prepare_leaf(0,0.0,VA_LIST); }
"__builtin_offsetof"{WS}*"(" { find_close_parentheses(1); count(); return prepare_leaf(0,0.0,CONSTANT); }
"__signed__" { return prepare_leaf(0,0.0,SIGNED); }
"__extension__" { count(); }
"__prog__" { count(); }
......
......@@ -71,6 +71,7 @@ void add_type_element(char *);
%token END_BLOCK
%token TYPECAST
%token TYPENAME_IDENTIFIER
%token T_TYPEOF
//%start translation_unit
%start start_unit
......@@ -373,6 +374,18 @@ declaration_specifiers
| function_specifier declaration_specifiers { $$ = $2; show_debug(__LINE__, $$, "declaration_specifiers");
// inline definition
free_tree($1); }
| T_TYPEOF '(' declaration_specifiers ')' { $$ = $3; show_debug(__LINE__, $$, "declaration_specifiers");
printf("Tipo 1 %s\n",$3->data);
free_tree($1);
free_tree($2);
free_tree($4); }
| T_TYPEOF '(' declaration_specifiers pointer ')' { $$ = $3; show_debug(__LINE__, $$, "declaration_specifiers");
$3->pointer += $4->pointer;
printf("Tipo 2 %s\n",$3->data);
free_tree($1);
free_tree($2);
free_tree($4);
free_tree($5); }
;
init_declarator_list
......@@ -398,22 +411,33 @@ storage_class_specifier
;
type_specifier
: VOID { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| CHAR { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| SHORT { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| INT { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| LONG { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| FLOAT { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| DOUBLE { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| SIGNED { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| UNSIGNED { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| BOOL { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| COMPLEX { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| IMAGINARY { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| VA_LIST { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| struct_or_union_specifier { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| enum_specifier { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| TYPE_NAME { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
: VOID { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| CHAR { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| SHORT { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| INT { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| LONG { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| FLOAT { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| DOUBLE { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| SIGNED { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| UNSIGNED { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| BOOL { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| COMPLEX { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| IMAGINARY { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| VA_LIST { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| struct_or_union_specifier { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| enum_specifier { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| TYPE_NAME { $$ = $1; $$->type = TYPE_SPECIFIER; show_debug(__LINE__, $$, "type_specifier"); }
| T_TYPEOF '(' postfix_expression ')' { $$ = $1; $$->type = TYPE_SPECIFIER; $$->t_char = true;
show_debug(__LINE__, $$, "type_specifier");
free_tree($2);
free_tree($3);
free_tree($4); }
| T_TYPEOF '(' pointer postfix_expression ')' { $$ = $1; $$->type = TYPE_SPECIFIER; $$->t_char = true; $$->pointer += $3->pointer;
show_debug(__LINE__, $$, "type_specifier");
free_tree($2);
free_tree($3);
free_tree($4);
free_tree($5); }
;
struct_or_union_specifier
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment