Eneboo - Documentación para desarrolladores
src/qsa/src/engine/qsenv.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qsenv.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 QSENV_H
00030 #define QSENV_H
00031 
00032 #include "qsobject.h"
00033 #include "qsclasslist.h"
00034 #include <qstring.h>
00035 #include <qvaluelist.h>
00036 #include <qptrlist.h>
00037 #include <qstringlist.h>
00038 
00039 class QSEngine;
00040 class QSClass;
00041 class QSObjectClass;
00042 class QSUndefinedClass;
00043 class QSNullClass;
00044 class QSBooleanClass;
00045 class QSNumberClass;
00046 class QSStringClass;
00047 class QSCharacterClass;
00048 class QSFunctionClass;
00049 class QSTypeClass;
00050 class QSDateClass;
00051 class QSMathClass;
00052 class QSRegExpClass;
00053 class QSArrayClass;
00054 class QSErrorClass;
00055 class QSArgumentsClass;
00056 class QSDynamicClass;
00057 class QSGlobalClass;
00058 class QSFuncRefClass;
00059 class QSDebugClass;
00060 class QSSystemClass;
00061 
00062 typedef QValueList<QSObject> ScopeChain;
00063 
00064 class QUICKCORE_EXPORT QSEnv
00065 {
00066 public:
00067   enum ExecutionMode { Normal, Break, Continue, ReturnValue, Throw };
00068   QSEnv(QSEngine *e);
00069   ~QSEnv();
00070   void init();
00071   void clear();
00072 
00073   QSEngine *engine() const {
00074     return eng;
00075   }
00076 
00077   //### AbanQ
00078 
00079   inline void pushScopeBlock() {
00080     QSObject obj;
00081     pushScope(obj);
00082     labels.push_front(QString::null);
00083   }
00084   inline void pushScope(const QSObject &scope) {
00085     scopeChain->push_front(scope);
00086   }
00087   inline void popScope() {
00088     scopeChain->pop_front();
00089   }
00090   inline void popScopeBlock() {
00091     while (!scopeChain->isEmpty() && scopeChain->first().isValid())
00092       popScope();
00093     popScope();
00094     labels.pop_front();
00095   }
00096 
00097   inline ScopeChain scope() const {
00098     ScopeChain chain;
00099     ScopeChain::const_iterator it = scopeChain->begin();
00100     while (it != scopeChain->end() && (*it).isValid()) {
00101       chain.push_back(*it);
00102       it++;
00103     }
00104     return chain;
00105   }
00106   inline QSObject currentScope() const {
00107     return scopeChain->first();
00108   }
00109 
00110   inline void clearScopeChain() {
00111     scopeChain->clear();
00112   }
00113   inline const ScopeChain *fullScopeChain() const {
00114     return scopeChain;
00115   }
00116 
00117   static void printScopeChain(const ScopeChain *chain);
00118   void printScopeChain() const;
00119 
00120   inline QSObject thisValue() const {
00121     return thVal;
00122   }
00123   inline void setThisValue(const QSObject &t) {
00124     thVal = t;
00125   }
00126   inline const QSClass *thisClass() const {
00127     return thisValue().objectType();
00128   }
00129   inline QSObject globalObject() const {
00130     return scopeChain->last();
00131   }
00132 
00133   QSObject getValueDirect(int index, int level);
00134   void setValueDirect(int index, int level, const QSObject &value);
00135   QSObject scopeObjectAt(int level) const;
00136 
00137   QSClass *classByName(const QString &n);
00138   QSClass *classByIdentifier(const QString &n);
00139 
00140   void pushLabel(const QString &l);
00141   void popLabel();
00142   bool containsLabel(const QString &l) const;
00143   QString currentLabel() const {
00144     return label;
00145   }
00146   void setCurrentLabel(const QString &l) {
00147     label = l;
00148   }
00149   bool isCurrentLabelValid() const;
00150 
00151   QSObjectClass *objectClass() const {
00152     return objClass;
00153   }
00154   QSNullClass *nullClass() const {
00155     return nilClass;
00156   }
00157   QSUndefinedClass *undefinedClass() const {
00158     return undefClass;
00159   }
00160   QSNumberClass *numberClass() const {
00161     return numClass;
00162   }
00163   QSBooleanClass *booleanClass() const {
00164     return boolClass;
00165   }
00166   QSStringClass *stringClass() const {
00167     return strClass;
00168   }
00169   QSTypeClass *typeClass() const {
00170     return typClass;
00171   }
00172   QSErrorClass *errorClass() const {
00173     return errClass;
00174   }
00175   QSArrayClass *arrayClass() const {
00176     return arrClass;
00177   }
00178   QSDateClass *dateClass() const {
00179     return datClass;
00180   }
00181   QSRegExpClass *regexpClass() const {
00182     return regClass;
00183   }
00184   QSMathClass *mathClass() const {
00185     return matClass;
00186   }
00187   QSFuncRefClass *funcRefClass() const {
00188     return refClass;
00189   }
00190   QSDebugClass *debugClass() const {
00191     return dbgClass;
00192   }
00193   QSSystemClass *systemClass() const {
00194     return sysClass;
00195   }
00196 
00197   // internal
00198   QSGlobalClass *globalClass() const {
00199     return globClass;
00200   }
00201   QSArgumentsClass *argumentsClass() const {
00202     return argsClass;
00203   }
00204   QSDynamicClass *dynamicClass() const {
00205     return dynClass;
00206   }
00207 
00208   void registerClass(QSClass *cl);
00209   void unregisterClass(QSClass *cl);
00210 
00211   QSObject resolveValue(const QString &n) const;
00212 
00213   QPtrList<QSClass> classes() const {
00214     return classList;
00215   }
00216 
00217   QSObject throwError(ErrorType e, const QString &m = QString::null,
00218                       int l = -1);
00219   QSObject throwError(const QString &msg);
00220 
00221   void setException(const QSObject &e);
00222   void setException(const QString &msg);
00223   QSObject exception();
00224   void clearException();
00225 
00226   void setExecutionMode(ExecutionMode mode);
00227   ExecutionMode executionMode() const {
00228     return execMode;
00229   }
00230   bool isNormalMode() const {
00231     return execMode == Normal;
00232   }
00233   bool isExceptionMode() const {
00234     return execMode == Throw;
00235   }
00236   bool isBreakMode() const {
00237     return execMode == Break;
00238   }
00239   bool isContinueMode() const {
00240     return execMode == Continue;
00241   }
00242   bool isReturnValueMode() const {
00243     return execMode == ReturnValue;
00244   }
00245 
00246   void setArguments(const QSList *lst) {
00247     args = lst;
00248   }
00249   const QSList *arguments() const {
00250     return args;
00251   }
00252   QSObject arg(int index) const {
00253     return index >= args->size() || index < 0 ?
00254            createUndefined() : args->at(index);
00255   }
00256   int numArgs() const {
00257     return args->size();
00258   }
00259 
00260   QSObject createNumber(double n) const;
00261   QSObject createBoolean(bool b) const;
00262   QSObject createString(const QString &s) const;
00263   QSObject createUndefined() const;
00264   QSObject createNull() const;
00265 
00266   QSObject createShared(const QSClass *cl, QSShared *sh) const;
00267   void registerShared(QSShared *sh) const;
00268   void removeShared(QSShared *sh) const;
00269   bool isShuttingDown() const {
00270     return shutDown;
00271   }
00272 
00273   int stackDepth() const {
00274     return stackDep;
00275   }
00276   void incrStackDepth() {
00277     ++stackDep;
00278   }
00279   void decrStackDepth() {
00280     --stackDep;
00281   }
00282 
00283 private:
00284   QSEngine *eng;
00285 
00286   QSObjectClass *objClass;
00287   QSUndefinedClass *undefClass;
00288   QSNullClass *nilClass;
00289   QSBooleanClass *boolClass;
00290   QSNumberClass *numClass;
00291   QSStringClass *strClass;
00292   QSCharacterClass *charClass;
00293   QSTypeClass *typClass;
00294   QSDateClass *datClass;
00295   QSMathClass *matClass;
00296   QSRegExpClass *regClass;
00297   QSArrayClass *arrClass;
00298   QSErrorClass *errClass;
00299   QSGlobalClass *globClass;
00300   QSArgumentsClass *argsClass;
00301   QSDynamicClass *dynClass;
00302   QSFuncRefClass *refClass;
00303   QSDebugClass *dbgClass;
00304   QSSystemClass *sysClass;
00305 
00306   ScopeChain *scopeChain;
00307   QSObject thVal;
00308   QSClassList classList;
00309   QStringList labels;
00310   QString label;
00311   const QSList *args;
00312   QSShared *sharedList;
00313 
00314   // exception
00315   QString exMsg;
00316   QSObject exVal;
00317   QSObject retVal;
00318 
00319   ExecutionMode execMode;
00320 
00321   int stackDep;
00322 
00323   uint shutDown : 1;
00324 };
00325 
00326 
00327 inline QSObject QSEnv::createNumber(double value) const
00328 {
00329   return QSNumber(this, value);
00330 }
00331 
00332 
00333 inline QSObject QSEnv::createBoolean(bool b) const
00334 {
00335   return QSBoolean(this, b);
00336 }
00337 
00338 inline QSObject QSEnv::createUndefined() const
00339 {
00340   return QSUndefined(this);
00341 }
00342 
00343 inline QSObject QSEnv::createString(const QString &s) const
00344 {
00345   return QSString(this, s);
00346 }
00347 
00348 inline QSObject QSEnv::createNull() const
00349 {
00350   return QSNull(this);
00351 }
00352 
00353 
00354 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'