aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Sema/Ownership.h86
-rw-r--r--lib/Sema/SemaOverload.cpp4
2 files changed, 21 insertions, 69 deletions
diff --git a/include/clang/Sema/Ownership.h b/include/clang/Sema/Ownership.h
index 8b42004e78..ef9b8f3b6e 100644
--- a/include/clang/Sema/Ownership.h
+++ b/include/clang/Sema/Ownership.h
@@ -222,7 +222,8 @@ namespace clang {
bool Invalid;
public:
- ActionResult(bool Invalid = false) : Val(PtrTy()), Invalid(Invalid) {}
+ ActionResult(bool Invalid = false)
+ : Val(PtrTy()), Invalid(Invalid) {}
ActionResult(PtrTy val) : Val(val), Invalid(false) {}
ActionResult(const DiagnosticBuilder &) : Val(PtrTy()), Invalid(true) {}
@@ -230,9 +231,15 @@ namespace clang {
ActionResult(const void *);
ActionResult(volatile void *);
+ bool isInvalid() const { return Invalid; }
+ bool isUsable() const { return !Invalid && Val; }
+
PtrTy get() const { return Val; }
+ PtrTy release() const { return Val; }
+ PtrTy take() const { return Val; }
+ template <typename T> T *takeAs() { return static_cast<T*>(get()); }
+
void set(PtrTy V) { Val = V; }
- bool isInvalid() const { return Invalid; }
const ActionResult &operator=(PtrTy RHS) {
Val = RHS;
@@ -258,17 +265,22 @@ namespace clang {
PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
}
+ ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) { }
// These two overloads prevent void* -> bool conversions.
ActionResult(const void *);
ActionResult(volatile void *);
- ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) { }
+ bool isInvalid() const { return PtrWithInvalid & 0x01; }
+ bool isUsable() const { return PtrWithInvalid > 0x01; }
PtrTy get() const {
void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
return PtrTraits::getFromVoidPointer(VP);
}
+ PtrTy take() const { return get(); }
+ PtrTy release() const { return get(); }
+ template <typename T> T *takeAs() { return static_cast<T*>(get()); }
void set(PtrTy V) {
void *VP = PtrTraits::getAsVoidPointer(V);
@@ -276,8 +288,6 @@ namespace clang {
assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
}
- bool isInvalid() const { return PtrWithInvalid & 0x01; }
-
const ActionResult &operator=(PtrTy RHS) {
void *VP = PtrTraits::getAsVoidPointer(RHS);
PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
@@ -286,68 +296,10 @@ namespace clang {
}
};
- /// ASTOwningResult - A moveable smart pointer for AST nodes that also
- /// has an extra flag to indicate an additional success status.
- template <typename PtrTy> class ASTOwningResult;
-
/// ASTMultiPtr - A moveable smart pointer to multiple AST nodes. Only owns
/// the individual pointers, not the array holding them.
template <typename PtrTy> class ASTMultiPtr;
- template <class PtrTy> class ASTOwningResult {
- public:
- typedef ActionResult<PtrTy> DumbResult;
-
- private:
- DumbResult Result;
-
- public:
- explicit ASTOwningResult(bool invalid = false)
- : Result(invalid) { }
- ASTOwningResult(PtrTy node) : Result(node) { }
- ASTOwningResult(const DumbResult &res) : Result(res) { }
- // Normal copying semantics are defined implicitly.
-
- // These two overloads prevent void* -> bool conversions.
- explicit ASTOwningResult(const void *);
- explicit ASTOwningResult(volatile void *);
-
- /// Assignment from a raw pointer.
- ASTOwningResult &operator=(PtrTy raw) {
- Result = raw;
- return *this;
- }
-
- /// Assignment from an ActionResult.
- ASTOwningResult &operator=(const DumbResult &res) {
- Result = res;
- return *this;
- }
-
- bool isInvalid() const { return Result.isInvalid(); }
-
- /// Does this point to a usable AST node? To be usable, the node
- /// must be valid and non-null.
- bool isUsable() const { return !Result.isInvalid() && get(); }
-
- /// It is forbidden to call either of these methods on an invalid
- /// pointer. We should assert that, but we're not going to,
- /// because it's likely to trigger it unpredictable ways on
- /// invalid code.
- PtrTy get() const { return Result.get(); }
- PtrTy take() const { return get(); }
-
- /// Take outside ownership of the raw pointer and cast it down.
- template<typename T>
- T *takeAs() { return static_cast<T*>(get()); }
-
- /// Alias for interface familiarity with unique_ptr.
- PtrTy release() { return take(); }
-
- /// Pass ownership to a classical ActionResult.
- DumbResult result() { return Result; }
- };
-
template <class PtrTy>
class ASTMultiPtr {
PtrTy *Nodes;
@@ -439,8 +391,8 @@ namespace clang {
}
// These versions are hopefully no-ops.
- template <class T> inline
- ASTOwningResult<T> move(ASTOwningResult<T> &ptr) {
+ template <class T, bool C>
+ inline ActionResult<T,C> move(ActionResult<T,C> &ptr) {
return ptr;
}
@@ -479,8 +431,8 @@ namespace clang {
typedef ActionResult<Decl*> DeclResult;
typedef OpaquePtr<TemplateName> ParsedTemplateTy;
- typedef ASTOwningResult<Expr*> OwningExprResult;
- typedef ASTOwningResult<Stmt*> OwningStmtResult;
+ typedef ActionResult<Expr*> OwningExprResult;
+ typedef ActionResult<Stmt*> OwningStmtResult;
inline Expr *move(Expr *E) { return E; }
inline Stmt *move(Stmt *S) { return S; }
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index f115a793a9..09adf14450 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -7470,7 +7470,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
return ActOnCallExpr(S, CE, LParenLoc,
MultiExprArg(*this, (ExprTy**)Args, NumArgs),
- CommaLocs, RParenLoc).result();
+ CommaLocs, RParenLoc);
}
CheckMemberOperatorAccess(LParenLoc, Object, 0, Best->FoundDecl);
@@ -7575,7 +7575,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
if (CheckFunctionCall(Method, TheCall))
return true;
- return MaybeBindToTemporary(TheCall).result();
+ return MaybeBindToTemporary(TheCall);
}
/// BuildOverloadedArrowExpr - Build a call to an overloaded @c operator->