p.print("\n#ifdef __CLUSTER_STANDALONE\n\n");   if (i == 0) { p.print("  message* "); } else { p.print("  "); }  p.print("__msg = new message("+size+", "+index+", ");
p.print("\n{\n#ifdef __CLUSTER_STANDALONE\n\n");  p.print("  message* __msg = new message("+size+", "+index+", ");
    public void visitMessageStatement(SIRMessageStatement self,                                      JExpression portal, String iname, String __ident,                                      JExpression[] params, SIRLatency latency) {        /*          p.print("//send_" + iname + "_" + ident + "(");          portal.accept(this);          p.print(", ");          latency.accept(this);          if (params != null)          for (int i = 0; i < params.length; i++)          if (params[i] != null)          {          p.print(", ");          params[i].accept(this);          }          p.print(");");        */        //String ident;        int num_params = 0;        if (portal instanceof SIRPortal) {            SIRStream receivers[] = ((SIRPortal) portal).getReceivers();            for (int i = 0; i < receivers.length; i++) {                int dst = NodeEnumerator.getSIROperatorId(receivers[i]);                if (ClusterBackend.debugPrint) {                    System.out.println("/* iname: " + iname + " ident: "                                       + self.getMessageName() + " type: "                                       + ((SIRPortal) portal).getPortalType().getCClass()                                       + "*/\n");                                        System.out.println("params size: " + params.length);                }                p.print("/*");                //                for (int y = 0;; y++) {                //                    // this causes only msg param to be output                //                    PRINT_MSG_PARAM = y;                //                    params[2].accept(this);                //                    if (PRINT_MSG_PARAM == -1)                //                        break; // no more params!                //                    num_params++;                //                    p.print(",");                //                }                for (int j = 0; j < params.length; j++) {                    params[j].accept(this);                    num_params++;                    if (j < params.length - 1) { p.print(",");}                }                                p.print(" num_params: " + num_params + "*/\n");                CClass pclass = ((SIRPortal) portal).getPortalType()                    .getCClass();                CMethod methods[] = pclass.getMethods();                int index = -1;                int size = 12; // size:4 mindex:4 exec_at:4                // int and float have size of 4 bytes                size += num_params * 4;                for (int t = 0; t < methods.length; t++) {                    if (ClusterBackend.debugPrint)                        System.out.println("/* has method: " + methods[t] + " */\n");                    if (methods[t].getIdent().equals(__ident)) {                        index = t;                        break;                    }                }                /*                  SIRStream dest_arr[] = ((SIRPortal)portal).getReceivers();                  System.out.println("Handler name is: "+ident);                   String ident2 = ident+"__";                  for (int t = 0; t < dest_arr.length; t++) {                  JMethodDeclaration m[] = dest_arr[t].getMethods();                  for (int z = 0; z < m.length; z++) {                  String name = m[z].getName();                  boolean guess = name.startsWith(ident2);                  System.out.println("== "+name+" == "+(guess?"***":""));                  if (guess) {                  System.out.println("ModState: "+ModState.methodModsState(m[z]));                  }                  }                  }                  int index = -1;                */                CType method_params[] = methods[index].getParameters();                /*                  if (params != null) {                  // int and float have size of 4 bytes                  size += params.length * 4;                   }                */                p.print("\n#ifdef __CLUSTER_STANDALONE\n\n");                // declare variable only first time through                if (i == 0) {                    p.print("  message* ");                } else {                    p.print("  ");                }                p.print("__msg = new message("+size+", "+index+", ");                if (latency instanceof SIRLatencyMax) {                    int max = ((SIRLatencyMax) latency).getMax();                    SIRFilter sender = (SIRFilter) NodeEnumerator                        .getOperator(selfID);                    SIRFilter receiver = (SIRFilter) NodeEnumerator                        .getOperator(dst);                    if (LatencyConstraints.isMessageDirectionDownstream(sender,                                                                        receiver)) {                        p.print("sdep_" + selfID + "_" + dst                                + "->getDstPhase4SrcPhase(__counter_" + selfID                                + "+" + max + "+1)-1);\n");                    } else {                        p.print("sdep_" + selfID + "_" + dst                                + "->getSrcPhase4DstPhase(__counter_" + selfID                                + "+" + max + "+1)-1);\n");                    }                } else {                    p.print("-1);\n");                }                p.print("  __msg->alloc_params("+num_params*4+");\n");                if (params != null) {                    for (int t = 0; t < method_params.length; t++) {                        String method_params_string = method_params[t].toString();                        p.print("  __msg->push_" + method_params_string + "(");                        params[t].accept(this);                        //if (t < method_params.length - 1) { p.print(", "); }                                                p.print(");\n");                    }                }                p.print("  __msg_stack_"+dst+" = __msg->push_on_stack(__msg_stack_"+dst+");\n");                p.print("\n#else\n\n");                p.print("  __msg_sock_" + selfID + "_" + dst + "out->write_int("                        + size + ");\n");                p.print("  __msg_sock_" + selfID + "_" + dst + "out->write_int("                        + index + ");\n");                if (latency instanceof SIRLatencyMax) {                    int max = ((SIRLatencyMax) latency).getMax();                    //p.print("__msg_sock_"+selfID+"_"+dst+"out->write_int("+max+");");                    SIRFilter sender = (SIRFilter) NodeEnumerator                        .getOperator(selfID);                    SIRFilter receiver = (SIRFilter) NodeEnumerator                        .getOperator(dst);                    if (LatencyConstraints.isMessageDirectionDownstream(sender,                                                                        receiver)) {                        p.print("  __msg_sock_" + selfID + "_" + dst                                + "out->write_int(sdep_" + selfID + "_" + dst                                + "->getDstPhase4SrcPhase(__counter_" + selfID                                + "+" + max + "+1)-1);\n");                    } else {                        p.print("  __msg_sock_" + selfID + "_" + dst                                + "out->write_int(sdep_" + selfID + "_" + dst                                + "->getSrcPhase4DstPhase(__counter_" + selfID                                + "+" + max + "+1)-1);\n");                    }                } else {                    p.print("  __msg_sock_" + selfID + "_" + dst                            + "out->write_int(-1);\n");                }                assert params.length == method_params.length :                    "Message send parameter list length " + params.length                     + " != formals list length " + method_params.length;                ;                                if (params != null) {                    for (int t = 0; t < method_params.length; t++) {                        String method_params_string = method_params[t]                            .toString();                        p.print("  __msg_sock_" + selfID + "_" + dst                                + "out->write_");                        if (method_params_string == "int"                            || method_params_string == "float") {                            p.print(method_params_string + "(");                        } else {                            p.print("unsupported/* " + method_params_string                                    + " */ (");                        }                        //          if (method_params[t].toString().equals("int")) {                        //              p.print("__msg_sock_"+selfID+"_"+dst+"out->write_int(");                        //          }                        //          if (method_params[t].toString().equals("float")) {                        //              p.print("__msg_sock_"+selfID+"_"+dst+"out->write_float(");                        //          }                        // print out the parameter!                        //                        PRINT_MSG_PARAM = t;                        //                        params[2].accept(this);                        //                        PRINT_MSG_PARAM = -1;                        params[t].accept(this);                        if (t < method_params.length - 1) { p.print(", "); }                                                p.print(");\n");                    }                }                p.print("\n#endif\n\n");            }        }    }