Exemple #1
0
    def visit_FuncDecl(self, node):
        if node.identifier is not None:
            name = node.identifier.value
            self.visit_Identifier(node.identifier)
        else:
            name = None

        func_sym = FuncSymbol(name=name, enclosing_scope=self.current_scope)
        if name is not None:
            if func_sym not in self.current_scope:
                self.current_scope.define(func_sym)
            #else:
            #self.current_scope.symbols[name].usage+=1

            #self.current_scope.define(func_sym)
            node.scope = self.current_scope

        # push function scope
        self.current_scope = func_sym
        for ident in node.parameters:

            symbol = VarSymbol(name=ident.value)
            if symbol not in self.current_scope:
                self.current_scope.define(symbol)
            else:
                self.current_scope.symbols[ident.value].usage += 1
            ident.scope = self.current_scope

        for element in node.elements:
            self.visit(element)

        # pop the function scope
        self.current_scope = self.current_scope.get_enclosing_scope()
Exemple #2
0
 def visit_VarDecl(self, node):
     ident = node.identifier
     symbol = VarSymbol(name=ident.value)
     if symbol not in self.current_scope:
         self.current_scope.define(symbol)
     ident.scope = self.current_scope
     self.visit(node.initializer)
Exemple #3
0
    def visit_Catch(self, node):
        # The catch identifier actually lives in a new scope, but additional
        # variables defined in the catch statement belong to the outer scope.
        # For the sake of simplicity we just reuse any existing variables
        # from the outer scope if they exist.
        ident = node.identifier
        existing_symbol = self.current_scope.symbols.get(ident.value)
        if existing_symbol is None:
            self.current_scope.define(VarSymbol(ident.value))
        ident.scope = self.current_scope

        for element in node.elements:
            self.visit(element)
Exemple #4
0
 def visit_Assign(self, node):
     ident = node.left
     if type(ident).__name__ != 'BracketAccessor' and type(
             ident).__name__ != 'DotAccessor':
         symbol = VarSymbol(name=ident.value)
         if symbol not in self.current_scope:
             self.current_scope.define(symbol)
         '''
         var a = 2;
         var a = 3;
         should still be unused
         '''
         #else:usage shouldn't go up when variables get reassigned
         #self.current_scope.symbols[ident.value].usage+=1
         ident.scope = self.current_scope
         ident._mangle_candidate = 0
         self.visit(node.right)
     else:
         for child in node:
             self.visit(child)
Exemple #5
0
    def visit_FuncDecl(self, node):
        if node.identifier is not None:
            name = node.identifier.value
            self.visit_Identifier(node.identifier)
        else:
            name = None

        func_sym = FuncSymbol(name=name, enclosing_scope=self.current_scope)
        if name is not None:
            self.current_scope.define(func_sym)
            node.scope = self.current_scope

        # push function scope
        self.current_scope = func_sym
        for ident in node.parameters:
            self.current_scope.define(VarSymbol(ident.value))
            ident.scope = self.current_scope

        for element in node.elements:
            self.visit(element)

        # pop the function scope
        self.current_scope = self.current_scope.get_enclosing_scope()