56void Foam::functionEntries::ifeqEntry::readToken(
token& t,
Istream& is)
70Foam::token Foam::functionEntries::ifeqEntry::expandToken
73 const string& keyword,
77 if (keyword[0] ==
'$')
79 const word varName(keyword.substr(1));
85 return token(ePtr->stream());
90 string expanded(keyword);
94 return token(expanded, t.lineNumber());
97 else if (!t.isString())
100 return token(keyword, t.lineNumber());
107Foam::token Foam::functionEntries::ifeqEntry::expandToken
115 return expandToken(
dict, t.wordToken(), t);
117 else if (t.isVariable())
119 return expandToken(
dict, t.stringToken(), t);
121 else if (t.isString())
123 return expandToken(
dict, t.stringToken(), t);
130bool Foam::functionEntries::ifeqEntry::equalToken
136 const bool eqType = (t1.type() == t2.type());
144 return (eqType && t1.boolToken() == t2.boolToken());
147 return (eqType && t1.flagToken() == t2.flagToken());
150 return (eqType && t1.pToken() == t2.pToken());
157 return t1.wordToken() == t2.wordToken();
159 else if (t2.isString())
162 return w2.match(t1.wordToken());
173 return w1.match(
w2) ||
w2.match(
w1);
175 else if (t2.isWord())
178 return w1.match(t2.wordToken());
187 if (t2.isStringType())
189 return t1.stringToken() == t2.stringToken();
198 return t1.int32Token() == t2.int32Token();
200 else if (t2.isLabel())
202 return t1.labelToken() == t2.labelToken();
204 else if (t2.isScalar())
206 return t1.labelToken() == t2.scalarToken();
215 return t1.int64Token() == t2.int64Token();
217 else if (t2.isLabel())
219 return t1.labelToken() == t2.labelToken();
221 else if (t2.isScalar())
223 return t1.labelToken() == t2.scalarToken();
232 return t1.uint32Token() == t2.uint32Token();
234 else if (t2.isLabel())
236 return t1.labelToken() == t2.labelToken();
238 else if (t2.isScalar())
240 return t1.labelToken() == t2.scalarToken();
249 return t1.uint64Token() == t2.uint64Token();
251 else if (t2.isLabel())
253 return t1.labelToken() == t2.labelToken();
255 else if (t2.isScalar())
257 return t1.labelToken() == t2.scalarToken();
266 return equal(t1.floatToken(), t2.floatToken());
268 else if (t2.isLabel())
270 return t1.floatToken() == t2.labelToken();
272 else if (t2.isScalar())
274 return t1.scalarToken() == t2.scalarToken();
283 return equal(t1.doubleToken(), t2.doubleToken());
285 else if (t2.isLabel())
287 return t1.doubleToken() == t2.labelToken();
289 else if (t2.isScalar())
291 return t1.scalarToken() == t2.scalarToken();
310void Foam::functionEntries::ifeqEntry::skipUntil
312 DynamicList<filePos>& stack,
314 const word& endDirective,
323 if (!t.isDirective())
327 else if (t.wordToken() ==
"#if" || t.wordToken() ==
"#ifeq")
329 stack.push_back(filePos(is.name(), is.lineNumber()));
330 skipUntil(stack, parentDict,
"#endif", is);
333 else if (t.wordToken() == endDirective)
340 <<
"Did not find matching " << endDirective <<
nl
359 bool pending =
false;
366 execute(stack, parentDict, is);
371 ifEntry::execute(stack, parentDict, is);
380 skipUntil(stack, parentDict,
"#endif", is);
416 DynamicList<filePos>& stack,
423 evaluate(
true, stack, parentDict, is);
434 if (!t.isDirective())
439 if (t.wordToken() ==
"#if" || t.wordToken() ==
"#ifeq")
441 stack.push_back(filePos(is.name(), is.lineNumber()));
442 skipUntil(stack, parentDict,
"#endif", is);
445 else if (t.wordToken() ==
"#else")
449 else if (t.wordToken() ==
"#elif")
455 dynamic_cast<ISstream&
>(is).getLine(line);
457 IStringStream lineStream(line);
458 const primitiveEntry
e(
"ifEntry", parentDict, lineStream);
460 if (ifEntry::isTrue(
e.stream()))
467 else if (t.wordToken() ==
"#endif")
474 if (t.wordToken() ==
"#else")
477 evaluate(
false, stack, parentDict, is);
479 else if (t.wordToken() ==
"#elif")
491 DynamicList<filePos>& stack,
496 const label nNested = stack.size();
498 stack.push_back(filePos(is.name(), is.lineNumber()));
502 cond1 = expandToken(parentDict, cond1);
506 cond2 = expandToken(parentDict, cond2);
508 const bool equal = equalToken(cond1, cond2);
517 if (stack.size() != nNested)
520 <<
"Did not find matching #endif for condition starting"
521 <<
" at line " << stack.back().second()
538 return execute(stack, parentDict, is);
Macros for easy insertion into member function selection tables.
#define addNamedToMemberFunctionSelectionTable(baseType, thisType, funcName, argNames, lookupName)
Add to hash-table of functions with 'lookupName' as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void pop_back(label n=1)
Reduce size by 1 or more elements. Can be called on an empty list.
void push_back(const T &val)
Copy append an element to the end of this list.
label lineNumber() const noexcept
Const access to the current stream line number.
bool bad() const noexcept
True if stream is corrupted.
virtual const fileName & name() const
The name of the stream.
bool eof() const noexcept
True if end of input seen.
Generic input stream using a standard (STL) stream.
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void putBack(const token &tok)
Put back a token (copy). Only a single put back is permitted.
virtual Istream & read(token &)=0
Return next token from stream.
T & back()
Access last element of the list, position [size()-1].
void size(const label n)
Older name for setAddressableSize.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
static bool New(dictionary &parentDict, Istream &is, const inputMode inpMode=inputMode::GLOBAL, const int endChar=0)
Construct from an Istream and insert into the dictionary.
Conditional parsing of dictionary entries.
static bool evaluate(const bool doIf, DynamicList< filePos > &stack, dictionary &parentDict, Istream &is)
static bool execute(const bool equal, DynamicList< filePos > &stack, dictionary &parentDict, Istream &is)
Main driver: depending on 'equal' starts evaluating or skips forward to else.
Tuple2< fileName, label > filePos
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
primitiveEntry(const keyType &key)
Construct from keyword and no tokens.
A token holds an item read from Istream.
@ ERROR
Token error encountered.
@ DOUBLE
double (double-precision) type
@ FLAG
stream flag (1-byte bitmask)
@ UNSIGNED_INTEGER_32
uint32 type
@ UNDEFINED
An undefined token-type.
@ COMPOUND
Compound type such as List<label> etc.
@ CHAR_DATA
String-variant: plain character content.
@ FLOAT
float (single-precision) type
@ UNSIGNED_INTEGER_64
uint64 type
@ STRING
Foam::string (usually double-quoted).
@ PUNCTUATION
single character punctuation
@ END_STATEMENT
End entry [isseparator].
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
bool isDirective() const noexcept
Token is DIRECTIVE (word variant).
const word & wordToken() const
Return const reference to the word contents.
@ DETECT
Detect if the string contains meta-characters.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Namespace for containing a functionEntry.
void inplaceExpand(std::string &s, const HashTable< string > &mapping, const char sigil='$')
Inplace expand occurrences of variables according to the mapping. Does not use environment values.
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
bool equal(const T &a, const T &b)
Compare two values for equality.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).