Clang import; else
This commit is contained in:
parent
b829c4cebb
commit
c4131bbc5b
|
@ -233,12 +233,12 @@ Scope *clangastdump::AstNode::createScope(TokenList *tokenList, Scope::ScopeType
|
|||
symbolDatabase->scopeList.push_back(Scope(nullptr, nullptr, nestedIn));
|
||||
Scope *scope = &symbolDatabase->scopeList.back();
|
||||
scope->type = scopeType;
|
||||
Token *bodyStart = addtoken(tokenList, "{");
|
||||
Token *bodyStart = astNode->addtoken(tokenList, "{");
|
||||
tokenList->back()->scope(scope);
|
||||
astNode->createTokens(tokenList);
|
||||
if (tokenList->back()->str() != ";")
|
||||
addtoken(tokenList, ";");
|
||||
Token *bodyEnd = addtoken(tokenList, "}");
|
||||
if (!Token::Match(tokenList->back(), "[;{}]"))
|
||||
astNode->addtoken(tokenList, ";");
|
||||
Token *bodyEnd = astNode->addtoken(tokenList, "}");
|
||||
bodyStart->link(bodyEnd);
|
||||
scope->bodyStart = bodyStart;
|
||||
scope->bodyEnd = bodyEnd;
|
||||
|
@ -345,6 +345,7 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
|
|||
if (nodeType == IfStmt) {
|
||||
AstNode *cond = children[2].get();
|
||||
AstNode *then = children[3].get();
|
||||
AstNode *else_ = children[4].get();
|
||||
Token *iftok = addtoken(tokenList, "if");
|
||||
Token *par1 = addtoken(tokenList, "(");
|
||||
par1->astOperand1(iftok);
|
||||
|
@ -352,6 +353,10 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
|
|||
Token *par2 = addtoken(tokenList, ")");
|
||||
par1->link(par2);
|
||||
createScope(tokenList, Scope::ScopeType::eIf, then);
|
||||
if (else_) {
|
||||
else_->addtoken(tokenList, "else");
|
||||
createScope(tokenList, Scope::ScopeType::eElse, else_);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
if (nodeType == ImplicitCastExpr)
|
||||
|
|
|
@ -31,6 +31,7 @@ private:
|
|||
void run() OVERRIDE {
|
||||
TEST_CASE(funcdecl1);
|
||||
TEST_CASE(funcdecl2);
|
||||
TEST_CASE(ifelse);
|
||||
TEST_CASE(vardecl1);
|
||||
TEST_CASE(vardecl2);
|
||||
}
|
||||
|
@ -66,6 +67,24 @@ private:
|
|||
"return x@1 / y@2 ; }", parse(clang));
|
||||
}
|
||||
|
||||
void ifelse() {
|
||||
const char clang[] = "`-FunctionDecl 0x2637ba8 <1.c:1:1, line:4:1> line:1:5 foo 'int (int)'\n"
|
||||
" |-ParmVarDecl 0x2637ae0 <col:9, col:13> col:13 used x 'int'\n"
|
||||
" `-CompoundStmt 0x2637d70 <col:16, line:4:1>\n"
|
||||
" `-IfStmt 0x2637d38 <line:2:5, line:3:11>\n"
|
||||
" |-<<<NULL>>>\n"
|
||||
" |-<<<NULL>>>\n"
|
||||
" |-BinaryOperator 0x2637cf0 <line:2:9, col:13> 'int' '>'\n"
|
||||
" | |-ImplicitCastExpr 0x2637cd8 <col:9> 'int' <LValueToRValue>\n"
|
||||
" | | `-DeclRefExpr 0x2637c90 <col:9> 'int' lvalue ParmVar 0x2637ae0 'x' 'int'\n"
|
||||
" | `-IntegerLiteral 0x2637cb8 <col:13> 'int' 10\n"
|
||||
" |-CompoundStmt 0x2637d18 <col:17, col:18>\n"
|
||||
" `-CompoundStmt 0x2637d28 <line:3:10, col:11>";
|
||||
ASSERT_EQUALS("int foo ( int x@1 ) {\n"
|
||||
"if ( x@1 > 10 ) { }\n"
|
||||
"else { } ; }", parse(clang));
|
||||
}
|
||||
|
||||
void vardecl1() {
|
||||
const char clang[] = "|-VarDecl 0x32b8aa0 <1.c:1:1, col:9> col:5 used a 'int' cinit\n"
|
||||
"| `-IntegerLiteral 0x32b8b40 <col:9> 'int' 1\n"
|
||||
|
|
Loading…
Reference in New Issue