forked from OSchip/llvm-project
Fold ASTOwningResult back into ActionResult.
llvm-svn: 111902
This commit is contained in:
parent
ba7bf59503
commit
e172be555d
|
@ -222,7 +222,8 @@ namespace clang {
|
||||||
bool Invalid;
|
bool Invalid;
|
||||||
|
|
||||||
public:
|
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(PtrTy val) : Val(val), Invalid(false) {}
|
||||||
ActionResult(const DiagnosticBuilder &) : Val(PtrTy()), Invalid(true) {}
|
ActionResult(const DiagnosticBuilder &) : Val(PtrTy()), Invalid(true) {}
|
||||||
|
|
||||||
|
@ -230,9 +231,15 @@ namespace clang {
|
||||||
ActionResult(const void *);
|
ActionResult(const void *);
|
||||||
ActionResult(volatile void *);
|
ActionResult(volatile void *);
|
||||||
|
|
||||||
PtrTy get() const { return Val; }
|
|
||||||
void set(PtrTy V) { Val = V; }
|
|
||||||
bool isInvalid() const { return Invalid; }
|
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; }
|
||||||
|
|
||||||
const ActionResult &operator=(PtrTy RHS) {
|
const ActionResult &operator=(PtrTy RHS) {
|
||||||
Val = RHS;
|
Val = RHS;
|
||||||
|
@ -258,17 +265,22 @@ namespace clang {
|
||||||
PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
|
PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
|
||||||
assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
|
assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
|
||||||
}
|
}
|
||||||
|
ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) { }
|
||||||
|
|
||||||
// These two overloads prevent void* -> bool conversions.
|
// These two overloads prevent void* -> bool conversions.
|
||||||
ActionResult(const void *);
|
ActionResult(const void *);
|
||||||
ActionResult(volatile void *);
|
ActionResult(volatile void *);
|
||||||
|
|
||||||
ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) { }
|
bool isInvalid() const { return PtrWithInvalid & 0x01; }
|
||||||
|
bool isUsable() const { return PtrWithInvalid > 0x01; }
|
||||||
|
|
||||||
PtrTy get() const {
|
PtrTy get() const {
|
||||||
void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
|
void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
|
||||||
return PtrTraits::getFromVoidPointer(VP);
|
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 set(PtrTy V) {
|
||||||
void *VP = PtrTraits::getAsVoidPointer(V);
|
void *VP = PtrTraits::getAsVoidPointer(V);
|
||||||
|
@ -276,8 +288,6 @@ namespace clang {
|
||||||
assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
|
assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInvalid() const { return PtrWithInvalid & 0x01; }
|
|
||||||
|
|
||||||
const ActionResult &operator=(PtrTy RHS) {
|
const ActionResult &operator=(PtrTy RHS) {
|
||||||
void *VP = PtrTraits::getAsVoidPointer(RHS);
|
void *VP = PtrTraits::getAsVoidPointer(RHS);
|
||||||
PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
|
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
|
/// ASTMultiPtr - A moveable smart pointer to multiple AST nodes. Only owns
|
||||||
/// the individual pointers, not the array holding them.
|
/// the individual pointers, not the array holding them.
|
||||||
template <typename PtrTy> class ASTMultiPtr;
|
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>
|
template <class PtrTy>
|
||||||
class ASTMultiPtr {
|
class ASTMultiPtr {
|
||||||
PtrTy *Nodes;
|
PtrTy *Nodes;
|
||||||
|
@ -439,8 +391,8 @@ namespace clang {
|
||||||
}
|
}
|
||||||
|
|
||||||
// These versions are hopefully no-ops.
|
// These versions are hopefully no-ops.
|
||||||
template <class T> inline
|
template <class T, bool C>
|
||||||
ASTOwningResult<T> move(ASTOwningResult<T> &ptr) {
|
inline ActionResult<T,C> move(ActionResult<T,C> &ptr) {
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,8 +431,8 @@ namespace clang {
|
||||||
typedef ActionResult<Decl*> DeclResult;
|
typedef ActionResult<Decl*> DeclResult;
|
||||||
typedef OpaquePtr<TemplateName> ParsedTemplateTy;
|
typedef OpaquePtr<TemplateName> ParsedTemplateTy;
|
||||||
|
|
||||||
typedef ASTOwningResult<Expr*> OwningExprResult;
|
typedef ActionResult<Expr*> OwningExprResult;
|
||||||
typedef ASTOwningResult<Stmt*> OwningStmtResult;
|
typedef ActionResult<Stmt*> OwningStmtResult;
|
||||||
|
|
||||||
inline Expr *move(Expr *E) { return E; }
|
inline Expr *move(Expr *E) { return E; }
|
||||||
inline Stmt *move(Stmt *S) { return S; }
|
inline Stmt *move(Stmt *S) { return S; }
|
||||||
|
|
|
@ -7470,7 +7470,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
|
||||||
|
|
||||||
return ActOnCallExpr(S, CE, LParenLoc,
|
return ActOnCallExpr(S, CE, LParenLoc,
|
||||||
MultiExprArg(*this, (ExprTy**)Args, NumArgs),
|
MultiExprArg(*this, (ExprTy**)Args, NumArgs),
|
||||||
CommaLocs, RParenLoc).result();
|
CommaLocs, RParenLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckMemberOperatorAccess(LParenLoc, Object, 0, Best->FoundDecl);
|
CheckMemberOperatorAccess(LParenLoc, Object, 0, Best->FoundDecl);
|
||||||
|
@ -7575,7 +7575,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
|
||||||
if (CheckFunctionCall(Method, TheCall))
|
if (CheckFunctionCall(Method, TheCall))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return MaybeBindToTemporary(TheCall).result();
|
return MaybeBindToTemporary(TheCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// BuildOverloadedArrowExpr - Build a call to an overloaded @c operator->
|
/// BuildOverloadedArrowExpr - Build a call to an overloaded @c operator->
|
||||||
|
|
Loading…
Reference in New Issue