From b93d2cb75a0e01876ab600dc3dec6a7f53d4dd8c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 13 Jun 2015 18:36:22 +0300 Subject: Fix different crash issues. --- src/analysis/function.cpp | 8 +++++-- src/nodes/decl/function_decl.h | 2 +- src/parsers/decl/function_decl.cpp | 3 +-- src/parsers/generic.cpp | 45 ++++++++++++++++++++------------------ src/parsers/type/union_type.cpp | 3 ++- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/analysis/function.cpp b/src/analysis/function.cpp index 114bb43..59406ed 100644 --- a/src/analysis/function.cpp +++ b/src/analysis/function.cpp @@ -44,8 +44,12 @@ void getFunctionArgTypes(FunctionDeclNode *node, if (!node->functionType) return; + // need impliment also for METHOD_TYPE + if (node->functionType->nodeType != FUNCTION_TYPE) + return; + // walk in TREE_LIST and get value nodes - FOR_TREE_LIST2(list, node->functionType->argTypes) + FOR_TREE_LIST2(list, static_cast(node->functionType)->argTypes) { arr.push_back(static_cast(list->value)); } @@ -109,7 +113,7 @@ void analyseFunction(FunctionDeclNode *node, const WalkItem &wi, WalkItem &wo) if (command == Command::FindArgs) Log::log("%s: ", node->label.c_str()); - int sz = node->args.size(); + size_t sz = node->args.size(); if (types.size() < sz) sz = types.size(); for (int f = 0; f < sz; f ++) diff --git a/src/nodes/decl/function_decl.h b/src/nodes/decl/function_decl.h index 9b8744d..957f911 100644 --- a/src/nodes/decl/function_decl.h +++ b/src/nodes/decl/function_decl.h @@ -50,7 +50,7 @@ struct FunctionDeclNode : public DeclNode { } - FunctionTypeNode *functionType; + TypeNode *functionType; ResultDeclNode *result; Node *code; Node *target; diff --git a/src/parsers/decl/function_decl.cpp b/src/parsers/decl/function_decl.cpp index 76f9f00..08304de 100644 --- a/src/parsers/decl/function_decl.cpp +++ b/src/parsers/decl/function_decl.cpp @@ -50,10 +50,9 @@ void parseFunctionDeclNode(FunctionDeclNode *node) return; fillDeclAttributes(node); - node->functionType = static_cast(createParseNode( + node->functionType = static_cast(createParseNode( node, TREE_TYPE(node->gccNode), - FUNCTION_TYPE, "function type")); node->result = static_cast(createParseNode( node, diff --git a/src/parsers/generic.cpp b/src/parsers/generic.cpp index 6b621b3..b2743a4 100644 --- a/src/parsers/generic.cpp +++ b/src/parsers/generic.cpp @@ -85,19 +85,6 @@ Node *createParseNode(Node *parent, node->parent = parent; node->gccNode = gccNode; node->parseChilds = parseChilds; - if (parent) - { - node->indent = parent->indent + 1; - if (tag.empty()) - node->tag = parent->tag; - else - node->tag = tag; - parent->childs.push_back(node); - } - else - { - node->tag = tag; - } if (wantType != ERROR_MARK && TREE_CODE(node->gccNode) != wantType) @@ -107,21 +94,34 @@ Node *createParseNode(Node *parent, Log::dump(node, "Wrong node type. Want %s but get %s", get_tree_code_name(wantType), - node->nodeTypeName.c_str()); + get_tree_code_name(TREE_CODE(node->gccNode))); } else { Log::dump(node, "Wrong node type. Want %s but get %s - %s", get_tree_code_name(wantType), - node->nodeTypeName.c_str(), + get_tree_code_name(TREE_CODE(node->gccNode)), tag.c_str()); } - if (!parent) - delete node; + delete node; return nullptr; } + if (parent) + { + node->indent = parent->indent + 1; + if (tag.empty()) + node->tag = parent->tag; + else + node->tag = tag; + parent->childs.push_back(node); + } + else + { + node->tag = tag; + } + switch (TREE_CODE(node->gccNode)) { #undef handleNodeType @@ -200,10 +200,13 @@ void fillLocation(Node *node) } location_t loc = DECL_SOURCE_LOCATION(node->gccNode); - node->location = loc; - node->file = LOCATION_FILE(loc); - node->line = LOCATION_LINE(loc); - node->column = LOCATION_COLUMN(loc); + if (loc) + { + node->location = loc; + node->file = LOCATION_FILE(loc); + node->line = LOCATION_LINE(loc); + node->column = LOCATION_COLUMN(loc); + } } } diff --git a/src/parsers/type/union_type.cpp b/src/parsers/type/union_type.cpp index c429f66..93e5d96 100644 --- a/src/parsers/type/union_type.cpp +++ b/src/parsers/type/union_type.cpp @@ -44,7 +44,8 @@ void parseUnionTypeNode(UnionTypeNode *node) node->methods = createParseNode( node, TYPE_METHODS(node->gccNode), - "type methods"); + "type methods", + false); } } -- cgit v1.2.3-70-g09d2