Clang import: handle DefaultStmt

This commit is contained in:
Daniel Marjamäki 2020-10-29 09:48:35 +01:00
parent 40156365b8
commit 16f4f198eb
2 changed files with 22 additions and 0 deletions

View File

@ -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());

View File

@ -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:9, col:13> col:13 used rc 'int'\n"
" `-CompoundStmt 0x1847868 <line:4:1, line:9:1>\n"
" `-SwitchStmt 0x18477e0 <line:5:3, line:8:3>\n"
" |-ImplicitCastExpr 0x18477c8 <line:5:10> 'int' <LValueToRValue>\n"
" | `-DeclRefExpr 0x18477a8 <col:10> 'int' lvalue ParmVar 0x18475e0 'rc' 'int'\n"
" `-CompoundStmt 0x1847850 <col:14, line:8:3>\n"
" `-DefaultStmt 0x1847830 <line:6:3, line:7:12>\n"
" `-ReturnStmt 0x1847820 <col:5, col:12>\n"
" `-IntegerLiteral 0x1847800 <col:12> '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 <line:2:1, col:34> col:6 foo 'void ()'\n"
" `-CompoundStmt 0x27fbd08 <col:12, col:34>\n"