[Bf-blender-cvs] [024247797f6] functions: keep track of original nodes

Jacques Lucke noreply at git.blender.org
Tue Mar 26 11:22:20 CET 2019


Commit: 024247797f60adfb39b8307d2f4e09573067ef85
Author: Jacques Lucke
Date:   Tue Mar 26 10:33:10 2019 +0100
Branches: functions
https://developer.blender.org/rB024247797f60adfb39b8307d2f4e09573067ef85

keep track of original nodes

===================================================================

M	source/blender/functions/backends/tuple_call/execution_context.cpp
M	source/blender/functions/backends/tuple_call/execution_context.hpp
M	source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
M	source/blender/functions/c_wrapper.cpp
M	source/blender/functions/core/data_flow_graph.hpp
M	source/blender/functions/frontends/data_flow_nodes/builder.cpp
M	source/blender/functions/frontends/data_flow_nodes/builder.hpp
M	source/blender/functions/frontends/data_flow_nodes/inserters.cpp
M	source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp

===================================================================

diff --git a/source/blender/functions/backends/tuple_call/execution_context.cpp b/source/blender/functions/backends/tuple_call/execution_context.cpp
index 9ca4a219957..147e111c48b 100644
--- a/source/blender/functions/backends/tuple_call/execution_context.cpp
+++ b/source/blender/functions/backends/tuple_call/execution_context.cpp
@@ -5,8 +5,8 @@ namespace FN {
 	void ExecutionStack::print_traceback() const
 	{
 		std::cout << "Traceback:" << std::endl;
-		for (const char *info : m_stack) {
-			std::cout << " > " << info << std::endl;
+		for (StackFrame *frame : m_stack) {
+			std::cout << " > " << frame->to_string() << std::endl;
 		}
 	}
 
diff --git a/source/blender/functions/backends/tuple_call/execution_context.hpp b/source/blender/functions/backends/tuple_call/execution_context.hpp
index f83d8dea2f6..c051ba1a92b 100644
--- a/source/blender/functions/backends/tuple_call/execution_context.hpp
+++ b/source/blender/functions/backends/tuple_call/execution_context.hpp
@@ -4,16 +4,64 @@
 
 namespace FN {
 
+	class StackFrame {
+	public:
+		virtual std::string to_string() const = 0;
+	};
+
+	class SourceInfoStackFrame : public StackFrame {
+	private:
+		SourceInfo *m_source;
+
+	public:
+		SourceInfoStackFrame(SourceInfo *source)
+			: m_source(source) {}
+
+		SourceInfo *source() const
+		{
+			return m_source;
+		}
+
+		std::string to_string() const override
+		{
+			if (m_source == nullptr) {
+				return "<unknown source>";
+			} else {
+				return m_source->to_string();
+			}
+		}
+	};
+
+	class TextStackFrame : public StackFrame {
+	private:
+		const char *m_text;
+
+	public:
+		TextStackFrame(const char *text)
+			: m_text(text) {}
+
+		const char *text() const
+		{
+			return m_text;
+		}
+
+		std::string to_string() const override
+		{
+			return std::string(m_text);
+		}
+	};
+
+
 	class ExecutionStack {
 	private:
-		SmallStack<const char *> m_stack;
+		SmallStack<StackFrame *> m_stack;
 
 	public:
 		ExecutionStack() = default;
 
-		void push(const char *info)
+		void push(StackFrame *frame)
 		{
-			m_stack.push(info);
+			m_stack.push(frame);
 		}
 
 		void pop()
diff --git a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
index fc9233ee679..9ebaf2575a5 100644
--- a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
+++ b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
@@ -401,9 +401,13 @@ namespace FN {
 					this->compute_socket(fn_in, tmp_in, i, node->input(i), ctx);
 				}
 
-				ctx.stack().push(fn->name().c_str());
+				SourceInfoStackFrame node_frame(node->source());
+				TextStackFrame function_frame(fn->name().c_str());
+				ctx.stack().push(&node_frame);
+				ctx.stack().push(&function_frame);
 				body->call(tmp_in, tmp_out, ctx);
 				ctx.stack().pop();
+				ctx.stack().pop();
 
 				Tuple::copy_element(tmp_out, socket.index(), out, out_index);
 			}
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index a15781baf55..e0324605424 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -149,7 +149,8 @@ void FN_tuple_call_invoke(FnTupleCallBody body, FnTuple fn_in, FnTuple fn_out)
 
 	BLI_assert(fn_in_.all_initialized());
 	ExecutionStack stack;
-	stack.push(body_->owner()->name().c_str());
+	TextStackFrame function_frame(body_->owner()->name().c_str());
+	stack.push(&function_frame);
 	ExecutionContext ctx(stack);
 	body_->call(fn_in_, fn_out_, ctx);
 	BLI_assert(fn_out_.all_initialized());
diff --git a/source/blender/functions/core/data_flow_graph.hpp b/source/blender/functions/core/data_flow_graph.hpp
index 60c700010f4..3b60f425553 100644
--- a/source/blender/functions/core/data_flow_graph.hpp
+++ b/source/blender/functions/core/data_flow_graph.hpp
@@ -112,6 +112,11 @@ namespace FN {
 			return this->signature().outputs().size();
 		}
 
+		SourceInfo *source() const
+		{
+			return m_source;
+		}
+
 		class SocketIterator {
 		private:
 			Node *m_node;
diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.cpp b/source/blender/functions/frontends/data_flow_nodes/builder.cpp
index 502d45e3ba2..f8120f43a81 100644
--- a/source/blender/functions/frontends/data_flow_nodes/builder.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/builder.cpp
@@ -8,11 +8,34 @@
 
 namespace FN { namespace DataFlowNodes {
 
+	class NodeSource : public SourceInfo {
+	private:
+		bNodeTree *m_btree;
+		bNode *m_bnode;
+
+	public:
+		NodeSource(bNodeTree *btree, bNode *bnode)
+			: m_btree(btree), m_bnode(bnode) {}
+
+		std::string to_string() const override
+		{
+			return m_btree->id.name + std::string(" : ") + m_bnode->name;
+		}
+	};
+
 	Node *Builder::insert_function(SharedFunction &function)
 	{
 		return m_graph->insert(function);
 	}
 
+	Node *Builder::insert_function(SharedFunction &function, bNodeTree *btree, bNode *bnode)
+	{
+		BLI_assert(btree != nullptr);
+		BLI_assert(bnode != nullptr);
+		NodeSource *source = new NodeSource(btree, bnode);
+		return m_graph->insert(function, source);
+	}
+
 	void Builder::insert_link(Socket a, Socket b)
 	{
 		m_graph->link(a, b);
diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.hpp b/source/blender/functions/frontends/data_flow_nodes/builder.hpp
index e3c4e0e7abd..89690bc9e06 100644
--- a/source/blender/functions/frontends/data_flow_nodes/builder.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/builder.hpp
@@ -28,6 +28,7 @@ namespace FN { namespace DataFlowNodes {
 			: m_graph(graph), m_socket_map(socket_map) {}
 
 		Node *insert_function(SharedFunction &function);
+		Node *insert_function(SharedFunction &function, struct bNodeTree *btree, struct bNode *bnode);
 		void insert_link(Socket a, Socket b);
 
 		void map_socket(Socket socket, struct bNodeSocket *bsocket);
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
index dab4366f34b..56b8ed81130 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
@@ -33,11 +33,11 @@ namespace FN { namespace DataFlowNodes {
 	{
 		auto inserter = [getter](
 				Builder &builder,
-				const BuilderContext &UNUSED(ctx),
+				const BuilderContext &ctx,
 				bNode *bnode)
 			{
 				SharedFunction fn = getter();
-				Node *node = builder.insert_function(fn);
+				Node *node = builder.insert_function(fn, ctx.btree(), bnode);
 				builder.map_sockets(node, bnode);
 			};
 		this->reg_node_inserter(idname, inserter);
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
index 77dcbb53fa6..2c758fdb23a 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
@@ -22,7 +22,7 @@ namespace FN { namespace DataFlowNodes {
 		Object *object = (Object *)RNA_pointer_get(&ptr, "object").id.data;
 
 		auto fn = Functions::object_location(object);
-		Node *node = builder.insert_function(fn);
+		Node *node = builder.insert_function(fn, ctx.btree(), bnode);
 		builder.map_sockets(node, bnode);
 	}
 
@@ -50,20 +50,20 @@ namespace FN { namespace DataFlowNodes {
 		int operation = RNA_enum_get(&ptr, "operation");
 
 		SharedFunction &fn = get_float_math_function(operation);
-		Node *node = builder.insert_function(fn);
+		Node *node = builder.insert_function(fn, ctx.btree(), bnode);
 		builder.map_sockets(node, bnode);
 	}
 
 	static void insert_clamp_node(
 		Builder &builder,
-		const BuilderContext &UNUSED(ctx),
+		const BuilderContext &ctx,
 		bNode *bnode)
 	{
 		SharedFunction &max_fn = Functions::max_floats();
 		SharedFunction &min_fn = Functions::min_floats();
 
-		Node *max_node = builder.insert_function(max_fn);
-		Node *min_node = builder.insert_function(min_fn);
+		Node *max_node = builder.insert_function(max_fn, ctx.btree(), bnode);
+		Node *min_node = builder.insert_function(min_fn, ctx.btree(), bnode);
 
 		builder.insert_link(max_node->output(0), min_node->input(0));
 		builder.map_input(max_node->input(0), bnode, 0);
@@ -79,7 +79,7 @@ namespace FN { namespace DataFlowNodes {
 	{
 		SharedType &base_type = ctx.type_from_rna(bnode, "active_type");
 		SharedFunction &fn = Functions::get_list_element(base_type);
-		Node *node = builder.insert_function(fn);
+		Node *node = builder.insert_function(fn, ctx.btree(), bnode);
 		builder.map_sockets(node, bnode);
 	}
 
@@ -91,7 +91,7 @@ namespace FN { namespace DataFlowNodes {
 		SharedType &base_type = ctx.type_from_rna(bnode, "active_type");
 
 		auto &empty_fn = Functions::empty_list(base_type);
-		Node *node = builder.insert_function(empty_fn);
+		Node *node = builder.insert_function(empty_fn, ctx.btree(), bnode);
 
 		PointerRNA ptr;
 		ctx.get_rna(bnode, &ptr);
@@ -104,14 +104,14 @@ namespace FN { namespace DataFlowNodes {
 			if (state == 0) {
 				/* single value case */
 				auto &append_fn = Functions::append_to_list(base_type);
-				new_node = builder.insert_function(append_fn);
+				new_node = builder.insert_function(append_fn, ctx.btree(), bnode);
 				builder.insert_link(node->output(0), new_node->input(0));
 				builder.map_input(new_node->input(1), bnode, index);
 			}
 			else if (state == 1) {
 				/* list case */
 				auto &combine_fn = Functions::combine_lists(base_type);
-				new_node = builder.insert_function(combine_fn);
+				new_node = builder.insert_function(combine_fn, ctx.btree(), bnode);
 				builder.insert_link(node->output(0), new_node->input(0));
 				builder.map_input(new_node->input(1), bnode, index);
 			}
@@ -147,7 +147,7 @@ namespace FN { namespace DataFlowNodes {
 		Optional<SharedFunction> fn = generate_function(btree);
 		BLI_assert(fn.has_value());
 
-		Node *node = builder.insert_function(fn.value());
+		Node *node = builder.insert_function(fn.value(), ctx.btree(), bnode);
 		builder.map_sockets(node, bnode);
 	}



More information about the Bf-blender-cvs mailing list