Clang import: fixed return type

This commit is contained in:
Daniel Marjamäki 2020-10-04 20:02:19 +02:00
parent e3ab688597
commit 67cc1776d5
3 changed files with 13 additions and 4 deletions

View File

@ -955,8 +955,10 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
} }
if (nodeType == ReturnStmt) { if (nodeType == ReturnStmt) {
Token *tok1 = addtoken(tokenList, "return"); Token *tok1 = addtoken(tokenList, "return");
if (!children.empty()) if (!children.empty()) {
children[0]->setValueType(tok1);
tok1->astOperand1(children[0]->createTokens(tokenList)); tok1->astOperand1(children[0]->createTokens(tokenList));
}
return tok1; return tok1;
} }
if (nodeType == StringLiteral) if (nodeType == StringLiteral)

View File

@ -5846,9 +5846,16 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
typestr += end->str(); typestr += end->str();
if (valuetype->fromLibraryType(typestr, settings)) if (valuetype->fromLibraryType(typestr, settings))
type = end; type = end;
} else if (ValueType::Type::UNKNOWN_TYPE != ValueType::typeFromString(type->str(), type->isLong())) } else if (ValueType::Type::UNKNOWN_TYPE != ValueType::typeFromString(type->str(), type->isLong())) {
ValueType::Type t0 = valuetype->type;
valuetype->type = ValueType::typeFromString(type->str(), type->isLong()); valuetype->type = ValueType::typeFromString(type->str(), type->isLong());
else if (type->str() == "auto") { if (t0 == ValueType::Type::LONG) {
if (valuetype->type == ValueType::Type::LONG)
valuetype->type = ValueType::Type::LONGLONG;
else if (valuetype->type == ValueType::Type::DOUBLE)
valuetype->type = ValueType::Type::LONGDOUBLE;
}
} else if (type->str() == "auto") {
const ValueType *vt = type->valueType(); const ValueType *vt = type->valueType();
if (!vt) if (!vt)
return nullptr; return nullptr;

View File

@ -84,7 +84,7 @@ def test2():
def test_ast_calculations(): def test_ast_calculations():
check_ast('int x = 5; int y = (x + 4) * 2;') check_ast('int x = 5; int y = (x + 4) * 2;')
todo_check_ast('int dostuff(int x) { return x ? 3 : 5; }') check_ast('long long dostuff(int x) { return x ? 3 : 5; }')
def test_ast_control_flow(): def test_ast_control_flow():
check_ast('void foo(int x) { if (x > 5){} }') check_ast('void foo(int x) { if (x > 5){} }')