Skip to content

Commit beb4849

Browse files
committed
removed hard-coded defaults in ClassModuleDeclaration
1 parent 5c28ef6 commit beb4849

File tree

3 files changed

+162
-146
lines changed

3 files changed

+162
-146
lines changed

Rubberduck.Parsing/Symbols/ClassModuleDeclaration.cs

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ namespace Rubberduck.Parsing.Symbols
88
{
99
public sealed class ClassModuleDeclaration : Declaration
1010
{
11-
private readonly bool _isExposed;
12-
private readonly bool _isGlobalClassModule;
13-
private readonly bool _hasDefaultInstanceVariable;
1411
private readonly List<string> _supertypeNames;
1512
private readonly HashSet<Declaration> _supertypes;
1613
private readonly HashSet<Declaration> _subtypes;
@@ -21,10 +18,7 @@ public ClassModuleDeclaration(
2118
string name,
2219
bool isBuiltIn,
2320
IEnumerable<IAnnotation> annotations,
24-
Attributes attributes,
25-
bool isExposed = false,
26-
bool isGlobalClassModule = false,
27-
bool hasDefaultInstanceVariable = false)
21+
Attributes attributes, bool hasDefaultInstanceVariable = false)
2822
: base(
2923
qualifiedName,
3024
projectDeclaration,
@@ -43,9 +37,10 @@ public ClassModuleDeclaration(
4337
annotations,
4438
attributes)
4539
{
46-
_isExposed = isExposed;
47-
_isGlobalClassModule = isGlobalClassModule;
48-
_hasDefaultInstanceVariable = hasDefaultInstanceVariable;
40+
if (hasDefaultInstanceVariable)
41+
{
42+
_hasPredeclaredId = true;
43+
}
4944
_supertypeNames = new List<string>();
5045
_supertypes = new HashSet<Declaration>();
5146
_subtypes = new HashSet<Declaration>();
@@ -60,6 +55,8 @@ public static IEnumerable<Declaration> GetSupertypes(Declaration type)
6055
return ((ClassModuleDeclaration)type).Supertypes;
6156
}
6257

58+
59+
private bool? _isExposed;
6360
/// <summary>
6461
/// Gets an attribute value indicating whether a class is exposed to other projects.
6562
/// If this value is false, any public types and members cannot be accessed from outside the project they're declared in.
@@ -68,30 +65,44 @@ public bool IsExposed
6865
{
6966
get
7067
{
71-
bool attributeIsExposed = false;
68+
if (_isExposed.HasValue)
69+
{
70+
return _isExposed.Value;
71+
}
72+
73+
var attributeIsExposed = false;
7274
IEnumerable<string> value;
7375
if (Attributes.TryGetValue("VB_Exposed", out value))
7476
{
7577
attributeIsExposed = value.Single() == "True";
7678
}
77-
return _isExposed || attributeIsExposed;
79+
_isExposed = attributeIsExposed;
80+
return _isExposed.Value;
7881
}
7982
}
8083

84+
private bool? _isGlobal;
8185
public bool IsGlobalClassModule
8286
{
8387
get
8488
{
85-
bool attributeIsGlobalClassModule = false;
89+
if (_isGlobal.HasValue)
90+
{
91+
return _isGlobal.Value;
92+
}
93+
94+
var attributeIsGlobalClassModule = false;
8695
IEnumerable<string> value;
8796
if (Attributes.TryGetValue("VB_GlobalNamespace", out value))
8897
{
8998
attributeIsGlobalClassModule = value.Single() == "True";
9099
}
91-
return _isGlobalClassModule || attributeIsGlobalClassModule;
100+
_isGlobal = attributeIsGlobalClassModule;
101+
return _isGlobal.Value;
92102
}
93103
}
94104

105+
private bool? _hasPredeclaredId;
95106
/// <summary>
96107
/// Gets an attribute value indicating whether a class has a predeclared ID.
97108
/// Such classes can be treated as "static classes", or as far as resolving is concerned, as standard modules.
@@ -100,13 +111,19 @@ public bool HasPredeclaredId
100111
{
101112
get
102113
{
103-
bool attributeHasDefaultInstanceVariable = false;
114+
if (_hasPredeclaredId.HasValue)
115+
{
116+
return _hasPredeclaredId.Value;
117+
}
118+
119+
var attributeHasDefaultInstanceVariable = false;
104120
IEnumerable<string> value;
105121
if (Attributes.TryGetValue("VB_PredeclaredId", out value))
106122
{
107123
attributeHasDefaultInstanceVariable = value.Single() == "True";
108124
}
109-
return _hasDefaultInstanceVariable || attributeHasDefaultInstanceVariable;
125+
_hasPredeclaredId = attributeHasDefaultInstanceVariable;
126+
return _hasPredeclaredId.Value;
110127
}
111128
}
112129

Rubberduck.Parsing/Symbols/ReferencedDeclarationsCollector.cs

Lines changed: 128 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@ private string GetTypeName(TYPEDESC desc, ITypeInfo info)
9090
case VarEnum.VT_USERDEFINED:
9191
unchecked
9292
{
93-
var href = (int)desc.lpValue.ToInt64(); // todo: verify this also works on 32-bit
93+
int href;
94+
if (Marshal.SizeOf(typeof (IntPtr)) == sizeof (long))
95+
{
96+
href = (int) desc.lpValue.ToInt64();
97+
}
98+
else
99+
{
100+
href = desc.lpValue.ToInt32();
101+
}
94102
ITypeInfo refTypeInfo;
95103
info.GetRefTypeInfo(href, out refTypeInfo);
96104
return GetTypeName(refTypeInfo);
@@ -183,39 +191,39 @@ public IEnumerable<Declaration> GetDeclarationsForReference(Reference reference)
183191
}
184192

185193
Declaration moduleDeclaration;
186-
if (typeDeclarationType == DeclarationType.ProceduralModule)
187-
{
188-
moduleDeclaration = new ProceduralModuleDeclaration(typeQualifiedMemberName, projectDeclaration, typeName, true, new List<IAnnotation>(), attributes);
189-
}
190-
else if (typeDeclarationType == DeclarationType.ClassModule)
191-
{
192-
var module = new ClassModuleDeclaration(typeQualifiedMemberName, projectDeclaration, typeName, true, new List<IAnnotation>(), attributes, isExposed: true, isGlobalClassModule: true);
193-
var implements = GetImplementedInterfaceNames(typeAttributes, info);
194-
foreach (var supertypeName in implements)
195-
{
196-
module.AddSupertype(supertypeName);
197-
}
198-
moduleDeclaration = module;
199-
}
200-
else
194+
switch (typeDeclarationType)
201195
{
202-
moduleDeclaration = new Declaration(
203-
typeQualifiedMemberName,
204-
projectDeclaration,
205-
projectDeclaration,
206-
typeName,
207-
null,
208-
false,
209-
false,
210-
Accessibility.Global,
211-
typeDeclarationType,
212-
null,
213-
Selection.Home,
214-
false,
215-
null,
216-
true,
217-
null,
218-
attributes);
196+
case DeclarationType.ProceduralModule:
197+
moduleDeclaration = new ProceduralModuleDeclaration(typeQualifiedMemberName, projectDeclaration, typeName, true, new List<IAnnotation>(), attributes);
198+
break;
199+
case DeclarationType.ClassModule:
200+
var module = new ClassModuleDeclaration(typeQualifiedMemberName, projectDeclaration, typeName, true, new List<IAnnotation>(), attributes);
201+
var implements = GetImplementedInterfaceNames(typeAttributes, info);
202+
foreach (var supertypeName in implements)
203+
{
204+
module.AddSupertype(supertypeName);
205+
}
206+
moduleDeclaration = module;
207+
break;
208+
default:
209+
moduleDeclaration = new Declaration(
210+
typeQualifiedMemberName,
211+
projectDeclaration,
212+
projectDeclaration,
213+
typeName,
214+
null,
215+
false,
216+
false,
217+
Accessibility.Global,
218+
typeDeclarationType,
219+
null,
220+
Selection.Home,
221+
false,
222+
null,
223+
true,
224+
null,
225+
attributes);
226+
break;
219227
}
220228

221229
yield return moduleDeclaration;
@@ -296,103 +304,94 @@ private Declaration CreateMemberDeclaration(out FUNCDESC memberDescriptor, TYPEK
296304
attributes.AddHiddenMemberAttribute(memberName);
297305
}
298306

299-
if (memberDeclarationType == DeclarationType.Procedure)
300-
{
301-
return new SubroutineDeclaration(
302-
new QualifiedMemberName(typeQualifiedModuleName, memberName),
303-
moduleDeclaration,
304-
moduleDeclaration,
305-
asTypeName,
306-
Accessibility.Global,
307-
null,
308-
Selection.Home,
309-
true,
310-
null,
311-
attributes);
312-
}
313-
else if (memberDeclarationType == DeclarationType.Function)
314-
{
315-
return new FunctionDeclaration(
316-
new QualifiedMemberName(typeQualifiedModuleName, memberName),
317-
moduleDeclaration,
318-
moduleDeclaration,
319-
asTypeName,
320-
null,
321-
null,
322-
Accessibility.Global,
323-
null,
324-
Selection.Home,
325-
// TODO: how to find out if it's an array?
326-
false,
327-
true,
328-
null,
329-
attributes);
330-
}
331-
else if (memberDeclarationType == DeclarationType.PropertyGet)
332-
{
333-
return new PropertyGetDeclaration(
334-
new QualifiedMemberName(typeQualifiedModuleName, memberName),
335-
moduleDeclaration,
336-
moduleDeclaration,
337-
asTypeName,
338-
null,
339-
null,
340-
Accessibility.Global,
341-
null,
342-
Selection.Home,
343-
// TODO: how to find out if it's an array?
344-
false,
345-
true,
346-
null,
347-
attributes);
348-
}
349-
else if (memberDeclarationType == DeclarationType.PropertySet)
350-
{
351-
return new PropertySetDeclaration(
352-
new QualifiedMemberName(typeQualifiedModuleName, memberName),
353-
moduleDeclaration,
354-
moduleDeclaration,
355-
asTypeName,
356-
Accessibility.Global,
357-
null,
358-
Selection.Home,
359-
true,
360-
null,
361-
attributes);
362-
}
363-
else if (memberDeclarationType == DeclarationType.PropertyLet)
307+
switch (memberDeclarationType)
364308
{
365-
return new PropertyLetDeclaration(
366-
new QualifiedMemberName(typeQualifiedModuleName, memberName),
367-
moduleDeclaration,
368-
moduleDeclaration,
369-
asTypeName,
370-
Accessibility.Global,
371-
null,
372-
Selection.Home,
373-
true,
374-
null,
375-
attributes);
376-
}
377-
else
378-
{
379-
return new Declaration(
380-
new QualifiedMemberName(typeQualifiedModuleName, memberName),
381-
moduleDeclaration,
382-
moduleDeclaration,
383-
asTypeName,
384-
null,
385-
false,
386-
false,
387-
Accessibility.Global,
388-
memberDeclarationType,
389-
null,
390-
Selection.Home,
391-
false,
392-
null,
393-
true,
394-
null,
395-
attributes);
309+
case DeclarationType.Procedure:
310+
return new SubroutineDeclaration(
311+
new QualifiedMemberName(typeQualifiedModuleName, memberName),
312+
moduleDeclaration,
313+
moduleDeclaration,
314+
asTypeName,
315+
Accessibility.Global,
316+
null,
317+
Selection.Home,
318+
true,
319+
null,
320+
attributes);
321+
case DeclarationType.Function:
322+
return new FunctionDeclaration(
323+
new QualifiedMemberName(typeQualifiedModuleName, memberName),
324+
moduleDeclaration,
325+
moduleDeclaration,
326+
asTypeName,
327+
null,
328+
null,
329+
Accessibility.Global,
330+
null,
331+
Selection.Home,
332+
// TODO: how to find out if it's an array?
333+
false,
334+
true,
335+
null,
336+
attributes);
337+
case DeclarationType.PropertyGet:
338+
return new PropertyGetDeclaration(
339+
new QualifiedMemberName(typeQualifiedModuleName, memberName),
340+
moduleDeclaration,
341+
moduleDeclaration,
342+
asTypeName,
343+
null,
344+
null,
345+
Accessibility.Global,
346+
null,
347+
Selection.Home,
348+
// TODO: how to find out if it's an array?
349+
false,
350+
true,
351+
null,
352+
attributes);
353+
case DeclarationType.PropertySet:
354+
return new PropertySetDeclaration(
355+
new QualifiedMemberName(typeQualifiedModuleName, memberName),
356+
moduleDeclaration,
357+
moduleDeclaration,
358+
asTypeName,
359+
Accessibility.Global,
360+
null,
361+
Selection.Home,
362+
true,
363+
null,
364+
attributes);
365+
case DeclarationType.PropertyLet:
366+
return new PropertyLetDeclaration(
367+
new QualifiedMemberName(typeQualifiedModuleName, memberName),
368+
moduleDeclaration,
369+
moduleDeclaration,
370+
asTypeName,
371+
Accessibility.Global,
372+
null,
373+
Selection.Home,
374+
true,
375+
null,
376+
attributes);
377+
default:
378+
return new Declaration(
379+
new QualifiedMemberName(typeQualifiedModuleName, memberName),
380+
moduleDeclaration,
381+
moduleDeclaration,
382+
asTypeName,
383+
null,
384+
false,
385+
false,
386+
Accessibility.Global,
387+
memberDeclarationType,
388+
null,
389+
Selection.Home,
390+
false,
391+
null,
392+
true,
393+
null,
394+
attributes);
396395
}
397396
}
398397

0 commit comments

Comments
 (0)