Changeset 10352 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Aug 26, 2005, 4:42:16 PM (20 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/function.cpp
r10207 r10352 32 32 #include "debugger.h" 33 33 #include "context.h" 34 #include "shared_ptr.h" 34 35 35 36 #include <stdio.h> … … 42 43 #include <unicode/uchar.h> 43 44 #endif 45 46 using namespace kxmlcore; 44 47 45 48 namespace KJS { … … 304 307 : FunctionImp(exec,n), body(b) 305 308 { 306 body->ref();307 309 setScope(sc); 308 }309 310 DeclaredFunctionImp::~DeclaredFunctionImp()311 {312 if ( body->deref() )313 delete body;314 310 } 315 311 … … 794 790 int errLine; 795 791 UString errMsg; 796 ProgramNode *progNode = Parser::parse(UString(), 0, s.data(),s.size(),&sid,&errLine,&errMsg);792 SharedPtr<ProgramNode> progNode(Parser::parse(UString(), 0, s.data(),s.size(),&sid,&errLine,&errMsg)); 797 793 798 794 Debugger *dbg = exec->dynamicInterpreter()->imp()->debugger(); … … 804 800 805 801 // no program node means a syntax occurred 806 if (!progNode) 802 if (!progNode) { 807 803 return throwError(exec, SyntaxError, errMsg, errLine, sid, NULL); 808 809 progNode->ref(); 810 804 } 805 811 806 // enter a new execution context 812 807 ObjectImp *thisVal = static_cast<ObjectImp *>(exec->context().thisValue()); … … 833 828 else if (c.isValueCompletion()) 834 829 res = c.value(); 835 836 if ( progNode->deref() )837 delete progNode;838 830 } 839 831 break; -
trunk/JavaScriptCore/kjs/function.h
r10148 r10352 77 77 DeclaredFunctionImp(ExecState *exec, const Identifier &n, 78 78 FunctionBodyNode *b, const ScopeChain &sc); 79 ~DeclaredFunctionImp();80 79 81 80 bool implementsConstruct() const; … … 84 83 virtual Completion execute(ExecState *exec); 85 84 CodeType codeType() const { return FunctionCode; } 86 FunctionBodyNode *body;85 kxmlcore::SharedPtr<FunctionBodyNode> body; 87 86 88 87 virtual const ClassInfo *classInfo() const { return &info; } -
trunk/JavaScriptCore/kjs/function_object.cpp
r10207 r10352 35 35 36 36 using namespace KJS; 37 using namespace kxmlcore; 37 38 38 39 // ------------------------------ FunctionPrototypeImp ------------------------- … … 198 199 int errLine; 199 200 UString errMsg; 200 ProgramNode *progNode = Parser::parse(sourceURL, lineNumber, body.data(),body.size(),&sid,&errLine,&errMsg);201 SharedPtr<ProgramNode> progNode = Parser::parse(sourceURL, lineNumber, body.data(),body.size(),&sid,&errLine,&errMsg); 201 202 202 203 // notify debugger that source has been parsed … … 219 220 ScopeChain scopeChain; 220 221 scopeChain.push(exec->dynamicInterpreter()->globalObject()); 221 FunctionBodyNode *bodyNode = progNode ;222 FunctionBodyNode *bodyNode = progNode.get(); 222 223 223 224 FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), bodyNode, -
trunk/JavaScriptCore/kjs/grammar.y
r10148 r10352 693 693 Program: 694 694 /* nothing, empty script */ { $$ = new ProgramNode(0); 695 Parser:: progNode = $$; }695 Parser::accept($$); } 696 696 | SourceElements { $$ = new ProgramNode($1); 697 Parser:: progNode = $$; }697 Parser::accept($$); } 698 698 ; 699 699 -
trunk/JavaScriptCore/kjs/internal.cpp
r10207 r10352 53 53 54 54 extern int kjsyyparse(); 55 56 using namespace kxmlcore; 55 57 56 58 namespace KJS { … … 346 348 // ------------------------------ Parser --------------------------------------- 347 349 348 ProgramNode *Parser::progNode = 0;350 static SharedPtr<ProgramNode> *progNode; 349 351 int Parser::sid = 0; 350 352 351 ProgramNode *Parser::parse(const UString &sourceURL, int startingLineNumber,352 const UChar *code, unsigned int length, int *sourceId,353 353 SharedPtr<ProgramNode> Parser::parse(const UString &sourceURL, int startingLineNumber, 354 const UChar *code, unsigned int length, int *sourceId, 355 int *errLine, UString *errMsg) 354 356 { 355 357 if (errLine) … … 357 359 if (errMsg) 358 360 *errMsg = 0; 359 361 if (!progNode) 362 progNode = new SharedPtr<ProgramNode>; 363 360 364 Lexer::curr()->setCode(sourceURL, startingLineNumber, code, length); 361 progNode = 0;365 *progNode = 0; 362 366 sid++; 363 367 if (sourceId) … … 369 373 bool lexError = Lexer::curr()->sawError(); 370 374 Lexer::curr()->doneParsing(); 371 ProgramNode *prog =progNode;372 progNode = 0;375 SharedPtr<ProgramNode> prog = *progNode; 376 *progNode = 0; 373 377 374 378 if (parseError || lexError) { … … 378 382 if (errMsg) 379 383 *errMsg = "Parse error"; 380 if (prog) { 381 // must ref and deref to clean up properly 382 prog->ref(); 383 prog->deref(); 384 delete prog; 385 } 386 return 0; 384 return SharedPtr<ProgramNode>(); 387 385 } 388 386 389 387 return prog; 390 388 } 389 390 void Parser::accept(ProgramNode *prog) 391 { 392 *progNode = prog; 393 } 394 391 395 392 396 // ------------------------------ InterpreterImp ------------------------------- … … 612 616 { 613 617 // Parser::parse() returns 0 in a syntax error occurs, so we just check for that 614 ProgramNode *progNode = Parser::parse(UString(), 0, code.data(),code.size(),0,0,0); 615 bool ok = (progNode != 0); 616 if (progNode) { 617 // must ref and deref to clean up properly 618 progNode->ref(); 619 progNode->deref(); 620 delete progNode; 621 } 622 return ok; 618 SharedPtr<ProgramNode> progNode = Parser::parse(UString(), 0, code.data(),code.size(),0,0,0); 619 return progNode; 623 620 } 624 621 … … 643 640 int errLine; 644 641 UString errMsg; 645 ProgramNode *progNode = Parser::parse(sourceURL, startingLineNumber, code.data(),code.size(),&sid,&errLine,&errMsg);642 SharedPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code.data(),code.size(),&sid,&errLine,&errMsg); 646 643 647 644 // notify debugger that source has been parsed … … 671 668 672 669 recursion++; 673 progNode->ref();674 670 675 671 ObjectImp *globalObj = globalObject(); … … 699 695 } 700 696 701 if (progNode->deref())702 delete progNode;703 697 recursion--; 704 698 -
trunk/JavaScriptCore/kjs/internal.h
r10182 r10352 33 33 #include "interpreter.h" 34 34 #include "scope_chain.h" 35 #include "shared_ptr.h" 35 36 36 37 #define I18N_NOOP(s) s … … 195 196 class Parser { 196 197 public: 197 static ProgramNode *parse(const UString &sourceURL, int startingLineNumber,198 const UChar *code, unsigned int length, int *sourceId = 0,199 200 201 static ProgramNode *progNode; 198 static kxmlcore::SharedPtr<ProgramNode> parse(const UString &sourceURL, int startingLineNumber, 199 const UChar *code, unsigned int length, int *sourceId = 0, 200 int *errLine = 0, UString *errMsg = 0); 201 static void accept(ProgramNode *prog); 202 202 203 static int sid; 203 204 }; -
trunk/JavaScriptCore/kjs/nodes.cpp
r10258 r10352 99 99 line = Lexer::curr()->lineNo(); 100 100 sourceURL = Lexer::curr()->sourceURL(); 101 refcount = 0; 102 #ifdef KJS_DEBUG_MEM 103 if (!s_nodes) 104 s_nodes = new std::list<Node *>; 105 s_nodes->push_back(this); 106 #endif 101 m_refcount = 0; 107 102 } 108 103 109 104 Node::~Node() 110 105 { 111 #ifdef KJS_DEBUG_MEM112 s_nodes->remove( this );113 #endif114 106 } 115 107 … … 337 329 // ------------------------------ GroupNode ------------------------------------ 338 330 339 void GroupNode::ref()340 {341 Node::ref();342 if ( group )343 group->ref();344 }345 346 bool GroupNode::deref()347 {348 if ( group && group->deref() )349 delete group;350 return Node::deref();351 }352 353 331 // ECMA 11.1.6 354 332 ValueImp *GroupNode::evaluate(ExecState *exec) … … 364 342 // ------------------------------ ElementNode ---------------------------------- 365 343 366 void ElementNode::ref()367 {368 for (ElementNode *n = this; n; n = n->list) {369 n->Node::ref();370 if (n->node)371 n->node->ref();372 }373 }374 375 bool ElementNode::deref()376 {377 ElementNode *next;378 for (ElementNode *n = this; n; n = next) {379 next = n->list;380 if (n->node && n->node->deref())381 delete n->node;382 if (n != this && n->Node::deref())383 delete n;384 }385 return Node::deref();386 }387 388 344 // ECMA 11.1.4 389 345 ValueImp *ElementNode::evaluate(ExecState *exec) … … 391 347 ObjectImp *array = exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty()); 392 348 int length = 0; 393 for (ElementNode *n = this; n; n = n->list ) {349 for (ElementNode *n = this; n; n = n->list.get()) { 394 350 ValueImp *val = n->node->evaluate(exec); 395 351 KJS_CHECKEXCEPTIONVALUE … … 401 357 402 358 // ------------------------------ ArrayNode ------------------------------------ 403 404 void ArrayNode::ref()405 {406 Node::ref();407 if ( element )408 element->ref();409 }410 411 bool ArrayNode::deref()412 {413 if ( element && element->deref() )414 delete element;415 return Node::deref();416 }417 359 418 360 // ECMA 11.1.4 … … 440 382 // ------------------------------ ObjectLiteralNode ---------------------------- 441 383 442 void ObjectLiteralNode::ref()443 {444 Node::ref();445 if ( list )446 list->ref();447 }448 449 bool ObjectLiteralNode::deref()450 {451 if ( list && list->deref() )452 delete list;453 return Node::deref();454 }455 456 384 // ECMA 11.1.5 457 385 ValueImp *ObjectLiteralNode::evaluate(ExecState *exec) … … 465 393 // ------------------------------ PropertyValueNode ---------------------------- 466 394 467 void PropertyValueNode::ref()468 {469 for (PropertyValueNode *n = this; n; n = n->list) {470 n->Node::ref();471 if (n->name)472 n->name->ref();473 if (n->assign)474 n->assign->ref();475 }476 }477 478 bool PropertyValueNode::deref()479 {480 PropertyValueNode *next;481 for (PropertyValueNode *n = this; n; n = next) {482 next = n->list;483 if ( n->name && n->name->deref() )484 delete n->name;485 if ( n->assign && n->assign->deref() )486 delete n->assign;487 if (n != this && n->Node::deref() )488 delete n;489 }490 return Node::deref();491 }492 493 395 // ECMA 11.1.5 494 396 ValueImp *PropertyValueNode::evaluate(ExecState *exec) … … 496 398 ObjectImp *obj = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); 497 399 498 for (PropertyValueNode *p = this; p; p = p->list ) {400 for (PropertyValueNode *p = this; p; p = p->list.get()) { 499 401 ValueImp *n = p->name->evaluate(exec); 500 402 KJS_CHECKEXCEPTIONVALUE … … 525 427 526 428 // ------------------------------ BracketAccessorNode -------------------------------- 527 528 void BracketAccessorNode::ref()529 {530 Node::ref();531 if ( expr1 )532 expr1->ref();533 if ( expr2 )534 expr2->ref();535 }536 537 bool BracketAccessorNode::deref()538 {539 if ( expr1 && expr1->deref() )540 delete expr1;541 if ( expr2 && expr2->deref() )542 delete expr2;543 return Node::deref();544 }545 429 546 430 // ECMA 11.2.1a … … 573 457 // ------------------------------ DotAccessorNode -------------------------------- 574 458 575 void DotAccessorNode::ref()576 {577 Node::ref();578 if ( expr )579 expr->ref();580 }581 582 bool DotAccessorNode::deref()583 {584 if ( expr && expr->deref() )585 delete expr;586 return Node::deref();587 }588 589 459 // ECMA 11.2.1b 590 460 ValueImp *DotAccessorNode::evaluate(ExecState *exec) … … 606 476 // ------------------------------ ArgumentListNode ----------------------------- 607 477 608 void ArgumentListNode::ref()609 {610 for (ArgumentListNode *n = this; n; n = n->list) {611 n->Node::ref();612 if (n->expr)613 n->expr->ref();614 }615 }616 617 bool ArgumentListNode::deref()618 {619 ArgumentListNode *next;620 for (ArgumentListNode *n = this; n; n = next) {621 next = n->list;622 if (n->expr && n->expr->deref())623 delete n->expr;624 if (n != this && n->Node::deref())625 delete n;626 }627 return Node::deref();628 }629 630 478 ValueImp *ArgumentListNode::evaluate(ExecState */*exec*/) 631 479 { … … 639 487 List l; 640 488 641 for (ArgumentListNode *n = this; n; n = n->list ) {489 for (ArgumentListNode *n = this; n; n = n->list.get()) { 642 490 ValueImp *v = n->expr->evaluate(exec); 643 491 KJS_CHECKEXCEPTIONLIST … … 650 498 // ------------------------------ ArgumentsNode -------------------------------- 651 499 652 void ArgumentsNode::ref()653 {654 Node::ref();655 if ( list )656 list->ref();657 }658 659 bool ArgumentsNode::deref()660 {661 if ( list && list->deref() )662 delete list;663 return Node::deref();664 }665 666 500 ValueImp *ArgumentsNode::evaluate(ExecState */*exec*/) 667 501 { … … 682 516 683 517 // ECMA 11.2.2 684 685 void NewExprNode::ref()686 {687 Node::ref();688 if ( expr )689 expr->ref();690 if ( args )691 args->ref();692 }693 694 bool NewExprNode::deref()695 {696 if ( expr && expr->deref() )697 delete expr;698 if ( args && args->deref() )699 delete args;700 return Node::deref();701 }702 518 703 519 ValueImp *NewExprNode::evaluate(ExecState *exec) … … 713 529 714 530 if (!v->isObject()) { 715 return throwError(exec, TypeError, "Value %s (result of expression %s) is not an object. Cannot be used with new.", v, expr );531 return throwError(exec, TypeError, "Value %s (result of expression %s) is not an object. Cannot be used with new.", v, expr.get()); 716 532 } 717 533 718 534 ObjectImp *constr = static_cast<ObjectImp*>(v); 719 535 if (!constr->implementsConstruct()) { 720 return throwError(exec, TypeError, "Value %s (result of expression %s) is not a constructor. Cannot be used with new.", v, expr );536 return throwError(exec, TypeError, "Value %s (result of expression %s) is not a constructor. Cannot be used with new.", v, expr.get()); 721 537 } 722 538 723 539 return constr->construct(exec, argList); 724 }725 726 void FunctionCallValueNode::ref()727 {728 Node::ref();729 if (expr)730 expr->ref();731 if (args)732 args->ref();733 }734 735 bool FunctionCallValueNode::deref()736 {737 if (expr && expr->deref())738 delete expr;739 if (args && args->deref())740 delete args;741 return Node::deref();742 540 } 743 541 … … 749 547 750 548 if (!v->isObject()) { 751 return throwError(exec, TypeError, "Value %s (result of expression %s) is not object.", v, expr );549 return throwError(exec, TypeError, "Value %s (result of expression %s) is not object.", v, expr.get()); 752 550 } 753 551 … … 755 553 756 554 if (!func->implementsCall()) { 757 return throwError(exec, TypeError, "Object %s (result of expression %s) does not allow calls.", v, expr );555 return throwError(exec, TypeError, "Object %s (result of expression %s) does not allow calls.", v, expr.get()); 758 556 } 759 557 … … 764 562 765 563 return func->call(exec, thisObj, argList); 766 }767 768 769 void FunctionCallResolveNode::ref()770 {771 Node::ref();772 if (args)773 args->ref();774 }775 776 bool FunctionCallResolveNode::deref()777 {778 if (args && args->deref())779 delete args;780 return Node::deref();781 564 } 782 565 … … 830 613 } 831 614 832 void FunctionCallBracketNode::ref()833 {834 Node::ref();835 if (base)836 base->ref();837 if (subscript)838 base->ref();839 if (args)840 args->ref();841 }842 843 bool FunctionCallBracketNode::deref()844 {845 if (base && base->deref())846 delete base;847 if (subscript && subscript->deref())848 delete subscript;849 if (args && args->deref())850 delete args;851 return Node::deref();852 }853 854 615 // ECMA 11.2.3 855 616 ValueImp *FunctionCallBracketNode::evaluate(ExecState *exec) … … 881 642 882 643 if (!funcVal->isObject()) { 883 return throwError(exec, TypeError, "Value %s (result of expression %s[%s]) is not object.", funcVal, base , subscript);644 return throwError(exec, TypeError, "Value %s (result of expression %s[%s]) is not object.", funcVal, base.get(), subscript.get()); 884 645 } 885 646 … … 887 648 888 649 if (!func->implementsCall()) { 889 return throwError(exec, TypeError, "Object %s (result of expression %s[%s]) does not allow calls.", funcVal, base , subscript);650 return throwError(exec, TypeError, "Object %s (result of expression %s[%s]) does not allow calls.", funcVal, base.get(), subscript.get()); 890 651 } 891 652 … … 901 662 } 902 663 903 904 void FunctionCallDotNode::ref()905 {906 Node::ref();907 if (base)908 base->ref();909 if (args)910 args->ref();911 }912 913 bool FunctionCallDotNode::deref()914 {915 if (base && base->deref())916 delete base;917 if (args && args->deref())918 delete args;919 return Node::deref();920 }921 922 664 static const char *dotExprNotAnObjectString() 923 665 { … … 941 683 942 684 if (!funcVal->isObject()) 943 return throwError(exec, TypeError, dotExprNotAnObjectString(), funcVal, base , ident);685 return throwError(exec, TypeError, dotExprNotAnObjectString(), funcVal, base.get(), ident); 944 686 945 687 ObjectImp *func = static_cast<ObjectImp*>(funcVal); 946 688 947 689 if (!func->implementsCall()) 948 return throwError(exec, TypeError, dotExprDoesNotAllowCallsString(), funcVal, base , ident);690 return throwError(exec, TypeError, dotExprDoesNotAllowCallsString(), funcVal, base.get(), ident); 949 691 950 692 List argList = args->evaluateList(exec); … … 961 703 // ------------------------------ PostfixNode ---------------------------------- 962 704 963 void PostfixNode::ref()964 {965 Node::ref();966 if ( expr )967 expr->ref();968 }969 970 bool PostfixNode::deref()971 {972 if ( expr && expr->deref() )973 delete expr;974 return Node::deref();975 }976 977 705 // ECMA 11.3 978 706 ValueImp *PostfixNode::evaluate(ExecState *exec) … … 993 721 // ------------------------------ DeleteNode ----------------------------------- 994 722 995 void DeleteNode::ref()996 {997 Node::ref();998 if ( expr )999 expr->ref();1000 }1001 1002 bool DeleteNode::deref()1003 {1004 if ( expr && expr->deref() )1005 delete expr;1006 return Node::deref();1007 }1008 1009 723 // ECMA 11.4.1 1010 724 ValueImp *DeleteNode::evaluate(ExecState *exec) … … 1017 731 // ------------------------------ VoidNode ------------------------------------- 1018 732 1019 void VoidNode::ref()1020 {1021 Node::ref();1022 if ( expr )1023 expr->ref();1024 }1025 1026 bool VoidNode::deref()1027 {1028 if ( expr && expr->deref() )1029 delete expr;1030 return Node::deref();1031 }1032 1033 733 // ECMA 11.4.2 1034 734 ValueImp *VoidNode::evaluate(ExecState *exec) … … 1041 741 1042 742 // ------------------------------ TypeOfNode ----------------------------------- 1043 1044 void TypeOfNode::ref()1045 {1046 Node::ref();1047 if ( expr )1048 expr->ref();1049 }1050 1051 bool TypeOfNode::deref()1052 {1053 if ( expr && expr->deref() )1054 delete expr;1055 return Node::deref();1056 }1057 743 1058 744 // ECMA 11.4.3 … … 1096 782 // ------------------------------ PrefixNode ----------------------------------- 1097 783 1098 void PrefixNode::ref()1099 {1100 Node::ref();1101 if ( expr )1102 expr->ref();1103 }1104 1105 bool PrefixNode::deref()1106 {1107 if ( expr && expr->deref() )1108 delete expr;1109 return Node::deref();1110 }1111 1112 784 // ECMA 11.4.4 and 11.4.5 1113 785 ValueImp *PrefixNode::evaluate(ExecState *exec) … … 1130 802 // ------------------------------ UnaryPlusNode -------------------------------- 1131 803 1132 void UnaryPlusNode::ref()1133 {1134 Node::ref();1135 if ( expr )1136 expr->ref();1137 }1138 1139 bool UnaryPlusNode::deref()1140 {1141 if ( expr && expr->deref() )1142 delete expr;1143 return Node::deref();1144 }1145 1146 804 // ECMA 11.4.6 1147 805 ValueImp *UnaryPlusNode::evaluate(ExecState *exec) … … 1154 812 1155 813 // ------------------------------ NegateNode ----------------------------------- 1156 1157 void NegateNode::ref()1158 {1159 Node::ref();1160 if ( expr )1161 expr->ref();1162 }1163 1164 bool NegateNode::deref()1165 {1166 if ( expr && expr->deref() )1167 delete expr;1168 return Node::deref();1169 }1170 814 1171 815 // ECMA 11.4.7 … … 1182 826 // ------------------------------ BitwiseNotNode ------------------------------- 1183 827 1184 void BitwiseNotNode::ref()1185 {1186 Node::ref();1187 if ( expr )1188 expr->ref();1189 }1190 1191 bool BitwiseNotNode::deref()1192 {1193 if ( expr && expr->deref() )1194 delete expr;1195 return Node::deref();1196 }1197 1198 828 // ECMA 11.4.8 1199 829 ValueImp *BitwiseNotNode::evaluate(ExecState *exec) … … 1206 836 // ------------------------------ LogicalNotNode ------------------------------- 1207 837 1208 void LogicalNotNode::ref()1209 {1210 Node::ref();1211 if ( expr )1212 expr->ref();1213 }1214 1215 bool LogicalNotNode::deref()1216 {1217 if ( expr && expr->deref() )1218 delete expr;1219 return Node::deref();1220 }1221 1222 838 // ECMA 11.4.9 1223 839 ValueImp *LogicalNotNode::evaluate(ExecState *exec) … … 1230 846 // ------------------------------ MultNode ------------------------------------- 1231 847 1232 void MultNode::ref()1233 {1234 Node::ref();1235 if ( term1 )1236 term1->ref();1237 if ( term2 )1238 term2->ref();1239 }1240 1241 bool MultNode::deref()1242 {1243 if ( term1 && term1->deref() )1244 delete term1;1245 if ( term2 && term2->deref() )1246 delete term2;1247 return Node::deref();1248 }1249 1250 848 // ECMA 11.5 1251 849 ValueImp *MultNode::evaluate(ExecState *exec) … … 1262 860 // ------------------------------ AddNode -------------------------------------- 1263 861 1264 void AddNode::ref()1265 {1266 Node::ref();1267 if ( term1 )1268 term1->ref();1269 if ( term2 )1270 term2->ref();1271 }1272 1273 bool AddNode::deref()1274 {1275 if ( term1 && term1->deref() )1276 delete term1;1277 if ( term2 && term2->deref() )1278 delete term2;1279 return Node::deref();1280 }1281 1282 862 // ECMA 11.6 1283 863 ValueImp *AddNode::evaluate(ExecState *exec) … … 1293 873 1294 874 // ------------------------------ ShiftNode ------------------------------------ 1295 1296 void ShiftNode::ref()1297 {1298 Node::ref();1299 if ( term1 )1300 term1->ref();1301 if ( term2 )1302 term2->ref();1303 }1304 1305 bool ShiftNode::deref()1306 {1307 if ( term1 && term1->deref() )1308 delete term1;1309 if ( term2 && term2->deref() )1310 delete term2;1311 return Node::deref();1312 }1313 875 1314 876 // ECMA 11.7 … … 1336 898 1337 899 // ------------------------------ RelationalNode ------------------------------- 1338 1339 void RelationalNode::ref()1340 {1341 Node::ref();1342 if ( expr1 )1343 expr1->ref();1344 if ( expr2 )1345 expr2->ref();1346 }1347 1348 bool RelationalNode::deref()1349 {1350 if ( expr1 && expr1->deref() )1351 delete expr1;1352 if ( expr2 && expr2->deref() )1353 delete expr2;1354 return Node::deref();1355 }1356 900 1357 901 // ECMA 11.8 … … 1380 924 if (!v2->isObject()) 1381 925 return throwError(exec, TypeError, 1382 "Value %s (result of expression %s) is not an object. Cannot be used with IN expression.", v2, expr2 );926 "Value %s (result of expression %s) is not an object. Cannot be used with IN expression.", v2, expr2.get()); 1383 927 ObjectImp *o2(static_cast<ObjectImp*>(v2)); 1384 928 b = o2->hasProperty(exec, Identifier(v1->toString(exec))); … … 1386 930 if (!v2->isObject()) 1387 931 return throwError(exec, TypeError, 1388 "Value %s (result of expression %s) is not an object. Cannot be used with instanceof operator.", v2, expr2 );932 "Value %s (result of expression %s) is not an object. Cannot be used with instanceof operator.", v2, expr2.get()); 1389 933 1390 934 ObjectImp *o2(static_cast<ObjectImp*>(v2)); … … 1406 950 // ------------------------------ EqualNode ------------------------------------ 1407 951 1408 void EqualNode::ref()1409 {1410 Node::ref();1411 if ( expr1 )1412 expr1->ref();1413 if ( expr2 )1414 expr2->ref();1415 }1416 1417 bool EqualNode::deref()1418 {1419 if ( expr1 && expr1->deref() )1420 delete expr1;1421 if ( expr2 && expr2->deref() )1422 delete expr2;1423 return Node::deref();1424 }1425 1426 952 // ECMA 11.9 1427 953 ValueImp *EqualNode::evaluate(ExecState *exec) … … 1447 973 // ------------------------------ BitOperNode ---------------------------------- 1448 974 1449 void BitOperNode::ref()1450 {1451 Node::ref();1452 if ( expr1 )1453 expr1->ref();1454 if ( expr2 )1455 expr2->ref();1456 }1457 1458 bool BitOperNode::deref()1459 {1460 if ( expr1 && expr1->deref() )1461 delete expr1;1462 if ( expr2 && expr2->deref() )1463 delete expr2;1464 return Node::deref();1465 }1466 1467 975 // ECMA 11.10 1468 976 ValueImp *BitOperNode::evaluate(ExecState *exec) … … 1487 995 // ------------------------------ BinaryLogicalNode ---------------------------- 1488 996 1489 void BinaryLogicalNode::ref()1490 {1491 Node::ref();1492 if ( expr1 )1493 expr1->ref();1494 if ( expr2 )1495 expr2->ref();1496 }1497 1498 bool BinaryLogicalNode::deref()1499 {1500 if ( expr1 && expr1->deref() )1501 delete expr1;1502 if ( expr2 && expr2->deref() )1503 delete expr2;1504 return Node::deref();1505 }1506 1507 997 // ECMA 11.11 1508 998 ValueImp *BinaryLogicalNode::evaluate(ExecState *exec) … … 1521 1011 1522 1012 // ------------------------------ ConditionalNode ------------------------------ 1523 1524 void ConditionalNode::ref()1525 {1526 Node::ref();1527 if ( expr1 )1528 expr1->ref();1529 if ( expr2 )1530 expr2->ref();1531 if ( logical )1532 logical->ref();1533 }1534 1535 bool ConditionalNode::deref()1536 {1537 if ( expr1 && expr1->deref() )1538 delete expr1;1539 if ( expr2 && expr2->deref() )1540 delete expr2;1541 if ( logical && logical->deref() )1542 delete logical;1543 return Node::deref();1544 }1545 1013 1546 1014 // ECMA 11.12 … … 1632 1100 // ------------------------------ AssignResolveNode ----------------------------------- 1633 1101 1634 void AssignResolveNode::ref()1635 {1636 Node::ref();1637 if (m_right)1638 m_right->ref();1639 }1640 1641 bool AssignResolveNode::deref()1642 {1643 if (m_right && m_right->deref())1644 delete m_right;1645 1646 return Node::deref();1647 }1648 1649 1102 ValueImp *AssignResolveNode::evaluate(ExecState *exec) 1650 1103 { … … 1688 1141 1689 1142 // ------------------------------ AssignDotNode ----------------------------------- 1690 1691 void AssignDotNode::ref()1692 {1693 Node::ref();1694 if (m_base)1695 m_base->ref();1696 if (m_right)1697 m_right->ref();1698 }1699 1700 bool AssignDotNode::deref()1701 {1702 if (m_base && m_base->deref())1703 delete m_base;1704 if (m_right && m_right->deref())1705 delete m_right;1706 return Node::deref();1707 }1708 1143 1709 1144 ValueImp *AssignDotNode::evaluate(ExecState *exec) … … 1732 1167 1733 1168 // ------------------------------ AssignBracketNode ----------------------------------- 1734 1735 void AssignBracketNode::ref()1736 {1737 Node::ref();1738 if (m_base)1739 m_base->ref();1740 if (m_subscript)1741 m_subscript->ref();1742 if (m_right)1743 m_right->ref();1744 }1745 1746 bool AssignBracketNode::deref()1747 {1748 if (m_base && m_base->deref())1749 delete m_base;1750 if (m_subscript && m_subscript->deref())1751 delete m_subscript;1752 if (m_right && m_right->deref())1753 delete m_right;1754 1755 return Node::deref();1756 }1757 1169 1758 1170 ValueImp *AssignBracketNode::evaluate(ExecState *exec) … … 1805 1217 // ------------------------------ CommaNode ------------------------------------ 1806 1218 1807 void CommaNode::ref()1808 {1809 Node::ref();1810 if ( expr1 )1811 expr1->ref();1812 if ( expr2 )1813 expr2->ref();1814 }1815 1816 bool CommaNode::deref()1817 {1818 if ( expr1 && expr1->deref() )1819 delete expr1;1820 if ( expr2 && expr2->deref() )1821 delete expr2;1822 return Node::deref();1823 }1824 1825 1219 // ECMA 11.14 1826 1220 ValueImp *CommaNode::evaluate(ExecState *exec) … … 1847 1241 l->list = this; 1848 1242 setLoc(l->firstLine(), s->lastLine(), l->sourceId()); 1849 }1850 1851 void StatListNode::ref()1852 {1853 for (StatListNode *n = this; n; n = n->list) {1854 n->Node::ref();1855 if (n->statement)1856 n->statement->ref();1857 }1858 }1859 1860 bool StatListNode::deref()1861 {1862 StatListNode *next;1863 for (StatListNode *n = this; n; n = next) {1864 next = n->list;1865 if (n->statement && n->statement->deref())1866 delete n->statement;1867 if (n != this && n->Node::deref())1868 delete n;1869 }1870 return Node::deref();1871 1243 } 1872 1244 … … 1887 1259 ValueImp *v = c.value(); 1888 1260 1889 for (StatListNode *n = list ; n; n = n->list) {1261 for (StatListNode *n = list.get(); n; n = n->list.get()) { 1890 1262 Completion c2 = n->statement->execute(exec); 1891 1263 KJS_ABORTPOINT … … 1909 1281 void StatListNode::processVarDecls(ExecState *exec) 1910 1282 { 1911 for (StatListNode *n = this; n; n = n->list )1283 for (StatListNode *n = this; n; n = n->list.get()) 1912 1284 n->statement->processVarDecls(exec); 1913 1285 } 1914 1286 1915 1287 // ------------------------------ AssignExprNode ------------------------------- 1916 1917 void AssignExprNode::ref()1918 {1919 Node::ref();1920 if ( expr )1921 expr->ref();1922 }1923 1924 bool AssignExprNode::deref()1925 {1926 if ( expr && expr->deref() )1927 delete expr;1928 return Node::deref();1929 }1930 1288 1931 1289 // ECMA 12.2 … … 1941 1299 : varType(t), ident(id), init(in) 1942 1300 { 1943 }1944 1945 void VarDeclNode::ref()1946 {1947 Node::ref();1948 if ( init )1949 init->ref();1950 }1951 1952 bool VarDeclNode::deref()1953 {1954 if ( init && init->deref() )1955 delete init;1956 return Node::deref();1957 1301 } 1958 1302 … … 2007 1351 // ------------------------------ VarDeclListNode ------------------------------ 2008 1352 2009 void VarDeclListNode::ref()2010 {2011 for (VarDeclListNode *n = this; n; n = n->list) {2012 n->Node::ref();2013 if (n->var)2014 n->var->ref();2015 }2016 }2017 2018 bool VarDeclListNode::deref()2019 {2020 VarDeclListNode *next;2021 for (VarDeclListNode *n = this; n; n = next) {2022 next = n->list;2023 if (n->var && n->var->deref())2024 delete n->var;2025 if (n != this && n->Node::deref())2026 delete n;2027 }2028 return Node::deref();2029 }2030 2031 2032 1353 // ECMA 12.2 2033 1354 ValueImp *VarDeclListNode::evaluate(ExecState *exec) 2034 1355 { 2035 for (VarDeclListNode *n = this; n; n = n->list ) {1356 for (VarDeclListNode *n = this; n; n = n->list.get()) { 2036 1357 n->var->evaluate(exec); 2037 1358 KJS_CHECKEXCEPTIONVALUE … … 2042 1363 void VarDeclListNode::processVarDecls(ExecState *exec) 2043 1364 { 2044 for (VarDeclListNode *n = this; n; n = n->list )1365 for (VarDeclListNode *n = this; n; n = n->list.get()) 2045 1366 n->var->processVarDecls(exec); 2046 1367 } 2047 1368 2048 1369 // ------------------------------ VarStatementNode ----------------------------- 2049 2050 void VarStatementNode::ref()2051 {2052 Node::ref();2053 if ( list )2054 list->ref();2055 }2056 2057 bool VarStatementNode::deref()2058 {2059 if ( list && list->deref() )2060 delete list;2061 return Node::deref();2062 }2063 1370 2064 1371 // ECMA 12.2 … … 2091 1398 } 2092 1399 2093 void BlockNode::ref()2094 {2095 Node::ref();2096 if ( source )2097 source->ref();2098 }2099 2100 bool BlockNode::deref()2101 {2102 if ( source && source->deref() )2103 delete source;2104 return Node::deref();2105 }2106 2107 1400 // ECMA 12.1 2108 1401 Completion BlockNode::execute(ExecState *exec) … … 2132 1425 // ------------------------------ ExprStatementNode ---------------------------- 2133 1426 2134 void ExprStatementNode::ref()2135 {2136 Node::ref();2137 if ( expr )2138 expr->ref();2139 }2140 2141 bool ExprStatementNode::deref()2142 {2143 if ( expr && expr->deref() )2144 delete expr;2145 return Node::deref();2146 }2147 2148 1427 // ECMA 12.4 2149 1428 Completion ExprStatementNode::execute(ExecState *exec) … … 2158 1437 2159 1438 // ------------------------------ IfNode --------------------------------------- 2160 2161 void IfNode::ref()2162 {2163 Node::ref();2164 if ( statement1 )2165 statement1->ref();2166 if ( statement2 )2167 statement2->ref();2168 if ( expr )2169 expr->ref();2170 }2171 2172 bool IfNode::deref()2173 {2174 if ( statement1 && statement1->deref() )2175 delete statement1;2176 if ( statement2 && statement2->deref() )2177 delete statement2;2178 if ( expr && expr->deref() )2179 delete expr;2180 return Node::deref();2181 }2182 1439 2183 1440 // ECMA 12.5 … … 2211 1468 2212 1469 // ------------------------------ DoWhileNode ---------------------------------- 2213 2214 void DoWhileNode::ref()2215 {2216 Node::ref();2217 if ( statement )2218 statement->ref();2219 if ( expr )2220 expr->ref();2221 }2222 2223 bool DoWhileNode::deref()2224 {2225 if ( statement && statement->deref() )2226 delete statement;2227 if ( expr && expr->deref() )2228 delete expr;2229 return Node::deref();2230 }2231 1470 2232 1471 // ECMA 12.6.1 … … 2265 1504 // ------------------------------ WhileNode ------------------------------------ 2266 1505 2267 void WhileNode::ref()2268 {2269 Node::ref();2270 if ( statement )2271 statement->ref();2272 if ( expr )2273 expr->ref();2274 }2275 2276 bool WhileNode::deref()2277 {2278 if ( statement && statement->deref() )2279 delete statement;2280 if ( expr && expr->deref() )2281 delete expr;2282 return Node::deref();2283 }2284 2285 1506 // ECMA 12.6.2 2286 1507 Completion WhileNode::execute(ExecState *exec) … … 2327 1548 2328 1549 // ------------------------------ ForNode -------------------------------------- 2329 2330 void ForNode::ref()2331 {2332 Node::ref();2333 if ( statement )2334 statement->ref();2335 if ( expr1 )2336 expr1->ref();2337 if ( expr2 )2338 expr2->ref();2339 if ( expr3 )2340 expr3->ref();2341 }2342 2343 bool ForNode::deref()2344 {2345 if ( statement && statement->deref() )2346 delete statement;2347 if ( expr1 && expr1->deref() )2348 delete expr1;2349 if ( expr2 && expr2->deref() )2350 delete expr2;2351 if ( expr3 && expr3->deref() )2352 delete expr3;2353 return Node::deref();2354 }2355 1550 2356 1551 // ECMA 12.6.3 … … 2412 1607 { 2413 1608 // for( var foo = bar in baz ) 2414 varDecl = new VarDeclNode(ident, init , VarDeclNode::Variable);1609 varDecl = new VarDeclNode(ident, init.get(), VarDeclNode::Variable); 2415 1610 lexpr = new ResolveNode(ident); 2416 }2417 2418 void ForInNode::ref()2419 {2420 Node::ref();2421 if ( statement )2422 statement->ref();2423 if ( expr )2424 expr->ref();2425 if ( lexpr )2426 lexpr->ref();2427 if ( init )2428 init->ref();2429 if ( varDecl )2430 varDecl->ref();2431 }2432 2433 bool ForInNode::deref()2434 {2435 if ( statement && statement->deref() )2436 delete statement;2437 if ( expr && expr->deref() )2438 delete expr;2439 if ( lexpr && lexpr->deref() )2440 delete lexpr;2441 if ( init && init->deref() )2442 delete init;2443 if ( varDecl && varDecl->deref() )2444 delete varDecl;2445 return Node::deref();2446 1611 } 2447 1612 … … 2552 1717 // ------------------------------ ReturnNode ----------------------------------- 2553 1718 2554 void ReturnNode::ref()2555 {2556 Node::ref();2557 if ( value )2558 value->ref();2559 }2560 2561 bool ReturnNode::deref()2562 {2563 if ( value && value->deref() )2564 delete value;2565 return Node::deref();2566 }2567 2568 1719 // ECMA 12.9 2569 1720 Completion ReturnNode::execute(ExecState *exec) … … 2586 1737 2587 1738 // ------------------------------ WithNode ------------------------------------- 2588 2589 void WithNode::ref()2590 {2591 Node::ref();2592 if ( statement )2593 statement->ref();2594 if ( expr )2595 expr->ref();2596 }2597 2598 bool WithNode::deref()2599 {2600 if ( statement && statement->deref() )2601 delete statement;2602 if ( expr && expr->deref() )2603 delete expr;2604 return Node::deref();2605 }2606 1739 2607 1740 // ECMA 12.10 … … 2628 1761 // ------------------------------ CaseClauseNode ------------------------------- 2629 1762 2630 void CaseClauseNode::ref()2631 {2632 Node::ref();2633 if ( expr )2634 expr->ref();2635 if ( list )2636 list->ref();2637 }2638 2639 bool CaseClauseNode::deref()2640 {2641 if ( expr && expr->deref() )2642 delete expr;2643 if ( list && list->deref() )2644 delete list;2645 return Node::deref();2646 }2647 2648 1763 // ECMA 12.11 2649 1764 ValueImp *CaseClauseNode::evaluate(ExecState *exec) … … 2672 1787 // ------------------------------ ClauseListNode ------------------------------- 2673 1788 2674 void ClauseListNode::ref()2675 {2676 for (ClauseListNode *n = this; n; n = n->nx) {2677 n->Node::ref();2678 if (n->cl)2679 n->cl->ref();2680 }2681 }2682 2683 bool ClauseListNode::deref()2684 {2685 ClauseListNode *next;2686 for (ClauseListNode *n = this; n; n = next) {2687 next = n->nx;2688 if (n->cl && n->cl->deref())2689 delete n->cl;2690 if (n != this && n->Node::deref())2691 delete n;2692 }2693 return Node::deref();2694 }2695 2696 1789 ValueImp *ClauseListNode::evaluate(ExecState */*exec*/) 2697 1790 { … … 2704 1797 void ClauseListNode::processVarDecls(ExecState *exec) 2705 1798 { 2706 for (ClauseListNode *n = this; n; n = n->nx )1799 for (ClauseListNode *n = this; n; n = n->nx.get()) 2707 1800 if (n->cl) 2708 1801 n->cl->processVarDecls(exec); … … 2731 1824 } 2732 1825 2733 void CaseBlockNode::ref()2734 {2735 Node::ref();2736 if ( def )2737 def->ref();2738 if ( list1 )2739 list1->ref();2740 if ( list2 )2741 list2->ref();2742 }2743 2744 bool CaseBlockNode::deref()2745 {2746 if ( def && def->deref() )2747 delete def;2748 if ( list1 && list1->deref() )2749 delete list1;2750 if ( list2 && list2->deref() )2751 delete list2;2752 return Node::deref();2753 }2754 2755 1826 ValueImp *CaseBlockNode::evaluate(ExecState */*exec*/) 2756 1827 { … … 2765 1836 ValueImp *v; 2766 1837 Completion res; 2767 ClauseListNode *a = list1, *b = list2; 1838 ClauseListNode *a = list1.get(); 1839 ClauseListNode *b = list2.get(); 2768 1840 CaseClauseNode *clause; 2769 1841 … … 2806 1878 return res; 2807 1879 } 2808 b = list2 ;1880 b = list2.get(); 2809 1881 step18: 2810 1882 while (b) { … … 2834 1906 // ------------------------------ SwitchNode ----------------------------------- 2835 1907 2836 void SwitchNode::ref()2837 {2838 Node::ref();2839 if ( expr )2840 expr->ref();2841 if ( block )2842 block->ref();2843 }2844 2845 bool SwitchNode::deref()2846 {2847 if ( expr && expr->deref() )2848 delete expr;2849 if ( block && block->deref() )2850 delete block;2851 return Node::deref();2852 }2853 2854 1908 // ECMA 12.11 2855 1909 Completion SwitchNode::execute(ExecState *exec) … … 2875 1929 2876 1930 // ------------------------------ LabelNode ------------------------------------ 2877 2878 void LabelNode::ref()2879 {2880 Node::ref();2881 if ( statement )2882 statement->ref();2883 }2884 2885 bool LabelNode::deref()2886 {2887 if ( statement && statement->deref() )2888 delete statement;2889 return Node::deref();2890 }2891 1931 2892 1932 // ECMA 12.12 … … 2914 1954 // ------------------------------ ThrowNode ------------------------------------ 2915 1955 2916 void ThrowNode::ref()2917 {2918 Node::ref();2919 if ( expr )2920 expr->ref();2921 }2922 2923 bool ThrowNode::deref()2924 {2925 if ( expr && expr->deref() )2926 delete expr;2927 return Node::deref();2928 }2929 2930 1956 // ECMA 12.13 2931 1957 Completion ThrowNode::execute(ExecState *exec) … … 2940 1966 2941 1967 // ------------------------------ CatchNode ------------------------------------ 2942 2943 void CatchNode::ref()2944 {2945 Node::ref();2946 if ( block )2947 block->ref();2948 }2949 2950 bool CatchNode::deref()2951 {2952 if ( block && block->deref() )2953 delete block;2954 return Node::deref();2955 }2956 1968 2957 1969 Completion CatchNode::execute(ExecState */*exec*/) … … 2985 1997 // ------------------------------ FinallyNode ---------------------------------- 2986 1998 2987 void FinallyNode::ref()2988 {2989 Node::ref();2990 if ( block )2991 block->ref();2992 }2993 2994 bool FinallyNode::deref()2995 {2996 if ( block && block->deref() )2997 delete block;2998 return Node::deref();2999 }3000 3001 1999 // ECMA 12.14 3002 2000 Completion FinallyNode::execute(ExecState *exec) … … 3011 2009 3012 2010 // ------------------------------ TryNode -------------------------------------- 3013 3014 void TryNode::ref()3015 {3016 Node::ref();3017 if ( block )3018 block->ref();3019 if ( _final )3020 _final->ref();3021 if ( _catch )3022 _catch->ref();3023 }3024 3025 bool TryNode::deref()3026 {3027 if ( block && block->deref() )3028 delete block;3029 if ( _final && _final->deref() )3030 delete _final;3031 if ( _catch && _catch->deref() )3032 delete _catch;3033 return Node::deref();3034 }3035 2011 3036 2012 // ECMA 12.14 … … 3079 2055 // ------------------------------ ParameterNode -------------------------------- 3080 2056 3081 void ParameterNode::ref()3082 {3083 for (ParameterNode *n = this; n; n = n->next)3084 n->Node::ref();3085 }3086 3087 bool ParameterNode::deref()3088 {3089 ParameterNode *next;3090 for (ParameterNode *n = this; n; n = next) {3091 next = n->next;3092 if (n != this && n->Node::deref())3093 delete n;3094 }3095 return Node::deref();3096 }3097 3098 2057 // ECMA 13 3099 2058 ValueImp *ParameterNode::evaluate(ExecState */*exec*/) … … 3119 2078 // ------------------------------ FuncDeclNode --------------------------------- 3120 2079 3121 void FuncDeclNode::ref()3122 {3123 Node::ref();3124 if ( param )3125 param->ref();3126 if ( body )3127 body->ref();3128 }3129 3130 bool FuncDeclNode::deref()3131 {3132 if ( param && param->deref() )3133 delete param;3134 if ( body && body->deref() )3135 delete body;3136 return Node::deref();3137 }3138 3139 2080 // ECMA 13 3140 2081 void FuncDeclNode::processFuncDecl(ExecState *exec) … … 3143 2084 3144 2085 // TODO: let this be an object with [[Class]] property "Function" 3145 FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body , context->scopeChain());2086 FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain()); 3146 2087 ObjectImp *func(fimp); // protect from GC 3147 2088 … … 3151 2092 3152 2093 int plen = 0; 3153 for(ParameterNode *p = param ; p != 0L; p = p->nextParam(), plen++)2094 for(ParameterNode *p = param.get(); p != 0L; p = p->nextParam(), plen++) 3154 2095 fimp->addParameter(p->ident()); 3155 2096 … … 3173 2114 // ------------------------------ FuncExprNode --------------------------------- 3174 2115 3175 void FuncExprNode::ref()3176 {3177 Node::ref();3178 if ( param )3179 param->ref();3180 if ( body )3181 body->ref();3182 }3183 3184 bool FuncExprNode::deref()3185 {3186 if ( param && param->deref() )3187 delete param;3188 if ( body && body->deref() )3189 delete body;3190 return Node::deref();3191 }3192 3193 3194 2116 // ECMA 13 3195 2117 ValueImp *FuncExprNode::evaluate(ExecState *exec) 3196 2118 { 3197 FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), body , exec->context().imp()->scopeChain());2119 FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), body.get(), exec->context().imp()->scopeChain()); 3198 2120 ValueImp *ret(fimp); 3199 2121 ValueImp *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); … … 3201 2123 3202 2124 int plen = 0; 3203 for(ParameterNode *p = param ; p != 0L; p = p->nextParam(), plen++)2125 for(ParameterNode *p = param.get(); p != 0L; p = p->nextParam(), plen++) 3204 2126 fimp->addParameter(p->ident()); 3205 2127 … … 3220 2142 s1->elements = this; 3221 2143 setLoc(s1->firstLine(), s2->lastLine(), s1->sourceId()); 3222 }3223 3224 void SourceElementsNode::ref()3225 {3226 for (SourceElementsNode *n = this; n; n = n->elements) {3227 n->Node::ref();3228 if (n->element)3229 n->element->ref();3230 }3231 }3232 3233 bool SourceElementsNode::deref()3234 {3235 SourceElementsNode *next;3236 for (SourceElementsNode *n = this; n; n = next) {3237 next = n->elements;3238 if (n->element && n->element->deref())3239 delete n->element;3240 if (n != this && n->Node::deref())3241 delete n;3242 }3243 return Node::deref();3244 2144 } 3245 2145 … … 3254 2154 return c1; 3255 2155 3256 for (SourceElementsNode *n = elements ; n; n = n->elements) {2156 for (SourceElementsNode *n = elements.get(); n; n = n->elements.get()) { 3257 2157 Completion c2 = n->element->execute(exec); 3258 2158 if (c2.complType() != Normal) … … 3270 2170 void SourceElementsNode::processFuncDecl(ExecState *exec) 3271 2171 { 3272 for (SourceElementsNode *n = this; n; n = n->elements )2172 for (SourceElementsNode *n = this; n; n = n->elements.get()) 3273 2173 n->element->processFuncDecl(exec); 3274 2174 } … … 3276 2176 void SourceElementsNode::processVarDecls(ExecState *exec) 3277 2177 { 3278 for (SourceElementsNode *n = this; n; n = n->elements )2178 for (SourceElementsNode *n = this; n; n = n->elements.get()) 3279 2179 n->element->processVarDecls(exec); 3280 2180 } -
trunk/JavaScriptCore/kjs/nodes.h
r10154 r10352 27 27 28 28 #include "fast_malloc.h" 29 #include "shared_ptr.h" 29 30 30 31 #include "internal.h" … … 92 93 public: 93 94 // reference counting mechanism 94 virtual void ref() { refcount++; } 95 #ifdef KJS_DEBUG_MEM 96 virtual bool deref() { assert( refcount > 0 ); return (!--refcount); } 97 #else 98 virtual bool deref() { return (!--refcount); } 99 #endif 100 101 102 #ifdef KJS_DEBUG_MEM 103 static void finalCheck(); 104 #endif 95 void ref() { ++m_refcount; } 96 void deref() { --m_refcount; if (!m_refcount) delete this; } 97 105 98 protected: 106 99 ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg); … … 114 107 int line; 115 108 UString sourceURL; 116 unsigned int refcount;109 unsigned int m_refcount; 117 110 virtual int sourceId() const { return -1; } 118 111 private: 119 #ifdef KJS_DEBUG_MEM120 // List of all nodes, for debugging purposes. Don't remove!121 static std::list<Node *> *s_nodes;122 #endif123 112 // disallow assignment 124 113 Node& operator=(const Node&); … … 165 154 class NumberNode : public Node { 166 155 public: 167 NumberNode(double v) : value(v) { 156 NumberNode(double v) : value(v) {} 168 157 ValueImp *evaluate(ExecState *exec); 169 158 virtual void streamTo(SourceStream &s) const; … … 211 200 public: 212 201 GroupNode(Node *g) : group(g) { } 213 virtual void ref();214 virtual bool deref();215 202 virtual ValueImp *evaluate(ExecState *exec); 216 203 virtual Reference evaluateReference(ExecState *exec); 217 204 virtual void streamTo(SourceStream &s) const; 218 205 private: 219 Node *group;206 kxmlcore::SharedPtr<Node> group; 220 207 }; 221 208 … … 226 213 ElementNode(ElementNode *l, int e, Node *n) 227 214 : list(l->list), elision(e), node(n) { l->list = this; } 228 virtual void ref();229 virtual bool deref();230 215 ValueImp *evaluate(ExecState *exec); 231 216 virtual void streamTo(SourceStream &s) const; 232 217 private: 233 218 friend class ArrayNode; 234 ElementNode *list;219 kxmlcore::SharedPtr<ElementNode> list; 235 220 int elision; 236 Node *node;221 kxmlcore::SharedPtr<Node> node; 237 222 }; 238 223 … … 244 229 ArrayNode(int eli, ElementNode *ele) 245 230 : element(ele->list), elision(eli), opt(true) { ele->list = 0; } 246 virtual void ref(); 247 virtual bool deref(); 248 ValueImp *evaluate(ExecState *exec); 249 virtual void streamTo(SourceStream &s) const; 250 private: 251 ElementNode *element; 231 ValueImp *evaluate(ExecState *exec); 232 virtual void streamTo(SourceStream &s) const; 233 private: 234 kxmlcore::SharedPtr<ElementNode> element; 252 235 int elision; 253 236 bool opt; … … 261 244 PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l) 262 245 : name(n), assign(a), list(l->list) { l->list = this; } 263 virtual void ref();264 virtual bool deref();265 246 ValueImp *evaluate(ExecState *exec); 266 247 virtual void streamTo(SourceStream &s) const; 267 248 private: 268 249 friend class ObjectLiteralNode; 269 PropertyNode *name;270 Node *assign;271 PropertyValueNode *list;250 kxmlcore::SharedPtr<PropertyNode> name; 251 kxmlcore::SharedPtr<Node> assign; 252 kxmlcore::SharedPtr<PropertyValueNode> list; 272 253 }; 273 254 … … 276 257 ObjectLiteralNode() : list(0) { } 277 258 ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; } 278 virtual void ref(); 279 virtual bool deref(); 280 ValueImp *evaluate(ExecState *exec); 281 virtual void streamTo(SourceStream &s) const; 282 private: 283 PropertyValueNode *list; 259 ValueImp *evaluate(ExecState *exec); 260 virtual void streamTo(SourceStream &s) const; 261 private: 262 kxmlcore::SharedPtr<PropertyValueNode> list; 284 263 }; 285 264 … … 298 277 public: 299 278 BracketAccessorNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {} 300 virtual void ref();301 virtual bool deref();302 279 ValueImp *evaluate(ExecState *exec); 303 280 virtual Reference evaluateReference(ExecState *exec); 304 281 virtual void streamTo(SourceStream &s) const; 305 282 private: 306 Node *expr1;307 Node *expr2;283 kxmlcore::SharedPtr<Node> expr1; 284 kxmlcore::SharedPtr<Node> expr2; 308 285 }; 309 286 … … 311 288 public: 312 289 DotAccessorNode(Node *e, const Identifier &s) : expr(e), ident(s) { } 313 virtual void ref();314 virtual bool deref();315 290 ValueImp *evaluate(ExecState *exec); 316 291 virtual Reference evaluateReference(ExecState *exec); 317 292 virtual void streamTo(SourceStream &s) const; 318 293 private: 319 Node *expr;294 kxmlcore::SharedPtr<Node> expr; 320 295 Identifier ident; 321 296 }; … … 327 302 ArgumentListNode(ArgumentListNode *l, Node *e) 328 303 : list(l->list), expr(e) { l->list = this; } 329 virtual void ref();330 virtual bool deref();331 304 ValueImp *evaluate(ExecState *exec); 332 305 List evaluateList(ExecState *exec); … … 334 307 private: 335 308 friend class ArgumentsNode; 336 ArgumentListNode *list;337 Node *expr;309 kxmlcore::SharedPtr<ArgumentListNode> list; 310 kxmlcore::SharedPtr<Node> expr; 338 311 }; 339 312 … … 343 316 ArgumentsNode(ArgumentListNode *l) 344 317 : list(l->list) { l->list = 0; } 345 virtual void ref();346 virtual bool deref();347 318 ValueImp *evaluate(ExecState *exec); 348 319 List evaluateList(ExecState *exec); 349 320 virtual void streamTo(SourceStream &s) const; 350 321 private: 351 ArgumentListNode *list;322 kxmlcore::SharedPtr<ArgumentListNode> list; 352 323 }; 353 324 … … 356 327 NewExprNode(Node *e) : expr(e), args(0) {} 357 328 NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {} 358 virtual void ref(); 359 virtual bool deref(); 360 ValueImp *evaluate(ExecState *exec); 361 virtual void streamTo(SourceStream &s) const; 362 private: 363 Node *expr; 364 ArgumentsNode *args; 329 ValueImp *evaluate(ExecState *exec); 330 virtual void streamTo(SourceStream &s) const; 331 private: 332 kxmlcore::SharedPtr<Node> expr; 333 kxmlcore::SharedPtr<ArgumentsNode> args; 365 334 }; 366 335 … … 368 337 public: 369 338 FunctionCallValueNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {} 370 virtual void ref(); 371 virtual bool deref(); 372 ValueImp *evaluate(ExecState *exec); 373 virtual void streamTo(SourceStream &s) const; 374 private: 375 Node *expr; 376 ArgumentsNode *args; 339 ValueImp *evaluate(ExecState *exec); 340 virtual void streamTo(SourceStream &s) const; 341 private: 342 kxmlcore::SharedPtr<Node> expr; 343 kxmlcore::SharedPtr<ArgumentsNode> args; 377 344 }; 378 345 … … 380 347 public: 381 348 FunctionCallResolveNode(const Identifier& i, ArgumentsNode *a) : ident(i), args(a) {} 382 virtual void ref();383 virtual bool deref();384 349 ValueImp *evaluate(ExecState *exec); 385 350 virtual void streamTo(SourceStream &s) const; 386 351 private: 387 352 Identifier ident; 388 ArgumentsNode *args;353 kxmlcore::SharedPtr<ArgumentsNode> args; 389 354 }; 390 355 … … 392 357 public: 393 358 FunctionCallBracketNode(Node *b, Node *s, ArgumentsNode *a) : base(b), subscript(s), args(a) {} 394 virtual void ref();395 virtual bool deref();396 359 ValueImp *evaluate(ExecState *exec); 397 360 virtual void streamTo(SourceStream &s) const; 398 361 protected: 399 Node *base;400 Node *subscript;401 ArgumentsNode *args;362 kxmlcore::SharedPtr<Node> base; 363 kxmlcore::SharedPtr<Node> subscript; 364 kxmlcore::SharedPtr<ArgumentsNode> args; 402 365 }; 403 366 … … 411 374 public: 412 375 FunctionCallDotNode(Node *b, const Identifier &i, ArgumentsNode *a) : base(b), ident(i), args(a) {} 413 virtual void ref();414 virtual bool deref();415 376 ValueImp *evaluate(ExecState *exec); 416 377 virtual void streamTo(SourceStream &s) const; 417 378 protected: 418 Node *base;379 kxmlcore::SharedPtr<Node> base; 419 380 Identifier ident; 420 ArgumentsNode *args;381 kxmlcore::SharedPtr<ArgumentsNode> args; 421 382 }; 422 383 … … 430 391 public: 431 392 PostfixNode(Node *e, Operator o) : expr(e), oper(o) {} 432 virtual void ref(); 433 virtual bool deref(); 434 ValueImp *evaluate(ExecState *exec); 435 virtual void streamTo(SourceStream &s) const; 436 private: 437 Node *expr; 393 ValueImp *evaluate(ExecState *exec); 394 virtual void streamTo(SourceStream &s) const; 395 private: 396 kxmlcore::SharedPtr<Node> expr; 438 397 Operator oper; 439 398 }; … … 442 401 public: 443 402 DeleteNode(Node *e) : expr(e) {} 444 virtual void ref(); 445 virtual bool deref(); 446 ValueImp *evaluate(ExecState *exec); 447 virtual void streamTo(SourceStream &s) const; 448 private: 449 Node *expr; 403 ValueImp *evaluate(ExecState *exec); 404 virtual void streamTo(SourceStream &s) const; 405 private: 406 kxmlcore::SharedPtr<Node> expr; 450 407 }; 451 408 … … 453 410 public: 454 411 VoidNode(Node *e) : expr(e) {} 455 virtual void ref(); 456 virtual bool deref(); 457 ValueImp *evaluate(ExecState *exec); 458 virtual void streamTo(SourceStream &s) const; 459 private: 460 Node *expr; 412 ValueImp *evaluate(ExecState *exec); 413 virtual void streamTo(SourceStream &s) const; 414 private: 415 kxmlcore::SharedPtr<Node> expr; 461 416 }; 462 417 … … 464 419 public: 465 420 TypeOfNode(Node *e) : expr(e) {} 466 virtual void ref(); 467 virtual bool deref(); 468 ValueImp *evaluate(ExecState *exec); 469 virtual void streamTo(SourceStream &s) const; 470 private: 471 Node *expr; 421 ValueImp *evaluate(ExecState *exec); 422 virtual void streamTo(SourceStream &s) const; 423 private: 424 kxmlcore::SharedPtr<Node> expr; 472 425 }; 473 426 … … 475 428 public: 476 429 PrefixNode(Operator o, Node *e) : oper(o), expr(e) {} 477 virtual void ref();478 virtual bool deref();479 430 ValueImp *evaluate(ExecState *exec); 480 431 virtual void streamTo(SourceStream &s) const; 481 432 private: 482 433 Operator oper; 483 Node *expr;434 kxmlcore::SharedPtr<Node> expr; 484 435 }; 485 436 … … 487 438 public: 488 439 UnaryPlusNode(Node *e) : expr(e) {} 489 virtual void ref(); 490 virtual bool deref(); 491 ValueImp *evaluate(ExecState *exec); 492 virtual void streamTo(SourceStream &s) const; 493 private: 494 Node *expr; 440 ValueImp *evaluate(ExecState *exec); 441 virtual void streamTo(SourceStream &s) const; 442 private: 443 kxmlcore::SharedPtr<Node> expr; 495 444 }; 496 445 … … 498 447 public: 499 448 NegateNode(Node *e) : expr(e) {} 500 virtual void ref(); 501 virtual bool deref(); 502 ValueImp *evaluate(ExecState *exec); 503 virtual void streamTo(SourceStream &s) const; 504 private: 505 Node *expr; 449 ValueImp *evaluate(ExecState *exec); 450 virtual void streamTo(SourceStream &s) const; 451 private: 452 kxmlcore::SharedPtr<Node> expr; 506 453 }; 507 454 … … 509 456 public: 510 457 BitwiseNotNode(Node *e) : expr(e) {} 511 virtual void ref(); 512 virtual bool deref(); 513 ValueImp *evaluate(ExecState *exec); 514 virtual void streamTo(SourceStream &s) const; 515 private: 516 Node *expr; 458 ValueImp *evaluate(ExecState *exec); 459 virtual void streamTo(SourceStream &s) const; 460 private: 461 kxmlcore::SharedPtr<Node> expr; 517 462 }; 518 463 … … 520 465 public: 521 466 LogicalNotNode(Node *e) : expr(e) {} 522 virtual void ref(); 523 virtual bool deref(); 524 ValueImp *evaluate(ExecState *exec); 525 virtual void streamTo(SourceStream &s) const; 526 private: 527 Node *expr; 467 ValueImp *evaluate(ExecState *exec); 468 virtual void streamTo(SourceStream &s) const; 469 private: 470 kxmlcore::SharedPtr<Node> expr; 528 471 }; 529 472 … … 531 474 public: 532 475 MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {} 533 virtual void ref(); 534 virtual bool deref(); 535 ValueImp *evaluate(ExecState *exec); 536 virtual void streamTo(SourceStream &s) const; 537 private: 538 Node *term1, *term2; 476 ValueImp *evaluate(ExecState *exec); 477 virtual void streamTo(SourceStream &s) const; 478 private: 479 kxmlcore::SharedPtr<Node> term1; 480 kxmlcore::SharedPtr<Node> term2; 539 481 char oper; 540 482 }; … … 543 485 public: 544 486 AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {} 545 virtual void ref(); 546 virtual bool deref(); 547 ValueImp *evaluate(ExecState *exec); 548 virtual void streamTo(SourceStream &s) const; 549 private: 550 Node *term1, *term2; 487 ValueImp *evaluate(ExecState *exec); 488 virtual void streamTo(SourceStream &s) const; 489 private: 490 kxmlcore::SharedPtr<Node> term1; 491 kxmlcore::SharedPtr<Node> term2; 551 492 char oper; 552 493 }; … … 556 497 ShiftNode(Node *t1, Operator o, Node *t2) 557 498 : term1(t1), term2(t2), oper(o) {} 558 virtual void ref(); 559 virtual bool deref(); 560 ValueImp *evaluate(ExecState *exec); 561 virtual void streamTo(SourceStream &s) const; 562 private: 563 Node *term1, *term2; 499 ValueImp *evaluate(ExecState *exec); 500 virtual void streamTo(SourceStream &s) const; 501 private: 502 kxmlcore::SharedPtr<Node> term1; 503 kxmlcore::SharedPtr<Node> term2; 564 504 Operator oper; 565 505 }; … … 569 509 RelationalNode(Node *e1, Operator o, Node *e2) : 570 510 expr1(e1), expr2(e2), oper(o) {} 571 virtual void ref(); 572 virtual bool deref(); 573 ValueImp *evaluate(ExecState *exec); 574 virtual void streamTo(SourceStream &s) const; 575 private: 576 Node *expr1, *expr2; 511 ValueImp *evaluate(ExecState *exec); 512 virtual void streamTo(SourceStream &s) const; 513 private: 514 kxmlcore::SharedPtr<Node> expr1; 515 kxmlcore::SharedPtr<Node> expr2; 577 516 Operator oper; 578 517 }; … … 582 521 EqualNode(Node *e1, Operator o, Node *e2) 583 522 : expr1(e1), expr2(e2), oper(o) {} 584 virtual void ref(); 585 virtual bool deref(); 586 ValueImp *evaluate(ExecState *exec); 587 virtual void streamTo(SourceStream &s) const; 588 private: 589 Node *expr1, *expr2; 523 ValueImp *evaluate(ExecState *exec); 524 virtual void streamTo(SourceStream &s) const; 525 private: 526 kxmlcore::SharedPtr<Node> expr1; 527 kxmlcore::SharedPtr<Node> expr2; 590 528 Operator oper; 591 529 }; … … 595 533 BitOperNode(Node *e1, Operator o, Node *e2) : 596 534 expr1(e1), expr2(e2), oper(o) {} 597 virtual void ref(); 598 virtual bool deref(); 599 ValueImp *evaluate(ExecState *exec); 600 virtual void streamTo(SourceStream &s) const; 601 private: 602 Node *expr1, *expr2; 535 ValueImp *evaluate(ExecState *exec); 536 virtual void streamTo(SourceStream &s) const; 537 private: 538 kxmlcore::SharedPtr<Node> expr1; 539 kxmlcore::SharedPtr<Node> expr2; 603 540 Operator oper; 604 541 }; … … 611 548 BinaryLogicalNode(Node *e1, Operator o, Node *e2) : 612 549 expr1(e1), expr2(e2), oper(o) {} 613 virtual void ref(); 614 virtual bool deref(); 615 ValueImp *evaluate(ExecState *exec); 616 virtual void streamTo(SourceStream &s) const; 617 private: 618 Node *expr1, *expr2; 550 ValueImp *evaluate(ExecState *exec); 551 virtual void streamTo(SourceStream &s) const; 552 private: 553 kxmlcore::SharedPtr<Node> expr1; 554 kxmlcore::SharedPtr<Node> expr2; 619 555 Operator oper; 620 556 }; … … 627 563 ConditionalNode(Node *l, Node *e1, Node *e2) : 628 564 logical(l), expr1(e1), expr2(e2) {} 629 virtual void ref();630 virtual bool deref();631 ValueImp *evaluate(ExecState *exec);632 virtual void streamTo(SourceStream &s) const;633 private:634 Node *logical, *expr1, *expr2;565 ValueImp *evaluate(ExecState *exec); 566 virtual void streamTo(SourceStream &s) const; 567 private: 568 kxmlcore::SharedPtr<Node> logical; 569 kxmlcore::SharedPtr<Node> expr1; 570 kxmlcore::SharedPtr<Node> expr2; 635 571 }; 636 572 … … 639 575 AssignResolveNode(const Identifier &ident, Operator oper, Node *right) 640 576 : m_ident(ident), m_oper(oper), m_right(right) {} 641 virtual void ref();642 virtual bool deref();643 577 ValueImp *evaluate(ExecState *exec); 644 578 virtual void streamTo(SourceStream &s) const; … … 646 580 Identifier m_ident; 647 581 Operator m_oper; 648 Node *m_right;582 kxmlcore::SharedPtr<Node> m_right; 649 583 }; 650 584 … … 653 587 AssignBracketNode(Node *base, Node *subscript, Operator oper, Node *right) 654 588 : m_base(base), m_subscript(subscript), m_oper(oper), m_right(right) {} 655 virtual void ref();656 virtual bool deref();657 589 ValueImp *evaluate(ExecState *exec); 658 590 virtual void streamTo(SourceStream &s) const; 659 591 protected: 660 Node *m_base;661 Node *m_subscript;592 kxmlcore::SharedPtr<Node> m_base; 593 kxmlcore::SharedPtr<Node> m_subscript; 662 594 Operator m_oper; 663 Node *m_right;595 kxmlcore::SharedPtr<Node> m_right; 664 596 }; 665 597 … … 668 600 AssignDotNode(Node *base, const Identifier& ident, Operator oper, Node *right) 669 601 : m_base(base), m_ident(ident), m_oper(oper), m_right(right) {} 670 virtual void ref();671 virtual bool deref();672 602 ValueImp *evaluate(ExecState *exec); 673 603 virtual void streamTo(SourceStream &s) const; 674 604 protected: 675 Node *m_base;605 kxmlcore::SharedPtr<Node> m_base; 676 606 Identifier m_ident; 677 607 Operator m_oper; 678 Node *m_right;608 kxmlcore::SharedPtr<Node> m_right; 679 609 }; 680 610 … … 682 612 public: 683 613 CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {} 684 virtual void ref(); 685 virtual bool deref(); 686 ValueImp *evaluate(ExecState *exec); 687 virtual void streamTo(SourceStream &s) const; 688 private: 689 Node *expr1, *expr2; 614 ValueImp *evaluate(ExecState *exec); 615 virtual void streamTo(SourceStream &s) const; 616 private: 617 kxmlcore::SharedPtr<Node> expr1; 618 kxmlcore::SharedPtr<Node> expr2; 690 619 }; 691 620 … … 695 624 StatListNode(StatementNode *s); 696 625 StatListNode(StatListNode *l, StatementNode *s); 697 virtual void ref();698 virtual bool deref();699 626 virtual Completion execute(ExecState *exec); 700 627 virtual void processVarDecls(ExecState *exec); … … 702 629 private: 703 630 friend class CaseClauseNode; 704 StatementNode *statement;705 StatListNode *list;631 kxmlcore::SharedPtr<StatementNode> statement; 632 kxmlcore::SharedPtr<StatListNode> list; 706 633 }; 707 634 … … 709 636 public: 710 637 AssignExprNode(Node *e) : expr(e) {} 711 virtual void ref(); 712 virtual bool deref(); 713 ValueImp *evaluate(ExecState *exec); 714 virtual void streamTo(SourceStream &s) const; 715 private: 716 Node *expr; 638 ValueImp *evaluate(ExecState *exec); 639 virtual void streamTo(SourceStream &s) const; 640 private: 641 kxmlcore::SharedPtr<Node> expr; 717 642 }; 718 643 … … 721 646 enum Type { Variable, Constant }; 722 647 VarDeclNode(const Identifier &id, AssignExprNode *in, Type t); 723 virtual void ref();724 virtual bool deref();725 648 ValueImp *evaluate(ExecState *exec); 726 649 virtual void processVarDecls(ExecState *exec); … … 729 652 Type varType; 730 653 Identifier ident; 731 AssignExprNode *init;654 kxmlcore::SharedPtr<AssignExprNode> init; 732 655 }; 733 656 … … 738 661 VarDeclListNode(VarDeclListNode *l, VarDeclNode *v) 739 662 : list(l->list), var(v) { l->list = this; } 740 virtual void ref();741 virtual bool deref();742 663 ValueImp *evaluate(ExecState *exec); 743 664 virtual void processVarDecls(ExecState *exec); … … 746 667 friend class ForNode; 747 668 friend class VarStatementNode; 748 VarDeclListNode *list;749 VarDeclNode *var;669 kxmlcore::SharedPtr<VarDeclListNode> list; 670 kxmlcore::SharedPtr<VarDeclNode> var; 750 671 }; 751 672 … … 753 674 public: 754 675 VarStatementNode(VarDeclListNode *l) : list(l->list) { l->list = 0; } 755 virtual void ref(); 756 virtual bool deref(); 757 virtual Completion execute(ExecState *exec); 758 virtual void processVarDecls(ExecState *exec); 759 virtual void streamTo(SourceStream &s) const; 760 private: 761 VarDeclListNode *list; 676 virtual Completion execute(ExecState *exec); 677 virtual void processVarDecls(ExecState *exec); 678 virtual void streamTo(SourceStream &s) const; 679 private: 680 kxmlcore::SharedPtr<VarDeclListNode> list; 762 681 }; 763 682 … … 765 684 public: 766 685 BlockNode(SourceElementsNode *s); 767 virtual void ref();768 virtual bool deref();769 686 virtual Completion execute(ExecState *exec); 770 687 virtual void processVarDecls(ExecState *exec); 771 688 virtual void streamTo(SourceStream &s) const; 772 689 protected: 773 SourceElementsNode *source;690 kxmlcore::SharedPtr<SourceElementsNode> source; 774 691 }; 775 692 … … 784 701 public: 785 702 ExprStatementNode(Node *e) : expr(e) { } 786 virtual void ref(); 787 virtual bool deref(); 788 virtual Completion execute(ExecState *exec); 789 virtual void streamTo(SourceStream &s) const; 790 private: 791 Node *expr; 703 virtual Completion execute(ExecState *exec); 704 virtual void streamTo(SourceStream &s) const; 705 private: 706 kxmlcore::SharedPtr<Node> expr; 792 707 }; 793 708 … … 796 711 IfNode(Node *e, StatementNode *s1, StatementNode *s2) 797 712 : expr(e), statement1(s1), statement2(s2) {} 798 virtual void ref(); 799 virtual bool deref(); 800 virtual Completion execute(ExecState *exec); 801 virtual void processVarDecls(ExecState *exec); 802 virtual void streamTo(SourceStream &s) const; 803 private: 804 Node *expr; 805 StatementNode *statement1, *statement2; 713 virtual Completion execute(ExecState *exec); 714 virtual void processVarDecls(ExecState *exec); 715 virtual void streamTo(SourceStream &s) const; 716 private: 717 kxmlcore::SharedPtr<Node> expr; 718 kxmlcore::SharedPtr<StatementNode> statement1; 719 kxmlcore::SharedPtr<StatementNode> statement2; 806 720 }; 807 721 … … 809 723 public: 810 724 DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {} 811 virtual void ref(); 812 virtual bool deref(); 813 virtual Completion execute(ExecState *exec); 814 virtual void processVarDecls(ExecState *exec); 815 virtual void streamTo(SourceStream &s) const; 816 private: 817 StatementNode *statement; 818 Node *expr; 725 virtual Completion execute(ExecState *exec); 726 virtual void processVarDecls(ExecState *exec); 727 virtual void streamTo(SourceStream &s) const; 728 private: 729 kxmlcore::SharedPtr<StatementNode> statement; 730 kxmlcore::SharedPtr<Node> expr; 819 731 }; 820 732 … … 822 734 public: 823 735 WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {} 824 virtual void ref(); 825 virtual bool deref(); 826 virtual Completion execute(ExecState *exec); 827 virtual void processVarDecls(ExecState *exec); 828 virtual void streamTo(SourceStream &s) const; 829 private: 830 Node *expr; 831 StatementNode *statement; 736 virtual Completion execute(ExecState *exec); 737 virtual void processVarDecls(ExecState *exec); 738 virtual void streamTo(SourceStream &s) const; 739 private: 740 kxmlcore::SharedPtr<Node> expr; 741 kxmlcore::SharedPtr<StatementNode> statement; 832 742 }; 833 743 … … 838 748 ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) : 839 749 expr1(e1->list), expr2(e2), expr3(e3), statement(s) { e1->list = 0; } 840 virtual void ref();841 virtual bool deref();842 virtual Completion execute(ExecState *exec);843 virtual void processVarDecls(ExecState *exec);844 virtual void streamTo(SourceStream &s) const;845 private:846 Node *expr1, *expr2, *expr3;847 StatementNode *statement;750 virtual Completion execute(ExecState *exec); 751 virtual void processVarDecls(ExecState *exec); 752 virtual void streamTo(SourceStream &s) const; 753 private: 754 kxmlcore::SharedPtr<Node> expr1; 755 kxmlcore::SharedPtr<Node> expr2; 756 kxmlcore::SharedPtr<Node> expr3; 757 kxmlcore::SharedPtr<StatementNode> statement; 848 758 }; 849 759 … … 852 762 ForInNode(Node *l, Node *e, StatementNode *s); 853 763 ForInNode(const Identifier &i, AssignExprNode *in, Node *e, StatementNode *s); 854 virtual void ref();855 virtual bool deref();856 764 virtual Completion execute(ExecState *exec); 857 765 virtual void processVarDecls(ExecState *exec); … … 859 767 private: 860 768 Identifier ident; 861 AssignExprNode *init; 862 Node *lexpr, *expr; 863 VarDeclNode *varDecl; 864 StatementNode *statement; 769 kxmlcore::SharedPtr<AssignExprNode> init; 770 kxmlcore::SharedPtr<Node> lexpr; 771 kxmlcore::SharedPtr<Node> expr; 772 kxmlcore::SharedPtr<VarDeclNode> varDecl; 773 kxmlcore::SharedPtr<StatementNode> statement; 865 774 }; 866 775 … … 888 797 public: 889 798 ReturnNode(Node *v) : value(v) {} 890 virtual void ref(); 891 virtual bool deref(); 892 virtual Completion execute(ExecState *exec); 893 virtual void streamTo(SourceStream &s) const; 894 private: 895 Node *value; 799 virtual Completion execute(ExecState *exec); 800 virtual void streamTo(SourceStream &s) const; 801 private: 802 kxmlcore::SharedPtr<Node> value; 896 803 }; 897 804 … … 899 806 public: 900 807 WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {} 901 virtual void ref(); 902 virtual bool deref(); 903 virtual Completion execute(ExecState *exec); 904 virtual void processVarDecls(ExecState *exec); 905 virtual void streamTo(SourceStream &s) const; 906 private: 907 Node *expr; 908 StatementNode *statement; 808 virtual Completion execute(ExecState *exec); 809 virtual void processVarDecls(ExecState *exec); 810 virtual void streamTo(SourceStream &s) const; 811 private: 812 kxmlcore::SharedPtr<Node> expr; 813 kxmlcore::SharedPtr<StatementNode> statement; 909 814 }; 910 815 … … 914 819 CaseClauseNode(Node *e, StatListNode *l) 915 820 : expr(e), list(l->list) { l->list = 0; } 916 virtual void ref();917 virtual bool deref();918 821 ValueImp *evaluate(ExecState *exec); 919 822 Completion evalStatements(ExecState *exec); … … 921 824 virtual void streamTo(SourceStream &s) const; 922 825 private: 923 Node *expr;924 StatListNode *list;826 kxmlcore::SharedPtr<Node> expr; 827 kxmlcore::SharedPtr<StatListNode> list; 925 828 }; 926 829 … … 931 834 ClauseListNode(ClauseListNode *n, CaseClauseNode *c) 932 835 : cl(c), nx(n->nx) { n->nx = this; } 933 virtual void ref(); 934 virtual bool deref(); 935 ValueImp *evaluate(ExecState *exec); 936 CaseClauseNode *clause() const { return cl; } 937 ClauseListNode *next() const { return nx; } 836 ValueImp *evaluate(ExecState *exec); 837 CaseClauseNode *clause() const { return cl.get(); } 838 ClauseListNode *next() const { return nx.get(); } 938 839 virtual void processVarDecls(ExecState *exec); 939 840 virtual void streamTo(SourceStream &s) const; 940 841 private: 941 842 friend class CaseBlockNode; 942 CaseClauseNode *cl;943 ClauseListNode *nx;843 kxmlcore::SharedPtr<CaseClauseNode> cl; 844 kxmlcore::SharedPtr<ClauseListNode> nx; 944 845 }; 945 846 … … 947 848 public: 948 849 CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2); 949 virtual void ref();950 virtual bool deref();951 850 ValueImp *evaluate(ExecState *exec); 952 851 Completion evalBlock(ExecState *exec, ValueImp *input); … … 954 853 virtual void streamTo(SourceStream &s) const; 955 854 private: 956 ClauseListNode *list1;957 CaseClauseNode *def;958 ClauseListNode *list2;855 kxmlcore::SharedPtr<ClauseListNode> list1; 856 kxmlcore::SharedPtr<CaseClauseNode> def; 857 kxmlcore::SharedPtr<ClauseListNode> list2; 959 858 }; 960 859 … … 962 861 public: 963 862 SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { } 964 virtual void ref(); 965 virtual bool deref(); 966 virtual Completion execute(ExecState *exec); 967 virtual void processVarDecls(ExecState *exec); 968 virtual void streamTo(SourceStream &s) const; 969 private: 970 Node *expr; 971 CaseBlockNode *block; 863 virtual Completion execute(ExecState *exec); 864 virtual void processVarDecls(ExecState *exec); 865 virtual void streamTo(SourceStream &s) const; 866 private: 867 kxmlcore::SharedPtr<Node> expr; 868 kxmlcore::SharedPtr<CaseBlockNode> block; 972 869 }; 973 870 … … 975 872 public: 976 873 LabelNode(const Identifier &l, StatementNode *s) : label(l), statement(s) { } 977 virtual void ref();978 virtual bool deref();979 874 virtual Completion execute(ExecState *exec); 980 875 virtual void processVarDecls(ExecState *exec); … … 982 877 private: 983 878 Identifier label; 984 StatementNode *statement;879 kxmlcore::SharedPtr<StatementNode> statement; 985 880 }; 986 881 … … 988 883 public: 989 884 ThrowNode(Node *e) : expr(e) {} 990 virtual void ref(); 991 virtual bool deref(); 992 virtual Completion execute(ExecState *exec); 993 virtual void streamTo(SourceStream &s) const; 994 private: 995 Node *expr; 885 virtual Completion execute(ExecState *exec); 886 virtual void streamTo(SourceStream &s) const; 887 private: 888 kxmlcore::SharedPtr<Node> expr; 996 889 }; 997 890 … … 999 892 public: 1000 893 CatchNode(const Identifier &i, StatementNode *b) : ident(i), block(b) {} 1001 virtual void ref();1002 virtual bool deref();1003 894 virtual Completion execute(ExecState *exec); 1004 895 Completion execute(ExecState *exec, ValueImp *arg); … … 1007 898 private: 1008 899 Identifier ident; 1009 StatementNode *block;900 kxmlcore::SharedPtr<StatementNode> block; 1010 901 }; 1011 902 … … 1013 904 public: 1014 905 FinallyNode(StatementNode *b) : block(b) {} 1015 virtual void ref(); 1016 virtual bool deref(); 1017 virtual Completion execute(ExecState *exec); 1018 virtual void processVarDecls(ExecState *exec); 1019 virtual void streamTo(SourceStream &s) const; 1020 private: 1021 StatementNode *block; 906 virtual Completion execute(ExecState *exec); 907 virtual void processVarDecls(ExecState *exec); 908 virtual void streamTo(SourceStream &s) const; 909 private: 910 kxmlcore::SharedPtr<StatementNode> block; 1022 911 }; 1023 912 … … 1030 919 TryNode(StatementNode *b, CatchNode *c, FinallyNode *f) 1031 920 : block(b), _catch(c), _final(f) {} 1032 virtual void ref(); 1033 virtual bool deref(); 1034 virtual Completion execute(ExecState *exec); 1035 virtual void processVarDecls(ExecState *exec); 1036 virtual void streamTo(SourceStream &s) const; 1037 private: 1038 StatementNode *block; 1039 CatchNode *_catch; 1040 FinallyNode *_final; 921 virtual Completion execute(ExecState *exec); 922 virtual void processVarDecls(ExecState *exec); 923 virtual void streamTo(SourceStream &s) const; 924 private: 925 kxmlcore::SharedPtr<StatementNode> block; 926 kxmlcore::SharedPtr<CatchNode> _catch; 927 kxmlcore::SharedPtr<FinallyNode> _final; 1041 928 }; 1042 929 … … 1047 934 ParameterNode(ParameterNode *list, const Identifier &i) 1048 935 : id(i), next(list->next) { list->next = this; } 1049 virtual void ref();1050 virtual bool deref();1051 936 ValueImp *evaluate(ExecState *exec); 1052 937 Identifier ident() { return id; } 1053 ParameterNode *nextParam() { return next ; }938 ParameterNode *nextParam() { return next.get(); } 1054 939 virtual void streamTo(SourceStream &s) const; 1055 940 private: … … 1057 942 friend class FuncExprNode; 1058 943 Identifier id; 1059 ParameterNode *next;944 kxmlcore::SharedPtr<ParameterNode> next; 1060 945 }; 1061 946 … … 1073 958 FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b) 1074 959 : ident(i), param(p->next), body(b) { p->next = 0; } 1075 virtual void ref();1076 virtual bool deref();1077 960 Completion execute(ExecState */*exec*/) 1078 961 { /* empty */ return Completion(); } … … 1081 964 private: 1082 965 Identifier ident; 1083 ParameterNode *param;1084 FunctionBodyNode *body;966 kxmlcore::SharedPtr<ParameterNode> param; 967 kxmlcore::SharedPtr<FunctionBodyNode> body; 1085 968 }; 1086 969 … … 1090 973 FuncExprNode(ParameterNode *p, FunctionBodyNode *b) 1091 974 : param(p->next), body(b) { p->next = 0; } 1092 virtual void ref(); 1093 virtual bool deref(); 1094 ValueImp *evaluate(ExecState *exec); 1095 virtual void streamTo(SourceStream &s) const; 1096 private: 1097 ParameterNode *param; 1098 FunctionBodyNode *body; 975 ValueImp *evaluate(ExecState *exec); 976 virtual void streamTo(SourceStream &s) const; 977 private: 978 kxmlcore::SharedPtr<ParameterNode> param; 979 kxmlcore::SharedPtr<FunctionBodyNode> body; 1099 980 }; 1100 981 … … 1105 986 SourceElementsNode(StatementNode *s1); 1106 987 SourceElementsNode(SourceElementsNode *s1, StatementNode *s2); 1107 virtual void ref(); 1108 virtual bool deref(); 988 1109 989 Completion execute(ExecState *exec); 1110 990 void processFuncDecl(ExecState *exec); … … 1113 993 private: 1114 994 friend class BlockNode; 1115 StatementNode *element; // 'this' element1116 SourceElementsNode *elements; // pointer to next995 kxmlcore::SharedPtr<StatementNode> element; // 'this' element 996 kxmlcore::SharedPtr<SourceElementsNode> elements; // pointer to next 1117 997 }; 1118 998 -
trunk/JavaScriptCore/kjs/nodes2string.cpp
r10218 r10352 24 24 #include "nodes.h" 25 25 26 using namespace kxmlcore; 27 26 28 namespace KJS { 27 29 /** … … 41 43 SourceStream& operator<<(Format f); 42 44 SourceStream& operator<<(const Node *); 45 template <typename T> SourceStream& operator<<(SharedPtr<T> n) { return this->operator<<(n.get()); } 43 46 private: 44 47 UString str; /* TODO: buffer */ … … 132 135 void ElementNode::streamTo(SourceStream &s) const 133 136 { 134 for (const ElementNode *n = this; n; n = n->list ) {137 for (const ElementNode *n = this; n; n = n->list.get()) { 135 138 for (int i = 0; i < n->elision; i++) 136 139 s << ","; … … 157 160 void PropertyValueNode::streamTo(SourceStream &s) const 158 161 { 159 for (const PropertyValueNode *n = this; n; n = n->list )162 for (const PropertyValueNode *n = this; n; n = n->list.get()) 160 163 s << n->name << ": " << n->assign; 161 164 } … … 182 185 { 183 186 s << expr; 184 for (ArgumentListNode *n = list ; n; n = n->list)187 for (ArgumentListNode *n = list.get(); n; n = n->list.get()) 185 188 s << ", " << n->expr; 186 189 } … … 443 446 void StatListNode::streamTo(SourceStream &s) const 444 447 { 445 for (const StatListNode *n = this; n; n = n->list )448 for (const StatListNode *n = this; n; n = n->list.get()) 446 449 s << n->statement; 447 450 } … … 460 463 { 461 464 s << var; 462 for (VarDeclListNode *n = list ; n; n = n->list)465 for (VarDeclListNode *n = list.get(); n; n = n->list.get()) 463 466 s << ", " << n->var; 464 467 } … … 578 581 void CaseBlockNode::streamTo(SourceStream &s) const 579 582 { 580 for (const ClauseListNode *n = list1 ; n; n = n->next())583 for (const ClauseListNode *n = list1.get(); n; n = n->next()) 581 584 s << n->clause(); 582 585 if (def) 583 586 s << def; 584 for (const ClauseListNode *n = list2 ; n; n = n->next())587 for (const ClauseListNode *n = list2.get(); n; n = n->next()) 585 588 s << n->clause(); 586 589 } … … 624 627 { 625 628 s << id; 626 for (ParameterNode *n = next ; n; n = n->next)629 for (ParameterNode *n = next.get(); n; n = n->next.get()) 627 630 s << ", " << n->id; 628 631 } … … 644 647 void SourceElementsNode::streamTo(SourceStream &s) const 645 648 { 646 for (const SourceElementsNode *n = this; n; n = n->elements )649 for (const SourceElementsNode *n = this; n; n = n->elements.get()) 647 650 s << n->element; 648 651 }
Note:
See TracChangeset
for help on using the changeset viewer.