Skip to content

Commit 49916b1

Browse files
committed
fixed attribute parser to also work when there's code in the module :)
1 parent 55d00e0 commit 49916b1

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Rubberduck.Parsing/VBA/AttributeParser.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,29 @@ public override void ExitModuleAttributes(AttributesParser.ModuleAttributesConte
7777
_attributes.Add(_currentScope, _currentScopeAttributes);
7878
}
7979

80+
private static readonly IReadOnlyDictionary<Type, DeclarationType> ScopingContextTypes =
81+
new Dictionary<Type, DeclarationType>
82+
{
83+
{typeof(AttributesParser.SubStmtContext), DeclarationType.Procedure},
84+
{typeof(AttributesParser.FunctionStmtContext), DeclarationType.Function},
85+
{typeof(AttributesParser.PropertyGetStmtContext), DeclarationType.PropertyGet},
86+
{typeof(AttributesParser.PropertyLetStmtContext), DeclarationType.PropertyLet},
87+
{typeof(AttributesParser.PropertySetStmtContext), DeclarationType.PropertySet}
88+
};
89+
90+
public override void EnterAmbiguousIdentifier(AttributesParser.AmbiguousIdentifierContext context)
91+
{
92+
DeclarationType type;
93+
if (!ScopingContextTypes.TryGetValue(context.Parent.GetType(), out type))
94+
{
95+
return;
96+
}
97+
98+
_currentScope = Tuple.Create(context.GetText(), type);
99+
}
100+
80101
public override void EnterSubStmt(AttributesParser.SubStmtContext context)
81102
{
82-
_currentScope = Tuple.Create(context.ambiguousIdentifier().GetText(), DeclarationType.Procedure);
83103
_currentScopeAttributes = new Attributes();
84104
}
85105

@@ -90,7 +110,6 @@ public override void ExitSubStmt(AttributesParser.SubStmtContext context)
90110

91111
public override void EnterFunctionStmt(AttributesParser.FunctionStmtContext context)
92112
{
93-
_currentScope = Tuple.Create(context.ambiguousIdentifier().GetText(), DeclarationType.Function);
94113
_currentScopeAttributes = new Attributes();
95114
}
96115

@@ -101,7 +120,6 @@ public override void ExitFunctionStmt(AttributesParser.FunctionStmtContext conte
101120

102121
public override void EnterPropertyGetStmt(AttributesParser.PropertyGetStmtContext context)
103122
{
104-
_currentScope = Tuple.Create(context.ambiguousIdentifier().GetText(), DeclarationType.PropertyGet);
105123
_currentScopeAttributes = new Attributes();
106124
}
107125

@@ -112,7 +130,6 @@ public override void ExitPropertyGetStmt(AttributesParser.PropertyGetStmtContext
112130

113131
public override void EnterPropertyLetStmt(AttributesParser.PropertyLetStmtContext context)
114132
{
115-
_currentScope = Tuple.Create(context.ambiguousIdentifier().GetText(), DeclarationType.PropertyLet);
116133
_currentScopeAttributes = new Attributes();
117134
}
118135

@@ -123,7 +140,6 @@ public override void ExitPropertyLetStmt(AttributesParser.PropertyLetStmtContext
123140

124141
public override void EnterPropertySetStmt(AttributesParser.PropertySetStmtContext context)
125142
{
126-
_currentScope = Tuple.Create(context.ambiguousIdentifier().GetText(), DeclarationType.PropertySet);
127143
_currentScopeAttributes = new Attributes();
128144
}
129145

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ private void Resolve(DeclarationFinder finder)
264264
{
265265
try
266266
{
267+
//Parallel.ForEach(_state.AllDeclarations, declaration => declaration.ClearReferences());
268+
267269
foreach (var kvp in _state.ParseTrees)
268270
{
269271
ResolveReferences(finder, kvp.Key, kvp.Value);

0 commit comments

Comments
 (0)