| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 1 | #include "generate_java.h" |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 2 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 7 | #include "code_writer.h" |
| Christopher Wiley | 775fa1f | 2015-09-22 15:00:12 -0700 | [diff] [blame] | 8 | #include "type_java.h" |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 9 | |
| 10 | namespace android { |
| 11 | namespace aidl { |
| 12 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 13 | // ================================================= |
| 14 | VariableFactory::VariableFactory(const string& base) |
| 15 | :m_base(base), |
| 16 | m_index(0) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | Variable* |
| Christopher Wiley | 8f6816e | 2015-09-22 17:03:47 -0700 | [diff] [blame^] | 21 | VariableFactory::Get(const Type* type) |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 22 | { |
| 23 | char name[100]; |
| 24 | sprintf(name, "%s%d", m_base.c_str(), m_index); |
| 25 | m_index++; |
| 26 | Variable* v = new Variable(type, name); |
| 27 | m_vars.push_back(v); |
| 28 | return v; |
| 29 | } |
| 30 | |
| 31 | Variable* |
| 32 | VariableFactory::Get(int index) |
| 33 | { |
| 34 | return m_vars[index]; |
| 35 | } |
| 36 | |
| 37 | // ================================================= |
| 38 | string |
| 39 | gather_comments(extra_text_type* extra) |
| 40 | { |
| 41 | string s; |
| 42 | while (extra) { |
| 43 | if (extra->which == SHORT_COMMENT) { |
| 44 | s += extra->data; |
| 45 | } |
| 46 | else if (extra->which == LONG_COMMENT) { |
| 47 | s += "/*"; |
| 48 | s += extra->data; |
| 49 | s += "*/"; |
| 50 | } |
| 51 | extra = extra->next; |
| 52 | } |
| 53 | return s; |
| 54 | } |
| 55 | |
| 56 | string |
| 57 | append(const char* a, const char* b) |
| 58 | { |
| 59 | string s = a; |
| 60 | s += b; |
| 61 | return s; |
| 62 | } |
| 63 | |
| 64 | // ================================================= |
| 65 | int |
| 66 | generate_java(const string& filename, const string& originalSrc, |
| 67 | interface_type* iface) |
| 68 | { |
| 69 | Class* cl; |
| 70 | |
| 71 | if (iface->document_item.item_type == INTERFACE_TYPE_BINDER) { |
| 72 | cl = generate_binder_interface_class(iface); |
| 73 | } |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 74 | |
| 75 | Document* document = new Document; |
| 76 | document->comment = ""; |
| 77 | if (iface->package) document->package = iface->package; |
| 78 | document->originalSrc = originalSrc; |
| 79 | document->classes.push_back(cl); |
| 80 | |
| Christopher Wiley | 413e042 | 2015-09-18 10:54:51 -0700 | [diff] [blame] | 81 | CodeWriterPtr code_writer = GetFileWriter(filename); |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 82 | document->Write(code_writer.get()); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 83 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 87 | } // namespace android |
| 88 | } // namespace aidl |