From 652ec1babf02f2a94e408314964f2ce7d51640a9 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 19 Oct 2009 22:43:18 +0000 Subject: [PATCH] Added a CYOutput object between std::ostream and the actual mechanism. --- Console.cpp | 6 +- Library.mm | 3 +- Output.cpp | 166 ++++++++++++++++++++-------------------- Parser.hpp | 215 +++++++++++++++++++++++++++++----------------------- 4 files changed, 208 insertions(+), 182 deletions(-) diff --git a/Console.cpp b/Console.cpp index f83c3a2..6ed69e6 100644 --- a/Console.cpp +++ b/Console.cpp @@ -276,7 +276,8 @@ static void Console(int socket) { code = command; else { std::ostringstream str; - driver.source_->Show(str); + CYOutput out(str); + driver.source_->Show(out); code = str.str(); } } @@ -431,7 +432,8 @@ int main(int argc, char *argv[]) { Run(socket, start, end - start, stdout); else { std::ostringstream str; - driver.source_->Show(str); + CYOutput out(str); + driver.source_->Show(out); std::string code(str.str()); if (compile) std::cout << code; diff --git a/Library.mm b/Library.mm index b550bf5..1b4a198 100644 --- a/Library.mm +++ b/Library.mm @@ -3450,7 +3450,8 @@ struct CYClient : size = _not(size_t); } else { std::ostringstream str; - driver.source_->Show(str); + CYOutput out(str); + driver.source_->Show(out); std::string code(str.str()); CYExecute_ execute = {pool, code.c_str()}; [client performSelectorOnMainThread:@selector(execute:) withObject:[NSValue valueWithPointer:&execute] waitUntilDone:YES]; diff --git a/Output.cpp b/Output.cpp index a5d9743..5af62e6 100644 --- a/Output.cpp +++ b/Output.cpp @@ -44,12 +44,12 @@ bool CYTrue::Value() const { #define CYPA 16 -void CYAddressOf::Output(std::ostream &out, CYFlags flags) const { +void CYAddressOf::Output(CYOutput &out, CYFlags flags) const { rhs_->Output(out, 1, CYLeft(flags)); out << ".$cya()"; } -void CYArgument::Output(std::ostream &out) const { +void CYArgument::Output(CYOutput &out) const { if (name_ != NULL) { out << *name_; if (value_ != NULL) @@ -66,14 +66,14 @@ void CYArgument::Output(std::ostream &out) const { } } -void CYArray::Output(std::ostream &out, CYFlags flags) const { +void CYArray::Output(CYOutput &out, CYFlags flags) const { out << '['; if (elements_ != NULL) elements_->Output(out); out << ']'; } -void CYArrayComprehension::Output(std::ostream &out, CYFlags flags) const { +void CYArrayComprehension::Output(CYOutput &out, CYFlags flags) const { // XXX: I don't necc. need the ()s out << "(function($cyv"; for (CYComprehension *comprehension(comprehensions_); comprehension != NULL; comprehension = comprehension->next_) @@ -91,18 +91,18 @@ void CYArrayComprehension::Output(std::ostream &out, CYFlags flags) const { out << "}())"; } -void CYAssignment::Output(std::ostream &out, CYFlags flags) const { +void CYAssignment::Output(CYOutput &out, CYFlags flags) const { lhs_->Output(out, Precedence() - 1, CYLeft(flags)); out << Operator(); rhs_->Output(out, Precedence(), CYRight(flags)); } -void CYBlock::Output(std::ostream &out) const { +void CYBlock::Output(CYOutput &out) const { for (CYSource *statement(statements_); statement != NULL; statement = statement->next_) statement->Output(out); } -void CYBoolean::Output(std::ostream &out, CYFlags flags) const { +void CYBoolean::Output(CYOutput &out, CYFlags flags) const { if ((flags & CYNoLeader) != 0) out << ' '; out << (Value() ? "true" : "false"); @@ -110,14 +110,14 @@ void CYBoolean::Output(std::ostream &out, CYFlags flags) const { out << ' '; } -void CYBreak::Output(std::ostream &out) const { +void CYBreak::Output(CYOutput &out) const { out << "break"; if (label_ != NULL) out << ' ' << *label_; out << ';'; } -void CYCall::Output(std::ostream &out, CYFlags flags) const { +void CYCall::Output(CYOutput &out, CYFlags flags) const { function_->Output(out, Precedence(), CYLeft(flags)); out << '('; if (arguments_ != NULL) @@ -125,12 +125,12 @@ void CYCall::Output(std::ostream &out, CYFlags flags) const { out << ')'; } -void CYCatch::Output(std::ostream &out) const { +void CYCatch::Output(CYOutput &out) const { out << "catch(" << *name_ << ')'; code_->Output(out, true); } -void CYCategory::Output(std::ostream &out) const { +void CYCategory::Output(CYOutput &out) const { out << "(function($cys,$cyp,$cyc,$cyn,$cyt){"; out << "$cyp=object_getClass($cys);"; out << "$cyc=$cys;"; @@ -141,12 +141,12 @@ void CYCategory::Output(std::ostream &out) const { out << ");"; } -void CYClass::Output(std::ostream &out) const { +void CYClass::Output(CYOutput &out) const { Output(out, CYNoBF); out << ";"; } -void CYClass::Output(std::ostream &out, CYFlags flags) const { +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);"; @@ -171,7 +171,7 @@ void CYClass::Output(std::ostream &out, CYFlags flags) const { out << "))"; } -void CYCompound::Output(std::ostream &out, CYFlags flags) const { +void CYCompound::Output(CYOutput &out, CYFlags flags) const { if (CYExpression *expression = expressions_) if (CYExpression *next = expression->next_) { expression->Output(out, CYLeft(flags)); @@ -187,13 +187,13 @@ void CYCompound::Output(std::ostream &out, CYFlags flags) const { expression->Output(out, flags); } -void CYComprehension::Output(std::ostream &out) const { +void CYComprehension::Output(CYOutput &out) const { Begin_(out); if (next_ != NULL) next_->Output(out); } -void CYCondition::Output(std::ostream &out, CYFlags flags) const { +void CYCondition::Output(CYOutput &out, CYFlags flags) const { test_->Output(out, Precedence() - 1, CYLeft(flags)); out << '?'; if (true_ != NULL) @@ -202,14 +202,14 @@ void CYCondition::Output(std::ostream &out, CYFlags flags) const { false_->Output(out, CYPA, CYRight(flags)); } -void CYContinue::Output(std::ostream &out) const { +void CYContinue::Output(CYOutput &out) const { out << "continue"; if (label_ != NULL) out << ' ' << *label_; out << ';'; } -void CYClause::Output(std::ostream &out) const { +void CYClause::Output(CYOutput &out) const { if (case_ != NULL) { out << "case"; case_->Output(out, CYNoLeader); @@ -226,18 +226,18 @@ const char *CYDeclaration::ForEachIn() const { return identifier_->Value(); } -void CYDeclaration::ForIn(std::ostream &out, CYFlags flags) const { +void CYDeclaration::ForIn(CYOutput &out, CYFlags flags) const { if ((flags & CYNoLeader) != 0) out << ' '; out << "var "; Output(out, CYRight(flags)); } -void CYDeclaration::ForEachIn(std::ostream &out) const { +void CYDeclaration::ForEachIn(CYOutput &out) const { out << *identifier_; } -void CYDeclaration::Output(std::ostream &out, CYFlags flags) const { +void CYDeclaration::Output(CYOutput &out, CYFlags flags) const { out << *identifier_; if (initialiser_ != NULL) { out << '='; @@ -246,12 +246,12 @@ void CYDeclaration::Output(std::ostream &out, CYFlags flags) const { out << ' '; } -void CYDeclarations::For(std::ostream &out) const { +void CYDeclarations::For(CYOutput &out) const { out << "var "; Output(out, CYNoIn); } -void CYDeclarations::Output(std::ostream &out, CYFlags flags) const { +void CYDeclarations::Output(CYOutput &out, CYFlags flags) const { const CYDeclarations *declaration(this); output: CYDeclarations *next(declaration->next_); @@ -265,7 +265,7 @@ void CYDeclarations::Output(std::ostream &out, CYFlags flags) const { } } -void CYDirectMember::Output(std::ostream &out, CYFlags flags) const { +void CYDirectMember::Output(CYOutput &out, CYFlags flags) const { object_->Output(out, Precedence(), CYLeft(flags)); if (const char *word = property_->Word()) out << '.' << word; @@ -276,7 +276,7 @@ void CYDirectMember::Output(std::ostream &out, CYFlags flags) const { } } -void CYDoWhile::Output(std::ostream &out) const { +void CYDoWhile::Output(CYOutput &out) const { // XXX: extra space character! out << "do "; code_->Output(out, false); @@ -285,7 +285,7 @@ void CYDoWhile::Output(std::ostream &out) const { out << ')'; } -void CYElement::Output(std::ostream &out) const { +void CYElement::Output(CYOutput &out) const { if (value_ != NULL) value_->Output(out, CYPA, CYNoFlags); if (next_ != NULL || value_ == NULL) @@ -294,23 +294,23 @@ void CYElement::Output(std::ostream &out) const { next_->Output(out); } -void CYEmpty::Output(std::ostream &out) const { +void CYEmpty::Output(CYOutput &out) const { out << ';'; } -void CYEmpty::Output(std::ostream &out, bool block) const { +void CYEmpty::Output(CYOutput &out, bool block) const { if (next_ != NULL) CYSource::Output(out, block); else out << "{}"; } -void CYExpress::Output(std::ostream &out) const { +void CYExpress::Output(CYOutput &out) const { expression_->Output(out, CYNoBF); out << ';'; } -void CYExpression::ClassName(std::ostream &out, bool object) const { +void CYExpression::ClassName(CYOutput &out, bool object) const { Output(out, CYPA, CYNoFlags); } @@ -318,21 +318,21 @@ const char *CYExpression::ForEachIn() const { return NULL; } -void CYExpression::For(std::ostream &out) const { +void CYExpression::For(CYOutput &out) const { Output(out, CYNoIn); } -void CYExpression::ForEachIn(std::ostream &out) const { +void CYExpression::ForEachIn(CYOutput &out) const { // XXX: this should handle LeftHandSideExpression Output(out, CYPA, CYNoFlags); } -void CYExpression::ForIn(std::ostream &out, CYFlags flags) const { +void CYExpression::ForIn(CYOutput &out, CYFlags flags) const { // XXX: this should handle LeftHandSideExpression Output(out, flags); } -void CYExpression::Output(std::ostream &out, unsigned precedence, CYFlags flags) const { +void CYExpression::Output(CYOutput &out, unsigned precedence, CYFlags flags) const { if (precedence < Precedence()) { out << '('; Output(out, CYNoFlags); @@ -341,11 +341,11 @@ void CYExpression::Output(std::ostream &out, unsigned precedence, CYFlags flags) Output(out, flags); } -void CYField::Output(std::ostream &out) const { +void CYField::Output(CYOutput &out) const { // XXX: implement! } -void CYFor::Output(std::ostream &out) const { +void CYFor::Output(CYOutput &out) const { out << "for("; if (initialiser_ != NULL) initialiser_->For(out); @@ -359,7 +359,7 @@ void CYFor::Output(std::ostream &out) const { code_->Output(out, false); } -void CYForEachIn::Output(std::ostream &out) const { +void CYForEachIn::Output(CYOutput &out) const { out << "with({$cys:0,$cyt:0}){"; out << "$cys="; @@ -378,7 +378,7 @@ void CYForEachIn::Output(std::ostream &out) const { out << '}'; } -void CYForEachInComprehension::Begin_(std::ostream &out) const { +void CYForEachInComprehension::Begin_(CYOutput &out) const { out << "(function($cys){"; out << "$cys="; set_->Output(out, CYPA, CYNoFlags); @@ -388,11 +388,11 @@ void CYForEachInComprehension::Begin_(std::ostream &out) const { out << *name_ << "=$cys[" << *name_ << "];"; } -void CYForEachInComprehension::End_(std::ostream &out) const { +void CYForEachInComprehension::End_(CYOutput &out) const { out << "}}());"; } -void CYForIn::Output(std::ostream &out) const { +void CYForIn::Output(CYOutput &out) const { out << "for("; initialiser_->ForIn(out, CYNoIn | CYNoTrailer); out << "in"; @@ -401,17 +401,17 @@ void CYForIn::Output(std::ostream &out) const { code_->Output(out, false); } -void CYForInComprehension::Begin_(std::ostream &out) const { +void CYForInComprehension::Begin_(CYOutput &out) const { out << "for(" << *name_ << " in"; set_->Output(out, CYNoLeader); out << ')'; } -void CYFunction::Output(std::ostream &out) const { +void CYFunction::Output(CYOutput &out) const { CYLambda::Output(out, CYNoFlags); } -void CYFunctionParameter::Output(std::ostream &out) const { +void CYFunctionParameter::Output(CYOutput &out) const { out << *name_; if (next_ != NULL) { out << ','; @@ -419,7 +419,7 @@ void CYFunctionParameter::Output(std::ostream &out) const { } } -void CYIf::Output(std::ostream &out) const { +void CYIf::Output(CYOutput &out) const { out << "if("; test_->Output(out, CYNoFlags); out << ')'; @@ -430,18 +430,18 @@ void CYIf::Output(std::ostream &out) const { } } -void CYIfComprehension::Begin_(std::ostream &out) const { +void CYIfComprehension::Begin_(CYOutput &out) const { out << "if("; test_->Output(out, CYNoFlags); out << ')'; } -void CYIndirect::Output(std::ostream &out, CYFlags flags) const { +void CYIndirect::Output(CYOutput &out, CYFlags flags) const { rhs_->Output(out, 1, CYLeft(flags)); out << ".$cyi"; } -void CYIndirectMember::Output(std::ostream &out, CYFlags flags) const { +void CYIndirectMember::Output(CYOutput &out, CYFlags flags) const { object_->Output(out, Precedence(), CYLeft(flags)); out << ".$cyi"; if (const char *word = property_->Word()) @@ -453,7 +453,7 @@ void CYIndirectMember::Output(std::ostream &out, CYFlags flags) const { } } -void CYInfix::Output(std::ostream &out, CYFlags flags) const { +void CYInfix::Output(CYOutput &out, CYFlags flags) const { const char *name(Operator()); bool protect((flags & CYNoIn) != 0 && strcmp(name, "in")); if (protect) @@ -474,7 +474,7 @@ void CYInfix::Output(std::ostream &out, CYFlags flags) const { out << ')'; } -void CYLambda::Output(std::ostream &out, CYFlags flags) const { +void CYLambda::Output(CYOutput &out, CYFlags flags) const { bool protect((flags & CYNoFunction) != 0); if (protect) out << '('; @@ -494,7 +494,7 @@ void CYLambda::Output(std::ostream &out, CYFlags flags) const { out << ')'; } -void CYLet::Output(std::ostream &out) const { +void CYLet::Output(CYOutput &out) const { out << "let("; declarations_->Output(out, CYNoFlags); out << "){"; @@ -503,7 +503,7 @@ void CYLet::Output(std::ostream &out) const { out << "}"; } -void CYMessage::Output(std::ostream &out, bool replace) const { +void CYMessage::Output(CYOutput &out, bool replace) const { if (next_ != NULL) next_->Output(out, replace); out << "$cyn=new Selector(\""; @@ -526,7 +526,7 @@ void CYMessage::Output(std::ostream &out, bool replace) const { out << "}.call(self);},$cyt),$cyt);"; } -void CYNew::Output(std::ostream &out, CYFlags flags) const { +void CYNew::Output(CYOutput &out, CYFlags flags) const { if ((flags & CYNoLeader) != 0) out << ' '; out << "new"; @@ -537,7 +537,7 @@ void CYNew::Output(std::ostream &out, CYFlags flags) const { out << ')'; } -void CYNull::Output(std::ostream &out, CYFlags flags) const { +void CYNull::Output(CYOutput &out, CYFlags flags) const { if ((flags & CYNoLeader) != 0) out << ' '; CYWord::Output(out); @@ -545,21 +545,21 @@ void CYNull::Output(std::ostream &out, CYFlags flags) const { out << ' '; } -void CYNumber::Output(std::ostream &out, CYFlags flags) const { +void CYNumber::Output(CYOutput &out, CYFlags flags) const { double value(Value()); if ((flags & CYNoLeader) != 0 || value < 0 && (flags & CYNoHyphen) != 0) out << ' '; // XXX: decide on correct precision - out << std::setprecision(9) << value; + out.out_ << std::setprecision(9) << value; if ((flags & CYNoTrailer) != 0) out << ' '; } -void CYNumber::PropertyName(std::ostream &out) const { +void CYNumber::PropertyName(CYOutput &out) const { Output(out); } -void CYObject::Output(std::ostream &out, CYFlags flags) const { +void CYObject::Output(CYOutput &out, CYFlags flags) const { bool protect((flags & CYNoBrace) != 0); if (protect) out << '('; @@ -571,12 +571,12 @@ void CYObject::Output(std::ostream &out, CYFlags flags) const { out << ')'; } -void CYPostfix::Output(std::ostream &out, CYFlags flags) const { +void CYPostfix::Output(CYOutput &out, CYFlags flags) const { lhs_->Output(out, Precedence(), CYLeft(flags)); out << Operator(); } -void CYPrefix::Output(std::ostream &out, CYFlags flags) const { +void CYPrefix::Output(CYOutput &out, CYFlags flags) const { const char *name(Operator()); bool alphabetic(Alphabetic()); if (alphabetic && (flags & CYNoLeader) != 0 || name[0] == '-' && (flags & CYNoHyphen) != 0) @@ -588,7 +588,7 @@ void CYPrefix::Output(std::ostream &out, CYFlags flags) const { rhs_->Output(out, Precedence(), right); } -void CYProperty::Output(std::ostream &out) const { +void CYProperty::Output(CYOutput &out) const { name_->PropertyName(out); out << ':'; value_->Output(out, CYPA, CYNoFlags); @@ -598,14 +598,14 @@ void CYProperty::Output(std::ostream &out) const { } } -void CYReturn::Output(std::ostream &out) const { +void CYReturn::Output(CYOutput &out) const { out << "return"; if (value_ != NULL) value_->Output(out, CYNoLeader); out << ';'; } -void CYSelector::Output(std::ostream &out, CYFlags flags) const { +void CYSelector::Output(CYOutput &out, CYFlags flags) const { if ((flags & CYNoLeader) != 0) out << ' '; out << "new Selector(\""; @@ -614,7 +614,7 @@ void CYSelector::Output(std::ostream &out, CYFlags flags) const { out << "\")"; } -void CYSelectorPart::Output(std::ostream &out) const { +void CYSelectorPart::Output(CYOutput &out) const { if (name_ != NULL) out << *name_; if (value_) @@ -623,7 +623,7 @@ void CYSelectorPart::Output(std::ostream &out) const { next_->Output(out); } -void CYSend::Output(std::ostream &out, CYFlags flags) const { +void CYSend::Output(CYOutput &out, CYFlags flags) const { if ((flags & CYNoLeader) != 0) out << ' '; out << "objc_msgSend("; @@ -636,7 +636,7 @@ void CYSend::Output(std::ostream &out, CYFlags flags) const { if (argument->value_ != NULL) name << ':'; } - out << reinterpret_cast(sel_registerName(name.str().c_str())); + out.out_ << reinterpret_cast(sel_registerName(name.str().c_str())); for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_) if (argument->value_ != NULL) { out << ","; @@ -645,12 +645,12 @@ void CYSend::Output(std::ostream &out, CYFlags flags) const { out << ')'; } -void CYSource::Show(std::ostream &out) const { +void CYSource::Show(CYOutput &out) const { for (const CYSource *next(this); next != NULL; next = next->next_) next->Output_(out); } -void CYSource::Output(std::ostream &out, bool block) const { +void CYSource::Output(CYOutput &out, bool block) const { if (!block && !IsBlock()) Output(out); else { @@ -660,17 +660,17 @@ void CYSource::Output(std::ostream &out, bool block) const { } } -void CYSource::Output_(std::ostream &out) const { +void CYSource::Output_(CYOutput &out) const { Output(out); } -void CYStatement::Output_(std::ostream &out) const { +void CYStatement::Output_(CYOutput &out) const { for (CYLabel *label(labels_); label != NULL; label = label->next_) out << *label->name_ << ':'; Output(out); } -void CYString::Output(std::ostream &out, CYFlags flags) const { +void CYString::Output(CYOutput &out, CYFlags flags) const { unsigned quot(0), apos(0); for (const char *value(value_), *end(value_ + size_); value != end; ++value) if (*value == '"') @@ -705,21 +705,21 @@ void CYString::Output(std::ostream &out, CYFlags flags) const { default: if (*value < 0x20 || *value >= 0x7f) - out << "\\x" << std::setbase(16) << std::setw(2) << std::setfill('0') << unsigned(*value); + out.out_ << "\\x" << std::setbase(16) << std::setw(2) << std::setfill('0') << unsigned(*value); else simple: out << *value; } out << (single ? '\'' : '"'); } -void CYString::PropertyName(std::ostream &out) const { +void CYString::PropertyName(CYOutput &out) const { if (const char *word = Word()) out << word; else Output(out); } -void CYSwitch::Output(std::ostream &out) const { +void CYSwitch::Output(CYOutput &out) const { out << "switch("; value_->Output(out, CYNoFlags); out << "){"; @@ -728,7 +728,7 @@ void CYSwitch::Output(std::ostream &out) const { out << '}'; } -void CYThis::Output(std::ostream &out, CYFlags flags) const { +void CYThis::Output(CYOutput &out, CYFlags flags) const { if ((flags & CYNoLeader) != 0) out << ' '; CYWord::Output(out); @@ -736,14 +736,14 @@ void CYThis::Output(std::ostream &out, CYFlags flags) const { out << ' '; } -void CYThrow::Output(std::ostream &out) const { +void CYThrow::Output(CYOutput &out) const { out << "throw"; if (value_ != NULL) value_->Output(out, CYNoLeader); out << ';'; } -void CYTry::Output(std::ostream &out) const { +void CYTry::Output(CYOutput &out) const { out << "try"; try_->Output(out, true); if (catch_ != NULL) @@ -754,13 +754,13 @@ void CYTry::Output(std::ostream &out) const { } } -void CYVar::Output(std::ostream &out) const { +void CYVar::Output(CYOutput &out) const { out << "var "; declarations_->Output(out, CYNoFlags); out << ';'; } -void CYVariable::Output(std::ostream &out, CYFlags flags) const { +void CYVariable::Output(CYOutput &out, CYFlags flags) const { if ((flags & CYNoLeader) != 0) out << ' '; out << *name_; @@ -768,21 +768,21 @@ void CYVariable::Output(std::ostream &out, CYFlags flags) const { out << ' '; } -void CYWhile::Output(std::ostream &out) const { +void CYWhile::Output(CYOutput &out) const { out << "while("; test_->Output(out, CYNoFlags); out << ')'; code_->Output(out, false); } -void CYWith::Output(std::ostream &out) const { +void CYWith::Output(CYOutput &out) const { out << "with("; scope_->Output(out, CYNoFlags); out << ')'; code_->Output(out, false); } -void CYWord::ClassName(std::ostream &out, bool object) const { +void CYWord::ClassName(CYOutput &out, bool object) const { if (object) out << "objc_getClass("; out << '"' << Value() << '"'; @@ -790,10 +790,10 @@ void CYWord::ClassName(std::ostream &out, bool object) const { out << ')'; } -void CYWord::Output(std::ostream &out) const { +void CYWord::Output(CYOutput &out) const { out << Value(); } -void CYWord::PropertyName(std::ostream &out) const { +void CYWord::PropertyName(CYOutput &out) const { Output(out); } diff --git a/Parser.hpp b/Parser.hpp index 66bd872..cab829a 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -67,13 +67,32 @@ struct CYNext { }; struct CYThing { - virtual void Output(std::ostream &out) const = 0; + virtual void Output(struct CYOutput &out) const = 0; }; -_finline std::ostream &operator <<(std::ostream &out, const CYThing &rhs) { - rhs.Output(out); - return out; -} +struct CYOutput { + std::ostream &out_; + + CYOutput(std::ostream &out) : + out_(out) + { + } + + _finline CYOutput &operator <<(char rhs) { + out_ << rhs; + return *this; + } + + _finline CYOutput &operator <<(const char *rhs) { + out_ << rhs; + return *this; + } + + _finline CYOutput &operator <<(const CYThing &rhs) { + rhs.Output(*this); + return *this; + } +}; struct CYSource : CYNext @@ -82,18 +101,18 @@ struct CYSource : return next_ != NULL; } - virtual void Show(std::ostream &out) const; - virtual void Output(std::ostream &out) const = 0; - virtual void Output(std::ostream &out, bool block) const; - virtual void Output_(std::ostream &out) const; + virtual void Show(CYOutput &out) const; + virtual void Output(CYOutput &out) const = 0; + virtual void Output(CYOutput &out, bool block) const; + virtual void Output_(CYOutput &out) const; }; struct CYPropertyName { - virtual void PropertyName(std::ostream &out) const = 0; + virtual void PropertyName(CYOutput &out) const = 0; }; struct CYClassName { - virtual void ClassName(std::ostream &out, bool object) const = 0; + virtual void ClassName(CYOutput &out, bool object) const = 0; }; struct CYWord : @@ -112,12 +131,16 @@ struct CYWord : return word_; } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; - virtual void ClassName(std::ostream &out, bool object) const; - virtual void PropertyName(std::ostream &out) const; + virtual void ClassName(CYOutput &out, bool object) const; + virtual void PropertyName(CYOutput &out) const; }; +_finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) { + return lhs << rhs.Value(); +} + struct CYIdentifier : CYWord { @@ -153,7 +176,7 @@ struct CYStatement : labels_ = new CYLabel(identifier, labels_); } - virtual void Output_(std::ostream &out) const; + virtual void Output_(CYOutput &out) const; }; struct CYBlock : @@ -170,7 +193,7 @@ struct CYBlock : return true; } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; enum CYState { @@ -223,13 +246,13 @@ enum CYFlags { }; struct CYForInitialiser { - virtual void For(std::ostream &out) const = 0; + virtual void For(CYOutput &out) const = 0; }; struct CYForInInitialiser { - virtual void ForIn(std::ostream &out, CYFlags flags) const = 0; + virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; virtual const char *ForEachIn() const = 0; - virtual void ForEachIn(std::ostream &out) const = 0; + virtual void ForEachIn(CYOutput &out) const = 0; }; struct CYExpression : @@ -240,16 +263,16 @@ struct CYExpression : { virtual unsigned Precedence() const = 0; - virtual void For(std::ostream &out) const; - virtual void ForIn(std::ostream &out, CYFlags flags) const; + virtual void For(CYOutput &out) const; + virtual void ForIn(CYOutput &out, CYFlags flags) const; virtual const char *ForEachIn() const; - virtual void ForEachIn(std::ostream &out) const; + virtual void ForEachIn(CYOutput &out) const; - virtual void Output(std::ostream &out, CYFlags flags) const = 0; - void Output(std::ostream &out, unsigned precedence, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const = 0; + void Output(CYOutput &out, unsigned precedence, CYFlags flags) const; - virtual void ClassName(std::ostream &out, bool object) const; + virtual void ClassName(CYOutput &out, bool object) const; virtual const char *Word() const { return NULL; @@ -286,18 +309,18 @@ struct CYCompound : CYPrecedence(17) - void Output(std::ostream &out, CYFlags flags) const; + void Output(CYOutput &out, CYFlags flags) const; }; struct CYComprehension : CYNext { - void Output(std::ostream &out) const; + void Output(CYOutput &out) const; virtual const char *Name() const = 0; - virtual void Begin_(std::ostream &out) const = 0; + virtual void Begin_(CYOutput &out) const = 0; - virtual void End_(std::ostream &out) const { + virtual void End_(CYOutput &out) const { } }; @@ -317,7 +340,7 @@ struct CYForInComprehension : return name_->Value(); } - virtual void Begin_(std::ostream &out) const; + virtual void Begin_(CYOutput &out) const; }; struct CYForEachInComprehension : @@ -336,8 +359,8 @@ struct CYForEachInComprehension : return name_->Value(); } - virtual void Begin_(std::ostream &out) const; - virtual void End_(std::ostream &out) const; + virtual void Begin_(CYOutput &out) const; + virtual void End_(CYOutput &out) const; }; struct CYIfComprehension : @@ -354,7 +377,7 @@ struct CYIfComprehension : return NULL; } - virtual void Begin_(std::ostream &out) const; + virtual void Begin_(CYOutput &out) const; }; struct CYArrayComprehension : @@ -371,7 +394,7 @@ struct CYArrayComprehension : CYPrecedence(0) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYLiteral : @@ -399,7 +422,7 @@ struct CYSelectorPart : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYSelector : @@ -414,7 +437,7 @@ struct CYSelector : CYPrecedence(1) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYRange { @@ -473,12 +496,12 @@ struct CYString : return Value(); } - virtual void Output(std::ostream &out) const { + virtual void Output(CYOutput &out) const { return Output(out, CYNoFlags); } - virtual void Output(std::ostream &out, CYFlags flags) const; - virtual void PropertyName(std::ostream &out) const; + virtual void Output(CYOutput &out, CYFlags flags) const; + virtual void PropertyName(CYOutput &out) const; }; struct CYNumber : @@ -496,12 +519,12 @@ struct CYNumber : return value_; } - virtual void Output(std::ostream &out) const { + virtual void Output(CYOutput &out) const { return Output(out, CYNoFlags); } - virtual void Output(std::ostream &out, CYFlags flags) const; - virtual void PropertyName(std::ostream &out) const; + virtual void Output(CYOutput &out, CYFlags flags) const; + virtual void PropertyName(CYOutput &out) const; }; struct CYNull : @@ -513,7 +536,7 @@ struct CYNull : { } - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYThis : @@ -525,14 +548,14 @@ struct CYThis : { } - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYBoolean : CYLiteral { virtual bool Value() const = 0; - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYFalse : @@ -571,7 +594,7 @@ struct CYVariable : CYPrecedence(0) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYPrefix : @@ -587,7 +610,7 @@ struct CYPrefix : virtual bool Alphabetic() const = 0; virtual const char *Operator() const = 0; - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYInfix : @@ -609,7 +632,7 @@ struct CYInfix : virtual bool Alphabetic() const = 0; virtual const char *Operator() const = 0; - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYPostfix : @@ -624,7 +647,7 @@ struct CYPostfix : virtual const char *Operator() const = 0; - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYAssignment : @@ -645,7 +668,7 @@ struct CYAssignment : virtual const char *Operator() const = 0; - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYArgument : @@ -661,7 +684,7 @@ struct CYArgument : { } - void Output(std::ostream &out) const; + void Output(CYOutput &out) const; }; struct CYBlank : @@ -686,7 +709,7 @@ struct CYClause : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYElement : @@ -700,7 +723,7 @@ struct CYElement : { } - void Output(std::ostream &out) const; + void Output(CYOutput &out) const; }; struct CYArray : @@ -713,7 +736,7 @@ struct CYArray : { } - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYDeclaration : @@ -728,12 +751,12 @@ struct CYDeclaration : { } - virtual void ForIn(std::ostream &out, CYFlags flags) const; + virtual void ForIn(CYOutput &out, CYFlags flags) const; virtual const char *ForEachIn() const; - virtual void ForEachIn(std::ostream &out) const; + virtual void ForEachIn(CYOutput &out) const; - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYDeclarations : @@ -748,8 +771,8 @@ struct CYDeclarations : { } - virtual void For(std::ostream &out) const; - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void For(CYOutput &out) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYVar : @@ -762,7 +785,7 @@ struct CYVar : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYLet : @@ -777,13 +800,13 @@ struct CYLet : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYField : CYNext { - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYMessageParameter : @@ -817,7 +840,7 @@ struct CYMessage : { } - virtual void Output(std::ostream &out, bool replace) const; + virtual void Output(CYOutput &out, bool replace) const; }; struct CYClass : @@ -839,8 +862,8 @@ struct CYClass : CYPrecedence(0) - virtual void Output(std::ostream &out) const; - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYCategory : @@ -855,7 +878,7 @@ struct CYCategory : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYFunctionParameter : @@ -870,7 +893,7 @@ struct CYFunctionParameter : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYFor : @@ -889,7 +912,7 @@ struct CYFor : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYForIn : @@ -906,7 +929,7 @@ struct CYForIn : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYForEachIn : @@ -923,7 +946,7 @@ struct CYForEachIn : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYProperty : @@ -939,7 +962,7 @@ struct CYProperty : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYObject : @@ -952,7 +975,7 @@ struct CYObject : { } - void Output(std::ostream &out, CYFlags flags) const; + void Output(CYOutput &out, CYFlags flags) const; }; struct CYCatch : @@ -967,7 +990,7 @@ struct CYCatch : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYSend : @@ -984,7 +1007,7 @@ struct CYSend : CYPrecedence(0) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYMember : @@ -1014,7 +1037,7 @@ struct CYDirectMember : CYPrecedence(1) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYIndirectMember : @@ -1027,7 +1050,7 @@ struct CYIndirectMember : CYPrecedence(1) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYNew : @@ -1044,7 +1067,7 @@ struct CYNew : CYPrecedence(1) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYCall : @@ -1061,7 +1084,7 @@ struct CYCall : CYPrecedence(2) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYIf : @@ -1078,7 +1101,7 @@ struct CYIf : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYDoWhile : @@ -1093,7 +1116,7 @@ struct CYDoWhile : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYWhile : @@ -1108,7 +1131,7 @@ struct CYWhile : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYLambda : @@ -1127,7 +1150,7 @@ struct CYLambda : CYPrecedence(0) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYFunction : @@ -1139,7 +1162,7 @@ struct CYFunction : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYExpress : @@ -1152,7 +1175,7 @@ struct CYExpress : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYContinue : @@ -1165,7 +1188,7 @@ struct CYContinue : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYBreak : @@ -1178,7 +1201,7 @@ struct CYBreak : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYReturn : @@ -1191,14 +1214,14 @@ struct CYReturn : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYEmpty : CYStatement { - virtual void Output(std::ostream &out) const; - virtual void Output(std::ostream &out, bool block) const; + virtual void Output(CYOutput &out) const; + virtual void Output(CYOutput &out, bool block) const; }; struct CYTry : @@ -1215,7 +1238,7 @@ struct CYTry : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYThrow : @@ -1228,7 +1251,7 @@ struct CYThrow : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYWith : @@ -1243,7 +1266,7 @@ struct CYWith : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYSwitch : @@ -1258,7 +1281,7 @@ struct CYSwitch : { } - virtual void Output(std::ostream &out) const; + virtual void Output(CYOutput &out) const; }; struct CYCondition : @@ -1277,7 +1300,7 @@ struct CYCondition : CYPrecedence(15) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYAddressOf : @@ -1295,7 +1318,7 @@ struct CYAddressOf : CYAlphabetic(false) CYPrecedence(2) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYIndirect : @@ -1313,7 +1336,7 @@ struct CYIndirect : CYAlphabetic(false) CYPrecedence(1) - virtual void Output(std::ostream &out, CYFlags flags) const; + virtual void Output(CYOutput &out, CYFlags flags) const; }; #define CYPostfix_(op, name) \ -- 2.45.2