interpreter.h
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.h,v 1.11.2.2 2003/05/17 11:19:24 mueller Exp $ 00023 */ 00024 00025 #ifndef _KJS_INTERPRETER_H_ 00026 #define _KJS_INTERPRETER_H_ 00027 00028 #include "value.h" 00029 #include "object.h" 00030 #include "types.h" 00031 00032 namespace KJS { 00033 00034 class ContextImp; 00035 class ExecStateImp; 00036 class InterpreterImp; 00037 00056 class Context { 00057 public: 00058 Context(ContextImp *); 00059 Context(const Context &c); 00060 Context& operator=(const Context &c); 00061 virtual ~Context(); 00062 00063 bool isNull() const; 00064 ContextImp *imp() const; 00065 00073 const List scopeChain() const; 00074 00081 Object variableObject() const; 00082 00098 Object thisValue() const; 00099 00108 const Context callingContext() const; 00109 private: 00110 ContextImp *rep; 00111 }; 00112 00119 class Interpreter { 00120 public: 00137 Interpreter(const Object &global); 00142 Interpreter(); 00143 virtual ~Interpreter(); 00144 00149 Object globalObject() const; 00150 00151 void initGlobalObject(); 00152 00164 ExecState *globalExec(); 00165 00172 bool checkSyntax(const UString &code); 00173 00189 Completion evaluate(const UString &code, const Value &thisV = Value()); 00190 00197 InterpreterImp *imp(); 00198 00207 Object builtinObject() const; 00208 00212 Object builtinFunction() const; 00213 00217 Object builtinArray() const; 00218 00219 00223 Object builtinBoolean() const; 00224 00228 Object builtinString() const; 00229 00233 Object builtinNumber() const; 00234 00238 Object builtinDate() const; 00239 00243 Object builtinRegExp() const; 00244 00248 Object builtinError() const; 00249 00253 Object builtinObjectPrototype() const; 00254 00258 Object builtinFunctionPrototype() const; 00259 00263 Object builtinArrayPrototype() const; 00264 00268 Object builtinBooleanPrototype() const; 00269 00273 Object builtinStringPrototype() const; 00274 00278 Object builtinNumberPrototype() const; 00279 00283 Object builtinDatePrototype() const; 00284 00288 Object builtinRegExpPrototype() const; 00289 00293 Object builtinErrorPrototype() const; 00294 00298 Object builtinEvalError() const; 00299 Object builtinRangeError() const; 00300 Object builtinReferenceError() const; 00301 Object builtinSyntaxError() const; 00302 Object builtinTypeError() const; 00303 Object builtinURIError() const; 00304 00305 Object builtinEvalErrorPrototype() const; 00306 Object builtinRangeErrorPrototype() const; 00307 Object builtinReferenceErrorPrototype() const; 00308 Object builtinSyntaxErrorPrototype() const; 00309 Object builtinTypeErrorPrototype() const; 00310 Object builtinURIErrorPrototype() const; 00311 00312 enum CompatMode { NativeMode, IECompat, NetscapeCompat }; 00319 void setCompatMode(CompatMode mode); 00320 CompatMode compatMode() const; 00321 00326 static bool collect(); 00327 00332 virtual void mark() {} 00333 00340 virtual int rtti() { return 0; } 00341 00342 #ifdef KJS_DEBUG_MEM 00343 00346 static void finalCheck(); 00347 #endif 00348 private: 00349 InterpreterImp *rep; 00350 00356 Interpreter(const Interpreter&); 00357 00363 Interpreter operator=(const Interpreter&); 00364 protected: 00365 virtual void virtual_hook( int id, void* data ); 00366 }; 00367 00373 class ExecState { 00374 friend class InterpreterImp; 00375 friend class FunctionImp; 00376 friend class GlobalFuncImp; 00377 public: 00378 virtual ~ExecState(); 00379 00385 Interpreter *interpreter() const; 00386 00392 const Context context() const; 00393 00394 void setException(const Value &e); 00395 void clearException(); 00396 Value exception() const; 00397 bool hadException() const; 00398 00399 /* 00400 * request for ending execution with an exception 00401 */ 00402 static void requestTerminate() { terminate_request = true; } 00403 private: 00404 ExecState(Interpreter *interp, ContextImp *con); 00405 ExecStateImp *rep; 00406 static bool terminate_request; 00407 }; 00408 00409 } // namespace 00410 00411 #endif // _KJS_INTERPRETER_H_