summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-03 00:12:02 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-03 00:12:02 +0300
commit14379df64eefacbfcc807fb5216470071adefdc2 (patch)
tree9ff0b4d6405170e524b63bd80d8e5f715bee6fee /src
parent49dbfa00f155632dc04ffe71320232799a712dfb (diff)
downloadparanucker-14379df64eefacbfcc807fb5216470071adefdc2.tar.gz
paranucker-14379df64eefacbfcc807fb5216470071adefdc2.tar.bz2
paranucker-14379df64eefacbfcc807fb5216470071adefdc2.tar.xz
paranucker-14379df64eefacbfcc807fb5216470071adefdc2.zip
Extend a bit basic node parsing.
Fix warning in gcc plugin includes.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am8
-rw-r--r--src/includes.h (renamed from src/plugin.h)16
-rw-r--r--src/nodes/create.h28
-rw-r--r--src/nodes/node.h4
-rw-r--r--src/parsers/functiondeclnode.cpp8
-rw-r--r--src/parsers/functiondeclnode.h5
-rw-r--r--src/parsers/generic.cpp57
-rw-r--r--src/parsers/generic.h10
-rw-r--r--src/plugin.cpp2
9 files changed, 76 insertions, 62 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index d5df14b..2227d39 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,14 +1,14 @@
AUTOMAKE_OPTIONS = subdir-objects
-SRC = nodes/create.h \
- nodes/functiondeclnode.h \
+SRC = nodes/functiondeclnode.h \
nodes/node.h \
parsers/functiondeclnode.cpp \
parsers/functiondeclnode.h \
parsers/generic.cpp \
parsers/generic.h \
- plugin.cpp \
- plugin.h
+ includes.h \
+ localconsts.h \
+ plugin.cpp
CXX := g++
# in future need remove -Wno-switch
diff --git a/src/plugin.h b/src/includes.h
index 369cb6c..9ecec71 100644
--- a/src/plugin.h
+++ b/src/includes.h
@@ -20,6 +20,22 @@
#ifndef PLUGIN_H
#define PLUGIN_H
+#ifdef PACKAGE_BUGREPORT
+#undef PACKAGE_BUGREPORT
+#endif
+#ifdef PACKAGE_NAME
+#undef PACKAGE_NAME
+#endif
+#ifdef PACKAGE_STRING
+#undef PACKAGE_STRING
+#endif
+#ifdef PACKAGE_TARNAME
+#undef PACKAGE_TARNAME
+#endif
+#ifdef PACKAGE_VERSION
+#undef PACKAGE_VERSION
+#endif
+
#include "gcc-plugin.h"
#include "print-tree.h"
#include "tree.h"
diff --git a/src/nodes/create.h b/src/nodes/create.h
deleted file mode 100644
index 47fa9b8..0000000
--- a/src/nodes/create.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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_CREATE_H
-#define NODES_CREATE_H
-
-#define createNode(node, parentNode, type) \
- type *node = new type; \
- node->parent = parentNode; \
- node->gccNode = gccNode
-
-#endif // NODES_CREATE_H
diff --git a/src/nodes/node.h b/src/nodes/node.h
index c5af7f4..8fba2a9 100644
--- a/src/nodes/node.h
+++ b/src/nodes/node.h
@@ -20,7 +20,7 @@
#ifndef NODES_NODE_H
#define NODES_NODE_H
-#include "plugin.h"
+#include "includes.h"
#include <string>
@@ -33,6 +33,7 @@ struct Node
file(),
gccNode(nullptr),
line(-1),
+ column(-1),
treeNumber(0)
{
}
@@ -43,6 +44,7 @@ struct Node
std::string file;
tree gccNode;
int line;
+ int column;
int treeNumber;
};
diff --git a/src/parsers/functiondeclnode.cpp b/src/parsers/functiondeclnode.cpp
index b08139d..269827c 100644
--- a/src/parsers/functiondeclnode.cpp
+++ b/src/parsers/functiondeclnode.cpp
@@ -20,7 +20,6 @@
#include "parsers/functiondeclnode.h"
#include "parsers/generic.h"
-#include "nodes/create.h"
#include "nodes/functiondeclnode.h"
#include "localconsts.h"
@@ -30,11 +29,10 @@ extern int plugin_is_GPL_compatible;
namespace Generic
{
-void parseFunctionDeclNode(Node *parent,
- tree gccNode)
+void parseFunctionDeclNode(Node *node)
{
- createNode(node, parent, FunctionDeclNode);
- fillType(node, gccNode);
+ fillType(node);
+ fillLocation(node);
}
}
diff --git a/src/parsers/functiondeclnode.h b/src/parsers/functiondeclnode.h
index 10c3882..afc13e9 100644
--- a/src/parsers/functiondeclnode.h
+++ b/src/parsers/functiondeclnode.h
@@ -20,7 +20,7 @@
#ifndef PARSERS_FUNCTIONDECLNODE_H
#define PARSERS_FUNCTIONDECLNODE_H
-#include "plugin.h"
+#include "includes.h"
#include <string>
@@ -28,8 +28,7 @@ struct Node;
namespace Generic
{
- void parseFunctionDeclNode(Node *parent,
- tree gccNode);
+ void parseFunctionDeclNode(Node *parent);
}
#endif // PARSERS_FUNCTIONDECLNODE_H
diff --git a/src/parsers/generic.cpp b/src/parsers/generic.cpp
index ef4ad10..a1e87df 100644
--- a/src/parsers/generic.cpp
+++ b/src/parsers/generic.cpp
@@ -19,7 +19,7 @@
#include "parsers/generic.h"
-#include "nodes/create.h"
+#include "nodes/functiondeclnode.h"
#include "nodes/node.h"
#include "parsers/functiondeclnode.h"
@@ -31,38 +31,67 @@ extern int plugin_is_GPL_compatible;
namespace Generic
{
-void parseNode(Node *parent,
- tree gccNode)
+Node *createEmptyNode(tree gccNode)
{
- if (!parent || gccNode == NULL_TREE)
+ if (gccNode == NULL_TREE)
{
- return;
+ return nullptr;
}
+ Node *node = nullptr;
switch (TREE_CODE(gccNode))
{
case FUNCTION_DECL:
- parseFunctionDeclNode(parent, gccNode);
+ node = new FunctionDeclNode;
+ }
+ return node;
+}
+
+void parseNode(Node *node)
+{
+ if (!node || node->gccNode == NULL_TREE)
+ {
+ return;
+ }
+
+ switch (TREE_CODE(node->gccNode))
+ {
+ case FUNCTION_DECL:
+ parseFunctionDeclNode(node);
}
}
void parseNodes(tree gccNode)
{
- Node *node = new Node;
- parseNode(node, gccNode);
+ //Node *rootNode = new Node;
+ Node *node = createEmptyNode(gccNode);
+ //node->parent = rootNode;
+ node->gccNode = gccNode;
+ parseNode(node);
+}
+
+void fillType(Node *node)
+{
+ if (!node || node->gccNode == NULL_TREE)
+ {
+ return;
+ }
+
+ node->treeNumber = static_cast<int>(TREE_CODE(node->gccNode));
+ node->nodeType = get_tree_code_name(TREE_CODE(node->gccNode));
}
-void fillType(Node *node,
- tree gccNode)
+void fillLocation(Node *node)
{
- if (!node || gccNode == NULL_TREE)
+ if (!node || node->gccNode == NULL_TREE)
{
return;
}
- location_t loc = DECL_SOURCE_LOCATION(gccNode);
- node->treeNumber = static_cast<int>(TREE_CODE(gccNode));
- node->nodeType = get_tree_code_name(TREE_CODE(gccNode));
+ location_t loc = DECL_SOURCE_LOCATION(node->gccNode);
+ node->file = LOCATION_FILE(loc);
+ node->line = LOCATION_LINE(loc);
+ node->column = LOCATION_COLUMN(loc);
}
}
diff --git a/src/parsers/generic.h b/src/parsers/generic.h
index be06005..238f7f3 100644
--- a/src/parsers/generic.h
+++ b/src/parsers/generic.h
@@ -20,7 +20,7 @@
#ifndef PARSERS_GENERIC_H
#define PARSERS_GENERIC_H
-#include "plugin.h"
+#include "includes.h"
#include <string>
@@ -30,13 +30,11 @@ namespace Generic
{
void parseNodes(tree gccNode);
- void parseNode(Node *parent, tree gccNode);
+ void parseNode(Node *parent);
- void parseFunctionDeclNode(Node *parent,
- tree gccNode);
+ void fillType(Node *node);
- void fillType(Node *node,
- tree gccNode);
+ void fillLocation(Node *node);
}
#endif // PARSERS_GENERIC_H
diff --git a/src/plugin.cpp b/src/plugin.cpp
index 597a1fc..121457c 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "plugin.h"
+#include "includes.h"
#include "parsers/generic.h"