@Override public Node leave(Node old, Node n, NodeVisitor v) { if (CEExt_c.ext(n).isConditionSet()) { // it's a set condition! Call c = (Call) n; if (c.target() instanceof Local) { // ignore local conditions, we're only interested in fields } else if (c.target() instanceof Field) { Field f = (Field) c.target(); this.setConds.addAll(autil.abstractLocations(f)); } else { throw new InternalCompilerError("Can't handle " + n); } } if (n instanceof Call) { process((Call) n); } else if (n instanceof New) { process((New) n); } else if (n instanceof ConstructorCall) { process((ConstructorCall) n); } return n; }
private boolean expectsBoxed(Call call, Node arg) { // implicit this argument also is present if (call.target() == arg) return isBoxedType(call.target().type()); // targets of primitive types are unboxed int i = call.arguments().indexOf(arg); if (i < 0) throw new InternalCompilerError("BoxingPropagator: cannot find argument in call"); Type type = call.methodInstance().def().formalTypes().get(i).get(); return isBoxedType(type); }
protected void process(Call n) { CEProcedureCallExt ext = (CEProcedureCallExt) CEExt_c.ext(n); MethodInstance mi = n.methodInstance(); SetConditionsAbsVal scs = autil.call(mi, n); this.setConds.addAll(scs.setConditions()); ext.recordSetConditionsResults(this.autil.currentContext(), scs.setConditions()); }
@Override public Node typeCheck(ContextVisitor tc) throws SemanticException { RuleDef sym = null; MethodInstance mi = call.methodInstance(); IbexClassType ct = (IbexClassType) mi.container(); for (RuleInstance rule : ct.rules()) { if (rule.name() == mi.name()) sym = rule.def(); } if (sym == null) throw new SemanticException("Cannot find rule for " + mi); RhsInvoke n = (RhsInvoke) symbol(sym.asNonterminal()).type(call.type()); if (assocTag) { Context c = tc.context(); CodeDef code = c.currentCode(); if (code instanceof RuleDef) { RuleDef rd = (RuleDef) code; if (rd != sym) throw new SemanticException( "Associativity annotation must be self-recursive.", position()); } } if (!call.type().isVoid()) { TypeSystem ts = tc.typeSystem(); LocalDef li = ts.localDef(position(), Flags.FINAL, Types.ref(call.type()), call.name().id()); // Formal parameters are never compile-time constants. li.setNotConstant(); IbexNodeFactory nf = (IbexNodeFactory) tc.nodeFactory(); LocalDecl ld = nf.LocalDecl( position(), nf.FlagsNode(position(), li.flags()), nf.CanonicalTypeNode(position(), li.type()), nf.Id(position(), li.name())); ld = ld.localDef(li); ld = ld.init(n); return nf.RhsSyntheticBind(position(), ld).type(n.type()); } return n; }
public String toString() { return (assocTag ? "^" : "") + call.toString(); }
private Node translateExtendedFor(ExtendedFor n, List<String> labels) throws SemanticException { if (n.expr().type().isArray()) { return translateExtForArray(n, labels); } Position pos = Position.compilerGenerated(); Type iterType = ts.typeForName("java.util.Iterator"); Type iteratedType = n.decl().type().type(); // translate "L1,...,Ln: for (C x: e) b" to // "{ Iterator iter = e.iterator(); L1,...,Ln: while (iter.hasNext();) { C x = (C)iter.next(); // b }" // Create the iter declaration "Iterator iter = e.iterator()" Id iterName = freshName("iter"); LocalDecl iterDecl; LocalInstance iterLI = ts.localInstance(pos, Flags.NONE, iterType, iterName.id()); { Id id = nodeFactory().Id(pos, "iterator"); Call iterator = nodeFactory().Call(pos, n.expr(), id); iterator = (Call) iterator.type(iterType); iterator = iterator.methodInstance( ts.findMethod( n.expr().type().toClass(), "iterator", Collections.<Type>emptyList(), this.context().currentClass())); iterDecl = nodeFactory() .LocalDecl( pos, Flags.NONE, nodeFactory().CanonicalTypeNode(pos, iterType), iterName, iterator); iterDecl = iterDecl.localInstance(iterLI); } // create the loop body List<Stmt> loopBody = new ArrayList<Stmt>(); { Id id = nodeFactory().Id(pos, "next"); Call call = nodeFactory() .Call( pos, ((Local) nodeFactory().Local(pos, iterName).type(iterType)) .localInstance(iterDecl.localInstance()), id); call = (Call) call.type(ts.Object()); call = call.methodInstance( ts.findMethod( iterType.toClass(), "next", Collections.<Type>emptyList(), this.context().currentClass())); Cast cast = nodeFactory().Cast(pos, nodeFactory().CanonicalTypeNode(pos, iteratedType), call); cast = (Cast) cast.type(iteratedType); loopBody.add(n.decl().init(cast)); loopBody.add(n.body()); } // create the while loop While loop; { Id id = nodeFactory().Id(pos, "hasNext"); Call cond = nodeFactory() .Call( pos, ((Local) nodeFactory().Local(pos, iterName).type(iterType)) .localInstance(iterDecl.localInstance()), id); cond = (Call) cond.type(ts.Boolean()); cond = cond.methodInstance( ts.findMethod( iterType.toClass(), "hasNext", Collections.<Type>emptyList(), this.context().currentClass())); loop = nodeFactory().While(pos, cond, nodeFactory().Block(pos, loopBody)); } return nodeFactory().Block(pos, iterDecl, labelStmt(loop, labels)); }
public CallSiteType getCallSiteType(Call call) { return callGraph.isParallel(call.methodInstance().def()) ? CallSiteType.CONCURRENT_CALL : CallSiteType.NORMAL; }