Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 1 | #include "Method.h" |
| 2 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame^] | 3 | #include "Annotation.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 4 | #include "Formatter.h" |
| 5 | #include "Type.h" |
| 6 | |
| 7 | namespace android { |
| 8 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame^] | 9 | Method::Method(const char *name, |
| 10 | std::vector<TypedVar *> *args, |
| 11 | std::vector<TypedVar *> *results, |
| 12 | KeyedVector<std::string, Annotation *> *annotations) |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 13 | : mName(name), |
| 14 | mArgs(args), |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame^] | 15 | mResults(results), |
| 16 | mAnnotationsByName(annotations) { |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 17 | } |
| 18 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 19 | std::string Method::name() const { |
| 20 | return mName; |
| 21 | } |
| 22 | |
| 23 | const std::vector<TypedVar *> &Method::args() const { |
| 24 | return *mArgs; |
| 25 | } |
| 26 | |
| 27 | const std::vector<TypedVar *> &Method::results() const { |
| 28 | return *mResults; |
| 29 | } |
| 30 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame^] | 31 | const KeyedVector<std::string, Annotation *> &Method::annotations() const { |
| 32 | return *mAnnotationsByName; |
| 33 | } |
| 34 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 35 | // static |
| 36 | std::string Method::GetSignature(const std::vector<TypedVar *> &args) { |
| 37 | bool first = true; |
| 38 | std::string out; |
| 39 | for (const auto &arg : args) { |
| 40 | if (!first) { |
| 41 | out += ", "; |
| 42 | } |
| 43 | |
| 44 | std::string extra; |
| 45 | out += arg->type().getCppArgumentType(&extra); |
| 46 | out += " "; |
| 47 | out += arg->name(); |
| 48 | out += extra; |
| 49 | |
| 50 | first = false; |
| 51 | } |
| 52 | |
| 53 | return out; |
| 54 | } |
| 55 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame^] | 56 | void Method::dumpAnnotations(Formatter &out) const { |
| 57 | if (mAnnotationsByName->size() == 0) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | out << "// "; |
| 62 | for (size_t i = 0; i < mAnnotationsByName->size(); ++i) { |
| 63 | if (i > 0) { |
| 64 | out << " "; |
| 65 | } |
| 66 | mAnnotationsByName->valueAt(i)->dump(out); |
| 67 | } |
| 68 | out << "\n"; |
| 69 | } |
| 70 | |
Andreas Huber | 31629bc | 2016-08-03 09:06:40 -0700 | [diff] [blame] | 71 | //////////////////////////////////////////////////////////////////////////////// |
| 72 | |
| 73 | TypedVar::TypedVar(const char *name, Type *type) |
| 74 | : mName(name), |
| 75 | mType(type) { |
| 76 | } |
| 77 | |
| 78 | std::string TypedVar::name() const { |
| 79 | return mName; |
| 80 | } |
| 81 | |
| 82 | const Type &TypedVar::type() const { |
| 83 | return *mType; |
| 84 | } |
| 85 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 86 | } // namespace android |
| 87 | |