TypeOfExpression.h 3.74 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
#include "DeprecatedLookupContext.h"
con's avatar
con committed
34

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

namespace CPlusPlus {

42 43 44
class Environment;
class Macro;

con's avatar
con committed
45 46 47 48 49
class CPLUSPLUS_EXPORT TypeOfExpression
{
public:
    TypeOfExpression();

50 51
    Snapshot snapshot() const;

con's avatar
con committed
52 53 54
    /**
     * Sets the documents used to evaluate expressions. Should be set before
     * calling this functor.
55 56 57
     *
     * 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
58
     */
59
    void setSnapshot(const Snapshot &documents);
con's avatar
con committed
60

61 62 63 64 65
    enum PreprocessMode {
        NoPreprocess,
        Preprocess
    };

con's avatar
con committed
66 67 68 69 70 71 72 73 74 75 76 77
    /**
     * 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.
     * @param document          The document the expression is part of.
     * @param lastVisibleSymbol The last visible symbol in the document.
     */
78
    QList<LookupItem> operator()(const QString &expression, Document::Ptr document,
79 80
                             Symbol *lastVisibleSymbol,
                             PreprocessMode mode = NoPreprocess);
con's avatar
con committed
81

82 83
    QString preprocess(const QString &expression, Document::Ptr document) const;

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

    /**
     * Returns the lookup context of the last evaluated expression.
     */
92
    const DeprecatedLookupContext &lookupContext() const;
con's avatar
con committed
93 94 95 96 97 98 99

    ExpressionAST *expressionAST() const;

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

100
    void processEnvironment(CPlusPlus::Snapshot documents,
101 102 103 104
                            CPlusPlus::Document::Ptr doc, CPlusPlus::Environment *env,
                            QSet<QString> *processed) const;

    QString preprocessedExpression(const QString &expression,
105
                                   CPlusPlus::Snapshot documents,
106 107
                                   CPlusPlus::Document::Ptr thisDocument) const;

108
    Snapshot m_snapshot;
con's avatar
con committed
109
    ExpressionAST *m_ast;
110
    DeprecatedLookupContext m_lookupContext;
con's avatar
con committed
111 112 113 114 115
};

} // namespace CPlusPlus

#endif // CPLUSPLUS_TYPEOFEXPRESSION_H