diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 50fc3cab4..f4a23843f 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -51,6 +51,7 @@ static const std::string CXXStaticCastExpr = "CXXStaticCastExpr"; static const std::string CXXThisExpr = "CXXThisExpr"; static const std::string DeclRefExpr = "DeclRefExpr"; static const std::string DeclStmt = "DeclStmt"; +static const std::string DoStmt = "DoStmt"; static const std::string ExprWithCleanups = "ExprWithCleanups"; static const std::string FieldDecl = "FieldDecl"; static const std::string FloatingLiteral = "FloatingLiteral"; @@ -646,6 +647,19 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) } if (nodeType == DeclStmt) return children[0]->createTokens(tokenList); + if (nodeType == DoStmt) { + addtoken(tokenList, "do"); + createScope(tokenList, Scope::ScopeType::eDo, children[0]); + Token *tok1 = addtoken(tokenList, "while"); + Token *par1 = addtoken(tokenList, "("); + Token *expr = children[1]->createTokens(tokenList); + Token *par2 = addtoken(tokenList, ")"); + par1->link(par2); + par2->link(par1); + par1->astOperand1(tok1); + par1->astOperand2(expr); + return nullptr; + } if (nodeType == ExprWithCleanups) return children[0]->createTokens(tokenList); if (nodeType == FieldDecl) diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index b1c4d2652..5491b5f79 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -52,6 +52,7 @@ private: TEST_CASE(cxxRecordDecl1); TEST_CASE(cxxStaticCastExpr1); TEST_CASE(cxxStaticCastExpr2); + TEST_CASE(doStmt); TEST_CASE(forStmt); TEST_CASE(funcdecl1); TEST_CASE(funcdecl2); @@ -395,6 +396,17 @@ private: ASSERT_EQUALS("int a@1 = static_cast,structLibrary::AllocFunc>>&&> ( ) ;", parse(clang)); } + void doStmt() { + const char clang[] = "`-FunctionDecl 0x27fbbc8 col:6 foo 'void ()'\n" + " `-CompoundStmt 0x27fbd08 \n" + " `-DoStmt 0x27fbce8 \n" + " |-CompoundStmt 0x27fbcb0 \n" + " | `-UnaryOperator 0x27fbc90 'int' postfix '++'\n" + " | `-DeclRefExpr 0x27fbc68 'int' lvalue Var 0x27fbae0 'x' 'int'\n" + " `-IntegerLiteral 0x27fbcc8 'int' 1"; + ASSERT_EQUALS("void foo ( ) { do { ++ x ; } while ( 1 ) ; }", parse(clang)); + } + void forStmt() { const char clang[] = "`-FunctionDecl 0x2f93ae0 <1.c:1:1, col:56> col:5 main 'int ()'\n" " `-CompoundStmt 0x2f93dc0 \n"