示例#1
0
 def findChild(self, search_child):
     """Locate a child node within this AstNode. Returns a tuple containing
        (property_name, index) where index may be None for non-indexable properties. Returns None
        if the child is not found"""
     for name, child in self.children.items():
         if isinstance(child, list):
             for index, subchild in enumerate(child):
                 if subchild is search_child:
                     return (underscoresToCamelCase(name), index)
         else:
             if child is search_child:
                return (underscoresToCamelCase(name), None)
     return (None, None) 
示例#2
0
 def _createChildListProperties(cls, name, bases, dict):    
     """
     Introspect the class being created to look for class members which
     contain 'declarative' [Node] objects. Move these declarations into the
     child_infos class member, and create getters, setters and properties
     to provide access to each of the child members.
     """
     list_infos = {}
     for info_name, v in dict.items():
         if isinstance(v, list) and isinstance(v[0], Node):
            list_infos[info_name] = v
             
     removal = []
     for info_name in list_infos.keys():
        property_name = underscoresToCamelCase(info_name)
        if info_name != property_name:
            removal.append(info_name)
        def _getProperty(self, info_name=info_name):
            return self._children[info_name]
        def _setProperty(self, value, info_name=info_name):
            self._children[info_name] = value
        if not hasprop(cls, property_name):
            setattr(cls, property_name, property(_getProperty, _setProperty))
                     
     for info_name in removal:
         delattr(cls, info_name)
 
     cls.child_infos.update(list_infos)
 def _setParent(self, parent, node, name, index=None):
     """
     Given a reference to the parent, and the name of a child value, create the
     property name and attach it, together with the reference to the parent, to
     the supplied node.
     """
     if node is not None:
         node.parent = parent
         node.parent_property = underscoresToCamelCase(name) # The property through which the parent can be accessed.
         node.parent_index = index
 def checkSignature(self, node):
     """
     Check the actualType of each child node against the formalType of each
     child node and determine if they are of compatible type. For example,
     IntegerType is compatible with NumericType, and NumericType is compatible
     with ScalarType, but StringType is not compatible with NumericType.
     """
     result = True
     for name, info in node.child_infos.items():
         if isinstance(info, list):
             info = info[0]
             formal_type = info.formalType
             child_nodes = getattr(node, underscoresToCamelCase(name))
             if child_nodes is not None:
                 for child_node in child_nodes:
                     child_result = self.checkType(node, child_node, formal_type, info)
                     result = result and child_result
         else:
             formal_type = info.formalType
             child_node = getattr(node, underscoresToCamelCase(name))
             child_result = self.checkType(node, child_node, formal_type, info)
             result = result and child_result
     return result