Index: include/clang/AST/SideEffectFinder.h =================================================================== --- /dev/null +++ include/clang/AST/SideEffectFinder.h @@ -0,0 +1,41 @@ +//===--- SideEffectFinder.h - Visitor for finding side-effects --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the SideEffectFinder. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_SIDEEFECTFINDER_H +#define LLVM_CLANG_AST_SIDEEFECTFINDER_H + +#include "clang/AST/EvaluatedExprVisitor.h" + +namespace clang { +/// \brief Look for any side effects within an Expr. +class SideEffectFinder : public ConstEvaluatedExprVisitor { + typedef ConstEvaluatedExprVisitor Inherited; + const bool IncludePossibleEffects; + bool HasSideEffects; + +public: + explicit SideEffectFinder(const ASTContext &Context, bool IncludePossible) + : Inherited(Context), + IncludePossibleEffects(IncludePossible), HasSideEffects(false) { } + + bool hasSideEffects() const { return HasSideEffects; } + + void VisitExpr(const Expr *E) { + if (!HasSideEffects && + E->HasSideEffects(Context, IncludePossibleEffects)) + HasSideEffects = true; + } +}; +} // end namespace clang + +#endif Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -22,6 +22,7 @@ #include "clang/AST/ExprCXX.h" #include "clang/AST/Mangle.h" #include "clang/AST/RecordLayout.h" +#include "clang/AST/SideEffectFinder.h" #include "clang/AST/StmtVisitor.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CharInfo.h" @@ -2892,28 +2893,6 @@ return false; } -namespace { - /// \brief Look for any side effects within a Stmt. - class SideEffectFinder : public ConstEvaluatedExprVisitor { - typedef ConstEvaluatedExprVisitor Inherited; - const bool IncludePossibleEffects; - bool HasSideEffects; - - public: - explicit SideEffectFinder(const ASTContext &Context, bool IncludePossible) - : Inherited(Context), - IncludePossibleEffects(IncludePossible), HasSideEffects(false) { } - - bool hasSideEffects() const { return HasSideEffects; } - - void VisitExpr(const Expr *E) { - if (!HasSideEffects && - E->HasSideEffects(Context, IncludePossibleEffects)) - HasSideEffects = true; - } - }; -} - bool Expr::HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects) const { // In circumstances where we care about definite side effects instead of