| 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 QSCRIPTFUNCTION_P_H | 
|---|
| 43 | #define QSCRIPTFUNCTION_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 "qscriptobjectdata_p.h" | 
|---|
| 57 |  | 
|---|
| 58 | #ifndef QT_NO_SCRIPT | 
|---|
| 59 |  | 
|---|
| 60 | #include "qscriptglobals_p.h" | 
|---|
| 61 | #include "qscriptnodepool_p.h" | 
|---|
| 62 |  | 
|---|
| 63 | #include <QtCore/QList> | 
|---|
| 64 |  | 
|---|
| 65 | #ifndef QT_NO_QOBJECT | 
|---|
| 66 | # include <QtCore/QPointer> | 
|---|
| 67 | # include <QtCore/QMetaMethod> | 
|---|
| 68 | #endif | 
|---|
| 69 |  | 
|---|
| 70 | QT_BEGIN_NAMESPACE | 
|---|
| 71 |  | 
|---|
| 72 | class QScriptContext; | 
|---|
| 73 | class QScriptContextPrivate; | 
|---|
| 74 | class QScriptNameIdImpl; | 
|---|
| 75 |  | 
|---|
| 76 | class QScriptFunction: public QScriptObjectData | 
|---|
| 77 | { | 
|---|
| 78 | public: | 
|---|
| 79 | enum Type { | 
|---|
| 80 | Unknown, | 
|---|
| 81 | Script, | 
|---|
| 82 | C, | 
|---|
| 83 | C2, | 
|---|
| 84 | C3, | 
|---|
| 85 | Qt, | 
|---|
| 86 | QtProperty | 
|---|
| 87 | }; | 
|---|
| 88 |  | 
|---|
| 89 | QScriptFunction(int len = 0) | 
|---|
| 90 | : length(len) | 
|---|
| 91 | { } | 
|---|
| 92 | virtual ~QScriptFunction(); | 
|---|
| 93 |  | 
|---|
| 94 | virtual void execute(QScriptContextPrivate *context) = 0; | 
|---|
| 95 | virtual QString toString(QScriptContextPrivate *context) const; | 
|---|
| 96 |  | 
|---|
| 97 | virtual Type type() const { return Unknown; } | 
|---|
| 98 |  | 
|---|
| 99 | // name of the file the function is defined in | 
|---|
| 100 | virtual QString fileName() const; | 
|---|
| 101 |  | 
|---|
| 102 | virtual QString functionName() const; | 
|---|
| 103 |  | 
|---|
| 104 | virtual int startLineNumber() const; | 
|---|
| 105 |  | 
|---|
| 106 | virtual int endLineNumber() const; | 
|---|
| 107 |  | 
|---|
| 108 | virtual void mark(QScriptEnginePrivate *engine, int generation); | 
|---|
| 109 |  | 
|---|
| 110 | public: // ### private | 
|---|
| 111 | int length; | 
|---|
| 112 | QList<QScriptNameIdImpl*> formals; | 
|---|
| 113 | }; | 
|---|
| 114 |  | 
|---|
| 115 | namespace QScript { | 
|---|
| 116 |  | 
|---|
| 117 | // public API function | 
|---|
| 118 | class CFunction: public QScriptFunction | 
|---|
| 119 | { | 
|---|
| 120 | public: | 
|---|
| 121 | CFunction(QScriptFunctionSignature funPtr, int length) | 
|---|
| 122 | : QScriptFunction(length), m_funPtr(funPtr) | 
|---|
| 123 | { } | 
|---|
| 124 |  | 
|---|
| 125 | virtual ~CFunction() { } | 
|---|
| 126 |  | 
|---|
| 127 | virtual void execute(QScriptContextPrivate *context); | 
|---|
| 128 |  | 
|---|
| 129 | virtual Type type() const { return QScriptFunction::C; } | 
|---|
| 130 |  | 
|---|
| 131 | virtual QString functionName() const; | 
|---|
| 132 |  | 
|---|
| 133 | private: | 
|---|
| 134 | QScriptFunctionSignature m_funPtr; | 
|---|
| 135 | }; | 
|---|
| 136 |  | 
|---|
| 137 | // internal API function | 
|---|
| 138 | class C2Function: public QScriptFunction | 
|---|
| 139 | { | 
|---|
| 140 | public: | 
|---|
| 141 | C2Function(QScriptInternalFunctionSignature funPtr, int length, | 
|---|
| 142 | QScriptClassInfo *classInfo, const QString &name) | 
|---|
| 143 | : QScriptFunction(length), m_funPtr(funPtr), | 
|---|
| 144 | m_classInfo(classInfo), m_name(name) | 
|---|
| 145 | { } | 
|---|
| 146 |  | 
|---|
| 147 | virtual ~C2Function() {} | 
|---|
| 148 |  | 
|---|
| 149 | virtual void execute(QScriptContextPrivate *context); | 
|---|
| 150 |  | 
|---|
| 151 | virtual Type type() const { return QScriptFunction::C2; } | 
|---|
| 152 |  | 
|---|
| 153 | virtual QString functionName() const; | 
|---|
| 154 |  | 
|---|
| 155 | private: | 
|---|
| 156 | QScriptInternalFunctionSignature m_funPtr; | 
|---|
| 157 | QScriptClassInfo *m_classInfo; | 
|---|
| 158 | QString m_name; | 
|---|
| 159 | }; | 
|---|
| 160 |  | 
|---|
| 161 | class C3Function: public QScriptFunction | 
|---|
| 162 | { | 
|---|
| 163 | public: | 
|---|
| 164 | C3Function(QScriptFunctionWithArgSignature funPtr, void *arg, int length) | 
|---|
| 165 | : QScriptFunction(length), m_funPtr(funPtr), m_arg(arg) | 
|---|
| 166 | { } | 
|---|
| 167 |  | 
|---|
| 168 | virtual ~C3Function() { } | 
|---|
| 169 |  | 
|---|
| 170 | virtual void execute(QScriptContextPrivate *context); | 
|---|
| 171 |  | 
|---|
| 172 | virtual Type type() const { return QScriptFunction::C3; } | 
|---|
| 173 |  | 
|---|
| 174 | private: | 
|---|
| 175 | QScriptFunctionWithArgSignature m_funPtr; | 
|---|
| 176 | void *m_arg; | 
|---|
| 177 | }; | 
|---|
| 178 |  | 
|---|
| 179 | namespace AST { | 
|---|
| 180 | class FunctionExpression; | 
|---|
| 181 | } | 
|---|
| 182 |  | 
|---|
| 183 | // implemented in qscriptcontext_p.cpp | 
|---|
| 184 | class ScriptFunction: public QScriptFunction | 
|---|
| 185 | { | 
|---|
| 186 | public: | 
|---|
| 187 | ScriptFunction(AST::FunctionExpression *definition, NodePool *astPool): | 
|---|
| 188 | m_definition(definition), m_astPool(astPool), m_compiledCode(0) {} | 
|---|
| 189 |  | 
|---|
| 190 | virtual ~ScriptFunction() {} | 
|---|
| 191 |  | 
|---|
| 192 | virtual void execute(QScriptContextPrivate *context); | 
|---|
| 193 |  | 
|---|
| 194 | virtual QString toString(QScriptContextPrivate *context) const; | 
|---|
| 195 |  | 
|---|
| 196 | virtual Type type() const | 
|---|
| 197 | { return QScriptFunction::Script; } | 
|---|
| 198 |  | 
|---|
| 199 | virtual QString fileName() const; | 
|---|
| 200 |  | 
|---|
| 201 | virtual QString functionName() const; | 
|---|
| 202 |  | 
|---|
| 203 | virtual int startLineNumber() const; | 
|---|
| 204 |  | 
|---|
| 205 | virtual int endLineNumber() const; | 
|---|
| 206 |  | 
|---|
| 207 | private: | 
|---|
| 208 | AST::FunctionExpression *m_definition; | 
|---|
| 209 | QExplicitlySharedDataPointer<NodePool> m_astPool; | 
|---|
| 210 | Code *m_compiledCode; | 
|---|
| 211 | }; | 
|---|
| 212 |  | 
|---|
| 213 | } // namespace QScript | 
|---|
| 214 |  | 
|---|
| 215 | QT_END_NAMESPACE | 
|---|
| 216 |  | 
|---|
| 217 | #endif // QT_NO_SCRIPT | 
|---|
| 218 |  | 
|---|
| 219 | #endif // QSCRIPTFUNCTION_P_H | 
|---|