TypeOfExpression.h 5.11 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
hjk's avatar
hjk committed
3 4
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
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>
37 38 39 40
#include <QMap>
#include <QObject>
#include <QString>
#include <QByteArray>
con's avatar
con committed
41 42 43

namespace CPlusPlus {

44 45 46
class Environment;
class Macro;

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

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

    /**
     * Sets the documents used to evaluate expressions. Should be set before
     * calling this functor.
57 58 59
     *
     * 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
60
     */
61 62 63 64
    void init(Document::Ptr thisDocument, const Snapshot &snapshot,
              QSharedPointer<CreateBindings> bindings = QSharedPointer<CreateBindings>());

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

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

con's avatar
con committed
71 72 73 74 75 76 77 78 79
    /**
     * 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.
80
     * @param scope             The scope enclosing the expression.
con's avatar
con committed
81
     */
82
    QList<LookupItem> operator()(const QByteArray &utf8code,
83
                                 Scope *scope,
84
                                 PreprocessMode mode = NoPreprocess);
con's avatar
con committed
85

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    /**
     * Returns a list of possible fully specified types associated with the
     * given expression AST from the given document.
     *
     * 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 in which the expression lives.
     * @param scope             The scope enclosing the expression.
     */
    QList<LookupItem> operator()(ExpressionAST *expression,
                                 Document::Ptr document,
                                 Scope *scope);

102
    QList<LookupItem> reference(const QByteArray &utf8code,
103 104 105 106 107 108 109
                                Scope *scope,
                                PreprocessMode mode = NoPreprocess);

    QList<LookupItem> reference(ExpressionAST *expression,
                                Document::Ptr document,
                                Scope *scope);

110
    QByteArray preprocess(const QByteArray &utf8code) const;
111

con's avatar
con committed
112 113 114 115 116 117 118 119
    /**
     * Returns the AST of the last evaluated expression.
     */
    ExpressionAST *ast() const;

    /**
     * Returns the lookup context of the last evaluated expression.
     */
120
    const LookupContext &context() const;
121
    Scope *scope() const;
con's avatar
con committed
122 123

    ExpressionAST *expressionAST() const;
124
    QByteArray preprocessedExpression(const QByteArray &utf8code) const;
con's avatar
con committed
125

126 127 128
    void setExpandTemplates(bool expandTemplates)
    { m_expandTemplates = expandTemplates; }

con's avatar
con committed
129 130
private:

131
    void processEnvironment(Document::Ptr doc, Environment *env,
132 133 134
                            QSet<QString> *processed) const;


135 136
private:
    Document::Ptr m_thisDocument;
137
    Snapshot m_snapshot;
138
    QSharedPointer<CreateBindings> m_bindings;
con's avatar
con committed
139
    ExpressionAST *m_ast;
140
    Scope *m_scope;
141 142
    LookupContext m_lookupContext;
    mutable QSharedPointer<Environment> m_environment;
143 144

    bool m_expandTemplates;
con's avatar
con committed
145 146
};

147 148 149
ExpressionAST CPLUSPLUS_EXPORT *extractExpressionAST(Document::Ptr doc);
Document::Ptr CPLUSPLUS_EXPORT documentForExpression(const QByteArray &utf8code);

con's avatar
con committed
150 151 152
} // namespace CPlusPlus

#endif // CPLUSPLUS_TYPEOFEXPRESSION_H