-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[WIP] Teach SourceKit name translation request to translate Swift names to ObjC ones (by using PrintAsObjC). #7449
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
Conversation
@swift-ci smoke test |
@swift-ci smoke test |
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.
Looks pretty good, but I do have a few comments.
@@ -433,6 +433,12 @@ class ObjCSelector { | |||
/// pieces. | |||
ObjCSelector(ASTContext &ctx, unsigned numArgs, ArrayRef<Identifier> pieces); | |||
|
|||
/// Construct an invalid ObjCSelector. | |||
ObjCSelector() : Storage() {}; |
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.
Nitpick: trailing semicolon. :-)
auto Name = getNameForObjC(VD, CustomNamesOnly); | ||
if (!Name.empty()) | ||
return {Ctx.getIdentifier(Name), ObjCSelector()}; | ||
return {PreferredName.getBaseName(), ObjCSelector()}; |
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.
Hang on, what if PreferredName is also null? (Classes and protocols would currently fall into this case.)
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.
We get an empty identifier then. I think it is fine.
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 it supposed to return the current name in that case?
static DeclName | ||
getSwiftDeclName(ASTContext &Ctx, NameTranslatingInfo &Info) { | ||
assert(SwiftLangSupport::getNameKindForUID(Info.NameKind) == NameKind::Swift); | ||
std::vector<Identifier> Args(Info.ArgNames.size(), 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.
Nitpick: Why not SmallVector?
std::transform(Pieces.begin(), Pieces.end(), Pieces.begin(), | ||
[](StringRef P) { return StringRef(P.data(), P.size() + 1); }); | ||
} | ||
Result.ArgNames = llvm::makeArrayRef(Pieces); |
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.
This looks suspicious, even though I know ArgNames isn't an ArrayRef itself. Can you go through a different API just to make it not look like you're storing the ArrayRef?
@@ -593,7 +593,7 @@ static int handleTestInvocation(ArrayRef<const char *> Args, | |||
} else { | |||
BaseName = Text.substr(0, ArgStart); | |||
auto ArgEnd = Text.find_last_of(')'); | |||
if (ArgEnd != StringRef::npos) { | |||
if (ArgEnd == StringRef::npos) { |
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.
Heh, oops.
llvm::raw_svector_ostream OS(Buffer); | ||
OS << getNameForObjC(ED).str(); | ||
SmallString<64> Scratch; | ||
OS << camel_case::toSentencecase(PreferredName.getBaseName().str(), |
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.
Can you abstract this out so that the actual printing code can use this too?
oh, this is already merged. I'll address your comments in another pull request. |
No description provided.