1 /* 2 * Copyright (C) 2016 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 #ifndef SCALAR_TYPE_H_ 18 19 #define SCALAR_TYPE_H_ 20 21 #include "Type.h" 22 23 namespace android { 24 25 struct ScalarType : public Type { 26 enum Kind { 27 KIND_BOOL, 28 KIND_INT8, 29 KIND_UINT8, 30 KIND_INT16, 31 KIND_UINT16, 32 KIND_INT32, 33 KIND_UINT32, 34 KIND_INT64, 35 KIND_UINT64, 36 KIND_FLOAT, 37 KIND_DOUBLE, 38 }; 39 40 ScalarType(Kind kind); 41 42 bool isScalar() const override; 43 44 bool isElidableType() const override; 45 const ScalarType *resolveToScalarType() const override; 46 47 bool canCheckEquality() const override; 48 49 std::string typeName() const override; 50 bool isValidEnumStorageType() const; 51 52 void addNamedTypesToSet(std::set<const FQName> &set) const override; 53 54 std::string getCppType( 55 StorageMode mode, 56 bool specifyNamespaces) const override; 57 58 std::string getJavaType(bool forInitializer) const override; 59 60 std::string getJavaWrapperType() const override; 61 std::string getJavaSuffix() const override; 62 63 std::string getVtsType() const override; 64 std::string getVtsScalarType() const; 65 66 void emitReaderWriter( 67 Formatter &out, 68 const std::string &name, 69 const std::string &parcelObj, 70 bool parcelObjIsPointer, 71 bool isReader, 72 ErrorMode mode) const override; 73 74 void emitReaderWriterWithCast( 75 Formatter &out, 76 const std::string &name, 77 const std::string &parcelObj, 78 bool parcelObjIsPointer, 79 bool isReader, 80 ErrorMode mode, 81 bool needsCast) const; 82 83 void emitHexDump( 84 Formatter &out, 85 const std::string &streamName, 86 const std::string &name) const; 87 88 void emitConvertToJavaHexString( 89 Formatter &out, 90 const std::string &name) const; 91 92 void emitJavaFieldReaderWriter( 93 Formatter &out, 94 size_t depth, 95 const std::string &parcelName, 96 const std::string &blobName, 97 const std::string &fieldName, 98 const std::string &offset, 99 bool isReader) const override; 100 101 status_t emitVtsTypeDeclarations(Formatter &out) const override; 102 103 void getAlignmentAndSize(size_t *align, size_t *size) const override; 104 105 Kind getKind() const; 106 107 private: 108 Kind mKind; 109 110 DISALLOW_COPY_AND_ASSIGN(ScalarType); 111 }; 112 113 } // namespace android 114 115 #endif // SCALAR_TYPE_H_ 116