Token: Add 'isSplittedVarDecl attribute
This commit is contained in:
parent
c7aed8bd0e
commit
7969bf7ae8
|
@ -137,6 +137,7 @@ class Token:
|
|||
isUnsigned Is this token a unsigned type
|
||||
isSigned Is this token a signed type
|
||||
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
|
||||
variable Variable information for this token. See the Variable class.
|
||||
function If this token points at a function call, this attribute has the Function
|
||||
|
@ -185,6 +186,7 @@ class Token:
|
|||
isUnsigned = False
|
||||
isSigned = False
|
||||
isExpandedMacro = False
|
||||
isSplittedVarDecl = False
|
||||
varId = None
|
||||
variableId = None
|
||||
variable = None
|
||||
|
@ -245,6 +247,8 @@ class Token:
|
|||
self.isLogicalOp = True
|
||||
if element.get('isExpandedMacro'):
|
||||
self.isExpandedMacro = True
|
||||
if element.get('isSplittedVarDecl'):
|
||||
self.isExpandedMacro = True
|
||||
self.linkId = element.get('link')
|
||||
self.link = None
|
||||
if element.get('varId'):
|
||||
|
@ -275,10 +279,10 @@ class Token:
|
|||
attrs = ["Id", "str", "scopeId", "isName", "isUnsigned", "isSigned",
|
||||
"isNumber", "isInt", "isFloat", "isString", "strlen",
|
||||
"isChar", "isOp", "isArithmeticalOp", "isComparisonOp",
|
||||
"isLogicalOp", "isExpandedMacro", "linkId", "varId",
|
||||
"variableId", "functionId", "valuesId", "valueType",
|
||||
"typeScopeId", "astParentId", "astOperand1Id", "file",
|
||||
"linenr", "column"]
|
||||
"isLogicalOp", "isExpandedMacro", "isSplittedVarDecl",
|
||||
"linkId", "varId", "variableId", "functionId", "valuesId",
|
||||
"valueType", "typeScopeId", "astParentId", "astOperand1Id",
|
||||
"file", "linenr", "column"]
|
||||
return "{}({})".format(
|
||||
"Token",
|
||||
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
|
||||
|
|
|
@ -1939,7 +1939,7 @@ void Variable::evaluate(const Settings* settings)
|
|||
setFlag(fIsReference, true); // Set also fIsReference
|
||||
}
|
||||
|
||||
if (tok->isMaybeUnused()) {
|
||||
if (tok->isAttributeMaybeUnused()) {
|
||||
setFlag(fIsMaybeUnused, true);
|
||||
}
|
||||
|
||||
|
|
41
lib/token.h
41
lib/token.h
|
@ -549,11 +549,11 @@ public:
|
|||
void isAttributeNodiscard(const bool value) {
|
||||
setFlag(fIsAttributeNodiscard, value);
|
||||
}
|
||||
bool isMaybeUnused() const {
|
||||
return getFlag(fIsMaybeUnused);
|
||||
bool isAttributeMaybeUnused() const {
|
||||
return getFlag(fIsAttributeMaybeUnused);
|
||||
}
|
||||
void isMaybeUnused(const bool value) {
|
||||
setFlag(fIsMaybeUnused, value);
|
||||
void isAttributeMaybeUnused(const bool value) {
|
||||
setFlag(fIsAttributeMaybeUnused, value);
|
||||
}
|
||||
void setCppcheckAttribute(TokenImpl::CppcheckAttributes::Type type, MathLib::bigint value) {
|
||||
mImpl->setCppcheckAttribute(type, value);
|
||||
|
@ -612,6 +612,12 @@ public:
|
|||
setFlag(fExternC, b);
|
||||
}
|
||||
|
||||
bool isSplittedVarDecl() const {
|
||||
return getFlag(fIsSplitVarDecl);
|
||||
}
|
||||
void isSplittedVarDecl(bool b) {
|
||||
setFlag(fIsSplitVarDecl, b);
|
||||
}
|
||||
|
||||
bool isBitfield() const {
|
||||
return mImpl->mBits > 0;
|
||||
|
@ -1182,19 +1188,20 @@ private:
|
|||
fIsAttributeNothrow = (1 << 13), // __attribute__((nothrow)), __declspec(nothrow)
|
||||
fIsAttributeUsed = (1 << 14), // __attribute__((used))
|
||||
fIsAttributePacked = (1 << 15), // __attribute__((packed))
|
||||
fIsControlFlowKeyword = (1 << 16), // if/switch/while/...
|
||||
fIsOperatorKeyword = (1 << 17), // operator=, etc
|
||||
fIsComplex = (1 << 18), // complex/_Complex type
|
||||
fIsEnumType = (1 << 19), // enumeration type
|
||||
fIsName = (1 << 20),
|
||||
fIsLiteral = (1 << 21),
|
||||
fIsTemplateArg = (1 << 22),
|
||||
fIsAttributeNodiscard = (1 << 23), // __attribute__ ((warn_unused_result)), [[nodiscard]]
|
||||
fAtAddress = (1 << 24), // @ 0x4000
|
||||
fIncompleteVar = (1 << 25),
|
||||
fConstexpr = (1 << 26),
|
||||
fExternC = (1 << 27),
|
||||
fIsMaybeUnused = (1 << 28), // [[maybe_unsed]]
|
||||
fIsAttributeMaybeUnused = (1 << 16), // [[maybe_unsed]]
|
||||
fIsControlFlowKeyword = (1 << 17), // if/switch/while/...
|
||||
fIsOperatorKeyword = (1 << 18), // operator=, etc
|
||||
fIsComplex = (1 << 19), // complex/_Complex type
|
||||
fIsEnumType = (1 << 20), // enumeration type
|
||||
fIsName = (1 << 21),
|
||||
fIsLiteral = (1 << 22),
|
||||
fIsTemplateArg = (1 << 23),
|
||||
fIsAttributeNodiscard = (1 << 24), // __attribute__ ((warn_unused_result)), [[nodiscard]]
|
||||
fAtAddress = (1 << 25), // @ 0x4000
|
||||
fIncompleteVar = (1 << 26),
|
||||
fConstexpr = (1 << 27),
|
||||
fExternC = (1 << 28),
|
||||
fIsSplitVarDecl = (1 << 29), // int a,b; <-- vardecl is split up
|
||||
};
|
||||
|
||||
Token::Type mTokType;
|
||||
|
|
|
@ -4950,9 +4950,9 @@ void Tokenizer::dump(std::ostream &out) const
|
|||
} else if (tok->isNumber()) {
|
||||
out << " type=\"number\"";
|
||||
if (MathLib::isInt(tok->str()))
|
||||
out << " isInt=\"True\"";
|
||||
out << " isInt=\"true\"";
|
||||
if (MathLib::isFloat(tok->str()))
|
||||
out << " isFloat=\"True\"";
|
||||
out << " isFloat=\"true\"";
|
||||
} else if (tok->tokType() == Token::eString)
|
||||
out << " type=\"string\" strlen=\"" << Token::getStrLength(tok) << '\"';
|
||||
else if (tok->tokType() == Token::eChar)
|
||||
|
@ -4962,16 +4962,18 @@ void Tokenizer::dump(std::ostream &out) const
|
|||
else if (tok->isOp()) {
|
||||
out << " type=\"op\"";
|
||||
if (tok->isArithmeticalOp())
|
||||
out << " isArithmeticalOp=\"True\"";
|
||||
out << " isArithmeticalOp=\"true\"";
|
||||
else if (tok->isAssignmentOp())
|
||||
out << " isAssignmentOp=\"True\"";
|
||||
out << " isAssignmentOp=\"true\"";
|
||||
else if (tok->isComparisonOp())
|
||||
out << " isComparisonOp=\"True\"";
|
||||
out << " isComparisonOp=\"true\"";
|
||||
else if (tok->tokType() == Token::eLogicalOp)
|
||||
out << " isLogicalOp=\"True\"";
|
||||
out << " isLogicalOp=\"true\"";
|
||||
}
|
||||
if (tok->isExpandedMacro())
|
||||
out << " isExpandedMacro=\"True\"";
|
||||
out << " isExpandedMacro=\"true\"";
|
||||
if (tok->isSplittedVarDecl())
|
||||
out << " isSplittedVarDecl=\"true\"";
|
||||
if (tok->link())
|
||||
out << " link=\"" << tok->link() << '\"';
|
||||
if (tok->varId() > 0)
|
||||
|
@ -6855,6 +6857,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
|
|||
|
||||
if (tok2->str() == ",") {
|
||||
tok2->str(";");
|
||||
tok2->isSplittedVarDecl(true);
|
||||
//TODO: should we have to add also template '<>' links?
|
||||
TokenList::insertTokens(tok2, type0, typelen);
|
||||
}
|
||||
|
@ -10268,7 +10271,7 @@ void Tokenizer::simplifyCPPAttribute()
|
|||
Token* head = tok->tokAt(5);
|
||||
while (isCPPAttribute(head))
|
||||
head = head->tokAt(5);
|
||||
head->isMaybeUnused(true);
|
||||
head->isAttributeMaybeUnused(true);
|
||||
} else if (Token::Match(tok->previous(), ") [ [ expects|ensures|assert default|audit|axiom| : %name% <|<=|>|>= %num% ] ]")) {
|
||||
const Token *vartok = tok->tokAt(4);
|
||||
if (vartok->str() == ":")
|
||||
|
|
Loading…
Reference in New Issue