blob: b1ba6fdd55bb6462b64992109a64e4ed4998300c [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2007, 2019 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.STATUSFLAG_ERROR_IN_CHILD;
import static org.eclipse.statet.r.core.rsource.IRSourceConstants.STATUSFLAG_REAL_ERROR;
import java.lang.reflect.InvocationTargetException;
/**
* update offsets in expressions
* not for control statements or function def/calls
*/
/* package */ class RScannerPostExprVisitor extends RAstVisitor {
static final int SYNTAXERROR_MASK= (STATUSFLAG_REAL_ERROR | STATUSFLAG_ERROR_IN_CHILD);
private boolean syntaxError;
public int check(final RAstNode node) {
this.syntaxError= false;
try {
node.acceptInR(this);
}
catch (final InvocationTargetException e) {
// not used
}
if (this.syntaxError) {
return STATUSFLAG_ERROR_IN_CHILD;
}
return 0;
}
public int checkTerminal(final RAstNode node) {
if ((node.getStatusCode() & SYNTAXERROR_MASK) != 0) {
return STATUSFLAG_ERROR_IN_CHILD;
}
return 0;
}
private void doAcceptIn(final RAstNode child) throws InvocationTargetException {
final boolean savedSyntaxError= this.syntaxError;
this.syntaxError= false;
child.acceptInR(this);
if (this.syntaxError) {
child.rParent.status |= STATUSFLAG_ERROR_IN_CHILD;
}
this.syntaxError |= savedSyntaxError;
}
private void doAccecptInChildren(final RAstNode node) throws InvocationTargetException {
final boolean savedSyntaxError= this.syntaxError;
this.syntaxError= false;
node.acceptInRChildren(this);
if (this.syntaxError) {
node.status |= STATUSFLAG_ERROR_IN_CHILD;
}
this.syntaxError |= savedSyntaxError;
}
@Override
public void visit(final SourceComponent node) {
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Block node) {
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Group node) {
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final CIfElse node) throws InvocationTargetException {
if (node.withElse) {
doAcceptIn(node.elseExpr.node);
}
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final CForLoop node) throws InvocationTargetException {
doAcceptIn(node.loopExpr.node);
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final CRepeatLoop node) throws InvocationTargetException {
doAcceptIn(node.loopExpr.node);
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final CWhileLoop node) throws InvocationTargetException {
doAcceptIn(node.loopExpr.node);
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final FCall node) throws InvocationTargetException {
doAcceptIn(node.refExpr.node);
node.updateStartOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final FCall.Args node) {
// throw new IllegalStateException();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final FCall.Arg node) {
// throw new IllegalStateException();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final FDef node) throws InvocationTargetException {
doAcceptIn(node.expr.node);
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final FDef.Args node) {
// throw new IllegalStateException();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final FDef.Arg node) {
// throw new IllegalStateException();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Assignment node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateStartOffset();
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Model node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateStartOffset();
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Relational node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateStartOffset();
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Logical node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateStartOffset();
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Arithmetic node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateStartOffset();
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Power node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateStartOffset();
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Seq node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateStartOffset();
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Special node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateStartOffset();
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Sign node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final SubIndexed node) throws InvocationTargetException {
doAcceptIn(node.expr.node);
node.updateStartOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final SubIndexed.Args node) {
// throw new IllegalStateException();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final SubIndexed.Arg node) {
// throw new IllegalStateException();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final SubNamed node) throws InvocationTargetException {
doAcceptIn(node.expr.node);
// name by scanner
node.updateStartOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final NSGet node) throws InvocationTargetException {
// children by scanner
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final StringConst node) {
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final NumberConst node) {
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Symbol node) {
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Help node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
@Override
public void visit(final Dummy node) throws InvocationTargetException {
doAccecptInChildren(node);
node.updateStartOffset();
node.updateEndOffset();
this.syntaxError |= ((node.getStatusCode() & SYNTAXERROR_MASK) != 0);
}
/*
@Override
public void visit(CLoopCommand node) throws InvocationTargetException {
}
@Override
public void visit(NullConst node) throws InvocationTargetException {
}
*/
/*
public void visit(final Comment node) throws InvocationTargetException {
}
public void visit(final DocuComment node) throws InvocationTargetException {
node.acceptInRChildren(this);
}
public void visit(final DocuTag node) throws InvocationTargetException {
}
public void visit(final DocuText node) throws InvocationTargetException {
}
*/
}