OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / shared / cplusplus / Token.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
33 //
34 // Permission is hereby granted, free of charge, to any person obtaining a copy
35 // of this software and associated documentation files (the "Software"), to deal
36 // in the Software without restriction, including without limitation the rights
37 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38 // copies of the Software, and to permit persons to whom the Software is
39 // furnished to do so, subject to the following conditions:
40 //
41 // The above copyright notice and this permission notice shall be included in
42 // all copies or substantial portions of the Software.
43 //
44 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
50 // THE SOFTWARE.
51
52 #include "Token.h"
53 #include "Literals.h"
54
55 using namespace CPlusPlus;
56
57 static const char *token_names[] = {
58     (""), ("<error>"),
59
60     ("<C++ comment>"), ("<C++ doxy comment>"),
61     ("<comment>"), ("<doxy comment>"),
62
63     ("<identifier>"), ("<numeric literal>"), ("<char literal>"),
64     ("<wide char literal>"), ("<string literal>"), ("<wide char literal>"),
65     ("<@string literal>"), ("<angle string literal>"),
66
67     ("&"), ("&&"), ("&="), ("->"), ("->*"), ("^"), ("^="), (":"), ("::"),
68     (","), ("/"), ("/="), ("."), ("..."), (".*"), ("="), ("=="), ("!"),
69     ("!="), (">"), (">="), (">>"), (">>="), ("{"), ("["), ("<"), ("<="),
70     ("<<"), ("<<="), ("("), ("-"), ("-="), ("--"), ("%"), ("%="), ("|"),
71     ("|="), ("||"), ("+"), ("+="), ("++"), ("#"), ("##"), ("?"), ("}"),
72     ("]"), (")"), (";"), ("*"), ("*="), ("~"), ("~="),
73
74     ("asm"), ("auto"), ("bool"), ("break"), ("case"), ("catch"), ("char"),
75     ("class"), ("const"), ("const_cast"), ("continue"), ("default"),
76     ("delete"), ("do"), ("double"), ("dynamic_cast"), ("else"), ("enum"),
77     ("explicit"), ("export"), ("extern"), ("false"), ("float"), ("for"),
78     ("friend"), ("goto"), ("if"), ("inline"), ("int"), ("long"),
79     ("mutable"), ("namespace"), ("new"), ("operator"), ("private"),
80     ("protected"), ("public"), ("register"), ("reinterpret_cast"),
81     ("return"), ("short"), ("signed"), ("sizeof"), ("static"),
82     ("static_cast"), ("struct"), ("switch"), ("template"), ("this"),
83     ("throw"), ("true"), ("try"), ("typedef"), ("typeid"), ("typename"),
84     ("union"), ("unsigned"), ("using"), ("virtual"), ("void"),
85     ("volatile"), ("wchar_t"), ("while"),
86
87     // gnu
88     ("__attribute__"), ("__typeof__"),
89
90     // objc @keywords
91     ("@catch"), ("@class"), ("@compatibility_alias"), ("@defs"), ("@dynamic"),
92     ("@encode"), ("@end"), ("@finally"), ("@implementation"), ("@interface"),
93     ("@not_keyword"), ("@optional"), ("@package"), ("@private"), ("@property"),
94     ("@protected"), ("@protocol"), ("@public"), ("@required"), ("@selector"),
95     ("@synchronized"), ("@synthesize"), ("@throw"), ("@try"),
96
97     // Qt keywords
98     ("SIGNAL"), ("SLOT"), ("Q_SIGNAL"), ("Q_SLOT"), ("signals"), ("slots"),
99     ("Q_FOREACH"), ("Q_D"), ("Q_Q"),
100     ("Q_INVOKABLE"), ("Q_PROPERTY"), ("Q_INTERFACES"), ("Q_ENUMS"), ("Q_FLAGS"),
101     ("Q_PRIVATE_SLOT"), ("Q_DECLARE_INTERFACE"), ("Q_OBJECT"), ("Q_GADGET"),
102
103 };
104
105 Token::Token() :
106     flags(0), offset(0), ptr(0)
107 {
108 }
109
110 Token::~Token()
111 {
112 }
113
114 void Token::reset()
115 {
116     flags = 0;
117     offset = 0;
118     ptr = 0;
119 }
120
121 const char *Token::name(int kind)
122 { return token_names[kind]; }
123
124 const char *Token::spell() const
125 {
126     switch (f.kind) {
127     case T_IDENTIFIER:
128         return identifier->chars();
129
130     case T_NUMERIC_LITERAL:
131     case T_CHAR_LITERAL:
132     case T_STRING_LITERAL:
133     case T_AT_STRING_LITERAL:
134     case T_ANGLE_STRING_LITERAL:
135     case T_WIDE_CHAR_LITERAL:
136     case T_WIDE_STRING_LITERAL:
137         return literal->chars();
138
139     default:
140         return token_names[f.kind];
141     } // switch
142 }
143
144