summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-13 13:41:37 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-13 13:41:37 +0300
commit07a8133bc73556e5b61309866182ff594e57a408 (patch)
tree50d32ed68893a6109d078cadbbfef97e892bee46
parent894d42931279184ef3ad05c2689f175c6bb982b5 (diff)
downloadparanucker-07a8133bc73556e5b61309866182ff594e57a408.tar.gz
paranucker-07a8133bc73556e5b61309866182ff594e57a408.tar.bz2
paranucker-07a8133bc73556e5b61309866182ff594e57a408.tar.xz
paranucker-07a8133bc73556e5b61309866182ff594e57a408.zip
Move indirect_ref and component_ref from expr directory to ref.
-rw-r--r--src/Makefile.files11
-rw-r--r--src/analysis/expression.cpp3
-rw-r--r--src/analysis/statement.cpp3
-rw-r--r--src/includes/nodeincludes.h4
-rw-r--r--src/nodes/base/ref.h38
-rw-r--r--src/nodes/ref/component_ref.h (renamed from src/nodes/expr/component_ref.h)12
-rw-r--r--src/nodes/ref/indirect_ref.h (renamed from src/nodes/expr/indirect_ref.h)12
-rw-r--r--src/parsers/base/ref.cpp82
-rw-r--r--src/parsers/base/ref.h39
-rw-r--r--src/parsers/ref/component_ref.cpp (renamed from src/parsers/expr/component_ref.cpp)10
-rw-r--r--src/parsers/ref/indirect_ref.cpp (renamed from src/parsers/expr/indirect_ref.cpp)8
11 files changed, 192 insertions, 30 deletions
diff --git a/src/Makefile.files b/src/Makefile.files
index f1bc323..b5cfe4a 100644
--- a/src/Makefile.files
+++ b/src/Makefile.files
@@ -13,6 +13,7 @@ SRC = analysis/analysis.cpp \
nodes/base/decl.h \
nodes/base/expr.h \
nodes/base/node.h \
+ nodes/base/ref.h \
nodes/base/stmt.h \
nodes/base/type.h \
nodes/cst/integer_cst.h \
@@ -35,6 +36,8 @@ SRC = analysis/analysis.cpp \
parsers/base/decl.h \
parsers/base/expr.cpp \
parsers/base/expr.h \
+ parsers/base/ref.cpp \
+ parsers/base/ref.h \
parsers/base/stmt.cpp \
parsers/base/stmt.h \
parsers/base/type.cpp \
@@ -107,8 +110,8 @@ SRC = analysis/analysis.cpp \
parsers/expr/ge_expr.cpp \
nodes/expr/ne_expr.h \
parsers/expr/ne_expr.cpp \
- nodes/expr/indirect_ref.h \
- parsers/expr/indirect_ref.cpp \
+ nodes/ref/indirect_ref.h \
+ parsers/ref/indirect_ref.cpp \
nodes/expr/loop_expr.h \
parsers/expr/loop_expr.cpp \
nodes/expr/nop_expr.h \
@@ -167,7 +170,7 @@ SRC = analysis/analysis.cpp \
parsers/expr/mustnotthrow_expr.cpp \
nodes/type/reference_type.h \
parsers/type/reference_type.cpp \
- nodes/expr/component_ref.h \
- parsers/expr/component_ref.cpp \
+ nodes/ref/component_ref.h \
+ parsers/ref/component_ref.cpp \
nodes/stmt/cleanup_stmt.h \
parsers/stmt/cleanup_stmt.cpp \ No newline at end of file
diff --git a/src/analysis/expression.cpp b/src/analysis/expression.cpp
index 27b6718..8185419 100644
--- a/src/analysis/expression.cpp
+++ b/src/analysis/expression.cpp
@@ -26,10 +26,11 @@
#include "analysis/walkitem.h"
#include "nodes/expr/addr_expr.h"
-#include "nodes/expr/indirect_ref.h"
#include "nodes/expr/modify_expr.h"
#include "nodes/expr/pointerplus_expr.h"
+#include "nodes/ref/indirect_ref.h"
+
#include <set>
#include "localconsts.h"
diff --git a/src/analysis/statement.cpp b/src/analysis/statement.cpp
index b3ca49b..8752edc 100644
--- a/src/analysis/statement.cpp
+++ b/src/analysis/statement.cpp
@@ -26,11 +26,12 @@
#include "analysis/walkitem.h"
#include "nodes/expr/eq_expr.h"
-#include "nodes/expr/indirect_ref.h"
#include "nodes/expr/modify_expr.h"
#include "nodes/expr/ne_expr.h"
#include "nodes/expr/pointerplus_expr.h"
+#include "nodes/ref/indirect_ref.h"
+
#include "nodes/stmt/if_stmt.h"
#include <set>
diff --git a/src/includes/nodeincludes.h b/src/includes/nodeincludes.h
index ba49df9..0bb3891 100644
--- a/src/includes/nodeincludes.h
+++ b/src/includes/nodeincludes.h
@@ -34,7 +34,7 @@
#include "nodes/expr/gt_expr.h"
#include "nodes/expr/ge_expr.h"
#include "nodes/expr/ne_expr.h"
-#include "nodes/expr/indirect_ref.h"
+#include "nodes/ref/indirect_ref.h"
#include "nodes/expr/loop_expr.h"
#include "nodes/expr/nop_expr.h"
#include "nodes/expr/cond_expr.h"
@@ -64,5 +64,5 @@
#include "nodes/type/method_type.h"
#include "nodes/expr/mustnotthrow_expr.h"
#include "nodes/type/reference_type.h"
-#include "nodes/expr/component_ref.h"
+#include "nodes/ref/component_ref.h"
#include "nodes/stmt/cleanup_stmt.h"
diff --git a/src/nodes/base/ref.h b/src/nodes/base/ref.h
new file mode 100644
index 0000000..69dd65d
--- /dev/null
+++ b/src/nodes/base/ref.h
@@ -0,0 +1,38 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NODES_BASE_REFNODE_H
+#define NODES_BASE_REFNODE_H
+
+#include "nodes/base/node.h"
+
+#include <vector>
+
+struct RefNode : public Node
+{
+ RefNode() :
+ Node(),
+ args()
+ {
+ }
+
+ std::vector<Node*> args;
+};
+
+#endif // NODES_BASE_REFNODE_H
diff --git a/src/nodes/expr/component_ref.h b/src/nodes/ref/component_ref.h
index 1f39432..1b5a299 100644
--- a/src/nodes/expr/component_ref.h
+++ b/src/nodes/ref/component_ref.h
@@ -17,19 +17,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NODES_EXPR_COMPONENTREFNODE_H
-#define NODES_EXPR_COMPONENTREFNODE_H
+#ifndef NODES_REF_COMPONENTREFNODE_H
+#define NODES_REF_COMPONENTREFNODE_H
-#include "nodes/base/expr.h"
+#include "nodes/base/ref.h"
#include "nodes/decl/field_decl.h"
#include <string>
-struct ComponentRefNode : public ExprNode
+struct ComponentRefNode : public RefNode
{
ComponentRefNode() :
- ExprNode(),
+ RefNode(),
object(nullptr),
field(nullptr)
{
@@ -38,4 +38,4 @@ struct ComponentRefNode : public ExprNode
FieldDeclNode *field;
};
-#endif // NODES_EXPR_COMPONENTREFNODE_H
+#endif // NODES_REF_COMPONENTREFNODE_H
diff --git a/src/nodes/expr/indirect_ref.h b/src/nodes/ref/indirect_ref.h
index 6a33f88..18f8321 100644
--- a/src/nodes/expr/indirect_ref.h
+++ b/src/nodes/ref/indirect_ref.h
@@ -17,19 +17,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef NODES_EXPR_INDIRECTREFNODE_H
-#define NODES_EXPR_INDIRECTREFNODE_H
+#ifndef NODES_REF_INDIRECTREFNODE_H
+#define NODES_REF_INDIRECTREFNODE_H
-#include "nodes/base/expr.h"
+#include "nodes/base/ref.h"
#include <string>
-struct IndirectRefNode : public ExprNode
+struct IndirectRefNode : public RefNode
{
IndirectRefNode() :
- ExprNode()
+ RefNode()
{
}
};
-#endif // NODES_EXPR_INDIRECTREFNODE_H
+#endif // NODES_REF_INDIRECTREFNODE_H
diff --git a/src/parsers/base/ref.cpp b/src/parsers/base/ref.cpp
new file mode 100644
index 0000000..76da1ba
--- /dev/null
+++ b/src/parsers/base/ref.cpp
@@ -0,0 +1,82 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "parsers/base/ref.h"
+
+#include "includes.h"
+
+#include "nodes/base/ref.h"
+
+#include "parsers/generic.h"
+
+#include "localconsts.h"
+
+namespace Generic
+{
+
+void fillRefLocation(Node *node)
+{
+ if (!node || node->gccNode == NULL_TREE)
+ {
+ return;
+ }
+
+ if (EXPR_HAS_LOCATION(node->gccNode))
+ {
+ location_t loc = EXPR_LOCATION(node->gccNode);
+ node->location = loc;
+ node->file = LOCATION_FILE(loc);
+ node->line = LOCATION_LINE(loc);
+ node->column = LOCATION_COLUMN(loc);
+ }
+}
+
+void fillRefOperands(RefNode *node)
+{
+ if (!node || node->gccNode == NULL_TREE)
+ {
+ return;
+ }
+ const int sz = TREE_OPERAND_LENGTH(node->gccNode);
+ for (int f = 0;f < sz; f ++)
+ {
+ node->args.push_back(createParseNode(
+ node,
+ TREE_OPERAND (node->gccNode, f),
+ "operand"));
+ }
+}
+
+Node *getRefOperand(RefNode *node,
+ const int pos,
+ const std::string &tag)
+{
+ if (!node || node->gccNode == NULL_TREE)
+ return nullptr;
+ const int sz = TREE_OPERAND_LENGTH(node->gccNode);
+ if (sz >= pos)
+ return nullptr;
+
+ return createParseNode(
+ node,
+ TREE_OPERAND (node->gccNode, pos),
+ tag);
+}
+
+}
diff --git a/src/parsers/base/ref.h b/src/parsers/base/ref.h
new file mode 100644
index 0000000..60acf45
--- /dev/null
+++ b/src/parsers/base/ref.h
@@ -0,0 +1,39 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PARSERS_BASE_REF_H
+#define PARSERS_BASE_REF_H
+
+#include <string>
+
+struct RefNode;
+struct Node;
+
+namespace Generic
+{
+ void fillRefLocation(Node *node);
+
+ void fillRefOperands(RefNode *node);
+
+ Node *getRefOperand(RefNode *node,
+ const int pos,
+ const std::string &tag);
+}
+
+#endif // PARSERS_BASE_REF_H
diff --git a/src/parsers/expr/component_ref.cpp b/src/parsers/ref/component_ref.cpp
index 039996c..0934400 100644
--- a/src/parsers/expr/component_ref.cpp
+++ b/src/parsers/ref/component_ref.cpp
@@ -21,11 +21,11 @@
parserDefine(ComponentRef);
-#include "parsers/base/expr.h"
+#include "parsers/base/ref.h"
#include "nodes/decl/field_decl.h"
-#include "nodes/expr/component_ref.h"
+#include "nodes/ref/component_ref.h"
namespace Generic
{
@@ -35,11 +35,9 @@ void parseComponentRefNode(ComponentRefNode *node)
fillType(node);
Log::dump(node);
- fillExprOperands(node);
-
- node->object = getExprOperand(node, 0, "object");
+ node->object = getRefOperand(node, 0, "object");
node->field = static_cast<FieldDeclNode*>(
- getExprOperand(node, 1, "field"));
+ getRefOperand(node, 1, "field"));
// args 0 object
// args 1 FIELD_DECL of member
diff --git a/src/parsers/expr/indirect_ref.cpp b/src/parsers/ref/indirect_ref.cpp
index 0b4e01b..d4ef67b 100644
--- a/src/parsers/expr/indirect_ref.cpp
+++ b/src/parsers/ref/indirect_ref.cpp
@@ -21,9 +21,9 @@
parserDefine(IndirectRef);
-#include "parsers/base/expr.h"
+#include "parsers/base/ref.h"
-#include "nodes/expr/indirect_ref.h"
+#include "nodes/ref/indirect_ref.h"
namespace Generic
{
@@ -31,13 +31,13 @@ namespace Generic
void parseIndirectRefNode(IndirectRefNode *node)
{
fillType(node);
- fillExprLocation(node);
+ fillRefLocation(node);
Log::dump(node);
// if (!node->parseChilds)
// return;
- fillExprOperands(node);
+ fillRefOperands(node);
}
}