package x2x.translator.xcodeml.transformation;

import java.util.ArrayList;

import x2x.translator.xcodeml.xelement.XcodeProg;
import x2x.translator.xcodeml.transformer.Transformer;

/**
 * An dependent transformation group check wether it can be transformed with
 * another pending transformation in the pipeline. Each transformation are
 * applied only once.
 */

public class DependentTransformationGroup<T extends Transformation<? super T>> extends TransformationGroup<T> {

  public DependentTransformationGroup(String name) {
    super(name);
  }

  public void applyTranslations(XcodeProg xcodeml, Transformer transformer){
    for(int i = 0; i < _translations.size(); ++i){
      T base = _translations.get(i);
      for(int j = i + 1; j < _translations.size(); ++j){
        T candidate = _translations.get(j);
        if(candidate.isTransformed()){
          continue;
        }
        if(base.canBeTransformedWith(candidate)){
          base.transform(xcodeml, transformer, candidate);
        }
      }
    }
  }
}

@@ -1019,10 +1019,415 @@
   %7D%0A  %7D%0A
+%0A%0A  // In the dependent transformation group, the order in which transformation%0A  // appears is important%0A  public void add(T translation)%7B%0A    int linePosition = translation.getStartLine();%0A    int insertIndex = 0;%0A    for(Transformation t : _translations)%7B%0A      if(t.getStartLine() %3E linePosition)%7B%0A        break;%0A      %7D%0A      ++insertIndex;%0A    %7D%0A    _translations.add(insertIndex, translation);%0A  %7D%0A
 %7D%0A

Add transformation in the pipeline according to their position