blob: 4afeaf01b77672f76c99b0e9bde8a4ef56ff2874 [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"
Ted Kremeneka2bfb912007-10-24 19:06:02 +000015
Reid Spencer5f016e22007-07-11 17:01:13 +000016#include <cassert>
17using namespace clang;
18
19static 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
26const char *tok::getTokenName(enum TokenKind Kind) {
27 assert(Kind < tok::NUM_TOKENS);
28 return TokNames[Kind];
29}
Douglas Gregor4b2d3f72009-02-26 21:00:50 +000030
Douglas Gregorb2fb6de2009-02-27 17:53:17 +000031const char *tok::getTokenSimpleSpelling(enum TokenKind Kind) {
Douglas Gregor4b2d3f72009-02-26 21:00:50 +000032 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}