blob: a71cd72517dee600909d9c7ef493dfc62ff986f5 [file] [log] [blame]
Chris Lattner22eb9722006-06-18 05:43:12 +00001//===--- TokenKinds.cpp - Token Kinds Support -----------------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner22eb9722006-06-18 05:43:12 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the TokenKind enum and support functions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/Basic/TokenKinds.h"
Alp Toker637b3472014-01-06 11:30:15 +000014#include "llvm/Support/ErrorHandling.h"
Chris Lattner23b7eb62007-06-15 23:05:46 +000015using namespace clang;
Chris Lattner22eb9722006-06-18 05:43:12 +000016
17static const char * const TokNames[] = {
18#define TOK(X) #X,
Chris Lattner69c7ee22006-12-04 07:45:05 +000019#define KEYWORD(X,Y) #X,
Chris Lattner22eb9722006-06-18 05:43:12 +000020#include "clang/Basic/TokenKinds.def"
Craig Topperf1186c52014-05-08 06:41:40 +000021 nullptr
Chris Lattner22eb9722006-06-18 05:43:12 +000022};
23
Alp Tokerb3f95012014-01-06 15:52:13 +000024const char *tok::getTokenName(TokenKind Kind) {
Alp Toker637b3472014-01-06 11:30:15 +000025 if (Kind < tok::NUM_TOKENS)
26 return TokNames[Kind];
27 llvm_unreachable("unknown TokenKind");
Craig Topperf1186c52014-05-08 06:41:40 +000028 return nullptr;
Chris Lattner22eb9722006-06-18 05:43:12 +000029}
Douglas Gregor87f95b02009-02-26 21:00:50 +000030
Alp Tokerb3f95012014-01-06 15:52:13 +000031const char *tok::getPunctuatorSpelling(TokenKind Kind) {
Douglas Gregor87f95b02009-02-26 21:00:50 +000032 switch (Kind) {
Kovarththanan Rajaratnam7632da42009-11-28 16:09:28 +000033#define PUNCTUATOR(X,Y) case X: return Y;
34#include "clang/Basic/TokenKinds.def"
Douglas Gregor87f95b02009-02-26 21:00:50 +000035 default: break;
36 }
Craig Topperf1186c52014-05-08 06:41:40 +000037 return nullptr;
Alp Tokera231ad22014-01-06 12:54:18 +000038}
Douglas Gregor87f95b02009-02-26 21:00:50 +000039
Alp Tokerb3f95012014-01-06 15:52:13 +000040const char *tok::getKeywordSpelling(TokenKind Kind) {
Alp Tokera231ad22014-01-06 12:54:18 +000041 switch (Kind) {
42#define KEYWORD(X,Y) case kw_ ## X: return #X;
43#include "clang/Basic/TokenKinds.def"
44 default: break;
45 }
Craig Topperf1186c52014-05-08 06:41:40 +000046 return nullptr;
Douglas Gregor87f95b02009-02-26 21:00:50 +000047}