Token: Add 'isSplittedVarDecl attribute

This commit is contained in:
Daniel Marjamäki 2020-09-06 11:02:22 +02:00
parent c7aed8bd0e
commit 7969bf7ae8
4 changed files with 44 additions and 30 deletions

View File

@ -137,6 +137,7 @@ class Token:
isUnsigned Is this token a unsigned type isUnsigned Is this token a unsigned type
isSigned Is this token a signed type isSigned Is this token a signed type
isExpandedMacro Is this token a expanded macro token isExpandedMacro Is this token a expanded macro token
isSplittedVarDecl Is this token a splitted variable declaration. "int a,b; => int a; int b;"
varId varId for token, each variable has a unique non-zero id varId varId for token, each variable has a unique non-zero id
variable Variable information for this token. See the Variable class. variable Variable information for this token. See the Variable class.
function If this token points at a function call, this attribute has the Function function If this token points at a function call, this attribute has the Function
@ -185,6 +186,7 @@ class Token:
isUnsigned = False isUnsigned = False
isSigned = False isSigned = False
isExpandedMacro = False isExpandedMacro = False
isSplittedVarDecl = False
varId = None varId = None
variableId = None variableId = None
variable = None variable = None
@ -245,6 +247,8 @@ class Token:
self.isLogicalOp = True self.isLogicalOp = True
if element.get('isExpandedMacro'): if element.get('isExpandedMacro'):
self.isExpandedMacro = True self.isExpandedMacro = True
if element.get('isSplittedVarDecl'):
self.isExpandedMacro = True
self.linkId = element.get('link') self.linkId = element.get('link')
self.link = None self.link = None
if element.get('varId'): if element.get('varId'):
@ -275,10 +279,10 @@ class Token:
attrs = ["Id", "str", "scopeId", "isName", "isUnsigned", "isSigned", attrs = ["Id", "str", "scopeId", "isName", "isUnsigned", "isSigned",
"isNumber", "isInt", "isFloat", "isString", "strlen", "isNumber", "isInt", "isFloat", "isString", "strlen",
"isChar", "isOp", "isArithmeticalOp", "isComparisonOp", "isChar", "isOp", "isArithmeticalOp", "isComparisonOp",
"isLogicalOp", "isExpandedMacro", "linkId", "varId", "isLogicalOp", "isExpandedMacro", "isSplittedVarDecl",
"variableId", "functionId", "valuesId", "valueType", "linkId", "varId", "variableId", "functionId", "valuesId",
"typeScopeId", "astParentId", "astOperand1Id", "file", "valueType", "typeScopeId", "astParentId", "astOperand1Id",
"linenr", "column"] "file", "linenr", "column"]
return "{}({})".format( return "{}({})".format(
"Token", "Token",
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs)) ", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))

View File

@ -1939,7 +1939,7 @@ void Variable::evaluate(const Settings* settings)
setFlag(fIsReference, true); // Set also fIsReference setFlag(fIsReference, true); // Set also fIsReference
} }
if (tok->isMaybeUnused()) { if (tok->isAttributeMaybeUnused()) {
setFlag(fIsMaybeUnused, true); setFlag(fIsMaybeUnused, true);
} }

View File

@ -549,11 +549,11 @@ public:
void isAttributeNodiscard(const bool value) { void isAttributeNodiscard(const bool value) {
setFlag(fIsAttributeNodiscard, value); setFlag(fIsAttributeNodiscard, value);
} }
bool isMaybeUnused() const { bool isAttributeMaybeUnused() const {
return getFlag(fIsMaybeUnused); return getFlag(fIsAttributeMaybeUnused);
} }
void isMaybeUnused(const bool value) { void isAttributeMaybeUnused(const bool value) {
setFlag(fIsMaybeUnused, value); setFlag(fIsAttributeMaybeUnused, value);
} }
void setCppcheckAttribute(TokenImpl::CppcheckAttributes::Type type, MathLib::bigint value) { void setCppcheckAttribute(TokenImpl::CppcheckAttributes::Type type, MathLib::bigint value) {
mImpl->setCppcheckAttribute(type, value); mImpl->setCppcheckAttribute(type, value);
@ -612,6 +612,12 @@ public:
setFlag(fExternC, b); setFlag(fExternC, b);
} }
bool isSplittedVarDecl() const {
return getFlag(fIsSplitVarDecl);
}
void isSplittedVarDecl(bool b) {
setFlag(fIsSplitVarDecl, b);
}
bool isBitfield() const { bool isBitfield() const {
return mImpl->mBits > 0; return mImpl->mBits > 0;
@ -1182,19 +1188,20 @@ private:
fIsAttributeNothrow = (1 << 13), // __attribute__((nothrow)), __declspec(nothrow) fIsAttributeNothrow = (1 << 13), // __attribute__((nothrow)), __declspec(nothrow)
fIsAttributeUsed = (1 << 14), // __attribute__((used)) fIsAttributeUsed = (1 << 14), // __attribute__((used))
fIsAttributePacked = (1 << 15), // __attribute__((packed)) fIsAttributePacked = (1 << 15), // __attribute__((packed))
fIsControlFlowKeyword = (1 << 16), // if/switch/while/... fIsAttributeMaybeUnused = (1 << 16), // [[maybe_unsed]]
fIsOperatorKeyword = (1 << 17), // operator=, etc fIsControlFlowKeyword = (1 << 17), // if/switch/while/...
fIsComplex = (1 << 18), // complex/_Complex type fIsOperatorKeyword = (1 << 18), // operator=, etc
fIsEnumType = (1 << 19), // enumeration type fIsComplex = (1 << 19), // complex/_Complex type
fIsName = (1 << 20), fIsEnumType = (1 << 20), // enumeration type
fIsLiteral = (1 << 21), fIsName = (1 << 21),
fIsTemplateArg = (1 << 22), fIsLiteral = (1 << 22),
fIsAttributeNodiscard = (1 << 23), // __attribute__ ((warn_unused_result)), [[nodiscard]] fIsTemplateArg = (1 << 23),
fAtAddress = (1 << 24), // @ 0x4000 fIsAttributeNodiscard = (1 << 24), // __attribute__ ((warn_unused_result)), [[nodiscard]]
fIncompleteVar = (1 << 25), fAtAddress = (1 << 25), // @ 0x4000
fConstexpr = (1 << 26), fIncompleteVar = (1 << 26),
fExternC = (1 << 27), fConstexpr = (1 << 27),
fIsMaybeUnused = (1 << 28), // [[maybe_unsed]] fExternC = (1 << 28),
fIsSplitVarDecl = (1 << 29), // int a,b; <-- vardecl is split up
}; };
Token::Type mTokType; Token::Type mTokType;

View File

@ -4950,9 +4950,9 @@ void Tokenizer::dump(std::ostream &out) const
} else if (tok->isNumber()) { } else if (tok->isNumber()) {
out << " type=\"number\""; out << " type=\"number\"";
if (MathLib::isInt(tok->str())) if (MathLib::isInt(tok->str()))
out << " isInt=\"True\""; out << " isInt=\"true\"";
if (MathLib::isFloat(tok->str())) if (MathLib::isFloat(tok->str()))
out << " isFloat=\"True\""; out << " isFloat=\"true\"";
} else if (tok->tokType() == Token::eString) } else if (tok->tokType() == Token::eString)
out << " type=\"string\" strlen=\"" << Token::getStrLength(tok) << '\"'; out << " type=\"string\" strlen=\"" << Token::getStrLength(tok) << '\"';
else if (tok->tokType() == Token::eChar) else if (tok->tokType() == Token::eChar)
@ -4962,16 +4962,18 @@ void Tokenizer::dump(std::ostream &out) const
else if (tok->isOp()) { else if (tok->isOp()) {
out << " type=\"op\""; out << " type=\"op\"";
if (tok->isArithmeticalOp()) if (tok->isArithmeticalOp())
out << " isArithmeticalOp=\"True\""; out << " isArithmeticalOp=\"true\"";
else if (tok->isAssignmentOp()) else if (tok->isAssignmentOp())
out << " isAssignmentOp=\"True\""; out << " isAssignmentOp=\"true\"";
else if (tok->isComparisonOp()) else if (tok->isComparisonOp())
out << " isComparisonOp=\"True\""; out << " isComparisonOp=\"true\"";
else if (tok->tokType() == Token::eLogicalOp) else if (tok->tokType() == Token::eLogicalOp)
out << " isLogicalOp=\"True\""; out << " isLogicalOp=\"true\"";
} }
if (tok->isExpandedMacro()) if (tok->isExpandedMacro())
out << " isExpandedMacro=\"True\""; out << " isExpandedMacro=\"true\"";
if (tok->isSplittedVarDecl())
out << " isSplittedVarDecl=\"true\"";
if (tok->link()) if (tok->link())
out << " link=\"" << tok->link() << '\"'; out << " link=\"" << tok->link() << '\"';
if (tok->varId() > 0) if (tok->varId() > 0)
@ -6855,6 +6857,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
if (tok2->str() == ",") { if (tok2->str() == ",") {
tok2->str(";"); tok2->str(";");
tok2->isSplittedVarDecl(true);
//TODO: should we have to add also template '<>' links? //TODO: should we have to add also template '<>' links?
TokenList::insertTokens(tok2, type0, typelen); TokenList::insertTokens(tok2, type0, typelen);
} }
@ -10268,7 +10271,7 @@ void Tokenizer::simplifyCPPAttribute()
Token* head = tok->tokAt(5); Token* head = tok->tokAt(5);
while (isCPPAttribute(head)) while (isCPPAttribute(head))
head = head->tokAt(5); head = head->tokAt(5);
head->isMaybeUnused(true); head->isAttributeMaybeUnused(true);
} else if (Token::Match(tok->previous(), ") [ [ expects|ensures|assert default|audit|axiom| : %name% <|<=|>|>= %num% ] ]")) { } else if (Token::Match(tok->previous(), ") [ [ expects|ensures|assert default|audit|axiom| : %name% <|<=|>|>= %num% ] ]")) {
const Token *vartok = tok->tokAt(4); const Token *vartok = tok->tokAt(4);
if (vartok->str() == ":") if (vartok->str() == ":")