All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.ppg.generator.Loop Maven / Gradle / Ivy

There is a newer version: 10.0.0.Beta3
Show newest version
package org.infinispan.ppg.generator;

import java.util.List;
import java.util.Set;

public class Loop implements Element {
   final Reference counter;
   final Element element;

   public Loop(Reference counter, Element element) {
      this.counter = counter;
      this.element = element;
   }

   @Override
   public void addReferences(Set references) {
      references.add(counter);
      element.addReferences(references);
   }

   @Override
   public Machine.State addStates(Machine.State prev, Machine.State target, Machine machine, Grammar grammar, List ruleStack) {
      prev.addSentinel(counter.sourceName + " == 0", target);
      Machine.State afterDecrement = prev.addAction(counter.sourceName + "--;", machine.addState(ruleStack));
      element.addStates(afterDecrement, prev, machine, grammar, ruleStack);
      return target;
   }

   @Override
   public String analyzeType(Grammar grammar) {
      // repetition is supposed to cause side-effects such as accumulation, not return value
      return "";
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy