Clang import; fixed ast for function call with multiple arguments

This commit is contained in:
Daniel Marjamäki 2020-10-09 07:54:16 +02:00
parent 65721dd7a9
commit 586ddf74f1
3 changed files with 10 additions and 7 deletions

View File

@ -1038,23 +1038,25 @@ Token * clangimport::AstNode::createTokensCall(TokenList *tokenList)
firstParam = 1;
f = children[0]->createTokens(tokenList);
}
f->setValueType(nullptr);
Token *par1 = addtoken(tokenList, "(");
par1->astOperand1(f);
Token *parent = par1;
int args = 0;
while (args < children.size() && children[args]->nodeType != CXXDefaultArgExpr)
args++;
Token *child = nullptr;
for (int c = firstParam; c < args; ++c) {
if (c + 1 < args) {
Token *child = children[c]->createTokens(tokenList);
if (child) {
Token *comma = addtoken(tokenList, ",");
comma->setValueType(nullptr);
comma->astOperand1(child);
parent->astOperand2(comma);
parent = comma;
comma->astOperand2(children[c]->createTokens(tokenList));
child = comma;
} else {
parent->astOperand2(children[c]->createTokens(tokenList));
child = children[c]->createTokens(tokenList);
}
}
par1->astOperand2(child);
Token *par2 = addtoken(tokenList, ")");
par1->link(par2);
par2->link(par1);

View File

@ -1560,7 +1560,7 @@ void Token::astStringVerboseRecursive(std::string& ret, const nonneg int indent1
ret += " \'" + mImpl->mValueType->str() + '\'';
if (function()) {
std::ostringstream ostr;
ostr << "0x" << std::hex << function();
ostr << std::hex << function();
ret += " f:" + ostr.str();
}
ret += '\n';

View File

@ -93,6 +93,7 @@ def test_ast_control_flow():
check_ast('void foo(int x) { if (x > 5){} }')
check_ast('int dostuff() { for (int x = 0; x < 10; x++); }')
check_ast('void foo(int x) { switch (x) {case 1: break; } }')
check_ast('void foo(int a, int b, int c) { foo(a,b,c); }')