# kjs Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# interpreter.cpp

    00001 // -*- c-basic-offset: 2 -*-
    00002 /*
    00003  *  This file is part of the KDE libraries
    00004  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
    00005  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    00006  *
    00007  *  This library is free software; you can redistribute it and/or
    00008  *  modify it under the terms of the GNU Lesser General Public
    00009  *  License as published by the Free Software Foundation; either
    00010  *  version 2 of the License, or (at your option) any later version.
    00011  *
    00012  *  This library is distributed in the hope that it will be useful,
    00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015  *  Lesser General Public License for more details.
    00016  *
    00017  *  You should have received a copy of the GNU Lesser General Public License
    00018  *  along with this library; see the file COPYING.LIB.  If not, write to
    00019  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020  *  Boston, MA 02111-1307, USA.
    00021  *
    00022  *  $Id: interpreter.cpp,v 1.12.2.2 2003/07/15 10:42:18 mueller Exp $
    00023  */
    00024
    00025 #include "value.h"
    00026 #include "object.h"
    00027 #include "types.h"
    00028 #include "interpreter.h"
    00029
    00030 #include <assert.h>
    00031 #include <math.h>
    00032 #include <stdio.h>
    00033
    00034 #include "internal.h"
    00035 #include "collector.h"
    00036 #include "operations.h"
    00037 #include "error_object.h"
    00038 #include "nodes.h"
    00039
    00040 using namespace KJS;
    00041
    00042 // ------------------------------ Context --------------------------------------
    00043
    00044 Context::Context(ContextImp *c)
    00045 {
    00046   rep = c;
    00047 }
    00048
    00049 Context::Context(const Context &c)
    00050 {
    00051   rep = c.rep;
    00052 }
    00053
    00054 Context& Context::operator=(const Context &c)
    00055 {
    00056   rep = c.rep;
    00057   return *this;
    00058 }
    00059
    00060 Context::~Context()
    00061 {
    00062 }
    00063
    00064 bool Context::isNull() const
    00065 {
    00066   return (rep == 0);
    00067 }
    00068
    00069 ContextImp *Context::imp() const
    00070 {
    00071   return rep;
    00072 }
    00073
    00074 const List Context::scopeChain() const
    00075 {
    00076   return rep->scopeChain();
    00077 }
    00078
    00079 Object Context::variableObject() const
    00080 {
    00081   return rep->variableObject();
    00082 }
    00083
    00084 Object Context::thisValue() const
    00085 {
    00086   return rep->thisValue();
    00087 }
    00088
    00089 const Context Context::callingContext() const
    00090 {
    00091   return rep->callingContext();
    00092 }
    00093
    00094 // ------------------------------ Interpreter ---------------------------------
    00095
    00096 Interpreter::Interpreter(const Object &global)
    00097 {
    00098   rep = new InterpreterImp(this,global);
    00099 }
    00100
    00101 Interpreter::Interpreter()
    00102 {
    00103   Object global(new ObjectImp());
    00104   rep = new InterpreterImp(this,global);
    00105 }
    00106
    00107 Interpreter::~Interpreter()
    00108 {
    00109   delete rep;
    00110 }
    00111
    00112 Object Interpreter::globalObject() const
    00113 {
    00114   return rep->globalObject();
    00115 }
    00116
    00117 void Interpreter::initGlobalObject()
    00118 {
    00119   rep->initGlobalObject();
    00120 }
    00121
    00122 ExecState *Interpreter::globalExec()
    00123 {
    00124   return rep->globalExec();
    00125 }
    00126
    00127 bool Interpreter::checkSyntax(const UString &code)
    00128 {
    00129   return rep->checkSyntax(code);
    00130 }
    00131
    00132 Completion Interpreter::evaluate(const UString &code, const Value &thisV)
    00133 {
    00134   return rep->evaluate(code,thisV);
    00135 }
    00136
    00137 InterpreterImp *Interpreter::imp()
    00138 {
    00139   return rep;
    00140 }
    00141
    00142 Object Interpreter::builtinObject() const
    00143 {
    00144   return rep->builtinObject();
    00145 }
    00146
    00147 Object Interpreter::builtinFunction() const
    00148 {
    00149   return rep->builtinFunction();
    00150 }
    00151
    00152 Object Interpreter::builtinArray() const
    00153 {
    00154   return rep->builtinArray();
    00155 }
    00156
    00157 Object Interpreter::builtinBoolean() const
    00158 {
    00159   return rep->builtinBoolean();
    00160 }
    00161
    00162 Object Interpreter::builtinString() const
    00163 {
    00164   return rep->builtinString();
    00165 }
    00166
    00167 Object Interpreter::builtinNumber() const
    00168 {
    00169   return rep->builtinNumber();
    00170 }
    00171
    00172 Object Interpreter::builtinDate() const
    00173 {
    00174   return rep->builtinDate();
    00175 }
    00176
    00177 Object Interpreter::builtinRegExp() const
    00178 {
    00179   return rep->builtinRegExp();
    00180 }
    00181
    00182 Object Interpreter::builtinError() const
    00183 {
    00184   return rep->builtinError();
    00185 }
    00186
    00187 Object Interpreter::builtinObjectPrototype() const
    00188 {
    00189   return rep->builtinObjectPrototype();
    00190 }
    00191
    00192 Object Interpreter::builtinFunctionPrototype() const
    00193 {
    00194   return rep->builtinFunctionPrototype();
    00195 }
    00196
    00197 Object Interpreter::builtinArrayPrototype() const
    00198 {
    00199   return rep->builtinArrayPrototype();
    00200 }
    00201
    00202 Object Interpreter::builtinBooleanPrototype() const
    00203 {
    00204   return rep->builtinBooleanPrototype();
    00205 }
    00206
    00207 Object Interpreter::builtinStringPrototype() const
    00208 {
    00209   return rep->builtinStringPrototype();
    00210 }
    00211
    00212 Object Interpreter::builtinNumberPrototype() const
    00213 {
    00214   return rep->builtinNumberPrototype();
    00215 }
    00216
    00217 Object Interpreter::builtinDatePrototype() const
    00218 {
    00219   return rep->builtinDatePrototype();
    00220 }
    00221
    00222 Object Interpreter::builtinRegExpPrototype() const
    00223 {
    00224   return rep->builtinRegExpPrototype();
    00225 }
    00226
    00227 Object Interpreter::builtinErrorPrototype() const
    00228 {
    00229   return rep->builtinErrorPrototype();
    00230 }
    00231
    00232 Object Interpreter::builtinEvalError() const
    00233 {
    00234   return rep->builtinEvalError();
    00235 }
    00236
    00237 Object Interpreter::builtinRangeError() const
    00238 {
    00239   return rep->builtinRangeError();
    00240 }
    00241
    00242 Object Interpreter::builtinReferenceError() const
    00243 {
    00244   return rep->builtinReferenceError();
    00245 }
    00246
    00247 Object Interpreter::builtinSyntaxError() const
    00248 {
    00249   return rep->builtinSyntaxError();
    00250 }
    00251
    00252 Object Interpreter::builtinTypeError() const
    00253 {
    00254   return rep->builtinTypeError();
    00255 }
    00256
    00257 Object Interpreter::builtinURIError() const
    00258 {
    00259   return rep->builtinURIError();
    00260 }
    00261
    00262 Object Interpreter::builtinEvalErrorPrototype() const
    00263 {
    00264   return rep->builtinEvalErrorPrototype();
    00265 }
    00266
    00267 Object Interpreter::builtinRangeErrorPrototype() const
    00268 {
    00269   return rep->builtinRangeErrorPrototype();
    00270 }
    00271
    00272 Object Interpreter::builtinReferenceErrorPrototype() const
    00273 {
    00274   return rep->builtinReferenceErrorPrototype();
    00275 }
    00276
    00277 Object Interpreter::builtinSyntaxErrorPrototype() const
    00278 {
    00279   return rep->builtinSyntaxErrorPrototype();
    00280 }
    00281
    00282 Object Interpreter::builtinTypeErrorPrototype() const
    00283 {
    00284   return rep->builtinTypeErrorPrototype();
    00285 }
    00286
    00287 Object Interpreter::builtinURIErrorPrototype() const
    00288 {
    00289   return rep->builtinURIErrorPrototype();
    00290 }
    00291
    00292 void Interpreter::setCompatMode(CompatMode mode)
    00293 {
    00294   rep->setCompatMode(mode);
    00295 }
    00296
    00297 Interpreter::CompatMode Interpreter::compatMode() const
    00298 {
    00299   return rep->compatMode();
    00300 }
    00301
    00302 bool Interpreter::collect()
    00303 {
    00304   return Collector::collect();
    00305 }
    00306
    00307 #ifdef KJS_DEBUG_MEM
    00308 #include "lexer.h"
    00309 void Interpreter::finalCheck()
    00310 {
    00311   fprintf(stderr,"Interpreter::finalCheck()\n");
    00312   // Garbage collect - as many times as necessary
    00313   // (we could delete an object which was holding another object, so
    00314   // the deref() will happen too late for deleting the impl of the 2nd object).
    00315   while( Collector::collect() )
    00316     ;
    00317
    00318   fprintf(stderr,"ListImp::count = %d\n", KJS::ListImp::count);
    00319   Node::finalCheck();
    00320   Collector::finalCheck();
    00321   Lexer::globalClear();
    00322   List::globalClear();
    00323   UString::globalClear();
    00324 }
    00325 #endif
    00326
    00327 // ------------------------------ ExecState --------------------------------------
    00328
    00329 namespace KJS {
    00330   class ExecStateImp
    00331   {
    00332   public:
    00333     ExecStateImp(Interpreter *interp, ContextImp *con)
    00334       : interpreter(interp), context(con) {};
    00335     Interpreter *interpreter;
    00336     ContextImp *context;
    00337     Value exception;
    00338   };
    00339 }
    00340
    00341 ExecState::~ExecState()
    00342 {
    00343   delete rep;
    00344 }
    00345
    00346 Interpreter *ExecState::interpreter() const
    00347 {
    00348   return rep->interpreter;
    00349 }
    00350
    00351 const Context ExecState::context() const
    00352 {
    00353   return rep->context;
    00354 }
    00355
    00356 void ExecState::setException(const Value &e)
    00357 {
    00358   rep->exception = e;
    00359 }
    00360
    00361 void ExecState::clearException()
    00362 {
    00363   terminate_request = false;
    00364   rep->exception = Value();
    00365 }
    00366
    00367 Value ExecState::exception() const
    00368 {
    00369   return rep->exception;
    00370 }
    00371
    00372 bool ExecState::terminate_request = false;
    00373
    00374 bool ExecState::hadException() const
    00375 {
    00376   if (terminate_request)
    00377       rep->exception = Error::create((ExecState*)this);
    00378   return rep->exception.isValid();
    00379 }
    00380
    00381 ExecState::ExecState(Interpreter *interp, ContextImp *con)
    00382 {
    00383   rep = new ExecStateImp(interp,con);
    00384 }
    00385
    00386 void Interpreter::virtual_hook( int, void* )
    00387 { /*BASE::virtual_hook( id, data );*/ }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:08:27 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001