Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rubberduck.parsing c#6&7 update #3582

Closed

Conversation

IvenBach
Copy link
Member

@IvenBach IvenBach commented Nov 29, 2017

F5 and Unit tested.

{
//Note - Enums and Types should enumerate *last*. That will prevent a duplicate module in the unlikely(?)
//instance where the TypeLib defines a module named "Enums" or "Types".
return _modules.Cast<IComType>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this comment get erased?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Learning mistake. For accessors like this with notes is it preferred to leave in { ... get { ... } } format?

@@ -29,8 +27,8 @@ public override IValue Evaluate()
var constantValue = _expression.Evaluate();
_symbolTable.Add(identifier, constantValue);
return new LivelinessExpression(
isAlive: new ConstantExpression(new BoolValue(false)),
tokens: _tokens).Evaluate();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing unnecessary argument names is not always good. They are usually there to aid readability.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will revert. Apologies for any overeager changes.

_stream = stream;
_tokenStream = tokenStream;
_symbolTable = symbolTable;
_stream = stream ?? throw new ArgumentNullException(nameof(stream));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I have already stated elsewhere, I do not really like guard clauses to be hidden away like this.

@@ -239,19 +232,20 @@ private void AddSubtype(Declaration subtype)
private void RemoveSubtype(Declaration subtype)
{
InvalidateCachedIsGlobal();
byte dummy;
_subtypes.TryRemove(subtype, out dummy);
_subtypes.TryRemove(subtype, out var dummy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be out _.

{
() =>
_unresolved = unresolvedMemberDeclarations
.ToList(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do such a change, please also remove the now clunky line break.

}

string token;
return HasTypeHint(out token);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't removing this eliminate the caching?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to take advantage of caching, the correct solution here is to introduce a Lazy instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lazy as in Lazy Class?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IvenBach the very one

{
foreach (var positionalArgument in argumentList.argument())
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to invert such conditions that lead to a continue or break statement?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#itdepends, I guess. in this case the benefit seems marginal

@@ -48,11 +47,13 @@ public override void EnterSubStmt(VBAParser.SubStmtContext context)

public override void ExitSubStmt(VBAParser.SubStmtContext context)
{
if(_currentScopeAttributes.Any())
if (!_currentScopeAttributes.Any())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why invert this condition?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over-eagerness with a new tool.

@@ -64,11 +65,13 @@ public override void EnterFunctionStmt(VBAParser.FunctionStmtContext context)

public override void ExitFunctionStmt(VBAParser.FunctionStmtContext context)
{
if(_currentScopeAttributes.Any())
if (!_currentScopeAttributes.Any())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito

@@ -80,11 +83,13 @@ public override void EnterPropertyGetStmt(VBAParser.PropertyGetStmtContext conte

public override void ExitPropertyGetStmt(VBAParser.PropertyGetStmtContext context)
{
if(_currentScopeAttributes.Any())
if (!_currentScopeAttributes.Any())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito

@@ -96,11 +101,13 @@ public override void EnterPropertyLetStmt(VBAParser.PropertyLetStmtContext conte

public override void ExitPropertyLetStmt(VBAParser.PropertyLetStmtContext context)
{
if(_currentScopeAttributes.Any())
if (!_currentScopeAttributes.Any())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito

@@ -112,11 +119,13 @@ public override void EnterPropertySetStmt(VBAParser.PropertySetStmtContext conte

public override void ExitPropertySetStmt(VBAParser.PropertySetStmtContext context)
{
if(_currentScopeAttributes.Any())
if (!_currentScopeAttributes.Any())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito

{
code = File.ReadAllText(path, Encoding.Default); //The VBE exports encoded in the current ANSI codepage from the windows settings.
}
var code = File.ReadAllText(path, module.ComponentType == ComponentType.Document ? Encoding.UTF8 : Encoding.Default);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the comments? They are rather helpful here.

@MDoerner
Copy link
Contributor

In contrast to what the title says, this PR does not merrily perform C#6 and C#7 syntactic updates.
Apparently, a lot more R# inspection results have been auto-fixed. In particular, a lot of conditions have been reverted for which I do not find the new order to be semantically more logical. Moreover, redundantly named arguments have been converted to ordinary arguments. There are still some more non-C#6, non-C#7 refactorings in this PR.

There are also some helpful comments that got erased in the refactorings.

@retailcoder retailcoder added the technical-debt This makes development harder or is leftover from a PullRequest. Needs to be adressed at some point. label Nov 30, 2017
@retailcoder
Copy link
Member

This PR touches on what's essentially the very core of RD; implementing the requested changes and keeping it up-to-date is becoming increasingly important.

@Vogel612 Vogel612 dismissed their stale review December 28, 2017 13:19

review is largely addressed. Remaining open points are not blocking

@IvenBach
Copy link
Member Author

I'll look at syncing this with the current build and getting it finalized by weekends end.

@codecov
Copy link

codecov bot commented Jan 3, 2018

Codecov Report

Merging #3582 into next will decrease coverage by 0.02%.
The diff coverage is 67.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #3582      +/-   ##
==========================================
- Coverage   71.21%   71.19%   -0.03%     
==========================================
  Files        1162     1161       -1     
  Lines       80274    80169     -105     
==========================================
- Hits        57167    57076      -91     
+ Misses      23107    23093      -14
Impacted Files Coverage Δ
...Parsing/VBA/SynchronousCOMReferenceSynchronizer.cs 100% <ø> (ø) ⬆️
Rubberduck.Parsing/ComReflection/ComType.cs 0% <ø> (ø) ⬆️
Rubberduck.Parsing/Emitter.cs 0% <ø> (ø) ⬆️
...ubberduck.Parsing/Preprocessing/VBAPreprocessor.cs 100% <ø> (ø) ⬆️
...k.Parsing/Preprocessing/VBAPrecompilationParser.cs 29.62% <ø> (ø) ⬆️
Rubberduck.Parsing/VBA/ParseRunnerBase.cs 90.16% <ø> (ø) ⬆️
...essing/ConditionalCompilationConstantExpression.cs 100% <ø> (ø) ⬆️
Rubberduck.Parsing/VBA/VBAModuleParser.cs 72.41% <ø> (ø) ⬆️
...ing/Preprocessing/CVarLibraryFunctionExpression.cs 100% <ø> (ø) ⬆️
Rubberduck.Parsing/Symbols/FunctionDeclaration.cs 54.76% <ø> (ø) ⬆️
... and 147 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c2f2320...eaab10f. Read the comment docs.

@@ -81,28 +81,31 @@ public bool HasExplicitCallStatement()
return Context.Parent is VBAParser.CallStmtContext && ((VBAParser.CallStmtContext)Context).CALL() != null;
}

private Lazy<bool> _hasTypeHint = new Lazy<bool>(() => ComputeHasTypeHint());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you don't need the line 84-91. You only need one line here -- private bool HasTypeHint() => new Lazy<bool>(() => ComputeTypeHint()).Value; (untested aircode!)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not correct. that's not caching the value again. What's necessary is initializing _hasTypeHint in the ctor. @bclothier your code instantiates a new Lazy every invocation of HasTypeHint(), which is exactly what we wanted to avoid.

HasTypeHint should become: public bool HasTypeHint() => _hasTypeHint.Value;

@@ -82,15 +84,7 @@ public bool HasExplicitCallStatement()
}

private Lazy<bool> _hasTypeHint;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is only initialized in the ctor, it can be made readonly or converted into an expression-bodied statement.

@retailcoder retailcoder added PR-Status: Conflicting PR can't be merged as it stands, conflicts must be resolved by the author. and removed PR-Status: WIP Pull request is work-in-progress, more commits should be expected. labels Jan 10, 2018
@IvenBach IvenBach deleted the Rubberduck.Parsing_C#6&7_Update branch January 25, 2018 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Status: Conflicting PR can't be merged as it stands, conflicts must be resolved by the author. technical-debt This makes development harder or is leftover from a PullRequest. Needs to be adressed at some point.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants