예제 #1
0
    def visit_Scope(self, node):
        scope = []
        for a in node.args:
            if isinstance(a, module.GenerateIf):
                if a.true_scope is None:
                    raise TypeError("GenerateIf statement without scope name"
                                    "can not be used as an scope index.")
                scope.append(vast.IdentifierScopeLabel(a.true_scope))
            elif isinstance(a, module.GenerateIfElse):
                if a.false_scope is None:
                    raise TypeError(
                        "GenerateIfElse statement without scope name"
                        "can not be used as an scope index.")
                scope.append(vast.IdentifierScopeLabel(a.false_scope))
            elif isinstance(a, module.GenerateFor):
                raise TypeError("Scope index must not be GenerateFor. "
                                "Use slice, like 'obj[index]'")
            elif isinstance(a, vtypes.ScopeIndex):
                scope.append(self.visit(a))
            elif isinstance(a, str):
                scope.append(vast.IdentifierScopeLabel(a))
            else:
                _id = self.visit(a)
                if not isinstance(_id, vast.Identifier):
                    raise TypeError(
                        "Cannot convert into IdentifierScopeLabel from %s." %
                        str(type(_id)))
                scope.append(vast.IdentifierScopeLabel(_id.name))

        if len(scope) == 1: return vast.Identifier(scope[0].name)
        return vast.Identifier(scope[-1].name,
                               vast.IdentifierScope(tuple(scope[:-1])))
예제 #2
0
 def visit_ScopeIndex(self, node):
     name = node.name
     index = self.visit(node.index)
     return vast.IdentifierScopeLabel(name, index)