OSDN Git Service

af7cb4fd549ec678d4d7c02423a8ee4c2b9632e2
[qt-creator-jp/qt-creator-jp.git] / src / shared / cplusplus / Literals.h
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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining a copy
36 // of this software and associated documentation files (the "Software"), to deal
37 // in the Software without restriction, including without limitation the rights
38 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39 // copies of the Software, and to permit persons to whom the Software is
40 // furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
51 // THE SOFTWARE.
52
53 #ifndef CPLUSPLUS_LITERALS_H
54 #define CPLUSPLUS_LITERALS_H
55
56 #include "CPlusPlusForwardDeclarations.h"
57 #include "Token.h"
58 #include "Name.h"
59
60 namespace CPlusPlus {
61
62 class CPLUSPLUS_EXPORT Literal
63 {
64     Literal(const Literal &other);
65     void operator =(const Literal &other);
66
67 public:
68     typedef const char *iterator;
69     typedef iterator const_iterator;
70
71 public:
72     Literal(const char *chars, unsigned size);
73     virtual ~Literal();
74
75     iterator begin() const;
76     iterator end() const;
77
78     char at(unsigned index) const;
79     const char *chars() const;
80     unsigned size() const;
81
82     unsigned hashCode() const;
83     static unsigned hashCode(const char *chars, unsigned size);
84
85     bool equalTo(const Literal *other) const;
86
87     Literal *_next; // ## private
88
89 private:
90     char *_chars;
91     unsigned _size;
92     unsigned _hashCode;
93
94 public:
95     unsigned _index;     // ### private
96 };
97
98 class CPLUSPLUS_EXPORT StringLiteral: public Literal
99 {
100 public:
101     StringLiteral(const char *chars, unsigned size);
102     virtual ~StringLiteral();
103 };
104
105 class CPLUSPLUS_EXPORT NumericLiteral: public Literal
106 {
107 public:
108     NumericLiteral(const char *chars, unsigned size);
109     virtual ~NumericLiteral();
110
111     bool isInt() const;
112     bool isFloat() const;
113     bool isDouble() const;
114     bool isLongDouble() const;
115     bool isLong() const;
116     bool isLongLong() const;
117
118     bool isUnsigned() const;
119     bool isHex() const;
120
121 private:
122     struct Flags {
123         unsigned _type      : 8;
124         unsigned _isHex     : 1;
125         unsigned _isUnsigned: 1;
126     };
127     union {
128         unsigned _flags;
129         Flags f;
130     };
131 };
132
133 class CPLUSPLUS_EXPORT Identifier: public Literal, public Name
134 {
135 public:
136     Identifier(const char *chars, unsigned size);
137     virtual ~Identifier();
138
139     virtual const Identifier *identifier() const { return this; }
140
141     virtual bool isEqualTo(const Name *other) const;
142
143     virtual const Identifier *asNameId() const
144     { return this; }
145
146 protected:
147     virtual void accept0(NameVisitor *visitor) const;
148 };
149
150 } // namespace CPlusPlus
151
152
153 #endif // CPLUSPLUS_LITERALS_H