forked from dotnet/java-interop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenericSymbol.cs
170 lines (138 loc) · 4.04 KB
/
GenericSymbol.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MonoDroid.Generation {
public class GenericSymbol : ISymbol {
bool is_concrete;
GenBase gen;
string [] java_params;
string tps;
ISymbol [] type_params;
public GenericSymbol (GenBase gen, string type_params)
{
this.gen = gen;
java_params = GenericParameterList.Parse (type_params);
}
public string DefaultValue {
get { return "IntPtr.Zero"; }
}
public string FullName {
get { return gen.FullName; }
}
public GenBase Gen {
get { return gen; }
}
public bool IsConcrete {
get { return is_concrete; }
}
public string JavaName {
get { return gen.JavaName; }
}
public string JniName {
get { return gen.JniName; }
}
public string NativeType {
get { return "IntPtr"; }
}
public bool IsEnum {
get { return false; }
}
public bool IsArray {
get { return false; }
}
public string ElementType {
get { return null; }
}
public ISymbol [] TypeParams {
get { return type_params; }
}
public string GetObjectHandleProperty (string variable)
{
return gen.GetObjectHandleProperty (variable);
}
string MapTypeParams (Dictionary<string, string> mappings)
{
StringBuilder sb = new StringBuilder ();
sb.Append ("<");
foreach (var tp in type_params) {
if (sb.Length > 1)
sb.Append (", ");
if (mappings.ContainsKey (tp.FullName))
sb.Append (mappings[tp.FullName]);
else
sb.Append (tp.FullName);
}
sb.Append (">");
return sb.ToString ();
}
public string FromNative (CodeGenerationOptions opt, string varname, bool owned)
{
return gen.FromNative (opt, varname, owned);
}
public string GetGenericType (Dictionary<string, string> mappings)
{
return gen.FullName + (mappings == null ? tps : MapTypeParams (mappings));
}
public string ToNative (CodeGenerationOptions opt, string varname)
{
return gen.ToNative (opt, varname);
}
public string ToNative (CodeGenerationOptions opt, string varname, Dictionary<string, string> mappings)
{
return varname;
}
public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList in_params)
{
if (!gen.Validate (opt, in_params))
return false;
is_concrete = true;
type_params = new ISymbol [java_params.Length];
for (int i = 0; i < java_params.Length; i++) {
string tp = java_params [i];
var gpd = in_params != null ? in_params.FirstOrDefault (t => t.Name == tp) : null;
if (gpd != null) {
type_params [i] = new GenericTypeParameter (gpd);
is_concrete = false;
continue;
} else if (tp == "?") {
if (in_params != null && in_params.Count == 1) {
type_params [i] = new GenericTypeParameter (in_params [0]);
is_concrete = false;
} else
type_params [i] = new SimpleSymbol ("null", "java.lang.Object", "object", "Ljava/lang/Object;");
continue;
}
ISymbol psym = SymbolTable.Lookup (tp, in_params);
if (psym == null || !psym.Validate (opt, in_params))
return false;
if (psym is GenericSymbol && !(psym as GenericSymbol).IsConcrete)
is_concrete = false;
type_params [i] = /*psym is IGeneric ? (psym as IGeneric).GetGenericType (null) : psym.FullName*/ psym;
}
tps = type_params == null ? null : "<" + String.Join (", ", (from tp in type_params select tp.FullName).ToArray ()) + ">";
return true;
}
public string[] PreCallback (CodeGenerationOptions opt, string var_name, bool owned)
{
return gen.PreCallback (opt, var_name, owned);
}
public string[] PostCallback (CodeGenerationOptions opt, string var_name)
{
return gen.PostCallback (opt, var_name);
}
public string[] PreCall (CodeGenerationOptions opt, string var_name)
{
return gen.PreCall (opt, var_name);
}
public string Call (CodeGenerationOptions opt, string var_name)
{
return gen.Call (opt, var_name);
}
public string[] PostCall (CodeGenerationOptions opt, string var_name)
{
return gen.PostCall (opt, var_name);
}
public bool NeedsPrep { get { return true; } }
}
}