LCOV - code coverage report
Current view: top level - include/parser - Builder.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 863ef6 Lines: 1 1 100.0 %
Date: 2025-10-15 18:16:15 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : // MOOSE includes
      13             : #include "ConsoleStreamInterface.h"
      14             : #include "MooseTypes.h"
      15             : #include "InputParameters.h"
      16             : 
      17             : #include "hit/hit.h"
      18             : 
      19             : #include <set>
      20             : #include <vector>
      21             : #include <string>
      22             : #include <iomanip>
      23             : #include <optional>
      24             : 
      25             : // Forward declarations
      26             : class ActionWarehouse;
      27             : class SyntaxTree;
      28             : class MooseApp;
      29             : class Factory;
      30             : class ActionFactory;
      31             : class JsonSyntaxTree;
      32             : class Parser;
      33             : class Syntax;
      34             : 
      35             : namespace Moose
      36             : {
      37             : class Builder;
      38             : 
      39             : class UnusedWalker : public hit::Walker
      40             : {
      41             : public:
      42      127822 :   UnusedWalker(std::set<std::string> used, Builder & p) : _used(used), _builder(p) {}
      43             : 
      44             :   void walk(const std::string & fullpath, const std::string & nodename, hit::Node * n) override;
      45             : 
      46             :   std::vector<hit::ErrorMessage> errors;
      47             : 
      48             : private:
      49             :   std::set<std::string> _used;
      50             :   Builder & _builder;
      51             : };
      52             : 
      53             : /**
      54             :  * Parses MOOSE input using HIT/WASP.
      55             :  */
      56             : class Builder : public ConsoleStreamInterface, public hit::Walker
      57             : {
      58             : public:
      59             :   enum SyntaxFormatterType
      60             :   {
      61             :     INPUT_FILE,
      62             :     YAML
      63             :   };
      64             : 
      65             :   Builder(MooseApp & app, ActionWarehouse & action_wh, Parser & parser);
      66             :   virtual ~Builder();
      67             : 
      68             :   /**
      69             :    * Parameters that are processed directly by the Parser and are valid anywhere in the input
      70             :    */
      71             :   static InputParameters validParams();
      72             : 
      73             :   /**
      74             :    * Return the primary (first) filename that was parsed
      75             :    */
      76             :   std::string getPrimaryFileName(bool stripLeadingPath = true) const;
      77             : 
      78             :   /**
      79             :    * Parse an input file (or text string if provided) consisting of hit syntax and setup objects
      80             :    * in the MOOSE derived application
      81             :    */
      82             :   void build();
      83             : 
      84             :   /**
      85             :    * Attempt to extract values from input starting with the section in input in \p section_node
      86             :    * based on the contents of the passed InputParameters \p p.
      87             :    *
      88             :    * If \p section_node is not provided, only the global parameters will be checked
      89             :    */
      90             :   void extractParams(const hit::Node * const section_node, InputParameters & p);
      91             :   /**
      92             :    * Attempt to extract values from input starting with the section in input defined
      93             :    * by the fullpath \p prefix based on the contents of the passed InputParameters \p p.
      94             :    */
      95             :   void extractParams(const std::string & prefix, InputParameters & p);
      96             : 
      97             :   /**
      98             :    * Creates a syntax formatter for printing
      99             :    */
     100             :   void initSyntaxFormatter(SyntaxFormatterType type, bool dump_mode);
     101             : 
     102             :   /**
     103             :    * Use MOOSE Factories to construct a full parse tree for documentation or echoing input.
     104             :    */
     105             :   void buildFullTree(const std::string & search_string);
     106             : 
     107             :   /**
     108             :    * Use MOOSE Factories to construct a parameter tree for documentation or echoing input.
     109             :    */
     110             :   void buildJsonSyntaxTree(JsonSyntaxTree & tree) const;
     111             : 
     112             :   void walk(const std::string & fullpath, const std::string & nodepath, hit::Node * n);
     113             : 
     114             :   void errorCheck(const libMesh::Parallel::Communicator & comm, bool warn_unused, bool err_unused);
     115             : 
     116             :   std::vector<std::string> listValidParams(std::string & section_name);
     117             : 
     118             : private:
     119             :   /**
     120             :    * @return Whether or not the given node \p node exists within the [GlobalParams] block
     121             :    */
     122             :   bool isGlobal(const hit::Node & node) const;
     123             : 
     124             :   /**
     125             :    * Get the [GlobalParams] section node if it exists
     126             :    *
     127             :    * We need to separate this so that we can call extractParams()
     128             :    * before calling build()
     129             :    */
     130             :   const hit::Node * queryGlobalParamsNode() const;
     131             : 
     132             :   /// The MooseApp this Parser is part of
     133             :   MooseApp & _app;
     134             :   /// The Factory associated with that MooseApp
     135             :   Factory & _factory;
     136             :   /// Action warehouse that will be filled by actions
     137             :   ActionWarehouse & _action_wh;
     138             :   /// The Factory that builds actions
     139             :   ActionFactory & _action_factory;
     140             :   /// Reference to an object that defines input file syntax
     141             :   Syntax & _syntax;
     142             :   /// The front parser
     143             :   Parser & _parser;
     144             :   /// The root node from the Parser
     145             :   hit::Node & _root;
     146             : 
     147             :   /// Object for holding the syntax parse tree
     148             :   std::unique_ptr<SyntaxTree> _syntax_formatter;
     149             : 
     150             :   /// The set of all variables extracted from the input file
     151             :   std::set<std::string> _extracted_vars;
     152             : 
     153             :   /// The sections that we need to execute first (read during the final walk)
     154             :   std::vector<std::string> _secs_need_first;
     155             : 
     156             :   /// The errors accumulated during the walk
     157             :   std::vector<hit::ErrorMessage> _errors;
     158             : 
     159             :   /// Deprecation warnings (object type/param name) -> (message)
     160             :   std::map<std::string, std::string> _deprecated_params;
     161             : 
     162             :   /// The hit Node for the [GlobalParams] block, if any
     163             :   /// If set (could be null), it means we have searched for it
     164             :   mutable std::optional<const hit::Node *> _global_params_node;
     165             : 
     166             :   void walkRaw(std::string fullpath, std::string nodepath, hit::Node * n);
     167             : };
     168             : }

Generated by: LCOV version 1.14