[Bf-blender-cvs] [324537287f6] functions-experimental-refactor: initial functions2 folder

Jacques Lucke noreply at git.blender.org
Fri Nov 1 20:31:23 CET 2019


Commit: 324537287f62cd6876faf32e83f7e9795f8110c6
Author: Jacques Lucke
Date:   Fri Nov 1 19:05:09 2019 +0100
Branches: functions-experimental-refactor
https://developer.blender.org/rB324537287f62cd6876faf32e83f7e9795f8110c6

initial functions2 folder

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

M	source/blender/CMakeLists.txt
M	source/blender/functions/FN_all-c.h
M	source/blender/functions/initialize.cpp
A	source/blender/functions2/CMakeLists.txt
A	source/blender/functions2/FN_cpp_type.h
A	source/blender/functions2/FN_initialize.h
A	source/blender/functions2/intern/cpp_type.cc
A	source/blender/functions2/intern/cpp_types.cc
A	source/blender/functions2/intern/cpp_types.h
A	source/blender/functions2/intern/initialize.cc
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/intern/wm_init_exit.c
M	source/creator/CMakeLists.txt
M	source/creator/creator.c

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

diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index 98a93af93c7..4cbc31d3f1b 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -112,6 +112,7 @@ add_subdirectory(modifiers)
 add_subdirectory(gpencil_modifiers)
 add_subdirectory(shader_fx)
 add_subdirectory(functions)
+add_subdirectory(functions2)
 add_subdirectory(simulations)
 add_subdirectory(makesdna)
 add_subdirectory(makesrna)
diff --git a/source/blender/functions/FN_all-c.h b/source/blender/functions/FN_all-c.h
index b970d8be2d5..71f8e2ed387 100644
--- a/source/blender/functions/FN_all-c.h
+++ b/source/blender/functions/FN_all-c.h
@@ -11,8 +11,8 @@
 extern "C" {
 #endif
 
-void FN_initialize(void);
-void FN_exit(void);
+void FN_old_initialize(void);
+void FN_old_exit(void);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/functions/initialize.cpp b/source/blender/functions/initialize.cpp
index a7a17469c89..b2f7171c666 100644
--- a/source/blender/functions/initialize.cpp
+++ b/source/blender/functions/initialize.cpp
@@ -1,12 +1,12 @@
 #include "FN_all.hpp"
 
-void FN_initialize()
+void FN_old_initialize()
 {
   FN::initialize_llvm();
   FN::Types::initialize_types();
 }
 
-void FN_exit()
+void FN_old_exit()
 {
   FN::Types::uninitialize_types();
 }
diff --git a/source/blender/functions2/CMakeLists.txt b/source/blender/functions2/CMakeLists.txt
new file mode 100644
index 00000000000..2f07f0a9930
--- /dev/null
+++ b/source/blender/functions2/CMakeLists.txt
@@ -0,0 +1,39 @@
+set(INC
+  .
+  ../blenlib
+  ../makesdna
+  ../makesrna
+  ../blenkernel
+  ../depsgraph
+  ../windowmanager
+  ../../../intern/guardedalloc
+)
+
+set(INC_SYS
+  ${LLVM_INCLUDE_DIRS}
+  ${PYTHON_INCLUDE_DIRS}
+)
+
+if(WITH_PYTHON)
+  add_definitions(-DWITH_PYTHON)
+  list(APPEND INC
+    ../python
+  )
+endif()
+
+set(SRC
+  intern/cpp_type.cc
+  intern/cpp_types.cc
+  intern/initialize.cc
+
+  FN_cpp_type.h
+  FN_initialize.h
+
+  intern/cpp_types.h
+)
+
+set(LIB
+  bf_blenlib
+)
+
+blender_add_lib(bf_functions2 "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/functions2/FN_cpp_type.h b/source/blender/functions2/FN_cpp_type.h
new file mode 100644
index 00000000000..8ab1e9f5ce4
--- /dev/null
+++ b/source/blender/functions2/FN_cpp_type.h
@@ -0,0 +1,160 @@
+#ifndef __FN_CPP_TYPE_H__
+#define __FN_CPP_TYPE_H__
+
+#include "BLI_string_ref.h"
+#include "BLI_utility_mixins.h"
+#include "BLI_vector.h"
+
+namespace FN {
+
+using BLI::StringRef;
+using BLI::StringRefNull;
+
+class CPPType {
+ public:
+  using ConstructDefaultF = void (*)(const CPPType *self, void *ptr);
+  using DestructF = void (*)(void *ptr);
+  using CopyToInitializedF = void (*)(const void *src, void *dst);
+  using CopyToUninitializedF = void (*)(const void *src, void *dst);
+  using RelocateToInitializedF = void (*)(void *src, void *dst);
+  using RelocateToUninitializedF = void (*)(void *src, void *dst);
+
+  CPPType(std::string name,
+          uint size,
+          uint alignment,
+          bool trivially_destructible,
+          ConstructDefaultF construct_default,
+          DestructF destruct,
+          CopyToInitializedF copy_to_initialized,
+          CopyToUninitializedF copy_to_uninitialized,
+          RelocateToInitializedF relocate_to_initialized,
+          RelocateToUninitializedF relocate_to_uninitialized,
+          const CPPType *generalization)
+      : m_size(size),
+        m_alignment(alignment),
+        m_trivially_destructible(trivially_destructible),
+        m_construct_default(construct_default),
+        m_destruct(destruct),
+        m_copy_to_initialized(copy_to_initialized),
+        m_copy_to_uninitialized(copy_to_uninitialized),
+        m_relocate_to_initialized(relocate_to_initialized),
+        m_relocate_to_uninitialized(relocate_to_uninitialized),
+        m_generalization(generalization),
+        m_name(name)
+  {
+    BLI_assert(is_power_of_2_i(m_alignment));
+    BLI_assert(generalization == nullptr ||
+               (generalization->size() == size && generalization->alignment() <= alignment));
+
+    m_alignment_mask = m_alignment - 1;
+  }
+
+  virtual ~CPPType();
+
+  StringRefNull name() const
+  {
+    return m_name;
+  }
+
+  uint size() const
+  {
+    return m_size;
+  }
+
+  uint alignment() const
+  {
+    return m_alignment;
+  }
+
+  const CPPType *generalization() const
+  {
+    return m_generalization;
+  }
+
+  bool trivially_destructible() const
+  {
+    return m_trivially_destructible;
+  }
+
+  bool pointer_has_valid_alignment(const void *ptr) const
+  {
+    return (POINTER_AS_UINT(ptr) & m_alignment_mask) == 0;
+  }
+
+  void construct_default(void *ptr) const
+  {
+    BLI_assert(this->pointer_has_valid_alignment(ptr));
+
+    m_construct_default(this, ptr);
+  }
+
+  void destruct(void *ptr) const
+  {
+    BLI_assert(this->pointer_has_valid_alignment(ptr));
+
+    m_destruct(ptr);
+  }
+
+  void copy_to_initialized(const void *src, void *dst) const
+  {
+    BLI_assert(this->pointer_has_valid_alignment(src));
+    BLI_assert(this->pointer_has_valid_alignment(dst));
+
+    m_copy_to_initialized(src, dst);
+  }
+
+  void copy_to_uninitialized(const void *src, void *dst) const
+  {
+    BLI_assert(this->pointer_has_valid_alignment(src));
+    BLI_assert(this->pointer_has_valid_alignment(dst));
+
+    m_copy_to_uninitialized(src, dst);
+  }
+
+  void relocate_to_initialized(void *src, void *dst) const
+  {
+    BLI_assert(this->pointer_has_valid_alignment(src));
+    BLI_assert(this->pointer_has_valid_alignment(dst));
+
+    m_relocate_to_initialized(src, dst);
+  }
+
+  void relocate_to_uninitialized(void *src, void *dst) const
+  {
+    BLI_assert(this->pointer_has_valid_alignment(src));
+    BLI_assert(this->pointer_has_valid_alignment(dst));
+
+    m_relocate_to_uninitialized(src, dst);
+  }
+
+  bool is_same_or_generalization(const CPPType &other) const
+  {
+    if (&other == this) {
+      return true;
+    }
+    if (m_generalization == nullptr) {
+      return false;
+    }
+    return m_generalization->is_same_or_generalization(other);
+  }
+
+ private:
+  uint m_size;
+  uint m_alignment;
+  uint m_alignment_mask;
+  bool m_trivially_destructible;
+  ConstructDefaultF m_construct_default;
+  DestructF m_destruct;
+  CopyToInitializedF m_copy_to_initialized;
+  CopyToUninitializedF m_copy_to_uninitialized;
+  RelocateToInitializedF m_relocate_to_initialized;
+  RelocateToUninitializedF m_relocate_to_uninitialized;
+  const CPPType *m_generalization;
+  std::string m_name;
+};
+
+template<typename T> const CPPType &GET_TYPE();
+
+}  // namespace FN
+
+#endif /* __FN_CPP_TYPE_H__ */
diff --git a/source/blender/functions2/FN_initialize.h b/source/blender/functions2/FN_initialize.h
new file mode 100644
index 00000000000..10e8a68f02d
--- /dev/null
+++ b/source/blender/functions2/FN_initialize.h
@@ -0,0 +1,10 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void FN_initialize(void);
+void FN_exit(void);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/functions2/intern/cpp_type.cc b/source/blender/functions2/intern/cpp_type.cc
new file mode 100644
index 00000000000..2e04b405a22
--- /dev/null
+++ b/source/blender/functions2/intern/cpp_type.cc
@@ -0,0 +1,9 @@
+#include "FN_cpp_type.h"
+
+namespace FN {
+
+CPPType::~CPPType()
+{
+}
+
+}  // namespace FN
diff --git a/source/blender/functions2/intern/cpp_types.cc b/source/blender/functions2/intern/cpp_types.cc
new file mode 100644
index 00000000000..54d78882991
--- /dev/null
+++ b/source/blender/functions2/intern/cpp_types.cc
@@ -0,0 +1,120 @@
+#include "FN_cpp_type.h"
+#include "cpp_types.h"
+
+#include "DNA_object_types.h"
+
+#include "BLI_math_cxx.h"
+#include "BLI_vector.h"
+
+namespace FN {
+
+using BLI::Vector;
+
+static Vector<CPPType *, 4, BLI::RawAllocator> allocated_types;
+
+void free_cpp_types()
+{
+  for (CPPType *type : allocated_types) {
+    delete type;
+  }
+}
+
+template<typename T> void ConstructDefault_CB(const CPPType *UNUSED(self), void *ptr)
+{
+  BLI::construct_default((T *)ptr);
+}
+
+template<typename T, bool IsDefaultConstructible> struct DefaultConstructor;
+template<typename T> struct DefaultConstructor<T, true> {
+  static CPPType::ConstructDefaultF get_callback()
+  {
+    return ConstructDefault_CB<T>;
+  }
+};
+template<typename T> struct DefaultConstructor<T, false> {
+  static CPPType::ConstructDefaultF get_callback()
+  {
+    return nullptr;
+  }
+};
+
+template<typename T> void Destruct_CB(void *ptr)
+{
+  BLI::destruct((T *)ptr);
+}
+template<typename T> void CopyToInitialized_CB(const void *src, void *dst)
+{
+  *(T *)dst = *(T *)src;
+}
+template<typename T> void CopyToUninitialized_CB(const void *src, void *dst)
+{
+  BLI::uninitialized_copy_n((T *)src, 1, (T *)dst);
+}
+template<typename T> void RelocateToInitialized_CB(void *src, void *dst)
+{
+  BLI::relocate((T *)src, (T *)dst);
+}
+template<typename T> void RelocateToUninitialized_CB(void *src, void *dst)
+{
+  BLI::uninitialized_relocate((T *)src, (T *)dst);
+}
+
+#define CPP_TYPE_DECLARE(IDENTIFIER) static CPPType *TYPE_##IDENTIFIER = nullptr
+
+CPP_TYPE_DECLARE(float);
+CPP_TYPE_DECLARE(bool);
+CPP_TYPE_DECLARE(ObjectPtr);
+CPP_TYPE_DECLARE(int32);
+CPP_TYPE_DECLARE(rgba_f);
+CPP_TYPE_DECLARE(float3);
+CPP_TYPE_DECLARE(string);
+
+#undef CPP_TYPE_DECLARE
+
+void init_cpp_types()
+{
+
+#define CPP_TYPE_CONSTRUCTION(IDENTIFIER, TYPE_NAME) \
+  TYPE_##IDENTIFIER = new CPPType( \
+      STRINGIFY(IDENTIFIER), \
+      sizeof(TYPE_NAME), \
+      alignof(TYPE_NAME), \
+      std::is_trivially_destructible<TYPE_NAME>::value, \
+      DefaultConstructor<TYPE_NAME, \
+                         std::is_default_constructible<TYPE_NAME>::value>::get_callback(), \
+      Destruct_CB<TYPE_NAME>, \
+      CopyToInitialized_CB<TYPE_NAME>, \
+      CopyToUninitialized_CB<TYPE_NAME>, \
+      RelocateToInitialized_CB<TYPE_NAME>, \
+      RelocateToUninitialized_CB<TYPE_NAME>, \
+      nullptr); \
+  allocated_types.append(TYPE_##IDENTIFIER)
+
+  CPP_TYPE_CONSTRUCTION(float, float);
+  CPP_TYPE_CONSTRUCTION(bool, bool);
+  CPP_TYPE_CONSTRUCTION(ObjectPtr, Object *);
+  CPP_TYPE_CONSTRUCTION(int32, int32_t);
+  CPP_TYPE_CONSTRUCTION(rgba_f, BLI::rgba_f);
+  CPP_TYPE_CO

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list