Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 1 | #include "Type.h" |
| 2 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame^] | 3 | #include "Formatter.h" |
| 4 | |
| 5 | #include <android-base/logging.h> |
| 6 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 7 | namespace android { |
| 8 | |
| 9 | Type::Type() {} |
| 10 | Type::~Type() {} |
| 11 | |
Andreas Huber | 5345ec2 | 2016-07-29 13:33:27 -0700 | [diff] [blame] | 12 | bool Type::isScope() const { |
| 13 | return false; |
| 14 | } |
| 15 | |
Andreas Huber | a2723d2 | 2016-07-29 15:36:07 -0700 | [diff] [blame] | 16 | bool Type::isInterface() const { |
| 17 | return false; |
| 18 | } |
| 19 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame^] | 20 | std::string Type::getCppType(StorageMode, std::string *) const { |
| 21 | CHECK(!"Should not be here"); |
| 22 | return std::string(); |
| 23 | } |
| 24 | |
| 25 | void Type::emitReaderWriter( |
| 26 | Formatter &, |
| 27 | const std::string &, |
| 28 | const std::string &, |
| 29 | bool, |
| 30 | bool, |
| 31 | ErrorMode) const { |
| 32 | CHECK(!"Should not be here"); |
| 33 | } |
| 34 | |
| 35 | void Type::emitReaderWriterEmbedded( |
| 36 | Formatter &, |
| 37 | const std::string &, |
| 38 | bool, |
| 39 | const std::string &, |
| 40 | bool, |
| 41 | bool, |
| 42 | ErrorMode, |
| 43 | const std::string &, |
| 44 | const std::string &) const { |
| 45 | CHECK(!"Should not be here"); |
| 46 | } |
| 47 | |
| 48 | void Type::handleError(Formatter &out, ErrorMode mode) const { |
| 49 | switch (mode) { |
| 50 | case ErrorMode_Ignore: |
| 51 | { |
| 52 | out << "/* _aidl_err ignored! */\n\n"; |
| 53 | break; |
| 54 | } |
| 55 | |
| 56 | case ErrorMode_Goto: |
| 57 | { |
| 58 | out << "if (_aidl_err != ::android::OK) { goto _aidl_error; }\n\n"; |
| 59 | break; |
| 60 | } |
| 61 | |
| 62 | case ErrorMode_Break: |
| 63 | { |
| 64 | out << "if (_aidl_err != ::android::OK) { break; }\n\n"; |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void Type::handleError2(Formatter &out, ErrorMode mode) const { |
| 71 | switch (mode) { |
| 72 | case ErrorMode_Goto: |
| 73 | { |
| 74 | out << "goto _aidl_error;\n"; |
| 75 | break; |
| 76 | } |
| 77 | case ErrorMode_Break: |
| 78 | { |
| 79 | out << "break;\n"; |
| 80 | break; |
| 81 | } |
| 82 | case ErrorMode_Ignore: |
| 83 | { |
| 84 | out << "/* ignoring _aidl_error! */"; |
| 85 | break; |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void Type::emitReaderWriterEmbeddedForTypeName( |
| 91 | Formatter &out, |
| 92 | const std::string &name, |
| 93 | bool nameIsPointer, |
| 94 | const std::string &parcelObj, |
| 95 | bool parcelObjIsPointer, |
| 96 | bool isReader, |
| 97 | ErrorMode mode, |
| 98 | const std::string &parentName, |
| 99 | const std::string &offsetText, |
| 100 | const std::string &typeName, |
| 101 | const std::string &childName) const { |
| 102 | const std::string parcelObjDeref = |
| 103 | parcelObjIsPointer ? ("*" + parcelObj) : parcelObj; |
| 104 | |
| 105 | const std::string parcelObjPointer = |
| 106 | parcelObjIsPointer ? parcelObj : ("&" + parcelObj); |
| 107 | |
| 108 | const std::string nameDeref = name + (nameIsPointer ? "->" : "."); |
| 109 | const std::string namePointer = nameIsPointer ? name : ("&" + name); |
| 110 | |
| 111 | out << "_aidl_err = "; |
| 112 | |
| 113 | if (isReader) { |
| 114 | out << "const_cast<" |
| 115 | << typeName |
| 116 | << " *>(" |
| 117 | << namePointer |
| 118 | << ")->readEmbeddedFromParcel(\n"; |
| 119 | } else { |
| 120 | out << nameDeref |
| 121 | << "writeEmbeddedToParcel(\n"; |
| 122 | } |
| 123 | |
| 124 | out.indent(); |
| 125 | out.indent(); |
| 126 | |
| 127 | out << (isReader ? parcelObjDeref : parcelObjPointer) |
| 128 | << ",\n" |
| 129 | << parentName |
| 130 | << ",\n" |
| 131 | << offsetText; |
| 132 | |
| 133 | if (!childName.empty()) { |
| 134 | out << ", &" |
| 135 | << childName; |
| 136 | } |
| 137 | |
| 138 | out << ");\n\n"; |
| 139 | |
| 140 | out.unindent(); |
| 141 | out.unindent(); |
| 142 | |
| 143 | handleError(out, mode); |
| 144 | } |
| 145 | |
| 146 | status_t Type::emitTypeDeclarations(Formatter &) const { |
| 147 | return OK; |
| 148 | } |
| 149 | |
| 150 | status_t Type::emitTypeDefinitions( |
| 151 | Formatter &, const std::string) const { |
| 152 | return OK; |
| 153 | } |
| 154 | |
| 155 | bool Type::needsEmbeddedReadWrite() const { |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | bool Type::resultNeedsDeref() const { |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | std::string Type::getCppType(std::string *extra) const { |
| 164 | return getCppType(StorageMode_Stack, extra); |
| 165 | } |
| 166 | |
| 167 | std::string Type::getCppResultType(std::string *extra) const { |
| 168 | return getCppType(StorageMode_Result, extra); |
| 169 | } |
| 170 | |
| 171 | std::string Type::getCppArgumentType(std::string *extra) const { |
| 172 | return getCppType(StorageMode_Argument, extra); |
| 173 | } |
| 174 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 175 | } // namespace android |
| 176 | |