001/*
002 * Copyright (c) 2012-2018 Institut National des Sciences Appliquées de Lyon (INSA Lyon) and others
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License 2.0 which is available at
006 * http://www.eclipse.org/legal/epl-2.0.
007 *
008 * SPDX-License-Identifier: EPL-2.0
009 */
010
011package gololang.ir;
012
013public final class LoopBreakFlowStatement extends GoloStatement<LoopBreakFlowStatement> {
014
015  public enum Type {
016    BREAK, CONTINUE
017  }
018
019  private final Type type;
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  protected LoopBreakFlowStatement self() { return this; }
035
036  public Type getType() {
037    return type;
038  }
039
040  public LoopStatement getEnclosingLoop() {
041    return ancestorOfType(LoopStatement.class);
042  }
043
044  /**
045   * {@inheritDoc}
046   */
047  @Override
048  public void accept(GoloIrVisitor visitor) {
049    visitor.visitLoopBreakFlowStatement(this);
050  }
051
052  /**
053   * {@inheritDoc}
054   */
055  @Override
056  protected void replaceElement(GoloElement<?> original, GoloElement<?> newElement) {
057    throw cantReplace();
058  }
059
060}