Skip to content

Commit 58d595f

Browse files
committed
Fix constant types, finished the struct members I forgot, consolidate enums and types in 2 pseudo-modules.
1 parent 0336253 commit 58d595f

File tree

6 files changed

+219
-121
lines changed

6 files changed

+219
-121
lines changed

Rubberduck.Parsing/ComReflection/ComField.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public ComField(string name, VARDESC varDesc, int index, DeclarationType type)
3535
}
3636
else
3737
{
38-
38+
Debug.Assert(varDesc.varkind == VARKIND.VAR_PERINSTANCE);
39+
string typeName;
40+
ValueType = ComVariant.TypeNames.TryGetValue((VarEnum)varDesc.elemdescVar.tdesc.vt, out typeName) ? typeName : "Object";
3941
}
4042
}
4143
}

Rubberduck.Parsing/ComReflection/ComProject.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public IEnumerable<IComType> Members
5959
{
6060
get
6161
{
62+
//Note - Enums and Types should enumerate *last*. That will prevent a duplicate module in the unlikely(?)
63+
//instance where the TypeLib defines a module named "Enums" or "Types".
6264
return _modules.Cast<IComType>()
6365
.Union(_interfaces)
6466
.Union(_classes)
@@ -118,6 +120,10 @@ private void LoadModules(ITypeLib typeLibrary)
118120
if (type != null) KnownTypes.TryAdd(typeAttributes.guid, coclass);
119121
break;
120122
case TYPEKIND.TKIND_ALIAS:
123+
//The current handling of this is wrong - these don't have to be classes or interfaces. In the VBE module for example,
124+
//"LongPtr" is defined as an alias to "Long" (at least on a 32 bit system) - RD is currently treating is like a class.
125+
//Unclear if these can *also* define alternative names for interfaces as well, but all the ones I've seen have been basically
126+
//a C typedef. So... this needs work. Don't make any assumptions about these elsewhere in the code until this is nailed down.
121127
case TYPEKIND.TKIND_DISPATCH:
122128
case TYPEKIND.TKIND_INTERFACE:
123129
var intface = type ?? new ComInterface(typeLibrary, info, typeAttributes, index);
@@ -138,10 +144,7 @@ private void LoadModules(ITypeLib typeLibrary)
138144
}
139145
info.ReleaseTypeAttr(typeAttributesPointer);
140146
}
141-
catch (NullReferenceException)
142-
{
143-
return;
144-
}
147+
catch (COMException) { }
145148
}
146149
}
147150
}

Rubberduck.Parsing/Symbols/Declaration.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public Declaration(ComEnumeration enumeration, Declaration parent, QualifiedModu
168168
module.QualifyMemberName(enumeration.Name),
169169
parent,
170170
parent,
171-
enumeration.Name,
171+
"Long", //Match the VBA default type declaration. Technically these *can* be a LongLong on 64 bit systems, but would likely crash the VBE...
172172
null,
173173
false,
174174
false,
@@ -182,6 +182,25 @@ public Declaration(ComEnumeration enumeration, Declaration parent, QualifiedModu
182182
null,
183183
new Attributes()) { }
184184

185+
public Declaration(ComStruct structure, Declaration parent, QualifiedModuleName module)
186+
: this(
187+
module.QualifyMemberName(structure.Name),
188+
parent,
189+
parent,
190+
structure.Name,
191+
null,
192+
false,
193+
false,
194+
Accessibility.Global,
195+
DeclarationType.UserDefinedType,
196+
null,
197+
Selection.Home,
198+
false,
199+
null,
200+
true,
201+
null,
202+
new Attributes()) { }
203+
185204
public Declaration(ComEnumerationMember member, Declaration parent, QualifiedModuleName module) : this(
186205
module.QualifyMemberName(member.Name),
187206
parent,
@@ -202,7 +221,7 @@ public Declaration(ComField field, Declaration parent, QualifiedModuleName modul
202221
module.QualifyMemberName(field.Name),
203222
parent,
204223
parent,
205-
field.Name,
224+
field.ValueType,
206225
null,
207226
false,
208227
false,

Rubberduck.Parsing/Symbols/ProceduralModuleDeclaration.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,7 @@ public ProceduralModuleDeclaration(ComModule statics, Declaration parent, Qualif
4646
IsPrivateModule = statics.IsRestricted;
4747
}
4848

49-
//This is the pseudo-module ctor for COM enumerations.
50-
public ProceduralModuleDeclaration(ComEnumeration enumeration, Declaration parent, QualifiedModuleName module)
51-
: this(
52-
module.QualifyMemberName(string.Format("_{0}", enumeration.Name)),
53-
parent,
54-
string.Format("_{0}", enumeration.Name),
55-
true,
56-
new List<IAnnotation>(),
57-
new Attributes()) { }
58-
59-
//This is the pseudo-module ctor for anything else from COM with fields instead of members.
49+
//This is the pseudo-module ctor for COM enumerations and types.
6050
public ProceduralModuleDeclaration(string pseudo, Declaration parent, QualifiedModuleName module)
6151
: this(
6252
module.QualifyMemberName(pseudo),

0 commit comments

Comments
 (0)