ENH: unified some common parser static methods

COMP: delay evaluation of fieldToken enumeration types

- lazy evaluation at runTime instead of compile-time to make the code
  independent of initialization order.
  Otherwise triggers problems on gcc-4.8.5 on some systems where
  glibc is the same age, or older.
This commit is contained in:
Mark Olesen
2019-12-11 13:32:36 +01:00
parent 622808c7d0
commit eb4fec371a
27 changed files with 818 additions and 525 deletions

View File

@ -0,0 +1,3 @@
Test-parserInfo.C
EXE = $(FOAM_USER_APPBIN)/Test-parserInfo

View File

@ -0,0 +1,7 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lmeshTools

View File

@ -0,0 +1,131 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Output some (expressions) parser information
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "IOstreams.H"
#include "List.H"
#include "fieldExprParser.H"
#include "patchExprParser.H"
#include "volumeExprParser.H"
using namespace Foam;
template<class Parser>
void printInformation
(
Ostream& os,
const word& name,
const bool printNames,
const bool printRules
)
{
if (printNames)
{
os << nl << name << " tokenNames:" << nl;
Parser::printTokenNames(os);
}
if (printRules)
{
os << nl << name << " rules:" << nl;
Parser::printRules(os);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noBanner();
argList::addNote
(
"Display token names or rules for specified expression parser(s)."
" Without options, displays everything."
);
argList::addBoolOption("rules", "Print parser rules");
argList::addBoolOption("tokens", "Print token names");
argList::addBoolOption("field", "Field expression parser");
argList::addBoolOption("patch", "Patch expression parser");
argList::addBoolOption("volume", "Volume expression parser");
argList args(argc, argv);
// Defaults
const bool all = !args.count({"field", "patch", "volume"});
const bool both = !args.count({"tokens", "rules"});
const bool printNames = both || args.found("tokens");
const bool printRules = both || args.found("rules");
if (all || args.found("field"))
{
printInformation<Foam::expressions::fieldExpr::parser>
(
Info,
"field",
printNames,
printRules
);
}
if (all || args.found("patch"))
{
printInformation<Foam::expressions::patchExpr::parser>
(
Info,
"patch",
printNames,
printRules
);
}
if (all || args.found("volume"))
{
printInformation<Foam::expressions::volumeExpr::parser>
(
Info,
"volume",
printNames,
printRules
);
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -39,6 +39,7 @@ Description
#include "fileName.H"
#include "stringList.H"
#include "stringOps.H"
#include "fieldExprFwd.H"
using namespace Foam;
@ -122,6 +123,9 @@ int main(int argc, char *argv[])
// Test numeric
{
Info<< nl << "Test numeric evaluation" << nl;
// expressions::fieldExpr::debug = 2;
for
(
const auto& cstr
@ -135,6 +139,9 @@ int main(int argc, char *argv[])
"vector=${{ 5 * vector(1,2,3) }}=",
"empty=${{ }}=",
"vector=${{ 5 * vector(1, 2, 3) ^ vector(4, 5, 6) }}=",
// NOT YET WORKING: "vector=${{ 5 * [1 2 3 ] ^ [ 4 5 6 ] }}=",
}
)
{