Skip to content

Commit 2a3003c

Browse files
authored
Merge pull request #1919 from Hosch250/Issue1843
Add overload to Visit in resolver
2 parents 593d34e + f679c57 commit 2a3003c

File tree

2 files changed

+26
-48
lines changed

2 files changed

+26
-48
lines changed

Rubberduck.Parsing/Binding/TypeBindingContext.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ private IExpressionBinding Visit(Declaration module, Declaration parent, VBAPars
4444
return Visit(module, parent, lexpr);
4545
}
4646

47+
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.IndexExprContext expression)
48+
{
49+
dynamic lexpr = expression.lExpression();
50+
var type = expression.lExpression().GetType();
51+
return Visit(module, parent, lexpr);
52+
}
53+
4754
private IExpressionBinding Visit(Declaration module, Declaration parent, VBAParser.SimpleNameExprContext expression)
4855
{
4956
return new SimpleNameTypeBinding(_declarationFinder, Declaration.GetProjectParent(parent), module, parent, expression);

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,14 @@ private void ParseAll()
260260
return;
261261
}
262262

263-
lock (State) // note, method is invoked from UI thread... really need the lock here?
263+
foreach (var component in toParse)
264264
{
265-
foreach (var component in toParse)
266-
{
267-
State.SetModuleState(component, ParserState.Pending);
268-
}
269-
foreach (var component in unchanged)
270-
{
271-
// note: seting to 'Parsed' would include them in the resolver walk. 'Ready' excludes them.
272-
State.SetModuleState(component, ParserState.Ready);
273-
}
265+
State.SetModuleState(component, ParserState.Pending);
266+
}
267+
foreach (var component in unchanged)
268+
{
269+
// note: seting to 'Parsed' would include them in the resolver walk. 'Ready' excludes them.
270+
State.SetModuleState(component, ParserState.Ready);
274271
}
275272

276273
// invalidation cleanup should go into ParseAsync?
@@ -304,10 +301,7 @@ private void ParseAll()
304301
Logger.Debug("Module '{0}' {1}", qualifiedName.ComponentName,
305302
State.IsNewOrModified(qualifiedName) ? "was modified" : "was NOT modified");
306303

307-
lock (State)
308-
{
309-
State.SetModuleState(toParse[index], ParserState.ResolvingDeclarations);
310-
}
304+
State.SetModuleState(toParse[index], ParserState.ResolvingDeclarations);
311305

312306
ResolveDeclarations(qualifiedName.Component,
313307
State.ParseTrees.Find(s => s.Key == qualifiedName).Value);
@@ -349,10 +343,7 @@ private Task[] ResolveReferencesAsync()
349343

350344
tasks[index] = Task.Run(() =>
351345
{
352-
lock (State)
353-
{
354-
State.SetModuleState(kvp.Key.Component, ParserState.ResolvingReferences);
355-
}
346+
State.SetModuleState(kvp.Key.Component, ParserState.ResolvingReferences);
356347

357348
ResolveReferences(finder, kvp.Key.Component, kvp.Value);
358349
});
@@ -363,14 +354,11 @@ private Task[] ResolveReferencesAsync()
363354

364355
private void AddBuiltInDeclarations()
365356
{
366-
lock (State)
357+
foreach (var customDeclarationLoader in _customDeclarationLoaders)
367358
{
368-
foreach (var customDeclarationLoader in _customDeclarationLoaders)
359+
foreach (var declaration in customDeclarationLoader.Load())
369360
{
370-
foreach (var declaration in customDeclarationLoader.Load())
371-
{
372-
State.AddDeclaration(declaration);
373-
}
361+
State.AddDeclaration(declaration);
374362
}
375363
}
376364
}
@@ -512,12 +500,8 @@ private void UnloadComReference(Reference reference, IReadOnlyList<VBProject> pr
512500

513501
private Task ParseAsync(VBComponent component, CancellationToken token, TokenStreamRewriter rewriter = null)
514502
{
515-
lock (State)
516-
lock (component)
517-
{
518-
State.ClearStateCache(component);
519-
State.SetModuleState(component, ParserState.Pending); // also clears module-exceptions
520-
}
503+
State.ClearStateCache(component);
504+
State.SetModuleState(component, ParserState.Pending); // also clears module-exceptions
521505

522506
var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_central.Token, token);
523507

@@ -566,11 +550,7 @@ private void ParseAsyncInternal(VBComponent component, CancellationToken token,
566550
var parser = new ComponentParseTask(component, preprocessor, _attributeParser, rewriter);
567551
parser.ParseFailure += (sender, e) =>
568552
{
569-
lock (State)
570-
lock (component)
571-
{
572-
State.SetModuleState(component, ParserState.Error, e.Cause as SyntaxErrorException);
573-
}
553+
State.SetModuleState(component, ParserState.Error, e.Cause as SyntaxErrorException);
574554
};
575555
parser.ParseCompleted += (sender, e) =>
576556
{
@@ -587,11 +567,8 @@ private void ParseAsyncInternal(VBComponent component, CancellationToken token,
587567
State.SetModuleState(component, ParserState.Parsed);
588568
}
589569
};
590-
lock (State)
591-
lock (component)
592-
{
593-
State.SetModuleState(component, ParserState.Parsing);
594-
}
570+
State.SetModuleState(component, ParserState.Parsing);
571+
595572
parser.Start(token);
596573
}
597574

@@ -611,10 +588,7 @@ private void ResolveDeclarations(VBComponent component, IParseTree tree)
611588
{
612589
projectDeclaration = CreateProjectDeclaration(projectQualifiedName, project);
613590
_projectDeclarations.AddOrUpdate(projectQualifiedName.ProjectId, projectDeclaration, (s, c) => projectDeclaration);
614-
lock (State)
615-
{
616-
State.AddDeclaration(projectDeclaration);
617-
}
591+
State.AddDeclaration(projectDeclaration);
618592
}
619593
Logger.Debug("Creating declarations for module {0}.", qualifiedModuleName.Name);
620594
var declarationsListener = new DeclarationSymbolsListener(State, qualifiedModuleName, component.Type, State.GetModuleAnnotations(component), State.GetModuleAttributes(component), projectDeclaration);
@@ -627,10 +601,7 @@ private void ResolveDeclarations(VBComponent component, IParseTree tree)
627601
catch (Exception exception)
628602
{
629603
Logger.Error(exception, "Exception thrown acquiring declarations for '{0}' (thread {1}).", component.Name, Thread.CurrentThread.ManagedThreadId);
630-
lock (State)
631-
{
632-
State.SetModuleState(component, ParserState.ResolverError);
633-
}
604+
State.SetModuleState(component, ParserState.ResolverError);
634605
}
635606
}
636607

0 commit comments

Comments
 (0)