diff options
-rw-r--r-- | src/Makefile.files | 4 | ||||
-rw-r--r-- | src/includes/nodeincludes.h | 1 | ||||
-rw-r--r-- | src/includes/nodeshandling.inc | 1 | ||||
-rw-r--r-- | src/includes/parserdefines.inc | 1 | ||||
-rw-r--r-- | src/nodes/expr/component_ref.h | 41 | ||||
-rw-r--r-- | src/parsers/base/expr.cpp | 16 | ||||
-rw-r--r-- | src/parsers/base/expr.h | 6 | ||||
-rw-r--r-- | src/parsers/expr/component_ref.cpp | 49 |
8 files changed, 118 insertions, 1 deletions
diff --git a/src/Makefile.files b/src/Makefile.files index 5a94f84..0bca659 100644 --- a/src/Makefile.files +++ b/src/Makefile.files @@ -166,4 +166,6 @@ SRC = analysis/analysis.cpp \ nodes/expr/mustnotthrow_expr.h \ parsers/expr/mustnotthrow_expr.cpp \ nodes/type/reference_type.h \ - parsers/type/reference_type.cpp
\ No newline at end of file + parsers/type/reference_type.cpp \ + nodes/expr/component_ref.h \ + parsers/expr/component_ref.cpp
\ No newline at end of file diff --git a/src/includes/nodeincludes.h b/src/includes/nodeincludes.h index bc844b6..6a75b1e 100644 --- a/src/includes/nodeincludes.h +++ b/src/includes/nodeincludes.h @@ -64,3 +64,4 @@ #include "nodes/type/method_type.h" #include "nodes/expr/mustnotthrow_expr.h" #include "nodes/type/reference_type.h" +#include "nodes/expr/component_ref.h" diff --git a/src/includes/nodeshandling.inc b/src/includes/nodeshandling.inc index d3ad46d..36dd043 100644 --- a/src/includes/nodeshandling.inc +++ b/src/includes/nodeshandling.inc @@ -63,3 +63,4 @@ handleNodeType(SAVE_EXPR, SaveExpr) handleNodeType(METHOD_TYPE, MethodType) handleNodeType(MUST_NOT_THROW_EXPR, MustNotThrowExpr) handleNodeType(REFERENCE_TYPE, ReferenceType) +handleNodeType(COMPONENT_REF, ComponentRef) diff --git a/src/includes/parserdefines.inc b/src/includes/parserdefines.inc index 707f9e0..8dfeb2a 100644 --- a/src/includes/parserdefines.inc +++ b/src/includes/parserdefines.inc @@ -63,3 +63,4 @@ parserDefine(SaveExpr); parserDefine(MethodType); parserDefine(MustNotThrowExpr); parserDefine(ReferenceType); +parserDefine(ComponentRef); diff --git a/src/nodes/expr/component_ref.h b/src/nodes/expr/component_ref.h new file mode 100644 index 0000000..1f39432 --- /dev/null +++ b/src/nodes/expr/component_ref.h @@ -0,0 +1,41 @@ +/* + * 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_EXPR_COMPONENTREFNODE_H +#define NODES_EXPR_COMPONENTREFNODE_H + +#include "nodes/base/expr.h" + +#include "nodes/decl/field_decl.h" + +#include <string> + +struct ComponentRefNode : public ExprNode +{ + ComponentRefNode() : + ExprNode(), + object(nullptr), + field(nullptr) + { + } + Node *object; + FieldDeclNode *field; +}; + +#endif // NODES_EXPR_COMPONENTREFNODE_H diff --git a/src/parsers/base/expr.cpp b/src/parsers/base/expr.cpp index e458366..9889a41 100644 --- a/src/parsers/base/expr.cpp +++ b/src/parsers/base/expr.cpp @@ -63,4 +63,20 @@ void fillExprOperands(ExprNode *node) } } +Node *getExprOperand(ExprNode *node, + const int pos, + const std::string &tag) +{ + if (!node || node->gccNode == NULL_TREE) + return nullptr; + const int sz = TREE_OPERAND_LENGTH(node->gccNode); + if (sz >= pos) + return nullptr; + + return createParseNode( + node, + TREE_OPERAND (node->gccNode, pos), + tag); +} + } diff --git a/src/parsers/base/expr.h b/src/parsers/base/expr.h index 9067133..33cfc33 100644 --- a/src/parsers/base/expr.h +++ b/src/parsers/base/expr.h @@ -20,6 +20,8 @@ #ifndef PARSERS_BASE_EXPR_H #define PARSERS_BASE_EXPR_H +#include <string> + struct ExprNode; struct Node; @@ -28,6 +30,10 @@ namespace Generic void fillExprLocation(Node *node); void fillExprOperands(ExprNode *node); + + Node *getExprOperand(ExprNode *node, + const int pos, + const std::string &tag); } #endif // PARSERS_BASE_EXPR_H diff --git a/src/parsers/expr/component_ref.cpp b/src/parsers/expr/component_ref.cpp new file mode 100644 index 0000000..039996c --- /dev/null +++ b/src/parsers/expr/component_ref.cpp @@ -0,0 +1,49 @@ +/* + * 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 "includes/parserincludes.h" + +parserDefine(ComponentRef); + +#include "parsers/base/expr.h" + +#include "nodes/decl/field_decl.h" + +#include "nodes/expr/component_ref.h" + +namespace Generic +{ + +void parseComponentRefNode(ComponentRefNode *node) +{ + fillType(node); + Log::dump(node); + + fillExprOperands(node); + + node->object = getExprOperand(node, 0, "object"); + node->field = static_cast<FieldDeclNode*>( + getExprOperand(node, 1, "field")); + + // args 0 object + // args 1 FIELD_DECL of member + // args 2 offset, better use component_ref_field_offset +} + +} |