//===- Ownership.h - Parser ownership helpers -------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file contains classes for managing ownership of Stmt and Expr nodes. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_SEMA_OWNERSHIP_H #define LLVM_CLANG_SEMA_OWNERSHIP_H #include "clang/AST/Expr.h" #include "clang/Basic/LLVM.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/Support/PointerLikeTypeTraits.h" #include "llvm/Support/type_traits.h" #include <cassert> #include <cstddef> #include <cstdint> //===----------------------------------------------------------------------===// // OpaquePtr //===----------------------------------------------------------------------===// namespace clang { class CXXBaseSpecifier; class CXXCtorInitializer; class Decl; class Expr; class ParsedTemplateArgument; class QualType; class Stmt; class TemplateName; class TemplateParameterList; /// Wrapper for void* pointer. /// \tparam PtrTy Either a pointer type like 'T*' or a type that behaves like /// a pointer. /// /// This is a very simple POD type that wraps a pointer that the Parser /// doesn't know about but that Sema or another client does. The PtrTy /// template argument is used to make sure that "Decl" pointers are not /// compatible with "Type" pointers for example. template <class PtrTy> class OpaquePtr { … }; /// UnionOpaquePtr - A version of OpaquePtr suitable for membership /// in a union. template <class T> struct UnionOpaquePtr { … }; } // namespace clang namespace llvm { PointerLikeTypeTraits<clang::OpaquePtr<T>>; } // namespace llvm namespace clang { class StreamingDiagnostic; // Determines whether the low bit of the result pointer for the // given UID is always zero. If so, ActionResult will use that bit // for it's "invalid" flag. template <class Ptr> struct IsResultPtrLowBitFree { … }; /// The result of parsing/analyzing an expression, statement etc. /// /// It may be: /// - usable: a valid pointer to the result object /// - unset (null but valid): for constructs that may legitimately be absent /// (for example, the condition of a for loop) /// - invalid: indicating an error /// (no detail is provided, usually the error has already been diagnosed) template <class PtrTy, bool Compress = IsResultPtrLowBitFree<PtrTy>::value> class ActionResult { … }; // If we PtrTy has a free bit, we can represent "invalid" as nullptr|1. ActionResult<PtrTy, true>; /// An opaque type for threading parsed type information through the parser. ParsedType; UnionParsedType; // We can re-use the low bit of expression, statement, base, and // member-initializer pointers for the "invalid" flag of // ActionResult. template <> struct IsResultPtrLowBitFree<Expr *> { … }; template <> struct IsResultPtrLowBitFree<Stmt *> { … }; template <> struct IsResultPtrLowBitFree<CXXBaseSpecifier *> { … }; template <> struct IsResultPtrLowBitFree<CXXCtorInitializer *> { … }; ExprResult; StmtResult; TypeResult; BaseResult; MemInitResult; DeclResult; ParsedTemplateTy; UnionParsedTemplateTy; MultiExprArg; MultiStmtArg; ASTTemplateArgsPtr; MultiTypeArg; MultiTemplateParamsArg; inline ExprResult ExprError() { … } inline StmtResult StmtError() { … } inline TypeResult TypeError() { … } inline ExprResult ExprError(const StreamingDiagnostic &) { … } inline StmtResult StmtError(const StreamingDiagnostic &) { … } inline ExprResult ExprEmpty() { … } inline StmtResult StmtEmpty() { … } inline Expr *AssertSuccess(ExprResult R) { … } inline Stmt *AssertSuccess(StmtResult R) { … } } // namespace clang #endif // LLVM_CLANG_SEMA_OWNERSHIP_H