This patch adds a PUNCTUATOR macro (specialization of TOK) in TokenKinds.def and makes use of it in tok::getTokenSimpleSpelling.

llvm-svn: 90042
This commit is contained in:
Kovarththanan Rajaratnam 2009-11-28 16:09:28 +00:00
parent 32140312ca
commit 7632da4b8a
2 changed files with 59 additions and 107 deletions

View File

@ -17,6 +17,9 @@
#ifndef TOK #ifndef TOK
#define TOK(X) #define TOK(X)
#endif #endif
#ifndef PUNCTUATOR
#define PUNCTUATOR(X,Y) TOK(X)
#endif
#ifndef KEYWORD #ifndef KEYWORD
#define KEYWORD(X,Y) TOK(kw_ ## X) #define KEYWORD(X,Y) TOK(kw_ ## X)
#endif #endif
@ -113,64 +116,63 @@ TOK(wide_string_literal) // L"foo"
TOK(angle_string_literal)// <foo> TOK(angle_string_literal)// <foo>
// C99 6.4.6: Punctuators. // C99 6.4.6: Punctuators.
TOK(l_square) // [ PUNCTUATOR(l_square, "[")
TOK(r_square) // ] PUNCTUATOR(r_square, "]")
TOK(l_paren) // ( PUNCTUATOR(l_paren, "(")
TOK(r_paren) // ) PUNCTUATOR(r_paren, ")")
TOK(l_brace) // { PUNCTUATOR(l_brace, "{")
TOK(r_brace) // } PUNCTUATOR(r_brace, "}")
TOK(period) // . PUNCTUATOR(period, ".")
TOK(ellipsis) // ... PUNCTUATOR(ellipsis, "...")
TOK(amp) // & PUNCTUATOR(amp, "&")
TOK(ampamp) // && PUNCTUATOR(ampamp, "&&")
TOK(ampequal) // &= PUNCTUATOR(ampequal, "&=")
TOK(star) // * PUNCTUATOR(star, "*")
TOK(starequal) // *= PUNCTUATOR(starequal, "*=")
TOK(plus) // + PUNCTUATOR(plus, "+")
TOK(plusplus) // ++ PUNCTUATOR(plusplus, "++")
TOK(plusequal) // += PUNCTUATOR(plusequal, "+=")
TOK(minus) // - PUNCTUATOR(minus, "-")
TOK(arrow) // -> PUNCTUATOR(arrow, "->")
TOK(minusminus) // -- PUNCTUATOR(minusminus, "--")
TOK(minusequal) // -= PUNCTUATOR(minusequal, "-=")
TOK(tilde) // ~ PUNCTUATOR(tilde, "~")
TOK(exclaim) // ! PUNCTUATOR(exclaim, "!")
TOK(exclaimequal) // != PUNCTUATOR(exclaimequal, "!=")
TOK(slash) // / PUNCTUATOR(slash, "/")
TOK(slashequal) // /= PUNCTUATOR(slashequal, "/=")
TOK(percent) // % PUNCTUATOR(percent, "%")
TOK(percentequal) // %= PUNCTUATOR(percentequal, "%=")
TOK(less) // < PUNCTUATOR(less, "<")
TOK(lessless) // << PUNCTUATOR(lessless, "<<")
TOK(lessequal) // <= PUNCTUATOR(lessequal, "<=")
TOK(lesslessequal) // <<= PUNCTUATOR(lesslessequal, "<<=")
TOK(greater) // > PUNCTUATOR(greater, ">")
TOK(greatergreater) // >> PUNCTUATOR(greatergreater, ">>")
TOK(greaterequal) // >= PUNCTUATOR(greaterequal, ">=")
TOK(greatergreaterequal) // >>= PUNCTUATOR(greatergreaterequal, ">>=")
TOK(caret) // ^ PUNCTUATOR(caret, "^")
TOK(caretequal) // ^= PUNCTUATOR(caretequal, "^=")
TOK(pipe) // | PUNCTUATOR(pipe, "|")
TOK(pipepipe) // || PUNCTUATOR(pipepipe, "||")
TOK(pipeequal) // |= PUNCTUATOR(pipeequal, "|=")
TOK(question) // ? PUNCTUATOR(question, "?")
TOK(colon) // : PUNCTUATOR(colon, ":")
TOK(semi) // ; PUNCTUATOR(semi, ";")
TOK(equal) // = PUNCTUATOR(equal, "=")
TOK(equalequal) // == PUNCTUATOR(equalequal, "==")
TOK(comma) // , PUNCTUATOR(comma, ",")
TOK(hash) // # PUNCTUATOR(hash, "#")
TOK(hashhash) // ## PUNCTUATOR(hashhash, "##")
TOK(hashat) // #@ PUNCTUATOR(hashat, "#@")
// C++ Support // C++ Support
TOK(periodstar) // .* PUNCTUATOR(periodstar, ".*")
TOK(arrowstar) // ->* PUNCTUATOR(arrowstar, "->*")
TOK(coloncolon) // :: PUNCTUATOR(coloncolon, "::")
// Objective C support. // Objective C support.
TOK(at) // @ PUNCTUATOR(at, "@")
// C99 6.4.1: Keywords. These turn into kw_* tokens. // C99 6.4.1: Keywords. These turn into kw_* tokens.
// Flags allowed: // Flags allowed:
@ -415,4 +417,5 @@ ANNOTATION(template_id) // annotation for a C++ template-id that names a
#undef PPKEYWORD #undef PPKEYWORD
#undef ALIAS #undef ALIAS
#undef KEYWORD #undef KEYWORD
#undef PUNCTUATOR
#undef TOK #undef TOK

View File

@ -30,59 +30,8 @@ const char *tok::getTokenName(enum TokenKind Kind) {
const char *tok::getTokenSimpleSpelling(enum TokenKind Kind) { const char *tok::getTokenSimpleSpelling(enum TokenKind Kind) {
switch (Kind) { switch (Kind) {
case tok::l_square: return "["; #define PUNCTUATOR(X,Y) case X: return Y;
case tok::r_square: return "]"; #include "clang/Basic/TokenKinds.def"
case tok::l_paren: return "(";
case tok::r_paren: return ")";
case tok::l_brace: return "{";
case tok::r_brace: return "}";
case tok::period: return ".";
case tok::ellipsis: return "...";
case tok::amp: return "&";
case tok::ampamp: return "&&";
case tok::ampequal: return "&=";
case tok::star: return "*";
case tok::starequal: return "*=";
case tok::plus: return "+";
case tok::plusplus: return "++";
case tok::plusequal: return "+=";
case tok::minus: return "-";
case tok::arrow: return "->";
case tok::minusminus: return "--";
case tok::minusequal: return "-=";
case tok::tilde: return "~";
case tok::exclaim: return "!";
case tok::exclaimequal: return "!=";
case tok::slash: return "/";
case tok::slashequal: return "/=";
case tok::percent: return "%";
case tok::percentequal: return "%=";
case tok::less: return "<";
case tok::lessless: return "<<";
case tok::lessequal: return "<=";
case tok::lesslessequal: return "<<=";
case tok::greater: return ">";
case tok::greatergreater: return ">>";
case tok::greaterequal: return ">=";
case tok::greatergreaterequal: return ">>=";
case tok::caret: return "^";
case tok::caretequal: return "^=";
case tok::pipe: return "|";
case tok::pipepipe: return "||";
case tok::pipeequal: return "|=";
case tok::question: return "?";
case tok::colon: return ":";
case tok::semi: return ";";
case tok::equal: return "=";
case tok::equalequal: return "==";
case tok::comma: return ",";
case tok::hash: return "#";
case tok::hashhash: return "##";
case tok::hashat: return "#@";
case tok::periodstar: return ".*";
case tok::arrowstar: return "->*";
case tok::coloncolon: return "::";
case tok::at: return "@";
default: break; default: break;
} }