Clang import; BreakStmt, ContinueStmt

This commit is contained in:
Daniel Marjamäki 2020-01-08 12:29:54 +01:00
parent ea414e46e1
commit e6ee29fd11
2 changed files with 34 additions and 0 deletions

View File

@ -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) {

View File

@ -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 <col:12, col:34>\n"
" `-WhileStmt 0x2c31c20 <col:14, col:24>\n"
" |-<<<NULL>>>\n"
" |-IntegerLiteral 0x2c31bf8 <col:21> 'int' 0\n"
" `-BreakStmt 0x3687c18 <col:24>";
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 <col:12, col:34>\n"
" `-WhileStmt 0x2c31c20 <col:14, col:24>\n"
" |-<<<NULL>>>\n"
" |-IntegerLiteral 0x2c31bf8 <col:21> 'int' 0\n"
" `-ContinueStmt 0x2c31c18 <col:24>";
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 <col:12, col:56>\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 <col:12, line:3:1>\n"