blob: de57ac7293643032b923710ae2fecf884ae06318 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2007, 2020 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.r.core.rsource.ast;
import static org.eclipse.statet.r.core.rsource.IRSourceConstants.STATUS2_SYNTAX_EXPR_AS_BODY_MISSING;
import static org.eclipse.statet.r.core.rsource.IRSourceConstants.STATUS3_REPEAT;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.statet.jcommons.lang.NonNullByDefault;
import org.eclipse.statet.jcommons.lang.Nullable;
import org.eclipse.statet.ltk.ast.core.AstNode;
import org.eclipse.statet.ltk.ast.core.AstVisitor;
import org.eclipse.statet.r.core.rlang.RTerminal;
/**
* <code>repeat §cont§</code>
*/
@NonNullByDefault
public final class CRepeatLoop extends RAstNode {
final Expression loopExpr= new Expression();
CRepeatLoop() {
}
@Override
public final NodeType getNodeType() {
return NodeType.C_REPEAT;
}
@Override
public final RTerminal getOperator(final int index) {
return RTerminal.WHILE;
}
@Override
public final boolean hasChildren() {
return true;
}
@Override
public final int getChildCount() {
return 1;
}
@Override
public final RAstNode getChild(final int index) {
switch (index) {
case 0:
return this.loopExpr.node;
default:
throw new IndexOutOfBoundsException();
}
}
@Override
public final RAstNode[] getChildren() {
return new RAstNode[] { this.loopExpr.node };
}
@Override
public final int getChildIndex(final AstNode child) {
if (this.loopExpr.node == child) {
return 0;
}
return -1;
}
public final RAstNode getContChild() {
return this.loopExpr.node;
}
@Override
public final void acceptInR(final RAstVisitor visitor) throws InvocationTargetException {
visitor.visit(this);
}
@Override
public final void acceptInRChildren(final RAstVisitor visitor) throws InvocationTargetException {
this.loopExpr.node.acceptInR(visitor);
}
@Override
public final void acceptInChildren(final AstVisitor visitor) throws InvocationTargetException {
visitor.visit(this.loopExpr.node);
}
@Override
final @Nullable Expression getExpr(final RAstNode child) {
if (this.loopExpr.node == child) {
return this.loopExpr;
}
return null;
}
@Override
final @Nullable Expression getLeftExpr() {
return null;
}
@Override
final Expression getRightExpr() {
return this.loopExpr;
}
@Override
public final boolean equalsSingle(final RAstNode element) {
return (NodeType.C_REPEAT == element.getNodeType());
}
@Override
final int getMissingExprStatus(final Expression expr) {
if (this.loopExpr == expr) {
return (STATUS2_SYNTAX_EXPR_AS_BODY_MISSING | STATUS3_REPEAT);
}
throw new IllegalArgumentException();
}
final void updateOffsets() {
this.endOffset= this.loopExpr.node.endOffset;
}
}