1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Diagnostics ;
4
3
using System . Runtime . InteropServices ;
5
4
using System . Runtime . InteropServices . ComTypes ;
6
5
using Microsoft . Vbe . Interop ;
19
18
using TYPEFLAGS = System . Runtime . InteropServices . ComTypes . TYPEFLAGS ;
20
19
using VARDESC = System . Runtime . InteropServices . ComTypes . VARDESC ;
21
20
using Rubberduck . Parsing . Annotations ;
22
- using System . Linq ;
23
21
using Rubberduck . Parsing . Grammar ;
24
22
25
23
namespace Rubberduck . Parsing . Symbols
@@ -130,21 +128,22 @@ private string GetTypeName(ITypeInfo info)
130
128
return typeName ;
131
129
}
132
130
133
- public IEnumerable < Declaration > GetDeclarationsForReference ( Reference reference )
131
+ public List < Declaration > GetDeclarationsForReference ( Reference reference )
134
132
{
133
+ var output = new List < Declaration > ( ) ;
135
134
var projectName = reference . Name ;
136
135
var path = reference . FullPath ;
137
136
ITypeLib typeLibrary ;
138
137
// Failure to load might mean that it's a "normal" VBProject that will get parsed by us anyway.
139
138
LoadTypeLibEx ( path , REGKIND . REGKIND_NONE , out typeLibrary ) ;
140
139
if ( typeLibrary == null )
141
140
{
142
- yield break ;
141
+ return output ;
143
142
}
144
143
var projectQualifiedModuleName = new QualifiedModuleName ( projectName , path , projectName ) ;
145
144
var projectQualifiedMemberName = new QualifiedMemberName ( projectQualifiedModuleName , projectName ) ;
146
145
var projectDeclaration = new ProjectDeclaration ( projectQualifiedMemberName , projectName , isBuiltIn : true ) ;
147
- yield return projectDeclaration ;
146
+ output . Add ( projectDeclaration ) ;
148
147
149
148
var typeCount = typeLibrary . GetTypeInfoCount ( ) ;
150
149
for ( var i = 0 ; i < typeCount ; i ++ )
@@ -156,7 +155,7 @@ public IEnumerable<Declaration> GetDeclarationsForReference(Reference reference)
156
155
}
157
156
catch ( NullReferenceException )
158
157
{
159
- yield break ;
158
+ return output ;
160
159
}
161
160
162
161
if ( info == null )
@@ -241,53 +240,56 @@ public IEnumerable<Declaration> GetDeclarationsForReference(Reference reference)
241
240
attributes ) ;
242
241
break ;
243
242
}
243
+ info . ReleaseTypeAttr ( typeAttributesPointer ) ;
244
244
245
- yield return moduleDeclaration ;
245
+ output . Add ( moduleDeclaration ) ;
246
246
247
247
for ( var memberIndex = 0 ; memberIndex < typeAttributes . cFuncs ; memberIndex ++ )
248
248
{
249
- FUNCDESC memberDescriptor ;
250
249
string [ ] memberNames ;
251
- var memberDeclaration = CreateMemberDeclaration ( out memberDescriptor , typeAttributes . typekind , info , memberIndex , typeQualifiedModuleName , moduleDeclaration , out memberNames ) ;
250
+
251
+ IntPtr memberDescriptorPointer ;
252
+ info . GetFuncDesc ( memberIndex , out memberDescriptorPointer ) ;
253
+ var memberDescriptor = ( FUNCDESC ) Marshal . PtrToStructure ( memberDescriptorPointer , typeof ( FUNCDESC ) ) ;
254
+ var memberDeclaration = CreateMemberDeclaration ( memberDescriptor , typeAttributes . typekind , info , memberIndex , typeQualifiedModuleName , moduleDeclaration , out memberNames ) ;
252
255
if ( memberDeclaration == null )
253
256
{
257
+ info . ReleaseFuncDesc ( memberDescriptorPointer ) ;
254
258
continue ;
255
259
}
256
260
if ( moduleDeclaration . DeclarationType == DeclarationType . ClassModule && memberDeclaration is ICanBeDefaultMember && ( ( ICanBeDefaultMember ) memberDeclaration ) . IsDefaultMember )
257
261
{
258
262
( ( ClassModuleDeclaration ) moduleDeclaration ) . DefaultMember = memberDeclaration ;
259
263
}
260
- yield return memberDeclaration ;
264
+ output . Add ( memberDeclaration ) ;
261
265
262
266
var parameterCount = memberDescriptor . cParams - 1 ;
263
267
for ( var paramIndex = 0 ; paramIndex < parameterCount ; paramIndex ++ )
264
268
{
265
269
var parameter = CreateParameterDeclaration ( memberNames , paramIndex , memberDescriptor , typeQualifiedModuleName , memberDeclaration , info ) ;
266
- if ( memberDeclaration is IDeclarationWithParameter )
270
+ var declaration = memberDeclaration as IDeclarationWithParameter ;
271
+ if ( declaration != null )
267
272
{
268
- ( ( IDeclarationWithParameter ) memberDeclaration ) . AddParameter ( parameter ) ;
273
+ declaration . AddParameter ( parameter ) ;
269
274
}
270
- yield return parameter ;
275
+ output . Add ( parameter ) ;
271
276
}
277
+ info . ReleaseFuncDesc ( memberDescriptorPointer ) ;
272
278
}
273
279
274
280
for ( var fieldIndex = 0 ; fieldIndex < typeAttributes . cVars ; fieldIndex ++ )
275
281
{
276
- yield return CreateFieldDeclaration ( info , fieldIndex , typeDeclarationType , typeQualifiedModuleName , moduleDeclaration ) ;
282
+ output . Add ( CreateFieldDeclaration ( info , fieldIndex , typeDeclarationType , typeQualifiedModuleName , moduleDeclaration ) ) ;
277
283
}
278
284
}
285
+ return output ;
279
286
}
280
287
281
- private Declaration CreateMemberDeclaration ( out FUNCDESC memberDescriptor , TYPEKIND typeKind , ITypeInfo info , int memberIndex ,
288
+ private Declaration CreateMemberDeclaration ( FUNCDESC memberDescriptor , TYPEKIND typeKind , ITypeInfo info , int memberIndex ,
282
289
QualifiedModuleName typeQualifiedModuleName , Declaration moduleDeclaration , out string [ ] memberNames )
283
290
{
284
- IntPtr memberDescriptorPointer ;
285
- info . GetFuncDesc ( memberIndex , out memberDescriptorPointer ) ;
286
- memberDescriptor = ( FUNCDESC ) Marshal . PtrToStructure ( memberDescriptorPointer , typeof ( FUNCDESC ) ) ;
287
-
288
291
if ( memberDescriptor . callconv != CALLCONV . CC_STDCALL )
289
292
{
290
- memberDescriptor = new FUNCDESC ( ) ;
291
293
memberNames = new string [ ] { } ;
292
294
return null ;
293
295
}
@@ -425,7 +427,8 @@ private Declaration CreateFieldDeclaration(ITypeInfo info, int fieldIndex, Decla
425
427
var fieldName = names [ 0 ] ;
426
428
var memberType = GetDeclarationType ( varDesc , typeDeclarationType ) ;
427
429
428
- var asTypeName = GetTypeName ( varDesc . elemdescVar . tdesc , info ) ;
430
+ var asTypeName = GetTypeName ( varDesc . elemdescVar . tdesc , info ) ;
431
+ info . ReleaseVarDesc ( ppVarDesc ) ;
429
432
430
433
return new Declaration ( new QualifiedMemberName ( typeQualifiedModuleName , fieldName ) ,
431
434
moduleDeclaration , moduleDeclaration , asTypeName , null , false , false , Accessibility . Global , memberType , null ,
@@ -458,6 +461,7 @@ private ParameterDeclaration CreateParameterDeclaration(IReadOnlyList<string> me
458
461
459
462
private IEnumerable < string > GetImplementedInterfaceNames ( TYPEATTR typeAttr , ITypeInfo info )
460
463
{
464
+ var output = new List < string > ( ) ;
461
465
for ( var implIndex = 0 ; implIndex < typeAttr . cImplTypes ; implIndex ++ )
462
466
{
463
467
int href ;
@@ -470,10 +474,11 @@ private IEnumerable<string> GetImplementedInterfaceNames(TYPEATTR typeAttr, ITyp
470
474
if ( implTypeName != "IDispatch" && implTypeName != "IUnknown" )
471
475
{
472
476
// skip IDispatch.. just about everything implements it and RD doesn't need to care about it; don't care about IUnknown either
473
- yield return implTypeName ;
477
+ output . Add ( implTypeName ) ;
474
478
}
475
479
//Debug.WriteLine(string.Format("\tImplements {0}", implTypeName));
476
480
}
481
+ return output ;
477
482
}
478
483
479
484
private DeclarationType GetDeclarationType ( ITypeLib typeLibrary , int i )
0 commit comments