Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- TokenKinds.cpp - Token Kinds Support -----------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the TokenKind enum and support functions. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Basic/TokenKinds.h" |
Ted Kremenek | a2bfb91 | 2007-10-24 19:06:02 +0000 | [diff] [blame] | 15 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | #include <cassert> |
| 17 | using namespace clang; |
| 18 | |
| 19 | static const char * const TokNames[] = { |
| 20 | #define TOK(X) #X, |
| 21 | #define KEYWORD(X,Y) #X, |
| 22 | #include "clang/Basic/TokenKinds.def" |
| 23 | 0 |
| 24 | }; |
| 25 | |
| 26 | const char *tok::getTokenName(enum TokenKind Kind) { |
| 27 | assert(Kind < tok::NUM_TOKENS); |
| 28 | return TokNames[Kind]; |
| 29 | } |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 30 | |
Douglas Gregor | b2fb6de | 2009-02-27 17:53:17 +0000 | [diff] [blame] | 31 | const char *tok::getTokenSimpleSpelling(enum TokenKind Kind) { |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 32 | switch (Kind) { |
| 33 | case tok::l_square: return "["; |
| 34 | case tok::r_square: return "]"; |
| 35 | case tok::l_paren: return "("; |
| 36 | case tok::r_paren: return ")"; |
| 37 | case tok::l_brace: return "{"; |
| 38 | case tok::r_brace: return "}"; |
| 39 | case tok::period: return "."; |
| 40 | case tok::ellipsis: return "..."; |
| 41 | case tok::amp: return "&"; |
| 42 | case tok::ampamp: return "&&"; |
| 43 | case tok::ampequal: return "&="; |
| 44 | case tok::star: return "*"; |
| 45 | case tok::starequal: return "*="; |
| 46 | case tok::plus: return "+"; |
| 47 | case tok::plusplus: return "++"; |
| 48 | case tok::plusequal: return "+="; |
| 49 | case tok::minus: return "-"; |
| 50 | case tok::arrow: return "->"; |
| 51 | case tok::minusminus: return "--"; |
| 52 | case tok::minusequal: return "-="; |
| 53 | case tok::tilde: return "~"; |
| 54 | case tok::exclaim: return "!"; |
| 55 | case tok::exclaimequal: return "!="; |
| 56 | case tok::slash: return "/"; |
| 57 | case tok::slashequal: return "/="; |
| 58 | case tok::percent: return "%"; |
| 59 | case tok::percentequal: return "%="; |
| 60 | case tok::less: return "<"; |
| 61 | case tok::lessless: return "<<"; |
| 62 | case tok::lessequal: return "<="; |
| 63 | case tok::lesslessequal: return "<<="; |
| 64 | case tok::greater: return ">"; |
| 65 | case tok::greatergreater: return ">>"; |
| 66 | case tok::greaterequal: return ">="; |
| 67 | case tok::greatergreaterequal: return ">>="; |
| 68 | case tok::caret: return "^"; |
| 69 | case tok::caretequal: return "^="; |
| 70 | case tok::pipe: return "|"; |
| 71 | case tok::pipepipe: return "||"; |
| 72 | case tok::pipeequal: return "|="; |
| 73 | case tok::question: return "?"; |
| 74 | case tok::colon: return ":"; |
| 75 | case tok::semi: return ";"; |
| 76 | case tok::equal: return "="; |
| 77 | case tok::equalequal: return "=="; |
| 78 | case tok::comma: return ","; |
| 79 | case tok::hash: return "#"; |
| 80 | case tok::hashhash: return "##"; |
| 81 | case tok::hashat: return "#@"; |
| 82 | case tok::periodstar: return ".*"; |
| 83 | case tok::arrowstar: return "->*"; |
| 84 | case tok::coloncolon: return "::"; |
| 85 | case tok::at: return "@"; |
| 86 | default: break; |
| 87 | } |
| 88 | |
| 89 | return 0; |
| 90 | } |