def __check_scope_and_type(self, _class): """ Check scope and type for each class. If it's a method, goes recursively inside the body. When a scope is created? With a new block, let, case, OBS: Every attribute is private and every method is public. """ for feature in _class.feature_list: _type = returned_type(feature, _class) if isAttribute(feature): value_type = get_expression_type(feature.body, _class, self.scope) # Test if the attribute value type is the same as declared. if feature.type != value_type: raise AttributeTypeError(feature, value_type) self.scope.add(feature.name, _type) elif isMethod(feature): self.scope.add(feature.name, _type) # Add arguments to scope. name:type for formal in feature.formal_list: self.scope.add(formal[0], formal[1]) self.__check_children(feature.body, _class)
def __check_scope_and_type(self, _class): """ Check scope and type for each class. If it's a method, goes recursively inside the body. When a scope is created? With a new block, let, case, OBS: Every attribute is private and every method is public. """ for feature in _class.feature_list: _type = returned_type(feature, _class) if isAttribute(feature): value_type = get_expression_type( feature.body, _class, self.scope ) # Test if the attribute value type is the same as declared. if feature.type != value_type: raise AttributeTypeError(feature, value_type) self.scope.add(feature.name, _type) elif isMethod(feature): self.scope.add(feature.name, _type) # Add arguments to scope. name:type for formal in feature.formal_list: self.scope.add(formal[0], formal[1]) self.__check_children(feature.body, _class)
def __get_attributes(self, _class): return [i for i in _class.feature_list if isAttribute(i)]