Commit 2410da04 authored by Sergio Costas's avatar Sergio Costas

Added fully support for ellipsis in CASE statements

Better support for __asm__ and asm statements

Allows to create typedefs from structs with the same name than the struct type
parent 1107f035
......@@ -220,14 +220,22 @@ Just paste the code that generated the error and send it to the author.
The parser recognizes the following non-standard statements (but it doesn't use them, just
doesn't fail if they are present in the code):
__builtin_va_list
__extension__
__prog__
__restrict
__inline
__attribute__ ((...))
__asm__ (...)
__asm__ volatile (...)
* #pragma
* __builtin_va_list
* __signed__
* __extension__
* __prog__
* __restrict
* __inline
It also recognizes the following syntax extensions:
* statements inside parentheses
* ellipsis syntax in CASE statements ( CASE n1 ... n2: )
* __attribute__ (...)
* __asm__ [XXXX] (...)
* asm [XXXXX] (...)
* __alignof__(...)
# CONTACTING THE AUTHOR
......
......@@ -81,6 +81,12 @@ class crust(object):
super().__init__()
self.status = crust.VALUE_UNINITIALIZED
self.init_line = None
self.type = ""
self.name = ""
self.line = -1
self.next = None
self.intval = 0
self.floatval = 0.0
def copy(self):
retval = crust.AST_node()
......@@ -1304,6 +1310,8 @@ class crust(object):
if tree[0].type == "START_BLOCK":
tree = tree[1:] # the variable block has been already added
blocks = [ (tree, thread_status) ]
# for element in blocks[0][0]:
# print("Tipo: {:s}; Valor {:s}; Linea {:d}".format(str(element.type), str(element.intval), element.line))
while len(blocks) > 0:
current_block = blocks[0]
blocks = blocks[1:]
......@@ -1358,7 +1366,7 @@ class crust(object):
def _process_block2(self, tree, thread_status):
node = tree[0]
#print("Tipo: {:s}".format(str(node.type)))
#print("Tipo: {:s}; Valor {:s}; Linea {:d}".format(str(node.type), str(node.intval), node.line))
#print("Tipo: {:s}; Nombre: {:s}; Linea: {:s}".format(str(node.type), str(node.name), str(node.line)))
if (node.type == "TYPE_SPECIFIER"):
if (node.enum_data is not None):
......@@ -1660,29 +1668,21 @@ class crust(object):
def _new_start_block(self):
node = self.AST_node()
node.type = "START_BLOCK"
node.line = -1
node.name = ""
return node
def _new_end_block(self):
node = self.AST_node()
node.type = "END_BLOCK"
node.line = -1
node.name = ""
return node
def _new_end_loop(self):
node = self.AST_node()
node.type = "END_LOOP"
node.line = -1
node.name = ""
return node
def _new_tmp_end_loop(self):
node = self.AST_node()
node.type = "TMP_END_LOOP"
node.line = -1
node.name = ""
return node
......@@ -1690,16 +1690,12 @@ class crust(object):
node = self.AST_node()
node.type = "EVAL_FALSE"
node.condition = condition.copy()
node.line = -1
node.name = ""
return node
def _new_eval_true(self, condition):
node = self.AST_node()
node.type = "EVAL_TRUE"
node.condition = condition.copy()
node.line = -1
node.name = ""
return node
......
......@@ -321,6 +321,7 @@ 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);
......
......@@ -103,11 +103,9 @@ void find_close_parentheses(int);
"__restrict" { count(); }
"__inline" { count(); }
"__attribute__"{WS}*"(" { find_close_parentheses(1); count(); }
"__asm__"{WS}*"(" { find_close_parentheses(1); count(); }
"__asm__"{WS}+"volatile"{WS}*"(" { find_close_parentheses(1); count(); }
"__asm__"{WS}+"__volatile__"{WS}*"(" { find_close_parentheses(1); count(); }
"asm"{WS}+"volatile"{WS}*"(" { find_close_parentheses(1); count(); }
"asm"{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); }
"__crust_t__" { 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); }
......
......@@ -432,6 +432,10 @@ struct_or_union_specifier
free($$->name);
$$->name = mystrdup($2->data);
free_tree($2); }
| struct_or_union TYPE_NAME { $$ = $1; show_debug(__LINE__, $$, "struct_or_union_specifier");
free($$->name);
$$->name = mystrdup($2->data);
free_tree($2); }
;
struct_or_union
......@@ -774,6 +778,29 @@ labeled_statement
$$->condition = $2;
append_next($$,$4);
free_tree($3); }
| CASE constant_expression ELLIPSIS constant_expression ':' statement
{ $$ = $1; show_debug(__LINE__, $$, "labeled_statement");
int c;
bool first = true;
for(c = $2->intval; c <= $4->intval; c++) {
if (first) {
tmpleaf = $1;
first = false;
} else {
tmpleaf = copy_leaf($1, false);
}
tmpleaf->condition = copy_leaf($2, false);
tmpleaf->condition->intval = c;
if (tmpleaf != $1) {
append_next($$,tmpleaf);
}
}
append_next($$,$6);
free_tree($2);
free_tree($3);
free_tree($4);
free_tree($5); }
| DEFAULT ':' statement { $$ = $1; show_debug(__LINE__, $$, "labeled_statement");
append_next($$,$3);
free_tree($2); }
......
......@@ -834,6 +834,9 @@ class Test(unittest.TestCase):
def test185CheckIfWithUninitializedVariable(self):
self._generic_test("unitest/test185.c", [ (crust.crust.MSG_ERROR, "Assigning the global variable '{:s}' to the global variable '{:s}' at line {:d}, but it already has assigned the block '{:s}'", "global_var1", "global_var2", 11, "param1" ) ])
def test186CheckIfWithUninitializedVariable(self):
self._generic_test("unitest/test186.c", [ (crust.crust.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point at line {:d}", "data", 7, 11) ])
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
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