X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/37954781d9756ece500551055562183a1e28e943..6a9812501258df26b7c487e50744b91abe8ebe39:/Output.cpp?ds=sidebyside diff --git a/Output.cpp b/Output.cpp index d36afe6..26dc81f 100644 --- a/Output.cpp +++ b/Output.cpp @@ -1,4 +1,4 @@ -/* Cycript - Remove Execution Server and Disassembler +/* Cycript - Inlining/Optimizing JavaScript Compiler * Copyright (C) 2009 Jay Freeman (saurik) */ @@ -59,7 +59,7 @@ _finline CYFlags &operator |=(CYFlags &lhs, CYFlags rhs) { } _finline CYFlags CYLeft(CYFlags flags) { - return flags & ~CYNoDangle; + return flags & ~(CYNoDangle | CYNoInteger); } _finline CYFlags CYRight(CYFlags flags) { @@ -85,14 +85,22 @@ CYOutput &CYOutput::operator <<(char rhs) { for (unsigned i(0); i != indent_; ++i) out_ << " "; else goto done; - else goto work; - + else if (rhs == '\r') { + if (right_) { + out_ << '\n'; + right_ = false; + } goto done; + } else goto work; + + right_ = true; mode_ = NoMode; goto done; work: - if (mode_ == Terminated && rhs != '}') + if (mode_ == Terminated && rhs != '}') { + right_ = true; out_ << ';'; + } if (rhs == ';') { if (pretty_) @@ -116,6 +124,7 @@ CYOutput &CYOutput::operator <<(char rhs) { } else none: mode_ = NoMode; + right_ = true; out_ << rhs; done: return *this; @@ -141,6 +150,7 @@ CYOutput &CYOutput::operator <<(const char *rhs) { else mode_ = NoMode; + right_ = true; out_ << rhs; return *this; } @@ -222,6 +232,13 @@ void Catch::Output(CYOutput &out) const { } } +void CYComment::Output(CYOutput &out, CYFlags flags) const { + out << '\r'; + out.out_ << value_; + out.right_ = true; + out << '\r'; +} + void CYCompound::Output(CYOutput &out, CYFlags flags) const { if (CYExpression *expression = expressions_) if (CYExpression *next = expression->next_) { @@ -266,7 +283,7 @@ void CYClause::Output(CYOutput &out) const { } const char *CYDeclaration::ForEachIn() const { - return identifier_->Value(); + return identifier_->Word(); } void CYDeclaration::ForIn(CYOutput &out, CYFlags flags) const { @@ -398,7 +415,8 @@ void CYForEachInComprehension::Output(CYOutput &out) const { void CYForIn::Output(CYOutput &out, CYFlags flags) const { out << "for" << ' ' << '('; - initialiser_->ForIn(out, CYNoIn); + if (initialiser_ != NULL) + initialiser_->ForIn(out, CYNoIn); out << "in" << *set_ << ')'; code_->Single(out, CYRight(flags)); } @@ -413,6 +431,8 @@ void CYFunction::Output(CYOutput &out, CYFlags flags) const { if (protect) out << '('; out << "function"; + if (out.options_.verbose_) + out.out_ << ':' << static_cast(this); if (name_ != NULL) out << ' ' << *name_; out << '(' << parameters_ << ')'; @@ -435,6 +455,10 @@ void CYFunctionParameter::Output(CYOutput &out) const { out << ',' << ' ' << *next_; } +const char *CYIdentifier::Word() const { + return replace_ == NULL || replace_ == this ? CYWord::Word() : replace_->Word(); +} + void CYIf::Output(CYOutput &out, CYFlags flags) const { bool protect(false); if (false_ == NULL && (flags & CYNoDangle) != 0) { @@ -513,7 +537,11 @@ void CYNull::Output(CYOutput &out, CYFlags flags) const { void CYNumber::Output(CYOutput &out, CYFlags flags) const { std::ostringstream str; CYNumerify(str, Value()); - out << str.str().c_str(); + std::string value(str.str()); + out << value.c_str(); + // XXX: this should probably also handle hex conversions and exponents + if ((flags & CYNoInteger) != 0 && value.find('.') == std::string::npos) + out << '.'; } void CYNumber::PropertyName(CYOutput &out) const { @@ -627,8 +655,6 @@ static const char *Reserved_[] = { "let", "yield", - "each", - NULL }; @@ -694,15 +720,21 @@ void CYWith::Output(CYOutput &out, CYFlags flags) const { void CYWord::ClassName(CYOutput &out, bool object) const { if (object) out << "objc_getClass("; - out << '"' << Value() << '"'; + out << '"' << Word() << '"'; if (object) out << ')'; } void CYWord::Output(CYOutput &out) const { - out << Value(); + out << Word(); + if (out.options_.verbose_) + out.out_ << '@' << this; } void CYWord::PropertyName(CYOutput &out) const { Output(out); } + +const char *CYWord::Word() const { + return word_; +}