Skip to content

Commit 8e38ea7

Browse files
Andrin Meierretailcoder
authored andcommitted
clean up file statements + consider inherited members as belonging to enclosed module + special forms (#1499)
* clean up file statements (fixes #1487) * consider members in supertypes as members of enclosing module (fixes #1489) * remove temp fix (should be fixed with #1489) * add support for Circle and Scale special forms (fixes #1498)
1 parent 1c24ea0 commit 8e38ea7

27 files changed

+13022
-8631
lines changed

Rubberduck.Parsing/Binding/DefaultBindingContext.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ public IExpressionBinding BuildTree(Declaration module, Declaration parent, Pars
3838

3939
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAExpressionParser.StartRuleContext expression, IBoundExpression withBlockVariable, ResolutionStatementContext statementContext)
4040
{
41-
// Call statements always have an argument list
41+
// Call statements always have an argument list.
42+
// One of the reasons we're doing this is that an empty argument list could represent a call to a default member,
43+
// which requires us to use an IndexDefaultBinding.
4244
if (statementContext == ResolutionStatementContext.CallStatement)
4345
{
4446
if (expression.callStmt() != null)
@@ -115,6 +117,14 @@ private IExpressionBinding Visit(Declaration module, Declaration parent, VBAExpr
115117
return Visit(module, parent, expression.newExpression(), withBlockVariable, ResolutionStatementContext.Undefined);
116118
}
117119

120+
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAExpressionParser.MarkedFileNumberExprContext expression, IBoundExpression withBlockVariable, ResolutionStatementContext statementContext)
121+
{
122+
// The MarkedFileNumberExpr doesn't actually exist but for backwards compatibility reasons we support it, ignore the "hash tag" of the file number
123+
// and resolve it as a normal expression.
124+
// This allows us to support functions such as Input(file1, #file1) which would otherwise not work.
125+
return Visit(module, parent, (dynamic)expression.expression(), withBlockVariable, ResolutionStatementContext.Undefined);
126+
}
127+
118128
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAExpressionParser.NewExpressionContext expression, IBoundExpression withBlockVariable, ResolutionStatementContext statementContext)
119129
{
120130
var typeExpressionBinding = Visit(module, parent, expression.typeExpression(), withBlockVariable, ResolutionStatementContext.Undefined);

Rubberduck.Parsing/Binding/IndexDefaultBinding.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ and declared type.
269269
*/
270270
if (lExpression.Classification == ExpressionClassification.Property
271271
|| lExpression.Classification == ExpressionClassification.Function
272-
|| lExpression.Classification == ExpressionClassification.Subroutine
273-
|| lExpression.Classification == ExpressionClassification.Type)
272+
|| lExpression.Classification == ExpressionClassification.Subroutine)
274273
{
275274
return new IndexExpression(lExpression.ReferencedDeclaration, lExpression.Classification, _expression, lExpression, _argumentList);
276275
}

Rubberduck.Parsing/Binding/MemberAccessDefaultBinding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ private IBoundExpression ResolveMemberInReferencedProject(bool lExpressionIsEncl
349349
{
350350
if (lExpressionIsEnclosingProject)
351351
{
352-
var foundType = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, _name, memberType);
352+
var foundType = _declarationFinder.FindMemberEnclosingModule(_module, _parent, _name, memberType);
353353
if (foundType != null)
354354
{
355355
return new MemberAccessExpression(foundType, classification, _context, _unrestrictedNameContext, _lExpression);

Rubberduck.Parsing/Binding/MemberAccessTypeBinding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ refers to the specified UDT or enum.
219219
*/
220220
if (lExpressionIsEnclosingProject)
221221
{
222-
var foundType = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, memberType);
222+
var foundType = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, memberType);
223223
if (foundType != null)
224224
{
225225
return new MemberAccessExpression(foundType, ExpressionClassification.Type, GetExpressionContext(), _unrestrictedNameContext, lExpression);

Rubberduck.Parsing/Binding/SimpleNameDefaultBinding.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,37 +101,37 @@ private IBoundExpression ResolveEnclosingModuleNamespace(string name)
101101
Enclosing Module namespace: A variable, constant, Enum type, Enum member, property,
102102
function or subroutine defined at the module-level in the enclosing module.
103103
*/
104-
var moduleVariable = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.Variable);
104+
var moduleVariable = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.Variable);
105105
if (IsValidMatch(moduleVariable, name))
106106
{
107107
return new SimpleNameExpression(moduleVariable, ExpressionClassification.Variable, _expression);
108108
}
109-
var moduleConstant = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.Constant);
109+
var moduleConstant = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.Constant);
110110
if (IsValidMatch(moduleConstant, name))
111111
{
112112
return new SimpleNameExpression(moduleConstant, ExpressionClassification.Variable, _expression);
113113
}
114-
var enumType = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.Enumeration);
114+
var enumType = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.Enumeration);
115115
if (IsValidMatch(enumType, name))
116116
{
117117
return new SimpleNameExpression(enumType, ExpressionClassification.Type, _expression);
118118
}
119-
var enumMember = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.EnumerationMember);
119+
var enumMember = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.EnumerationMember);
120120
if (IsValidMatch(enumMember, name))
121121
{
122122
return new SimpleNameExpression(enumMember, ExpressionClassification.Value, _expression);
123123
}
124-
var property = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, _propertySearchType);
124+
var property = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, _propertySearchType);
125125
if (IsValidMatch(property, name))
126126
{
127127
return new SimpleNameExpression(property, ExpressionClassification.Property, _expression);
128128
}
129-
var function = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.Function);
129+
var function = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.Function);
130130
if (IsValidMatch(function, name))
131131
{
132132
return new SimpleNameExpression(function, ExpressionClassification.Function, _expression);
133133
}
134-
var subroutine = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.Procedure);
134+
var subroutine = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.Procedure);
135135
if (IsValidMatch(subroutine, name))
136136
{
137137
return new SimpleNameExpression(subroutine, ExpressionClassification.Subroutine, _expression);

Rubberduck.Parsing/Binding/SimpleNameProcedurePointerBinding.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ private IBoundExpression ResolveEnclosingModule(string name)
4848
Enclosing Module namespace: A function, subroutine or property with a Property Get defined
4949
at the module-level in the enclosing module.
5050
*/
51-
var function = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.Function);
51+
var function = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.Function);
5252
if (function != null)
5353
{
5454
return new SimpleNameExpression(function, ExpressionClassification.Function, _expression);
5555
}
56-
var subroutine = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.Procedure);
56+
var subroutine = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.Procedure);
5757
if (subroutine != null)
5858
{
5959
return new SimpleNameExpression(subroutine, ExpressionClassification.Subroutine, _expression);
6060
}
61-
var propertyGet = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.PropertyGet);
61+
var propertyGet = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.PropertyGet);
6262
if (propertyGet != null)
6363
{
6464
return new SimpleNameExpression(propertyGet, ExpressionClassification.Property, _expression);

Rubberduck.Parsing/Binding/SimpleNameTypeBinding.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ private IBoundExpression ResolveEnclosingModule(string name)
9797
Enclosing Module namespace: A UDT or Enum type defined at the module-level in the
9898
enclosing module.
9999
*/
100-
var udt = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.UserDefinedType);
100+
var udt = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.UserDefinedType);
101101
if (udt != null)
102102
{
103103
return new SimpleNameExpression(udt, ExpressionClassification.Type, _expression);
104104
}
105-
var enumType = _declarationFinder.FindMemberEnclosingModule(_project, _module, _parent, name, DeclarationType.Enumeration);
105+
var enumType = _declarationFinder.FindMemberEnclosingModule(_module, _parent, name, DeclarationType.Enumeration);
106106
if (enumType != null)
107107
{
108108
return new SimpleNameExpression(enumType, ExpressionClassification.Type, _expression);

0 commit comments

Comments
 (0)