OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / libs / cplusplus / TypeOfExpression.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 #ifndef CPLUSPLUS_TYPEOFEXPRESSION_H
34 #define CPLUSPLUS_TYPEOFEXPRESSION_H
35
36 #include "CppDocument.h"
37 #include "LookupContext.h"
38 #include "PreprocessorEnvironment.h"
39
40 #include <ASTfwd.h>
41 #include <QtCore/QMap>
42 #include <QtCore/QObject>
43 #include <QtCore/QString>
44
45 namespace CPlusPlus {
46
47 class Environment;
48 class Macro;
49
50 class CPLUSPLUS_EXPORT TypeOfExpression
51 {
52     Q_DISABLE_COPY(TypeOfExpression)
53
54 public:
55     TypeOfExpression();
56
57     /**
58      * Sets the documents used to evaluate expressions. Should be set before
59      * calling this functor.
60      *
61      * Also clears the lookup context, so can be used to make sure references
62      * to the documents previously used are removed.
63      */
64     void init(Document::Ptr thisDocument, const Snapshot &snapshot,
65               QSharedPointer<CreateBindings> bindings = QSharedPointer<CreateBindings>());
66
67     void reset();
68
69     enum PreprocessMode {
70         NoPreprocess,
71         Preprocess
72     };
73
74     /**
75      * Returns a list of possible fully specified types associated with the
76      * given expression.
77      *
78      * NOTE: The fully specified types only stay valid for as long as this
79      * expression evaluator instance still exists, and no new call to evaluate
80      * has been made!
81      *
82      * @param expression        The expression to evaluate.
83      * @param scope             The scope enclosing the expression.
84      */
85     QList<LookupItem> operator()(const QString &expression,
86                                  Scope *scope,
87                                  PreprocessMode mode = NoPreprocess);
88
89     /**
90      * Returns a list of possible fully specified types associated with the
91      * given expression AST from the given document.
92      *
93      * NOTE: The fully specified types only stay valid for as long as this
94      * expression evaluator instance still exists, and no new call to evaluate
95      * has been made!
96      *
97      * @param expression        The expression to evaluate.
98      * @param document          The document in which the expression lives.
99      * @param scope             The scope enclosing the expression.
100      */
101     QList<LookupItem> operator()(ExpressionAST *expression,
102                                  Document::Ptr document,
103                                  Scope *scope);
104
105     QList<LookupItem> reference(const QString &expression,
106                                 Scope *scope,
107                                 PreprocessMode mode = NoPreprocess);
108
109     QList<LookupItem> reference(ExpressionAST *expression,
110                                 Document::Ptr document,
111                                 Scope *scope);
112
113     QString preprocess(const QString &expression) const;
114
115     /**
116      * Returns the AST of the last evaluated expression.
117      */
118     ExpressionAST *ast() const;
119
120     /**
121      * Returns the lookup context of the last evaluated expression.
122      */
123     const LookupContext &context() const;
124     Scope *scope() const;
125
126     ExpressionAST *expressionAST() const;
127
128 private:
129     ExpressionAST *extractExpressionAST(Document::Ptr doc) const;
130     Document::Ptr documentForExpression(const QString &expression) const;
131
132     void processEnvironment(Document::Ptr doc, Environment *env,
133                             QSet<QString> *processed) const;
134
135     QString preprocessedExpression(const QString &expression) const;
136
137 private:
138     Document::Ptr m_thisDocument;
139     Snapshot m_snapshot;
140     QSharedPointer<CreateBindings> m_bindings;
141     ExpressionAST *m_ast;
142     Scope *m_scope;
143     LookupContext m_lookupContext;
144     mutable QSharedPointer<Environment> m_environment;
145 };
146
147 } // namespace CPlusPlus
148
149 #endif // CPLUSPLUS_TYPEOFEXPRESSION_H