https://mooseframework.inl.gov
Builder.h
Go to the documentation of this file.
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  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;
51 };
52 
56 class Builder : public ConsoleStreamInterface, public hit::Walker
57 {
58 public:
60  {
63  };
64 
65  Builder(MooseApp & app, ActionWarehouse & action_wh, Parser & parser);
66  virtual ~Builder();
67 
72 
76  std::string getPrimaryFileName(bool stripLeadingPath = true) const;
77 
82  void build();
83 
90  void extractParams(const hit::Node * const section_node, InputParameters & p);
95  void extractParams(const std::string & prefix, InputParameters & p);
96 
100  void initSyntaxFormatter(SyntaxFormatterType type, bool dump_mode);
101 
105  void buildFullTree(const std::string & search_string);
106 
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:
122  bool isGlobal(const hit::Node & node) const;
123 
130  const hit::Node * queryGlobalParamsNode() const;
131 
145  hit::Node & _root;
146 
148  std::unique_ptr<SyntaxTree> _syntax_formatter;
149 
151  std::set<std::string> _extracted_vars;
152 
154  std::vector<std::string> _secs_need_first;
155 
157  std::vector<hit::ErrorMessage> _errors;
158 
160  std::map<std::string, std::string> _deprecated_params;
161 
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 }
void build()
Parse an input file (or text string if provided) consisting of hit syntax and setup objects in the MO...
Definition: Builder.C:300
ActionFactory & _action_factory
The Factory that builds actions.
Definition: Builder.h:139
MooseApp & _app
The MooseApp this Parser is part of.
Definition: Builder.h:133
void walk(const std::string &fullpath, const std::string &nodename, hit::Node *n) override
Definition: Builder.C:159
void walkRaw(std::string fullpath, std::string nodepath, hit::Node *n)
Definition: Builder.C:186
Parser & _parser
The front parser.
Definition: Builder.h:143
void buildFullTree(const std::string &search_string)
Use MOOSE Factories to construct a full parse tree for documentation or echoing input.
Definition: Builder.C:579
Generic factory class for build all sorts of objects.
Definition: Factory.h:28
std::vector< std::string > _secs_need_first
The sections that we need to execute first (read during the final walk)
Definition: Builder.h:154
Builder(MooseApp &app, ActionWarehouse &action_wh, Parser &parser)
Definition: Builder.C:105
Builder & _builder
Definition: Builder.h:50
static InputParameters validParams()
Parameters that are processed directly by the Parser and are valid anywhere in the input...
Definition: Builder.C:121
Base class for MOOSE-based applications.
Definition: MooseApp.h:103
Storage for action instances.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unique_ptr< SyntaxTree > _syntax_formatter
Object for holding the syntax parse tree.
Definition: Builder.h:148
Holds the syntax in a Json::Value tree.
void extractParams(const hit::Node *const section_node, InputParameters &p)
Attempt to extract values from input starting with the section in input in section_node based on the ...
Definition: Builder.C:666
hit::Node & _root
The root node from the Parser.
Definition: Builder.h:145
std::set< std::string > _extracted_vars
The set of all variables extracted from the input file.
Definition: Builder.h:151
UnusedWalker(std::set< std::string > used, Builder &p)
Definition: Builder.h:42
void initSyntaxFormatter(SyntaxFormatterType type, bool dump_mode)
Creates a syntax formatter for printing.
Definition: Builder.C:402
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:50
An inteface for the _console for outputting to the Console object.
void buildJsonSyntaxTree(JsonSyntaxTree &tree) const
Use MOOSE Factories to construct a parameter tree for documentation or echoing input.
Definition: Builder.C:419
void errorCheck(const libMesh::Parallel::Communicator &comm, bool warn_unused, bool err_unused)
Definition: Builder.C:361
std::string getPrimaryFileName(bool stripLeadingPath=true) const
Return the primary (first) filename that was parsed.
Definition: Builder.C:179
std::vector< hit::ErrorMessage > errors
Definition: Builder.h:46
bool isGlobal(const hit::Node &node) const
Definition: Builder.C:826
std::vector< hit::ErrorMessage > _errors
The errors accumulated during the walk.
Definition: Builder.h:157
std::map< std::string, std::string > _deprecated_params
Deprecation warnings (object type/param name) -> (message)
Definition: Builder.h:160
Syntax & _syntax
Reference to an object that defines input file syntax.
Definition: Builder.h:141
std::set< std::string > _used
Definition: Builder.h:49
Holding syntax for parsing input files.
Definition: Syntax.h:21
Factory & _factory
The Factory associated with that MooseApp.
Definition: Builder.h:135
virtual ~Builder()
Definition: Builder.C:118
std::vector< std::string > listValidParams(std::string &section_name)
Definition: Builder.C:142
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
ActionWarehouse & _action_wh
Action warehouse that will be filled by actions.
Definition: Builder.h:137
Parses MOOSE input using HIT/WASP.
Definition: Builder.h:56
const hit::Node * queryGlobalParamsNode() const
Get the [GlobalParams] section node if it exists.
Definition: Builder.C:833
Class for parsing input files.
Definition: Parser.h:87
std::optional< const hit::Node * > _global_params_node
The hit Node for the [GlobalParams] block, if any If set (could be null), it means we have searched f...
Definition: Builder.h:164
void walk(const std::string &fullpath, const std::string &nodepath, hit::Node *n)
Definition: Builder.C:289