token: Generalised the handling of the type name of the primitive token types
The new token::typeName() function is used in stringOps to provide dictionary with better support for automatic type inference for variables in #calc expressions.
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -29,12 +29,31 @@ License
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
const char* const token::typeName = "token";
|
||||
token token::undefinedToken;
|
||||
|
||||
typedef token::compound tokenCompound;
|
||||
defineTypeNameAndDebug(tokenCompound, 0);
|
||||
defineRunTimeSelectionTable(tokenCompound, Istream);
|
||||
|
||||
const word token::typeNames_[] =
|
||||
{
|
||||
"undefined",
|
||||
"char",
|
||||
"word",
|
||||
"functionName",
|
||||
"variable",
|
||||
"string",
|
||||
"verbatimString",
|
||||
"int32_t",
|
||||
"int64_t",
|
||||
"uint32_t",
|
||||
"uint64_t",
|
||||
"floatScalar",
|
||||
"doubleScalar",
|
||||
"longDoubleScalar",
|
||||
"compound",
|
||||
"error"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -79,6 +98,23 @@ Foam::autoPtr<Foam::token::compound> Foam::token::compound::New
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::word& Foam::token::typeName() const
|
||||
{
|
||||
if (type_ == token::UNDEFINED)
|
||||
{
|
||||
return typeNames_[0];
|
||||
}
|
||||
else if (type_ == token::COMPOUND)
|
||||
{
|
||||
return compoundTokenPtr_->type();
|
||||
}
|
||||
else
|
||||
{
|
||||
return typeNames_[type_ - token::PUNCTUATION + 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::token::compound::isCompound(const word& name)
|
||||
{
|
||||
return
|
||||
|
||||
@ -245,6 +245,9 @@ private:
|
||||
|
||||
// Private Data
|
||||
|
||||
//- List of token type names
|
||||
static const word typeNames_[];
|
||||
|
||||
//- The token type
|
||||
tokenType type_;
|
||||
|
||||
@ -282,11 +285,6 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
// Static Data Members
|
||||
|
||||
static const char* const typeName;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
@ -347,6 +345,9 @@ public:
|
||||
inline bool undefined() const;
|
||||
inline bool error() const;
|
||||
|
||||
//- Return the type name of the token
|
||||
const word& typeName() const;
|
||||
|
||||
inline bool isPunctuation() const;
|
||||
inline punctuationToken pToken() const;
|
||||
|
||||
|
||||
@ -522,21 +522,8 @@ Foam::string& Foam::stringOps::inplaceExpandCodeString
|
||||
// Check that the primitive entry is a single token
|
||||
if (pe.size() == 1)
|
||||
{
|
||||
const token& t = pe[0];
|
||||
|
||||
// Map the token type to the variable type
|
||||
if (t.isScalar())
|
||||
{
|
||||
varType = "scalar";
|
||||
}
|
||||
else if (t.isLabel())
|
||||
{
|
||||
varType = "label";
|
||||
}
|
||||
else if (t.isString())
|
||||
{
|
||||
varType = "string";
|
||||
}
|
||||
// Map the token type name to the variable type
|
||||
varType = pe[0].typeName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user