Reactor: Split Traits.hpp into Traits.hpp and Traits.inl
Some templated traits need more than just the forward declaration in order to be complied:
Reactor.hpp uses the CToReactor<> templates, and some of these specializations use the
ConstantPointer() function declared in Reactor.hpp.
Without splitting this into a declaration and implementation that sandwich Reactor.hpp,
you'll get compilation errors, so include Traits.hpp at the start of Reactor.hpp, and
Traits.inl at the end.
Bug: b/143479561
Change-Id: I15c2165325633cf01c0ae7a285d1798c128499a7
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/38388
Reviewed-by: Alexis Hétu <sugoi@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
index 8b2716d..9f93adf 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -3761,4 +3761,6 @@
else // ELSE_BLOCK__
}
+#include "Traits.inl"
+
#endif // rr_Reactor_hpp
diff --git a/src/Reactor/Reactor.vcxproj b/src/Reactor/Reactor.vcxproj
index 2b96c28..9859409 100644
--- a/src/Reactor/Reactor.vcxproj
+++ b/src/Reactor/Reactor.vcxproj
@@ -304,6 +304,7 @@
<ClInclude Include="Routine.hpp" />
<ClInclude Include="Thread.hpp" />
<ClInclude Include="Traits.hpp" />
+ <ClInclude Include="Traits.inl" />
<ClInclude Include="x86.hpp" />
</ItemGroup>
<ItemGroup>
diff --git a/src/Reactor/Reactor.vcxproj.filters b/src/Reactor/Reactor.vcxproj.filters
index c7efa0b..32900aa 100644
--- a/src/Reactor/Reactor.vcxproj.filters
+++ b/src/Reactor/Reactor.vcxproj.filters
@@ -74,5 +74,8 @@
<ClInclude Include="Traits.hpp">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="Traits.inl">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
diff --git a/src/Reactor/Traits.hpp b/src/Reactor/Traits.hpp
index 1ebb37c..4636c69 100644
--- a/src/Reactor/Traits.hpp
+++ b/src/Reactor/Traits.hpp
@@ -91,7 +91,7 @@
template<typename T> struct CToReactorPtrT<T, typename std::enable_if< IsDefined< CToReactorT<T> >::value>::type >
{
using type = Pointer< CToReactorT<T> >;
- static type cast(T v) { return type(v); }
+ static inline type cast(T v); // implemented in Traits.inl
};
// CToReactor specialization for pointer types.
@@ -103,7 +103,7 @@
{
using elem = typename std::remove_pointer<T>::type;
using type = CToReactorPtr<elem>;
- static type cast(T v) { return type(v); }
+ static inline type cast(T v); // implemented in Traits.inl
};
// CToReactor specialization for void*.
@@ -111,7 +111,7 @@
template<> struct CToReactor<void*>
{
using type = Pointer<Byte>;
- static type cast(void* v);
+ static type cast(void* v); // implemented in Reactor.cpp
};
// CToReactor specialization for void*.
@@ -119,7 +119,7 @@
template<> struct CToReactor<const char*>
{
using type = Pointer<Byte>;
- static type cast(const char* v);
+ static type cast(const char* v); // implemented in Reactor.cpp
};
// CToReactor specialization for enum types.
@@ -128,7 +128,7 @@
{
using underlying = typename std::underlying_type<T>::type;
using type = CToReactorT<underlying>;
- static type cast(T v) { return type(v); }
+ static type cast(T v); // implemented in Traits.inl
};
// IsRValue::value is true if T is of type RValue<X>, where X is any type.
diff --git a/src/Reactor/Traits.inl b/src/Reactor/Traits.inl
new file mode 100644
index 0000000..6654344
--- /dev/null
+++ b/src/Reactor/Traits.inl
@@ -0,0 +1,43 @@
+// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef rr_Traits_inl
+#define rr_Traits_inl
+
+namespace rr
+{
+ template<typename T>
+ Pointer<CToReactorT<T>>
+ CToReactorPtrT<T, typename std::enable_if< IsDefined< CToReactorT<T> >::value>::type >::cast(T v)
+ {
+ return type(v);
+ }
+
+ template<typename T>
+ CToReactorPtr<typename std::remove_pointer<T>::type>
+ CToReactor<T, typename std::enable_if<std::is_pointer<T>::value>::type>::cast(T v)
+ {
+ return type(v);
+ }
+
+ template<typename T>
+ CToReactorT<typename std::underlying_type<T>::type>
+ CToReactor<T, typename std::enable_if<std::is_enum<T>::value>::type>::cast(T v)
+ {
+ return type(v);
+ }
+
+} // namespace rr
+
+#endif // rr_Traits_inl