]> git.saurik.com Git - cycript.git/blobdiff - Replace.cpp
Support SO variable even when not Mach.
[cycript.git] / Replace.cpp
index 353894483deed0a2e58693bf937466d30561c50d..5803478d1d6ffc16418e3c703eae99c3f0a6c527 100644 (file)
@@ -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);
     }
 }
@@ -748,13 +735,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]);