1// Copyright 2019 The SwiftShader Authors. All Rights Reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15#ifndef rr_Traits_inl 16#define rr_Traits_inl 17 18namespace rr { 19 20// Non-specialized implementation of CToReactorPtr::cast() defaults to 21// returning a ConstantPointer for v. 22template<typename T, typename ENABLE> 23Pointer<Byte> CToReactorPtr<T, ENABLE>::cast(const T *v) 24{ 25 return ConstantPointer(v); 26} 27 28// CToReactorPtr specialization for T types that have a CToReactorT<> 29// specialization. 30template<typename T> 31Pointer<CToReactorT<T>> 32CToReactorPtr<T, std::enable_if_t<HasReactorType<T>::value>>::cast(const T *v) 33{ 34 return type(v); 35} 36 37// CToReactorPtr specialization for void*. 38Pointer<Byte> CToReactorPtr<void, void>::cast(const void *v) 39{ 40 return ConstantPointer(v); 41} 42 43// CToReactorPtrT specialization for function pointer types. 44template<typename T> 45Pointer<Byte> 46CToReactorPtr<T, std::enable_if_t<std::is_function<T>::value>>::cast(T *v) 47{ 48 return ConstantPointer(v); 49} 50 51// CToReactor specialization for pointer types. 52template<typename T> 53CToReactorPtrT<typename std::remove_pointer<T>::type> 54CToReactor<T, std::enable_if_t<std::is_pointer<T>::value>>::cast(T v) 55{ 56 return CToReactorPtr<elem>::cast(v); 57} 58 59// CToReactor specialization for enum types. 60template<typename T> 61CToReactorT<typename std::underlying_type<T>::type> 62CToReactor<T, std::enable_if_t<std::is_enum<T>::value>>::cast(T v) 63{ 64 return CToReactor<underlying>::cast(v); 65} 66 67} // namespace rr 68 69#endif // rr_Traits_inl 70