Refactoring to separate the logic bridging expressions with values, and the logic for nullability on pointer values to increase reusability of each piece of logic.

PiperOrigin-RevId: 466890614
diff --git a/nullability_verification/pointer_nullability.h b/nullability_verification/pointer_nullability.h
index ab5fd68..c8d69e9 100644
--- a/nullability_verification/pointer_nullability.h
+++ b/nullability_verification/pointer_nullability.h
@@ -15,12 +15,10 @@
 namespace tidy {
 namespace nullability {
 
-/// Returns the properties representing the nullness information of a pointer.
-///
-/// The first boolean indicates if the pointer's nullability is known.
-/// The second boolean indicates if the pointer's value is not null.
-std::pair<dataflow::AtomicBoolValue&, dataflow::AtomicBoolValue&>
-getPointerNullState(const Expr* PointerExpr, const dataflow::Environment& Env);
+/// Returns the `PointerValue` allocated to `PointerExpr` if available,
+/// otherwise returns nullptr.
+dataflow::PointerValue* getPointerValueFromExpr(
+    const Expr* PointerExpr, const dataflow::Environment& Env);
 
 /// Returns the properties representing the nullness information of a pointer.
 ///
@@ -30,16 +28,6 @@
 getPointerNullState(const dataflow::PointerValue& PointerVal,
                     const dataflow::Environment& Env);
 
-/// Sets the nullness properties on the PointerValue assigned to `PointerExpr`
-/// if not already initialised.
-///
-/// The boolean properties may be constrained by specifying `KnownConstraint`
-/// and `NotNullConstraint`. Otherwise, the properties are set to freshly
-/// created atomic booleans.
-void initPointerNullState(const Expr* PointerExpr, dataflow::Environment& Env,
-                          dataflow::BoolValue* KnownConstraint = nullptr,
-                          dataflow::BoolValue* NotNullConstraint = nullptr);
-
 /// Sets the nullness properties on `PointerVal` if not already initialised.
 ///
 /// The boolean properties may be constrained by specifying `KnownConstraint`
@@ -50,6 +38,48 @@
                           dataflow::BoolValue* KnownConstraint = nullptr,
                           dataflow::BoolValue* NotNullConstraint = nullptr);
 
+/// Sets the nullness properties on `PointerVal` representing a nullptr if not
+/// already initialised.
+///
+/// `Known` is constrained to true, `NotNull` is constrained to false.
+inline void initNullPointer(dataflow::PointerValue& PointerVal,
+                            dataflow::Environment& Env) {
+  initPointerNullState(PointerVal, Env,
+                       /*KnownConstraint=*/&Env.getBoolLiteralValue(true),
+                       /*NotNullConstraint=*/&Env.getBoolLiteralValue(false));
+}
+
+/// Sets the nullness properties on `PointerVal` representing a pointer that is
+/// not null if not already initialised.
+///
+/// `Known` is constrained to true, `NotNull` is constrained to true.
+inline void initNotNullPointer(dataflow::PointerValue& PointerVal,
+                               dataflow::Environment& Env) {
+  initPointerNullState(PointerVal, Env,
+                       /*KnownConstraint=*/&Env.getBoolLiteralValue(true),
+                       /*NotNullConstraint=*/&Env.getBoolLiteralValue(true));
+}
+
+/// Sets the nullness properties on `PointerVal` representing a pointer that is
+/// nullable if not already initialised.
+///
+/// `Known` is constrained to true, `NotNull` is unconstrained.
+inline void initNullablePointer(dataflow::PointerValue& PointerVal,
+                                dataflow::Environment& Env) {
+  initPointerNullState(PointerVal, Env,
+                       /*KnownConstraint=*/&Env.getBoolLiteralValue(true));
+}
+
+/// Sets the nullness properties on `PointerVal` representing a pointer with
+/// unknown nullability if not already initialised.
+///
+/// `Known` is constrained to false, `NotNull` is unconstrained.
+inline void initUnknownPointer(dataflow::PointerValue& PointerVal,
+                               dataflow::Environment& Env) {
+  initPointerNullState(PointerVal, Env,
+                       /*KnownConstraint=*/&Env.getBoolLiteralValue(false));
+}
+
 }  // namespace nullability
 }  // namespace tidy
 }  // namespace clang