================
@@ -2012,6 +2003,74 @@ enum class MultiVersionKind {
   TargetVersion
 };
 
+/// Represents a single C++26 contract annotation (P2900R14).
+///
+/// This is the primary template for pre-conditions (IsPostCondition=false).
+/// Nodes are ASTContext-allocated and form a singly-linked list on
+/// FunctionDecl.
+///
+/// \code
+///   int f(int x) pre(x > 0) pre(x < 100);
+///   //           ^~~~~~~~~~~ ^~~~~~~~~~~~
+///   //           two PreContractAnnotation nodes linked together
+/// \endcode
+template <bool IsPostCondition> class ContractAnnotationBase {
+  Expr *Predicate;
+  ContractAnnotationBase *Next = nullptr;
+  SourceLocation KwLoc;
+  SourceLocation LParenLoc, RParenLoc;
+
+public:
+  ContractAnnotationBase(Expr *Pred, SourceLocation KwLoc, SourceLocation LP,
+                         SourceLocation RP)
+      : Predicate(Pred), KwLoc(KwLoc), LParenLoc(LP), RParenLoc(RP) {}
+
+  Expr *getPredicate() const { return Predicate; }
+  void setPredicate(Expr *P) { Predicate = P; }
+  ContractAnnotationBase *getNext() const { return Next; }
+  void setNext(ContractAnnotationBase *N) { Next = N; }
+  SourceLocation getKeywordLoc() const { return KwLoc; }
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+  SourceLocation getRParenLoc() const { return RParenLoc; }
+};
+
+/// Specialization for post-conditions, which additionally store an optional
+/// result variable for the return value name in \c post(name: expr).
+///
+/// \code
+///   int f(int x) post(r: r >= 0);
+///   //           ^~~~~~~~~~~~~~~~
+///   //           PostContractAnnotation with ResultVar for 'r'
+/// \endcode
+template <> class ContractAnnotationBase<true> {
----------------
yronglin wrote:

Can this be achieved using inheritance or shared this class between `pre` and 
`post`? It seems that only `ResultVar` is unique to `post`. 

https://github.com/llvm/llvm-project/pull/205739
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to