From 49a697cb7d536f09bc3c8791eb6f1808e6e0a8d6 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 13 Jun 2015 22:49:13 +0300 Subject: Add parsing ENUMERAL_TYPE. --- src/Makefile.files | 4 ++- src/includes/nodeincludes.h | 1 + src/includes/nodeshandling.inc | 1 + src/includes/parserdefines.inc | 1 + src/nodes/type/enumeral_type.h | 50 ++++++++++++++++++++++++++++++ src/parsers/type/enumeral_type.cpp | 63 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/nodes/type/enumeral_type.h create mode 100644 src/parsers/type/enumeral_type.cpp diff --git a/src/Makefile.files b/src/Makefile.files index 9437936..fc02518 100644 --- a/src/Makefile.files +++ b/src/Makefile.files @@ -252,4 +252,6 @@ SRC = analysis/analysis.cpp \ nodes/expr/cast_expr.h \ parsers/expr/cast_expr.cpp \ nodes/handler.h \ - parsers/handler.cpp \ No newline at end of file + parsers/handler.cpp \ + nodes/type/enumeral_type.h \ + parsers/type/enumeral_type.cpp \ No newline at end of file diff --git a/src/includes/nodeincludes.h b/src/includes/nodeincludes.h index 65a3cff..88a11c1 100644 --- a/src/includes/nodeincludes.h +++ b/src/includes/nodeincludes.h @@ -104,3 +104,4 @@ #include "nodes/block/try_block.h" #include "nodes/expr/cast_expr.h" #include "nodes/handler.h" +#include "nodes/type/enumeral_type.h" diff --git a/src/includes/nodeshandling.inc b/src/includes/nodeshandling.inc index 3d8c552..d98a115 100644 --- a/src/includes/nodeshandling.inc +++ b/src/includes/nodeshandling.inc @@ -103,3 +103,4 @@ handleNodeType(TREE_VEC, TreeVec) handleNodeType(TRY_BLOCK, TryBlock) handleNodeType(CAST_EXPR, CastExpr) handleNodeType(HANDLER, Handler) +handleNodeType(ENUMERAL_TYPE, EnumeralType) diff --git a/src/includes/parserdefines.inc b/src/includes/parserdefines.inc index 91a7da0..05f1086 100644 --- a/src/includes/parserdefines.inc +++ b/src/includes/parserdefines.inc @@ -103,3 +103,4 @@ parserDefine(TreeVec); parserDefine(TryBlock); parserDefine(CastExpr); parserDefine(Handler); +parserDefine(EnumeralType); diff --git a/src/nodes/type/enumeral_type.h b/src/nodes/type/enumeral_type.h new file mode 100644 index 0000000..ab57adb --- /dev/null +++ b/src/nodes/type/enumeral_type.h @@ -0,0 +1,50 @@ +/* + * 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 . + */ + +#ifndef NODES_TYPE_ENUMERALTYPENODE_H +#define NODES_TYPE_ENUMERALTYPENODE_H + +#include "nodes/base/type.h" + +#include "nodes/cst/integer_cst.h" + +#include "nodes/list/tree_list.h" + +#include + +struct EnumeralTypeNode : public TypeNode +{ + EnumeralTypeNode() : + TypeNode(), + minValue(nullptr), + maxValue(nullptr), + values(nullptr), + precisionBits(0), + isUnsigned(false) + { + } + + IntegerCstNode *minValue; + IntegerCstNode *maxValue; + TreeListNode *values; + int precisionBits; + bool isUnsigned; +}; + +#endif // NODES_TYPE_ENUMERALTYPENODE_H diff --git a/src/parsers/type/enumeral_type.cpp b/src/parsers/type/enumeral_type.cpp new file mode 100644 index 0000000..b609fa9 --- /dev/null +++ b/src/parsers/type/enumeral_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 . + */ + +#include "includes/parserincludes.h" + +parserDefine(EnumeralType); + +#include "parsers/base/type.h" + +#include "nodes/type/enumeral_type.h" + +namespace Generic +{ + +void parseEnumeralTypeNode(EnumeralTypeNode *node) +{ + fillType(node); + Log::dump(node); + + setPrintField(node, TYPE_PRECISION, precisionBits); + node->isUnsigned = TYPE_UNSIGNED(node->gccNode); + if (node->isUnsigned) + Log::dumpRaw(node, "- unsigned"); + else + Log::dumpRaw(node, "- signed"); + + fillTypeName(node); + fillTypeAttributes(node); + + node->minValue = static_cast(createParseNode( + node, + TYPE_MIN_VALUE(node->gccNode), + INTEGER_CST, + "min value")); + node->maxValue = static_cast(createParseNode( + node, + TYPE_MAX_VALUE(node->gccNode), + INTEGER_CST, + "max value")); + node->values = static_cast(createParseNode( + node, + TYPE_VALUES(node->gccNode), + TREE_LIST, + "values")); +} + +} -- cgit v1.2.3-60-g2f50