Skip to content

Escape all keywords when printing DeclBaseNames #11309

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 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/SIL/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/FileSystem.h"
Expand Down Expand Up @@ -239,11 +240,21 @@ static void printValueDecl(ValueDecl *Decl, raw_ostream &OS) {

if (Decl->isOperator()) {
OS << '"' << Decl->getBaseName() << '"';
} else if (Decl->getBaseName() == "subscript" ||
Decl->getBaseName() == "deinit") {
OS << '`' << Decl->getBaseName() << '`';
} else {
OS << Decl->getBaseName();
bool shouldEscape = !Decl->getBaseName().isSpecial() &&
llvm::StringSwitch<bool>(Decl->getBaseName().userFacingName())
// FIXME: Represent "init" by a special name and remove this case
.Case("init", false)
#define KEYWORD(kw) \
.Case(#kw, true)
#include "swift/Syntax/TokenKinds.def"
.Default(false);

if (shouldEscape) {
OS << '`' << Decl->getBaseName().userFacingName() << '`';
} else {
OS << Decl->getBaseName().userFacingName();
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/SILGen/decls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,9 @@ func unboundMethodReferences() {
_ = type(of: Derived.method1)
_ = type(of: Derived.method2)
}

// CHECK-LABEL: sil_vtable EscapeKeywordsInDottedPaths
class EscapeKeywordsInDottedPaths {
// CHECK: #EscapeKeywordsInDottedPaths.`switch`!getter.1
var `switch`: String = ""
}