X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/9efd8b032d404ee2ad8267df43e7888416e4ff83..210e14b3fd3765a57e5f151c159c2ad921dadc98:/Replace.cpp diff --git a/Replace.cpp b/Replace.cpp index 3538944..e6b761f 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -86,7 +86,7 @@ CYExpression *CYAssignment::Replace(CYContext &context) { } CYStatement *CYBlock::Replace(CYContext &context) { - statements_ = statements_->ReplaceAll(context); + context.ReplaceAll(statements_); if (statements_ == NULL) return $ CYEmpty(); return this; @@ -127,7 +127,7 @@ void Catch::Replace(CYContext &context) { $T() void CYClause::Replace(CYContext &context) { $T() context.Replace(case_); - statements_ = statements_->ReplaceAll(context); + context.ReplaceAll(statements_); next_->Replace(context); } @@ -136,9 +136,7 @@ CYStatement *CYComment::Replace(CYContext &context) { } CYExpression *CYCompound::Replace(CYContext &context) { - CYExpression **last(&expressions_); - for (CYExpression *next(expressions_); next != NULL; next = next->next_) - last = &(*last = next->Replace(context))->next_; + context.ReplaceAll(expressions_); return this; } @@ -215,15 +213,7 @@ CYProperty *CYDeclarations::Property(CYContext &context) { $T(NULL) } CYCompound *CYDeclarations::Replace(CYContext &context) { - CYCompound *compound; - if (next_ == NULL) compound: - compound = $ CYCompound(); - else { - compound = next_->Replace(context); - if (compound == NULL) - goto compound; - } - + CYCompound *compound(next_ == NULL ? $ CYCompound() : next_->Replace(context)); if (CYAssignment *assignment = declaration_->Assignment(context)) compound->AddPrev(assignment); return compound; @@ -463,10 +453,7 @@ namespace cy { namespace Syntax { CYExpression *New::AddArgument(CYContext &context, CYExpression *value) { - CYArgument **argument(&arguments_); - while (*argument != NULL) - argument = &(*argument)->next_; - *argument = $ CYArgument(value); + CYSetLast(arguments_, $ CYArgument(value)); return this; } @@ -545,7 +532,7 @@ void CYProgram::Replace(CYContext &context) { CYScope scope(CYScopeProgram, context, statements_); context.nextlocal_ = $ CYNonLocal(); - statements_ = statements_->ReplaceAll(context); + context.ReplaceAll(statements_); context.NonLocal(statements_); scope.Close(); @@ -559,8 +546,8 @@ void CYProgram::Replace(CYContext &context) { IdentifierUsages usages; if (offset < context.rename_.size()) - for (CYIdentifier *i(context.rename_[offset].identifier_); i != NULL; i = i->next_) - usages.insert(i); + CYForEach (i, context.rename_[offset].identifier_) + usages.insert(i); // XXX: totalling the probable occurrences and sorting by them would improve the result for (CYIdentifierUsageVector::const_iterator i(context.rename_.begin()); i != context.rename_.end(); ++i, ++offset) { @@ -592,7 +579,7 @@ void CYProgram::Replace(CYContext &context) { // XXX: at some point, this could become a keyword } - for (CYIdentifier *identifier(i->identifier_); identifier != NULL; identifier = identifier->next_) + CYForEach (identifier, i->identifier_) identifier->Set(name); } } @@ -634,6 +621,9 @@ CYScope::CYScope(CYScopeType type, CYContext &context, CYStatement *&statements) context_.scope_ = this; } +CYScope::~CYScope() { +} + void CYScope::Close() { context_.scope_ = parent_; Scope(context_, statements_); @@ -748,13 +738,6 @@ CYStatement *CYStatement::Collapse(CYContext &context) { return this; } -CYStatement *CYStatement::ReplaceAll(CYContext &context) { $T(NULL) - CYStatement *replace(this); - context.Replace(replace); - replace->SetNext(next_->ReplaceAll(context)); - return replace->Collapse(context); -} - CYString *CYString::Concat(CYContext &context, CYString *rhs) const { size_t size(size_ + rhs->size_); char *value($ char[size + 1]);