| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtScript module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QSCRIPTASM_P_H
|
|---|
| 43 | #define QSCRIPTASM_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 49 | // This file is not part of the Qt API. It exists purely as an
|
|---|
| 50 | // implementation detail. This header file may change from version to
|
|---|
| 51 | // version without notice, or even be removed.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #include <QtCore/qglobal.h>
|
|---|
| 57 |
|
|---|
| 58 | #ifndef QT_NO_SCRIPT
|
|---|
| 59 |
|
|---|
| 60 | #include <QtCore/qvector.h>
|
|---|
| 61 |
|
|---|
| 62 | #include "qscriptvalueimplfwd_p.h"
|
|---|
| 63 |
|
|---|
| 64 | QT_BEGIN_NAMESPACE
|
|---|
| 65 |
|
|---|
| 66 | class QTextStream;
|
|---|
| 67 |
|
|---|
| 68 | class QScriptInstruction
|
|---|
| 69 | {
|
|---|
| 70 | public:
|
|---|
| 71 | enum Operator {
|
|---|
| 72 | #define Q_SCRIPT_DEFINE_OPERATOR(op) OP_##op,
|
|---|
| 73 | #include "instruction.table"
|
|---|
| 74 | #undef Q_SCRIPT_DEFINE_OPERATOR
|
|---|
| 75 | OP_Dummy
|
|---|
| 76 | };
|
|---|
| 77 |
|
|---|
| 78 | public:
|
|---|
| 79 | Operator op;
|
|---|
| 80 | QScriptValueImpl operand[2];
|
|---|
| 81 | #if defined(Q_SCRIPT_DIRECT_CODE)
|
|---|
| 82 | void *code;
|
|---|
| 83 | #endif
|
|---|
| 84 |
|
|---|
| 85 | void print(QTextStream &out) const;
|
|---|
| 86 |
|
|---|
| 87 | static const char *opcode[];
|
|---|
| 88 | };
|
|---|
| 89 |
|
|---|
| 90 | namespace QScript {
|
|---|
| 91 |
|
|---|
| 92 | class NodePool;
|
|---|
| 93 |
|
|---|
| 94 | class ExceptionHandlerDescriptor
|
|---|
| 95 | {
|
|---|
| 96 | public:
|
|---|
| 97 | ExceptionHandlerDescriptor()
|
|---|
| 98 | : m_startInstruction(0),
|
|---|
| 99 | m_endInstruction(0),
|
|---|
| 100 | m_handlerInstruction(0) {}
|
|---|
| 101 |
|
|---|
| 102 | ExceptionHandlerDescriptor(
|
|---|
| 103 | int startInstruction,
|
|---|
| 104 | int endInstruction,
|
|---|
| 105 | int handlerInstruction)
|
|---|
| 106 | : m_startInstruction(startInstruction),
|
|---|
| 107 | m_endInstruction(endInstruction),
|
|---|
| 108 | m_handlerInstruction(handlerInstruction) {}
|
|---|
| 109 |
|
|---|
| 110 | inline int startInstruction() const { return m_startInstruction; }
|
|---|
| 111 | inline int endInstruction() const { return m_endInstruction; }
|
|---|
| 112 | inline int handlerInstruction() const { return m_handlerInstruction; }
|
|---|
| 113 |
|
|---|
| 114 | private:
|
|---|
| 115 | int m_startInstruction;
|
|---|
| 116 | int m_endInstruction;
|
|---|
| 117 | int m_handlerInstruction;
|
|---|
| 118 | };
|
|---|
| 119 |
|
|---|
| 120 | class CompilationUnit
|
|---|
| 121 | {
|
|---|
| 122 | public:
|
|---|
| 123 | CompilationUnit(): m_valid(true),
|
|---|
| 124 | m_errorLineNumber(-1) {}
|
|---|
| 125 |
|
|---|
| 126 | bool isValid() const { return m_valid; }
|
|---|
| 127 |
|
|---|
| 128 | void setError(const QString &message, int lineNumber)
|
|---|
| 129 | {
|
|---|
| 130 | m_errorMessage = message;
|
|---|
| 131 | m_errorLineNumber = lineNumber;
|
|---|
| 132 | m_valid = false;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | QString errorMessage() const
|
|---|
| 136 | { return m_errorMessage; }
|
|---|
| 137 | int errorLineNumber() const
|
|---|
| 138 | { return m_errorLineNumber; }
|
|---|
| 139 |
|
|---|
| 140 | QVector<QScriptInstruction> instructions() const
|
|---|
| 141 | { return m_instructions; }
|
|---|
| 142 | void setInstructions(const QVector<QScriptInstruction> &instructions)
|
|---|
| 143 | { m_instructions = instructions; }
|
|---|
| 144 |
|
|---|
| 145 | QVector<ExceptionHandlerDescriptor> exceptionHandlers() const
|
|---|
| 146 | { return m_exceptionHandlers; }
|
|---|
| 147 | void setExceptionHandlers(const QVector<ExceptionHandlerDescriptor> &exceptionHandlers)
|
|---|
| 148 | { m_exceptionHandlers = exceptionHandlers; }
|
|---|
| 149 |
|
|---|
| 150 | private:
|
|---|
| 151 | bool m_valid;
|
|---|
| 152 | QString m_errorMessage;
|
|---|
| 153 | int m_errorLineNumber;
|
|---|
| 154 | QVector<QScriptInstruction> m_instructions;
|
|---|
| 155 | QVector<ExceptionHandlerDescriptor> m_exceptionHandlers;
|
|---|
| 156 | };
|
|---|
| 157 |
|
|---|
| 158 | class Code
|
|---|
| 159 | {
|
|---|
| 160 | public:
|
|---|
| 161 | Code();
|
|---|
| 162 | ~Code();
|
|---|
| 163 |
|
|---|
| 164 | void init(const CompilationUnit &compilation, NodePool *astPool);
|
|---|
| 165 |
|
|---|
| 166 | public: // attributes
|
|---|
| 167 | bool optimized;
|
|---|
| 168 | QScriptInstruction *firstInstruction;
|
|---|
| 169 | QScriptInstruction *lastInstruction;
|
|---|
| 170 | QVector<ExceptionHandlerDescriptor> exceptionHandlers;
|
|---|
| 171 | NodePool *astPool;
|
|---|
| 172 |
|
|---|
| 173 | private:
|
|---|
| 174 | Q_DISABLE_COPY(Code)
|
|---|
| 175 | };
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 | } // namespace QScript
|
|---|
| 179 |
|
|---|
| 180 | QT_END_NAMESPACE
|
|---|
| 181 |
|
|---|
| 182 | #endif // QT_NO_SCRIPT
|
|---|
| 183 | #endif // QSCRIPTASM_P_H
|
|---|