From 16f4f198eb30d1ad4a8bd298339f51ec7df627a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 29 Oct 2020 09:48:35 +0100 Subject: [PATCH] Clang import: handle DefaultStmt --- lib/clangimport.cpp | 7 +++++++ test/testclangimport.cpp | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index d10646ed7..27ef5aaf0 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -63,6 +63,7 @@ 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 DefaultStmt = "DefaultStmt"; static const std::string DoStmt = "DoStmt"; static const std::string EnumConstantDecl = "EnumConstantDecl"; static const std::string EnumDecl = "EnumDecl"; @@ -747,6 +748,12 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) } if (nodeType == DeclStmt) return children[0]->createTokens(tokenList); + if (nodeType == DefaultStmt) { + addtoken(tokenList, "default"); + addtoken(tokenList, ":"); + children.back()->createTokens(tokenList); + return nullptr; + } if (nodeType == DoStmt) { addtoken(tokenList, "do"); createScope(tokenList, Scope::ScopeType::eDo, children[0], tokenList->back()); diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 99fadaf1b..453ac8593 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -63,6 +63,7 @@ private: TEST_CASE(cxxStaticCastExpr2); TEST_CASE(cxxStdInitializerListExpr); TEST_CASE(cxxThrowExpr); + TEST_CASE(defaultStmt); TEST_CASE(doStmt); TEST_CASE(enumDecl); TEST_CASE(forStmt); @@ -577,6 +578,20 @@ private: ASSERT_EQUALS("void foo ( ) { throw 1 ; }", parse(clang)); } + void defaultStmt() { + const char clang[] = "`-FunctionDecl 0x18476b8 <1.c:3:1, line:9:1> line:3:5 foo 'int (int)'\n" + " |-ParmVarDecl 0x18475e0 col:13 used rc 'int'\n" + " `-CompoundStmt 0x1847868 \n" + " `-SwitchStmt 0x18477e0 \n" + " |-ImplicitCastExpr 0x18477c8 'int' \n" + " | `-DeclRefExpr 0x18477a8 'int' lvalue ParmVar 0x18475e0 'rc' 'int'\n" + " `-CompoundStmt 0x1847850 \n" + " `-DefaultStmt 0x1847830 \n" + " `-ReturnStmt 0x1847820 \n" + " `-IntegerLiteral 0x1847800 'int' 1"; + ASSERT_EQUALS("int foo ( int rc@1 ) {\n\nswitch ( rc@1 ) {\ndefault : return 1 ; } }", parse(clang)); + } + void doStmt() { const char clang[] = "`-FunctionDecl 0x27fbbc8 col:6 foo 'void ()'\n" " `-CompoundStmt 0x27fbd08 \n"