Changeset 4168 for proto/s2k


Ignore:
Timestamp:
Sep 13, 2014, 3:20:20 AM (5 years ago)
Author:
ksherdy
Message:

Added s2k accessors and generators as required.

Location:
proto/s2k/trunk/framework/src/toolchain/s2k/ast
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/s2k/trunk/framework/src/toolchain/s2k/ast/Accessors.java

    r4108 r4168  
    88
    99import s2k.ast.*;
     10import sun.org.mozilla.javascript.ast.FunctionCall;
    1011import toolchain.s2k.lang.type.Type;
    1112
     
    1920        ////////////////////////////////////////////////////////////////////////////
    2021               
    21         public static IdisaFuncCallArgListNode argListNode(IdisaFuncCallNode node) {
     22        public static IdisaFuncCallArgListNode argsListNode(IdisaFuncCallNode node) {
    2223                ASTNode idisaFuncCallArgListNode = node.child(2);
    2324                assert idisaFuncCallArgListNode instanceof IdisaFuncCallArgListNode;
     
    2526        }
    2627       
     28    public static FieldWidthNode FieldWidthNode(IdisaFuncCallNode node) {
     29        ASTNode fieldWidthNode = node.child(1);
     30        assert fieldWidthNode instanceof FieldWidthNode;
     31        return (FieldWidthNode) fieldWidthNode;
     32    }   
     33       
    2734    public static int argCount(IdisaFuncCallNode node) {
    28         ASTNode argList = Accessors.argListNode(node);
     35        ASTNode argList = Accessors.argsListNode(node);
    2936        return argList.nChildren();
    3037    }
     
    339346        }
    340347        public static BlockStmtNode blockStmtNode(FilterDefNode node) {
    341                 ASTNode child = node.child(3);
     348                ASTNode child = node.child(2);
    342349                assert child instanceof BlockStmtNode;
    343350        return (BlockStmtNode) child;
     
    572579        public static final ASTNode NO_ENCLOSING_NODE = null;
    573580       
    574         public static BlockStmtNode getEnclosingBlockStmt(ASTNode node) {
    575             BlockStmtNode enclosingBlockStmt = (BlockStmtNode) getEnclosingNodeOfType(node, BlockStmtNode.class);
    576             assert enclosingBlockStmt != NO_ENCLOSING_NODE : "getEnclosingBlockStmt(node) has no ancestor of type 'BlockStmtNode'";
    577             return enclosingBlockStmt;
    578         }
    579 
     581    public static BlockStmtNode getEnclosingBlockStmt(ASTNode node) {
     582        BlockStmtNode enclosingBlockStmt = (BlockStmtNode) getEnclosingNodeOfType(node, BlockStmtNode.class);
     583        assert enclosingBlockStmt != NO_ENCLOSING_NODE : "getEnclosingBlockStmt(node) has no ancestor of type 'BlockStmtNode'";
     584        return enclosingBlockStmt;
     585    }
     586       
     587    public static ASTNode getEnclosingStmtWithinBlockStmt(ASTNode node) {
     588       
     589        System.out.println(node);
     590       
     591        assert hasEnclosingBlockStmt(node) : "getEnclosingBlockStmt(node) has no ancestor of type 'BlockStmtNode'";
     592       
     593        ASTNode lastExpr = node;
     594        ASTNode current = node.getParent();
     595        while(!(current instanceof BlockStmtNode)) {
     596           
     597            if(current instanceof IfStmtNode || current instanceof WhileStmtNode || current instanceof ReturnStmtNode || current instanceof AssignNode) {
     598                return current;
     599            }
     600           
     601            lastExpr = current;
     602            current = current.getParent();
     603        }
     604
     605        return lastExpr;
     606   
     607    }   
     608   
     609    public static boolean hasEnclosingBlockStmt(ASTNode node) {
     610        return hasEnclosingNodeOfType(node, BlockStmtNode.class);
     611    }     
     612           
    580613        public static boolean hasEnclosingWhileStmt(ASTNode node) {
    581614            return hasEnclosingNodeOfType(node, WhileStmtNode.class);
    582615        }
    583616       
     617        public static boolean hasEnclosingIfStmt(ASTNode node) {
     618        return hasEnclosingNodeOfType(node, IfStmtNode.class);
     619    }
     620
     621    public static boolean hasEnclosingReturnStmt(ASTNode node) {
     622        return hasEnclosingNodeOfType(node, ReturnStmtNode.class);
     623    }   
     624
     625    public static boolean hasEnclosingAssignmentStmt(ASTNode node) {
     626        return hasEnclosingNodeOfType(node, AssignNode.class);
     627    }   
     628   
    584629        public static boolean hasEnclosingNodeOfType(ASTNode node, Class<?> clazz) {
    585630            if(getEnclosingNodeOfType(node, clazz) != NO_ENCLOSING_NODE) {
     
    589634            }
    590635        }
     636       
     637
    591638       
    592639        public static ASTNode getEnclosingNodeOfType(ASTNode node, Class<?> clazz) {
  • proto/s2k/trunk/framework/src/toolchain/s2k/ast/Generators.java

    r4021 r4168  
    246246// KH: Unused (for now)
    247247//     
    248 //  public static IdisaFuncCallNode makeIdisaFuncCallNode(Locator locator, String packageName, String baseName, FieldWidthNode fieldWidth, ASTNode... args ) {
    249 //  CompoundIdentifierNode identifier = Generators.makeCompoundIdentifierNode(locator, packageName, baseName);   
    250 //  IdisaFuncCallNode idisaFuncCall = Generators.makeIdisaFuncCallNode(locator, identifier, fieldWidth, args);
    251 //  return idisaFuncCall;
    252 //}   
    253 //
    254 //public static IdisaFuncCallNode makeIdisaFuncCallNode(Locator locator, CompoundIdentifierNode identifier, FieldWidthNode fieldWidth, ASTNode... args) {
    255 //  IdisaFuncCallNode idisaFuncCall = new IdisaFuncCallNode(makeLextantToken(locator, Lextant.LANGLE));
    256 //  idisaFuncCall.appendChild(identifier);
    257 //  idisaFuncCall.appendChild(fieldWidth);
    258 // 
    259 // 
    260 //  idisaFuncCall.appendChild(new IdisaFuncCallArgListNode( Generators.makeLextantToken(locator, Lextant.LROUND)));   
    261 //  Generators.addIdisaFuncCallArgs(idisaFuncCall, args);
    262 //  return idisaFuncCall;
    263 //}
    264 //
    265 //private static void addIdisaFuncCallArgs(IdisaFuncCallNode node, ASTNode ...args) {
    266 //  if(args.length > 0) {
    267 //      for(ASTNode child: args) {
    268 //          Accessors.argListNode(node).appendChild(child.deepCopy());
    269 //      }
    270 //      Accessors.argListNode(node).setToken(args[0].getToken());
    271 //  }   
    272 //}     
    273 //
    274 //public static FieldWidthNode makeIdisaFieldWidthNode(Locator locator, int fw) {
    275 //  IntConstantToken fieldWidthConstant = Generators.makeIntegerConstantToken(locator, fw);
    276 //  FieldWidthNode fieldWidthNode = new FieldWidthNode(fieldWidthConstant);
    277 // 
    278 //  IntegerConstantNode integerConstant = Generators.makeIntegerConstantNode(locator, fw);
    279 //  fieldWidthNode.appendChild(integerConstant);
    280 // 
    281 //  return fieldWidthNode;
    282 //}     
    283        
     248public static IdisaFuncCallNode makeIdisaFuncCallNode(Locator locator, String packageName, String baseName, FieldWidthNode fieldWidth, ASTNode... args ) {
     249  CompoundIdentifierNode identifier = Generators.makeCompoundIdentifierNode(locator, packageName, baseName);   
     250  IdisaFuncCallNode idisaFuncCall = Generators.makeIdisaFuncCallNode(locator, identifier, fieldWidth, args);
     251  return idisaFuncCall;
     252}   
     253
     254public static IdisaFuncCallNode makeIdisaFuncCallNode(Locator locator, CompoundIdentifierNode identifier, FieldWidthNode fieldWidth, ASTNode... args) {
     255  IdisaFuncCallNode idisaFuncCall = new IdisaFuncCallNode(makeLextantToken(locator, Lextant.LANGLE));
     256  idisaFuncCall.appendChild(identifier);
     257  idisaFuncCall.appendChild(fieldWidth);
     258 
     259 
     260  idisaFuncCall.appendChild(new IdisaFuncCallArgListNode( Generators.makeLextantToken(locator, Lextant.LROUND)));   
     261  Generators.addIdisaFuncCallArgs(idisaFuncCall, args);
     262  return idisaFuncCall;
    284263}
     264
     265private static void addIdisaFuncCallArgs(IdisaFuncCallNode node, ASTNode ...args) {
     266  if(args.length > 0) {
     267      for(ASTNode child: args) {
     268          Accessors.argsListNode(node).appendChild(child.deepCopy());
     269      }
     270      Accessors.argsListNode(node).setToken(args[0].getToken());
     271  }   
     272}       
     273
     274public static FieldWidthNode makeIdisaFieldWidthNode(Locator locator, int fw) {
     275  IntConstantToken fieldWidthConstant = Generators.makeIntegerConstantToken(locator, fw);
     276  FieldWidthNode fieldWidthNode = new FieldWidthNode(fieldWidthConstant);
     277 
     278  IntegerConstantNode integerConstant = Generators.makeIntegerConstantNode(locator, fw);
     279  fieldWidthNode.appendChild(integerConstant);
     280 
     281  return fieldWidthNode;
     282}       
     283       
     284}
Note: See TracChangeset for help on using the changeset viewer.