Commit 7e11f46d by Ben Clayton

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/+/38388Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent 79afb762
...@@ -3761,4 +3761,6 @@ namespace rr ...@@ -3761,4 +3761,6 @@ namespace rr
else // ELSE_BLOCK__ else // ELSE_BLOCK__
} }
#include "Traits.inl"
#endif // rr_Reactor_hpp #endif // rr_Reactor_hpp
...@@ -304,6 +304,7 @@ ...@@ -304,6 +304,7 @@
<ClInclude Include="Routine.hpp" /> <ClInclude Include="Routine.hpp" />
<ClInclude Include="Thread.hpp" /> <ClInclude Include="Thread.hpp" />
<ClInclude Include="Traits.hpp" /> <ClInclude Include="Traits.hpp" />
<ClInclude Include="Traits.inl" />
<ClInclude Include="x86.hpp" /> <ClInclude Include="x86.hpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -74,5 +74,8 @@ ...@@ -74,5 +74,8 @@
<ClInclude Include="Traits.hpp"> <ClInclude Include="Traits.hpp">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Traits.inl">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -91,7 +91,7 @@ namespace rr ...@@ -91,7 +91,7 @@ namespace rr
template<typename T> struct CToReactorPtrT<T, typename std::enable_if< IsDefined< CToReactorT<T> >::value>::type > template<typename T> struct CToReactorPtrT<T, typename std::enable_if< IsDefined< CToReactorT<T> >::value>::type >
{ {
using type = Pointer< CToReactorT<T> >; 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. // CToReactor specialization for pointer types.
...@@ -103,7 +103,7 @@ namespace rr ...@@ -103,7 +103,7 @@ namespace rr
{ {
using elem = typename std::remove_pointer<T>::type; using elem = typename std::remove_pointer<T>::type;
using type = CToReactorPtr<elem>; 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*. // CToReactor specialization for void*.
...@@ -111,7 +111,7 @@ namespace rr ...@@ -111,7 +111,7 @@ namespace rr
template<> struct CToReactor<void*> template<> struct CToReactor<void*>
{ {
using type = Pointer<Byte>; using type = Pointer<Byte>;
static type cast(void* v); static type cast(void* v); // implemented in Reactor.cpp
}; };
// CToReactor specialization for void*. // CToReactor specialization for void*.
...@@ -119,7 +119,7 @@ namespace rr ...@@ -119,7 +119,7 @@ namespace rr
template<> struct CToReactor<const char*> template<> struct CToReactor<const char*>
{ {
using type = Pointer<Byte>; 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. // CToReactor specialization for enum types.
...@@ -128,7 +128,7 @@ namespace rr ...@@ -128,7 +128,7 @@ namespace rr
{ {
using underlying = typename std::underlying_type<T>::type; using underlying = typename std::underlying_type<T>::type;
using type = CToReactorT<underlying>; 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. // IsRValue::value is true if T is of type RValue<X>, where X is any type.
......
// 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment