@@ -46,12 +46,38 @@ public override bool VisitClassDecl(Class @class)
46
46
return base . VisitClassDecl ( @class ) ;
47
47
}
48
48
49
+ public override bool VisitClassTemplateSpecializationDecl ( ClassTemplateSpecialization specialization )
50
+ {
51
+ if ( ! base . VisitClassTemplateSpecializationDecl ( specialization ) ||
52
+ ! specialization . IsGenerated || ! specialization . TemplatedDecl . TemplatedDecl . IsGenerated )
53
+ return false ;
54
+
55
+ foreach ( TemplateArgument arg in specialization . Arguments . Where (
56
+ a => a . Kind == TemplateArgument . ArgumentKind . Type ) )
57
+ {
58
+ arg . Type = CheckForDelegate ( arg . Type , specialization ) ;
59
+ }
60
+
61
+ return true ;
62
+ }
63
+
49
64
public override bool VisitMethodDecl ( Method method )
50
65
{
51
66
if ( ! base . VisitMethodDecl ( method ) || ! method . IsVirtual || method . Ignore )
52
67
return false ;
53
68
54
- method . FunctionType = CheckForDelegate ( method . FunctionType , method ) ;
69
+ var functionType = new FunctionType
70
+ {
71
+ CallingConvention = method . CallingConvention ,
72
+ IsDependent = method . IsDependent ,
73
+ ReturnType = method . ReturnType
74
+ } ;
75
+
76
+ functionType . Parameters . AddRange (
77
+ method . GatherInternalParams ( Context . ParserOptions . IsItaniumLikeAbi , true ) ) ;
78
+
79
+ method . FunctionType = CheckForDelegate ( new QualifiedType ( functionType ) ,
80
+ method . Namespace , @private : true ) ;
55
81
56
82
return true ;
57
83
}
@@ -61,7 +87,8 @@ public override bool VisitFunctionDecl(Function function)
61
87
if ( ! base . VisitFunctionDecl ( function ) || function . Ignore )
62
88
return false ;
63
89
64
- function . ReturnType = CheckForDelegate ( function . ReturnType , function ) ;
90
+ function . ReturnType = CheckForDelegate ( function . ReturnType ,
91
+ function . Namespace ) ;
65
92
return true ;
66
93
}
67
94
@@ -71,7 +98,8 @@ public override bool VisitParameterDecl(Parameter parameter)
71
98
parameter . Namespace . Ignore )
72
99
return false ;
73
100
74
- parameter . QualifiedType = CheckForDelegate ( parameter . QualifiedType , parameter ) ;
101
+ parameter . QualifiedType = CheckForDelegate ( parameter . QualifiedType ,
102
+ parameter . Namespace ) ;
75
103
76
104
return true ;
77
105
}
@@ -81,7 +109,8 @@ public override bool VisitProperty(Property property)
81
109
if ( ! base . VisitProperty ( property ) )
82
110
return false ;
83
111
84
- property . QualifiedType = CheckForDelegate ( property . QualifiedType , property ) ;
112
+ property . QualifiedType = CheckForDelegate ( property . QualifiedType ,
113
+ property . Namespace ) ;
85
114
86
115
return true ;
87
116
}
@@ -91,12 +120,14 @@ public override bool VisitFieldDecl(Field field)
91
120
if ( ! base . VisitFieldDecl ( field ) )
92
121
return false ;
93
122
94
- field . QualifiedType = CheckForDelegate ( field . QualifiedType , field ) ;
123
+ field . QualifiedType = CheckForDelegate ( field . QualifiedType ,
124
+ field . Namespace ) ;
95
125
96
126
return true ;
97
127
}
98
128
99
- private QualifiedType CheckForDelegate ( QualifiedType type , ITypedDecl decl )
129
+ private QualifiedType CheckForDelegate ( QualifiedType type ,
130
+ DeclarationContext declarationContext , bool @private = false )
100
131
{
101
132
if ( type . Type is TypedefType )
102
133
return type ;
@@ -109,22 +140,21 @@ private QualifiedType CheckForDelegate(QualifiedType type, ITypedDecl decl)
109
140
if ( pointee is TypedefType )
110
141
return type ;
111
142
112
- var functionType = pointee . Desugar ( ) as FunctionType ;
113
- if ( functionType == null )
143
+ desugared = pointee . Desugar ( ) ;
144
+ FunctionType functionType = desugared as FunctionType ;
145
+ if ( functionType == null && ! desugared . IsPointerTo ( out functionType ) )
114
146
return type ;
115
147
116
- TypedefDecl @delegate = GetDelegate ( type , decl ) ;
148
+ TypedefDecl @delegate = GetDelegate ( functionType , declarationContext , @private ) ;
117
149
return new QualifiedType ( new TypedefType { Declaration = @delegate } ) ;
118
150
}
119
151
120
- private TypedefDecl GetDelegate ( QualifiedType type , ITypedDecl typedDecl )
152
+ private TypedefDecl GetDelegate ( FunctionType functionType ,
153
+ DeclarationContext declarationContext , bool @private = false )
121
154
{
122
- FunctionType newFunctionType = GetNewFunctionType ( typedDecl , type ) ;
123
-
124
- var delegateName = GetDelegateName ( newFunctionType ) ;
125
- var access = typedDecl is Method ? AccessSpecifier . Private : AccessSpecifier . Public ;
126
- var decl = ( Declaration ) typedDecl ;
127
- Module module = decl . TranslationUnit . Module ;
155
+ var delegateName = GetDelegateName ( functionType ) ;
156
+ var access = @private ? AccessSpecifier . Private : AccessSpecifier . Public ;
157
+ Module module = declarationContext . TranslationUnit . Module ;
128
158
var existingDelegate = delegates . Find ( t => Match ( t , delegateName , module ) ) ;
129
159
if ( existingDelegate != null )
130
160
{
@@ -135,18 +165,18 @@ private TypedefDecl GetDelegate(QualifiedType type, ITypedDecl typedDecl)
135
165
136
166
// Check if there is an existing delegate with a different calling convention
137
167
if ( ( ( FunctionType ) existingDelegate . Type . GetPointee ( ) ) . CallingConvention ==
138
- newFunctionType . CallingConvention )
168
+ functionType . CallingConvention )
139
169
return existingDelegate ;
140
170
141
171
// Add a new delegate with the calling convention appended to its name
142
- delegateName += '_' + newFunctionType . CallingConvention . ToString ( ) ;
172
+ delegateName += '_' + functionType . CallingConvention . ToString ( ) ;
143
173
existingDelegate = delegates . Find ( t => Match ( t , delegateName , module ) ) ;
144
174
if ( existingDelegate != null )
145
175
return existingDelegate ;
146
176
}
147
177
148
- var namespaceDelegates = GetDeclContextForDelegates ( decl . Namespace ) ;
149
- var delegateType = new QualifiedType ( new PointerType ( new QualifiedType ( newFunctionType ) ) ) ;
178
+ var namespaceDelegates = GetDeclContextForDelegates ( declarationContext ) ;
179
+ var delegateType = new QualifiedType ( new PointerType ( new QualifiedType ( functionType ) ) ) ;
150
180
existingDelegate = new TypedefDecl
151
181
{
152
182
Access = access ,
@@ -160,30 +190,6 @@ private TypedefDecl GetDelegate(QualifiedType type, ITypedDecl typedDecl)
160
190
return existingDelegate ;
161
191
}
162
192
163
- private FunctionType GetNewFunctionType ( ITypedDecl decl , QualifiedType type )
164
- {
165
- var functionType = new FunctionType ( ) ;
166
- var method = decl as Method ;
167
- if ( method != null && method . FunctionType == type )
168
- {
169
- functionType . Parameters . AddRange (
170
- method . GatherInternalParams ( Context . ParserOptions . IsItaniumLikeAbi , true ) ) ;
171
- functionType . CallingConvention = method . CallingConvention ;
172
- functionType . IsDependent = method . IsDependent ;
173
- functionType . ReturnType = method . ReturnType ;
174
- }
175
- else
176
- {
177
- var funcTypeParam = ( FunctionType ) decl . Type . Desugar ( ) . GetFinalPointee ( ) . Desugar ( ) ;
178
- functionType = new FunctionType ( funcTypeParam ) ;
179
- }
180
-
181
- for ( int i = 0 ; i < functionType . Parameters . Count ; i ++ )
182
- functionType . Parameters [ i ] . Name = $ "_{ i } ";
183
-
184
- return functionType ;
185
- }
186
-
187
193
private static bool Match ( TypedefDecl t , string delegateName , Module module )
188
194
{
189
195
return t . Name == delegateName &&
0 commit comments