diff --git a/doc/changes/dynamicCode.org b/doc/changes/dynamicCode.org index 16c0b39143..12217c6f6c 100644 --- a/doc/changes/dynamicCode.org +++ b/doc/changes/dynamicCode.org @@ -233,7 +233,11 @@ - codedFixedValue could be extended to provide local data however in terms of complexity this is not really worthwhile. - - all templates come from - =etc/codeTemplates/dynamicCode= - =~/.OpenFOAM/dev/codeTemplates/dynamicCode= + - all templates come from (in order of preference) =FOAM_TEMPLATE_DIR= + =~/.OpenFOAM/dev/codeTemplates/dynamicCode= + =etc/codeTemplates/dynamicCode= + + - any generated C++ code will display line numbers relative to the original + dictionary (using the '#line' directive) to ease finding compilation + errors. diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C index d28494463f..56402b28e5 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C @@ -522,7 +522,7 @@ bool Foam::dynamicCode::copyOrCreateFiles(const bool verbose) const bool Foam::dynamicCode::wmakeLibso() const { - const Foam::string wmakeCmd("wmake -s libso " + this->codeRelPath()); + const Foam::string wmakeCmd("wmake -s libso " + this->codePath()); Info<< "Invoking " << wmakeCmd << endl; if (Foam::system(wmakeCmd)) diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C index ef6231d9b3..81c1a50ceb 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C @@ -34,44 +34,57 @@ License Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict) : dict_(dict), - code_(stringOps::trim(dict["code"])), + code_(), localCode_(), include_(), options_(), libs_() { // expand dictionary entries - stringOps::inplaceExpand(code_, dict); + + { + const entry& codeEntry = dict.lookupEntry("code", false, false); + code_ = stringOps::trim(codeEntry.stream()); + stringOps::inplaceExpand(code_, dict); + addLineDirective(code_, codeEntry.startLineNumber(), dict.name()); + } // note: removes any leading/trailing whitespace // - necessary for compilation options, convenient for includes // and body. // optional - if (dict.found("localCode")) + const entry* includePtr = dict.lookupEntryPtr + ( + "codeInclude", + false, + false + ); + if (includePtr) { - localCode_ = stringOps::trim(dict["localCode"]); - stringOps::inplaceExpand(localCode_, dict); - } - - // optional - if (dict.found("codeInclude")) - { - include_ = stringOps::trim(dict["codeInclude"]); + include_ = stringOps::trim(includePtr->stream()); stringOps::inplaceExpand(include_, dict); + addLineDirective(include_, includePtr->startLineNumber(), dict.name()); } // optional - if (dict.found("codeOptions")) + const entry* optionsPtr = dict.lookupEntryPtr + ( + "codeOptions", + false, + false + ); + if (optionsPtr) { - options_ = stringOps::trim(dict["codeOptions"]); + options_ = stringOps::trim(optionsPtr->stream()); stringOps::inplaceExpand(options_, dict); } // optional - if (dict.found("codeLibs")) + const entry* libsPtr = dict.lookupEntryPtr("codeLibs", false, false); + if (libsPtr) { - libs_ = stringOps::trim(dict["codeLibs"]); + libs_ = stringOps::trim(libsPtr->stream()); stringOps::inplaceExpand(libs_, dict); } @@ -82,4 +95,17 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict) } +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::dynamicCodeContext::addLineDirective +( + string& code, + const label lineNum, + const fileName& name +) +{ + code = "#line " + Foam::name(lineNum) + " \"" + name + "\"\n" + code; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H index f4a38695b7..8ff83b0724 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H @@ -51,6 +51,7 @@ namespace Foam class dynamicCodeContext { // Private data + //- The parent dictionary context const dictionary& dict_; @@ -123,6 +124,13 @@ public: return sha1_; } + //- Helper: add #line directive + static void addLineDirective + ( + string&, + const label lineNum, + const fileName& name + ); }; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C index 208077b262..8dd28c5e07 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C @@ -241,10 +241,6 @@ void Foam::codedFixedValueFvPatchField::createLibrary // Write files for new library if (!dynCode.upToDate(context)) { - Info<< "Using dynamicCode for patch " << this->patch().name() - << " on field " << this->dimensionedInternalField().name() - << endl; - // filter with this context dynCode.reset(context); @@ -271,7 +267,7 @@ void Foam::codedFixedValueFvPatchField::createLibrary dynCode.setMakeOptions ( "EXE_INC = -g \\\n" - "-I$(LIB_SRC)/finiteVolume/lnInclude\\\n" + "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" + context.options() + "\n\nLIB_LIBS = \\\n" + " -lOpenFOAM \\\n" @@ -343,6 +339,12 @@ void Foam::codedFixedValueFvPatchField::updateLibrary() const return; } + Info<< "Using dynamicCode for patch " << this->patch().name() + << " on field " << this->dimensionedInternalField().name() << nl + << "at line " << codeDict.startLineNumber() + << " in " << codeDict.name() << endl; + + // remove instantiation of fvPatchField provided by library redirectPatchFieldPtr_.clear(); diff --git a/src/postProcessing/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C b/src/postProcessing/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C index 36da451a63..5dcdf627c7 100644 --- a/src/postProcessing/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C +++ b/src/postProcessing/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C @@ -188,9 +188,6 @@ void Foam::codedFunctionObject::createLibrary // Write files for new library if (!dynCode.upToDate(context)) { - Info<< "Using dynamicCode for functionObject " << name() - << endl; - // filter with this context dynCode.reset(context); @@ -282,6 +279,11 @@ void Foam::codedFunctionObject::updateLibrary() const return; } + Info<< "Using dynamicCode for functionObject " << name() + << " at line " << dict_.startLineNumber() + << " in " << dict_.name() << endl; + + // remove instantiation of fvPatchField provided by library redirectFunctionObjectPtr_.clear(); @@ -375,21 +377,60 @@ bool Foam::codedFunctionObject::read(const dictionary& dict) { dict.lookup("redirectType") >> redirectType_; - if (dict.found("codeRead")) + const entry* readPtr = dict.lookupEntryPtr + ( + "codeRead", + false, + false + ); + if (readPtr) { - codeRead_ = stringOps::trim(dict["codeRead"]); + codeRead_ = stringOps::trim(readPtr->stream()); stringOps::inplaceExpand(codeRead_, dict); + dynamicCodeContext::addLineDirective + ( + codeRead_, + readPtr->startLineNumber(), + dict.name() + ); } - if (dict.found("codeExecute")) + + const entry* execPtr = dict.lookupEntryPtr + ( + "codeExecute", + false, + false + ); + if (execPtr) { - codeExecute_ = stringOps::trim(dict["codeExecute"]); + codeExecute_ = stringOps::trim(execPtr->stream()); stringOps::inplaceExpand(codeExecute_, dict); + dynamicCodeContext::addLineDirective + ( + codeExecute_, + execPtr->startLineNumber(), + dict.name() + ); } - if (dict.found("codeEnd")) + + const entry* endPtr = dict.lookupEntryPtr + ( + "codeEnd", + false, + false + ); + if (execPtr) { - codeEnd_ = stringOps::trim(dict["codeEnd"]); + codeEnd_ = stringOps::trim(endPtr->stream()); stringOps::inplaceExpand(codeEnd_, dict); + dynamicCodeContext::addLineDirective + ( + codeEnd_, + endPtr->startLineNumber(), + dict.name() + ); } + updateLibrary(); return redirectFunctionObject().read(dict); }