1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "dynamicCodeContext.H"
27 #include "stringOps.H"
28 #include "OSHA1stream.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
42 // expand dictionary entries
45 const entry& codeEntry = dict.lookupEntry("code", false, false);
46 code_ = stringOps::trim(codeEntry.stream());
47 stringOps::inplaceExpand(code_, dict);
50 // note: removes any leading/trailing whitespace
51 // - necessary for compilation options, convenient for includes
55 const entry* includePtr = dict.lookupEntryPtr
63 include_ = stringOps::trim(includePtr->stream());
64 stringOps::inplaceExpand(include_, dict);
68 const entry* optionsPtr = dict.lookupEntryPtr
76 options_ = stringOps::trim(optionsPtr->stream());
77 stringOps::inplaceExpand(options_, dict);
81 const entry* libsPtr = dict.lookupEntryPtr("codeLibs", false, false);
84 libs_ = stringOps::trim(libsPtr->stream());
85 stringOps::inplaceExpand(libs_, dict);
88 // calculate SHA1 digest from include, options, localCode, code
90 os << include_ << options_ << libs_ << localCode_ << code_;
95 // Add line number after calculating sha1 since includes processorDDD
96 // in path which differs between processors.
99 const entry& codeEntry = dict.lookupEntry("code", false, false);
100 addLineDirective(code_, codeEntry.startLineNumber(), dict.name());
104 addLineDirective(include_, includePtr->startLineNumber(), dict.name());
108 addLineDirective(options_, optionsPtr->startLineNumber(), dict.name());
112 addLineDirective(libs_, libsPtr->startLineNumber(), dict.name());
117 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
119 void Foam::dynamicCodeContext::addLineDirective
126 code = "#line " + Foam::name(lineNum) + " \"" + name + "\"\n" + code;
130 // ************************************************************************* //