예제 #1
0
파일: Expression.py 프로젝트: qram9/c_ast
    def __init__(self):
        """Expression type is somewhat of an C++/Java abstract type, 
__init__ must only be called by a subclass. 
Sets _needs_parens to False. User may set it 
to true in a subclass to add a parenthesis expression"""
        self._needs_parens = False
        Traversable.__init__(self)
예제 #2
0
파일: Expression.py 프로젝트: qram9/c_ast
    def setChild(self, which, t):
        """Overrides Traversable's setChild to 
enforce the rule that a child of an Expression must be 
type Expression"""
        if isinstance(t, Expression):
            Traversable.setChild(self, which, t)
        else:
            raise ChildNotAnExpressionError(str(type(t)))
        return self
예제 #3
0
 def __init__(self):
     """Initializes SymbolTable with a new dict type"""
     self.currSyms = {}
     Traversable.__init__(self)
예제 #4
0
파일: Declaration.py 프로젝트: qram9/c_ast
    def setParent(self, t):
        """Overrides the setParent in Traversable to
catch unsupported parent node"""
        self._catchParentNotCorrectType(t)
        Traversable.setParent(self, t)
예제 #5
0
파일: Declaration.py 프로젝트: qram9/c_ast
    def removeChild(self, t):
        """Overrides the Traversable removeChild to 
catch unsupported referenced nodes"""
        self._catchChildNotCorrectType(t)
        Traversable.removeChild(self, t)
예제 #6
0
파일: Declaration.py 프로젝트: qram9/c_ast
    def setChild(self, which, t):
        """Overrides the Traversable setChild to catch
unsupported child nodes"""
        self._catchChildNotCorrectType(t)
        Traversable.setChild(self, which, t)
예제 #7
0
파일: Declaration.py 프로젝트: qram9/c_ast
 def __init__(self, size=1):
     Traversable.__init__(self)
     self.setNumChildren(size)
예제 #8
0
파일: Expression.py 프로젝트: qram9/c_ast
        """Returns a dict representing the contents of 
this Expression object and its base classes 
instances' contents. Uses the items() function.
Contents added here is _needs_parens, by calling
'items' function"""
        return dict(self.items())

    def __setstate__(self, statedict):
        """Blindly calls setattr with entried from hir. 
__getstate__ like string->attr dict"""
        for k, v in list(statedict.items()):
            setattr(self, k, v)

if __name__ == '__main__':
    exp = Expression()
    #    exp.testIfNoChild()
    #    exp.testIfNoParent()
    tra = Traversable()
    exp.setParens(True)
    exp.setParent(tra)
    exp.setNumChildren(2)
    chi1 = Expression()
    chi2 = Expression()
    exp.setChild(0, chi1)
    exp.setChild(1, chi2)
    #    exp.getChild(100)
    #    exp.setChild(1,1)
    #    exp.setChild(100,chi1)
    print((repr(exp)))
#    exp.setParent(1)
예제 #9
0
 def __init__(self):
     Traversable.__init__(self)
예제 #10
0
 def __init__(self):
     Traversable.__init__(self)
     self.setNumChildren(0)