Changeset 101

Show
Ignore:
Timestamp:
07/06/08 00:24:04 (6 months ago)
Author:
mb0
Message:

CLOSED - # 87: static members need their own scope.
http://axdt.org/ticket/87

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • axdt/trunk/org.axdt.as3/src/org/axdt/as3/imp/parser/AS3Parser.g

    r100 r101  
    219219    -- class 
    220220    ClassDeclaration$ClassDeclaration ::= Annotations Modifiers class$ IDENTIFIER$Name ClassExtends Implements ClassBody$Body 
     221    /. 
     222        $action_type.SymbolTable symbolTable; 
     223        public void setSymbolTable($action_type.SymbolTable symbolTable) { this.symbolTable = symbolTable; } 
     224        public $action_type.SymbolTable getSymbolTable() { return symbolTable; } 
     225    ./ 
    221226     
    222227    ClassExtends$Type ::= %empty | extends$ Name 
     
    577582                                if (n instanceof FunctionExpression) return ((FunctionExpression) n).getSymbolTable(); 
    578583                                if (n instanceof ClassBody) return ((ClassBody) n).getSymbolTable(); 
     584                                if (n instanceof ClassDeclaration) return ((ClassDeclaration) n).getSymbolTable(); 
    579585                                if (n instanceof InterfaceBody) return ((InterfaceBody) n).getSymbolTable(); 
    580586                                if (n instanceof ForStatement) return ((ForStatement) n).getSymbolTable(); 
  • axdt/trunk/org.axdt.as3/src/org/axdt/as3/imp/parser/SymbolTableVisitor.java

    r92 r101  
    1313import org.axdt.as3.imp.parser.Ast.Block; 
    1414import org.axdt.as3.imp.parser.Ast.ClassBody; 
     15import org.axdt.as3.imp.parser.Ast.ClassDeclaration; 
    1516import org.axdt.as3.imp.parser.Ast.CustomNamespace; 
    1617import org.axdt.as3.imp.parser.Ast.ExpressionStatement; 
     
    2122import org.axdt.as3.imp.parser.Ast.InterfaceBody; 
    2223import org.axdt.as3.imp.parser.Ast.MethodDeclaration; 
     24import org.axdt.as3.imp.parser.Ast.OtherMod; 
    2325import org.axdt.as3.imp.parser.Ast.PackageBody; 
    2426import org.axdt.as3.imp.parser.Ast.VariableDeclarator; 
     
    8082        } 
    8183 
     84        public boolean visit(ClassDeclaration n) { 
     85                n.setSymbolTable(pushNewTable()); 
     86                return true; 
     87        } 
     88 
    8289        public boolean visit(ClassBody n) { 
    8390                n.setSymbolTable(pushNewTable()); 
     
    115122                } 
    116123                for (Object o:n.getModifiers().getArrayList()) { 
    117                         if (o instanceof CustomNamespace) { 
     124                        if (o instanceof OtherMod && "static".equals(o.toString())) { 
     125                                symbol_table = symbol_table.getParent(); 
     126                        } else if (o instanceof CustomNamespace) { 
    118127                                name = o.toString() + "::" + name; 
    119                                 break; 
    120128                        } 
    121129                } 
     
    169177        public boolean visit(VariableDeclarator n) { 
    170178                IAst parent = n.getParent().getParent(); 
     179                SymbolTable symbol_table = peekTable(); 
    171180                String name = n.getName().toString(); 
    172181                if (parent instanceof FieldDeclaration) { 
    173182                        FieldDeclaration f = (FieldDeclaration) parent; 
    174183                        for (Object o:f.getModifiers().getArrayList()) { 
    175                                 if (o instanceof CustomNamespace) { 
     184                                if (o instanceof OtherMod && "static".equals(o.toString())) { 
     185                                        symbol_table = symbol_table.getParent(); 
     186                                } else if (o instanceof CustomNamespace) { 
    176187                                        name = o.toString() + "::" + name; 
    177                                         break; 
    178188                                } 
    179189                        } 
    180190                } 
    181                 if (!peekTable().create(name, n)) emitError(n, "Illegal redeclaration of " + name); 
     191                if (!symbol_table.create(name, n)) emitError(n, "Illegal redeclaration of " + name); 
    182192                return true; 
    183193        }