summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2014-01-06 12:54:18 +0000
committerAlp Toker <alp@nuanti.com>2014-01-06 12:54:18 +0000
commita231ad2216d2b6362d6034d4c5f84dbdf6a6ef9a (patch)
treee36146a8d7de5c2fa188a61f5951a71541af6116 /clang/lib/Basic
parent6d35eab5a6f575f557c266892f6dedf951851828 (diff)
downloadbcm5719-llvm-a231ad2216d2b6362d6034d4c5f84dbdf6a6ef9a.tar.gz
bcm5719-llvm-a231ad2216d2b6362d6034d4c5f84dbdf6a6ef9a.zip
Support diagnostic formatting of keyword tokens
Implemented with a new getKeywordSpelling() accessor. Unlike getTokenName() the result of this function is stable and may be used in diagnostic output. Uses of this feature are split out into the subsequent commit. llvm-svn: 198604
Diffstat (limited to 'clang/lib/Basic')
-rw-r--r--clang/lib/Basic/Diagnostic.cpp20
-rw-r--r--clang/lib/Basic/TokenKinds.cpp8
2 files changed, 21 insertions, 7 deletions
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 9d7643b3622..a5242c94521 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -639,12 +639,15 @@ static void HandlePluralModifier(const Diagnostic &DInfo, unsigned ValNo,
}
}
-/// \brief Returns the friendly name for a token kind that will / appear
-// without quotes in diagnostic messages.
-static const char *getTokenNameForDiagnostic(tok::TokenKind Kind) {
+/// \brief Returns the friendly description for a token kind that will appear
+/// without quotes in diagnostic messages. These strings may be translatable in
+/// future.
+static const char *getTokenDescForDiagnostic(tok::TokenKind Kind) {
switch (Kind) {
case tok::identifier:
return "identifier";
+ case tok::annot_template_id:
+ return "template name";
default:
return 0;
}
@@ -828,12 +831,15 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
assert(ModifierLen == 0 && "No modifiers for token kinds yet");
llvm::raw_svector_ostream Out(OutStr);
- if (const char *S = getTokenNameForDiagnostic(Kind))
+ if (const char *S = tok::getPunctuatorSpelling(Kind))
+ // Quoted token spelling for punctuators.
+ Out << '\'' << S << '\'';
+ else if (const char *S = tok::getKeywordSpelling(Kind))
+ // Unquoted token spelling for keywords.
+ Out << S;
+ else if (const char *S = getTokenDescForDiagnostic(Kind))
// Unquoted translatable token name.
Out << S;
- else if (const char *S = tok::getPunctuatorSpelling(Kind))
- // Quoted token spelling, currently only covers punctuators.
- Out << '\'' << S << '\'';
else if (const char *S = tok::getTokenName(Kind))
// Debug name, shouldn't appear in user-facing diagnostics.
Out << '<' << S << '>';
diff --git a/clang/lib/Basic/TokenKinds.cpp b/clang/lib/Basic/TokenKinds.cpp
index 2a9c9bfa2f9..50fe0a68877 100644
--- a/clang/lib/Basic/TokenKinds.cpp
+++ b/clang/lib/Basic/TokenKinds.cpp
@@ -35,6 +35,14 @@ const char *tok::getPunctuatorSpelling(enum TokenKind Kind) {
#include "clang/Basic/TokenKinds.def"
default: break;
}
+ return 0;
+}
+const char *tok::getKeywordSpelling(enum TokenKind Kind) {
+ switch (Kind) {
+#define KEYWORD(X,Y) case kw_ ## X: return #X;
+#include "clang/Basic/TokenKinds.def"
+ default: break;
+ }
return 0;
}
OpenPOWER on IntegriCloud