/* We'll have to make a method on each class w/ a portal that makes a portal of that type. */ TransferMode { // take a local var of type, called local, and make a var called remote that can be sent. // remote is created. The type of remote is depended on the passing convention. // perhaps these funcs should work on streams- then we could return the type of the created remote var String make_pack_var(JavaType type, String local, String remote) to * { start (@ return_val = "// BEGIN make_pack_var("+type+","+remote+","+local+")\n"; @) before NotPassed (@ return_val += "/* not passed */\n"; @) before GlobalRef (@ return_val += " RIDL_Runtime.RIDL_Object "+remote+" = " + local+"._make_fake(); \n"; @) before Copy (@ return_val += ""; if (RIDL.has_portal(type)) return_val += " if ("+local+"._proxy != null) {\n"+ " System.err.println(\""+local+ " is a gref, and cannot be passed by copy\"); \n"+ " System.exit(1); \n"+ " }\n"; @) before FullCopy (@ return_val += " "+type+" "+remote+" = "+local+"; // Full copy \n"; @) before TravCopy (@ String cv = local+"_cv"; return_val += " CopyVisitor "+cv+" = new CopyVisitor("+local+".getClass()); \n" + " "+local+"."+host.get_traversalname().toString()+"("+cv+"); \n" + " "+type+" "+remote+" = "+ "("+type+") "+cv+".get_return_val(); // copy by trav\n"; // A) make a new var ArgType argname_copy = pruned copy of argname @) finish (@ return_val += "// END make_pack_var("+type+","+remote+","+local+")\n"; @) } // to figure out the type of the created arg, we do this: JavaType what_packed_type(JavaType localtype) to * { before GlobalRef (@ return_val = JavaType.parse("RIDL_Runtime.RIDL_Object"); @) before Copy (@ return_val = localtype; @) before NotPassed (@ return_val = JavaType.parse("void"); @) } // same idea, but in reverse- take what came as a remote var, and create a local String make_unpack_var(JavaType type, String remote, String local) to * { start (@ return_val = "// BEGIN make_unpack_var("+type+","+remote+","+local+")\n"; @) before NotPassed (@ return_val += "/* not passed */ \n"; @) before GlobalRef (@ return_val += " "+type+" "+local+" = ("+type+") "+remote+"; \n"; @) before Copy (@ return_val += " "+type+" "+local+" = "+remote+"; \n"; @) finish (@ return_val += "// END make_unpack_var("+type+","+remote+","+local+")\n"; @) } String p_makeretvar(MethodSignature ms, String name) to * { // make a variable of the above type, named name (@ JavaType jt;@) before Copy (@ return_val = ms.get_returntype().createvar(name); @) before GlobalRef (@ return_val = "RIDL_Runtime.RIDL_Object "+name+ " = null;"; @) before NotPassed (@ return_val = ""; @) } String p_makecallpp(MethodSignature ms, String name,String callexp) (@ return ms.get_returntype().assignvar(name,callexp); @) String pp_makeretvar(MethodSignature ms, String name) to * { (@ JavaType jt; @) after TransferMode (@ return_val = ms.get_returntype().createvar(name); @) } // make a string that assigns name the returnval of evalling pp (in callexp) // The only difficulty might be that the rettype is void String pp_makecallreal(MethodSignature ms, String name,String callexp) (@ return ms.get_returntype().assignvar(name,callexp); @) } Arg { public String get_argnamestring() to {ParmName, ReturnName} { before ReturnName (@ return_val = "return"; @) before ParmName (@ return_val = host.toString(); @) } } JavaType { (@ static java.util.Hashtable primtypes = new java.util.Hashtable(); static { // maps prim types to default values primtypes.put("int","0"); primtypes.put("byte","0"); primtypes.put("short","0"); primtypes.put("long","0"); primtypes.put("float","0.0"); primtypes.put("double","0.0"); primtypes.put("char","'\0'"); primtypes.put("void", "null"); } @) String defaultinitval() (@ return (this.objtype()?"null":(String)primtypes.get(this.toString())); @) boolean objtype() (@ return primtypes.get(this.toString()) == null; @) boolean voidtype() (@ return this.toString().equals("void"); @) String createvar(String var) (@ if (voidtype()) { return ""; } else return toString() +" "+var+" = "+defaultinitval()+";\n"; @) String assignvar(String var, String val) (@ if (voidtype()) { return val; } else { return (var+" = "+val); } @) String returnvar(String var) (@ if (voidtype()) { return ""; } else { return (" return "+var+";\n"); } @) } JavaStrings { /* Since we have to special case alot of things on whether or not something is a primitive Java type or object, we have a class that knows about these things: JavaStrings.... We ASSUME that anything passed by a gref must be an Object type */ /* This is were out first stumbling block comes in: the return type of the method. Because we may need to return the result of the some indirect call and because of the way java handles return void, we need to take 3 cases into account: 1) the type of the returned result is void. Ifso, we issue no return values, and the concept of the temporary variable to hold the result is meaningless. 2) the return type is a primitive (int, byte...). Ifso, we need to assign the temporary variable some default value (or a per type basis!) 3) the value is of an object type. This is the simplest case, the temporary variable is inited to null. So, what do we do? We create a MethodStrings object that is able to do the Right Thing in some cases. I really want higher order things here... */ /* String createvar(String var) (@ type.createvar(var); @) String assignvar(String var, String val) (@ type.assignvar(var,val); @) String returnvar(String var) (@ type.returnvar(var); @) */ }