[Bf-blender-cvs] [e99f72ae6d6] functions: common base class for function bodies

Jacques Lucke noreply at git.blender.org
Sun Mar 3 10:57:11 CET 2019


Commit: e99f72ae6d63eebb591fd231edc3601e1a90747c
Author: Jacques Lucke
Date:   Sun Mar 3 10:56:57 2019 +0100
Branches: functions
https://developer.blender.org/rBe99f72ae6d63eebb591fd231edc3601e1a90747c

common base class for function bodies

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

M	source/blender/functions/backends/dependencies/dependencies.hpp
M	source/blender/functions/backends/llvm/llvm_gen.hpp
M	source/blender/functions/backends/tuple_call/tuple_call.hpp
M	source/blender/functions/core/function.hpp

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

diff --git a/source/blender/functions/backends/dependencies/dependencies.hpp b/source/blender/functions/backends/dependencies/dependencies.hpp
index ed18aff0c10..0dacf8e45d5 100644
--- a/source/blender/functions/backends/dependencies/dependencies.hpp
+++ b/source/blender/functions/backends/dependencies/dependencies.hpp
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "BLI_small_set.hpp"
+#include "FN_core.hpp"
 
 struct Object;
 struct DepsNodeHandle;
@@ -24,7 +24,7 @@ namespace FN {
 			const struct OperationKeyRef *target);
 	};
 
-	class DependenciesBody {
+	class DependenciesBody : public FunctionBody {
 	public:
 		static const char *identifier_in_composition();
 		static void free_self(void *value);
diff --git a/source/blender/functions/backends/llvm/llvm_gen.hpp b/source/blender/functions/backends/llvm/llvm_gen.hpp
index 20f13698adb..f6d8ba6a3aa 100644
--- a/source/blender/functions/backends/llvm/llvm_gen.hpp
+++ b/source/blender/functions/backends/llvm/llvm_gen.hpp
@@ -7,7 +7,7 @@ namespace FN {
 
 	using LLVMValues = SmallVector<llvm::Value *>;
 
-	class LLVMGenBody {
+	class LLVMGenBody : public FunctionBody {
 	public:
 		static const char *identifier_in_composition();
 		static void free_self(void *value);
diff --git a/source/blender/functions/backends/tuple_call/tuple_call.hpp b/source/blender/functions/backends/tuple_call/tuple_call.hpp
index 115fe42ca92..33237778f29 100644
--- a/source/blender/functions/backends/tuple_call/tuple_call.hpp
+++ b/source/blender/functions/backends/tuple_call/tuple_call.hpp
@@ -4,7 +4,7 @@
 
 namespace FN {
 
-	class TupleCallBody {
+	class TupleCallBody : public FunctionBody {
 	public:
 		static const char *identifier_in_composition();
 		static void free_self(void *value);
diff --git a/source/blender/functions/core/function.hpp b/source/blender/functions/core/function.hpp
index b3d012f46a1..b45016196d4 100644
--- a/source/blender/functions/core/function.hpp
+++ b/source/blender/functions/core/function.hpp
@@ -4,6 +4,31 @@
 
 namespace FN {
 
+	class Function;
+
+	class FunctionBody {
+	private:
+		Function *m_owner = nullptr;
+
+		void set_owner(Function *fn)
+		{
+			m_owner = fn;
+		}
+
+		friend class Function;
+
+	public:
+		Function *owner()
+		{
+			return m_owner;
+		}
+
+		bool has_owner()
+		{
+			return m_owner != nullptr;
+		}
+	};
+
 	class Function final {
 	public:
 		Function(const std::string &name, const Signature &signature)
@@ -31,10 +56,13 @@ namespace FN {
 		}
 
 		template<typename T>
-		void add_body(const T *body)
+		void add_body(T *body)
 		{
+			static_assert(std::is_base_of<FunctionBody, T>::value);
 			BLI_assert(m_bodies.get<T>() == nullptr);
+			BLI_assert(!body->has_owner());
 			m_bodies.add(body);
+			body->set_owner(this);
 		}
 
 		void print() const;



More information about the Bf-blender-cvs mailing list