Clang import; InitListExpr
This commit is contained in:
parent
7a2c10f9f1
commit
066e43cce3
|
@ -56,6 +56,7 @@ static const std::string FunctionDecl = "FunctionDecl";
|
|||
static const std::string FunctionTemplateDecl = "FunctionTemplateDecl";
|
||||
static const std::string IfStmt = "IfStmt";
|
||||
static const std::string ImplicitCastExpr = "ImplicitCastExpr";
|
||||
static const std::string InitListExpr = "InitListExpr";
|
||||
static const std::string IntegerLiteral = "IntegerLiteral";
|
||||
static const std::string MemberExpr = "MemberExpr";
|
||||
static const std::string NamespaceDecl = "NamespaceDecl";
|
||||
|
@ -387,7 +388,7 @@ const Scope *clangimport::AstNode::getNestedInScope(TokenList *tokenList)
|
|||
{
|
||||
if (!tokenList->back())
|
||||
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();
|
||||
}
|
||||
|
@ -652,6 +653,21 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
|
|||
setValueType(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)
|
||||
return addtoken(tokenList, mExtTokens.back());
|
||||
if (nodeType == NullStmt)
|
||||
|
|
|
@ -57,6 +57,7 @@ private:
|
|||
TEST_CASE(funcdecl4);
|
||||
TEST_CASE(functionTemplateDecl1);
|
||||
TEST_CASE(functionTemplateDecl2);
|
||||
TEST_CASE(initListExpr);
|
||||
TEST_CASE(ifelse);
|
||||
TEST_CASE(memberExpr);
|
||||
TEST_CASE(namespaceDecl);
|
||||
|
@ -429,6 +430,15 @@ private:
|
|||
"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() {
|
||||
// C code:
|
||||
// struct S { int x };
|
||||
|
|
Loading…
Reference in New Issue