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" |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame^] | 15 | #include "llvm/Support/ErrorHandling.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | using namespace clang; |
| 17 | |
| 18 | static const char * const TokNames[] = { |
| 19 | #define TOK(X) #X, |
| 20 | #define KEYWORD(X,Y) #X, |
| 21 | #include "clang/Basic/TokenKinds.def" |
| 22 | 0 |
| 23 | }; |
| 24 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame^] | 25 | const char *tok::getTokenName(TokenKind Kind) { |
| 26 | if (Kind < tok::NUM_TOKENS) |
| 27 | return TokNames[Kind]; |
| 28 | llvm_unreachable("unknown TokenKind"); |
| 29 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 30 | } |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 31 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame^] | 32 | const char *tok::getPunctuatorSpelling(TokenKind Kind) { |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 33 | switch (Kind) { |
Kovarththanan Rajaratnam | 59c55e7 | 2009-11-28 16:09:28 +0000 | [diff] [blame] | 34 | #define PUNCTUATOR(X,Y) case X: return Y; |
| 35 | #include "clang/Basic/TokenKinds.def" |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 36 | default: break; |
| 37 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame^] | 38 | return 0; |
| 39 | } |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 40 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame^] | 41 | const char *tok::getKeywordSpelling(TokenKind Kind) { |
| 42 | switch (Kind) { |
| 43 | #define KEYWORD(X,Y) case kw_ ## X: return #X; |
| 44 | #include "clang/Basic/TokenKinds.def" |
| 45 | default: break; |
| 46 | } |
Douglas Gregor | 4b2d3f7 | 2009-02-26 21:00:50 +0000 | [diff] [blame] | 47 | return 0; |
| 48 | } |