From 4ba19c42ba1b6983c5b713f8638ad5fb2641baf2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:58:16 +0200 Subject: [PATCH] Bump simplecpp (fix #11991) (#5486) --- Makefile | 2 +- externals/simplecpp/simplecpp.cpp | 2 +- externals/simplecpp/simplecpp.h | 6 +++++- lib/token.cpp | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f4df0927a..2e421a3c1 100644 --- a/Makefile +++ b/Makefile @@ -627,7 +627,7 @@ $(libcppdir)/templatesimplifier.o: lib/templatesimplifier.cpp lib/color.h lib/co $(libcppdir)/timer.o: lib/timer.cpp lib/config.h lib/timer.h lib/utils.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/timer.cpp -$(libcppdir)/token.o: lib/token.cpp lib/astutils.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/tokenrange.h lib/utils.h lib/valueflow.h lib/vfvalue.h +$(libcppdir)/token.o: lib/token.cpp externals/simplecpp/simplecpp.h lib/astutils.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/tokenrange.h lib/utils.h lib/valueflow.h lib/vfvalue.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/token.cpp $(libcppdir)/tokenlist.o: lib/tokenlist.cpp externals/simplecpp/simplecpp.h lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/keywords.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 1f572fda7..6bad9e303 100755 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -949,7 +949,7 @@ void simplecpp::TokenList::combineOperators() if (tok->previous && tok->previous->number && sameline(tok->previous, tok)) { tok->setstr(tok->previous->str() + '.'); deleteToken(tok->previous); - if (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp"))) { + if (sameline(tok, tok->next) && (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp")))) { tok->setstr(tok->str() + tok->next->str()); deleteToken(tok->next); } diff --git a/externals/simplecpp/simplecpp.h b/externals/simplecpp/simplecpp.h index afd7d92c6..55a78b451 100755 --- a/externals/simplecpp/simplecpp.h +++ b/externals/simplecpp/simplecpp.h @@ -120,7 +120,7 @@ namespace simplecpp { name = (std::isalpha(static_cast(string[0])) || string[0] == '_' || string[0] == '$') && (std::memchr(string.c_str(), '\'', string.size()) == nullptr); comment = string.size() > 1U && string[0] == '/' && (string[1] == '/' || string[1] == '*'); - number = std::isdigit(static_cast(string[0])) || (string.size() > 1U && (string[0] == '-' || string[0] == '+') && std::isdigit(static_cast(string[1]))); + number = isNumberLike(string); op = (string.size() == 1U && !name && !comment && !number) ? string[0] : '\0'; } @@ -135,6 +135,10 @@ namespace simplecpp { bool isOneOf(const char ops[]) const; bool startsWithOneOf(const char c[]) const; bool endsWithOneOf(const char c[]) const; + static bool isNumberLike(const std::string& str) { + return std::isdigit(static_cast(str[0])) || + (str.size() > 1U && (str[0] == '-' || str[0] == '+') && std::isdigit(static_cast(str[1]))); + } TokenString macro; char op; diff --git a/lib/token.cpp b/lib/token.cpp index f047cb456..02f285234 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -22,6 +22,7 @@ #include "errortypes.h" #include "library.h" #include "settings.h" +#include "simplecpp.h" #include "symboldatabase.h" #include "tokenlist.h" #include "utils.h" @@ -143,7 +144,7 @@ void Token::update_property_info() tokType(eKeyword); else if (mTokType != eVariable && mTokType != eFunction && mTokType != eType && mTokType != eKeyword) tokType(eName); - } else if (std::isdigit((unsigned char)mStr[0]) || (mStr.length() > 1 && mStr[0] == '-' && std::isdigit((unsigned char)mStr[1]))) { + } else if (simplecpp::Token::isNumberLike(mStr)) { if (MathLib::isInt(mStr) || MathLib::isFloat(mStr)) tokType(eNumber); else