[cfe-commits] r76795 - in /cfe/trunk: include/clang/Analysis/Support/SaveAndRestore.h lib/Analysis/CFG.cpp
Ted Kremenek
kremenek at apple.com
Wed Jul 22 14:45:16 PDT 2009
Author: kremenek
Date: Wed Jul 22 16:45:16 2009
New Revision: 76795
URL: http://llvm.org/viewvc/llvm-project?rev=76795&view=rev
Log:
Make 'SaveAndRestore' and friends reusable classes in libAnalysis.
Added:
cfe/trunk/include/clang/Analysis/Support/SaveAndRestore.h
Modified:
cfe/trunk/lib/Analysis/CFG.cpp
Added: cfe/trunk/include/clang/Analysis/Support/SaveAndRestore.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Support/SaveAndRestore.h?rev=76795&view=auto
==============================================================================
--- cfe/trunk/include/clang/Analysis/Support/SaveAndRestore.h (added)
+++ cfe/trunk/include/clang/Analysis/Support/SaveAndRestore.h Wed Jul 22 16:45:16 2009
@@ -0,0 +1,44 @@
+//===-- SaveAndRestore.h - Utility -------------------------------*- C++ -*-=//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides utility classes that uses RAII to save and restore
+// values.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_ANALYSIS_SAVERESTORE
+#define LLVM_CLANG_ANALYSIS_SAVERESTORE
+
+namespace clang {
+
+// SaveAndRestore - A utility class that uses RAII to save and restore
+// the value of a variable.
+template<typename T>
+struct SaveAndRestore {
+ SaveAndRestore(T& x) : X(x), old_value(x) {}
+ ~SaveAndRestore() { X = old_value; }
+ T get() { return old_value; }
+private:
+ T& X;
+ T old_value;
+};
+
+// SaveOr - Similar to SaveAndRestore. Operates only on bools; the old
+// value of a variable is saved, and during the dstor the old value is
+// or'ed with the new value.
+struct SaveOr {
+ SaveOr(bool& x) : X(x), old_value(x) { x = false; }
+ ~SaveOr() { X |= old_value; }
+private:
+ bool& X;
+ const bool old_value;
+};
+
+}
+#endif
\ No newline at end of file
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=76795&r1=76794&r2=76795&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Wed Jul 22 16:45:16 2009
@@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/Analysis/Support/SaveAndRestore.h"
#include "clang/Analysis/CFG.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/PrettyPrinter.h"
@@ -27,18 +28,6 @@
namespace {
-// SaveAndRestore - A utility class that uses RIIA to save and restore
-// the value of a variable.
-template<typename T>
-struct VISIBILITY_HIDDEN SaveAndRestore {
- SaveAndRestore(T& x) : X(x), old_value(x) {}
- ~SaveAndRestore() { X = old_value; }
- T get() { return old_value; }
-
- T& X;
- T old_value;
-};
-
static SourceLocation GetEndLoc(Decl* D) {
if (VarDecl* VD = dyn_cast<VarDecl>(D))
if (Expr* Ex = VD->getInit())
More information about the cfe-commits
mailing list