1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
33 #ifndef CPLUSPLUS_TYPEOFEXPRESSION_H
34 #define CPLUSPLUS_TYPEOFEXPRESSION_H
36 #include "CppDocument.h"
37 #include "LookupContext.h"
38 #include "PreprocessorEnvironment.h"
41 #include <QtCore/QMap>
42 #include <QtCore/QObject>
43 #include <QtCore/QString>
50 class CPLUSPLUS_EXPORT TypeOfExpression
52 Q_DISABLE_COPY(TypeOfExpression)
58 * Sets the documents used to evaluate expressions. Should be set before
59 * calling this functor.
61 * Also clears the lookup context, so can be used to make sure references
62 * to the documents previously used are removed.
64 void init(Document::Ptr thisDocument, const Snapshot &snapshot,
65 QSharedPointer<CreateBindings> bindings = QSharedPointer<CreateBindings>());
75 * Returns a list of possible fully specified types associated with the
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
82 * @param expression The expression to evaluate.
83 * @param scope The scope enclosing the expression.
85 QList<LookupItem> operator()(const QString &expression,
87 PreprocessMode mode = NoPreprocess);
90 * Returns a list of possible fully specified types associated with the
91 * given expression AST from the given document.
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
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.
101 QList<LookupItem> operator()(ExpressionAST *expression,
102 Document::Ptr document,
105 QList<LookupItem> reference(const QString &expression,
107 PreprocessMode mode = NoPreprocess);
109 QList<LookupItem> reference(ExpressionAST *expression,
110 Document::Ptr document,
113 QString preprocess(const QString &expression) const;
116 * Returns the AST of the last evaluated expression.
118 ExpressionAST *ast() const;
121 * Returns the lookup context of the last evaluated expression.
123 const LookupContext &context() const;
124 Scope *scope() const;
126 ExpressionAST *expressionAST() const;
129 ExpressionAST *extractExpressionAST(Document::Ptr doc) const;
130 Document::Ptr documentForExpression(const QString &expression) const;
132 void processEnvironment(Document::Ptr doc, Environment *env,
133 QSet<QString> *processed) const;
135 QString preprocessedExpression(const QString &expression) const;
138 Document::Ptr m_thisDocument;
140 QSharedPointer<CreateBindings> m_bindings;
141 ExpressionAST *m_ast;
143 LookupContext m_lookupContext;
144 mutable QSharedPointer<Environment> m_environment;
147 } // namespace CPlusPlus
149 #endif // CPLUSPLUS_TYPEOFEXPRESSION_H