Commit f4bb039e authored by Sergio Costas's avatar Sergio Costas

Now detects fine when a return value is a pointer

Now process fine the return value
parent 5597ca94
......@@ -134,12 +134,12 @@ class crusty(object):
print (rv.stderr.decode("utf-8"))
return None
datasize = len(rv.stdout)
retval = self.libcrusty.parse_data(c_bool(False),c_char_p(filename.encode("utf8")),rv.stdout,datasize)
retval = self.libcrusty.parse_data(c_bool(True),c_char_p(filename.encode("utf8")),rv.stdout,datasize)
if retval:
tree = self._fix_tree(retval)
else:
# If there is an error, run again the parsing with VERBOSE = True to show the error to the user
self.libcrusty.parse_data(c_bool(True),c_char_p(filename.encode("utf8")),rv.stdout,datasize)
#self.libcrusty.parse_data(c_bool(True),c_char_p(filename.encode("utf8")),rv.stdout,datasize)
sys.exit(-1)
return tree
......@@ -297,6 +297,8 @@ class crusty(object):
elif state[0] == crusty.CONDITION_FALSE:
retvals += self._eval_assignment(assignment.child2,state[1],function_container)
return retvals
#elif assignment.type == "FUNCTION_CALL":
else:
print("assignment type Unknown {:s}".format(assignment.type))
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container)) ]
......@@ -324,7 +326,7 @@ class crusty(object):
return ((variable["properties"] & property) != 0)
def _get_variable_properties(self,node,is_parameter):
def _get_variable_properties(self,node, is_parameter, is_retval = False):
if not isinstance(node,self.AST_node):
return 0
retval = 0
......@@ -336,7 +338,10 @@ class crusty(object):
else:
self._add_error(self.MSG_CRITICAL,_("Parameter {:s} defined as __crust_t__ type at line {:d}, but it is not a pointer").format(node.name,node.line))
else:
self._add_error(self.MSG_CRITICAL,_("Variable {:s} is defined as __crust_t__ type at line {:d}, but it is not a pointer").format(node.name,node.line))
if is_retval:
self._add_error(self.MSG_CRITICAL,_("Return value for function {:s}, defined at line {:d}, is defined as __crust_t__ type, but it is not a pointer").format(node.name,node.line))
else:
self._add_error(self.MSG_CRITICAL,_("Variable {:s} is defined as __crust_t__ type at line {:d}, but it is not a pointer").format(node.name,node.line))
retval += crusty.PROPERTY_CRUST_VARIABLE
if (node.t_crusty_borrow or node.t_crusty_recycle):
if not is_parameter:
......@@ -368,9 +373,17 @@ class crusty(object):
var_container[0][node.name] = {"properties":self._get_variable_properties(node,False), "status":crusty.STATUS_GLOBAL, "init_line": None, "pointer": node.pointer }
continue
if (node.type == "FUNCTION_DECLARATION") or (node.type == "FUNCTION_DEFINITION"):
counter = 0
for parameter in node.function_params:
if parameter.t_crusty_recycle:
counter += 1
if counter > 1:
self._add_error(self.MSG_CRITICAL,_("The function {:s}, at line {:d}, has more than one RECYCLE parameter.").format(node.name,node.line))
if (counter != 0) and (not node.t_crusty):
self._add_error(self.MSG_CRITICAL,_("The function {:s}, at line {:d}, has a RECYCLE parameter, but doesn't return a CRUST pointer").format(node.name,node.line))
if not node.t_typedef:
# the first parameter is the return value
parameters = [self._get_variable_properties(node,False)]
parameters = [self._get_variable_properties(node,False,True)]
for parameter in node.function_params:
parameters.append( self._get_variable_properties(parameter,True) )
function_container[node.name] = parameters
......@@ -387,7 +400,7 @@ class crusty(object):
tmpvars = self._copy_container(var_container)
tmpvars.insert(0,{})
for element in node.function_params:
tmpvars[0][element.name] = {"properties":self._get_variable_properties(element,False), "status":crusty.STATUS_NOT_NULL_OR_NULL, "init_line": element.line, "pointer": element.pointer }
tmpvars[0][element.name] = {"properties":self._get_variable_properties(element,True), "status":crusty.STATUS_NOT_NULL_OR_NULL, "init_line": element.line, "pointer": element.pointer }
self._process_block(node.child1,tmpvars, function_container)
......
......@@ -683,6 +683,7 @@ function_definition
: declaration_specifiers declarator declaration_list compound_statement { $$ = $1; show_error(__LINE__, $$); }
| declaration_specifiers declarator compound_statement { $$ = $1;
$$->type = FUNCTION_DEFINITION;
$$->pointer += $2->pointer;
$$->name = strdup($2->name);
$$->function_params = $2->function_params;
$$->child1 = $3; }
......
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