summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/logger.cpp15
-rw-r--r--src/logger.h4
-rw-r--r--src/nodes/integertypenode.h52
-rw-r--r--src/parsers/generic.cpp6
-rw-r--r--src/parsers/integer_cst.cpp9
-rw-r--r--src/parsers/integer_type.cpp63
-rw-r--r--src/stringutils.cpp2
-rw-r--r--src/stringutils.h2
9 files changed, 152 insertions, 3 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f6c6efe..547a4aa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,7 @@ SRC = nodes/base/cstnode.h \
nodes/functiontypenode.h \
nodes/identifiernode.h \
nodes/integercstnode.h \
+ nodes/integertypenode.h \
nodes/parmdeclnode.h \
nodes/pointertypernode.h \
nodes/resultdeclnode.h \
@@ -20,6 +21,7 @@ SRC = nodes/base/cstnode.h \
parsers/generic.h \
parsers/identifier_node.cpp \
parsers/integer_cst.cpp \
+ parsers/integer_type.cpp \
parsers/parserincludes.h \
parsers/pointer_type.cpp \
parsers/result_decl.cpp \
diff --git a/src/logger.cpp b/src/logger.cpp
index 1933fb4..fe52a8b 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -43,6 +43,21 @@ void log(const Node *const node,
va_end(ap);
}
+void logRaw(const Node *const node,
+ const char *const text,
+ ...)
+{
+ va_list ap;
+ va_start(ap, text);
+
+ if (node)
+ fprintf(stderr, "%s", node->getIndent().c_str());
+ vfprintf(stderr, text, ap);
+ fprintf(stderr, "\n");
+
+ va_end(ap);
+}
+
void logInt(const Node *const node,
const char *const text,
const int val)
diff --git a/src/logger.h b/src/logger.h
index 4830665..fa365f6 100644
--- a/src/logger.h
+++ b/src/logger.h
@@ -30,6 +30,10 @@ namespace Log
const char *const text,
...);
+ void logRaw(const Node *const node,
+ const char *const text,
+ ...);
+
void logInt(const Node *const node,
const char *const text,
const int val);
diff --git a/src/nodes/integertypenode.h b/src/nodes/integertypenode.h
new file mode 100644
index 0000000..088f2a7
--- /dev/null
+++ b/src/nodes/integertypenode.h
@@ -0,0 +1,52 @@
+/*
+ * 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_INTEGERTYPENODE_H
+#define NODES_INTEGERTYPENODE_H
+
+#include "nodes/integercstnode.h"
+
+#include "nodes/base/typenode.h"
+
+#include <string>
+
+struct IntegerTypeNode : public TypeNode
+{
+ IntegerTypeNode() :
+ TypeNode(),
+ typeSize(nullptr),
+ minValue(nullptr),
+ maxValue(nullptr),
+ precisionBits(0),
+ sizeBits(0),
+ isChar(false),
+ isUnsigned(false)
+ {
+ }
+
+ IntegerCstNode *typeSize;
+ IntegerCstNode *minValue;
+ IntegerCstNode *maxValue;
+ int precisionBits;
+ int sizeBits;
+ bool isChar;
+ bool isUnsigned;
+};
+
+#endif // NODES_INTEGERTYPENODE_H
diff --git a/src/parsers/generic.cpp b/src/parsers/generic.cpp
index 732f2f3..9b8f1f7 100644
--- a/src/parsers/generic.cpp
+++ b/src/parsers/generic.cpp
@@ -21,6 +21,7 @@
#include "nodes/functiondeclnode.h"
#include "nodes/functiontypenode.h"
+#include "nodes/integertypenode.h"
#include "nodes/pointertypenode.h"
#include "nodes/voidtypenode.h"
#include "nodes/typedeclnode.h"
@@ -32,9 +33,12 @@
parserDefine(FunctionDecl);
parserDefine(ResultDecl);
parserDefine(TypeDecl);
+
parserDefine(FunctionType);
+parserDefine(IntegerType);
parserDefine(PointerType);
parserDefine(VoidType);
+
parserDefine(TreeList);
parserDefine(Identifier);
parserDefine(IntegerCst);
@@ -82,6 +86,7 @@ Node *createParseNode(Node *parent,
createNodeType(RESULT_DECL, ResultDeclNode);
createNodeType(TYPE_DECL, TypeDeclNode);
createNodeType(FUNCTION_TYPE, FunctionTypeNode);
+ createNodeType(INTEGER_TYPE, IntegerTypeNode);
createNodeType(VOID_TYPE, VoidTypeNode);
createNodeType(POINTER_TYPE, PointerTypeNode);
createNodeType(TREE_LIST, TreeListNode);
@@ -118,6 +123,7 @@ Node *createParseNode(Node *parent,
parseNodeType(RESULT_DECL, ResultDecl);
parseNodeType(TYPE_DECL, TypeDecl);
parseNodeType(FUNCTION_TYPE, FunctionType);
+ parseNodeType(INTEGER_TYPE, IntegerType);
parseNodeType(VOID_TYPE, VoidType);
parseNodeType(POINTER_TYPE, PointerType);
parseNodeType(TREE_LIST, TreeList);
diff --git a/src/parsers/integer_cst.cpp b/src/parsers/integer_cst.cpp
index 812c0dc..05b1c33 100644
--- a/src/parsers/integer_cst.cpp
+++ b/src/parsers/integer_cst.cpp
@@ -37,8 +37,15 @@ 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)));
+ node->label.append(toString(-(unsigned HOST_WIDE_INT)
+ tree_to_shwi(node->gccNode)));
+ }
+ else
+ {
+ node->label.append(toString(tree_to_shwi(node->gccNode)));
+ }
Log::log(node);
}
diff --git a/src/parsers/integer_type.cpp b/src/parsers/integer_type.cpp
new file mode 100644
index 0000000..35addab
--- /dev/null
+++ b/src/parsers/integer_type.cpp
@@ -0,0 +1,63 @@
+/*
+ * 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"
+
+parserDefine(IntegerType);
+
+#include "parsers/base/type.h"
+
+#include "nodes/integertypenode.h"
+
+namespace Generic
+{
+
+void parseIntegerTypeNode(IntegerTypeNode *node)
+{
+ fillType(node);
+ Log::log(node);
+
+ setPrintField(node, TYPE_PRECISION, precisionBits);
+ setPrintField(node, TYPE_STRING_FLAG, isChar);
+ node->isUnsigned = TYPE_UNSIGNED(node->gccNode);
+ if (node->isUnsigned)
+ Log::logRaw(node, "- unsigned");
+ else
+ Log::logRaw(node, "- signed");
+
+ fillTypeName(node);
+ fillTypeAttributes(node);
+ node->typeSize = static_cast<IntegerCstNode*>(createParseNode(
+ node,
+ TYPE_SIZE(node->gccNode),
+ INTEGER_CST,
+ "type size"));
+ node->minValue = static_cast<IntegerCstNode*>(createParseNode(
+ node,
+ TYPE_MIN_VALUE(node->gccNode),
+ INTEGER_CST,
+ "min value"));
+ node->maxValue = static_cast<IntegerCstNode*>(createParseNode(
+ node,
+ TYPE_MAX_VALUE(node->gccNode),
+ INTEGER_CST,
+ "max value"));
+}
+
+}
diff --git a/src/stringutils.cpp b/src/stringutils.cpp
index df5adbb..c5fdc4b 100644
--- a/src/stringutils.cpp
+++ b/src/stringutils.cpp
@@ -21,7 +21,7 @@
#include "localconsts.h"
-std::string toString(const int num)
+std::string toString(const unsigned int num)
{
static char str[100];
snprintf(str, sizeof(str), "%u", num);
diff --git a/src/stringutils.h b/src/stringutils.h
index 58a4e5e..880e609 100644
--- a/src/stringutils.h
+++ b/src/stringutils.h
@@ -22,6 +22,6 @@
#include <string>
-std::string toString(const int num);
+std::string toString(const unsigned int num);
#endif // STRINGUTILS_H