From dba9c486bfe77e7bd67cbf31ead19e73b971b542 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 16 Apr 2015 10:55:30 +0100 Subject: giscanner: Store parent link in AST for TypeContainer instances It is useful for navigating the AST to have a link from each TypeContainer instance (e.g. each Parameter and Return) to the parent AST node, such as a Function. This will be used in the g-ir-diff tool. https://bugzilla.gnome.org/show_bug.cgi?id=747979 --- giscanner/ast.py | 32 ++++++++++++++++++++++++++++++++ giscanner/girparser.py | 3 +++ 2 files changed, 35 insertions(+) (limited to 'giscanner') diff --git a/giscanner/ast.py b/giscanner/ast.py index f0fb7df1..721aafcd 100644 --- a/giscanner/ast.py +++ b/giscanner/ast.py @@ -665,6 +665,34 @@ class Callable(Node): self.instance_parameter = None # Parameter self.parent = None # A Class or Interface + def _get_retval(self): + return self._retval + + def _set_retval(self, value): + self._retval = value + if self._retval is not None: + self._retval.parent = self + retval = property(_get_retval, _set_retval) + + def _get_instance_parameter(self): + return self._instance_parameter + + def _set_instance_parameter(self, value): + self._instance_parameter = value + if value is not None: + value.parent = self + instance_parameter = property(_get_instance_parameter, + _set_instance_parameter) + + def _get_parameters(self): + return self._parameters + + def _set_parameters(self, value): + self._parameters = value + for param in self._parameters: + param.parent = self + parameters = property(_get_parameters, _set_parameters) + # Returns all parameters, including the instance parameter @property def all_parameters(self): @@ -703,6 +731,8 @@ class Function(Callable): # copy the parameters array so a change to self.parameters does not # influence clone.parameters. clone.parameters = self.parameters[:] + for param in clone.parameters: + param.parent = clone return clone def is_type_meta_function(self): @@ -839,6 +869,7 @@ class Parameter(TypeContainer): self.argname = argname self.direction = direction self.optional = optional + self.parent = None # A Callable if allow_none: if self.direction == PARAM_DIRECTION_OUT: @@ -858,6 +889,7 @@ class Return(TypeContainer): def __init__(self, rtype, nullable=False, transfer=None): TypeContainer.__init__(self, rtype, nullable, transfer) self.direction = PARAM_DIRECTION_OUT + self.parent = None # A Callable class Enum(Node, Registered): diff --git a/giscanner/girparser.py b/giscanner/girparser.py index 463ff9a9..57f3e908 100644 --- a/giscanner/girparser.py +++ b/giscanner/girparser.py @@ -371,6 +371,9 @@ class GIRParser(object): self._parse_type_array_length(parameters, returnnode, retval.type) + # Re-set the function's parameters to notify it of changes to the list. + func.parameters = parameters + self._parse_generic_attribs(node, func) self._namespace.track(func) -- cgit v1.2.1