Type.cpp revision 881227d860c59471eee31d39946e96ce2daa35d6
1#include "Type.h" 2 3#include "Formatter.h" 4 5#include <android-base/logging.h> 6 7namespace android { 8 9Type::Type() {} 10Type::~Type() {} 11 12bool Type::isScope() const { 13 return false; 14} 15 16bool Type::isInterface() const { 17 return false; 18} 19 20std::string Type::getCppType(StorageMode, std::string *) const { 21 CHECK(!"Should not be here"); 22 return std::string(); 23} 24 25void 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 35void 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 48void 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 70void 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 90void 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 146status_t Type::emitTypeDeclarations(Formatter &) const { 147 return OK; 148} 149 150status_t Type::emitTypeDefinitions( 151 Formatter &, const std::string) const { 152 return OK; 153} 154 155bool Type::needsEmbeddedReadWrite() const { 156 return false; 157} 158 159bool Type::resultNeedsDeref() const { 160 return false; 161} 162 163std::string Type::getCppType(std::string *extra) const { 164 return getCppType(StorageMode_Stack, extra); 165} 166 167std::string Type::getCppResultType(std::string *extra) const { 168 return getCppType(StorageMode_Result, extra); 169} 170 171std::string Type::getCppArgumentType(std::string *extra) const { 172 return getCppType(StorageMode_Argument, extra); 173} 174 175} // namespace android 176 177