Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 1 | #include "ScalarType.h" |
| 2 | |
| 3 | #include "Formatter.h" |
| 4 | |
| 5 | namespace android { |
| 6 | |
| 7 | ScalarType::ScalarType(Kind kind) |
| 8 | : mKind(kind) { |
| 9 | } |
| 10 | |
| 11 | void ScalarType::dump(Formatter &out) const { |
| 12 | static const char *const kName[] = { |
| 13 | "char", "bool", "opaque", "int8_t", "uint8_t", "int16_t", "uint16_t", |
| 14 | "int32_t", "uint32_t", "int64_t", "uint64_t", "float", "double" |
| 15 | }; |
| 16 | out << kName[mKind]; |
| 17 | } |
| 18 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame^] | 19 | std::string ScalarType::getCppType(StorageMode, std::string *extra) const { |
| 20 | static const char *const kName[] = { |
| 21 | "char", |
| 22 | "bool", |
| 23 | "void *", |
| 24 | "int8_t", |
| 25 | "uint8_t", |
| 26 | "int16_t", |
| 27 | "uint16_t", |
| 28 | "int32_t", |
| 29 | "uint32_t", |
| 30 | "int64_t", |
| 31 | "uint64_t", |
| 32 | "float", |
| 33 | "double" |
| 34 | }; |
| 35 | |
| 36 | extra->clear(); |
| 37 | |
| 38 | return kName[mKind]; |
| 39 | } |
| 40 | |
| 41 | void ScalarType::emitReaderWriter( |
| 42 | Formatter &out, |
| 43 | const std::string &name, |
| 44 | const std::string &parcelObj, |
| 45 | bool parcelObjIsPointer, |
| 46 | bool isReader, |
| 47 | ErrorMode mode) const { |
| 48 | static const char *const kSuffix[] = { |
| 49 | "Uint8", |
| 50 | "Uint8", |
| 51 | "Pointer", |
| 52 | "Int8", |
| 53 | "Uint8", |
| 54 | "Int16", |
| 55 | "Uint16", |
| 56 | "Int32", |
| 57 | "Uint32", |
| 58 | "Int64", |
| 59 | "Uint64", |
| 60 | "Float", |
| 61 | "Double" |
| 62 | }; |
| 63 | |
| 64 | const std::string parcelObjDeref = |
| 65 | parcelObj + (parcelObjIsPointer ? "->" : "."); |
| 66 | |
| 67 | out << "_aidl_err = " |
| 68 | << parcelObjDeref |
| 69 | << (isReader ? "read" : "write") |
| 70 | << kSuffix[mKind] |
| 71 | << "("; |
| 72 | |
| 73 | if (isReader) { |
| 74 | out << "&"; |
| 75 | } |
| 76 | |
| 77 | out << name |
| 78 | << ");\n"; |
| 79 | |
| 80 | handleError(out, mode); |
| 81 | } |
| 82 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 83 | } // namespace android |
| 84 | |