Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 1 | // Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 2 | // Exceptions. See /LICENSE for license information. |
| 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | |
| 5 | #ifndef DEVTOOLS_RUST_CC_INTEROP_LIFETIME_ANALYSIS_OBJECT_H_ |
| 6 | #define DEVTOOLS_RUST_CC_INTEROP_LIFETIME_ANALYSIS_OBJECT_H_ |
| 7 | |
Dmitri Gribenko | a087d23 | 2023-07-10 08:03:46 -0700 | [diff] [blame] | 8 | #include <optional> |
| 9 | #include <ostream> |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 10 | #include <string> |
| 11 | |
Luca Versari | 5082488 | 2023-01-23 05:51:35 -0800 | [diff] [blame] | 12 | #include "lifetime_annotations/function_lifetimes.h" |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 13 | #include "lifetime_annotations/lifetime.h" |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 14 | #include "clang/AST/Type.h" |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 15 | |
| 16 | namespace clang { |
| 17 | namespace tidy { |
| 18 | namespace lifetimes { |
| 19 | |
| 20 | // Any object that has a lifetime. Multiple objects might have the same |
| 21 | // lifetime, but two equal objects always have the same lifetime. |
Luca Versari | a12c9d5 | 2023-02-23 08:40:48 -0800 | [diff] [blame] | 22 | // An object may also represent a function whose lifetime signature is |
| 23 | // known, obtainable by GetFuncLifetimes. |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 24 | class Object { |
| 25 | public: |
Martin Brænne | 57e0bfa | 2022-07-01 13:27:14 -0700 | [diff] [blame] | 26 | Object(const Object&) = delete; |
Martin Brænne | 617c92b | 2022-07-01 06:25:54 -0700 | [diff] [blame] | 27 | Object(Object&&) = delete; |
Martin Brænne | 57e0bfa | 2022-07-01 13:27:14 -0700 | [diff] [blame] | 28 | Object& operator=(const Object&) = delete; |
Martin Brænne | 617c92b | 2022-07-01 06:25:54 -0700 | [diff] [blame] | 29 | Object& operator=(Object&&) = delete; |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 30 | |
Martin Brænne | 4a1231d | 2022-07-01 01:45:44 -0700 | [diff] [blame] | 31 | // Creates an object with the given lifetime and type. |
| 32 | // This constructor should only be used in tests. Outside of tests, use |
| 33 | // one of the ObjectRepository::CreateObject...() functions. |
Luca Versari | a12c9d5 | 2023-02-23 08:40:48 -0800 | [diff] [blame] | 34 | Object(Lifetime lifetime, clang::QualType type, |
| 35 | std::optional<FunctionLifetimes> func_lifetimes); |
Martin Brænne | 4a1231d | 2022-07-01 01:45:44 -0700 | [diff] [blame] | 36 | |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 37 | // Returns the lifetime of the object. |
| 38 | Lifetime GetLifetime() const { return lifetime_; } |
| 39 | |
| 40 | clang::QualType Type() const { return type_; } |
| 41 | |
| 42 | // Returns a textual representation of the object for debug logging. |
| 43 | std::string DebugString() const; |
| 44 | |
Luca Versari | 5082488 | 2023-01-23 05:51:35 -0800 | [diff] [blame] | 45 | // Returns the lifetimes of function that this object represents, if known; |
| 46 | // note that lifetimes may not be known even if GetFunc() returns non-null. |
| 47 | const std::optional<FunctionLifetimes>& GetFuncLifetimes() const { |
| 48 | return func_lifetimes_; |
| 49 | } |
| 50 | |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 51 | private: |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 52 | Lifetime lifetime_; |
| 53 | clang::QualType type_; |
Luca Versari | 5082488 | 2023-01-23 05:51:35 -0800 | [diff] [blame] | 54 | std::optional<FunctionLifetimes> func_lifetimes_; |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | std::ostream& operator<<(std::ostream& os, Object object); |
| 58 | |
| 59 | } // namespace lifetimes |
| 60 | } // namespace tidy |
| 61 | } // namespace clang |
| 62 | |
Luca Versari | 99fddff | 2022-05-25 10:22:32 -0700 | [diff] [blame] | 63 | #endif // DEVTOOLS_RUST_CC_INTEROP_LIFETIME_ANALYSIS_OBJECT_H_ |