1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "data_type.h"
18 
19 namespace art {
20 
21 static const char* kTypeNames[] = {
22     "Reference",
23     "Bool",
24     "Uint8",
25     "Int8",
26     "Uint16",
27     "Int16",
28     "Uint32",
29     "Int32",
30     "Uint64",
31     "Int64",
32     "Float32",
33     "Float64",
34     "Void",
35 };
36 
PrettyDescriptor(Type type)37 const char* DataType::PrettyDescriptor(Type type) {
38   static_assert(arraysize(kTypeNames) == static_cast<size_t>(Type::kLast) + 1,
39                 "Missing element");
40   uint32_t uint_type = static_cast<uint32_t>(type);
41   CHECK_LE(uint_type, static_cast<uint32_t>(Type::kLast));
42   return kTypeNames[uint_type];
43 }
44 
operator <<(std::ostream & os,DataType::Type type)45 std::ostream& operator<<(std::ostream& os, DataType::Type type) {
46   uint32_t uint_type = static_cast<uint32_t>(type);
47   if (uint_type <= static_cast<uint32_t>(DataType::Type::kLast)) {
48     os << kTypeNames[uint_type];
49   } else {
50     os << "Type[" << uint_type << "]";
51   }
52   return os;
53 }
54 
55 }  // namespace art
56