Skip to content

Commit b711f88

Browse files
committed
TokenList: store Settings::Language instead of individual booleans
1 parent e51d809 commit b711f88

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ $(libcppdir)/checkautovariables.o: lib/checkautovariables.cpp lib/addoninfo.h li
491491
$(libcppdir)/checkbool.o: lib/checkbool.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checkbool.h lib/config.h lib/errortypes.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/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
492492
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkbool.cpp
493493

494-
$(libcppdir)/checkboost.o: lib/checkboost.cpp lib/check.h lib/checkboost.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
494+
$(libcppdir)/checkboost.o: lib/checkboost.cpp lib/addoninfo.h lib/check.h lib/checkboost.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
495495
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkboost.cpp
496496

497497
$(libcppdir)/checkbufferoverrun.o: lib/checkbufferoverrun.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/astutils.h lib/check.h lib/checkbufferoverrun.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.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/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h lib/xml.h
@@ -593,7 +593,7 @@ $(libcppdir)/infer.o: lib/infer.cpp lib/calculate.h lib/config.h lib/errortypes.
593593
$(libcppdir)/keywords.o: lib/keywords.cpp lib/config.h lib/keywords.h lib/standards.h lib/utils.h
594594
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/keywords.cpp
595595

596-
$(libcppdir)/library.o: lib/library.cpp externals/tinyxml2/tinyxml2.h lib/astutils.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h lib/xml.h
596+
$(libcppdir)/library.o: lib/library.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/astutils.h lib/config.h lib/errortypes.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/valueflow.h lib/vfvalue.h lib/xml.h
597597
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/library.cpp
598598

599599
$(libcppdir)/mathlib.o: lib/mathlib.cpp externals/simplecpp/simplecpp.h lib/config.h lib/errortypes.h lib/mathlib.h lib/utils.h
@@ -626,7 +626,7 @@ $(libcppdir)/settings.o: lib/settings.cpp externals/picojson/picojson.h lib/addo
626626
$(libcppdir)/summaries.o: lib/summaries.cpp lib/addoninfo.h lib/analyzerinfo.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
627627
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/summaries.cpp
628628

629-
$(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/mathlib.h lib/path.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h
629+
$(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h
630630
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/suppressions.cpp
631631

632632
$(libcppdir)/templatesimplifier.o: lib/templatesimplifier.cpp lib/addoninfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h

lib/tokenlist.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ void TokenList::deallocateTokens()
8080

8181
void TokenList::determineCppC()
8282
{
83-
if (!mSettings) {
84-
mIsC = Path::isC(getSourceFilePath());
85-
mIsCpp = Path::isCPP(getSourceFilePath());
83+
if (mSettings && (mSettings->enforcedLang != Settings::Language::None)) {
84+
mLang = mSettings->enforcedLang;
8685
} else {
87-
mIsC = mSettings->enforcedLang == Settings::Language::C || (mSettings->enforcedLang == Settings::Language::None && Path::isC(getSourceFilePath()));
88-
mIsCpp = mSettings->enforcedLang == Settings::Language::CPP || (mSettings->enforcedLang == Settings::Language::None && Path::isCPP(getSourceFilePath()));
86+
if (Path::isC(getSourceFilePath()))
87+
mLang = Settings::Language::C;
88+
else if (Path::isCPP(getSourceFilePath()))
89+
mLang = Settings::Language::CPP;
8990
}
9091
}
9192

@@ -1854,7 +1855,7 @@ void TokenList::simplifyPlatformTypes()
18541855
if (!mSettings)
18551856
return;
18561857

1857-
const bool isCPP11 = mIsCpp && (mSettings->standards.cpp >= Standards::CPP11);
1858+
const bool isCPP11 = isCPP() && (mSettings->standards.cpp >= Standards::CPP11);
18581859

18591860
enum { isLongLong, isLong, isInt } type;
18601861

@@ -1996,7 +1997,7 @@ void TokenList::simplifyStdType()
19961997
continue;
19971998
}
19981999

1999-
if (Token::Match(tok, "char|short|int|long|unsigned|signed|double|float") || (mIsC && (mSettings->standards.c >= Standards::C99) && Token::Match(tok, "complex|_Complex"))) {
2000+
if (Token::Match(tok, "char|short|int|long|unsigned|signed|double|float") || (isC() && (mSettings->standards.c >= Standards::C99) && Token::Match(tok, "complex|_Complex"))) {
20002001
bool isFloat= false;
20012002
bool isSigned = false;
20022003
bool isUnsigned = false;
@@ -2019,7 +2020,7 @@ void TokenList::simplifyStdType()
20192020
else if (Token::Match(tok2, "float|double")) {
20202021
isFloat = true;
20212022
typeSpec = tok2;
2022-
} else if (mIsC && (mSettings->standards.c >= Standards::C99) && Token::Match(tok2, "complex|_Complex"))
2023+
} else if (isC() && (mSettings->standards.c >= Standards::C99) && Token::Match(tok2, "complex|_Complex"))
20232024
isComplex = !isFloat || tok2->str() == "_Complex" || Token::Match(tok2->next(), "*|&|%name%"); // Ensure that "complex" is not the variables name
20242025
else if (Token::Match(tok2, "char|int")) {
20252026
if (!typeSpec)
@@ -2057,7 +2058,7 @@ void TokenList::simplifyStdType()
20572058

20582059
bool TokenList::isKeyword(const std::string &str) const
20592060
{
2060-
if (mIsCpp) {
2061+
if (isCPP()) {
20612062
// TODO: integrate into keywords?
20622063
// types and literals are not handled as keywords
20632064
static const std::unordered_set<std::string> cpp_types = {"bool", "false", "true"};

lib/tokenlist.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
//---------------------------------------------------------------------------
2323

2424
#include "config.h"
25+
#include "settings.h"
2526

2627
#include <cstddef>
2728
#include <iosfwd>
2829
#include <string>
2930
#include <vector>
3031

31-
class Settings;
3232
class Token;
3333
class TokenList;
3434

@@ -61,12 +61,12 @@ class CPPCHECKLIB TokenList {
6161

6262
/** Is the code C. Used for bailouts */
6363
bool isC() const {
64-
return mIsC;
64+
return mLang == Settings::Language::C;
6565
}
6666

6767
/** Is the code CPP. Used for bailouts */
6868
bool isCPP() const {
69-
return mIsCpp;
69+
return mLang == Settings::Language::CPP;
7070
}
7171

7272
/**
@@ -214,8 +214,7 @@ class CPPCHECKLIB TokenList {
214214
const Settings* const mSettings{};
215215

216216
/** File is known to be C/C++ code */
217-
bool mIsC{};
218-
bool mIsCpp{};
217+
Settings::Language mLang{Settings::Language::None};
219218
};
220219

221220
/// @}

0 commit comments

Comments
 (0)