Skip to content

Commit 20ad92c

Browse files
committed
compound assignment
1 parent d24882d commit 20ad92c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/clangimport.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,11 @@ namespace clangimport {
414414

415415
std::string clangimport::AstNode::getSpelling() const
416416
{
417-
if (mJsonObject.count("name") == 0)
418-
return {};
419-
return mJsonObject.at("name").get<std::string>();
417+
if (mJsonObject.count("opcode") > 0)
418+
return mJsonObject.at("opcode").get<std::string>();
419+
if (mJsonObject.count("name") > 0)
420+
return mJsonObject.at("name").get<std::string>();
421+
return {};
420422
}
421423

422424
std::string clangimport::AstNode::getQualType() const
@@ -751,7 +753,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
751753
}
752754
if (mKind == BinaryOperator) {
753755
Token *tok1 = getChild(0)->createTokens(tokenList);
754-
Token *binop = addtoken(tokenList, mJsonObject.at("opcode").get<std::string>());
756+
Token *binop = addtoken(tokenList, getSpelling());
755757
Token *tok2 = children[1]->createTokens(tokenList);
756758
binop->astOperand1(tok1);
757759
binop->astOperand2(tok2);
@@ -1249,16 +1251,16 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList)
12491251
return addtoken(tokenList, getSpelling());
12501252
}
12511253
if (mKind == UnaryOperator) {
1252-
const std::string& opcode = mJsonObject.at("opcode").get<std::string>();
1254+
const std::string& spelling = getSpelling();
12531255
const bool postfix = mJsonObject.count("isPostfix") > 0 && mJsonObject.at("isPostfix").get<bool>();
12541256
if (postfix) {
12551257
Token* tok = getChild(0)->createTokens(tokenList);
1256-
Token *unaryOp = addtoken(tokenList, opcode);
1258+
Token *unaryOp = addtoken(tokenList, spelling);
12571259
setValueType(unaryOp);
12581260
unaryOp->astOperand1(tok);
12591261
return unaryOp;
12601262
} else {
1261-
Token *unaryOp = addtoken(tokenList, opcode);
1263+
Token *unaryOp = addtoken(tokenList, spelling);
12621264
setValueType(unaryOp);
12631265
unaryOp->astOperand1(getChild(0)->createTokens(tokenList));
12641266
return unaryOp;

test/cli/clang-import_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def test_tokens_function2(tmp_path):
364364
def test_tokens_function3(tmp_path):
365365
test_file = tmp_path / 'test.cpp'
366366
stdout = _run_cppcheck_debug(test_file, '\nint x; void foo(){ x |= 1 << 30; }')
367-
assert '2: int ...void foo ( int x@var1 , int y@var2 ) { }' in stdout
367+
assert '2: int x@var1 ; void foo ( ) { x@var1 |=@exprUNIQUE 1 <<@exprUNIQUE 30 ; }\n' in stdout
368368

369369
def test_tokens_for(tmp_path):
370370
test_file = tmp_path / 'test.cpp'

0 commit comments

Comments
 (0)