Skip to content

Commit 7969bf7

Browse files
committed
Token: Add 'isSplittedVarDecl attribute
1 parent c7aed8b commit 7969bf7

4 files changed

Lines changed: 44 additions & 30 deletions

File tree

addons/cppcheckdata.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class Token:
137137
isUnsigned Is this token a unsigned type
138138
isSigned Is this token a signed type
139139
isExpandedMacro Is this token a expanded macro token
140+
isSplittedVarDecl Is this token a splitted variable declaration. "int a,b; => int a; int b;"
140141
varId varId for token, each variable has a unique non-zero id
141142
variable Variable information for this token. See the Variable class.
142143
function If this token points at a function call, this attribute has the Function
@@ -185,6 +186,7 @@ class Token:
185186
isUnsigned = False
186187
isSigned = False
187188
isExpandedMacro = False
189+
isSplittedVarDecl = False
188190
varId = None
189191
variableId = None
190192
variable = None
@@ -245,6 +247,8 @@ def __init__(self, element):
245247
self.isLogicalOp = True
246248
if element.get('isExpandedMacro'):
247249
self.isExpandedMacro = True
250+
if element.get('isSplittedVarDecl'):
251+
self.isExpandedMacro = True
248252
self.linkId = element.get('link')
249253
self.link = None
250254
if element.get('varId'):
@@ -275,10 +279,10 @@ def __repr__(self):
275279
attrs = ["Id", "str", "scopeId", "isName", "isUnsigned", "isSigned",
276280
"isNumber", "isInt", "isFloat", "isString", "strlen",
277281
"isChar", "isOp", "isArithmeticalOp", "isComparisonOp",
278-
"isLogicalOp", "isExpandedMacro", "linkId", "varId",
279-
"variableId", "functionId", "valuesId", "valueType",
280-
"typeScopeId", "astParentId", "astOperand1Id", "file",
281-
"linenr", "column"]
282+
"isLogicalOp", "isExpandedMacro", "isSplittedVarDecl",
283+
"linkId", "varId", "variableId", "functionId", "valuesId",
284+
"valueType", "typeScopeId", "astParentId", "astOperand1Id",
285+
"file", "linenr", "column"]
282286
return "{}({})".format(
283287
"Token",
284288
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ void Variable::evaluate(const Settings* settings)
19391939
setFlag(fIsReference, true); // Set also fIsReference
19401940
}
19411941

1942-
if (tok->isMaybeUnused()) {
1942+
if (tok->isAttributeMaybeUnused()) {
19431943
setFlag(fIsMaybeUnused, true);
19441944
}
19451945

lib/token.h

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,11 @@ class CPPCHECKLIB Token {
549549
void isAttributeNodiscard(const bool value) {
550550
setFlag(fIsAttributeNodiscard, value);
551551
}
552-
bool isMaybeUnused() const {
553-
return getFlag(fIsMaybeUnused);
552+
bool isAttributeMaybeUnused() const {
553+
return getFlag(fIsAttributeMaybeUnused);
554554
}
555-
void isMaybeUnused(const bool value) {
556-
setFlag(fIsMaybeUnused, value);
555+
void isAttributeMaybeUnused(const bool value) {
556+
setFlag(fIsAttributeMaybeUnused, value);
557557
}
558558
void setCppcheckAttribute(TokenImpl::CppcheckAttributes::Type type, MathLib::bigint value) {
559559
mImpl->setCppcheckAttribute(type, value);
@@ -612,6 +612,12 @@ class CPPCHECKLIB Token {
612612
setFlag(fExternC, b);
613613
}
614614

615+
bool isSplittedVarDecl() const {
616+
return getFlag(fIsSplitVarDecl);
617+
}
618+
void isSplittedVarDecl(bool b) {
619+
setFlag(fIsSplitVarDecl, b);
620+
}
615621

616622
bool isBitfield() const {
617623
return mImpl->mBits > 0;
@@ -1182,19 +1188,20 @@ class CPPCHECKLIB Token {
11821188
fIsAttributeNothrow = (1 << 13), // __attribute__((nothrow)), __declspec(nothrow)
11831189
fIsAttributeUsed = (1 << 14), // __attribute__((used))
11841190
fIsAttributePacked = (1 << 15), // __attribute__((packed))
1185-
fIsControlFlowKeyword = (1 << 16), // if/switch/while/...
1186-
fIsOperatorKeyword = (1 << 17), // operator=, etc
1187-
fIsComplex = (1 << 18), // complex/_Complex type
1188-
fIsEnumType = (1 << 19), // enumeration type
1189-
fIsName = (1 << 20),
1190-
fIsLiteral = (1 << 21),
1191-
fIsTemplateArg = (1 << 22),
1192-
fIsAttributeNodiscard = (1 << 23), // __attribute__ ((warn_unused_result)), [[nodiscard]]
1193-
fAtAddress = (1 << 24), // @ 0x4000
1194-
fIncompleteVar = (1 << 25),
1195-
fConstexpr = (1 << 26),
1196-
fExternC = (1 << 27),
1197-
fIsMaybeUnused = (1 << 28), // [[maybe_unsed]]
1191+
fIsAttributeMaybeUnused = (1 << 16), // [[maybe_unsed]]
1192+
fIsControlFlowKeyword = (1 << 17), // if/switch/while/...
1193+
fIsOperatorKeyword = (1 << 18), // operator=, etc
1194+
fIsComplex = (1 << 19), // complex/_Complex type
1195+
fIsEnumType = (1 << 20), // enumeration type
1196+
fIsName = (1 << 21),
1197+
fIsLiteral = (1 << 22),
1198+
fIsTemplateArg = (1 << 23),
1199+
fIsAttributeNodiscard = (1 << 24), // __attribute__ ((warn_unused_result)), [[nodiscard]]
1200+
fAtAddress = (1 << 25), // @ 0x4000
1201+
fIncompleteVar = (1 << 26),
1202+
fConstexpr = (1 << 27),
1203+
fExternC = (1 << 28),
1204+
fIsSplitVarDecl = (1 << 29), // int a,b; <-- vardecl is split up
11981205
};
11991206

12001207
Token::Type mTokType;

lib/tokenize.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4950,9 +4950,9 @@ void Tokenizer::dump(std::ostream &out) const
49504950
} else if (tok->isNumber()) {
49514951
out << " type=\"number\"";
49524952
if (MathLib::isInt(tok->str()))
4953-
out << " isInt=\"True\"";
4953+
out << " isInt=\"true\"";
49544954
if (MathLib::isFloat(tok->str()))
4955-
out << " isFloat=\"True\"";
4955+
out << " isFloat=\"true\"";
49564956
} else if (tok->tokType() == Token::eString)
49574957
out << " type=\"string\" strlen=\"" << Token::getStrLength(tok) << '\"';
49584958
else if (tok->tokType() == Token::eChar)
@@ -4962,16 +4962,18 @@ void Tokenizer::dump(std::ostream &out) const
49624962
else if (tok->isOp()) {
49634963
out << " type=\"op\"";
49644964
if (tok->isArithmeticalOp())
4965-
out << " isArithmeticalOp=\"True\"";
4965+
out << " isArithmeticalOp=\"true\"";
49664966
else if (tok->isAssignmentOp())
4967-
out << " isAssignmentOp=\"True\"";
4967+
out << " isAssignmentOp=\"true\"";
49684968
else if (tok->isComparisonOp())
4969-
out << " isComparisonOp=\"True\"";
4969+
out << " isComparisonOp=\"true\"";
49704970
else if (tok->tokType() == Token::eLogicalOp)
4971-
out << " isLogicalOp=\"True\"";
4971+
out << " isLogicalOp=\"true\"";
49724972
}
49734973
if (tok->isExpandedMacro())
4974-
out << " isExpandedMacro=\"True\"";
4974+
out << " isExpandedMacro=\"true\"";
4975+
if (tok->isSplittedVarDecl())
4976+
out << " isSplittedVarDecl=\"true\"";
49754977
if (tok->link())
49764978
out << " link=\"" << tok->link() << '\"';
49774979
if (tok->varId() > 0)
@@ -6855,6 +6857,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
68556857

68566858
if (tok2->str() == ",") {
68576859
tok2->str(";");
6860+
tok2->isSplittedVarDecl(true);
68586861
//TODO: should we have to add also template '<>' links?
68596862
TokenList::insertTokens(tok2, type0, typelen);
68606863
}
@@ -10268,7 +10271,7 @@ void Tokenizer::simplifyCPPAttribute()
1026810271
Token* head = tok->tokAt(5);
1026910272
while (isCPPAttribute(head))
1027010273
head = head->tokAt(5);
10271-
head->isMaybeUnused(true);
10274+
head->isAttributeMaybeUnused(true);
1027210275
} else if (Token::Match(tok->previous(), ") [ [ expects|ensures|assert default|audit|axiom| : %name% <|<=|>|>= %num% ] ]")) {
1027310276
const Token *vartok = tok->tokAt(4);
1027410277
if (vartok->str() == ":")

0 commit comments

Comments
 (0)