Clang import; InitListExpr

This commit is contained in:
Daniel Marjamäki 2020-01-13 12:44:11 +01:00
parent 7a2c10f9f1
commit 066e43cce3
2 changed files with 27 additions and 1 deletions

View File

@ -56,6 +56,7 @@ static const std::string FunctionDecl = "FunctionDecl";
static const std::string FunctionTemplateDecl = "FunctionTemplateDecl"; static const std::string FunctionTemplateDecl = "FunctionTemplateDecl";
static const std::string IfStmt = "IfStmt"; static const std::string IfStmt = "IfStmt";
static const std::string ImplicitCastExpr = "ImplicitCastExpr"; static const std::string ImplicitCastExpr = "ImplicitCastExpr";
static const std::string InitListExpr = "InitListExpr";
static const std::string IntegerLiteral = "IntegerLiteral"; static const std::string IntegerLiteral = "IntegerLiteral";
static const std::string MemberExpr = "MemberExpr"; static const std::string MemberExpr = "MemberExpr";
static const std::string NamespaceDecl = "NamespaceDecl"; static const std::string NamespaceDecl = "NamespaceDecl";
@ -387,7 +388,7 @@ const Scope *clangimport::AstNode::getNestedInScope(TokenList *tokenList)
{ {
if (!tokenList->back()) if (!tokenList->back())
return &mData->mSymbolDatabase->scopeList.front(); return &mData->mSymbolDatabase->scopeList.front();
if (tokenList->back()->str() == "}") if (tokenList->back()->str() == "}" && !tokenList->back()->link()->astParent())
return tokenList->back()->scope()->nestedIn; return tokenList->back()->scope()->nestedIn;
return tokenList->back()->scope(); return tokenList->back()->scope();
} }
@ -652,6 +653,21 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
setValueType(expr); setValueType(expr);
return expr; return expr;
} }
if (nodeType == InitListExpr) {
const Scope *scope = tokenList->back()->scope();
Token *start = addtoken(tokenList, "{");
start->scope(scope);
for (AstNodePtr child: children) {
if (tokenList->back()->str() != "{")
addtoken(tokenList, ",");
child->createTokens(tokenList);
}
Token *end = addtoken(tokenList, "}");
end->scope(scope);
start->link(end);
end->link(start);
return start;
}
if (nodeType == IntegerLiteral) if (nodeType == IntegerLiteral)
return addtoken(tokenList, mExtTokens.back()); return addtoken(tokenList, mExtTokens.back());
if (nodeType == NullStmt) if (nodeType == NullStmt)

View File

@ -57,6 +57,7 @@ private:
TEST_CASE(funcdecl4); TEST_CASE(funcdecl4);
TEST_CASE(functionTemplateDecl1); TEST_CASE(functionTemplateDecl1);
TEST_CASE(functionTemplateDecl2); TEST_CASE(functionTemplateDecl2);
TEST_CASE(initListExpr);
TEST_CASE(ifelse); TEST_CASE(ifelse);
TEST_CASE(memberExpr); TEST_CASE(memberExpr);
TEST_CASE(namespaceDecl); TEST_CASE(namespaceDecl);
@ -429,6 +430,15 @@ private:
"else { } }", parse(clang)); "else { } }", parse(clang));
} }
void initListExpr() {
const char clang[] = "|-VarDecl 0x397c680 <1.cpp:2:1, col:26> col:11 used ints 'const int [3]' cinit\n"
"| `-InitListExpr 0x397c7d8 <col:20, col:26> 'const int [3]'\n"
"| |-IntegerLiteral 0x397c720 <col:21> 'int' 1\n"
"| |-IntegerLiteral 0x397c740 <col:23> 'int' 2\n"
"| `-IntegerLiteral 0x397c760 <col:25> 'int' 3";
ASSERT_EQUALS("const int [3] ints@1 = { 1 , 2 , 3 } ;", parse(clang));
}
void memberExpr() { void memberExpr() {
// C code: // C code:
// struct S { int x }; // struct S { int x };