From 7fecc17707fe5e485a13c9a9655bcb4dc46e2552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 21 Jan 2020 11:16:22 +0100 Subject: [PATCH] Clang import; CXXThrowExpr --- lib/clangimport.cpp | 6 ++++++ test/testclangimport.cpp | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 9a56bc03a..c3f41624b 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -53,6 +53,7 @@ static const std::string CXXRecordDecl = "CXXRecordDecl"; static const std::string CXXStaticCastExpr = "CXXStaticCastExpr"; static const std::string CXXTemporaryObjectExpr = "CXXTemporaryObjectExpr"; static const std::string CXXThisExpr = "CXXThisExpr"; +static const std::string CXXThrowExpr = "CXXThrowExpr"; static const std::string DeclRefExpr = "DeclRefExpr"; static const std::string DeclStmt = "DeclStmt"; static const std::string DoStmt = "DoStmt"; @@ -659,6 +660,11 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) return children[0]->createTokens(tokenList); if (nodeType == CXXThisExpr) return addtoken(tokenList, "this"); + if (nodeType == CXXThrowExpr) { + Token *t = addtoken(tokenList, "throw"); + t->astOperand1(children[0]->createTokens(tokenList)); + return t; + } if (nodeType == DeclRefExpr) { const std::string addr = mExtTokens[mExtTokens.size() - 3]; std::string name = unquote(getSpelling()); diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index cf621f05d..3304a1403 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -53,6 +53,7 @@ private: TEST_CASE(cxxRecordDecl1); TEST_CASE(cxxStaticCastExpr1); TEST_CASE(cxxStaticCastExpr2); + TEST_CASE(cxxThrowExpr); TEST_CASE(doStmt); TEST_CASE(forStmt); TEST_CASE(funcdecl1); @@ -409,6 +410,14 @@ private: ASSERT_EQUALS("int a@1 = static_cast,structLibrary::AllocFunc>>&&> ( ) ;", parse(clang)); } + void cxxThrowExpr() { + const char clang[] = "`-FunctionDecl 0x3701690 <1.cpp:2:1, col:23> col:6 foo 'void ()'\n" + " `-CompoundStmt 0x37017b0 \n" + " `-CXXThrowExpr 0x3701790 'void'\n" + " `-IntegerLiteral 0x3701770 'int' 1"; + ASSERT_EQUALS("void foo ( ) { throw 1 ; }", parse(clang)); + } + void doStmt() { const char clang[] = "`-FunctionDecl 0x27fbbc8 col:6 foo 'void ()'\n" " `-CompoundStmt 0x27fbd08 \n"