summaryrefslogtreecommitdiff
path: root/src/parsers
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-03 21:36:15 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-03 22:23:13 +0300
commit342f6ec4820d3087e1c16204c7a788a165a00f48 (patch)
tree255c79f72db4809058828cc521e4899d5368cb3c /src/parsers
parentc6fde1ca0668f1ef352b615b0ba81a4eb81c0e08 (diff)
downloadparanucker-342f6ec4820d3087e1c16204c7a788a165a00f48.tar.gz
paranucker-342f6ec4820d3087e1c16204c7a788a165a00f48.tar.bz2
paranucker-342f6ec4820d3087e1c16204c7a788a165a00f48.tar.xz
paranucker-342f6ec4820d3087e1c16204c7a788a165a00f48.zip
Add tag for nodes. It allow describe parent node relation type.
Diffstat (limited to 'src/parsers')
-rw-r--r--src/parsers/functiondeclnode.cpp31
-rw-r--r--src/parsers/generic.cpp50
-rw-r--r--src/parsers/generic.h6
3 files changed, 67 insertions, 20 deletions
diff --git a/src/parsers/functiondeclnode.cpp b/src/parsers/functiondeclnode.cpp
index 548601b..fbd5919 100644
--- a/src/parsers/functiondeclnode.cpp
+++ b/src/parsers/functiondeclnode.cpp
@@ -36,20 +36,35 @@ void parseFunctionDeclNode(FunctionDeclNode *node)
fillType(node);
fillLocation(node);
Log::log(node);
- node->functionType = static_cast<FunctionTypeNode*>(
- createParseNode(node, TREE_TYPE(node->gccNode), FUNCTION_TYPE));
- node->result = static_cast<ResultDeclNode*>(
- createParseNode(node, DECL_RESULT(node->gccNode), RESULT_DECL));
+ node->functionType = static_cast<FunctionTypeNode*>(createParseNode(
+ node,
+ TREE_TYPE(node->gccNode),
+ FUNCTION_TYPE,
+ "function type"));
+ node->result = static_cast<ResultDeclNode*>(createParseNode(
+ node,
+ DECL_RESULT(node->gccNode),
+ RESULT_DECL,
+ "function result"));
FOR_CHAIN(node->gccNode, it)
{
node->args.push_back(static_cast<ParmDeclNode*>(
- createParseNode(node, it, PARM_DECL)));
+ createParseNode(node, it, PARM_DECL, "argument")));
}
- node->code = createParseNode(node, DECL_SAVED_TREE(node->gccNode));
+ node->code = createParseNode(
+ node,
+ DECL_SAVED_TREE(node->gccNode),
+ "code");
node->isAutoGenerated = DECL_ARTIFICIAL(node->gccNode);
- node->target = createParseNode(node, DECL_FUNCTION_SPECIFIC_TARGET(node->gccNode));
+ node->target = createParseNode(
+ node,
+ DECL_FUNCTION_SPECIFIC_TARGET(node->gccNode),
+ "target");
node->hasTargets = DECL_FUNCTION_VERSIONED(node->gccNode) ? true : false;
- node->optimisation = createParseNode(node, DECL_FUNCTION_SPECIFIC_OPTIMIZATION(node->gccNode));
+ node->optimisation = createParseNode(
+ node,
+ DECL_FUNCTION_SPECIFIC_OPTIMIZATION(node->gccNode),
+ "optiomisations");
node->isVirtual = DECL_VIRTUAL_P(node->gccNode);
node->isFinal = DECL_FINAL_P(node->gccNode);
}
diff --git a/src/parsers/generic.cpp b/src/parsers/generic.cpp
index 8bc4b63..8965584 100644
--- a/src/parsers/generic.cpp
+++ b/src/parsers/generic.cpp
@@ -33,12 +33,20 @@
namespace Generic
{
-Node *createParseNode(Node *parent, tree gccNode)
+Node *createParseNode(Node *parent,
+ tree gccNode,
+ std::string tag)
{
- return createParseNode(parent, gccNode, ERROR_MARK);
+ return createParseNode(parent,
+ gccNode,
+ ERROR_MARK,
+ tag);
}
-Node *createParseNode(Node *parent, tree gccNode, tree_code wantType)
+Node *createParseNode(Node *parent,
+ tree gccNode,
+ tree_code wantType,
+ std::string tag)
{
if (gccNode == NULL_TREE)
{
@@ -55,13 +63,14 @@ Node *createParseNode(Node *parent, tree gccNode, tree_code wantType)
node = new FunctionTypeNode;
break;
case RESULT_DECL:
- node = new Node;
+ node = new ResultDeclNode;
break;
default:
Log::log(parent,
1,
- "Not supported node type: %s",
- get_tree_code_name(TREE_CODE(gccNode)));
+ "Not supported node type: %s - %s",
+ get_tree_code_name(TREE_CODE(gccNode)),
+ tag.c_str());
break;
}
if (node)
@@ -69,7 +78,17 @@ Node *createParseNode(Node *parent, tree gccNode, tree_code wantType)
node->parent = parent;
node->gccNode = gccNode;
if (parent)
+ {
node->indent = parent->indent + 1;
+ if (tag.empty())
+ node->tag = parent->tag;
+ else
+ node->tag = tag;
+ }
+ else
+ {
+ node->tag = tag;
+ }
switch (TREE_CODE(node->gccNode))
{
@@ -88,10 +107,21 @@ Node *createParseNode(Node *parent, tree gccNode, tree_code wantType)
if (wantType != ERROR_MARK &&
node->nodeType != get_tree_code_name(wantType))
{
- Log::log(node,
- "Wrong node type. Want %s but get %s",
- get_tree_code_name(wantType),
- node->nodeType.c_str());
+ if (tag.empty())
+ {
+ Log::log(node,
+ "Wrong node type. Want %s but get %s",
+ get_tree_code_name(wantType),
+ node->nodeType.c_str());
+ }
+ else
+ {
+ Log::log(node,
+ "Wrong node type. Want %s but get %s - %s",
+ get_tree_code_name(wantType),
+ node->nodeType.c_str(),
+ tag.c_str());
+ }
}
}
return node;
diff --git a/src/parsers/generic.h b/src/parsers/generic.h
index 37bbb12..7ad1b25 100644
--- a/src/parsers/generic.h
+++ b/src/parsers/generic.h
@@ -37,11 +37,13 @@ namespace Generic
void fillLocation(Node *node);
Node *createParseNode(Node *parent,
- tree gccNode);
+ tree gccNode,
+ std::string tag = "");
Node *createParseNode(Node *parent,
tree gccNode,
- tree_code wantType);
+ tree_code wantType,
+ std::string tag = "");
}
#endif // PARSERS_GENERIC_H