NamedDecl* RedundantLocalVariableRule::extractFromReturnStmt(Stmt *stmt) {
  ReturnStmt *returnStmt = dyn_cast<ReturnStmt>(stmt);
  if (returnStmt) {
    Expr *returnValue = returnStmt->getRetValue();
    if (returnValue) {
      ImplicitCastExpr *implicitCastExpr = dyn_cast<ImplicitCastExpr>(returnValue);
      if (implicitCastExpr) {
        DeclRefExpr *returnExpr = dyn_cast<DeclRefExpr>(implicitCastExpr->getSubExpr());
        if (returnExpr) {
          return returnExpr->getFoundDecl();
        }
      }
    }
  }
  return NULL;
}
예제 #2
0
 bool VisitBinaryOperator(BinaryOperator *binaryOperator)
 {
     Expr *leftExpr = binaryOperator->getLHS();
     if (binaryOperator->getOpcode() == BO_Assign && leftExpr && isa<DeclRefExpr>(leftExpr))
     {
         DeclRefExpr *declRefExpr = dyn_cast<DeclRefExpr>(leftExpr);
         for (const auto& name : _names)
         {
             if (declRefExpr->getFoundDecl()->getNameAsString() == name)
             {
                 _binaryOperators.push_back(binaryOperator);
                 break;
             }
         }
     }
     return true;
 }