From e6ee29fd11bcdee99260c880c7c305165dc8a2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 8 Jan 2020 12:29:54 +0100 Subject: [PATCH] Clang import; BreakStmt, ContinueStmt --- lib/clangastdump.cpp | 6 ++++++ test/testclangastdump.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/clangastdump.cpp b/lib/clangastdump.cpp index 3733b2de6..ed6e3debf 100644 --- a/lib/clangastdump.cpp +++ b/lib/clangastdump.cpp @@ -28,8 +28,10 @@ static const std::string ArraySubscriptExpr = "ArraySubscriptExpr"; static const std::string BinaryOperator = "BinaryOperator"; +static const std::string BreakStmt = "BreakStmt"; static const std::string CallExpr = "CallExpr"; static const std::string CompoundStmt = "CompoundStmt"; +static const std::string ContinueStmt = "ContinueStmt"; static const std::string DeclRefExpr = "DeclRefExpr"; static const std::string DeclStmt = "DeclStmt"; static const std::string FieldDecl = "FieldDecl"; @@ -296,6 +298,8 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList) binop->astOperand2(tok2); return binop; } + if (nodeType == BreakStmt) + return addtoken(tokenList, "break"); if (nodeType == CallExpr) { Token *f = children[0]->createTokens(tokenList); Token *par1 = addtoken(tokenList, "("); @@ -322,6 +326,8 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList) } return nullptr; } + if (nodeType == ContinueStmt) + return addtoken(tokenList, "continue"); if (nodeType == DeclStmt) return children[0]->createTokens(tokenList); if (nodeType == DeclRefExpr) { diff --git a/test/testclangastdump.cpp b/test/testclangastdump.cpp index 4e279adae..5bde68134 100644 --- a/test/testclangastdump.cpp +++ b/test/testclangastdump.cpp @@ -29,6 +29,8 @@ public: private: void run() OVERRIDE { + TEST_CASE(breakStmt); + TEST_CASE(continueStmt); TEST_CASE(forStmt); TEST_CASE(funcdecl1); TEST_CASE(funcdecl2); @@ -37,6 +39,7 @@ private: TEST_CASE(recordDecl); TEST_CASE(vardecl1); TEST_CASE(vardecl2); + TEST_CASE(vardecl3); TEST_CASE(whileStmt); } @@ -48,6 +51,26 @@ private: return tokenizer.tokens()->stringifyList(true, false, false, true, false); } + void breakStmt() { + const char clang[] = "`-FunctionDecl 0x2c31b18 <1.c:1:1, col:34> col:6 foo 'void ()'\n" + " `-CompoundStmt 0x2c31c40 \n" + " `-WhileStmt 0x2c31c20 \n" + " |-<<>>\n" + " |-IntegerLiteral 0x2c31bf8 'int' 0\n" + " `-BreakStmt 0x3687c18 "; + ASSERT_EQUALS("void foo ( ) { while ( 0 ) { break ; } ; }", parse(clang)); + } + + void continueStmt() { + const char clang[] = "`-FunctionDecl 0x2c31b18 <1.c:1:1, col:34> col:6 foo 'void ()'\n" + " `-CompoundStmt 0x2c31c40 \n" + " `-WhileStmt 0x2c31c20 \n" + " |-<<>>\n" + " |-IntegerLiteral 0x2c31bf8 'int' 0\n" + " `-ContinueStmt 0x2c31c18 "; + ASSERT_EQUALS("void foo ( ) { while ( 0 ) { continue ; } ; }", parse(clang)); + } + void forStmt() { const char clang[] = "`-FunctionDecl 0x2f93ae0 <1.c:1:1, col:56> col:5 main 'int ()'\n" " `-CompoundStmt 0x2f93dc0 \n" @@ -167,6 +190,11 @@ private: parse(clang)); } + void vardecl3() { + const char clang[] = "`-VarDecl 0x25a8aa0 <1.c:1:1, col:12> col:12 p 'const int *'"; + ASSERT_EQUALS("const int * p@1 ;", parse(clang)); + } + void whileStmt() { const char clang[] = "`-FunctionDecl 0x3d45b18 <1.c:1:1, line:3:1> line:1:6 foo 'void ()'\n" " `-CompoundStmt 0x3d45c48 \n"