summaryrefslogtreecommitdiff
path: root/src/parsers
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 /src/parsers
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.
Diffstat (limited to 'src/parsers')
-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
4 files changed, 129 insertions, 10 deletions
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);
}
}