-
Notifications
You must be signed in to change notification settings - Fork 2
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
Replace libdparse with DMD in UselessInitializerChecker #121
Replace libdparse with DMD in UselessInitializerChecker #121
Conversation
dd1f4f9
to
06c9ae3
Compare
return; | ||
|
||
assert(_inStruct.length > 1); | ||
string structName = cast(string) structDecl.ident.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't the cast useless here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. Identifier#toString() returns const(char)[]
. Isn't the D string an alias for immutable(char)[]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I expected that toString returns a D string.
assert(_inStruct.length > 1); | ||
string structName = cast(string) structDecl.ident.toString(); | ||
if (isNestedStruct()) | ||
structName = structStack[$ - 1] ~ "." ~ structName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you constructing the qualified name here? if you call "toPrettyChars" on a StructDeclaration it will give you the fully qualified name which is a good unique identifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... on a second thought, it might be possible that toPrettyChars doesn't work correctly here if you are not performing semantic. Please check whether it works or not, because if it does it will save you some pain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only nested structs are counted. Wouldn't toPrettyChars
also print the encapsulating class, if present?
visitedStructs[structName].shouldErrorOnInit = !isDisabled; | ||
} | ||
|
||
override void visit(AST.VarDeclaration varDeclaration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to find smaller names that are congruent with the dmd codebase. For example, vd
is consistently used for variable declarations variables throughout dmd. If that seems not expressive enough, you can use varDecl. Having smaller if conditions in length is eye candy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can shorten it, however for a function this long a longer name is better - I prefer shorter names in local / small scopes. vd
is an awful name though
This check looks for useless initializers on:
This check also ignores variables declared with a DDoc comment (/// comment), typeof expressions and "compiles" trait expression. It also ignores disabled structs or structs having the default ctor disabled. This check is also limited when it comes to structs - it can only detect previously defined structs in the module. I've kept the same behavior when migrating to DMD.