diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g index 4520db6..32e896f 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g @@ -414,14 +414,14 @@ scope MkNonGeneric { protected CommonTree wrapType(CommonTree t, IToken tok) { CommonTree root = (CommonTree)adaptor.Nil; - root = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(JAVAWRAPPERTYPE, tok, "TYPE"), root); + root = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(JAVAWRAPPERTYPE, tok, "JAVAWRAPPERTYPE"), root); adaptor.AddChild(root, dupTree(t)); return (CommonTree)adaptor.RulePostProcessing(root); } protected CommonTree wrapTypeOfType(TypeRepTemplate t, IToken tok) { CommonTree root = (CommonTree)adaptor.Nil; - root = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(JAVAWRAPPEREXPRESSION, tok, "EXPRESSION"), root); + root = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(JAVAWRAPPEREXPRESSION, tok, "JAVAWRAPPEREXPRESSION"), root); adaptor.AddChild(root, (CommonTree)adaptor.Create(IDENTIFIER, tok, t.Java)); return (CommonTree)adaptor.RulePostProcessing(root); } @@ -456,6 +456,60 @@ scope MkNonGeneric { populateParamMap(pMap, ps, argTrees, argTreeTypeofTypes, argListTree, incStar, null, null, tok); } + /// + /// Populates the param Map that gives values for tokens in a Java template + /// + /// + /// A . The map to populate. + /// + /// + /// A . The parameters. + /// + /// + /// A . The expressions for each parameter. + /// + /// + /// A . (May be null). The type of each argument. + /// + /// + /// A . (May be null). A Tree with the list of arguments. If needed and not provided then we build it from argTrees. + /// + /// + /// A . If true then substitute for arglist parameters ("${*]n}") using argListTree. + /// + /// + /// A . (May be null). Array of Type Parameter Names. + /// + /// + /// A (May be null). Types to substitute for typeParams. + /// + /// + /// A Mark created trees with this token's posiition. + /// + protected void populateParamMap(Dictionary pMap, IList ps, + IList argTrees, IList argTreeTypeofTypes, CommonTree argListTree, + bool incStar, Dictionary tyVarMap, + IToken tok) { + // WARNING: logic duplicated from method overload below + for (int idx = 0; idx < ps.Count; idx++) { + pMap[ps[idx].Name] = wrapArgument(argTrees[idx], tok); + if (ps[idx].Name.StartsWith("TYPEOF") && argTreeTypeofTypes != null && argTreeTypeofTypes[idx] != null) { + // if this argument is a typeof expression then add a TYPEOF_TYPEOF-> typeof's type mapping + pMap[ps[idx].Name + "_TYPE"] = wrapTypeOfType(argTreeTypeofTypes[idx], tok); + } + } + if (incStar) + { + pMap["*"] = wrapArgumentList(argListTree != null ? argListTree : mkArgumentList(tok, argTrees), tok); + } + + if (tyVarMap != null) { + foreach(KeyValuePair entry in tyVarMap) { + pMap[entry.Key] = wrapExpression(mkJavaRep(tok, entry.Value), tok); + } + } + } + /// /// Populates the param Map that gives values for tokens in a Java template /// @@ -490,6 +544,7 @@ scope MkNonGeneric { IList argTrees, IList argTreeTypeofTypes, CommonTree argListTree, bool incStar, String[] typeParams, IList typeTrees, IToken tok) { + // WARNING: logic duplicated from method overload below for (int idx = 0; idx < ps.Count; idx++) { pMap[ps[idx].Name] = wrapArgument(argTrees[idx], tok); if (ps[idx].Name.StartsWith("TYPEOF") && argTreeTypeofTypes != null && argTreeTypeofTypes[idx] != null) { @@ -1320,7 +1375,9 @@ scope { } calleeMethod = calleeResult.Result as MethodRepTemplate; } - populateParamMap(myMap, calleeMethod.Params, $argument_list.argTrees, $argument_list.argTreeTypeofTypes, $argument_list.tree, wantsStar(calleeMethod.Java), $i2.tree.Token); + populateParamMap(myMap, calleeMethod.Params, $argument_list.argTrees, $argument_list.argTreeTypeofTypes, $argument_list.tree, wantsStar(calleeMethod.Java), + expType.TyVarMap, + $i2.tree.Token); ret = mkJavaWrapper(calleeMethod.Java, myMap, $i2.tree.Token); AddToImports(calleeMethod.Imports); $dotNetType = calleeResult.ResultType;