Skip to content

Commit eaf2de5

Browse files
committed
Fix for bad VT_PTR pointers in referenced type libraries (#1596)
* added AsTypeName to the context-sensitive commandbar * clear built-in references at every resolution; fixed issue with null parse trees, given built-in modules get a module state instance. * fixed OverflowException in GetTypeName; built-in parameters now have return type info :) * returning built-in members now have return type info as well * removed hard-coded defaults in ClassModuleDeclaration * added IsBadReadPtr check in COM declarations collector
1 parent e4a415d commit eaf2de5

File tree

3 files changed

+172
-147
lines changed

3 files changed

+172
-147
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

0 commit comments

Comments
 (0)