LCOV - code coverage report
Current view: top level - include/parser - Builder.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 1 1 100.0 %
Date: 2025-07-17 01:28:37 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             : #include "Syntax.h"
      17             : #include "Parser.h"
      18             : 
      19             : #include "hit/hit.h"
      20             : 
      21             : #include <vector>
      22             : #include <string>
      23             : #include <iomanip>
      24             : #include <optional>
      25             : 
      26             : // Forward declarations
      27             : class ActionWarehouse;
      28             : class SyntaxTree;
      29             : class MooseApp;
      30             : class Factory;
      31             : class ActionFactory;
      32             : class GlobalParamsAction;
      33             : class JsonSyntaxTree;
      34             : 
      35             : namespace Moose
      36             : {
      37             : class Builder;
      38             : 
      39             : class UnusedWalker : public hit::Walker
      40             : {
      41             : public:
      42      114488 :   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<std::string> 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, std::shared_ptr<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             :    * This function attempts to extract values from the input file based on the contents of
      86             :    * the passed parameters objects.  It handles a number of various types with dynamic casting
      87             :    * including vector types
      88             :    */
      89             :   void extractParams(const std::string & prefix, InputParameters & p);
      90             : 
      91             :   /**
      92             :    * Creates a syntax formatter for printing
      93             :    */
      94             :   void initSyntaxFormatter(SyntaxFormatterType type, bool dump_mode);
      95             : 
      96             :   /**
      97             :    * Use MOOSE Factories to construct a full parse tree for documentation or echoing input.
      98             :    */
      99             :   void buildFullTree(const std::string & search_string);
     100             : 
     101             :   /**
     102             :    * Use MOOSE Factories to construct a parameter tree for documentation or echoing input.
     103             :    */
     104             :   void buildJsonSyntaxTree(JsonSyntaxTree & tree) const;
     105             : 
     106             :   void walk(const std::string & fullpath, const std::string & nodepath, hit::Node * n);
     107             : 
     108             :   void errorCheck(const libMesh::Parallel::Communicator & comm, bool warn_unused, bool err_unused);
     109             : 
     110             :   std::vector<std::string> listValidParams(std::string & section_name);
     111             : 
     112             :   /**
     113             :    * @return The root node in the parser
     114             :    */
     115             :   hit::Node * root();
     116             : 
     117             : protected:
     118             :   /**
     119             :    * Helper functions for setting parameters of arbitrary types - bodies are in the .C file
     120             :    * since they are called only from this Object
     121             :    */
     122             :   /// Template method for setting any scalar type parameter read from the input file or command line
     123             :   template <typename T, typename Base>
     124             :   void setScalarParameter(const std::string & full_name,
     125             :                           const std::string & short_name,
     126             :                           InputParameters::Parameter<T> * param,
     127             :                           bool in_global,
     128             :                           GlobalParamsAction * global_block);
     129             : 
     130             :   template <typename T, typename UP_T, typename Base>
     131             :   void setScalarValueTypeParameter(const std::string & full_name,
     132             :                                    const std::string & short_name,
     133             :                                    InputParameters::Parameter<T> * param,
     134             :                                    bool in_global,
     135             :                                    GlobalParamsAction * global_block);
     136             : 
     137             :   /// Template method for setting any vector type parameter read from the input file or command line
     138             :   template <typename T, typename Base>
     139             :   void setVectorParameter(const std::string & full_name,
     140             :                           const std::string & short_name,
     141             :                           InputParameters::Parameter<std::vector<T>> * param,
     142             :                           bool in_global,
     143             :                           GlobalParamsAction * global_block);
     144             : 
     145             :   /// Template method for setting any map type parameter read from the input file or command line
     146             :   template <typename KeyType, typename MappedType>
     147             :   void setMapParameter(const std::string & full_name,
     148             :                        const std::string & short_name,
     149             :                        InputParameters::Parameter<std::map<KeyType, MappedType>> * param,
     150             :                        bool in_global,
     151             :                        GlobalParamsAction * global_block);
     152             : 
     153             :   /**
     154             :    * Template method for setting any double indexed type parameter read from the input file or
     155             :    * command line.
     156             :    */
     157             :   template <typename T>
     158             :   void setDoubleIndexParameter(const std::string & full_name,
     159             :                                const std::string & short_name,
     160             :                                InputParameters::Parameter<std::vector<std::vector<T>>> * param,
     161             :                                bool in_global,
     162             :                                GlobalParamsAction * global_block);
     163             : 
     164             :   /**
     165             :    * Template method for setting any triple indexed type parameter read from the input file or
     166             :    * command line.
     167             :    */
     168             :   template <typename T>
     169             :   void setTripleIndexParameter(
     170             :       const std::string & full_name,
     171             :       const std::string & short_name,
     172             :       InputParameters::Parameter<std::vector<std::vector<std::vector<T>>>> * param,
     173             :       bool in_global,
     174             :       GlobalParamsAction * global_block);
     175             : 
     176             :   /**
     177             :    * Template method for setting any multivalue "scalar" type parameter read from the input file or
     178             :    * command line.  Examples include "Point" and "RealVectorValue".
     179             :    */
     180             :   template <typename T>
     181             :   void setScalarComponentParameter(const std::string & full_name,
     182             :                                    const std::string & short_name,
     183             :                                    InputParameters::Parameter<T> * param,
     184             :                                    bool in_global,
     185             :                                    GlobalParamsAction * global_block);
     186             : 
     187             :   /**
     188             :    * Template method for setting several multivalue "scalar" type parameter read from the input
     189             :    * file or command line.  Examples include "Point" and "RealVectorValue".
     190             :    */
     191             :   template <typename T>
     192             :   void setVectorComponentParameter(const std::string & full_name,
     193             :                                    const std::string & short_name,
     194             :                                    InputParameters::Parameter<std::vector<T>> * param,
     195             :                                    bool in_global,
     196             :                                    GlobalParamsAction * global_block);
     197             : 
     198             :   /**
     199             :    * Template method for setting vector of several multivalue "scalar" type parameter read from the
     200             :    * input file or command line.  Examples include vectors of several "Point"s and
     201             :    * "RealVectorValue"s such as (a three-element vector; each element is several "Point"s):
     202             :    * points_values = '0 0 0
     203             :    *                  0 0 1;
     204             :    *                  0 1 0;
     205             :    *                  1 0 0
     206             :    *                  1 1 0
     207             :    *                  1 1 1'
     208             :    */
     209             :   template <typename T>
     210             :   void
     211             :   setVectorVectorComponentParameter(const std::string & full_name,
     212             :                                     const std::string & short_name,
     213             :                                     InputParameters::Parameter<std::vector<std::vector<T>>> * param,
     214             :                                     bool in_global,
     215             :                                     GlobalParamsAction * global_block);
     216             : 
     217             :   std::unique_ptr<hit::Node> _cli_root = nullptr;
     218             :   /// The root node from the Parser; in the future, we should probably clone this so that
     219             :   /// we don't muck with the root node in the Parser
     220             :   hit::Node * _root;
     221             :   std::vector<std::string> _secs_need_first;
     222             : 
     223             :   /// The MooseApp this Parser is part of
     224             :   MooseApp & _app;
     225             :   /// The Factory associated with that MooseApp
     226             :   Factory & _factory;
     227             :   /// Action warehouse that will be filled by actions
     228             :   ActionWarehouse & _action_wh;
     229             :   /// The Factory that builds actions
     230             :   ActionFactory & _action_factory;
     231             :   /// Reference to an object that defines input file syntax
     232             :   Syntax & _syntax;
     233             :   /// The front parser
     234             :   const std::shared_ptr<Parser> _parser;
     235             : 
     236             :   /// Object for holding the syntax parse tree
     237             :   std::unique_ptr<SyntaxTree> _syntax_formatter;
     238             : 
     239             :   /// The set of all variables extracted from the input file
     240             :   std::set<std::string> _extracted_vars;
     241             : 
     242             :   /// Boolean to indicate whether parsing has started (sections have been extracted)
     243             :   bool _sections_read;
     244             : 
     245             :   /// The current parameter object for which parameters are being extracted
     246             :   InputParameters * _current_params;
     247             : 
     248             :   /// The current stream object used for capturing errors during extraction
     249             :   std::ostringstream * _current_error_stream;
     250             : 
     251             :   /// Tracks whether a deprecated param has had its warning message printed already.
     252             :   std::unordered_set<std::string> _deprec_param_tracker;
     253             : 
     254             : private:
     255             :   std::string _errmsg;
     256             :   std::string _warnmsg;
     257             :   void walkRaw(std::string fullpath, std::string nodepath, hit::Node * n);
     258             : };
     259             : }

Generated by: LCOV version 1.14