Commit a3fde8b9 authored by Sergio Costas's avatar Sergio Costas

Added support for element __crust_override__

parent 1e66d920
......@@ -1118,7 +1118,7 @@ class crust(object):
alias: the variable is an alias type
"""
retval = {"name": None, "crust": False, "borrowed": False, "recycle": False, "not_null": False, "is_parameter": is_parameter, "void": False, "enum": False, "value": self.VALUE_UNINITIALIZED, "pointer": pointers, "struct": False, "array": False, "function": False, "function_params": None, "ellipsis": False, "init_line": -1, "global": False, "uid": None, "alias": False }
retval = {"name": None, "crust": False, "borrowed": False, "recycle": False, "not_null": False, "is_parameter": is_parameter, "void": False, "enum": False, "value": self.VALUE_UNINITIALIZED, "pointer": pointers, "struct": False, "override": False, "array": False, "function": False, "function_params": None, "ellipsis": False, "init_line": -1, "global": False, "uid": None, "alias": False }
if not isinstance(node, self.AST_node):
return retval
......@@ -1152,6 +1152,9 @@ class crust(object):
else:
self._add_error(thread_status, self.MSG_CRITICAL, "An argument can be BORROW or RECYCLE, not both. (argument '{:s}' at line {:d})", node.name, node.line)
if node.t_override:
retval["override"] = True
if node.t_crust_borrow:
retval["borrowed"] = True
......
......@@ -94,6 +94,7 @@ class tokens(object):
347:'CRUST_NO_ZERO',
348:'CRUST_SET_NULL',
349:'CRUST_SET_NOT_NULL',
350:'CRUST_OVERRIDE',
'IDENTIFIER':258,
'CONSTANT':259,
'STRING_LITERAL':260,
......@@ -186,6 +187,7 @@ class tokens(object):
'CRUST_NO_ZERO':347,
'CRUST_SET_NULL':348,
'CRUST_SET_NOT_NULL':349,
'CRUST_OVERRIDE':350,
}
@staticmethod
......
......@@ -107,6 +107,7 @@ struct AST * new_leaf(int type, struct AST *template) {
ast->t_null = false;
ast->t_ellipsis = false;
ast->t_label = false;
ast->t_override = false;
return ast;
}
......@@ -158,6 +159,7 @@ void mix_ast_leaves(struct AST *base, struct AST *origin_leaf) {
base->t_null |= origin_leaf->t_null;
base->t_ellipsis |= origin_leaf->t_ellipsis;
base->t_label |= origin_leaf->t_label;
base->t_override |= origin_leaf->t_override;
if (base->function_params == NULL) {
base->function_params = copy_leaf(origin_leaf->function_params, true);
}
......@@ -208,6 +210,7 @@ void copy_ast_data(struct AST *base, struct AST *new_leaf) {
base->t_null = new_leaf->t_null;
base->t_ellipsis = new_leaf->t_ellipsis;
base->t_label = new_leaf->t_label;
base->t_override = new_leaf->t_override;
//base->t_ |= new_leaf->t_;
}
......
......@@ -63,6 +63,7 @@ struct AST {
bool t_null;
bool t_ellipsis;
bool t_label;
bool t_override;
long long int intval;
double floatval;
......
......@@ -121,6 +121,7 @@ void find_close_parentheses(int);
"__crust_not_null__" { return prepare_leaf(0,0.0,CRUST_NOT_NULL); }
"__crust_set_null__" { return prepare_leaf(0,0.0,CRUST_SET_NULL); }
"__crust_set_not_null__" { return prepare_leaf(0,0.0,CRUST_SET_NOT_NULL); }
"__crust_override__" { return prepare_leaf(0,0.0,CRUST_OVERRIDE); }
{L}({L}|{D})* { return prepare_leaf(0,0.0,TYPENAME_IDENTIFIER); }
......
......@@ -75,6 +75,7 @@ void add_type_element(char *);
%token CRUST_NO_ZERO
%token CRUST_SET_NULL
%token CRUST_SET_NOT_NULL
%token CRUST_OVERRIDE
//%start translation_unit
%start start_unit
......@@ -101,7 +102,8 @@ primary_expression
long_string_literal
: STRING_LITERAL { $$ = $1; show_debug(__LINE__, $$, "long_string_literal"); }
| long_string_literal STRING_LITERAL { int size1 = strlen($1->data);
| long_string_literal STRING_LITERAL { /* support for "xxxxx""yyy" strings */
int size1 = strlen($1->data);
char *data = (char *)malloc(size1 + strlen($2->data) - 1);
strcpy(data,$1->data);
data[size1 - 1] = 0; // remove the last double quote
......@@ -375,6 +377,9 @@ declaration
}
;
override_declaration
: CRUST_OVERRIDE declaration { $$ = $2; $$->t_override = true; }
declaration_specifiers
: storage_class_specifier { $$ = $1; show_debug(__LINE__, $$, "declaration_specifiers"); }
| storage_class_specifier declaration_specifiers { $$ = $1; show_debug(__LINE__, $$, "declaration_specifiers");
......@@ -878,6 +883,7 @@ block_item_list
block_item
: declaration { $$ = $1; show_debug(__LINE__, $$, "block_item"); }
| override_declaration { $$ = $1; show_debug(__LINE__, $$, "block_item"); }
| statement { $$ = $1; show_debug(__LINE__, $$, "block_item"); }
| CRUST_ENABLE { $$ = $1; show_debug(__LINE__, $$, "block_item"); }
| CRUST_DISABLE { $$ = $1; show_debug(__LINE__, $$, "block_item"); }
......
......@@ -18,6 +18,5 @@ int main(crust_t var) {
}
a++;
}
return 0;
}
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