package jetbrains.mps.kotlin.dataFlow;

/*Generated by MPS */

import jetbrains.mps.lang.dataFlow.DataFlowBuilder;
import jetbrains.mps.lang.dataFlow.DataFlowBuilderContext;
import jetbrains.mps.kotlin.behavior.AbstractConditionalLoop__BehaviorDescriptor;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.kotlin.dataflow.instructions.ResetBooleanStateMarker;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

public class WhileStatement_DataFlow extends DataFlowBuilder {
  public void build(final DataFlowBuilderContext _context) {
    if (!((boolean) AbstractConditionalLoop__BehaviorDescriptor.isRunOnce_id4vugIDe7jmg.invoke(_context.getNode()))) {
      _context.getBuilder().build((SNode) SLinkOperations.getTarget(_context.getNode(), LINKS.condition$2cvd));
      _context.getBuilder().emitJump(_context.getBuilder().after(_context.getNode()), "r:08ab5e45-1c79-495b-9ba5-962c1dd58af6(jetbrains.mps.kotlin.dataFlow)/6374444830330945462");
    } else {
      _context.getBuilder().emitWrite(SLinkOperations.getTarget(_context.getNode(), LINKS.condition$2cvd), ResetBooleanStateMarker.get(), "r:08ab5e45-1c79-495b-9ba5-962c1dd58af6(jetbrains.mps.kotlin.dataFlow)/8386893935424195186");
      _context.getBuilder().build((SNode) SLinkOperations.getTarget(_context.getNode(), LINKS.condition$2cvd));

      // Branch assumed to be true
      _context.getBuilder().emitIfJump(_context.getBuilder().label(_context.getNode(), "content"), "r:08ab5e45-1c79-495b-9ba5-962c1dd58af6(jetbrains.mps.kotlin.dataFlow)/8386893935424200145");
      _context.getBuilder().emitJump(_context.getBuilder().after(_context.getNode()), "r:08ab5e45-1c79-495b-9ba5-962c1dd58af6(jetbrains.mps.kotlin.dataFlow)/8386893935424202764");
    }

    _context.getBuilder().emitLabel("content");
    ListSequence.fromList(SLinkOperations.getChildren(_context.getNode(), LINKS.statements$R3pt)).visitAll((it) -> _context.getBuilder().build((SNode) it));
    _context.getBuilder().emitJump(_context.getBuilder().before(_context.getNode()), "r:08ab5e45-1c79-495b-9ba5-962c1dd58af6(jetbrains.mps.kotlin.dataFlow)/8386893935424205824");
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink condition$2cvd = MetaAdapterFactory.getContainmentLink(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x47de42ea4e1d0294L, 0x28bef6d7551af746L, "condition");
    /*package*/ static final SContainmentLink statements$R3pt = MetaAdapterFactory.getContainmentLink(0x6b3888c1980244d8L, 0x8baff8e6c33ed689L, 0x123d0b402b8869eeL, 0x123d0b402b8869f1L, "statements");
  }
}
