package com.hpctoday.fada.c2fada;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import com.hpctoday.fada.Expression;
/*
* This class creates the FADA Array Access Node
*/
public class ArrayAccessVisitor extends ASTVisitor {
String id;
List<Expression> indices;
ArrayAccessVisitor() {
indices = new ArrayList<Expression>();
this.shouldVisitExpressions=true;
}
public int visit(IASTExpression expr) {
if (expr instanceof IASTIdExpression ){
id = expr.getRawSignature();
return PROCESS_SKIP;
} else if (expr instanceof IASTArraySubscriptExpression) {
IASTArraySubscriptExpression arrayExpr = (IASTArraySubscriptExpression) expr;
IASTInitializerClause subscript = arrayExpr.getArgument();
ExprVisitor exprVisitor = new ExprVisitor();
subscript.accept(exprVisitor);
indices.add(((Expression) exprVisitor.finalExpr));
visit(arrayExpr.getArrayExpression());
return PROCESS_SKIP;
} else {
return PROCESS_ABORT;
}
}
}