summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-04 23:57:45 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-04 23:57:45 +0300
commit2d95ee1669cb4b9b8bf60c4381ac7b8d9499fc53 (patch)
tree46d91428f135d55aaf6b78766a5149d52438f89f /src
parent4ca525cbb5e619f73a066a2e529daf6fd0ca07ce (diff)
downloadparanucker-2d95ee1669cb4b9b8bf60c4381ac7b8d9499fc53.tar.gz
paranucker-2d95ee1669cb4b9b8bf60c4381ac7b8d9499fc53.tar.bz2
paranucker-2d95ee1669cb4b9b8bf60c4381ac7b8d9499fc53.tar.xz
paranucker-2d95ee1669cb4b9b8bf60c4381ac7b8d9499fc53.zip
Add parsing INTEGER_CST node.
Also add function for convertng int to string.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am10
-rw-r--r--src/nodes/base/cstnode.h33
-rw-r--r--src/nodes/integercstnode.h33
-rw-r--r--src/parsers/generic.cpp4
-rw-r--r--src/parsers/integer_cst.cpp45
-rw-r--r--src/stringutils.cpp30
-rw-r--r--src/stringutils.h27
7 files changed, 180 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 6475cf4..f5d1f36 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,11 +1,13 @@
AUTOMAKE_OPTIONS = subdir-objects
-SRC = nodes/base/declnode.h \
+SRC = nodes/base/cstnode.h \
+ nodes/base/declnode.h \
nodes/base/node.h \
nodes/base/typenode.h \
nodes/functiondeclnode.h \
nodes/functiontypenode.h \
nodes/identifiernode.h \
+ nodes/integercstnode.h \
nodes/parmdeclnode.h \
nodes/resultdeclnode.h \
nodes/treelistnode.h \
@@ -16,6 +18,7 @@ SRC = nodes/base/declnode.h \
parsers/generic.cpp \
parsers/generic.h \
parsers/identifier_node.cpp \
+ parsers/integer_cst.cpp \
parsers/parserincludes.h \
parsers/result_decl.cpp \
parsers/tree_list.cpp \
@@ -29,7 +32,10 @@ SRC = nodes/base/declnode.h \
localconsts.h \
logger.cpp \
logger.h \
- plugin.cpp
+ plugin.cpp \
+ stringutils.cpp \
+ stringutils.h
+
CXX := g++
# in future need remove -Wno-switch
diff --git a/src/nodes/base/cstnode.h b/src/nodes/base/cstnode.h
new file mode 100644
index 0000000..e05981f
--- /dev/null
+++ b/src/nodes/base/cstnode.h
@@ -0,0 +1,33 @@
+/*
+ * 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_CSTNODE_H
+#define NODES_BASE_CSTNODE_H
+
+#include "nodes/base/node.h"
+
+struct CstNode : public Node
+{
+ CstNode() :
+ Node()
+ {
+ }
+};
+
+#endif // NODES_BASE_CSTNODE_H
diff --git a/src/nodes/integercstnode.h b/src/nodes/integercstnode.h
new file mode 100644
index 0000000..ca5d71c
--- /dev/null
+++ b/src/nodes/integercstnode.h
@@ -0,0 +1,33 @@
+/*
+ * 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_INTEGERCSTNODE_H
+#define NODES_BASE_INTEGERCSTNODE_H
+
+#include "nodes/base/cstnode.h"
+
+struct IntegerCstNode : public CstNode
+{
+ IntegerCstNode() :
+ CstNode()
+ {
+ }
+};
+
+#endif // NODES_BASE_INTEGERCSTNODE_H
diff --git a/src/parsers/generic.cpp b/src/parsers/generic.cpp
index 184cd40..1cf74b4 100644
--- a/src/parsers/generic.cpp
+++ b/src/parsers/generic.cpp
@@ -24,6 +24,7 @@
#include "nodes/voidtypenode.h"
#include "nodes/typedeclnode.h"
#include "nodes/identifiernode.h"
+#include "nodes/integercstnode.h"
#include "parsers/parserincludes.h"
@@ -34,6 +35,7 @@ parserDefine(VoidType);
parserDefine(TypeDecl);
parserDefine(TreeList);
parserDefine(Identifier);
+parserDefine(IntegerCst);
#include "localconsts.h"
@@ -81,6 +83,7 @@ Node *createParseNode(Node *parent,
createNodeType(VOID_TYPE, VoidTypeNode);
createNodeType(TREE_LIST, TreeListNode);
createNodeType(IDENTIFIER_NODE, IdentifierNode);
+ createNodeType(INTEGER_CST, IntegerCstNode);
default:
Log::log(parent,
1,
@@ -115,6 +118,7 @@ Node *createParseNode(Node *parent,
parseNodeType(VOID_TYPE, VoidType);
parseNodeType(TREE_LIST, TreeList);
parseNodeType(IDENTIFIER_NODE, Identifier);
+ parseNodeType(INTEGER_CST, IntegerCst);
default:
break;
}
diff --git a/src/parsers/integer_cst.cpp b/src/parsers/integer_cst.cpp
new file mode 100644
index 0000000..812c0dc
--- /dev/null
+++ b/src/parsers/integer_cst.cpp
@@ -0,0 +1,45 @@
+/*
+ * 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/parserincludes.h"
+
+#include "stringutils.h"
+
+parserDefine(IntegerCst);
+
+#include "parsers/base/type.h"
+
+#include "nodes/integercstnode.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+namespace Generic
+{
+
+void parseIntegerCstNode(IntegerCstNode *node)
+{
+ fillType(node);
+ if (tree_int_cst_sgn(node->gccNode) < 0)
+ node->label = "-";
+ node->label.append(toString(tree_to_shwi(node->gccNode)));
+ Log::log(node);
+}
+
+}
diff --git a/src/stringutils.cpp b/src/stringutils.cpp
new file mode 100644
index 0000000..df5adbb
--- /dev/null
+++ b/src/stringutils.cpp
@@ -0,0 +1,30 @@
+/*
+ * 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 "stringutils.h"
+
+#include "localconsts.h"
+
+std::string toString(const int num)
+{
+ static char str[100];
+ snprintf(str, sizeof(str), "%u", num);
+ str[99] = 0;
+ return str;
+}
diff --git a/src/stringutils.h b/src/stringutils.h
new file mode 100644
index 0000000..58a4e5e
--- /dev/null
+++ b/src/stringutils.h
@@ -0,0 +1,27 @@
+/*
+ * 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 STRINGUTILS_H
+#define STRINGUTILS_H
+
+#include <string>
+
+std::string toString(const int num);
+
+#endif // STRINGUTILS_H