From 9eb5f9ddfdb7ae7c002ef4f53e7fe42956a68401 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 13 Jun 2015 16:43:56 +0300 Subject: Add parsing node FOR_STMT. --- src/Makefile.files | 4 ++- src/includes/nodeincludes.h | 1 + src/includes/nodeshandling.inc | 1 + src/includes/parserdefines.inc | 1 + src/nodes/stmt/for_stmt.h | 46 ++++++++++++++++++++++++++++++++++ src/parsers/stmt/for_stmt.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/nodes/stmt/for_stmt.h create mode 100644 src/parsers/stmt/for_stmt.cpp diff --git a/src/Makefile.files b/src/Makefile.files index e056089..b492029 100644 --- a/src/Makefile.files +++ b/src/Makefile.files @@ -213,4 +213,6 @@ SRC = analysis/analysis.cpp \ nodes/expr/roundmod_expr.h \ parsers/expr/roundmod_expr.cpp \ nodes/expr/negate_expr.h \ - parsers/expr/negate_expr.cpp \ No newline at end of file + parsers/expr/negate_expr.cpp \ + nodes/stmt/for_stmt.h \ + parsers/stmt/for_stmt.cpp \ No newline at end of file diff --git a/src/includes/nodeincludes.h b/src/includes/nodeincludes.h index 2ebd342..3065288 100644 --- a/src/includes/nodeincludes.h +++ b/src/includes/nodeincludes.h @@ -86,3 +86,4 @@ #include "nodes/expr/ceilmod_expr.h" #include "nodes/expr/roundmod_expr.h" #include "nodes/expr/negate_expr.h" +#include "nodes/stmt/for_stmt.h" diff --git a/src/includes/nodeshandling.inc b/src/includes/nodeshandling.inc index e5904b0..e63cec2 100644 --- a/src/includes/nodeshandling.inc +++ b/src/includes/nodeshandling.inc @@ -85,3 +85,4 @@ handleNodeType(FLOOR_MOD_EXPR, FloorModExpr) handleNodeType(CEIL_MOD_EXPR, CeilModExpr) handleNodeType(ROUND_MOD_EXPR, RoundModExpr) handleNodeType(NEGATE_EXPR, NegateExpr) +handleNodeType(FOR_STMT, ForStmt) diff --git a/src/includes/parserdefines.inc b/src/includes/parserdefines.inc index 33ea1a0..a6ae523 100644 --- a/src/includes/parserdefines.inc +++ b/src/includes/parserdefines.inc @@ -85,3 +85,4 @@ parserDefine(FloorModExpr); parserDefine(CeilModExpr); parserDefine(RoundModExpr); parserDefine(NegateExpr); +parserDefine(ForStmt); diff --git a/src/nodes/stmt/for_stmt.h b/src/nodes/stmt/for_stmt.h new file mode 100644 index 0000000..e2e47a9 --- /dev/null +++ b/src/nodes/stmt/for_stmt.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2015 Andrei Karas + * + * This file is part of AstDumper. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NODES_STMT_FORSTMTNODE_H +#define NODES_STMT_FORSTMTNODE_H + +#include "nodes/base/stmt.h" + +#include "nodes/base/expr.h" + +#include + +struct ForStmtNode : public StmtNode +{ + ForStmtNode() : + StmtNode(), + body(nullptr), + condition(nullptr), + expression(nullptr), + init(nullptr) + { + } + + StmtNode *body; + ExprNode *condition; + ExprNode *expression; + StmtNode *init; +}; + +#endif // NODES_STMT_FORSTMTNODE_H diff --git a/src/parsers/stmt/for_stmt.cpp b/src/parsers/stmt/for_stmt.cpp new file mode 100644 index 0000000..ba6e18b --- /dev/null +++ b/src/parsers/stmt/for_stmt.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2015 Andrei Karas + * + * This file is part of AstDumper. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "includes/parserincludes.h" + +parserDefine(ForStmt); + +#include "parsers/base/stmt.h" + +#include "nodes/stmt/for_stmt.h" + +namespace Generic +{ + +void parseForStmtNode(ForStmtNode *node) +{ + fillType(node); + Log::dump(node); + + node->init = static_cast(createParseNode( + node, + FOR_INIT_STMT(node->gccNode), + "init")); + + node->expression = static_cast(createParseNode( + node, + FOR_EXPR(node->gccNode), + "expression")); + + node->condition = static_cast(createParseNode( + node, + FOR_COND(node->gccNode), + "condition")); + + node->body = static_cast(createParseNode( + node, + FOR_BODY(node->gccNode), + "body")); +} + +} -- cgit v1.2.3-60-g2f50