ENH: dynamicCode: display line numbers

This commit is contained in:
mattijs
2011-03-25 04:43:29 +00:00
parent 19f88515a3
commit 20b1d49a82
6 changed files with 114 additions and 33 deletions

View File

@ -233,7 +233,11 @@
- codedFixedValue could be extended to provide local data however - codedFixedValue could be extended to provide local data however
in terms of complexity this is not really worthwhile. in terms of complexity this is not really worthwhile.
- all templates come from - all templates come from (in order of preference)
=etc/codeTemplates/dynamicCode=
=~/.OpenFOAM/dev/codeTemplates/dynamicCode=
=FOAM_TEMPLATE_DIR= =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.

View File

@ -522,7 +522,7 @@ bool Foam::dynamicCode::copyOrCreateFiles(const bool verbose) const
bool Foam::dynamicCode::wmakeLibso() 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; Info<< "Invoking " << wmakeCmd << endl;
if (Foam::system(wmakeCmd)) if (Foam::system(wmakeCmd))

View File

@ -34,44 +34,57 @@ License
Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict) Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
: :
dict_(dict), dict_(dict),
code_(stringOps::trim(dict["code"])), code_(),
localCode_(), localCode_(),
include_(), include_(),
options_(), options_(),
libs_() libs_()
{ {
// expand dictionary entries // 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 // note: removes any leading/trailing whitespace
// - necessary for compilation options, convenient for includes // - necessary for compilation options, convenient for includes
// and body. // and body.
// optional // optional
if (dict.found("localCode")) const entry* includePtr = dict.lookupEntryPtr
(
"codeInclude",
false,
false
);
if (includePtr)
{ {
localCode_ = stringOps::trim(dict["localCode"]); include_ = stringOps::trim(includePtr->stream());
stringOps::inplaceExpand(localCode_, dict);
}
// optional
if (dict.found("codeInclude"))
{
include_ = stringOps::trim(dict["codeInclude"]);
stringOps::inplaceExpand(include_, dict); stringOps::inplaceExpand(include_, dict);
addLineDirective(include_, includePtr->startLineNumber(), dict.name());
} }
// optional // 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); stringOps::inplaceExpand(options_, dict);
} }
// optional // 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); 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;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -51,6 +51,7 @@ namespace Foam
class dynamicCodeContext class dynamicCodeContext
{ {
// Private data // Private data
//- The parent dictionary context //- The parent dictionary context
const dictionary& dict_; const dictionary& dict_;
@ -123,6 +124,13 @@ public:
return sha1_; return sha1_;
} }
//- Helper: add #line directive
static void addLineDirective
(
string&,
const label lineNum,
const fileName& name
);
}; };

View File

@ -241,10 +241,6 @@ void Foam::codedFixedValueFvPatchField<Type>::createLibrary
// Write files for new library // Write files for new library
if (!dynCode.upToDate(context)) if (!dynCode.upToDate(context))
{ {
Info<< "Using dynamicCode for patch " << this->patch().name()
<< " on field " << this->dimensionedInternalField().name()
<< endl;
// filter with this context // filter with this context
dynCode.reset(context); dynCode.reset(context);
@ -271,7 +267,7 @@ void Foam::codedFixedValueFvPatchField<Type>::createLibrary
dynCode.setMakeOptions dynCode.setMakeOptions
( (
"EXE_INC = -g \\\n" "EXE_INC = -g \\\n"
"-I$(LIB_SRC)/finiteVolume/lnInclude\\\n" "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
+ context.options() + context.options()
+ "\n\nLIB_LIBS = \\\n" + "\n\nLIB_LIBS = \\\n"
+ " -lOpenFOAM \\\n" + " -lOpenFOAM \\\n"
@ -343,6 +339,12 @@ void Foam::codedFixedValueFvPatchField<Type>::updateLibrary() const
return; 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 // remove instantiation of fvPatchField provided by library
redirectPatchFieldPtr_.clear(); redirectPatchFieldPtr_.clear();

View File

@ -188,9 +188,6 @@ void Foam::codedFunctionObject::createLibrary
// Write files for new library // Write files for new library
if (!dynCode.upToDate(context)) if (!dynCode.upToDate(context))
{ {
Info<< "Using dynamicCode for functionObject " << name()
<< endl;
// filter with this context // filter with this context
dynCode.reset(context); dynCode.reset(context);
@ -282,6 +279,11 @@ void Foam::codedFunctionObject::updateLibrary() const
return; return;
} }
Info<< "Using dynamicCode for functionObject " << name()
<< " at line " << dict_.startLineNumber()
<< " in " << dict_.name() << endl;
// remove instantiation of fvPatchField provided by library // remove instantiation of fvPatchField provided by library
redirectFunctionObjectPtr_.clear(); redirectFunctionObjectPtr_.clear();
@ -375,21 +377,60 @@ bool Foam::codedFunctionObject::read(const dictionary& dict)
{ {
dict.lookup("redirectType") >> redirectType_; 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); 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); 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); stringOps::inplaceExpand(codeEnd_, dict);
dynamicCodeContext::addLineDirective
(
codeEnd_,
endPtr->startLineNumber(),
dict.name()
);
} }
updateLibrary(); updateLibrary();
return redirectFunctionObject().read(dict); return redirectFunctionObject().read(dict);
} }