1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
32 #ifndef CPLUSPLUS_TYPEOFEXPRESSION_H
33 #define CPLUSPLUS_TYPEOFEXPRESSION_H
35 #include "CppDocument.h"
36 #include "LookupContext.h"
37 #include "PreprocessorEnvironment.h"
40 #include <QtCore/QMap>
41 #include <QtCore/QObject>
42 #include <QtCore/QString>
49 class CPLUSPLUS_EXPORT TypeOfExpression
51 Q_DISABLE_COPY(TypeOfExpression)
57 * Sets the documents used to evaluate expressions. Should be set before
58 * calling this functor.
60 * Also clears the lookup context, so can be used to make sure references
61 * to the documents previously used are removed.
63 void init(Document::Ptr thisDocument, const Snapshot &snapshot,
64 QSharedPointer<CreateBindings> bindings = QSharedPointer<CreateBindings>());
74 * Returns a list of possible fully specified types associated with the
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
81 * @param expression The expression to evaluate.
82 * @param scope The scope enclosing the expression.
84 QList<LookupItem> operator()(const QString &expression,
86 PreprocessMode mode = NoPreprocess);
89 * Returns a list of possible fully specified types associated with the
90 * given expression AST from the given document.
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
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.
100 QList<LookupItem> operator()(ExpressionAST *expression,
101 Document::Ptr document,
104 QList<LookupItem> reference(const QString &expression,
106 PreprocessMode mode = NoPreprocess);
108 QList<LookupItem> reference(ExpressionAST *expression,
109 Document::Ptr document,
112 QString preprocess(const QString &expression) const;
115 * Returns the AST of the last evaluated expression.
117 ExpressionAST *ast() const;
120 * Returns the lookup context of the last evaluated expression.
122 const LookupContext &context() const;
123 Scope *scope() const;
125 ExpressionAST *expressionAST() const;
128 ExpressionAST *extractExpressionAST(Document::Ptr doc) const;
129 Document::Ptr documentForExpression(const QString &expression) const;
131 void processEnvironment(Document::Ptr doc, Environment *env,
132 QSet<QString> *processed) const;
134 QString preprocessedExpression(const QString &expression) const;
137 Document::Ptr m_thisDocument;
139 QSharedPointer<CreateBindings> m_bindings;
140 ExpressionAST *m_ast;
142 LookupContext m_lookupContext;
143 mutable QSharedPointer<Environment> m_environment;
146 } // namespace CPlusPlus
148 #endif // CPLUSPLUS_TYPEOFEXPRESSION_H