OSDN Git Service

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