def __init__(self, node, c=None): if node == None or node.name != "FieldDeclaration": self.mods = [] self.name = "" self.type = None else: self.mods = ast.get_modifiers(node.find_child("Modifiers")) self.name = node.find_child("Identifier").value.value self.type = c.get_type(node.find_child("Type")) node.obj = self if c != None and c.interface: self.mods.append("Abstract") self.node = node self.declared_in = c
def __init__(self, node, c=None): if node == None or (node.name != "MethodDeclaration" and node.name != "ConstructorDeclaration"): self.mods = [] self.type = None self.name = "" self.params = [] else: self.mods = ast.get_modifiers(node.find_child("Modifiers")) if node.name == "ConstructorDeclaration": self.type = None else: self.type = c.get_type(node.find_child("Type")) self.name = node.find_child("Identifier").value.value self.params = c.get_parameters(node.find_child("Parameters")) node.obj = self if c != None and c.interface: self.mods.append("Abstract") self.node = node self.declared_in = c
def typecheck_local_var_decl(node, c, method, t_i, c_i): type_node = node.find_child('Type') init_node = node.find_child('Initializer') if type_node == None or init_node == None: logging.error('FATAL ERROR: typecheck_var_decl') sys.exit(1) # Extract type from Type node. var_type = type_node.canon initializer_type = var_type if len(init_node.children) == 1: initializer_type = typecheck_expr(init_node[0], c, method, t_i, c_i) if is_assignable(var_type, initializer_type, c_i): node.typ = var_type return node.typ else: logging.error('Invalid initializer for variable of type %s to %s' % (initializer_type, var_type)) sys.exit(42)