Commit e636481d authored by Sergio Costas's avatar Sergio Costas

Now the aliases work

parent 6eb67114
......@@ -341,7 +341,7 @@ class crust(object):
#remove the alias variable from the old aliased variable
new_aliases = []
for a in base_alias["aliases"]:
if a is not var_alias["uid"]:
if a != var_alias["uid"]:
new_aliases.append(a)
base_alias["aliases"] = new_aliases
var_alias["aliases"] = None
......@@ -480,6 +480,8 @@ class crust(object):
retvals = []
for v in values:
dest_data = self._find_variable(v["varlist"], dest_var.name, statement.line)
dest_status = dest_data["status"]
orig_type = v["type"]
if v["node"] is not None:
orig_var = self._find_variable(v["varlist"], v["node"].name, v["node"].line)
......@@ -489,6 +491,9 @@ class crust(object):
self._add_error(v["varlist"], self.MSG_ERROR, "Assigning the crust-type result value of function '{:s}' at line {:d} to the non-crust variable {:s}", statement.name, statement.line, orig_var["name"])
if (not ret_value["crust"]) and (dest_type == self.TYPE_CRUST):
self._add_error(v["varlist"], self.MSG_ERROR, "Assigning the non-crust-type result value of function '{:s}' at line {:d} to the crust variable {:s}", statement.name, statement.line, orig_var["name"])
if dest_data["alias"]:
self._remove_alias(v["varlist"],dest_data)
self._set_var_value(v["varlist"], dest_var.name, v["status"], statement.line, False, False, True)
else:
if orig_var["borrowed"] and (v["node"].right is None):
self._add_error(var_container, self.MSG_ERROR,"Assigning a borrowed block into a local variable is not allowed (assigning '{:s}' at line {:d})",orig_var["name"],statement.line)
......@@ -496,16 +501,22 @@ class crust(object):
self._add_error(v["varlist"], self.MSG_CRITICAL, "Assigning the crust variable '{:s}' to the non-crust variable '{:s}' at line {:d}", v["node"].name, dest_data["name"], statement.line)
if (orig_type == self.TYPE_NO_CRUST) and (dest_type == self.TYPE_CRUST):
self._add_error(v["varlist"], self.MSG_CRITICAL, "Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}", v["node"].name, dest_data["name"], statement.line)
if (orig_type == self.TYPE_CRUST) and self._check_statement_is_crust(v["node"],orig_var):
# only check and modify if the origin variable IS really a crust one, and is being managed as a crust one
self._check_can_be_used(v["varlist"], v["node"], statement.line)
self._set_var_value(v["varlist"], v["node"].name, self.STATUS_FREED, statement.line, True, True)
if dest_data["alias"]:
self._assign_alias(v["varlist"],dest_data,orig_var,v["status"])
else:
if (orig_type == self.TYPE_CRUST) and self._check_statement_is_crust(v["node"],orig_var):
# only check and modify if the origin variable IS really a crust one, and is being managed as a crust one
self._check_can_be_used(v["varlist"], v["node"], statement.line)
self._set_var_value(v["varlist"], v["node"].name, self.STATUS_FREED, statement.line, True, True)
else:
if (orig_type == self.TYPE_CRUST) and (dest_type == self.TYPE_NO_CRUST):
self._add_error(v["varlist"], self.MSG_CRITICAL, "Assigning a crust pointer to the non-crust variable '{:s}' at line {:d}", dest_data["name"], statement.line)
if (orig_type == self.TYPE_NO_CRUST) and (dest_type == self.TYPE_CRUST):
self._add_error(v["varlist"], self.MSG_CRITICAL, "Assigning a non-crust value to the crust variable '{:s}' at line {:d}", dest_data["name"], statement.line)
if dest_var.right is None:
if dest_data["alias"]:
self._remove_alias(v["varlist"],dest_data)
self._set_var_value(v["varlist"], dest_var.name, v["status"], statement.line, False, False, True)
if (dest_var.right is None) and (not dest_data["alias"]):
self._set_var_value(v["varlist"], dest_var.name, v["status"], statement.line)
retvals.append( { "varlist":v["varlist"], "status":v["status"], "type":dest_type, "condition":self._status_to_condition(v["status"]), "node":dest_var} )
return retvals
......
......@@ -5,6 +5,6 @@ typedef __crust_t__ int *crust_t;
void main(crust_t param) {
crust_t __crust_alias__ an_alias = param;
main(an_alias); // this must work, and no error has to be emited because 'param' has been freed, because it is aliased by 'an_alias'
main(an_alias); // this must work, and no error has to be emited because 'param' has not been freed, because it is aliased by 'an_alias'
__crust_debug__
}
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