blob: 92fc2a221d75942e6a8d94e2f7f2b3466c37d811 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- TokenKinds.cpp - Token Kinds Support -----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the TokenKind enum and support functions.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Basic/TokenKinds.h"
Stephen Hines651f13c2014-04-23 16:59:28 -070015#include "llvm/Support/ErrorHandling.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016using namespace clang;
17
18static 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 Hines651f13c2014-04-23 16:59:28 -070025const char *tok::getTokenName(TokenKind Kind) {
26 if (Kind < tok::NUM_TOKENS)
27 return TokNames[Kind];
28 llvm_unreachable("unknown TokenKind");
29 return 0;
Reid Spencer5f016e22007-07-11 17:01:13 +000030}
Douglas Gregor4b2d3f72009-02-26 21:00:50 +000031
Stephen Hines651f13c2014-04-23 16:59:28 -070032const char *tok::getPunctuatorSpelling(TokenKind Kind) {
Douglas Gregor4b2d3f72009-02-26 21:00:50 +000033 switch (Kind) {
Kovarththanan Rajaratnam59c55e72009-11-28 16:09:28 +000034#define PUNCTUATOR(X,Y) case X: return Y;
35#include "clang/Basic/TokenKinds.def"
Douglas Gregor4b2d3f72009-02-26 21:00:50 +000036 default: break;
37 }
Stephen Hines651f13c2014-04-23 16:59:28 -070038 return 0;
39}
Douglas Gregor4b2d3f72009-02-26 21:00:50 +000040
Stephen Hines651f13c2014-04-23 16:59:28 -070041const 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 Gregor4b2d3f72009-02-26 21:00:50 +000047 return 0;
48}