Token: add isRestrict flag

This commit is contained in:
Daniel Marjamäki 2022-05-22 14:10:40 +02:00
parent e2c35abde5
commit 03c9253962
2 changed files with 23 additions and 6 deletions

View File

@ -651,6 +651,13 @@ public:
setFlag(fIsInline, b); setFlag(fIsInline, b);
} }
bool isRestrict() const {
return getFlag(fIsRestrict);
}
void isRestrict(bool b) {
setFlag(fIsRestrict, b);
}
bool isRemovedVoidParameter() const { bool isRemovedVoidParameter() const {
return getFlag(fIsRemovedVoidParameter); return getFlag(fIsRemovedVoidParameter);
} }
@ -1277,6 +1284,7 @@ private:
fIsSimplifedScope = (1ULL << 34), // scope added when simplifying e.g. if (int i = ...; ...) fIsSimplifedScope = (1ULL << 34), // scope added when simplifying e.g. if (int i = ...; ...)
fIsRemovedVoidParameter = (1ULL << 35), // A void function parameter has been removed fIsRemovedVoidParameter = (1ULL << 35), // A void function parameter has been removed
fIsIncompleteConstant = (1ULL << 36), fIsIncompleteConstant = (1ULL << 36),
fIsRestrict = (1ULL << 37), // Is this a restrict pointer type
}; };
Token::Type mTokType; Token::Type mTokType;

View File

@ -5498,6 +5498,8 @@ void Tokenizer::dump(std::ostream &out) const
out << " isImplicitInt=\"true\""; out << " isImplicitInt=\"true\"";
if (tok->isComplex()) if (tok->isComplex())
out << " isComplex=\"true\""; out << " isComplex=\"true\"";
if (tok->isRestrict())
out << " isRestrict=\"true\"";
if (tok->link()) if (tok->link())
out << " link=\"" << tok->link() << '\"'; out << " link=\"" << tok->link() << '\"';
if (tok->varId() > 0) if (tok->varId() > 0)
@ -11249,11 +11251,14 @@ void Tokenizer::simplifyKeyword()
if (keywords.find(tok->str()) != keywords.end()) { if (keywords.find(tok->str()) != keywords.end()) {
// Don't remove struct members // Don't remove struct members
if (!Token::simpleMatch(tok->previous(), ".")) { if (!Token::simpleMatch(tok->previous(), ".")) {
if (tok->str().find("inline") != std::string::npos) { const bool isinline = (tok->str().find("inline") != std::string::npos);
Token *temp = tok->next(); const bool isrestrict = (tok->str().find("restrict") != std::string::npos);
while (temp != nullptr && Token::Match(temp, "%name%")) { if (isinline || isrestrict) {
for (Token *temp = tok->next(); Token::Match(temp, "%name%"); temp = temp->next()) {
if (isinline)
temp->isInline(true); temp->isInline(true);
temp = temp->next(); if (isrestrict)
temp->isRestrict(true);
} }
} }
tok->deleteThis(); // Simplify.. tok->deleteThis(); // Simplify..
@ -11271,8 +11276,12 @@ void Tokenizer::simplifyKeyword()
tok->deleteNext(); tok->deleteNext();
if (c99) { if (c99) {
while (tok->str() == "restrict") if (tok->str() == "restrict") {
for (Token *temp = tok->next(); Token::Match(temp, "%name%"); temp = temp->next()) {
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")