@Override public int getKind() { return base.getKind(); }
@Override public int getKind() { return base.getKind(); }
private boolean inFunction() { for(CAstEntity e : getEnclosingEntities()) if(e.getKind() == CAstEntity.FUNCTION_ENTITY) return true; return false; }
private boolean inFunction() { for(CAstEntity e : getEnclosingEntities()) if(e.getKind() == CAstEntity.FUNCTION_ENTITY) return true; return false; }
@Override protected void leaveFieldEntity(CAstEntity n, WalkContext context, CAstVisitor<WalkContext> visitor) { // Define a new field in the enclosing type, if the language we're // processing allows such. CAstEntity topEntity = context.top(); // better be a type assert topEntity.getKind() == CAstEntity.TYPE_ENTITY : "Parent of field entity is not a type???"; defineField(topEntity, context, n); }
@Override protected void leaveFieldEntity(CAstEntity n, WalkContext context, CAstVisitor<WalkContext> visitor) { // Define a new field in the enclosing type, if the language we're // processing allows such. CAstEntity topEntity = context.top(); // better be a type assert topEntity.getKind() == CAstEntity.TYPE_ENTITY : "Parent of field entity is not a type???"; defineField(topEntity, context, n); }
@Override protected EntityContext makeCodeContext(EntityContext context, CAstEntity n) { if (n.getKind() == CAstEntity.FUNCTION_ENTITY) { // need to handle arguments String[] argumentNames = n.getArgumentNames(); for (String arg : argumentNames) { // System.err.println("declaration of " + arg + " in " + n); MapUtil.findOrCreateSet(entity2DeclaredNames, n).add(arg); } } return new EntityContext(n); }
@Override protected EntityContext makeCodeContext(EntityContext context, CAstEntity n) { if (n.getKind() == CAstEntity.FUNCTION_ENTITY) { // need to handle arguments String[] argumentNames = n.getArgumentNames(); for (String arg : argumentNames) { // System.err.println("declaration of " + arg + " in " + n); MapUtil.findOrCreateSet(entity2DeclaredNames, n).add(arg); } } return new EntityContext(n); }
@Override protected Position[] getParameterPositions(CAstEntity e) { if (e.getKind() == CAstEntity.SCRIPT_ENTITY) { return new Position[0]; } else { Position[] ps = new Position[ e.getArgumentCount() ]; for(int i = 2; i < e.getArgumentCount(); i++) { ps[i] = e.getPosition(i-2); } return ps; } }
@Override protected String composeEntityName(WalkContext parent, CAstEntity f) { if (f.getKind() == CAstEntity.SCRIPT_ENTITY) return f.getName(); else return parent.getName() + '/' + f.getName(); }
@Override protected Position[] getParameterPositions(CAstEntity e) { if (e.getKind() == CAstEntity.SCRIPT_ENTITY) { return new Position[0]; } else { Position[] ps = new Position[ e.getArgumentCount() ]; for(int i = 2; i < e.getArgumentCount(); i++) { ps[i] = e.getPosition(i-2); } return ps; } }
@Override protected void declareFunction(CAstEntity N, WalkContext context) { String fnName = composeEntityName(context, N); if (N.getKind() == CAstEntity.SCRIPT_ENTITY) { ((JavaScriptLoader) loader).defineScriptType('L' + fnName, N.getPosition(), N, context); } else if (N.getKind() == CAstEntity.FUNCTION_ENTITY) { ((JavaScriptLoader) loader).defineFunctionType('L' + fnName, N.getPosition(), N, context); } else { Assertions.UNREACHABLE(); } }
@Override protected String composeEntityName(WalkContext parent, CAstEntity f) { if (f.getKind() == CAstEntity.SCRIPT_ENTITY) return f.getName(); else return parent.getName() + '/' + f.getName(); }
@Override protected void declareFunction(CAstEntity N, WalkContext context) { String fnName = composeEntityName(context, N); if (N.getKind() == CAstEntity.SCRIPT_ENTITY) { ((JavaScriptLoader) loader).defineScriptType('L' + fnName, N.getPosition(), N, context); } else if (N.getKind() == CAstEntity.FUNCTION_ENTITY) { ((JavaScriptLoader) loader).defineFunctionType('L' + fnName, N.getPosition(), N, context); } else { Assertions.UNREACHABLE(); } }
@Override protected void defineField(CAstEntity topEntity, WalkContext definingContext, CAstEntity n) { assert topEntity.getKind() == CAstEntity.TYPE_ENTITY; assert n.getKind() == CAstEntity.FIELD_ENTITY; // N.B.: base class may actually ask to create a synthetic type to wrap // code bodies, so we may see other things than TYPE_ENTITY here. TypeName ownerName = makeType(topEntity.getType()).getName(); IClass owner = loader.lookupClass(ownerName); assert owner != null || exclusions.contains(ownerName.toString()) : ownerName + " not found in " + loader; if (owner != null) { ((JavaSourceLoaderImpl) loader).defineField(n, owner); } }
@Override protected void defineField(CAstEntity topEntity, WalkContext definingContext, CAstEntity n) { assert topEntity.getKind() == CAstEntity.TYPE_ENTITY; assert n.getKind() == CAstEntity.FIELD_ENTITY; // N.B.: base class may actually ask to create a synthetic type to wrap // code bodies, so we may see other things than TYPE_ENTITY here. TypeName ownerName = makeType(topEntity.getType()).getName(); IClass owner = loader.lookupClass(ownerName); assert owner != null || exclusions.contains(ownerName.toString()) : ownerName + " not found in " + loader; if (owner != null) { ((JavaSourceLoaderImpl) loader).defineField(n, owner); } }
@Override protected WalkContext makeCodeContext(WalkContext context, CAstEntity n) { AbstractScope scope; if (n.getKind() == CAstEntity.SCRIPT_ENTITY) scope = makeScriptScope(n, context.currentScope()); else scope = makeFunctionScope(n, context.currentScope()); return new CodeEntityContext(context, scope, n); }
@Override protected WalkContext makeCodeContext(WalkContext context, CAstEntity n) { AbstractScope scope; if (n.getKind() == CAstEntity.SCRIPT_ENTITY) scope = makeScriptScope(n, context.currentScope()); else scope = makeFunctionScope(n, context.currentScope()); return new CodeEntityContext(context, scope, n); }
@Override protected void leaveFunctionStmt(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { CAstEntity fn = (CAstEntity) n.getChild(0).getValue(); Scope cs = c.currentScope(); if (!cs.contains(fn.getName()) || cs.lookup(fn.getName()).getDefiningScope().getEntity().getKind() == CAstEntity.SCRIPT_ENTITY) { int result = processFunctionExpr(n, c); assignValue(n, c, cs.lookup(fn.getName()), fn.getName(), result); } else { super.leaveFunctionStmt(n, c, visitor); } } };
@Override protected void leaveFunctionStmt(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { CAstEntity fn = (CAstEntity) n.getChild(0).getValue(); Scope cs = c.currentScope(); if (!cs.contains(fn.getName()) || cs.lookup(fn.getName()).getDefiningScope().getEntity().getKind() == CAstEntity.SCRIPT_ENTITY) { int result = processFunctionExpr(n, c); assignValue(n, c, cs.lookup(fn.getName()), fn.getName(), result); } else { super.leaveFunctionStmt(n, c, visitor); } } };