BUG: bad '#line' directives for dynamicCode (fixes #1282)

- now suppress any '#line' if the input number number is invalid
  (ie, an empty set of tokens)
This commit is contained in:
Mark Olesen
2019-04-15 12:42:29 +02:00
committed by Andrew Heather
parent 53d01c8a0a
commit cd7748f8e4
2 changed files with 13 additions and 7 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -124,11 +124,16 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict)
void Foam::dynamicCodeContext::addLineDirective void Foam::dynamicCodeContext::addLineDirective
( (
string& code, string& code,
const label lineNum, label lineNum,
const fileName& name const fileName& name
) )
{ {
code = "#line " + Foam::name(lineNum + 1) + " \"" + name + "\"\n" + code; ++lineNum; // Change from 0-based to 1-based
if (lineNum > 0 && !name.empty())
{
code = "#line " + Foam::name(lineNum) + " \"" + name + "\"\n" + code;
}
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -80,7 +80,7 @@ public:
// Constructors // Constructors
//- Construct from a dictionary //- Construct from a dictionary
dynamicCodeContext(const dictionary&); dynamicCodeContext(const dictionary& dict);
// Member functions // Member functions
@ -128,10 +128,11 @@ public:
} }
//- Helper: add \#line directive //- Helper: add \#line directive
// The lineNum is 0-based. No-op if the lineNum is negative.
static void addLineDirective static void addLineDirective
( (
string&, string& code,
const label lineNum, label lineNum,
const fileName& name const fileName& name
); );
}; };