Skip to content

[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

Merged
merged 7 commits into from
Feb 14, 2017

Conversation

nkcsgexi
Copy link
Contributor

No description provided.

@nkcsgexi
Copy link
Contributor Author

@swift-ci smoke test

@nkcsgexi
Copy link
Contributor Author

@swift-ci smoke test

@nkcsgexi nkcsgexi merged commit 055da1f into swiftlang:master Feb 14, 2017
@nkcsgexi nkcsgexi deleted the swift-to-objc branch February 14, 2017 22:25
Copy link
Contributor

@jrose-apple jrose-apple left a 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() {};
Copy link
Contributor

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()};
Copy link
Contributor

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.)

Copy link
Contributor Author

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.

Copy link
Contributor

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());
Copy link
Contributor

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);
Copy link
Contributor

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) {
Copy link
Contributor

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(),
Copy link
Contributor

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?

@nkcsgexi
Copy link
Contributor Author

oh, this is already merged. I'll address your comments in another pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants