summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.files1
-rw-r--r--src/analysis/analysis.cpp19
-rw-r--r--src/analysis/analysis.h7
-rw-r--r--src/analysis/function.cpp23
-rw-r--r--src/analysis/function.h3
-rw-r--r--src/analysis/walkitem.h39
-rw-r--r--src/plugin.cpp2
7 files changed, 81 insertions, 13 deletions
diff --git a/src/Makefile.files b/src/Makefile.files
index b338808..4e4f055 100644
--- a/src/Makefile.files
+++ b/src/Makefile.files
@@ -2,6 +2,7 @@ SRC = analysis/analysis.cpp \
analysis/analysis.h \
analysis/function.cpp \
analysis/function.h \
+ analysis/walkitem.h \
nodes/base/cst.h \
nodes/base/decl.h \
nodes/base/expr.h \
diff --git a/src/analysis/analysis.cpp b/src/analysis/analysis.cpp
index fa1672c..3221ccf 100644
--- a/src/analysis/analysis.cpp
+++ b/src/analysis/analysis.cpp
@@ -22,6 +22,7 @@
#include "command.h"
#include "analysis/function.h"
+#include "analysis/walkitem.h"
#include "nodes/decl/function_decl.h"
@@ -30,23 +31,31 @@
namespace Analysis
{
-void walkTree(Node *node)
+void startWalkTree(Node *node)
{
- analyseNode(node);
+ walkTree(node, WalkItem());
+}
+
+void walkTree(Node *node, WalkItem wi)
+{
+ wi = analyseNode(node, wi);
+ if (wi.stopWalking)
+ return;
FOR_EACH (std::vector<Node*>::iterator, it, node->childs)
{
- walkTree(*it);
+ walkTree(*it, wi);
}
}
-void analyseNode(Node *node)
+WalkItem analyseNode(Node *node, WalkItem wi)
{
// searching function declaration
if (node->nodeType == FUNCTION_DECL)
{
- analyseFunction(static_cast<FunctionDeclNode*>(node));
+ return analyseFunction(static_cast<FunctionDeclNode*>(node), wi);
}
+ return wi;
}
}
diff --git a/src/analysis/analysis.h b/src/analysis/analysis.h
index 64ecffd..641ada9 100644
--- a/src/analysis/analysis.h
+++ b/src/analysis/analysis.h
@@ -23,12 +23,15 @@
#include "includes.h"
struct Node;
+struct WalkItem;
namespace Analysis
{
- void walkTree(Node *node);
+ void startWalkTree(Node *node);
- void analyseNode(Node *node);
+ void walkTree(Node *node, WalkItem wi);
+
+ WalkItem analyseNode(Node *node, WalkItem wi);
}
#endif // ANALYSIS_ANALYSIS_H
diff --git a/src/analysis/function.cpp b/src/analysis/function.cpp
index fb48231..3b9473a 100644
--- a/src/analysis/function.cpp
+++ b/src/analysis/function.cpp
@@ -22,6 +22,9 @@
#include "command.h"
#include "logger.h"
+#include "analysis/analysis.h"
+#include "analysis/walkitem.h"
+
#include "nodes/decl/function_decl.h"
#include "nodes/list/tree_list.h"
@@ -86,18 +89,23 @@ void getFunctionParamsNonNullAttributes(FunctionDeclNode *node,
}
}
-void analyseFunction(FunctionDeclNode *node)
+WalkItem analyseFunction(FunctionDeclNode *node, WalkItem wi)
{
// ignore external functions
if (node->isExternal)
- return;
+ {
+ wi.stopWalking = true;
+ return wi;
+ }
std::vector<TypeNode*> types;
std::set<int> nonNull;
- std::set<std::string> checkNames;
+ WalkItem wi2 = wi;
getFunctionArgTypes(node, types);
getFunctionParamsNonNullAttributes(node, nonNull);
+ // here need check is variables already present in wi2.checkNullVars
+
if (command == Command::FindArgs)
{
Log::log("%s: ", node->label.c_str());
@@ -113,11 +121,18 @@ void analyseFunction(FunctionDeclNode *node)
Log::log("%s %s, ",
type->nodeTypeName.c_str(),
name->label.c_str());
- checkNames.insert(name->label);
+ wi2.checkNullVars.insert(name->label);
}
}
Log::log("\n");
}
+
+ if (!wi2.checkNullVars.empty())
+ {
+ walkTree(node->code, wi2);
+ }
+ wi.stopWalking = true;
+ return wi;
}
}
diff --git a/src/analysis/function.h b/src/analysis/function.h
index 4e1ded5..9ff3e0f 100644
--- a/src/analysis/function.h
+++ b/src/analysis/function.h
@@ -25,10 +25,11 @@
struct FunctionDeclNode;
struct TreeListNode;
struct TypeNode;
+struct WalkItem;
namespace Analysis
{
- void analyseFunction(FunctionDeclNode *node);
+ WalkItem analyseFunction(FunctionDeclNode *node, WalkItem wi);
void getFunctionArgTypes(FunctionDeclNode *node,
std::vector<TypeNode*> &arr);
diff --git a/src/analysis/walkitem.h b/src/analysis/walkitem.h
new file mode 100644
index 0000000..dee65dc
--- /dev/null
+++ b/src/analysis/walkitem.h
@@ -0,0 +1,39 @@
+/*
+ * 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 ANALYSIS_WALKITEM_H
+#define ANALYSIS_WALKITEM_H
+
+#include <set>
+#include <string>
+
+struct WalkItem
+{
+ WalkItem() :
+ checkNullVars(),
+ stopWalking(false)
+ {
+ }
+
+ std::set<std::string> checkNullVars;
+ bool stopWalking;
+};
+
+
+#endif // ANALYSIS_WALKITEM_H
diff --git a/src/plugin.cpp b/src/plugin.cpp
index ffd86f9..04715f0 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -42,7 +42,7 @@ static void pre_generic(void *gcc_data,
{
Node *node = Generic::parseNodes((tree)gcc_data);
if (command == Command::FindArgs)
- Analysis::walkTree(node);
+ Analysis::startWalkTree(node);
Generic::cleanAllNodes(node);
}