@@ -50,6 +50,9 @@ TokenList::TokenList(const Settings* settings) :
5050 mSettings(settings)
5151{
5252 mTokensFrontBack .list = this ;
53+ if (mSettings && (mSettings ->enforcedLang != Settings::Language::None)) {
54+ mLang = mSettings ->enforcedLang ;
55+ }
5356}
5457
5558TokenList::~TokenList ()
@@ -80,12 +83,12 @@ void TokenList::deallocateTokens()
8083
8184void TokenList::determineCppC ()
8285{
83- if (! mSettings ) {
84- mIsC = Path::isC ( getSourceFilePath ());
85- mIsCpp = Path::isCPP (getSourceFilePath ());
86- } 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+ // only try to determine it if it wasn't enforced
87+ if ( mLang == Settings::Language::None) {
88+ if ( Path::isC (getSourceFilePath ()))
89+ mLang = Settings::Language::C;
90+ else if ( Path::isCPP (getSourceFilePath ()))
91+ mLang = Settings::Language::CPP ;
8992 }
9093}
9194
@@ -1722,10 +1725,10 @@ namespace {
17221725 };
17231726}
17241727
1725- void TokenList::validateAst () const
1728+ void TokenList::validateAst (bool print ) const
17261729{
17271730 OnException oe{[&] {
1728- if (mSettings && mSettings -> debugnormal )
1731+ if (print )
17291732 mTokensFrontBack .front ->printOut ();
17301733 }};
17311734 // Check for some known issues in AST to avoid crash/hang later on
@@ -1854,7 +1857,7 @@ void TokenList::simplifyPlatformTypes()
18541857 if (!mSettings )
18551858 return ;
18561859
1857- const bool isCPP11 = mSettings ->standards .cpp >= Standards::CPP11;
1860+ const bool isCPP11 = isCPP () && ( mSettings ->standards .cpp >= Standards::CPP11) ;
18581861
18591862 enum { isLongLong, isLong, isInt } type;
18601863
@@ -1996,7 +1999,7 @@ void TokenList::simplifyStdType()
19961999 continue ;
19972000 }
19982001
1999- if (Token::Match (tok, " char|short|int|long|unsigned|signed|double|float" ) || (mSettings ->standards .c >= Standards::C99 && Token::Match (tok, " complex|_Complex" ))) {
2002+ if (Token::Match (tok, " char|short|int|long|unsigned|signed|double|float" ) || (isC () && (! mSettings || ( mSettings ->standards .c >= Standards::C99)) && Token::Match (tok, " complex|_Complex" ))) {
20002003 bool isFloat= false ;
20012004 bool isSigned = false ;
20022005 bool isUnsigned = false ;
@@ -2019,7 +2022,7 @@ void TokenList::simplifyStdType()
20192022 else if (Token::Match (tok2, " float|double" )) {
20202023 isFloat = true ;
20212024 typeSpec = tok2;
2022- } else if (mSettings ->standards .c >= Standards::C99 && Token::Match (tok2, " complex|_Complex" ))
2025+ } else if (isC () && (! mSettings || ( mSettings ->standards .c >= Standards::C99)) && Token::Match (tok2, " complex|_Complex" ))
20232026 isComplex = !isFloat || tok2->str () == " _Complex" || Token::Match (tok2->next (), " *|&|%name%" ); // Ensure that "complex" is not the variables name
20242027 else if (Token::Match (tok2, " char|int" )) {
20252028 if (!typeSpec)
@@ -2057,7 +2060,7 @@ void TokenList::simplifyStdType()
20572060
20582061bool TokenList::isKeyword (const std::string &str) const
20592062{
2060- if (mIsCpp ) {
2063+ if (isCPP () ) {
20612064 // TODO: integrate into keywords?
20622065 // types and literals are not handled as keywords
20632066 static const std::unordered_set<std::string> cpp_types = {" bool" , " false" , " true" };
0 commit comments