void CYAddressOf::Output(std::ostream &out, CYFlags flags) const {
rhs_->Output(out, 1, CYLeft(flags));
- out << ".addressOf()";
+ out << ".$cya()";
}
void CYArgument::Output(std::ostream &out) const {
code_->Output(out, true);
}
+void CYCategory::Output(std::ostream &out) const {
+ out << "(function($cys,$cyp,$cyc,$cyn,$cyt){";
+ out << "$cyp=object_getClass($cys);";
+ out << "$cyc=$cys;";
+ if (messages_ != NULL)
+ messages_->Output(out, true);
+ out << "})(";
+ name_->ClassName(out);
+ out << ");";
+}
+
void CYClass::Output(std::ostream &out) const {
- out << "(function($cys,$cyc,$cym,$cyn,$cyt){";
+ out << "(function($cys,$cyp,$cyc,$cyn,$cyt,$cym){";
+ out << "$cyp=object_getClass($cys);";
out << "$cyc=objc_allocateClassPair($cys,\"" << *name_ << "\",0);";
out << "$cym=object_getClass($cyc);";
if (fields_ != NULL)
fields_->Output(out);
if (messages_ != NULL)
- messages_->Output(out);
+ messages_->Output(out, false);
out << "objc_registerClassPair($cyc);";
out << "})(";
if (super_ != NULL)
out << ");";
}
+void CYCompound::Output(std::ostream &out, CYFlags flags) const {
+ if (CYExpression *expression = expressions_)
+ if (CYExpression *next = expression->next_) {
+ expression->Output(out, CYLeft(flags));
+ CYFlags center(CYCenter(flags));
+ while (next != NULL) {
+ expression = next;
+ out << ',';
+ next = expression->next_;
+ CYFlags right(next != NULL ? center : CYRight(flags));
+ expression->Output(out, right);
+ }
+ } else
+ expression->Output(out, flags);
+}
+
void CYCondition::Output(std::ostream &out, CYFlags flags) const {
test_->Output(out, Precedence() - 1, CYLeft(flags));
out << '?';
out << ';';
}
+void CYDirectMember::Output(std::ostream &out, CYFlags flags) const {
+ object_->Output(out, Precedence(), CYLeft(flags));
+ if (const char *word = property_->Word())
+ out << '.' << word;
+ else {
+ out << '[';
+ property_->Output(out, CYNoFlags);
+ out << ']';
+ }
+}
+
void CYDoWhile::Output(std::ostream &out) const {
// XXX: extra space character!
out << "do ";
out << ';';
}
+void CYExpression::ClassName(std::ostream &out) const {
+ Output(out, CYPA, CYNoFlags);
+}
+
void CYExpression::Part(std::ostream &out) const {
// XXX: this should handle LeftHandSideExpression
Output(out, CYNoIn);
}
-void CYCompound::Output(std::ostream &out, CYFlags flags) const {
- if (CYExpression *expression = expressions_)
- if (CYExpression *next = expression->next_) {
- expression->Output(out, CYLeft(flags));
- CYFlags center(CYCenter(flags));
- while (next != NULL) {
- expression = next;
- out << ',';
- next = expression->next_;
- CYFlags right(next != NULL ? center : CYRight(flags));
- expression->Output(out, right);
- }
- } else
- expression->Output(out, flags);
-}
-
void CYExpression::Output(std::ostream &out, unsigned precedence, CYFlags flags) const {
if (precedence < Precedence()) {
out << '(';
void CYIndirect::Output(std::ostream &out, CYFlags flags) const {
rhs_->Output(out, 1, CYLeft(flags));
- out << "[0]";
+ out << ".$cyi";
+}
+
+void CYIndirectMember::Output(std::ostream &out, CYFlags flags) const {
+ object_->Output(out, Precedence(), CYLeft(flags));
+ out << ".$cyi";
+ if (const char *word = property_->Word())
+ out << '.' << word;
+ else {
+ out << '[';
+ property_->Output(out, CYNoFlags);
+ out << ']';
+ }
}
void CYInfix::Output(std::ostream &out, CYFlags flags) const {
out << ')';
}
-void CYMember::Output(std::ostream &out, CYFlags flags) const {
- object_->Output(out, Precedence(), CYLeft(flags));
- if (const char *word = property_->Word())
- out << '.' << word;
- else {
- out << '[';
- property_->Output(out, CYNoFlags);
- out << ']';
- }
-}
-
-void CYMessage::Output(std::ostream &out) const {
+void CYMessage::Output(std::ostream &out, bool replace) const {
if (next_ != NULL)
- next_->Output(out);
+ next_->Output(out, replace);
out << "$cyn=new Selector(\"";
for (CYMessageParameter *parameter(parameter_); parameter != NULL; parameter = parameter->next_)
if (parameter->tag_ != NULL) {
out << ':';
}
out << "\");";
- out << "$cyt=$cyn.type($cys," << (instance_ ? "true" : "false") << ");";
- out << "class_addMethod($cy" << (instance_ ? 'c' : 'm') << ",$cyn,";
+ out << "$cyt=$cyn.type($cy" << (instance_ ? 's' : 'p') << ");";
+ out << "class_" << (replace ? "replace" : "add") << "Method($cy" << (instance_ ? 'c' : 'm') << ",$cyn,";
out << "new Functor(function(self,_cmd";
for (CYMessageParameter *parameter(parameter_); parameter != NULL; parameter = parameter->next_)
if (parameter->name_ != NULL)
}
void CYNew::Output(std::ostream &out, CYFlags flags) const {
+ if ((flags & CYNoLeader) != 0)
+ out << ' ';
out << "new";
constructor_->Output(out, Precedence(), CYCenter(flags) | CYNoLeader);
out << '(';
void CYNumber::Output(std::ostream &out, CYFlags flags) const {
if ((flags & CYNoLeader) != 0)
out << ' ';
- // XXX: this is not a useful formatting
- out << Value();
+ // XXX: decide on correct precision
+ out << std::setprecision(9) << Value();
if ((flags & CYNoTrailer) != 0)
out << ' ';
}
+void CYNumber::PropertyName(std::ostream &out) const {
+ Output(out);
+}
+
void CYObject::Output(std::ostream &out, CYFlags flags) const {
bool protect((flags & CYNoBrace) != 0);
if (protect)
}
void CYProperty::Output(std::ostream &out) const {
- out << *name_;
+ name_->PropertyName(out);
out << ':';
value_->Output(out, CYPA, CYNoFlags);
if (next_ != NULL) {
}
void CYSelector::Output(std::ostream &out, CYFlags flags) const {
+ if ((flags & CYNoLeader) != 0)
+ out << ' ';
out << "new Selector(\"";
if (name_ != NULL)
name_->Output(out);
}
void CYSend::Output(std::ostream &out, CYFlags flags) const {
+ if ((flags & CYNoLeader) != 0)
+ out << ' ';
out << "objc_msgSend(";
self_->Output(out, CYPA, CYNoFlags);
out << ",";
out << (single ? '\'' : '"');
}
+void CYString::PropertyName(std::ostream &out) const {
+ if (const char *word = Word())
+ out << word;
+ else
+ Output(out);
+}
+
void CYSwitch::Output(std::ostream &out) const {
out << "switch(";
value_->Output(out, CYNoFlags);
out << "try";
try_->Output(out, true);
if (catch_ != NULL)
- out << catch_;
+ catch_->Output(out);
if (finally_ != NULL) {
out << "finally";
finally_->Output(out, true);
code_->Output(out, false);
}
+void CYWord::ClassName(std::ostream &out) const {
+ out << "objc_getClass(\"" << Value() << "\")";
+}
+
void CYWord::Output(std::ostream &out) const {
out << Value();
}
+
+void CYWord::PropertyName(std::ostream &out) const {
+ Output(out);
+}