TypeOfExpression.h 3.73 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11 12 13 14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
con's avatar
con committed
29 30 31
#ifndef CPLUSPLUS_TYPEOFEXPRESSION_H
#define CPLUSPLUS_TYPEOFEXPRESSION_H

32
#include "CppDocument.h"
33 34
#include "LookupContext.h"
#include "PreprocessorEnvironment.h"
con's avatar
con committed
35

36
#include <ASTfwd.h>
con's avatar
con committed
37 38 39 40 41 42
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QString>

namespace CPlusPlus {

43 44 45
class Environment;
class Macro;

con's avatar
con committed
46 47
class CPLUSPLUS_EXPORT TypeOfExpression
{
48 49
    Q_DISABLE_COPY(TypeOfExpression)

con's avatar
con committed
50 51 52 53 54 55
public:
    TypeOfExpression();

    /**
     * Sets the documents used to evaluate expressions. Should be set before
     * calling this functor.
56 57 58
     *
     * Also clears the lookup context, so can be used to make sure references
     * to the documents previously used are removed.
con's avatar
con committed
59
     */
60 61 62 63
    void init(Document::Ptr thisDocument, const Snapshot &snapshot,
              QSharedPointer<CreateBindings> bindings = QSharedPointer<CreateBindings>());

    void reset();
con's avatar
con committed
64

65 66 67 68 69
    enum PreprocessMode {
        NoPreprocess,
        Preprocess
    };

con's avatar
con committed
70 71 72 73 74 75 76 77 78
    /**
     * Returns a list of possible fully specified types associated with the
     * given expression.
     *
     * NOTE: The fully specified types only stay valid for as long as this
     * expression evaluator instance still exists, and no new call to evaluate
     * has been made!
     *
     * @param expression        The expression to evaluate.
79
     * @param scope             The scope enclosing the expression.
con's avatar
con committed
80
     */
81
    QList<LookupItem> operator()(const QString &expression,
82
                                 Scope *scope,
83
                                 PreprocessMode mode = NoPreprocess);
con's avatar
con committed
84

85
    QString preprocess(const QString &expression) const;
86

con's avatar
con committed
87 88 89 90 91 92 93 94
    /**
     * Returns the AST of the last evaluated expression.
     */
    ExpressionAST *ast() const;

    /**
     * Returns the lookup context of the last evaluated expression.
     */
95
    const LookupContext &lookupContext() const;
96
    Scope *scope() const;
con's avatar
con committed
97 98 99 100 101 102 103

    ExpressionAST *expressionAST() const;

private:
    ExpressionAST *extractExpressionAST(Document::Ptr doc) const;
    Document::Ptr documentForExpression(const QString &expression) const;

104
    void processEnvironment(Document::Ptr doc, Environment *env,
105 106
                            QSet<QString> *processed) const;

107
    QString preprocessedExpression(const QString &expression) const;
108

109 110
private:
    Document::Ptr m_thisDocument;
111
    Snapshot m_snapshot;
112
    QSharedPointer<CreateBindings> m_bindings;
con's avatar
con committed
113
    ExpressionAST *m_ast;
114
    Scope *m_scope;
115 116
    LookupContext m_lookupContext;
    mutable QSharedPointer<Environment> m_environment;
con's avatar
con committed
117 118 119 120 121
};

} // namespace CPlusPlus

#endif // CPLUSPLUS_TYPEOFEXPRESSION_H