//--------------------------------------------------------- VarDecl* isFortranLoop(ForStmt* Node, const char*& errMsg) { // cond must be of form "x >/</!=/ expr": BinaryOperator* condCmp = dyn_cast_or_null<BinaryOperator>(Node->getCond()); if (condCmp == 0 || ((!condCmp->isRelationalOp()) && condCmp->getOpcode() != BO_NE)) { errMsg = "for-cond not fortran-like (must be x rel expr)"; return 0; } DeclRefExpr* condVar = dyn_cast<DeclRefExpr>(stripParenCasts(condCmp->getLHS())); if (condVar == 0 || !condVar->getType()->isIntegerType()) { errMsg = "no integer for-init variable"; return 0; } VarDecl* VD = dyn_cast<VarDecl>(condVar->getDecl()); if (VD == 0) { errMsg = "strange unrecognized lhs in for-condition"; return 0; } // inc must be of form "++x/x++": UnaryOperator* incStmt = dyn_cast_or_null<UnaryOperator>(Node->getInc()); if (incStmt == 0 || (!incStmt->isIncrementOp())) { errMsg = "for-inc not fortran-like (must be ++x/x++)"; return 0; } DeclRefExpr* incVar = dyn_cast<DeclRefExpr>(incStmt->getSubExpr()); if (incVar == 0 || incVar->getDecl() != VD) { errMsg = "for-inc doesn't refer to for-cond variable"; return 0; } return VD; }