Tokenizer: dumpfile will say if type token is _Atomic (#5189)

This commit is contained in:
Daniel Marjamäki 2023-06-25 11:22:30 +02:00 committed by GitHub
parent 60321edd0d
commit 87c2b8df04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 6 deletions

View File

@ -661,6 +661,13 @@ public:
setFlag(fIsInline, b); setFlag(fIsInline, b);
} }
bool isAtomic() const {
return getFlag(fIsAtomic);
}
void isAtomic(bool b) {
setFlag(fIsAtomic, b);
}
bool isRestrict() const { bool isRestrict() const {
return getFlag(fIsRestrict); return getFlag(fIsRestrict);
} }
@ -1337,8 +1344,9 @@ private:
fIsRemovedVoidParameter = (1ULL << 36), // A void function parameter has been removed fIsRemovedVoidParameter = (1ULL << 36), // A void function parameter has been removed
fIsIncompleteConstant = (1ULL << 37), fIsIncompleteConstant = (1ULL << 37),
fIsRestrict = (1ULL << 38), // Is this a restrict pointer type fIsRestrict = (1ULL << 38), // Is this a restrict pointer type
fIsSimplifiedTypedef = (1ULL << 39), fIsAtomic = (1ULL << 39), // Is this a _Atomic declaration
fIsFinalType = (1ULL << 40), // Is this a type with final specifier fIsSimplifiedTypedef = (1ULL << 40),
fIsFinalType = (1ULL << 41), // Is this a type with final specifier
}; };
enum : uint64_t { enum : uint64_t {

View File

@ -5852,6 +5852,8 @@ void Tokenizer::dump(std::ostream &out) const
out << " isComplex=\"true\""; out << " isComplex=\"true\"";
if (tok->isRestrict()) if (tok->isRestrict())
out << " isRestrict=\"true\""; out << " isRestrict=\"true\"";
if (tok->isAtomic())
out << " isAtomic=\"true\"";
if (tok->isAttributeExport()) if (tok->isAttributeExport())
out << " isAttributeExport=\"true\""; out << " isAttributeExport=\"true\"";
if (tok->link()) if (tok->link())
@ -9046,18 +9048,33 @@ void Tokenizer::simplifyKeyword()
tok->deleteNext(); tok->deleteNext();
if (c99) { if (c99) {
if (tok->str() == "restrict") { auto getTypeTokens = [tok]() {
for (Token *temp = tok->next(); Token::Match(temp, "%name%"); temp = temp->next()) { std::vector<Token*> ret;
temp->isRestrict(true); 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()) {
if (!temp->isKeyword())
ret.emplace_back(temp);
}
return ret;
};
if (tok->str() == "restrict") {
for (Token* temp: getTypeTokens())
temp->isRestrict(true);
tok->deleteThis(); tok->deleteThis();
} }
if (mSettings->standards.c >= Standards::C11) { if (mSettings->standards.c >= Standards::C11) {
while (tok->str() == "_Atomic") while (tok->str() == "_Atomic") {
for (Token* temp: getTypeTokens())
temp->isAtomic(true);
tok->deleteThis(); tok->deleteThis();
} }
} }
}
else if (cpp11) { else if (cpp11) {
if (cpp20 && tok->str() == "consteval") { if (cpp20 && tok->str() == "consteval") {