diff --git a/applications/test/dictionary/Make/files b/applications/test/dictionary/Make/files index 6f1da0059a6e051fdeffc6bd09ff2fe62b2a0454..b9363efb23b13e6012274d16c0a250cdf9d2ca39 100644 --- a/applications/test/dictionary/Make/files +++ b/applications/test/dictionary/Make/files @@ -1,7 +1,3 @@ dictionaryTest.C -calcEntry/calcEntryParser.atg -calcEntry/calcEntryInternal.C -calcEntry/calcEntry.C - EXE = $(FOAM_USER_APPBIN)/dictionaryTest diff --git a/applications/test/dictionary/Make/options b/applications/test/dictionary/Make/options index 22051a7c0563f37e541487b164c21fa942fdc693..41306609f208806f0c6f42a2426867d3e10d4897 100644 --- a/applications/test/dictionary/Make/options +++ b/applications/test/dictionary/Make/options @@ -1 +1 @@ -EXE_INC = -IcalcEntry -I$(OBJECTS_DIR) +EXE_INC = diff --git a/applications/test/dictionary/testDictCalc b/applications/test/dictionary/testDictCalc index f1d67650e855526718e33e461fa254079990eac9..577cbf112d96c38a3c443cfb190961a4720892d6 100644 --- a/applications/test/dictionary/testDictCalc +++ b/applications/test/dictionary/testDictCalc @@ -10,7 +10,7 @@ FoamFile version 2.0; format ascii; class dictionary; - object testDictTest; + object testDictCalc; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -19,28 +19,13 @@ flowRatePerHour 720; x 10; y 20; z t s v; -// z #test{ // this -// 123 - 456 -// // comments // are -// /* stripped -// * 10 -// * {} -// */ -// + 1 /*100 */ 10 -// }; - -p this calculation #calc{ - 1 + 2 + 10 * 15 + - $x - $y - // $x + $y -} -is done inplace; +p #calc{ 1 + 2 + 10 * 15 + $x - $y }; +// this calculation is in-place, but does not work inside a string: +flowRate "The flow rate " #calc{ $flowRatePerHour / 3600 } "kg/s"; -flowRate #calc{ $flowRatePerHour / 3600}; +// this is also okay +x #calc{ $x * 1E-3 }; -xxx yyy; -foo 30; -bar 15; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/test/dictionary/testDictCalcError b/applications/test/dictionary/testDictCalcError new file mode 100644 index 0000000000000000000000000000000000000000..95b90ce8e8186a01ee01164bd2969f5cbe2d2027 --- /dev/null +++ b/applications/test/dictionary/testDictCalcError @@ -0,0 +1,46 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: Any | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object testDictCalcError; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +flowRatePerHour 720; + +x 10; +y 20; +z t s v; +// z #test{ // this +// 123 - 456 +// // comments // are +// /* stripped +// * 10 +// * {} +// */ +// + 1 /*100 */ 10 +// }; + +p this calculation #calc{ + 1xxx1 + 2 + 10 * 15 + + $x - $y + // $x + $y +} +is done inplace; + + +flowRate #calc{ $flowRatePerHour / 3600}; + +xxx yyy; +foo 30; +bar 15; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 9c18e7255554a2f30fdde1980d8b2b24cff66dbe..d8634de6dfdc75f0852cab846fd032ff45c8da8b 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -142,6 +142,12 @@ $(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C $(functionEntries)/inputModeEntry/inputModeEntry.C $(functionEntries)/removeEntry/removeEntry.C +calcEntry = $(functionEntries)/calcEntry +$(calcEntry)/calcEntryParser.atg +$(calcEntry)/calcEntryInternal.C +$(calcEntry)/calcEntry.C + + IOdictionary = db/IOobjects/IOdictionary $(IOdictionary)/IOdictionary.C $(IOdictionary)/IOdictionaryIO.C diff --git a/src/OpenFOAM/Make/options b/src/OpenFOAM/Make/options index 4eba86ae56d914aed88f7c06eb8d50c24b6f492b..b1cc1a2d10a16d24ecee7fd9ac347019fa4ed786 100644 --- a/src/OpenFOAM/Make/options +++ b/src/OpenFOAM/Make/options @@ -1,4 +1,4 @@ -EXE_INC = +EXE_INC = -I$(OBJECTS_DIR) LIB_LIBS = \ $(FOAM_LIBBIN)/libOSspecific.o \ diff --git a/applications/test/dictionary/calcEntry/calcEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C similarity index 100% rename from applications/test/dictionary/calcEntry/calcEntry.C rename to src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C diff --git a/applications/test/dictionary/calcEntry/calcEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.H similarity index 100% rename from applications/test/dictionary/calcEntry/calcEntry.H rename to src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.H diff --git a/applications/test/dictionary/calcEntry/calcEntryInternal.C b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntryInternal.C similarity index 100% rename from applications/test/dictionary/calcEntry/calcEntryInternal.C rename to src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntryInternal.C diff --git a/applications/test/dictionary/calcEntry/calcEntryInternal.H b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntryInternal.H similarity index 100% rename from applications/test/dictionary/calcEntry/calcEntryInternal.H rename to src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntryInternal.H diff --git a/applications/test/dictionary/calcEntry/calcEntryParser.atg b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntryParser.atg similarity index 76% rename from applications/test/dictionary/calcEntry/calcEntryParser.atg rename to src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntryParser.atg index f3751f77d4d127587bff7b9ae393471f7e679e01..755f539d98398a20060c0625de835882096cb3ae 100644 --- a/applications/test/dictionary/calcEntry/calcEntryParser.atg +++ b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntryParser.atg @@ -1,3 +1,8 @@ +/*---------------------------------------------------------------------------*\ + Attributed Grammar for Coco/R (-*- C++ -*- version) + compile with: + coco-cpp calcEntryParser.atg +\*---------------------------------------------------------------------------*/ [copy] /*---------------------------------*- C++ -*---------------------------------*\ ========= | @@ -36,13 +41,6 @@ SourceFiles \*---------------------------------------------------------------------------*/ [/copy] -/*---------------------------------------------------------------------------*\ - compile with: - Coco \ - [-single] -frames $WM_THIRD_PARTY_DIR/coco-r \ - calcEntryParser.atg -\*---------------------------------------------------------------------------*/ - #include "dictionary.H" #include "wchar.H" #include "calcEntryInternal.H" @@ -52,7 +50,9 @@ COMPILER calcEntry // grammar pragmas: $prefix=calcEntry $namespace=Foam::functionEntries::calcEntryInternal - $explicitEOF=true // grammar handles eof itself + $define=EXPLICIT_EOF // grammar handles eof itself + $define=STREAMS_ONLY // only use STL streams + $define=NO_UTF8 // disable UTF8 on input private: //- The parent dictionary @@ -62,56 +62,7 @@ private: scalar val; //- lookup dictionary entry - scalar getDictLookup() const - { - if (!dict_) - { - FatalErrorIn - ( - "calcEntry::getDictEntry() const" - ) << "No dictionary attached!" - << exit(FatalError); - - return 0; - } - - char* str = coco_string_create_char - ( - t->val, - 1, - (coco_string_length(t->val) - 1) - ); - word keyword(str); - coco_string_delete(str); - - scalar dictValue = 0; - - entry* entryPtr = dict_->lookupEntryPtr(keyword, true, false); - if (entryPtr && !entryPtr->isDict()) - { - if (entryPtr->stream().size() != 1) - { - FatalErrorIn - ( - "calcEntry::getDictEntry() const" - ) << "keyword " << keyword << " has " - << entryPtr->stream().size() << " values in dictionary " - << exit(FatalError); - } - entryPtr->stream() >> dictValue; - } - else - { - FatalErrorIn - ( - "calcEntry::getDictEntry() const" - ) << "keyword " << keyword << " is undefined in dictionary " - << exit(FatalError); - } - - return dictValue; - } - + scalar getDictLookup(const word&) const; public: @@ -128,11 +79,57 @@ public: } -[initialize] +/*---------------------------------------------------------------------------*/ + +[initialize] // add to Parser constructor dict_ = 0; val = 0; [/initialize] +/*---------------------------------------------------------------------------*/ +[code] +Foam::scalar Parser::getDictLookup(const word& keyword) const +{ + if (!dict_) + { + FatalErrorIn + ( + "calcEntry::getDictEntry(const word&) const" + ) << "No dictionary attached!" + << exit(FatalError); + + return 0; + } + + scalar dictValue = 0; + + entry* entryPtr = dict_->lookupEntryPtr(keyword, true, false); + if (entryPtr && !entryPtr->isDict()) + { + if (entryPtr->stream().size() != 1) + { + FatalErrorIn + ( + "calcEntry::getDictEntry(const word&) const" + ) << "keyword " << keyword << " has " + << entryPtr->stream().size() << " values in dictionary " + << exit(FatalError); + } + entryPtr->stream() >> dictValue; + } + else + { + FatalErrorIn + ( + "calcEntry::getDictEntry(const word&) const" + ) << "keyword " << keyword << " is undefined in dictionary " + << exit(FatalError); + } + + return dictValue; +} +[/code] + /*---------------------------------------------------------------------------*/ CHARACTERS @@ -226,7 +223,10 @@ Factor<scalar& val> (. bool negative = false; .) ] ( Func<val> | '(' Expr<val> ')' - | variable (. val = getDictLookup(); .) + | variable (. + // skip leading '$' for the keyword + val = getDictLookup(t->toString(1, t->length()-1)); + .) | number (. val = coco_string_toDouble(t->val); .) ) (. if (negative) { val = -val; } .) . @@ -238,9 +238,7 @@ Factor<scalar& val> (. bool negative = false; .) Func<scalar& val> = ident (. - char* str = coco_string_create_char(t->val); - word funcName(str); - coco_string_delete(str); + word funcName(t->toString()); DynamicList<scalar> stack(4); .) '(' diff --git a/src/OpenFOAM/db/error/CocoParserErrors.H b/src/OpenFOAM/db/error/CocoParserErrors.H index d9d2155db2624c9ebe273b880d041a387b3a2bf3..97d503204f1b38ccf5abfaffb4990a5eb4af4621 100644 --- a/src/OpenFOAM/db/error/CocoParserErrors.H +++ b/src/OpenFOAM/db/error/CocoParserErrors.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2009-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,7 +45,7 @@ namespace Foam Class CocoParserErrors Declaration \*---------------------------------------------------------------------------*/ -template<class BaseClass, class CharClass=wchar_t> +template<class BaseClass, class StringClass=std::wstring> class CocoParserErrors : public BaseClass @@ -90,14 +90,14 @@ public: // Error Handling //- Handle a general warning 'msg' - virtual void Warning(const CharClass* msg) + virtual void Warning(const StringClass& msg) { WarningIn(name_) << msg << endl; } //- Handle a general warning 'msg' - virtual void Warning(int line, int col, const CharClass* msg) + virtual void Warning(int line, int col, const StringClass& msg) { WarningIn(name_) <<"line " << line << " col " << col << ": " @@ -105,7 +105,7 @@ public: } //- Handle general error 'msg' (eg, a semantic error) - virtual void Error(int line, int col, const CharClass* msg) + virtual void Error(int line, int col, const StringClass& msg) { FatalErrorIn(name_) << "line " << line << " col " << col <<": " << msg << endl @@ -113,7 +113,7 @@ public: } //- Handle general error 'msg' (eg, a semantic error) - virtual void Error(const CharClass* msg) + virtual void Error(const StringClass& msg) { FatalErrorIn(name_) << msg << endl @@ -121,7 +121,7 @@ public: } //- Handle a general exception 'msg' - virtual void Exception(const CharClass* msg) + virtual void Exception(const StringClass& msg) { this->Error(msg); } diff --git a/src/OpenFOAM/primitives/chars/wchar/wchar.H b/src/OpenFOAM/primitives/chars/wchar/wchar.H index 61519a51d345032b8e96e262035b7009d8eba642..d4df7a61eaac704c77d8a39cc3e5ef465148f474 100644 --- a/src/OpenFOAM/primitives/chars/wchar/wchar.H +++ b/src/OpenFOAM/primitives/chars/wchar/wchar.H @@ -41,6 +41,7 @@ SeeAlso #define wchar_H #include <cwchar> +#include <string> // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -58,6 +59,9 @@ Ostream& operator<<(Ostream&, const wchar_t); //- Output wide character (Unicode) string as UTF-8 Ostream& operator<<(Ostream&, const wchar_t*); +//- Output wide character (Unicode) string as UTF-8 +Ostream& operator<<(Ostream&, const std::wstring&); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/chars/wchar/wcharIO.C b/src/OpenFOAM/primitives/chars/wchar/wcharIO.C index 9796d4b6eb9658eb4f8f68c8ff6fe8e3683a9f38..37f81321efd0e5fa6112bfb8cf33b3a59713efd6 100644 --- a/src/OpenFOAM/primitives/chars/wchar/wcharIO.C +++ b/src/OpenFOAM/primitives/chars/wchar/wcharIO.C @@ -101,13 +101,13 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const wchar_t wc) } -Foam::Ostream& Foam::operator<<(Ostream& os, const wchar_t* ws) +Foam::Ostream& Foam::operator<<(Ostream& os, const wchar_t* wstr) { - if (ws) + if (wstr) { - for (const wchar_t* p = ws; *p; ++p) + for (const wchar_t* iter = wstr; *iter; ++iter) { - os << *p; + os << *iter; } } @@ -115,4 +115,20 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const wchar_t* ws) } +Foam::Ostream& Foam::operator<<(Ostream& os, const std::wstring& wstr) +{ + for + ( + std::wstring::const_iterator iter = wstr.begin(); + iter != wstr.end(); + ++iter + ) + { + os << *iter; + } + + return os; +} + + // ************************************************************************* // diff --git a/wmake/rules/General/coco b/wmake/rules/General/coco index ca07810bdb1ede81986930baa4dcc739824d0afd..7f7bd2ff29b58e6d8b869fa567b2aa00cf2b1bd4 100644 --- a/wmake/rules/General/coco +++ b/wmake/rules/General/coco @@ -3,7 +3,7 @@ .SUFFIXES: .atg atgtoo = \ - $(WM_THIRD_PARTY_DIR)/coco-cpp/platforms/$(WM_ARCH)/bin/coco-cpp \ + $(WM_THIRD_PARTY_DIR)/coco-cpp/platforms/$(WM_ARCH)$(WM_COMPILER)/bin/coco-cpp \ -single \ -frames $(WM_THIRD_PARTY_DIR)/coco-cpp/platforms/share/coco-cpp \ $$SOURCE -o $(OBJECTS_DIR) && \