Package com.hpctoday.fada.c2fada

Source Code of com.hpctoday.fada.c2fada.ArrayAccessVisitor

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;
    }
  }
}
TOP

Related Classes of com.hpctoday.fada.c2fada.ArrayAccessVisitor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.