Skip to content

Commit

Permalink
Tokenizer: dumpfile will say if type token is _Atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Jun 25, 2023
1 parent 60321ed commit 6350131
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
12 changes: 10 additions & 2 deletions lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,13 @@ class CPPCHECKLIB Token {
setFlag(fIsInline, b);
}

bool isAtomic() const {
return getFlag(fIsAtomic);
}
void isAtomic(bool b) {
setFlag(fIsAtomic, b);
}

bool isRestrict() const {
return getFlag(fIsRestrict);
}
Expand Down Expand Up @@ -1337,8 +1344,9 @@ class CPPCHECKLIB Token {
fIsRemovedVoidParameter = (1ULL << 36), // A void function parameter has been removed
fIsIncompleteConstant = (1ULL << 37),
fIsRestrict = (1ULL << 38), // Is this a restrict pointer type
fIsSimplifiedTypedef = (1ULL << 39),
fIsFinalType = (1ULL << 40), // Is this a type with final specifier
fIsAtomic = (1ULL << 39), // Is this a _Atomic declaration
fIsSimplifiedTypedef = (1ULL << 40),
fIsFinalType = (1ULL << 41), // Is this a type with final specifier
};

enum : uint64_t {
Expand Down
23 changes: 20 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5852,6 +5852,8 @@ void Tokenizer::dump(std::ostream &out) const
out << " isComplex=\"true\"";
if (tok->isRestrict())
out << " isRestrict=\"true\"";
if (tok->isAtomic())
out << " isAtomic=\"true\"";
if (tok->isAttributeExport())
out << " isAttributeExport=\"true\"";
if (tok->link())
Expand Down Expand Up @@ -9046,16 +9048,31 @@ void Tokenizer::simplifyKeyword()
tok->deleteNext();

if (c99) {
if (tok->str() == "restrict") {
auto getTypeTokens = [tok]() {
std::vector<Token*> ret;
for (Token *temp = tok; Token::Match(temp, "%name%"); temp = temp->previous()) {
if (!temp->isKeyword())
ret.emplace_back(temp);
}
for (Token *temp = tok->next(); Token::Match(temp, "%name%"); temp = temp->next()) {
temp->isRestrict(true);
if (!temp->isKeyword())
ret.emplace_back(temp);
}
return ret;
};

if (tok->str() == "restrict") {
for (Token* temp: getTypeTokens())
temp->isRestrict(true);
tok->deleteThis();
}

if (mSettings->standards.c >= Standards::C11) {
while (tok->str() == "_Atomic")
while (tok->str() == "_Atomic") {
for (Token* temp: getTypeTokens())
temp->isAtomic(true);
tok->deleteThis();
}
}
}

Expand Down

0 comments on commit 6350131

Please sign in to comment.