Exemplo n.º 1
0
    def semantic(self, scope):
        # HACK: check scope.symbols directly, because we do not care if outer
        # scopes have a symbol with the same name, only if two symbols have
        # the same name, and are at the same level.

        if self.__wasChecked: return self
        self.__wasChecked = True

        if scope.symbols.get(self.name, self) is not self:
            raise error.NameError, "A symbol named '%s' already exists in the current scope." % self.name

        scope[self.name] = self

        self.__checkBases(scope)
        self.__checkConcreteness(scope)

        childScope = Scope(parent=scope)
        childScope.klass = self

        # If the class has no constructors, define a default ctor
        from ast.ctor import Ctor, DefaultCtor
        hasCtor = bool([d for d in self.body.decls if isinstance(d, Ctor)])

        if not hasCtor:
            self.body.decls.append(DefaultCtor())

        self.body = self.body.semantic(childScope)

        return self
Exemplo n.º 2
0
    def semantic2(self, scope):
        childScope = Scope(parent=scope)
        childScope.klass = self

        self.body = self.body.semantic2(childScope)

        return self
Exemplo n.º 3
0
    def semantic(self, scope):
        if scope.symbols.get(self.name, self) is not self:
            raise error.NameError, "A symbol named '%s' already exists in the current scope." % self.name

        scope[self.name] = self

        childScope = Scope(parent=scope)
        childScope.klass = self
        self.body = self.body.semantic(childScope)
        return self