...
 
Commits (2)
  • Sergio Costas's avatar
    Added support for _Static_assert · 7a91af0d
    Sergio Costas authored
    7a91af0d
  • Sergio Costas's avatar
    Added preliminar support for statements in expressions · 02cdd9f6
    Sergio Costas authored
    A GNU extension used in several headers is to have statements or
    declarations in an expression. An example is:
    
       a = ({ int y = foo(); if (y>1) y = 7;});
    
    This patch adds preliminary support for this. It only avoids the
    "syntax error" error, but the block is never executed. Thus this
    extension must not be used in the code to be checked, only is allowed
    in the headers, in definitions never used in the true code.
    
    This is useful for FreeRTOS, which has several of these in their
    headers, thus allowing to check code for this operating system.
    02cdd9f6
......@@ -82,6 +82,9 @@ class crust(crust_helpers):
if statement.type == "STRING_LITERAL":
return [ {"thread_status":thread_status, "value":self.VALUE_NOT_NULL, "type":self.TYPE_NO_CRUST, "condition":self.CONDITION_TRUE, "node":None, "pure": True} ]
if statement.type == "ASSIGN_BLOCK":
print("\nAssign block: unimplemented.\n")
return [ {"thread_status":thread_status, "value":self.VALUE_NOT_NULL_OR_NULL, "type":self.TYPE_NO_MATTER, "condition":self._status_to_condition(self.VALUE_NOT_NULL_OR_NULL), "node":None, "pure": False} ]
if statement.type == "IDENTIFIER":
vardata = self._find_variable(thread_status, statement.name, statement.line)
......
......@@ -96,6 +96,7 @@ class tokens(object):
349:'CRUST_SET_NOT_NULL',
350:'CRUST_OVERRIDE',
351:'OWN_POINTER',
352:'ASSIGN_BLOCK',
'IDENTIFIER':258,
'CONSTANT':259,
'STRING_LITERAL':260,
......@@ -190,6 +191,7 @@ class tokens(object):
'CRUST_SET_NOT_NULL':349,
'CRUST_OVERRIDE':350,
'OWN_POINTER':351,
'ASSIGN_BLOCK':352,
}
@staticmethod
......
......@@ -324,13 +324,12 @@ void check_typedef(struct AST *name) {
return;
}
//printf("Tipo: %s, linea: %d, fichero: %s\n", name->data, name->line, name->filename);
struct AST *leaf = copy_leaf(name,false);
if (find_type(leaf->data) != NULL) {
printf("Repetido %s",leaf->data);
exit(-1);
}
//printf(" (Anado %s; %d (%s)) ",leaf->name,leaf->pointer,leaf->function ? "es funcion" : "no es funcion");
leaf->next = types_list;
types_list = leaf;
}
......
......@@ -55,7 +55,7 @@ int current_line = 1;
char *current_file = NULL;
char do_verbose = 0;
void find_close_parentheses(int);
void find_close_parentheses(int, bool);
%}
......@@ -106,17 +106,18 @@ void find_close_parentheses(int);
"__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); }
"__builtin_offsetof"{WS}*"(" { find_close_parentheses(1, false); count(); return prepare_leaf(0,0.0,CONSTANT); }
"__signed__" { return prepare_leaf(0,0.0,SIGNED); }
"__extension__" { count(); }
"__prog__" { count(); }
"__restrict" { count(); }
"__inline" { count(); }
"__attribute__"{WS}*"(" { find_close_parentheses(1); count(); }
"__asm__"({WS}+[a-zA-Z_]+)*{WS}*"(" { find_close_parentheses(1); count(); }
"__asm"({WS}+[a-zA-Z_]+)*{WS}*"(" { find_close_parentheses(1); count(); }
"asm"({WS}+[a-zA-Z_]+)*{WS}*"(" { find_close_parentheses(1); count(); }
"__alignof__(" { find_close_parentheses(1); count(); return prepare_leaf(1,0.0,CONSTANT); }
"__attribute__"{WS}*"(" { find_close_parentheses(1, false); count(); }
"_Static_assert"{WS}*"(" { find_close_parentheses(1, true); count(); }
"__asm__"({WS}+[a-zA-Z_]+)*{WS}*"(" { find_close_parentheses(1, false); count(); }
"__asm"({WS}+[a-zA-Z_]+)*{WS}*"(" { find_close_parentheses(1, false); count(); }
"asm"({WS}+[a-zA-Z_]+)*{WS}*"(" { find_close_parentheses(1, false); count(); }
"__alignof__(" { find_close_parentheses(1, false); count(); return prepare_leaf(1,0.0,CONSTANT); }
"__crust__" { return prepare_leaf(0,0.0,CRUST_T); }
"__crust_borrow__" { return prepare_leaf(0,0.0,CRUST_BORROW); }
"__crust_recycle__" { return prepare_leaf(0,0.0,CRUST_RECYCLE); }
......@@ -440,7 +441,7 @@ int prepare_leaf(unsigned long long int v1, double v2, int current_token) {
return current_token;
}
void find_close_parentheses(int init_counter) {
void find_close_parentheses(int init_counter, bool remove_semicolon) {
char c;
int counter = init_counter;
......@@ -481,6 +482,11 @@ void find_close_parentheses(int init_counter) {
continue;
}
}
if (remove_semicolon) {
do {
c = input();
} while(c != ';');
}
}
void comment(void) {
......
......@@ -81,6 +81,7 @@ void add_type_element(char *);
%token CRUST_SET_NOT_NULL
%token CRUST_OVERRIDE
%token OWN_POINTER
%token ASSIGN_BLOCK
//%start translation_unit
%start start_unit
......@@ -333,6 +334,11 @@ assignment_expression
| unary_expression assignment_operator assignment_expression { $$ = $2; show_debug(__LINE__, $$, "assignment_expression");
$$->child1 = $1;
$$->child2 = $3; }
| '(' compound_statement ')' { $$ = $1;
$1->type = ASSIGN_BLOCK;
$1->child1 = $2;
free_tree($3);
show_debug(__LINE__, $$, "assignment_expression"); }
;
assignment_operator
......