clang API Documentation

TokenKinds.cpp
Go to the documentation of this file.
00001 //===--- TokenKinds.cpp - Token Kinds Support -----------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file implements the TokenKind enum and support functions.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "clang/Basic/TokenKinds.h"
00015 #include "llvm/Support/ErrorHandling.h"
00016 using namespace clang;
00017 
00018 static const char * const TokNames[] = {
00019 #define TOK(X) #X,
00020 #define KEYWORD(X,Y) #X,
00021 #include "clang/Basic/TokenKinds.def"
00022   nullptr
00023 };
00024 
00025 const char *tok::getTokenName(TokenKind Kind) {
00026   if (Kind < tok::NUM_TOKENS)
00027     return TokNames[Kind];
00028   llvm_unreachable("unknown TokenKind");
00029   return nullptr;
00030 }
00031 
00032 const char *tok::getPunctuatorSpelling(TokenKind Kind) {
00033   switch (Kind) {
00034 #define PUNCTUATOR(X,Y) case X: return Y;
00035 #include "clang/Basic/TokenKinds.def"
00036   default: break;
00037   }
00038   return nullptr;
00039 }
00040 
00041 const char *tok::getKeywordSpelling(TokenKind Kind) {
00042   switch (Kind) {
00043 #define KEYWORD(X,Y) case kw_ ## X: return #X;
00044 #include "clang/Basic/TokenKinds.def"
00045     default: break;
00046   }
00047   return nullptr;
00048 }