Changeset 1259 for proto


Ignore:
Timestamp:
Aug 3, 2011, 1:17:33 AM (8 years ago)
Author:
shermer
Message:

Added symbol-table handling to AST interface, to the base AST node implementation, and to specific node types that represent a scope.

Also added two convenience methods to StructFieldASTB to get the structure and field names.

This is a partial commit of a working copy, but it should create a working revision.

Location:
proto/pebble/trunk/src/ast
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • proto/pebble/trunk/src/ast/AST.java

    r1242 r1259  
    33import java.util.List;
    44
     5import symbolTable.SymbolTable;
    56import symbolTable.Type;
    67import util.PStringBuilder;
     
    3637        public Type getType();
    3738
     39        // Some nodes are the base of a variable-name scope,
     40        // and so have a symbol table.
     41        public boolean hasSymbolTable();
     42        public void setSymbolTable(SymbolTable symbolTable);
     43        public SymbolTable getSymbolTable();
     44        public SymbolTable getEnclosingSymbolTable();   // does not include the node's own ST.
     45       
    3846        // Some nodes have an arbitrary list of children rather than specific ones.
    3947        // This signals that their children can simply remove themselves.
  • proto/pebble/trunk/src/ast/baseNodes/NodeImp.java

    r1242 r1259  
    99
    1010import symbolTable.PrimitiveType;
     11import symbolTable.SymbolTable;
    1112import symbolTable.Type;
    1213import util.PStringBuilder;
     
    1718        private AST parent;
    1819        private Type type;                      // common to enough nodes that it is included here.
     20        private SymbolTable symbolTable;
    1921
    2022        public NodeImp() {
     
    4143        }
    4244
    43        
     45        ///////////////////////////////////////////////////////////
     46        // scope
     47        ///////////////////////////////////////////////////////////
     48        public boolean hasSymbolTable() {
     49                return symbolTable != null;
     50        }
     51        public void setSymbolTable(SymbolTable symbolTable) {
     52                this.symbolTable = symbolTable;
     53        }
     54        public SymbolTable getSymbolTable() {
     55                return symbolTable;
     56        }
     57        public SymbolTable getEnclosingSymbolTable() {
     58                for(AST ancestor: pathToRoot()) {
     59                        if(ancestor.hasSymbolTable())
     60                                return ancestor.getSymbolTable();
     61                }
     62                return null;    // if tree has ProgramASTN at top, this won't happen.
     63        }
     64
    4465        ///////////////////////////////////////////////////////////
    4566        // parent
     
    113134        public AST copy() {
    114135                AST other = copyThisNode();
     136                other.setType(type);            // should be type.copy?
    115137                copyChildrenTo(other);
    116138                return other;
  • proto/pebble/trunk/src/ast/exprNodes/StructFieldASTB.java

    r1258 r1259  
    2222                addChild(operand2);
    2323        }
     24
     25        ///////////////////////////////////////////////////////////
     26        // node features - fancy access to subnodes.
     27        ///////////////////////////////////////////////////////////
     28        public String structName() {
     29                AST struct = getChild(0);
     30                VariableASTB vStruct = (VariableASTB)struct;
     31                return vStruct.getName();
     32        }
     33        public String fieldName() {
     34                AST field = getChild(1);
     35                VariableASTB vField = (VariableASTB)field;
     36                return vField.getName();
     37        }
     38       
    2439        ///////////////////////////////////////////////////////////
    2540        // BoolExpr features
  • proto/pebble/trunk/src/ast/nodes/BlockStatementASTN.java

    r1242 r1259  
    22
    33import lexicalStream.LexicalCollector;
     4import symbolTable.SymbolTable;
    45import util.PStringBuilder;
    56import ast.AST;
     
    3031                assumptions = null;
    3132                collector = new LexicalCollector();
     33                setSymbolTable(new SymbolTable(this));
    3234        }       
    3335       
  • proto/pebble/trunk/src/ast/nodes/ExecutionBlockASTN.java

    r1242 r1259  
    11package ast.nodes;
    22
     3import symbolTable.SymbolTable;
    34import lexicalStream.LexicalCollector;
    45import ast.AST;
     
    2526                super();
    2627                collector = new LexicalCollector();
     28                setSymbolTable(new SymbolTable(this));
    2729        }
    2830        public ExecutionBlockASTN(String name, boolean isMacro) {
     
    3032                collector = new LexicalCollector();
    3133                this.isMacro = isMacro;
     34                setSymbolTable(new SymbolTable(this));
    3235        }
    3336
  • proto/pebble/trunk/src/ast/nodes/ProgramBlockASTN.java

    r1242 r1259  
    11package ast.nodes;
    22
     3import symbolTable.SymbolTable;
    34import lexicalStream.LexicalCollector;
    45import ast.AST;
     
    1819                super();
    1920                collector = new LexicalCollector();
     21                setSymbolTable(new SymbolTable(this));
    2022        }
    2123        public ProgramBlockASTN(String name) {
    2224                super(name);
    2325                collector = new LexicalCollector();
     26                setSymbolTable(new SymbolTable(this));
    2427        }
    2528
  • proto/pebble/trunk/src/ast/nodes/StructBlockASTN.java

    r1242 r1259  
    11package ast.nodes;
    22
     3import symbolTable.SymbolTable;
    34import ast.AST;
    45import ast.ASTVisitor;
     
    1920        public StructBlockASTN() {
    2021                super();
     22                setSymbolTable(new SymbolTable(this));
    2123        }
    2224        public StructBlockASTN(String name) {
    2325                super(name);
     26                setSymbolTable(new SymbolTable(this));
    2427        }
    2528
Note: See TracChangeset for help on using the changeset viewer.