From db02b1b3d2fb9b2ebd9014f0519d6f623c8ce73c Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Sat, 5 Aug 2017 14:24:41 +0200 Subject: [PATCH] Escape all keywords when printing SIL dotted paths --- lib/SIL/SILPrinter.cpp | 19 +++++++++++++++---- test/SILGen/decls.swift | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/SIL/SILPrinter.cpp b/lib/SIL/SILPrinter.cpp index 284ab607bdf0f..00ed0bc83ffd8 100644 --- a/lib/SIL/SILPrinter.cpp +++ b/lib/SIL/SILPrinter.cpp @@ -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" @@ -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(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(); + } } } diff --git a/test/SILGen/decls.swift b/test/SILGen/decls.swift index 09c408d9f6a35..36479ef14cb7d 100644 --- a/test/SILGen/decls.swift +++ b/test/SILGen/decls.swift @@ -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 = "" +}