001/*
002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon)
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 */
009
010package org.eclipse.golo.compiler.ir;
011
012public final class LoopBreakFlowStatement extends GoloStatement {
013
014  public static enum Type {
015    BREAK, CONTINUE
016  }
017
018  private final Type type;
019  private LoopStatement enclosingLoop;
020
021  private LoopBreakFlowStatement(Type type) {
022    super();
023    this.type = type;
024  }
025
026  public static LoopBreakFlowStatement newContinue() {
027    return new LoopBreakFlowStatement(Type.CONTINUE);
028  }
029
030  public static LoopBreakFlowStatement newBreak() {
031    return new LoopBreakFlowStatement(Type.BREAK);
032  }
033
034  public Type getType() {
035    return type;
036  }
037
038  public LoopStatement getEnclosingLoop() {
039    return enclosingLoop;
040  }
041
042  public void setEnclosingLoop(LoopStatement enclosingLoop) {
043    this.enclosingLoop = enclosingLoop;
044  }
045
046  @Override
047  public void accept(GoloIrVisitor visitor) {
048    visitor.visitLoopBreakFlowStatement(this);
049  }
050
051  @Override
052  public void walk(GoloIrVisitor visitor) {
053    // nothing to do, not a composite
054  }
055
056  @Override
057  protected void replaceElement(GoloElement original, GoloElement newElement) {
058    throw cantReplace();
059  }
060
061}