#include "Parser.hpp"
-#include <iostream>
#include <iomanip>
-
-#include <objc/runtime.h>
#include <sstream>
_finline CYFlags operator ~(CYFlags rhs) {
return CYLeft(CYRight(flags));
}
-#define CYPA 16
-
void CYOutput::Terminate() {
out_ << ';';
mode_ = NoMode;
out << ' ' << "catch" << ' ' << '(' << *name_ << ')' << ' ' << code_;
}
-void CYCategory::Output(CYOutput &out, CYFlags flags) 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, true);
- out << ')';
- out << ';';
-}
-
-void CYClass::Output(CYOutput &out, CYFlags flags) const {
- // XXX: I don't necc. need the ()s
- out << "(function($cys,$cyp,$cyc,$cyn,$cyt,$cym){";
- out << "$cyp=object_getClass($cys);";
- out << "$cyc=objc_allocateClassPair($cys,";
- if (name_ != NULL)
- name_->ClassName(out, false);
- else
- out << "$cyq(\"CY$\")";
- out << ",0);";
- out << "$cym=object_getClass($cyc);";
- if (fields_ != NULL)
- fields_->Output(out);
- if (messages_ != NULL)
- messages_->Output(out, false);
- out << "objc_registerClassPair($cyc);";
- out << "return $cyc;";
- out << "}(";
- if (super_ != NULL)
- super_->Output(out, CYPA, CYNoFlags);
- else
- out << "null";
- out << "))";
-}
-
-void CYClassExpression::Output(CYOutput &out, CYFlags flags) const {
- CYClass::Output(out, flags);
-}
-
-void CYClassStatement::Output(CYOutput &out, CYFlags flags) const {
- CYClass::Output(out, flags);
-}
-
void CYCompound::Output(CYOutput &out, CYFlags flags) const {
if (CYExpression *expression = expressions_)
if (CYExpression *next = expression->next_) {
Output(out, flags);
}
-void CYField::Output(CYOutput &out) const {
- // XXX: implement!
-}
-
void CYFinally::Output(CYOutput &out) const {
out << ' ' << "finally" << ' ' << code_;
}
out << "let" << ' ' << '(' << *declarations_ << ')' << ' ' << code_;
}
-void CYMessage::Output(CYOutput &out, bool replace) const {
- if (next_ != NULL)
- next_->Output(out, replace);
- out << "$cyn=new Selector(\"";
- for (CYMessageParameter *parameter(parameters_); parameter != NULL; parameter = parameter->next_)
- if (parameter->tag_ != NULL) {
- out << *parameter->tag_;
- if (parameter->name_ != NULL)
- out << ':';
- }
- out << "\");";
- out << "$cyt=$cyn.type($cy" << (instance_ ? 's' : 'p') << ')' << ';';
- out << (replace ? "class_replaceMethod" : "class_addMethod") << '(' << (instance_ ? "$cyc" : "$cym") << ',' << "$cyn" << ',';
- out << "new Functor(function(self,_cmd";
- for (CYMessageParameter *parameter(parameters_); parameter != NULL; parameter = parameter->next_)
- if (parameter->name_ != NULL)
- out << ',' << *parameter->name_;
- out << "){return function(){";
- if (statements_ != NULL)
- statements_->Multiple(out);
- out << "}.call(self);},$cyt),$cyt);";
-}
-
void CYNew::Output(CYOutput &out, CYFlags flags) const {
out << "new" << ' ';
CYFlags jacks(CYNoCall | CYCenter(flags));
out << ';';
}
-void CYSelector::Output(CYOutput &out, CYFlags flags) const {
- out << "@selector" << '(' << name_ << ')';
-}
-
-void CYSelectorPart::Output(CYOutput &out) const {
- out << name_;
- if (value_)
- out << ':';
- out << next_;
-}
-
-void CYSend::Output(CYOutput &out, CYFlags flags) const {
- out << '[';
- self_->Output(out, CYPA, CYNoFlags);
- out << ']';
-
- std::ostringstream name;
- for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_)
- if (argument->name_ != NULL) {
- name << *argument->name_;
- if (argument->value_ != NULL)
- name << ':';
- }
-
- out.out_ << reinterpret_cast<void *>(sel_registerName(name.str().c_str()));
- for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_)
- if (argument->value_ != NULL) {
- out << ',';
- argument->value_->Output(out, CYPA, CYNoFlags);
- }
- out << ')';
-}
-
void CYStatement::Multiple(CYOutput &out, CYFlags flags) const {
bool first(true);
for (const CYStatement *next(this); next != NULL; next = next->next_) {