00001 #include "stree.h"
00002 #include "streeconstant.h"
00003
00004 bool stringToBool(string value) {
00005 if (value=="0") return false; else return true;
00006 };
00007 string boolToString(bool value) {
00008 if (value) return "1"; else return "0";
00009 };
00010 int stringToInt(string value){
00011 if (value=="")
00012 return 0;
00013 else {
00014 istringstream str(value);
00015 int i;
00016 str >> i;
00017 return i;
00018 }
00019 };
00020 string intToString(int value){
00021 ostringstream str;
00022 str << value;
00023 return str.str();
00024 };
00025
00026
00027 StatementList::StatementList() : NamedList(CStatementList){};
00028
00029 StatementList::StatementList(Node *statement) : NamedList(CStatementList,statement){};
00030
00031 ostream& StatementList::php(ostream &os) const{
00032 const_iterator it = begin();
00033 const_iterator eit = end();
00034 while (it!=eit){
00035 os << (*it);
00036 it++;
00037 };
00038 return os;
00039 };
00040
00041 Node* StatementList::copy() const{
00042 return copyContent(new StatementList());
00043 };
00044
00045 InlineHTMLList::InlineHTMLList() : NamedList(CInlineHTMLList){};
00046
00047 InlineHTMLList::InlineHTMLList(Node *statement) : NamedList(CInlineHTMLList,statement){};
00048
00049 ostream& InlineHTMLList::php(ostream &os) const{
00050 const_iterator it = begin();
00051 const_iterator eit = end();
00052 while (it!=eit){
00053 os << (*it);
00054 it++;
00055 };
00056 return os;
00057 };
00058
00059 Node* InlineHTMLList::copy() const{
00060 return copyContent(new InlineHTMLList());
00061 };
00062
00063 TemplateList::TemplateList() : NamedList(CTemplateList){};
00064
00065 TemplateList::TemplateList(Node *statement) : NamedList(CTemplateList,statement){};
00066
00067 ostream& TemplateList::php(ostream &os) const{
00068 const_iterator it = begin();
00069 const_iterator eit = end();
00070 while (it!=eit){
00071 os << (*it);
00072 it++;
00073 if (it!=eit) os << ",";
00074 };
00075 return os;
00076 };
00077
00078 Node* TemplateList::copy() const{
00079 return copyContent(new TemplateList());
00080 };
00081
00082 ExpressionList::ExpressionList() : NamedList(CExpressionList){};
00083
00084 ExpressionList::ExpressionList(Node *statement) : NamedList(CExpressionList,statement){};
00085
00086 ostream& ExpressionList::php(ostream &os) const{
00087 const_iterator it = begin();
00088 const_iterator eit = end();
00089 while (it!=eit){
00090 (*it)->php(os);
00091 it++;
00092 if (it!=eit) os << ",";
00093 };
00094 return os;
00095 };
00096
00097 Node* ExpressionList::copy() const{
00098 return copyContent(new ExpressionList());
00099 };
00100
00101 ArrayPairList::ArrayPairList() : NamedList(CArrayPairList){};
00102
00103 ArrayPairList::ArrayPairList(Node *statement) : NamedList(CArrayPairList,statement){};
00104
00105 ostream& ArrayPairList::php(ostream &os) const{
00106 const_iterator it = begin();
00107 const_iterator eit = end();
00108 while (it!=eit){
00109 (*it)->php(os);
00110 it++;
00111 if (it!=eit) os << ",";
00112 };
00113 return os;
00114 };
00115
00116 Node* ArrayPairList::copy() const{
00117 return copyContent(new ArrayPairList());
00118 };
00119
00120
00121 DeclareList::DeclareList() : NamedList(CDeclareList){};
00122
00123 DeclareList::DeclareList(Node *statement) : NamedList(CDeclareList,statement){};
00124
00125 ostream& DeclareList::php(ostream &os) const{
00126 const_iterator it = begin();
00127 const_iterator eit = end();
00128 while (it!=eit){
00129 (*it)->php(os);
00130 it++;
00131 if (it!=eit) os<< ",";
00132 };
00133 return os;
00134 };
00135
00136 Node* DeclareList::copy() const{
00137 return copyContent(new DeclareList());
00138 };
00139
00140 CaseList::CaseList() : NamedList(CCaseList){};
00141
00142 CaseList::CaseList(Node *statement) : NamedList(CCaseList,statement){};
00143
00144 ostream& CaseList::php(ostream &os) const{
00145 const_iterator it = begin();
00146 const_iterator eit = end();
00147 while (it!=eit){
00148 (*it)->php(os);
00149 it++;
00150 };
00151 return os;
00152 };
00153
00154 Node* CaseList::copy() const{
00155 return copyContent(new CaseList());
00156 };
00157
00158 EncapsList::EncapsList() : NamedList(CEncapsList){};
00159
00160 EncapsList::EncapsList(Node *statement) : NamedList(CEncapsList,statement){};
00161
00162 ostream& EncapsList::php(ostream &os) const{
00163 const_iterator it = begin();
00164 const_iterator eit = end();
00165 while (it!=eit){
00166 (*it)->php(os);
00167 it++;
00168 };
00169 return os;
00170 };
00171
00172 Node* EncapsList::copy() const{
00173 return copyContent(new EncapsList());
00174 };
00175
00176 string EncapsList::evaluate(const NameSpace &nameSpace) const{
00177 return toString();
00178 };
00179
00180 AssignmentList::AssignmentList() : NamedList(CAssignmentList){};
00181
00182 AssignmentList::AssignmentList(Node *statement) : NamedList(CAssignmentList,statement){};
00183
00184 ostream& AssignmentList::php(ostream &os) const{
00185 const_iterator it = begin();
00186 const_iterator eit = end();
00187 while (it!=eit){
00188 (*it)->php(os);
00189 it++;
00190 if (it!=eit) os<< ",";
00191 };
00192 return os;
00193 };
00194
00195 Node* AssignmentList::copy() const{
00196 return copyContent(new AssignmentList());
00197 };
00198
00199
00200 PHP::PHP(Node *statement) : Unary(CPHP,statement) {};
00201
00202 ostream& PHP::php(ostream &os) const{
00203 os << "<?\n" << getStatement1() << "?>\n";
00204 return os;
00205 };
00206
00207 Node* PHP::copy() const{
00208 return new PHP(getStatement1()->copy());
00209 };
00210
00211 EchoPHP::EchoPHP(Node *statement) : Unary(CEchoPHP,statement) {};
00212
00213 ostream& EchoPHP::php(ostream &os) const{
00214 os << "<?=\n" << getStatement1() << "?>\n";
00215 return os;
00216 };
00217
00218 Node* EchoPHP::copy() const{
00219 return new EchoPHP(getStatement1()->copy());
00220 };
00221
00222 CurlyBraces::CurlyBraces(Node *statement) : Unary(CCurlyBraces,statement) {};
00223
00224 ostream& CurlyBraces::php(ostream &os) const{
00225 os << "{\n" << getStatement1() << "}\n";
00226 return os;
00227 };
00228
00229 Node* CurlyBraces::copy() const{
00230 return new CurlyBraces(getStatement1()->copy());
00231 };
00232
00233 SmartyBraces::SmartyBraces(Node *statement) : Unary(CSmartyBraces,statement) {};
00234
00235 ostream& SmartyBraces::php(ostream &os) const{
00236 os << "{" << getStatement1() << "}";
00237 return os;
00238 };
00239
00240 Node* SmartyBraces::copy() const{
00241 return new SmartyBraces(getStatement1()->copy());
00242 };
00243
00244 DoubleQuote::DoubleQuote(Node *statement) : Unary(CDoubleQuote,statement) {};
00245
00246 ostream& DoubleQuote::php(ostream &os) const{
00247 os << "\"" << getStatement1() << "\"";
00248 return os;
00249 };
00250
00251 Node* DoubleQuote::copy() const{
00252 return new DoubleQuote(getStatement1()->copy());
00253 };
00254
00255 string DoubleQuote::evaluate(const NameSpace &nameSpace) const{
00256 return getStatement1()->evaluate(nameSpace);
00257 };
00258
00259
00260 If::If(Node* statement1, Node* statement2, Node* statement3)
00261 : Ternary(CIf,statement1,statement2,statement3){};
00262
00263 ostream& If::php(ostream &os) const{
00264 os << "if" << "(" << getStatement1() << ")" << getStatement2();
00265 if (getStatement3()->getType()!=SPin) os << "else" << getStatement3();
00266 return os;
00267 };
00268
00269 Node* If::copy() const{
00270 return new If(getStatement1()->copy(),getStatement2()->copy(),getStatement3()->copy());
00271 };
00272
00273 For::For(Node* statement1, Node* statement2, Node* statement3, Node* statement4)
00274 : Quadary(CFor,statement1,statement2,statement3,statement4){};
00275
00276 ostream& For::php(ostream &os) const{
00277 os << "for" << "(" << getStatement1() << ";" << getStatement2() << ";"
00278 << getStatement3() << ")" << endl << getStatement4();
00279 return os;
00280 };
00281
00282 Node* For::copy() const{
00283 return new For(getStatement1()->copy(),getStatement2()->copy(),getStatement3()->copy(),getStatement4()->copy());
00284 };
00285
00286 While::While(Node* statement1, Node* statement2)
00287 : Binary(CWhile,statement1,statement2){};
00288
00289 ostream& While::php(ostream &os) const{
00290 os << "while" << "(" << getStatement1() << ")" << getStatement2();
00291 return os;
00292 };
00293
00294 Node* While::copy() const{
00295 return new While(getStatement1()->copy(),getStatement2()->copy());
00296 };
00297
00298 Do::Do(Node* statement1, Node* statement2)
00299 : Binary(CDo,statement1,statement2){};
00300
00301 ostream& Do::php(ostream &os) const{
00302 os << "do" << getStatement1() << "while(" << getStatement2() << ");\n";
00303 return os;
00304 };
00305
00306 Node* Do::copy() const{
00307 return new Do(getStatement1()->copy(),getStatement2()->copy());
00308 };
00309
00310 Switch::Switch(Node* statement1, Node* statement2)
00311 : Binary(CSwitch,statement1,statement2){};
00312
00313 ostream& Switch::php(ostream &os) const{
00314 os << "switch(" << getStatement1() << ")" << getStatement2();
00315 return os;
00316 };
00317
00318 Node* Switch::copy() const{
00319 return new Switch(getStatement1()->copy(),getStatement2()->copy());
00320 };
00321
00322 Break::Break(Node *statement) : Unary(CBreak,statement) {};
00323
00324 ostream& Break::php(ostream &os) const{
00325 os << "break " << getStatement1();
00326 return os << ";\n";
00327 };
00328
00329 Node* Break::copy() const{
00330 return new Break(getStatement1()->copy());
00331 };
00332
00333 Continue::Continue(Node *statement) : Unary(CContinue,statement) {};
00334
00335 ostream& Continue::php(ostream &os) const{
00336 os << "continue " << getStatement1();
00337 return os << ";\n";
00338 };
00339
00340 Node* Continue::copy() const{
00341 return new Continue(getStatement1()->copy());
00342 };
00343
00344 Return::Return(Node *statement) : Unary(CReturn,statement) {};
00345
00346 ostream& Return::php(ostream &os) const{
00347 os << "return " << getStatement1();
00348 return os << ";\n";
00349 };
00350
00351 Node* Return::copy() const{
00352 return new Return(getStatement1()->copy());
00353 };
00354
00355 Global::Global(Node *statement) : Unary(CGlobal,statement) {};
00356
00357 ostream& Global::php(ostream &os) const{
00358 os << "global " << getStatement1() << ";\n";
00359 return os;
00360 };
00361
00362 Node* Global::copy() const{
00363 return new Global(getStatement1()->copy());
00364 };
00365
00366 Static::Static(Node *statement) : Unary(CStatic,statement) {};
00367
00368 ostream& Static::php(ostream &os) const{
00369 os << "static " << getStatement1() << ";\n";
00370 return os;
00371 };
00372
00373 Node* Static::copy() const{
00374 return new Static(getStatement1()->copy());
00375 };
00376
00377 Echo::Echo(Node *statement) : Unary(CEcho,statement) {};
00378
00379 ostream& Echo::php(ostream &os) const{
00380 os << "echo " << getStatement1() << ";\n";
00381 return os;
00382 };
00383
00384 Node* Echo::copy() const{
00385 return new Echo(getStatement1()->copy());
00386 };
00387
00388 Template::Template(Node *statement) : Unary(CTemplate,statement) {};
00389
00390 ostream& Template::php(ostream &os) const{
00391 os << getStatement1() << "\n";
00392 return os;
00393 };
00394
00395 Node* Template::copy() const{
00396 return new Template(getStatement1()->copy());
00397 };
00398
00399 SmartyAssign::SmartyAssign(Node* statement1, Node* statement2)
00400 : Binary(CSmartyAssign,statement1,statement2){};
00401
00402 SmartyAssign::SmartyAssign(Node* statement1, Node* statement2, string iphpOut)
00403 : Binary(CSmartyAssign,statement1,statement2), phpOut(iphpOut) {};
00404
00405 ostream& SmartyAssign::php(ostream &os) const{
00406 os << phpOut;
00407 return os;
00408 };
00409
00410 const Node* SmartyAssign::getVariable() const{
00411 return getStatement1();
00412 };
00413
00414 const Node* SmartyAssign::getAssignment() const{
00415 return getStatement2();
00416 };
00417
00418 void SmartyAssign::setPHPOut(string iphpOut) {
00419 phpOut = iphpOut;
00420 };
00421
00422 Node* SmartyAssign::copy() const{
00423 return new SmartyAssign(getStatement1()->copy(),getStatement2()->copy(), phpOut);
00424 };
00425
00426 InlineHTML::InlineHTML(Node *statement) : Unary(CInlineHTML,statement) {};
00427
00428 ostream& InlineHTML::php(ostream &os) const{
00429 os << getStatement1();
00430 return os;
00431 };
00432
00433 Node* InlineHTML::copy() const{
00434 return new InlineHTML(getStatement1()->copy());
00435 };
00436
00437 string InlineHTML::getHTML() const{
00438 return dynamic_cast<const Constant *>(getStatement1())->getValue();
00439 };
00440
00441 void InlineHTML::setHTML(const string &html){
00442 delete *begin();
00443 *begin() = new Constant(html);
00444 };
00445
00446
00447 Expression::Expression(Node *statement) : Unary(CExpression,statement) {};
00448
00449 ostream& Expression::php(ostream &os) const{
00450 os << getStatement1() << ";\n";
00451 return os;
00452 };
00453
00454 Node* Expression::copy() const{
00455 return new Expression(getStatement1()->copy());
00456 };
00457
00458 Unset::Unset(Node *statement) : Unary(CUnset,statement) {};
00459
00460 ostream& Unset::php(ostream &os) const{
00461 os << "unset (" << getStatement1() << ");\n";
00462 return os;
00463 };
00464
00465 Node* Unset::copy() const{
00466 return new Unset(getStatement1()->copy());
00467 };
00468
00469 Use::Use(Node *statement) : Unary(CUse,statement) {};
00470
00471 ostream& Use::php(ostream &os) const{
00472 os << "use " << getStatement1() << ";\n";
00473 return os;
00474 };
00475
00476 Node* Use::copy() const{
00477 return new Use(getStatement1()->copy());
00478 };
00479
00480 Foreach::Foreach(Node* statement1, Node* statement2, Node* statement3, Node* statement4)
00481 : Quadary(CForeach,statement1,statement2,statement3,statement4){};
00482
00483 ostream& Foreach::php(ostream &os) const{
00484 os << "foreach" << "(" << getStatement1() << "as" << getStatement2();
00485 if (getStatement3()->getType()!=SPin) os << "=>" << getStatement3();
00486 os << ")" << getStatement4();
00487 return os;
00488 };
00489
00490 Node* Foreach::copy() const{
00491 return new Foreach(getStatement1()->copy(),getStatement2()->copy(),getStatement3()->copy(),getStatement4()->copy());
00492 };
00493
00494 Declare::Declare(Node* statement1, Node* statement2)
00495 : Binary(CDeclare,statement1,statement2){};
00496
00497 ostream& Declare::php(ostream &os) const{
00498 os << "declare(" << getStatement1() << ")" << getStatement2();
00499 return os;
00500 };
00501
00502 Node* Declare::copy() const{
00503 return new Declare(getStatement1()->copy(),getStatement2()->copy());
00504 };
00505
00506 EmptyStatement::EmptyStatement() : Nullary(CEmptyStatement) {};
00507
00508 ostream& EmptyStatement::php(ostream &os) const{
00509 return os << ";\n";
00510 };
00511
00512 Node* EmptyStatement::copy() const{
00513 return new EmptyStatement();
00514 };
00515
00516 Function::Function(Node* statement1, Node* statement2, Node* statement3, Node* statement4)
00517 : Quadary(CFunction,statement1,statement2,statement3,statement4){};
00518
00519 ostream& Function::php(ostream &os) const{
00520 os << "function " << getStatement1() << getStatement2() << "("
00521 << getStatement3() << ")" << endl << "{" << endl << getStatement4() << "}" << endl;
00522 return os;
00523 };
00524
00525 Node* Function::copy() const{
00526 return new Function(getStatement1()->copy(),getStatement2()->copy(),getStatement3()->copy(),getStatement4()->copy());
00527 };
00528
00529 Class::Class(Node* statement1, Node* statement2, Node* statement3)
00530 : Ternary(CClass,statement1,statement2,statement3){};
00531
00532 ostream& Class::php(ostream &os) const{
00533 os << "class" << getStatement1();
00534 if (getStatement2()->getType()!=SPin) os << "extends" << getStatement2();
00535 os << "{" << getStatement3() << "}";
00536 return os;
00537 };
00538
00539 Node* Class::copy() const{
00540 return new Class(getStatement1()->copy(),getStatement2()->copy(),getStatement3()->copy());
00541 };
00542
00543 Const::Const(Node* statement1, Node* statement2)
00544 : Binary(CConst,statement1,statement2){};
00545
00546 ostream& Const::php(ostream &os) const{
00547 os << getStatement1() << "=" << getStatement2();
00548 return os;
00549 };
00550
00551 Node* Const::copy() const{
00552 return new Const(getStatement1()->copy(),getStatement2()->copy());
00553 };
00554
00555 Case::Case(Node* statement1, Node* statement2)
00556 : Binary(CCase,statement1,statement2){};
00557
00558 ostream& Case::php(ostream &os) const{
00559 if (getStatement1()->getType()!=SPin){
00560 os << "case" << getStatement1() << ":" << getStatement2();
00561 } else {
00562 os << "default :" << getStatement2();
00563 }
00564 return os;
00565 };
00566
00567 Node* Case::copy() const{
00568 return new Case(getStatement1()->copy(),getStatement2()->copy());
00569 };
00570
00571 Parameter::Parameter(Node* statement1, Node* statement2, Node* statement3)
00572 : Ternary(CParameter,statement1,statement2,statement3){};
00573
00574 ostream& Parameter::php(ostream &os) const{
00575 if (getStatement1()->getType()!=SPin) os << getStatement1();
00576 os << getStatement2();
00577 if (getStatement3()->getType()!=SPin) os << "=" << getStatement3();
00578 return os;
00579 };
00580
00581 Node* Parameter::copy() const{
00582 return new Parameter(getStatement1()->copy(),getStatement2()->copy(),getStatement3()->copy());
00583 };
00584
00585
00586 ClassVariable::ClassVariable(Node *statement) : Unary(CClassVariable,statement) {};
00587
00588 ostream& ClassVariable::php(ostream &os) const{
00589 os << "var " << getStatement1() << ";\n";
00590 return os;
00591 };
00592
00593 Node* ClassVariable::copy() const{
00594 return new ClassVariable(getStatement1()->copy());
00595 };
00596
00597 UnaryOperator::UnaryOperator(string oname, Node* statement2)
00598 : Binary(CUnaryOperator,new Constant(oname),statement2) {};
00599
00600 ostream& UnaryOperator::php(ostream &os) const{
00601 os << getStatement1() << getStatement2();
00602 return os;
00603 };
00604
00605 Node* UnaryOperator::copy() const{
00606 return new UnaryOperator(dynamic_cast<const Constant*>(getStatement1())->getValue(),getStatement2()->copy());
00607 };
00608
00609 string UnaryOperator::evaluate(const NameSpace &nameSpace) const{
00610 string o = dynamic_cast<const Constant*>(getStatement1())->getValue();
00611 if (o == "++")
00612 return intToString(stringToInt(getStatement2()->evaluate(nameSpace))+1);
00613 else if (o == "--")
00614 return intToString(stringToInt(getStatement2()->evaluate(nameSpace))-1);
00615 else if (o == "+")
00616 return getStatement2()->evaluate(nameSpace);
00617 else if (o == "-")
00618 return intToString(-stringToInt(getStatement2()->evaluate(nameSpace)));
00619 else if (o == "!")
00620 return boolToString(!stringToBool(getStatement2()->evaluate(nameSpace)));
00621 else throw "ERROR: UnaryOperator::evaluate - operation " + o + " not implemented";
00622 }
00623
00624 PostUnaryOperator::PostUnaryOperator(string oname, Node* statement2)
00625 : Binary(CPostUnaryOperator,new Constant(oname),statement2){};
00626
00627 ostream& PostUnaryOperator::php(ostream &os) const{
00628 os << getStatement2() << getStatement1();
00629 return os;
00630 };
00631
00632 Node* PostUnaryOperator::copy() const{
00633 return new PostUnaryOperator(dynamic_cast<const Constant*>(getStatement1())->getValue(),getStatement2()->copy());
00634 };
00635
00636 string PostUnaryOperator::evaluate(const NameSpace &nameSpace) const{
00637 string o = dynamic_cast<const Constant*>(getStatement1())->getValue();
00638 if (o == "++")
00639 return intToString(stringToInt(getStatement2()->evaluate(nameSpace))+1);
00640 else if (o == "--")
00641 return intToString(stringToInt(getStatement2()->evaluate(nameSpace))-1);
00642 else throw "ERROR: PostUnaryOperator::evaluate - operation " + o + " not implemented";
00643 }
00644
00645 BinaryOperator::BinaryOperator(string oname, Node* statement2, Node* statement3)
00646 : Ternary(CBinaryOperator,new Constant(oname),statement2,statement3){};
00647 BinaryOperator::BinaryOperator(Node* ioperator, Node* statement2, Node* statement3)
00648 : Ternary(CBinaryOperator, ioperator ,statement2,statement3){};
00649
00650 ostream& BinaryOperator::php(ostream &os) const{
00651 os << getStatement2() << " "<< getStatement1() << " " << getStatement3();
00652 return os;
00653 };
00654
00655 Node* BinaryOperator::copy() const{
00656 return new BinaryOperator(dynamic_cast<const Constant*>(getStatement1())->getValue(),getStatement2()->copy(),getStatement3()->copy());
00657 };
00658
00659 string BinaryOperator::evaluate(const NameSpace &nameSpace) const{
00660 string o = dynamic_cast<const Constant*>(getStatement1())->getValue();
00661 if (o == "OR")
00662 return boolToString(stringToBool(getStatement2()->evaluate(nameSpace)) || stringToBool(getStatement3()->evaluate(nameSpace)));
00663 else if (o == "AND")
00664 return boolToString(stringToBool(getStatement2()->evaluate(nameSpace)) && stringToBool(getStatement3()->evaluate(nameSpace)));
00665 else if (o == "XOR")
00666 return boolToString(stringToBool(getStatement2()->evaluate(nameSpace)) xor stringToBool(getStatement3()->evaluate(nameSpace)));
00667 else if (o == ".")
00668 return getStatement2()->evaluate(nameSpace) + getStatement3()->evaluate(nameSpace);
00669 else if (o == "+")
00670 return intToString(stringToInt(getStatement2()->evaluate(nameSpace)) + stringToInt(getStatement3()->evaluate(nameSpace)));
00671 else if (o == "-")
00672 return intToString(stringToInt(getStatement2()->evaluate(nameSpace)) - stringToInt(getStatement3()->evaluate(nameSpace)));
00673 else if (o == "*")
00674 return intToString(stringToInt(getStatement2()->evaluate(nameSpace)) * stringToInt(getStatement3()->evaluate(nameSpace)));
00675 else if (o == "%")
00676 return intToString(stringToInt(getStatement2()->evaluate(nameSpace)) % stringToInt(getStatement3()->evaluate(nameSpace)));
00677 else if (o == "/")
00678 return intToString(stringToInt(getStatement2()->evaluate(nameSpace)) / stringToInt(getStatement3()->evaluate(nameSpace)));
00679 else if (o == "==")
00680 return boolToString(getStatement2()->evaluate(nameSpace) == getStatement3()->evaluate(nameSpace));
00681 else if (o == "!=")
00682 return boolToString(getStatement2()->evaluate(nameSpace) != getStatement3()->evaluate(nameSpace));
00683 else if (o == "<")
00684 return intToString(stringToInt(getStatement2()->evaluate(nameSpace)) < stringToInt(getStatement3()->evaluate(nameSpace)));
00685 else if (o == "<=")
00686 return intToString(stringToInt(getStatement2()->evaluate(nameSpace)) <= stringToInt(getStatement3()->evaluate(nameSpace)));
00687 else if (o == ">")
00688 return intToString(stringToInt(getStatement2()->evaluate(nameSpace)) > stringToInt(getStatement3()->evaluate(nameSpace)));
00689 else if (o == ">=")
00690 return intToString(stringToInt(getStatement2()->evaluate(nameSpace)) >= stringToInt(getStatement3()->evaluate(nameSpace)));
00691 else throw "ERROR: BinaryOperator::evaluate - operation " + o + " not implemented";
00692 };
00693
00694
00695 AList::AList(Node *statement) : Unary(CAList,statement) {};
00696
00697 ostream& AList::php(ostream &os) const{
00698 os << "list(" << getStatement1() << ")";
00699 return os;
00700 };
00701
00702 Node* AList::copy() const{
00703 return new AList(getStatement1()->copy());
00704 };
00705
00706
00707 EncapsExpr::EncapsExpr(string ebegin, Node *statement, string eend) : Ternary(CEncapsExpr,new Constant(ebegin),statement, new Constant(eend)) {};
00708
00709 ostream& EncapsExpr::php(ostream &os) const{
00710 os << getStatement1() << getStatement2() << getStatement3();
00711 return os;
00712 };
00713
00714 Node* EncapsExpr::copy() const{
00715 return new EncapsExpr(dynamic_cast<const Constant*>(getStatement1())->getValue(),
00716 getStatement2()->copy(),
00717 dynamic_cast<const Constant*>(getStatement3())->getValue());
00718 };
00719
00720 string EncapsExpr::evaluate(const NameSpace &nameSpace) const{
00721 return getStatement2()->evaluate(nameSpace);
00722 };
00723
00724
00725 AskOperator::AskOperator(Node* statement1, Node* statement2, Node* statement3)
00726 : Ternary(CAskOperator,statement1,statement2,statement3){};
00727
00728 ostream& AskOperator::php(ostream &os) const{
00729 os << getStatement1() << "?" << getStatement2() << ":" << getStatement3();
00730 return os;
00731 };
00732
00733 Node* AskOperator::copy() const{
00734 return new AskOperator(getStatement1()->copy(),getStatement2()->copy(),getStatement3()->copy());
00735 };
00736
00737 string AskOperator::evaluate(const NameSpace &nameSpace) const{
00738 return (getStatement1()->evaluate(nameSpace)=="0") ? getStatement2()->evaluate(nameSpace) : getStatement3()->evaluate(nameSpace);
00739 };
00740
00741
00742 Exit::Exit(Node *statement) : Unary(CExit,statement) {};
00743
00744 ostream& Exit::php(ostream &os) const{
00745 os << "exit(" << getStatement1() << ")";
00746 return os;
00747 };
00748
00749 Node* Exit::copy() const{
00750 return new Exit(getStatement1()->copy());
00751 };
00752
00753 Print::Print(Node *statement) : Unary(CPrint,statement) {};
00754
00755 ostream& Print::php(ostream &os) const{
00756 os << "print " << getStatement1();
00757 return os;
00758 };
00759
00760 Node* Print::copy() const{
00761 return new Print(getStatement1()->copy());
00762 };
00763
00764 Array::Array(Node *statement) : Unary(CArray,statement) {};
00765
00766 ostream& Array::php(ostream &os) const{
00767 os << "array(" << getStatement1() << ")";
00768 return os;
00769 };
00770
00771 Node* Array::copy() const{
00772 return new Array(getStatement1()->copy());
00773 };
00774
00775 FunctionCall::FunctionCall(Node* statement1, Node* statement2, Node* statement3)
00776 : Ternary(CFunctionCall,statement1,statement2,statement3){};
00777
00778 ostream& FunctionCall::php(ostream &os) const{
00779 if (getStatement1()->getType()!=SPin)
00780 os << getStatement1() << "::";
00781 os << getStatement2() << "(" << getStatement3() << ")";
00782 return os;
00783 };
00784
00785 Node* FunctionCall::copy() const{
00786 return new FunctionCall(getStatement1()->copy(),getStatement2()->copy(),getStatement3()->copy());
00787 };
00788
00789
00790 ArrayPair::ArrayPair(Node* statement1, Node* statement2)
00791 : Binary(CArrayPair,statement1,statement2){};
00792
00793 ostream& ArrayPair::php(ostream &os) const{
00794
00795 if (getStatement1()->getType()!=SPin)
00796 os << getStatement1() << "=>";
00797
00798 os << getStatement2();
00799
00800 return os;
00801 };
00802
00803 Node* ArrayPair::copy() const{
00804 return new ArrayPair(getStatement1()->copy(),getStatement2()->copy());
00805 };
00806
00807 ObjectOperator::ObjectOperator(Node* statement1, Node* statement2)
00808 : Binary(CObjectOperator,statement1,statement2){};
00809
00810 ostream& ObjectOperator::php(ostream &os) const{
00811 os << getStatement1() << "->" << getStatement2();
00812 return os;
00813 };
00814
00815 Node* ObjectOperator::copy() const{
00816 return new ObjectOperator(getStatement1()->copy(),getStatement2()->copy());
00817 };
00818
00819 ArrayOperator::ArrayOperator(Node* statement1, Node* statement2)
00820 : Binary(CArrayOperator,statement1,statement2){};
00821
00822 ostream& ArrayOperator::php(ostream &os) const{
00823 os << getStatement1() << "[" << getStatement2() << "]";
00824 return os;
00825 };
00826
00827 Node* ArrayOperator::copy() const{
00828 return new ArrayOperator(getStatement1()->copy(),getStatement2()->copy());
00829 };
00830
00831 MapOperator::MapOperator(Node* statement1, Node* statement2)
00832 : Binary(CMapOperator,statement1,statement2){};
00833
00834 ostream& MapOperator::php(ostream &os) const{
00835 os << getStatement1() << "{" << getStatement2() << "}";
00836 return os;
00837 };
00838
00839 Node* MapOperator::copy() const{
00840 return new MapOperator(getStatement1()->copy(),getStatement2()->copy());
00841 };
00842
00843 Ref::Ref(Node* statement)
00844 : UnaryOperator(OpRef,statement){};
00845
00846
00847 Isset::Isset(Node *statement) : Unary(CIsset,statement) {};
00848
00849 ostream& Isset::php(ostream &os) const{
00850 os << "isset(" << getStatement1() << ")";
00851 return os;
00852 };
00853
00854 Node* Isset::copy() const{
00855 return new Isset(getStatement1()->copy());
00856 };
00857
00858 ConstantEncapsedString::ConstantEncapsedString(Node *statement) : Unary(CConstantEncapsedString,statement) {};
00859
00860 ostream& ConstantEncapsedString::php(ostream &os) const{
00861 os << "'" << getStatement1() << "'";
00862 return os;
00863 };
00864
00865 Node* ConstantEncapsedString::copy() const{
00866 return new ConstantEncapsedString(getStatement1()->copy());
00867 };
00868
00869 string ConstantEncapsedString::evaluate(const NameSpace &nameSpace) const{
00870 return getStatement1()->evaluate(nameSpace);
00871 };
00872
00873 PHPVariable::PHPVariable(Node *statement) : Unary(CPHPVariable,statement) {};
00874
00875 ostream& PHPVariable::php(ostream &os) const{
00876 os << getStatement1();
00877 return os;
00878 };
00879
00880 Node* PHPVariable::copy() const{
00881 return new PHPVariable(getStatement1()->copy());
00882 };
00883
00884 ConstantString::ConstantString(Node *statement) : Unary(CConstantString,statement) {};
00885
00886 ostream& ConstantString::php(ostream &os) const{
00887 os << getStatement1();
00888 return os;
00889 };
00890
00891 Node* ConstantString::copy() const{
00892 return new ConstantString(getStatement1()->copy());
00893 };
00894
00895 string ConstantString::evaluate(const NameSpace &nameSpace) const{
00896 return getStatement1()->evaluate(nameSpace);
00897 };