Skip to content

Commit 6d65242

Browse files
authored
Merge pull request #2658 from comintern/next
Finish first class support of TYPEKIND.TKIND_ALIAS. *Now* closes #2538
2 parents af0f60b + 2d4434e commit 6d65242

File tree

13 files changed

+96
-26
lines changed

13 files changed

+96
-26
lines changed

RetailCoder.VBE/UI/Command/MenuItems/CommandBars/IContextFormatter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ private string Format(Declaration declaration)
8484
declaration.IdentifierName,
8585
typeName);
8686
}
87+
else if (declaration.DeclarationType == DeclarationType.ComAlias)
88+
{
89+
formattedDeclaration = string.Format("{0};{1}.{2} (alias:{3})",
90+
System.IO.Path.GetFileName(moduleName.ProjectPath), moduleName.ProjectName,
91+
declaration.IdentifierName, declaration.AsTypeName);
92+
}
8793

8894
var subscripts = declaration.IsArray ? "()" : string.Empty;
8995
if (declaration.ParentDeclaration != null && declaration.ParentDeclaration.DeclarationType.HasFlag(DeclarationType.Member))

RetailCoder.VBE/VersionCheck/IVersionCheck.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ public VersionCheck()
2626
{
2727
if (_latestVersion != default(Version)) { return _latestVersion; }
2828

29-
using (var client = new HttpClient())
29+
try
3030
{
31-
var url = new Uri("http://rubberduckvba.com/Build/Version/Stable");
32-
var response = await client.GetAsync(url, token);
33-
var content = await response.Content.ReadAsStringAsync();
34-
var doc = new HtmlAgilityPack.HtmlDocument();
35-
doc.LoadHtml(content);
36-
var version = doc.DocumentNode.Descendants("body").Single().InnerText.Trim();
37-
return _latestVersion = new Version(version);
31+
using (var client = new HttpClient())
32+
{
33+
var url = new Uri("http://rubberduckvba.com/Build/Version/Stable");
34+
var response = await client.GetAsync(url, token);
35+
var content = await response.Content.ReadAsStringAsync();
36+
var doc = new HtmlAgilityPack.HtmlDocument();
37+
doc.LoadHtml(content);
38+
var version = doc.DocumentNode.Descendants("body").Single().InnerText.Trim();
39+
return _latestVersion = new Version(version);
40+
}
41+
}
42+
catch
43+
{
44+
return _latestVersion;
3845
}
3946
}
4047

Rubberduck.Parsing/Binding/SimpleNameTypeBinding.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ procedural module or class module within a referenced project.
205205
{
206206
return new SimpleNameExpression(referencedProjectEnumType, ExpressionClassification.Type, _expression);
207207
}
208+
var referencedProjectAliasType = _declarationFinder.FindMemberReferencedProject(_project, _module, _parent, name, DeclarationType.ComAlias);
209+
if (referencedProjectAliasType != null)
210+
{
211+
return new SimpleNameExpression(referencedProjectAliasType, ExpressionClassification.Type, _expression);
212+
}
208213
return null;
209214
}
210215
}

Rubberduck.Parsing/ComReflection/ComAlias.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,45 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
4-
using System.Linq;
53
using System.Runtime.InteropServices;
64
using System.Runtime.InteropServices.ComTypes;
7-
using System.Security.Permissions;
8-
using System.Text;
9-
using System.Threading.Tasks;
105
using TYPEATTR = System.Runtime.InteropServices.ComTypes.TYPEATTR;
6+
using TYPEFLAGS = System.Runtime.InteropServices.ComTypes.TYPEFLAGS;
117

128
namespace Rubberduck.Parsing.ComReflection
139
{
10+
[DebuggerDisplay("{Name} As {TypeName}")]
1411
public class ComAlias : ComBase
1512
{
16-
public VarEnum VarType { get; set; }
17-
18-
public string TypeName { get; set; }
13+
public VarEnum VarType { get; private set; }
14+
public string TypeName { get; private set; }
15+
public bool IsHidden { get; private set; }
16+
public bool IsRestricted { get; private set; }
1917

2018
public ComAlias(ITypeLib typeLib, ITypeInfo info, int index, TYPEATTR attributes) : base(typeLib, index)
2119
{
2220
Index = index;
2321
Documentation = new ComDocumentation(typeLib, index);
22+
Guid = attributes.guid;
2423
VarType = (VarEnum)attributes.tdescAlias.vt;
24+
IsHidden = attributes.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FHIDDEN);
25+
IsRestricted = attributes.wTypeFlags.HasFlag(TYPEFLAGS.TYPEFLAG_FRESTRICTED);
26+
27+
if (Name.Equals("LONG_PTR"))
28+
{
29+
TypeName = "LongPtr";
30+
return;
31+
}
32+
2533
if (ComVariant.TypeNames.ContainsKey(VarType))
2634
{
2735
TypeName = ComVariant.TypeNames[VarType];
2836
}
2937
else if (VarType == VarEnum.VT_USERDEFINED)
3038
{
31-
//?
39+
ITypeInfo refType;
40+
info.GetRefTypeInfo((int)attributes.tdescAlias.lpValue, out refType);
41+
var doc = new ComDocumentation(refType, -1);
42+
TypeName = doc.Name;
3243
}
3344
else
3445
{

Rubberduck.Parsing/ComReflection/ComDocumentation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private void LoadDocumentation(ITypeLib typeLib, ITypeInfo info, int index)
3636
}
3737

3838
//See http://chat.stackexchange.com/transcript/message/30119269#30119269
39-
Name = name.Equals("LONG_PTR") ? "LongPtr" : name;
39+
Name = name;
4040
DocString = docString;
4141
HelpContext = helpContext;
4242
HelpFile = helpFile;

Rubberduck.Parsing/ComReflection/ComProject.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ private void LoadModules(ITypeLib typeLibrary)
125125
_classes.Add(coclass as ComCoClass);
126126
if (type != null) KnownTypes.TryAdd(typeAttributes.guid, coclass);
127127
break;
128-
case TYPEKIND.TKIND_ALIAS:
129128
case TYPEKIND.TKIND_DISPATCH:
130129
case TYPEKIND.TKIND_INTERFACE:
131130
var intface = type ?? new ComInterface(typeLibrary, info, typeAttributes, index);
@@ -141,11 +140,10 @@ private void LoadModules(ITypeLib typeLibrary)
141140
_modules.Add(module as ComModule);
142141
if (type != null) KnownTypes.TryAdd(typeAttributes.guid, module);
143142
break;
144-
//case TYPEKIND.TKIND_ALIAS:
145-
// //TKIND_ALIAS does not appear to be a supported member type in VBA - cache it internally to use the aliased type.
146-
// var alias = new ComAlias(typeLibrary, info, index, typeAttributes);
147-
// _aliases.Add(alias);
148-
// break;
143+
case TYPEKIND.TKIND_ALIAS:
144+
var alias = new ComAlias(typeLibrary, info, index, typeAttributes);
145+
_aliases.Add(alias);
146+
break;
149147
case TYPEKIND.TKIND_UNION:
150148
//TKIND_UNION is not a supported member type in VBA.
151149
break;

Rubberduck.Parsing/ComReflection/ComVariant.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ComVariant
1313
{VarEnum.VT_DISPATCH, Tokens.Object},
1414
{VarEnum.VT_VOID, string.Empty},
1515
{VarEnum.VT_VARIANT, Tokens.Variant},
16+
{VarEnum.VT_UNKNOWN, Tokens.Object},
1617
{VarEnum.VT_BLOB_OBJECT, Tokens.Object},
1718
{VarEnum.VT_STORED_OBJECT, Tokens.Object},
1819
{VarEnum.VT_STREAMED_OBJECT, Tokens.Object},
@@ -35,7 +36,7 @@ public class ComVariant
3536
{VarEnum.VT_DECIMAL, Tokens.Decimal},
3637
{VarEnum.VT_EMPTY, Tokens.Empty},
3738
{VarEnum.VT_R4, Tokens.Single},
38-
{VarEnum.VT_R8, Tokens.Double},
39+
{VarEnum.VT_R8, Tokens.Double}
3940
};
4041

4142

Rubberduck.Parsing/ComReflection/ReferencedDeclarationsCollector.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ public List<Declaration> LoadDeclarationsFromLibrary()
132132
_serialized = new SerializableProject(project);
133133
_declarations.Add(project);
134134

135+
foreach (var alias in type.Aliases.Select(item => new AliasDeclaration(item, project, projectName)))
136+
{
137+
_declarations.Add(alias);
138+
_serialized.AddDeclaration(new SerializableDeclarationTree(alias));
139+
}
140+
135141
foreach (var module in type.Members)
136142
{
137143
var moduleName = new QualifiedModuleName(_referenceName, _path,

Rubberduck.Parsing/Rubberduck.Parsing.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
<Compile Include="ComReflection\ComModule.cs" />
148148
<Compile Include="ComReflection\ComProject.cs" />
149149
<Compile Include="SymbolList.cs" />
150+
<Compile Include="Symbols\AliasDeclaration.cs" />
150151
<Compile Include="Symbols\DeclarationLoaders\SpecialFormDeclarations.cs" />
151152
<Compile Include="Symbols\CommentNode.cs" />
152153
<Compile Include="ComReflection\ComParameter.cs" />

Rubberduck.Parsing/Symbols/AccessibilityCheck.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,15 @@ public static bool IsMemberAccessible(Declaration callingProject, Declaration ca
4545
{
4646
return true;
4747
}
48+
if (calleeMember.IsBuiltIn && calleeMember.Accessibility > Accessibility.Friend)
49+
{
50+
return true;
51+
}
4852
var memberModule = Declaration.GetModuleParent(calleeMember);
4953
return IsModuleAccessible(callingProject, callingModule, memberModule)
5054
&& (calleeMember.DeclarationType.HasFlag(DeclarationType.EnumerationMember)
5155
|| calleeMember.DeclarationType.HasFlag(DeclarationType.UserDefinedTypeMember)
56+
|| calleeMember.DeclarationType.HasFlag(DeclarationType.ComAlias)
5257
|| HasPublicScope(calleeMember)
5358
|| (IsEnclosingProject(callingProject, memberModule) && IsAccessibleThroughoutTheSameProject(calleeMember)));
5459
}

0 commit comments

Comments
 (0)