Skip to content

Commit

Permalink
close Issue #557
Browse files Browse the repository at this point in the history
  • Loading branch information
thelfer committed May 16, 2024
1 parent 82c0d3c commit b699b90
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
12 changes: 9 additions & 3 deletions mfront/include/MFront/MFrontBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <vector>
#include <memory>

#include "TFEL/Utilities/Data.hxx"
#include "TFEL/Utilities/ArgumentParserBase.hxx"
#include "MFront/MFrontConfig.hxx"
#include "MFront/TargetsDescription.hxx"
Expand All @@ -34,17 +35,22 @@ namespace mfront {
struct MFRONT_VISIBILITY_EXPORT MFrontBase {
/*!
* \param[in] f : file name
* \param[in] dsl_options: options passed to the DSL
* \return an abstract dsl that will handle the file
*/
static std::shared_ptr<AbstractDSL> getDSL(const std::string&);
static std::shared_ptr<AbstractDSL> getDSL(const std::string&,
const tfel::utilities::DataMap& = {});
/*!
* \return an abstract dsl that will handle the source described by the
* given iterators \param[in] pt: iterator to the first token of the source
* given iterators
* \param[in] pt: iterator to the first token of the source
* \param[in] pte: iterator to the last token of the source
* \param[in] dsl_options: options passed to the DSL
*/
static std::shared_ptr<AbstractDSL> getDSL(
tfel::utilities::CxxTokenizer::const_iterator,
const tfel::utilities::CxxTokenizer::const_iterator);
const tfel::utilities::CxxTokenizer::const_iterator,
const tfel::utilities::DataMap& = {});
/*!
* \brief add a new DSL option
* \param[in] o: option. Must of a string of the form
Expand Down
24 changes: 14 additions & 10 deletions mfront/src/MFrontBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ namespace mfront {

std::shared_ptr<AbstractDSL> MFrontBase::getDSL(
const tfel::utilities::CxxTokenizer::const_iterator ptb,
const tfel::utilities::CxxTokenizer::const_iterator pte) {
const tfel::utilities::CxxTokenizer::const_iterator pte,
const tfel::utilities::DataMap& dsl_options) {
using namespace tfel::system;
auto throw_if = [](const bool b, const std::string& m) {
tfel::raise_if(b, "MFrontBase::getDSL: " + m);
};
auto dsl_options = tfel::utilities::DataMap{};
// local dsl options
auto ldsl_options = dsl_options;
const auto& global_options =
GlobalDomainSpecificLanguageOptionsManager::get();
auto& dslFactory = DSLFactory::getDSLFactory();
Expand Down Expand Up @@ -76,8 +78,10 @@ namespace mfront {
throw_if(pt == pte, "unexpected end of file (exepected dsl name)");
if (pt->value == "{") {
const auto o = tfel::utilities::DataParsingOptions{};
dsl_options = tfel::utilities::Data::read(pt, pte, o)
.get<tfel::utilities::DataMap>();
ldsl_options = tfel::utilities::merge(ldsl_options,
tfel::utilities::Data::read(pt, pte, o)
.get<tfel::utilities::DataMap>(),
false);
}
throw_if(pt == pte,
"unexpected end of file (exepected ';' or library name)");
Expand Down Expand Up @@ -107,23 +111,23 @@ namespace mfront {
}
try {
// first try to get the target type of the DSL
dsl = dslFactory.createNewDSL(dslName, dsl_options);
dsl = dslFactory.createNewDSL(dslName, ldsl_options);
const auto t = dsl->getTargetType();
if (t == AbstractDSL::MATERIALPROPERTYDSL) {
dsl = dslFactory.createNewDSL(
dslName, tfel::utilities::merge(
global_options.getMaterialPropertyDSLOptions(),
dsl_options, true));
ldsl_options, true));
} else if (t == AbstractDSL::BEHAVIOURDSL) {
dsl = dslFactory.createNewDSL(
dslName,
tfel::utilities::merge(global_options.getBehaviourDSLOptions(),
dsl_options, true));
ldsl_options, true));
} else if (t == AbstractDSL::MODELDSL) {
dsl = dslFactory.createNewDSL(
dslName,
tfel::utilities::merge(global_options.getModelDSLOptions(),
dsl_options, true));
ldsl_options, true));
} else {
tfel::raise("MFrontBase::getDSL: unsupported DSL target type");
}
Expand All @@ -142,7 +146,7 @@ namespace mfront {
return dsl;
} // end of getDSL

std::shared_ptr<AbstractDSL> MFrontBase::getDSL(const std::string& f) {
std::shared_ptr<AbstractDSL> MFrontBase::getDSL(const std::string& f, const tfel::utilities::DataMap& dsl_options) {
tfel::utilities::CxxTokenizer file;
if ((tfel::utilities::starts_with(f, "madnex:")) ||
(tfel::utilities::starts_with(f, "mdnx:")) ||
Expand All @@ -160,7 +164,7 @@ namespace mfront {
file.openFile(f);
}
file.stripComments();
auto dsl = MFrontBase::getDSL(file.cbegin(), file.cend());
auto dsl = MFrontBase::getDSL(file.cbegin(), file.cend(), dsl_options);
if ((tfel::utilities::starts_with(f, "madnex:")) ||
(tfel::utilities::starts_with(f, "mdnx:")) ||
(tfel::utilities::starts_with(f, "edf:"))) {
Expand Down

0 comments on commit b699b90

Please sign in to comment.