예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
 def __get_attributes(self, _class):
     return [i for i in _class.feature_list if isAttribute(i)]
예제 #4
0
 def __get_attributes(self, _class):
     return [i for i in _class.feature_list if isAttribute(i)]