deduplicate the 'isSomeFunction' equivalent#6835
deduplicate the 'isSomeFunction' equivalent#6835UplinkCoder wants to merge 1 commit intodlang:masterfrom
Conversation
src/ddmd/traits.d
Outdated
| return new IntegerExp(e.loc, false, Type.tbool); | ||
| } | ||
|
|
||
| TypeFunction firstArgFunctionType() |
There was a problem hiding this comment.
IMO a better abstraction is toTypeFunction(RootObject o) and passing the validated parameter into this function. That would allow it not being a nested function and used elsewhere, too.
Even better, I'd split it into two overloads, one for Type, and one for Dsymbol, as you now have widen the allowed parameters to traits that support types only so far.
There was a problem hiding this comment.
the reason I did not do this is because I'd have to import rootobject
There was a problem hiding this comment.
also let's generalize when/if needed and not on speculation.
There was a problem hiding this comment.
do you agree ?
Mostly. The diff didn't show that there's also support for function symbols in the other traits.
You should remove the handling for FuncDeclaration in traits getLinkage, getFunctionVariadicStyle and getParameterStorageClasses, though. It is duplicated now.
the reason I did not do this is because I'd have to import rootobject
That's not really a good excuse. You can also use typeof(args[0]) to avoid an import... ;-)
|
travis fails because of connection error |
|
@UplinkCoder: restarted and created another card for it https://trello.com/c/aM5r3Bio/320-use-more-download-fallbacks-in-the-installer-script |
722b1f9 to
58d5861
Compare
|
@rainers do you like it better now ? |
58d5861 to
ffe5e23
Compare
|
@WalterBright any objections ? |
| return new IntegerExp(e.loc, false, Type.tbool); | ||
| } | ||
|
|
||
| static TypeFunction traitsFuncArg(RootObject o, FuncDeclaration* fdp = null) |
There was a problem hiding this comment.
No documentation saying what function does.
|
LGTM provided the function is documented |
Not a bad idea. |
41897b0 to
3b8ef98
Compare
| In case of a function declaration being passed verbatim | ||
| it will set the second optional argument to the FuncDeclarartion | ||
| given it was provided. | ||
| */ |
There was a problem hiding this comment.
Please use Ddoc style documentation. It this case it means having a Params: section and a Returns: section. This is the standard for new functions.
There was a problem hiding this comment.
@UplinkCoder don't forget that we already publish the documentation of ddmd on dlang.org:
- http://dlang.org/phobos-prerelease/ddmd_mars.html (Ddoc)
- http://dlang.org/library-prerelease/ddmd/mars.html (Ddox)
and we intend to publish it on the main page very soon (e.g. once Fix issue 17392 - Add Dub file for the lexer and parser #6771 is merged).
This is also why it can be very helpful for both the contributor and the reviewers to preview the style changes at Vladimir's excellent DAutoTest, e.g.
(in this case it's a function within a function and thus not publicly accessible)
src/ddmd/traits.d
Outdated
|
|
||
| /** | ||
| if traitsFuncArg is passed either a delegate. a function | ||
| or a function pointer or a variable of types. |
There was a problem hiding this comment.
omit trailing period in middle of sentence
src/ddmd/traits.d
Outdated
| it will return the functionType. | ||
| else it will return null | ||
|
|
||
| In case of a function declaration being passed verbatim |
There was a problem hiding this comment.
passed verbatim has no meaning in regards to code.
src/ddmd/traits.d
Outdated
| Returns: a function-type if | ||
| o is a declarion of type delegate, function, | ||
| or function pointer | ||
| or a variable of those types. |
There was a problem hiding this comment.
When using periods, please do not put them in the middle of sentences. Replace it with a ,
47a68fb to
61c95c9
Compare
|
@WalterBright addressed. |
src/ddmd/traits.d
Outdated
| } | ||
|
|
||
| /** | ||
| Params: o: the AST-node to check. |
There was a problem hiding this comment.
Please read the Ddoc documentation I provided a link for. Note the o: in the above line. This is not how it's done and Ddoc will not work with it. It's o=.
|
@UplinkCoder Are you going to take this across the finish line? |
src/ddmd/traits.d
Outdated
|
|
||
| /** | ||
| Params: o: the AST-node to check. | ||
| Params: fdp: optionally a pointer to a function declararion, |
There was a problem hiding this comment.
declararion --> declaration
| else | ||
| it will return null. | ||
| */ | ||
| static TypeFunction traitsFuncArg(RootObject o, FuncDeclaration* fdp = null) |
There was a problem hiding this comment.
I recommend a different name. Perhaps getTypeFunction.
| it will return the functionType | ||
| else | ||
| it will return null. | ||
| */ |
There was a problem hiding this comment.
I offer you this documentation header:
/**
Gets the `TypeFunction` for `o`
Params:
o = the AST node to get the `TypeFunction` for
fdp = optional pointer to a function declararion, to be set
if `o` is a function declarartion
Returns:
a `TypeFunction` if `o` is a declaration for a delegate, function,
or avariable of those types. Otherwise, `null`
*/|
@UplinkCoder ping? |
61c95c9 to
497cd06
Compare
|
Thanks for your pull request, @UplinkCoder! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
497cd06 to
00977b0
Compare
| or a variable of the former. Otherwise, `null`. | ||
| */ | ||
|
|
||
| static TypeFunction traitsFuncArg(RootObject o, FuncDeclaration* fdp = null) |
There was a problem hiding this comment.
All other DDoc headers in DMD seem to follow this convention:
/*************************************************************
* Whatever
* Whatever
*/Please remove the extra space between the DDoc header and the function declaration.
I cannot, in good conscience, approve a function name like traitsFuncArg. Please use a more descriptive name like getFuncType or something along those lines (Yes, I know my own names have been poor).
There was a problem hiding this comment.
Please remove the extra space between the DDoc header and the function declaration.
Hmm the above is the Phobos style:
Compare with e.g. https://github.com/dlang/phobos/blob/master/std/algorithm/comparison.d
If you really want to stick with this style at DMD, then this should be documented in a DMD-specific style guide?
There was a problem hiding this comment.
Hmm the above is the Phobos style.
I see.
If you really want to stick with this style at DMD, then this should be documented in a DMD-specific style guide.
Agreed.
Aside from the name then, LGTM.
There was a problem hiding this comment.
Also, consider making this a non-member function instead of static, and preferably private. Refer to @WalterBright's comment
There was a problem hiding this comment.
Phobos has a mixed style when it comes to comments [1] [2] [3] [4]. This is even within the same module.
[1] https://github.com/dlang/phobos/blob/master/std/string.d#L2194-L2205
[2] https://github.com/dlang/phobos/blob/master/std/string.d#L2254-L2267
[3] https://github.com/dlang/phobos/blob/master/std/string.d#L2332-L2358
[4] https://github.com/dlang/phobos/blob/master/std/string.d#L2664-L2689
There was a problem hiding this comment.
Let's use https://github.com/dlang/phobos/blob/master/std/string.d#L2254-L2267 for new code, thanks.
|
This PR needs to have the reviewers' concerns addressed and rebased. This PR is nice, and normally I would revive such a PR if the author was no longer active. I would also revive it if it were an important bug fix or something of higher priority. This PR, however, is just a refactoring, so I'm going to put it in the Phantom Zone and close it for now. |
|
Resubmitted at #7749 |
Since the code is now used multiple times in
__traitslet's dedup it.