From ce77db2b1bfe0ba6fc0084622acfa7bee9dee004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 23 Jan 2020 16:06:25 +0100 Subject: [PATCH] Clang import; EnumDecl --- lib/clangimport.cpp | 17 +++++++++++++++++ test/testclangimport.cpp | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 6c9062a77..4addfd7c6 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -60,6 +60,8 @@ static const std::string CXXThrowExpr = "CXXThrowExpr"; static const std::string DeclRefExpr = "DeclRefExpr"; static const std::string DeclStmt = "DeclStmt"; static const std::string DoStmt = "DoStmt"; +static const std::string EnumConstantDecl = "EnumConstantDecl"; +static const std::string EnumDecl = "EnumDecl"; static const std::string ExprWithCleanups = "ExprWithCleanups"; static const std::string FieldDecl = "FieldDecl"; static const std::string FloatingLiteral = "FloatingLiteral"; @@ -714,6 +716,21 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) par1->astOperand2(expr); return nullptr; } + if (nodeType == EnumConstantDecl) + return addtoken(tokenList, getSpelling()); + if (nodeType == EnumDecl) { + Token *enumtok = addtoken(tokenList, "enum"); + if (mExtTokens[mExtTokens.size() - 3].compare(0,4,"col:") == 0) + addtoken(tokenList, mExtTokens.back()); + createScope(tokenList, Scope::ScopeType::eEnum, children, enumtok); + for (Token *tok = enumtok; tok; tok = tok->next()) { + if (Token::simpleMatch(tok, "; }")) + tok->deleteThis(); + else if (tok->str() == ";") + tok->str(","); + } + return nullptr; + } if (nodeType == ExprWithCleanups) return children[0]->createTokens(tokenList); if (nodeType == FieldDecl) diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 1851ebb14..b5e957e3a 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -59,6 +59,7 @@ private: TEST_CASE(cxxStdInitializerListExpr); TEST_CASE(cxxThrowExpr); TEST_CASE(doStmt); + TEST_CASE(enumDecl); TEST_CASE(forStmt); TEST_CASE(funcdecl1); TEST_CASE(funcdecl2); @@ -484,6 +485,14 @@ private: ASSERT_EQUALS("void foo ( ) { do { ++ x ; } while ( 1 ) ; }", parse(clang)); } + void enumDecl() { + const char clang[] = "`-EnumDecl 0x2660660 col:6 referenced abc\n" + " |-EnumConstantDecl 0x2660720 col:11 referenced a 'abc'\n" + " |-EnumConstantDecl 0x2660768 col:13 b 'abc'\n" + " `-EnumConstantDecl 0x26607b0 col:15 c 'abc'"; + ASSERT_EQUALS("enum abc { a , b , c }", parse(clang)); + } + void forStmt() { const char clang[] = "`-FunctionDecl 0x2f93ae0 <1.c:1:1, col:56> col:5 main 'int ()'\n" " `-CompoundStmt 0x2f93dc0 \n"