public Formal mangledFormal(AJNodeFactory nf, AJTypeSystem ts) {
   TypeNode tn = nf.CanonicalTypeNode(position, mangleType);
   String name = UniqueID.newID("formal");
   Formal mangledFormal = nf.Formal(position, Flags.NONE, tn, name);
   LocalInstance li = ts.localInstance(position, Flags.NONE, mangleType, name);
   return mangledFormal.localInstance(li);
 }
示例#2
0
  /** Perform the appropriate flow operations for declaration of a formal parameter */
  protected Map flowFormal(DataFlowItem inItem, FlowGraph graph, Formal f, Set succEdgeKeys) {
    Map m = new HashMap(inItem.initStatus);
    // a formal argument is always defined.
    m.put(f.localInstance(), new MinMaxInitCount(InitCount.ONE, InitCount.ONE));

    // record the fact that we have seen the formal declaration
    currCBI.localDeclarations.add(f.localInstance());

    return itemToMap(new DataFlowItem(m), succEdgeKeys);
  }
  private Node buildFormal(Formal f) throws SemanticException // Based on buildLocalDecl.
      {
    Type t = f.declType();
    SJLocalInstance li = (SJLocalInstance) f.localInstance();

    if (t.isSubtype(SJ_ABSTRACT_CHANNEL_TYPE)) {
      if (!(f instanceof SJFormal)) {
        throw new SemanticException(
            "[SJProtocolDeclTypeBuilder] Session socket parameters should be declared by their session type: "
                + f);
      }

      SJTypeNode tn = disambiguateSJTypeNode(this, ((SJFormal) f).sessionType());
      SJSessionType st = tn.type();
      String sjname = f.name(); // Should match that given by SJVariable.sjname.

      f = f.localInstance(sjts.SJLocalProtocolInstance(li, st, sjname));
      f = setSJFormalExt((SJFormal) f, tn, sjname);
    }

    return f;
  }
示例#4
0
  @Override
  protected void genMethods() throws SemanticException {

    CodeBlockSynth fastBodySynth = fastMSynth.getMethodBodySynth(compilerPos);
    CodeBlockSynth resumeBodySynth = resumeMSynth.getMethodBodySynth(compilerPos);
    CodeBlockSynth backBodySynth = backMSynth.getMethodBodySynth(compilerPos);

    AbstractWSClassGen childFrameGen =
        genChildFrame(xts.RegularFrame(), codeBlock, WSUtil.getBlockFrameClassName(getClassName()));
    List<Stmt> stmts = wsynth.genInvocateFrameStmts(1, classSynth, fastMSynth, childFrameGen);

    // now add codes to three path;
    // FIXME: just a simple try. Not correct
    // Some style
    // try {  child frame call }
    // catch { original code but replace the local var access with field access}
    // finally {still replace the local var access with field access}
    //

    // fast path & resume path
    Block tryBlockFast = xnf.Block(tryStmt.tryBlock().position(), stmts);
    Block tryBlockResume =
        xnf.Block(tryStmt.tryBlock().position(), wsynth.genRethrowStmt(resumeMSynth));

    Try tryFast = tryStmt.tryBlock(tryBlockFast);
    Try tryResume = tryStmt.tryBlock(tryBlockResume);

    List<Catch> catchBlocksFast = new ArrayList<Catch>();
    List<Catch> catchBlocksResume = new ArrayList<Catch>();

    Name formalName = xct.getNewVarName();

    Formal fa = synth.createFormal(compilerPos, xts.Abort(), formalName, Flags.NONE);
    Stmt ea =
        xnf.Throw(
            compilerPos,
            xnf.Local(compilerPos, xnf.Id(compilerPos, formalName))
                .localInstance(fa.localDef().asInstance())
                .type(xts.Abort()));
    Catch ca = xnf.Catch(compilerPos, fa, xnf.Block(compilerPos, ea));

    catchBlocksFast.add(ca);
    catchBlocksResume.add(ca);
    for (Catch c : tryStmt.catchBlocks()) {
      // note there is only one local var, the exception
      int pc = 1; // No need the pc;
      TransCodes catchBody =
          transNormalStmt(c.body(), pc, Collections.singleton(c.formal().name().id()));
      catchBlocksFast.add(c.body(WSUtil.stmtToBlock(xnf, catchBody.getFastStmts().get(0))));
      catchBlocksResume.add(c.body(WSUtil.stmtToBlock(xnf, catchBody.getResumeStmts().get(0))));
    }
    tryFast = tryFast.catchBlocks(catchBlocksFast);
    tryResume = tryResume.catchBlocks(catchBlocksResume);

    if (tryStmt.finallyBlock() != null) {
      int pc = 1;
      TransCodes finalBody = transNormalStmt(tryStmt.finallyBlock(), pc, Collections.EMPTY_SET);
      tryFast.finallyBlock(WSUtil.stmtToBlock(xnf, finalBody.getFastStmts().get(0)));
      tryResume.finallyBlock(WSUtil.stmtToBlock(xnf, finalBody.getResumeStmts().get(0)));
    }
    fastBodySynth.addStmt(tryFast);
    resumeBodySynth.addStmt(tryResume);
  }