From 2081a818759feeef2aa824e48c287da4cf1fbc2f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 13 Jun 2015 14:41:10 +0300 Subject: Add parsing ARRAY_TYPE. --- src/Makefile.files | 4 ++- src/includes/nodeincludes.h | 1 + src/includes/nodeshandling.inc | 1 + src/includes/parserdefines.inc | 1 + src/nodes/type/array_type.h | 48 +++++++++++++++++++++++++++++++ src/parsers/type/array_type.cpp | 62 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/nodes/type/array_type.h create mode 100644 src/parsers/type/array_type.cpp diff --git a/src/Makefile.files b/src/Makefile.files index 86ffffa..bf2770e 100644 --- a/src/Makefile.files +++ b/src/Makefile.files @@ -181,4 +181,6 @@ SRC = analysis/analysis.cpp \ nodes/expr/lshift_expr.h \ parsers/expr/lshift_expr.cpp \ nodes/expr/postincrement_expr.h \ - parsers/expr/postincrement_expr.cpp \ No newline at end of file + parsers/expr/postincrement_expr.cpp \ + nodes/type/array_type.h \ + parsers/type/array_type.cpp \ No newline at end of file diff --git a/src/includes/nodeincludes.h b/src/includes/nodeincludes.h index 918ca6c..f04a7f2 100644 --- a/src/includes/nodeincludes.h +++ b/src/includes/nodeincludes.h @@ -70,3 +70,4 @@ #include "nodes/expr/rshift_expr.h" #include "nodes/expr/lshift_expr.h" #include "nodes/expr/postincrement_expr.h" +#include "nodes/type/array_type.h" diff --git a/src/includes/nodeshandling.inc b/src/includes/nodeshandling.inc index 67f8176..9ad8380 100644 --- a/src/includes/nodeshandling.inc +++ b/src/includes/nodeshandling.inc @@ -69,3 +69,4 @@ handleNodeType(TRY_CATCH_EXPR, TryCatchExpr) handleNodeType(RSHIFT_EXPR, RShiftExpr) handleNodeType(LSHIFT_EXPR, LShiftExpr) handleNodeType(POSTINCREMENT_EXPR, PostIncrementExpr) +handleNodeType(ARRAY_TYPE, ArrayType) diff --git a/src/includes/parserdefines.inc b/src/includes/parserdefines.inc index 53d0c7b..53ede88 100644 --- a/src/includes/parserdefines.inc +++ b/src/includes/parserdefines.inc @@ -69,3 +69,4 @@ parserDefine(TryCatchExpr); parserDefine(RShiftExpr); parserDefine(LShiftExpr); parserDefine(PostIncrementExpr); +parserDefine(ArrayType); diff --git a/src/nodes/type/array_type.h b/src/nodes/type/array_type.h new file mode 100644 index 0000000..3a5d714 --- /dev/null +++ b/src/nodes/type/array_type.h @@ -0,0 +1,48 @@ +/* + * 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_ARRAYTYPENODE_H +#define NODES_TYPE_ARRAYTYPENODE_H + +#include "nodes/base/type.h" + +#include "nodes/cst/integer_cst.h" + +#include + +struct ArrayTypeNode : public TypeNode +{ + ArrayTypeNode() : + TypeNode(), + domain(nullptr), + elementType(nullptr), + minIndex(nullptr), + maxIndex(nullptr), + isString(false) + { + } + + TypeNode *domain; + TypeNode *elementType; + IntegerCstNode *minIndex; + IntegerCstNode *maxIndex; + bool isString; +}; + +#endif // NODES_TYPE_ARRAYTYPENODE_H diff --git a/src/parsers/type/array_type.cpp b/src/parsers/type/array_type.cpp new file mode 100644 index 0000000..a1594a7 --- /dev/null +++ b/src/parsers/type/array_type.cpp @@ -0,0 +1,62 @@ +/* + * 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(ArrayType); + +#include "parsers/base/type.h" + +#include "nodes/type/array_type.h" + +namespace Generic +{ + +void parseArrayTypeNode(ArrayTypeNode *node) +{ + fillType(node); + Log::dump(node); + + setPrintField(node, TYPE_STRING_FLAG, isString); + + fillTypeName(node); + fillTypeAttributes(node); + + node->elementType = static_cast(createParseNode( + node, + TREE_TYPE(node->gccNode), + "element type")); + + node->domain = static_cast(createParseNode( + node, + TYPE_DOMAIN(node->gccNode), + "domain")); + node->minIndex = static_cast(createParseNode( + node, + TYPE_MIN_VALUE(node->gccNode), + INTEGER_CST, + "min index")); + node->maxIndex = static_cast(createParseNode( + node, + TYPE_MAX_VALUE(node->gccNode), + INTEGER_CST, + "max index")); +} + +} -- cgit v1.2.3-70-g09d2