LCOV - code coverage report
Current view: top level - include/parser - Builder.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fef103 Lines: 1 1 100.0 %
Date: 2025-09-03 20:01:23 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 <vector>
      20             : #include <string>
      21             : #include <iomanip>
      22             : #include <optional>
      23             : 
      24             : // Forward declarations
      25             : class ActionWarehouse;
      26             : class SyntaxTree;
      27             : class MooseApp;
      28             : class Factory;
      29             : class ActionFactory;
      30             : class GlobalParamsAction;
      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      125680 :   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             :    * 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             : private:
     113             :   /**
     114             :    * Helper functions for setting parameters of arbitrary types - bodies are in the .C file
     115             :    * since they are called only from this Object
     116             :    */
     117             :   /// Template method for setting any scalar type parameter read from the input file or command line
     118             :   template <typename T, typename Base>
     119             :   void setScalarParameter(const std::string & full_name,
     120             :                           const std::string & short_name,
     121             :                           InputParameters::Parameter<T> * param,
     122             :                           bool in_global,
     123             :                           GlobalParamsAction * global_block);
     124             : 
     125             :   template <typename T, typename UP_T, typename Base>
     126             :   void setScalarValueTypeParameter(const std::string & full_name,
     127             :                                    const std::string & short_name,
     128             :                                    InputParameters::Parameter<T> * param,
     129             :                                    bool in_global,
     130             :                                    GlobalParamsAction * global_block,
     131             :                                    const hit::Node & node);
     132             : 
     133             :   /// Template method for setting any vector type parameter read from the input file or command line
     134             :   template <typename T, typename Base>
     135             :   void setVectorParameter(const std::string & full_name,
     136             :                           const std::string & short_name,
     137             :                           InputParameters::Parameter<std::vector<T>> * param,
     138             :                           bool in_global,
     139             :                           GlobalParamsAction * global_block);
     140             : 
     141             :   /// Template method for setting any map type parameter read from the input file or command line
     142             :   template <typename KeyType, typename MappedType>
     143             :   void setMapParameter(const std::string & full_name,
     144             :                        const std::string & short_name,
     145             :                        InputParameters::Parameter<std::map<KeyType, MappedType>> * param,
     146             :                        bool in_global,
     147             :                        GlobalParamsAction * global_block);
     148             : 
     149             :   /**
     150             :    * Template method for setting any double indexed type parameter read from the input file or
     151             :    * command line.
     152             :    */
     153             :   template <typename T>
     154             :   void setDoubleIndexParameter(const std::string & full_name,
     155             :                                const std::string & short_name,
     156             :                                InputParameters::Parameter<std::vector<std::vector<T>>> * param,
     157             :                                bool in_global,
     158             :                                GlobalParamsAction * global_block);
     159             : 
     160             :   /**
     161             :    * Template method for setting any triple indexed type parameter read from the input file or
     162             :    * command line.
     163             :    */
     164             :   template <typename T>
     165             :   void setTripleIndexParameter(
     166             :       const std::string & full_name,
     167             :       const std::string & short_name,
     168             :       InputParameters::Parameter<std::vector<std::vector<std::vector<T>>>> * param,
     169             :       bool in_global,
     170             :       GlobalParamsAction * global_block);
     171             : 
     172             :   /**
     173             :    * Template method for setting any multivalue "scalar" type parameter read from the input file or
     174             :    * command line.  Examples include "Point" and "RealVectorValue".
     175             :    */
     176             :   template <typename T>
     177             :   void setScalarComponentParameter(const std::string & full_name,
     178             :                                    const std::string & short_name,
     179             :                                    InputParameters::Parameter<T> * param,
     180             :                                    bool in_global,
     181             :                                    GlobalParamsAction * global_block);
     182             : 
     183             :   /**
     184             :    * Template method for setting several multivalue "scalar" type parameter read from the input
     185             :    * file or command line.  Examples include "Point" and "RealVectorValue".
     186             :    */
     187             :   template <typename T>
     188             :   void setVectorComponentParameter(const std::string & full_name,
     189             :                                    const std::string & short_name,
     190             :                                    InputParameters::Parameter<std::vector<T>> * param,
     191             :                                    bool in_global,
     192             :                                    GlobalParamsAction * global_block);
     193             : 
     194             :   /**
     195             :    * Template method for setting vector of several multivalue "scalar" type parameter read from the
     196             :    * input file or command line.  Examples include vectors of several "Point"s and
     197             :    * "RealVectorValue"s such as (a three-element vector; each element is several "Point"s):
     198             :    * points_values = '0 0 0
     199             :    *                  0 0 1;
     200             :    *                  0 1 0;
     201             :    *                  1 0 0
     202             :    *                  1 1 0
     203             :    *                  1 1 1'
     204             :    */
     205             :   template <typename T>
     206             :   void
     207             :   setVectorVectorComponentParameter(const std::string & full_name,
     208             :                                     const std::string & short_name,
     209             :                                     InputParameters::Parameter<std::vector<std::vector<T>>> * param,
     210             :                                     bool in_global,
     211             :                                     GlobalParamsAction * global_block);
     212             : 
     213             :   /// The MooseApp this Parser is part of
     214             :   MooseApp & _app;
     215             :   /// The Factory associated with that MooseApp
     216             :   Factory & _factory;
     217             :   /// Action warehouse that will be filled by actions
     218             :   ActionWarehouse & _action_wh;
     219             :   /// The Factory that builds actions
     220             :   ActionFactory & _action_factory;
     221             :   /// Reference to an object that defines input file syntax
     222             :   Syntax & _syntax;
     223             :   /// The front parser
     224             :   Parser & _parser;
     225             :   /// The root node from the Parser
     226             :   hit::Node & _root;
     227             : 
     228             :   /// Object for holding the syntax parse tree
     229             :   std::unique_ptr<SyntaxTree> _syntax_formatter;
     230             : 
     231             :   /// The set of all variables extracted from the input file
     232             :   std::set<std::string> _extracted_vars;
     233             : 
     234             :   /// The sections that we need to execute first (read during the final walk)
     235             :   std::vector<std::string> _secs_need_first;
     236             : 
     237             :   /// The current parameter object for which parameters are being extracted
     238             :   InputParameters * _current_params;
     239             : 
     240             :   /// The errors accumulated during the walk
     241             :   std::vector<hit::ErrorMessage> _errors;
     242             : 
     243             :   /// Deprecation warnings
     244             :   std::unordered_map<std::string, std::string> _deprecated_params;
     245             : 
     246             :   void walkRaw(std::string fullpath, std::string nodepath, hit::Node * n);
     247             : };
     248             : }

Generated by: LCOV version 1.14