diff --git a/src/OpenFOAM/db/IOstreams/token/token.C b/src/OpenFOAM/db/IOstreams/token/token.C index 10fb5c19e8..df6fe702ee 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.C +++ b/src/OpenFOAM/db/IOstreams/token/token.C @@ -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::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 diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index ca6e79cce8..279e436e97 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -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; diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C index c2eeedc2d8..9d1064ae48 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -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(); } } }