Eneboo - Documentación para desarrolladores
src/qsa/src/qsa/qsinterpreter.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qsinterpreter.h  1.1.5   edited 2006-02-23T15:39:57$
00003 **
00004 ** Copyright (C) 2001-2006 Trolltech AS.  All rights reserved.
00005 **
00006 ** This file is part of the Qt Script for Applications framework (QSA).
00007 **
00008 ** This file may be distributed and/or modified under the terms of the
00009 ** GNU General Public License version 2 as published by the Free Software
00010 ** Foundation and appearing in the file LICENSE.GPL included in the
00011 ** packaging of this file.
00012 **
00013 ** Licensees holding a valid Qt Script for Applications license may use
00014 ** this file in accordance with the Qt Script for Applications License
00015 ** Agreement provided with the Software.
00016 **
00017 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00018 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00019 **
00020 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00021 **   information about QSA Commercial License Agreements.
00022 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00023 **
00024 ** Contact info@trolltech.com if any conditions of this licensing are
00025 ** not clear to you.
00026 **
00027 *****************************************************************************/
00028 
00029 #ifndef QSINTERPRETER_H
00030 #define QSINTERPRETER_H
00031 
00032 #include "qsaglobal.h"
00033 #include "qsproject.h"
00034 #include "qsargument.h"
00035 
00036 #include <qobject.h>
00037 #include <qvariant.h>
00038 #include <qobjectlist.h>
00039 
00040 class QSProject;
00041 class QSInterpreterPrivate;
00042 class QuickInterpreter;
00043 class QSObjectFactory;
00044 class QSWrapperFactory;
00045 
00046 class QSA_EXPORT QSStackFrame
00047 {
00048 public:
00049   QSStackFrame(const QString &fun = QString::null,
00050                const QString &file = QString::null,
00051                int line = 0,
00052                QObject *con = 0) :
00053     fname(file), func(fun), ln(line), cont(con) {
00054   }
00055 
00056   QString scriptName() const {
00057     return fname;
00058   }
00059   QString function() const {
00060     return func;
00061   }
00062   int line() const {
00063     return ln;
00064   }
00065   QObject *context() const {
00066     return cont;
00067   }
00068 private:
00069   QString fname, func;
00070   int ln;
00071   QObject *cont;
00072 };
00073 
00074 bool operator==(const QSStackFrame &a, const QSStackFrame &b);
00075 
00076 class QSA_EXPORT QSStackTrace : public QValueList<QSStackFrame>
00077 {
00078 public:
00079   QString toString() const;
00080 };
00081 
00082 class QSA_EXPORT QSInterpreter : public QObject
00083 {
00084   friend class QSProject;
00085   friend class QSWrapperFactory; // for access to interpreter()
00086   friend class QSObjectFactory;
00087   friend class QSInterfaceFactory;
00088   friend class QSToolkitFactory;
00089   friend QuickInterpreter *get_quick_interpreter(QSInterpreter *ip);
00090 
00091   Q_OBJECT
00092   Q_ENUMS(ErrorMode)
00093   Q_PROPERTY(ErrorMode errorMode READ errorMode WRITE setErrorMode)
00094   Q_PROPERTY(int timeoutInterval READ timeoutInterval WRITE setTimeoutInterval)
00095 
00096 public:
00097   enum ErrorMode { Notify, Nothing };
00098   enum ClassFlags { AllClasses, GlobalClasses };
00099   enum FunctionFlags { FunctionNames = 0,
00100                        FunctionSignatures = 1,
00101                        IncludeMemberFunctions = 2
00102                      };
00103 
00104   QSInterpreter(QObject *parent = 0, const char *name = 0);
00105   virtual ~QSInterpreter();
00106 
00107   static QSInterpreter *defaultInterpreter();
00108 
00109   QSArgument evaluate(const QString &code, QObject *context = 0,
00110                       const QString &scriptName = QString::null);
00111   QSArgument call(const QString &function,
00112                   const QSArgumentList &arguments = QSArgumentList(),
00113                   QObject *context = 0);
00114   QObject *currentContext() const;
00115 
00116   bool checkSyntax(const QString &code);
00117 
00118   void setErrorMode(ErrorMode m);
00119   ErrorMode errorMode() const;
00120 
00121   QSProject *project() const;
00122 
00123   QStringList functions(FunctionFlags flag = FunctionNames) const;
00124   QStringList functions(const QString &context,
00125                         uint mask = FunctionNames) const;
00126   QStringList functions(QObject *context,
00127                         FunctionFlags flag = FunctionNames) const;
00128 
00129   QStringList classes(ClassFlags = AllClasses) const;
00130   QStringList classes(const QString &context) const;
00131   QStringList classes(QObject *context) const;
00132 
00133   QStringList variables(bool includeStatic = false,
00134                         bool includeCustom = false,
00135                         bool includeMemberVariables = false) const;
00136   QStringList variables(const QString &context, bool includeStatic = false,
00137                         bool includeCustom = false,
00138                         bool includeMemberVariables = false) const;
00139   QStringList variables(QObject *context, bool includeStatic = false,
00140                         bool includeCustom = false,
00141                         bool includeMemberVariables = false) const;
00142 
00143   bool hasFunction(const QString &function) const;
00144   bool hasClass(const QString &className) const;
00145   bool hasVariable(const QString &variable) const;
00146 
00147   void addTransientVariable(const QString &variable, const QSArgument &arg, QObject *context = 0);
00148   QSArgument variable(const QString &variable, QObject *context = 0) const;
00149 
00150   QObjectList presentObjects() const;
00151   void addTransientObject(QObject *object);
00152 
00153   bool isRunning() const;
00154 
00155   void throwError(const QString &message);
00156 
00157   void addObjectFactory(QSObjectFactory *factory);
00158   void addWrapperFactory(QSWrapperFactory *factory);
00159 
00160   QSStackTrace stackTrace() const;
00161   QString errorMessage() const;
00162   bool hadError() const;
00163 
00164   void addTransientSignalHandler(QObject *sender,
00165                                  const char *signal,
00166                                  const char *qtscriptFunction);
00167 
00168   void removeTransientSignalHandler(QObject *sender,
00169                                     const char *signal,
00170                                     const char *qtscriptFunction);
00171 
00172   void setTimeoutInterval(int msecs);
00173   int timeoutInterval() const;
00174 
00175 public slots:
00176   void clear();
00177   void stopExecution();
00178 
00179 signals:
00180   void error(const QString &message, const QString &scriptName,
00181              int lineNumber);
00182   void error(const QString &message, QObject *context,
00183              const QString &scriptName, int lineNumber);
00184 
00185   void timeout(int runnningTime);
00186 
00187 private:
00188   // disabled copy constructor and assignment operator
00189   QSInterpreter(const QSInterpreter &);
00190   QSInterpreter &operator=(const QSInterpreter &);
00191   QSInterpreter(QSProject *project, const char *name = 0);
00192 
00193   void init();
00194 
00195   // used by factory classes
00196   QuickInterpreter *interpreter() const;
00197 
00198   void removeObjectFactory(QSObjectFactory *factory);
00199   void removeWrapperFactory(QSWrapperFactory *factory);
00200 
00201 private slots:
00202   void runtimeError(const QString &message, const QString &filename, int lineNumber);
00203   void runtimeError();
00204   void parseError();
00205 
00206 private:
00207   QSInterpreterPrivate *d;
00208 
00209   uint running: 1;
00210 };
00211 
00212 inline bool QSInterpreter::isRunning() const
00213 {
00214   return running;
00215 }
00216 
00217 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'