Skip to content

Commit 87c2b8d

Browse files
authored
Tokenizer: dumpfile will say if type token is _Atomic (cppcheck-opensource#5189)
1 parent 60321ed commit 87c2b8d

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

lib/token.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,13 @@ class CPPCHECKLIB Token {
661661
setFlag(fIsInline, b);
662662
}
663663

664+
bool isAtomic() const {
665+
return getFlag(fIsAtomic);
666+
}
667+
void isAtomic(bool b) {
668+
setFlag(fIsAtomic, b);
669+
}
670+
664671
bool isRestrict() const {
665672
return getFlag(fIsRestrict);
666673
}
@@ -1337,8 +1344,9 @@ class CPPCHECKLIB Token {
13371344
fIsRemovedVoidParameter = (1ULL << 36), // A void function parameter has been removed
13381345
fIsIncompleteConstant = (1ULL << 37),
13391346
fIsRestrict = (1ULL << 38), // Is this a restrict pointer type
1340-
fIsSimplifiedTypedef = (1ULL << 39),
1341-
fIsFinalType = (1ULL << 40), // Is this a type with final specifier
1347+
fIsAtomic = (1ULL << 39), // Is this a _Atomic declaration
1348+
fIsSimplifiedTypedef = (1ULL << 40),
1349+
fIsFinalType = (1ULL << 41), // Is this a type with final specifier
13421350
};
13431351

13441352
enum : uint64_t {

lib/tokenize.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5852,6 +5852,8 @@ void Tokenizer::dump(std::ostream &out) const
58525852
out << " isComplex=\"true\"";
58535853
if (tok->isRestrict())
58545854
out << " isRestrict=\"true\"";
5855+
if (tok->isAtomic())
5856+
out << " isAtomic=\"true\"";
58555857
if (tok->isAttributeExport())
58565858
out << " isAttributeExport=\"true\"";
58575859
if (tok->link())
@@ -9046,16 +9048,31 @@ void Tokenizer::simplifyKeyword()
90469048
tok->deleteNext();
90479049

90489050
if (c99) {
9049-
if (tok->str() == "restrict") {
9051+
auto getTypeTokens = [tok]() {
9052+
std::vector<Token*> ret;
9053+
for (Token *temp = tok; Token::Match(temp, "%name%"); temp = temp->previous()) {
9054+
if (!temp->isKeyword())
9055+
ret.emplace_back(temp);
9056+
}
90509057
for (Token *temp = tok->next(); Token::Match(temp, "%name%"); temp = temp->next()) {
9051-
temp->isRestrict(true);
9058+
if (!temp->isKeyword())
9059+
ret.emplace_back(temp);
90529060
}
9061+
return ret;
9062+
};
9063+
9064+
if (tok->str() == "restrict") {
9065+
for (Token* temp: getTypeTokens())
9066+
temp->isRestrict(true);
90539067
tok->deleteThis();
90549068
}
90559069

90569070
if (mSettings->standards.c >= Standards::C11) {
9057-
while (tok->str() == "_Atomic")
9071+
while (tok->str() == "_Atomic") {
9072+
for (Token* temp: getTypeTokens())
9073+
temp->isAtomic(true);
90589074
tok->deleteThis();
9075+
}
90599076
}
90609077
}
90619078

0 commit comments

Comments
 (0)