@@ -50,53 +50,64 @@ private void SetupTypeMaps(IEnumerable<System.Type> types,
50
50
51
51
public bool FindTypeMap ( Declaration decl , Type type , out TypeMap typeMap )
52
52
{
53
+ if ( type != null && typeMaps . ContainsKey ( type ) )
54
+ {
55
+ typeMap = typeMaps [ type ] ;
56
+ return typeMap . IsEnabled ;
57
+ }
58
+
53
59
// We try to find type maps from the most qualified to less qualified
54
60
// types. Example: '::std::vector', 'std::vector' and 'vector'
55
61
56
62
var typePrinter = new CppTypePrinter { PrintLogicalNames = true } ;
57
63
58
- if ( FindTypeMap ( decl . Visit ( typePrinter ) , out typeMap ) )
59
- {
60
- typeMap . Type = type ;
64
+ if ( FindTypeMap ( decl , type , out typeMap , typePrinter ) )
61
65
return true ;
62
- }
63
66
64
67
typePrinter . PrintScopeKind = TypePrintScopeKind . Qualified ;
65
- if ( FindTypeMap ( decl . Visit ( typePrinter ) , out typeMap ) )
66
- {
67
- typeMap . Type = type ;
68
+ if ( FindTypeMap ( decl , type , out typeMap , typePrinter ) )
68
69
return true ;
69
- }
70
70
71
71
typePrinter . ResolveTypedefs = true ;
72
- if ( FindTypeMap ( decl . Visit ( typePrinter ) , out typeMap ) )
73
- {
74
- typeMap . Type = type ;
72
+ if ( FindTypeMap ( decl , type , out typeMap , typePrinter ) )
75
73
return true ;
76
- }
77
74
typePrinter . ResolveTypedefs = false ;
78
75
79
76
typePrinter . PrintScopeKind = TypePrintScopeKind . Local ;
80
- if ( FindTypeMap ( decl . Visit ( typePrinter ) , out typeMap ) )
81
- {
82
- typeMap . Type = type ;
77
+ if ( FindTypeMap ( decl , type , out typeMap , typePrinter ) )
83
78
return true ;
84
- }
85
79
86
80
var specialization = decl as ClassTemplateSpecialization ;
87
81
if ( specialization != null &&
88
- FindTypeMap ( specialization . TemplatedDecl . Visit ( typePrinter ) , out typeMap ) )
89
- {
90
- typeMap . Type = type ;
82
+ FindTypeMap ( specialization . TemplatedDecl , type , out typeMap , typePrinter ) )
91
83
return true ;
92
- }
93
84
94
85
var typedef = decl as TypedefDecl ;
95
86
return typedef != null && FindTypeMap ( typedef . Type , out typeMap ) ;
96
87
}
97
88
89
+ private bool FindTypeMap ( Declaration decl , Type type , out TypeMap typeMap , CppTypePrinter typePrinter )
90
+ {
91
+ if ( FindTypeMap ( decl . Visit ( typePrinter ) , out typeMap ) )
92
+ {
93
+ if ( type != null && typeMap . Type == null )
94
+ {
95
+ typeMap . Type = type ;
96
+ typeMaps [ type ] = typeMap ;
97
+ }
98
+ return true ;
99
+ }
100
+ return false ;
101
+ }
102
+
98
103
public bool FindTypeMap ( Type type , out TypeMap typeMap )
99
104
{
105
+ if ( typeMaps . ContainsKey ( type ) )
106
+ {
107
+ typeMap = typeMaps [ type ] ;
108
+ return typeMap . IsEnabled ;
109
+ }
110
+
100
111
var typePrinter = new CppTypePrinter
101
112
{
102
113
PrintTypeQualifiers = false ,
@@ -119,13 +130,15 @@ public bool FindTypeMap(Type type, out TypeMap typeMap)
119
130
if ( FindTypeMap ( type . Visit ( typePrinter ) , out typeMap ) )
120
131
{
121
132
typeMap . Type = type ;
133
+ typeMaps [ type ] = typeMap ;
122
134
return true ;
123
135
}
124
136
125
137
typePrinter . PrintScopeKind = TypePrintScopeKind . Qualified ;
126
138
if ( FindTypeMap ( type . Visit ( typePrinter ) , out typeMap ) )
127
139
{
128
140
typeMap . Type = type ;
141
+ typeMaps [ type ] = typeMap ;
129
142
return true ;
130
143
}
131
144
@@ -157,5 +170,7 @@ private bool FindTypeMap(string name, out TypeMap typeMap)
157
170
{
158
171
return TypeMaps . TryGetValue ( name , out typeMap ) && typeMap . IsEnabled ;
159
172
}
173
+
174
+ private Dictionary < Type , TypeMap > typeMaps = new Dictionary < Type , TypeMap > ( ) ;
160
175
}
161
176
}
0 commit comments