]>
git.saurik.com Git - cycript.git/blob - Output.cpp
0728e82ccd38f5f3d5404e25a2f9d79f85633602
   6 _finline CYFlags 
operator ~(CYFlags rhs
) { 
   7     return static_cast<CYFlags
>(~static_cast<unsigned>(rhs
)); 
  10 _finline CYFlags 
operator &(CYFlags lhs
, CYFlags rhs
) { 
  11     return static_cast<CYFlags
>(static_cast<unsigned>(lhs
) & static_cast<unsigned>(rhs
)); 
  14 _finline CYFlags 
operator |(CYFlags lhs
, CYFlags rhs
) { 
  15     return static_cast<CYFlags
>(static_cast<unsigned>(lhs
) | static_cast<unsigned>(rhs
)); 
  18 _finline CYFlags 
&operator |=(CYFlags 
&lhs
, CYFlags rhs
) { 
  19     return lhs 
= lhs 
| rhs
; 
  22 _finline CYFlags 
CYLeft(CYFlags flags
) { 
  23     return flags 
& ~CYNoTrailer
; 
  26 _finline CYFlags 
CYCenter(CYFlags flags
) { 
  27     return flags 
& CYNoIn
; 
  30 _finline CYFlags 
CYRight(CYFlags flags
) { 
  31     return flags 
& (CYNoIn 
| CYNoTrailer
); 
  34 bool CYFalse::Value() const { 
  38 bool CYTrue::Value() const { 
  44 void CYAddressOf::Output(std::ostream 
&out
, CYFlags flags
) const { 
  45     rhs_
->Output(out
, 1, CYLeft(flags
)); 
  49 void CYArgument::Output(std::ostream 
&out
) const { 
  56         value_
->Output(out
, CYPA
, CYNoFlags
); 
  58         if (next_
->name_ 
== NULL
) 
  66 void CYArray::Output(std::ostream 
&out
, CYFlags flags
) const { 
  68     if (elements_ 
!= NULL
) 
  69         elements_
->Output(out
); 
  73 void CYAssignment::Output(std::ostream 
&out
, CYFlags flags
) const { 
  74     lhs_
->Output(out
, Precedence() - 1, CYLeft(flags
)); 
  76     rhs_
->Output(out
, Precedence(), CYRight(flags
)); 
  79 void CYBoolean::Output(std::ostream 
&out
, CYFlags flags
) const { 
  80     if ((flags 
& CYNoLeader
) != 0) 
  82     out 
<< (Value() ? "true" : "false"); 
  83     if ((flags 
& CYNoTrailer
) != 0) 
  87 void CYBreak::Output(std::ostream 
&out
) const { 
  90         out 
<< ' ' << *label_
; 
  94 void CYCall::Output(std::ostream 
&out
, CYFlags flags
) const { 
  95     function_
->Output(out
, Precedence(), CYLeft(flags
)); 
  97     if (arguments_ 
!= NULL
) 
  98         arguments_
->Output(out
); 
 102 void CYCatch::Output(std::ostream 
&out
) const { 
 103     out 
<< "catch(" << *name_ 
<< ')'; 
 104     code_
->Output(out
, true); 
 107 void CYClass::Output(std::ostream 
&out
) const { 
 108     out 
<< "(function($cys,$cyc,$cym,$cyn,$cyt){"; 
 109     out 
<< "$cyc=objc_allocateClassPair($cys,\"" << *name_ 
<< "\",0);"; 
 110     out 
<< "$cym=object_getClass($cyc);"; 
 112         fields_
->Output(out
); 
 113     if (messages_ 
!= NULL
) 
 114         messages_
->Output(out
); 
 115     out 
<< "objc_registerClassPair($cyc);"; 
 118         super_
->Output(out
, CYPA
, CYNoFlags
); 
 124 void CYCondition::Output(std::ostream 
&out
, CYFlags flags
) const { 
 125     test_
->Output(out
, Precedence() - 1, CYLeft(flags
)); 
 128         true_
->Output(out
, CYPA
, CYNoFlags
); 
 130     false_
->Output(out
, CYPA
, CYRight(flags
)); 
 133 void CYContinue::Output(std::ostream 
&out
) const { 
 136         out 
<< ' ' << *label_
; 
 140 void CYClause::Output(std::ostream 
&out
) const { 
 143         case_
->Output(out
, CYNoFlags
); 
 148         code_
->Output(out
, false); 
 152 // XXX: deal with NoIn 
 153 void CYDeclaration::Part(std::ostream 
&out
) const { 
 158 void CYDeclaration::Output(std::ostream 
&out
) const { 
 160     if (initialiser_ 
!= NULL
) { 
 162         initialiser_
->Output(out
, CYPA
, CYNoFlags
); 
 166 // XXX: deal with NoIn 
 167 void CYDeclarations::Part(std::ostream 
&out
) const { 
 170     const CYDeclarations 
*declaration(this); 
 172     out 
<< *declaration
->declaration_
; 
 173     declaration 
= declaration
->next_
; 
 175     if (declaration 
!= NULL
) { 
 181 void CYDeclarations::Output(std::ostream 
&out
) const { 
 186 void CYDoWhile::Output(std::ostream 
&out
) const { 
 187     // XXX: extra space character! 
 189     code_
->Output(out
, false); 
 191     test_
->Output(out
, CYNoFlags
); 
 195 void CYElement::Output(std::ostream 
&out
) const { 
 197         value_
->Output(out
, CYPA
, CYNoFlags
); 
 198     if (next_ 
!= NULL 
|| value_ 
== NULL
) 
 204 void CYEmpty::Output(std::ostream 
&out
) const { 
 208 void CYEmpty::Output(std::ostream 
&out
, bool block
) const { 
 210         CYSource::Output(out
, block
); 
 215 void CYExpress::Output(std::ostream 
&out
) const { 
 216     expression_
->Output(out
, CYNoFunction 
| CYNoBrace
); 
 220 void CYExpression::Part(std::ostream 
&out
) const { 
 221     // XXX: this should handle LeftHandSideExpression 
 225 void CYCompound::Output(std::ostream 
&out
, CYFlags flags
) const { 
 226     if (CYExpression 
*expression 
= expressions_
) 
 227         if (CYExpression 
*next 
= expression
->next_
) { 
 228             expression
->Output(out
, CYLeft(flags
)); 
 229             CYFlags 
center(CYCenter(flags
)); 
 230             while (next 
!= NULL
) { 
 233                 next 
= expression
->next_
; 
 234                 CYFlags 
right(next 
!= NULL 
? center 
: CYRight(flags
)); 
 235                 expression
->Output(out
, right
); 
 238             expression
->Output(out
, flags
); 
 241 void CYExpression::Output(std::ostream 
&out
, unsigned precedence
, CYFlags flags
) const { 
 242     if (precedence 
< Precedence()) { 
 244         Output(out
, CYNoFlags
); 
 250 void CYField::Output(std::ostream 
&out
) const { 
 254 void CYFor::Output(std::ostream 
&out
) const { 
 256     if (initialiser_ 
!= NULL
) 
 257         initialiser_
->Part(out
); 
 260         test_
->Output(out
, CYNoFlags
); 
 262     if (increment_ 
!= NULL
) 
 263         increment_
->Output(out
, CYNoFlags
); 
 265     code_
->Output(out
, false); 
 268 void CYForIn::Output(std::ostream 
&out
) const { 
 270     initialiser_
->Part(out
); 
 271     // XXX: deal with this space character! 
 274     set_
->Output(out
, CYNoLeader
); 
 276     code_
->Output(out
, false); 
 279 void CYFunction::Output(std::ostream 
&out
) const { 
 280     CYLambda::Output(out
, CYNoFlags
); 
 283 void CYFunctionParameter::Output(std::ostream 
&out
) const { 
 291 void CYIf::Output(std::ostream 
&out
) const { 
 293     test_
->Output(out
, CYNoFlags
); 
 295     true_
->Output(out
, true); 
 296     if (false_ 
!= NULL
) { 
 298         false_
->Output(out
, false); 
 302 void CYIndirect::Output(std::ostream 
&out
, CYFlags flags
) const { 
 303     rhs_
->Output(out
, 1, CYLeft(flags
)); 
 307 void CYInfix::Output(std::ostream 
&out
, CYFlags flags
) const { 
 308     const char *name(Operator()); 
 309     bool protect((flags 
& CYNoIn
) != 0 && strcmp(name
, "in")); 
 312     bool alphabetic(Alphabetic()); 
 313     CYFlags 
left(protect 
? CYNoFlags 
: CYLeft(flags
)); 
 316     lhs_
->Output(out
, Precedence(), left
); 
 318     CYFlags 
right(protect 
? CYNoFlags 
: CYRight(flags
)); 
 321     rhs_
->Output(out
, Precedence() - 1, right
); 
 326 void CYLambda::Output(std::ostream 
&out
, CYFlags flags
) const { 
 327     bool protect((flags 
& CYNoFunction
) != 0); 
 332         out 
<< ' ' << *name_
; 
 334     if (parameters_ 
!= NULL
) 
 344 void CYMember::Output(std::ostream 
&out
, CYFlags flags
) const { 
 345     object_
->Output(out
, Precedence(), CYLeft(flags
)); 
 346     if (const char *word 
= property_
->Word()) 
 350         property_
->Output(out
, CYNoFlags
); 
 355 void CYMessage::Output(std::ostream 
&out
) const { 
 358     out 
<< "$cyn=new Selector(\""; 
 359     for (CYMessageParameter 
*parameter(parameter_
); parameter 
!= NULL
; parameter 
= parameter
->next_
) 
 360         if (parameter
->tag_ 
!= NULL
) { 
 361             out 
<< *parameter
->tag_
; 
 362             if (parameter
->name_ 
!= NULL
) 
 366     out 
<< "$cyt=$cyn.type($cys," << (instance_ 
? "true" : "false") << ");"; 
 367     out 
<< "class_addMethod($cy" << (instance_ 
? 'c' : 'm') << ",$cyn,"; 
 368     out 
<< "new Functor(function(self,_cmd"; 
 369     for (CYMessageParameter 
*parameter(parameter_
); parameter 
!= NULL
; parameter 
= parameter
->next_
) 
 370         if (parameter
->name_ 
!= NULL
) 
 371             out 
<< ',' << *parameter
->name_
; 
 372     out 
<< "){return function(){"; 
 375     out 
<< "}.call(self);},$cyt),$cyt);"; 
 378 void CYNew::Output(std::ostream 
&out
, CYFlags flags
) const { 
 380     constructor_
->Output(out
, Precedence(), CYCenter(flags
) | CYNoLeader
); 
 382     if (arguments_ 
!= NULL
) 
 383         arguments_
->Output(out
); 
 387 void CYNull::Output(std::ostream 
&out
, CYFlags flags
) const { 
 388     if ((flags 
& CYNoLeader
) != 0) 
 391     if ((flags 
& CYNoTrailer
) != 0) 
 395 void CYNumber::Output(std::ostream 
&out
, CYFlags flags
) const { 
 396     if ((flags 
& CYNoLeader
) != 0) 
 398     // XXX: this is not a useful formatting 
 400     if ((flags 
& CYNoTrailer
) != 0) 
 404 void CYObject::Output(std::ostream 
&out
, CYFlags flags
) const { 
 405     bool protect((flags 
& CYNoBrace
) != 0); 
 409     if (property_ 
!= NULL
) 
 410         property_
->Output(out
); 
 416 void CYPostfix::Output(std::ostream 
&out
, CYFlags flags
) const { 
 417     lhs_
->Output(out
, Precedence(), CYLeft(flags
)); 
 421 void CYPrefix::Output(std::ostream 
&out
, CYFlags flags
) const { 
 422     bool alphabetic(Alphabetic()); 
 424     CYFlags 
right(CYRight(flags
)); 
 427     rhs_
->Output(out
, Precedence(), right
); 
 430 void CYProperty::Output(std::ostream 
&out
) const { 
 433     value_
->Output(out
, CYPA
, CYNoFlags
); 
 440 void CYReturn::Output(std::ostream 
&out
) const { 
 443         value_
->Output(out
, CYNoLeader
); 
 447 void CYSelector::Output(std::ostream 
&out
, CYFlags flags
) const { 
 448     out 
<< "new Selector(\""; 
 454 void CYSelectorPart::Output(std::ostream 
&out
) const { 
 463 void CYSend::Output(std::ostream 
&out
, CYFlags flags
) const { 
 464     out 
<< "objc_msgSend("; 
 465     self_
->Output(out
, CYPA
, CYNoFlags
); 
 467     for (CYArgument 
*argument(arguments_
); argument 
!= NULL
; argument 
= argument
->next_
) 
 468         if (argument
->name_ 
!= NULL
) { 
 469             out 
<< *argument
->name_
; 
 470             if (argument
->value_ 
!= NULL
) 
 474     for (CYArgument 
*argument(arguments_
); argument 
!= NULL
; argument 
= argument
->next_
) 
 475         if (argument
->value_ 
!= NULL
) { 
 477             argument
->value_
->Output(out
, CYPA
, CYNoFlags
); 
 482 void CYSource::Show(std::ostream 
&out
) const { 
 483     for (const CYSource 
*next(this); next 
!= NULL
; next 
= next
->next_
) 
 487 void CYSource::Output(std::ostream 
&out
, bool block
) const { 
 488     if (!block 
&& next_ 
== NULL
) 
 497 void CYString::Output(std::ostream 
&out
, CYFlags flags
) const { 
 499     for (const char *value(value_
), *end(value_ 
+ size_
); value 
!= end
; ++value
) 
 501             case '"': out 
<< "\\\""; break; 
 502             case '\\': out 
<< "\\\\"; break; 
 503             case '\b': out 
<< "\\b"; break; 
 504             case '\f': out 
<< "\\f"; break; 
 505             case '\n': out 
<< "\\n"; break; 
 506             case '\r': out 
<< "\\r"; break; 
 507             case '\t': out 
<< "\\t"; break; 
 508             case '\v': out 
<< "\\v"; break; 
 511                 if (*value 
< 0x20 || *value 
>= 0x7f) 
 512                     out 
<< "\\x" << std::setbase(16) << std::setw(2) << std::setfill('0') << unsigned(*value
); 
 519 void CYSwitch::Output(std::ostream 
&out
) const { 
 521     value_
->Output(out
, CYNoFlags
); 
 523     if (clauses_ 
!= NULL
) 
 528 void CYThis::Output(std::ostream 
&out
, CYFlags flags
) const { 
 529     if ((flags 
& CYNoLeader
) != 0) 
 532     if ((flags 
& CYNoTrailer
) != 0) 
 536 void CYThrow::Output(std::ostream 
&out
) const { 
 539         value_
->Output(out
, CYNoLeader
); 
 543 void CYTry::Output(std::ostream 
&out
) const { 
 545     try_
->Output(out
, true); 
 548     if (finally_ 
!= NULL
) { 
 550         finally_
->Output(out
, true); 
 554 void CYVariable::Output(std::ostream 
&out
, CYFlags flags
) const { 
 555     if ((flags 
& CYNoLeader
) != 0) 
 558     if ((flags 
& CYNoTrailer
) != 0) 
 562 void CYWhile::Output(std::ostream 
&out
) const { 
 564     test_
->Output(out
, CYNoFlags
); 
 566     code_
->Output(out
, false); 
 569 void CYWith::Output(std::ostream 
&out
) const { 
 571     scope_
->Output(out
, CYNoFlags
); 
 573     code_
->Output(out
, false); 
 576 void CYWord::Output(std::ostream 
&out
) const {