LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/rewriter - rewrite_db.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2026-06-04 10:35:05 Functions: 1 1 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * This file is part of the cvc5 project.
       3                 :            :  *
       4                 :            :  * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
       5                 :            :  * in the top-level source directory and their institutional affiliations.
       6                 :            :  * All rights reserved.  See the file COPYING in the top-level source
       7                 :            :  * directory for licensing information.
       8                 :            :  * ****************************************************************************
       9                 :            :  *
      10                 :            :  * Rewrite database
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "cvc5_private.h"
      14                 :            : 
      15                 :            : #ifndef CVC5__REWRITER__REWRITE_DB__H
      16                 :            : #define CVC5__REWRITER__REWRITE_DB__H
      17                 :            : 
      18                 :            : #include <map>
      19                 :            : #include <vector>
      20                 :            : 
      21                 :            : #include "expr/nary_match_trie.h"
      22                 :            : #include "expr/nary_term_util.h"
      23                 :            : #include "expr/node.h"
      24                 :            : #include "expr/term_canonize.h"
      25                 :            : #include "rewriter/rewrite_proof_rule.h"
      26                 :            : #include "rewriter/rewrites.h"
      27                 :            : 
      28                 :            : namespace cvc5::internal {
      29                 :            : namespace rewriter {
      30                 :            : 
      31                 :            : /** Type class callback */
      32                 :            : class IsListTypeClassCallback : public expr::TypeClassCallback
      33                 :            : {
      34                 :            :  public:
      35                 :            :   /**
      36                 :            :    * Returns an identifier that distinguished whether v has list semantics
      37                 :            :    * (1 if yes, 0 if no). This is used when canonizing terms for the
      38                 :            :    * database below.
      39                 :            :    */
      40                 :            :   uint32_t getTypeClass(TNode v) override;
      41                 :            : };
      42                 :            : 
      43                 :            : /**
      44                 :            :  * A database of conditional rewrite rules. The rules of this class are
      45                 :            :  * automatically populated based on the compilation of the rewrite rule files.
      46                 :            :  */
      47                 :            : class RewriteDb
      48                 :            : {
      49                 :            :  public:
      50                 :            :   /**
      51                 :            :    * Constructor. The body of this method is auto-generated by the rules
      52                 :            :    * defined in the rewrite_rules files.
      53                 :            :    */
      54                 :            :   RewriteDb(NodeManager* nm);
      55                 :       8909 :   ~RewriteDb() {}
      56                 :            :   /** Add rule id to this database
      57                 :            :    *
      58                 :            :    * @param id The identifier of the rule
      59                 :            :    * @param fvs The free variables of the rule
      60                 :            :    * @param a The left hand side of the rule
      61                 :            :    * @param b The right hand side of the rule
      62                 :            :    * @param cond The condition, or null if this is not a conditional rule
      63                 :            :    * @param context The term context, if one exists
      64                 :            :    * @param level Whether this rule is expert
      65                 :            :    */
      66                 :            :   void addRule(ProofRewriteRule id,
      67                 :            :                const std::vector<Node> fvs,
      68                 :            :                Node a,
      69                 :            :                Node b,
      70                 :            :                Node cond,
      71                 :            :                Node context,
      72                 :            :                Level level);
      73                 :            :   /**
      74                 :            :    * Get matches, which incrementally makes callbacks on the notify class
      75                 :            :    * ntm for all rules that match eq.
      76                 :            :    */
      77                 :            :   void getMatches(const Node& eq, expr::NotifyMatch* ntm);
      78                 :            :   /** Get the rule definition for id */
      79                 :            :   const RewriteProofRule& getRule(ProofRewriteRule id) const;
      80                 :            :   /**
      81                 :            :    * Get ids for conclusion, returns the list of identifiers of rules whose
      82                 :            :    * conclusion is eq.
      83                 :            :    */
      84                 :            :   const std::vector<ProofRewriteRule>& getRuleIdsForConclusion(
      85                 :            :       const Node& eq) const;
      86                 :            :   /**
      87                 :            :    * Get ids for head, returns the list of identifiers of rules whose
      88                 :            :    * head (the left hand side of its equality) is h.
      89                 :            :    */
      90                 :            :   const std::vector<ProofRewriteRule>& getRuleIdsForHead(const Node& h) const;
      91                 :            :   /** Return the union of free variables in all rules */
      92                 :            :   const std::unordered_set<Node>& getAllFreeVariables() const;
      93                 :            :   /** Return all rewrite rules */
      94                 :            :   const std::map<ProofRewriteRule, RewriteProofRule>& getAllRules() const;
      95                 :            : 
      96                 :            :  private:
      97                 :            :   /** common constants */
      98                 :            :   Node d_true;
      99                 :            :   Node d_false;
     100                 :            :   /** Callback to distinguish list variables */
     101                 :            :   IsListTypeClassCallback d_canonCb;
     102                 :            :   /** the term canonization utility */
     103                 :            :   expr::TermCanonize d_canon;
     104                 :            :   /** The match trie */
     105                 :            :   expr::NaryMatchTrie d_mt;
     106                 :            :   /** map ids to rewrite db rule information */
     107                 :            :   std::map<ProofRewriteRule, RewriteProofRule> d_rewDbRule;
     108                 :            :   /** map conclusions to proof ids */
     109                 :            :   std::map<Node, std::vector<ProofRewriteRule> > d_concToRules;
     110                 :            :   /** map head to proof ids */
     111                 :            :   std::map<Node, std::vector<ProofRewriteRule> > d_headToRules;
     112                 :            :   /** dummy empty vector */
     113                 :            :   std::vector<ProofRewriteRule> d_emptyVec;
     114                 :            :   /** All free variables in all rules */
     115                 :            :   std::unordered_set<Node> d_allFv;
     116                 :            : };
     117                 :            : 
     118                 :            : }  // namespace rewriter
     119                 :            : }  // namespace cvc5::internal
     120                 :            : 
     121                 :            : #endif /* CVC5__THEORY__REWRITE_DB__H */

Generated by: LCOV version 1.14