OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / libs / qmljs / parser / qmljsengine_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
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 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QMLJSENGINE_P_H
43 #define QMLJSENGINE_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include "qmljsglobal_p.h"
57 #include "qmljsastfwd_p.h"
58
59 #include <QString>
60 #include <QSet>
61
62 QT_QML_BEGIN_NAMESPACE
63
64 namespace QmlJS {
65 class QML_PARSER_EXPORT NameId
66 {
67     QString _text;
68
69 public:
70     NameId(const QChar *u, int s)
71         : _text(u, s)
72     { }
73
74     const QString asString() const
75     { return _text; }
76
77     bool operator == (const NameId &other) const
78     { return _text == other._text; }
79
80     bool operator != (const NameId &other) const
81     { return _text != other._text; }
82
83     bool operator < (const NameId &other) const
84     { return _text < other._text; }
85 };
86
87 uint qHash(const QmlJS::NameId &id);
88
89 } // end of namespace QmlJS
90
91 #if defined(Q_CC_MSVC) && _MSC_VER <= 1300
92 //this ensures that code outside QmlJS can use the hash function
93 //it also a workaround for some compilers
94 inline uint qHash(const QmlJS::NameId &nameId) { return QmlJS::qHash(nameId); }
95 #endif
96
97 namespace QmlJS {
98
99 class Lexer;
100 class NodePool;
101
102 namespace Ecma {
103
104 class QML_PARSER_EXPORT RegExp
105 {
106 public:
107     enum RegExpFlag {
108         Global     = 0x01,
109         IgnoreCase = 0x02,
110         Multiline  = 0x04
111     };
112
113 public:
114     static int flagFromChar(const QChar &);
115     static QString flagsToString(int flags);
116 };
117
118 } // end of namespace Ecma
119
120 class QML_PARSER_EXPORT DiagnosticMessage
121 {
122 public:
123     enum Kind { Warning, Error };
124
125     DiagnosticMessage()
126         : kind(Error) {}
127
128     DiagnosticMessage(Kind kind, const AST::SourceLocation &loc, const QString &message)
129         : kind(kind), loc(loc), message(message) {}
130
131     bool isWarning() const
132     { return kind == Warning; }
133
134     bool isError() const
135     { return kind == Error; }
136
137     Kind kind;
138     AST::SourceLocation loc;
139     QString message;
140 };
141
142 class QML_PARSER_EXPORT Engine
143 {
144     Lexer *_lexer;
145     NodePool *_nodePool;
146     QSet<NameId> _literals;
147     QList<QmlJS::AST::SourceLocation> _comments;
148
149 public:
150     Engine();
151     ~Engine();
152
153     QSet<NameId> literals() const;
154
155     void addComment(int pos, int len, int line, int col);
156     QList<QmlJS::AST::SourceLocation> comments() const;
157
158     NameId *intern(const QChar *u, int s);
159
160     static QString toString(NameId *id);
161
162     Lexer *lexer() const;
163     void setLexer(Lexer *lexer);
164
165     NodePool *nodePool() const;
166     void setNodePool(NodePool *nodePool);
167 };
168
169 } // end of namespace QmlJS
170
171 QT_QML_END_NAMESPACE
172
173 #endif // QMLJSENGINE_P_H