mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
Make sure we process type sin delegate arguments correctly
This commit is contained in:
parent
317aa189f2
commit
1b2222254a
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
This file is
|
||||
@ -9,7 +9,7 @@
|
||||
-->
|
||||
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
|
||||
<Imports />
|
||||
<Java>Array</Java>
|
||||
<Java>${T}[]</Java>
|
||||
<Name>System.Array</Name>
|
||||
<TypeParams>
|
||||
<Name>T</Name>
|
||||
|
@ -518,16 +518,34 @@ scope MkNonGeneric {
|
||||
return root;
|
||||
}
|
||||
|
||||
protected CommonTree mkJavaRep(IToken tok, TypeRepTemplate ty) {
|
||||
if (ty.InstantiatedTypes.Length == 0) {
|
||||
return (CommonTree)adaptor.Create(IDENTIFIER, tok, ty.Java);
|
||||
}
|
||||
else {
|
||||
Dictionary<string,CommonTree> tyMap = new Dictionary<string,CommonTree>();
|
||||
int i = 0;
|
||||
foreach (TypeRepTemplate tyArg in ty.InstantiatedTypes) {
|
||||
CommonTree typeRoot = (CommonTree)adaptor.Nil;
|
||||
typeRoot = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(TYPE, tok, "TYPE"), typeRoot);
|
||||
adaptor.AddChild(typeRoot, mkJavaRep(tok, tyArg));
|
||||
tyMap[ty.TypeParams[i]] = wrapType(typeRoot, tok);
|
||||
i++;
|
||||
}
|
||||
return mkJavaWrapper(ty.Java, tyMap, tok);
|
||||
}
|
||||
}
|
||||
|
||||
// either ^(PARAMS (type identifier)*) or ^(ARGS identifier*) depending on value of formal
|
||||
protected CommonTree mkParams(List<ParamRepTemplate> inParams, bool formal, IToken tok) {
|
||||
protected CommonTree mkParams(TypeRepTemplate tyRep, List<ParamRepTemplate> inParams, bool formal, IToken tok) {
|
||||
CommonTree root = (CommonTree)adaptor.Nil;
|
||||
root = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(formal ? PARAMS : ARGS, tok, formal ? "PARAMS" : "ARGS"), root);
|
||||
foreach (ParamRepTemplate p in inParams) {
|
||||
if (formal) {
|
||||
TypeRepTemplate ty = findType(p.Type);
|
||||
TypeRepTemplate ty = tyRep.BuildType(p.Type, AppEnv, new UnknownRepTemplate(p.Type));
|
||||
CommonTree typeRoot = (CommonTree)adaptor.Nil;
|
||||
typeRoot = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(TYPE, tok, "TYPE"), typeRoot);
|
||||
adaptor.AddChild(typeRoot, (CommonTree)adaptor.Create(IDENTIFIER, tok, ty.Java));
|
||||
adaptor.AddChild(typeRoot, mkJavaRep(tok, ty));
|
||||
adaptor.AddChild(root, typeRoot);
|
||||
AddToImports(ty.Imports);
|
||||
}
|
||||
@ -686,7 +704,7 @@ scope MkNonGeneric {
|
||||
|
||||
adaptor.AddChild(method, (CommonTree)adaptor.Create(IDENTIFIER, tok, "Invoke"));
|
||||
if (delg.Invoke.Params.Count > 0) {
|
||||
adaptor.AddChild(method, mkParams(delg.Invoke.Params, true, tok));
|
||||
adaptor.AddChild(method, mkParams(delg, delg.Invoke.Params, true, tok));
|
||||
}
|
||||
adaptor.AddChild(method, (CommonTree)adaptor.Create(OPEN_BRACE, tok, "{"));
|
||||
|
||||
@ -697,7 +715,7 @@ scope MkNonGeneric {
|
||||
call = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(APPLY, tok, "APPLY"), call);
|
||||
adaptor.AddChild(call, dupTree(methTree));
|
||||
if (delg.Invoke.Params.Count > 0) {
|
||||
adaptor.AddChild(call, mkParams(delg.Invoke.Params, false, tok));
|
||||
adaptor.AddChild(call, mkParams(delg, delg.Invoke.Params, false, tok));
|
||||
}
|
||||
if (returnType.IsA(VoidType, AppEnv)) {
|
||||
adaptor.AddChild(ret, call);
|
||||
|
@ -41,6 +41,7 @@ namespace Tester.DelegateUser
|
||||
|
||||
delegate void TestDelegate (string s);
|
||||
delegate void TestRefDelegate (string s, ref int cumul);
|
||||
delegate void ProcessStringArray(string[] args);
|
||||
static void M (string s)
|
||||
{
|
||||
Console.WriteLine (s);
|
||||
@ -51,6 +52,13 @@ namespace Tester.DelegateUser
|
||||
Console.Out.WriteLine ("Notify: {0}", i);
|
||||
}
|
||||
|
||||
public void PrintMessages (string[] msgs)
|
||||
{
|
||||
foreach (string s in msgs) {
|
||||
Console.Out.WriteLine ("Message: {0}", s);
|
||||
}
|
||||
}
|
||||
|
||||
public void UserResponse (String nameParam, bool resultParam)
|
||||
{
|
||||
Console.Out.WriteLine ("{0} was {1}", nameParam, resultParam);
|
||||
@ -63,6 +71,13 @@ namespace Tester.DelegateUser
|
||||
cbackProperty = new CompleteCallback (UserResponse);
|
||||
}
|
||||
|
||||
public void ProcessArray ()
|
||||
{
|
||||
ProcessStringArray delg = PrintMessages;
|
||||
|
||||
delg(new string[] {"Hello","Kevin"});
|
||||
}
|
||||
|
||||
public void SwingIt ()
|
||||
{
|
||||
CompleteCallback cback = new CompleteCallback (UserResponse);
|
||||
@ -184,6 +199,7 @@ namespace Tester.DelegateUser
|
||||
myDel.SwingIt ();
|
||||
myDel.HelloGoodbye ();
|
||||
myDel.EventLogger();
|
||||
myDel.ProcessArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ namespace Tester
|
||||
public static void Main (string[] args)
|
||||
{
|
||||
|
||||
//Tester.DelegateUser.DelegateTest<int>.DelMain(args);
|
||||
Tester.DelegateUser.DelegateTest<int>.DelMain(args);
|
||||
|
||||
//Tester.RefOut.RefOutTest.RefOutMain(args);
|
||||
|
||||
//Tester.PartialUser.PartialMain(args);
|
||||
|
||||
Tester.Delegates.EventHandler.Sample.EHMain();
|
||||
//Tester.Delegates.EventHandler.Sample.EHMain();
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user