diff options
author | Casey Dahlin <sadmac@google.com> | 2015-10-07 18:49:10 -0700 |
---|---|---|
committer | Casey Dahlin <sadmac@google.com> | 2015-10-09 17:08:30 -0700 |
commit | 1ae2bc56d20fe0e19262f2721abc338662fa6e30 (patch) | |
tree | 4072b94d3e6c9683b4455239504952249a8c9e75 | |
parent | 0edf34239909bbc16e884ea2517e5f3398185d0f (diff) | |
download | android_system_tools_aidl-1ae2bc56d20fe0e19262f2721abc338662fa6e30.tar.gz android_system_tools_aidl-1ae2bc56d20fe0e19262f2721abc338662fa6e30.tar.bz2 android_system_tools_aidl-1ae2bc56d20fe0e19262f2721abc338662fa6e30.zip |
Convert document item structs to classes
This is the least-complete first run for any of these structs, but this
shift is going to be particularly gnarly, so we need to be
extra-incremental about it.
Change-Id: I7295add8b9a1291f229743f8c36d941569a16ab6
Test: unit tests
Bug: 24410295
Signed-off-by: Casey Dahlin <sadmac@google.com>
-rw-r--r-- | aidl.cpp | 58 | ||||
-rw-r--r-- | aidl.h | 2 | ||||
-rw-r--r-- | aidl_language.h | 74 | ||||
-rw-r--r-- | aidl_language_y.y | 197 | ||||
-rw-r--r-- | generate_cpp.cpp | 16 | ||||
-rw-r--r-- | generate_cpp.h | 2 | ||||
-rw-r--r-- | generate_cpp_unittest.cpp | 16 | ||||
-rw-r--r-- | generate_java.cpp | 4 | ||||
-rw-r--r-- | generate_java.h | 4 | ||||
-rw-r--r-- | generate_java_binder.cpp | 2 | ||||
-rw-r--r-- | type_cpp.cpp | 4 | ||||
-rw-r--r-- | type_cpp.h | 4 | ||||
-rw-r--r-- | type_java.cpp | 4 | ||||
-rw-r--r-- | type_java.h | 4 | ||||
-rw-r--r-- | type_java_unittest.cpp | 7 | ||||
-rw-r--r-- | type_namespace.h | 4 |
16 files changed, 195 insertions, 207 deletions
@@ -146,15 +146,15 @@ int check_filename(const std::string& filename, return 0; } -int check_filenames(const std::string& filename, const document_item_type* items) { +int check_filenames(const std::string& filename, const AidlDocumentItem* items) { int err = 0; while (items) { if (items->item_type == USER_DATA_TYPE) { - user_data_type* p = (user_data_type*)items; + const AidlParcelable* p = reinterpret_cast<const AidlParcelable*>(items); err |= check_filename(filename, p->package, &p->name); } else if (items->item_type == INTERFACE_TYPE_BINDER) { - interface_type* c = (interface_type*)items; + const AidlInterface* c = reinterpret_cast<const AidlInterface*>(items); err |= check_filename(filename, c->package, &c->name); } else { @@ -179,16 +179,16 @@ char* rfind(char* str, char c) { } bool gather_types(const std::string& filename, - const document_item_type* all_items, + const AidlDocumentItem* all_items, TypeNamespace* types) { bool success = true; - for (const document_item_type* item = all_items; item; item = item->next) { + for (const AidlDocumentItem* item = all_items; item; item = item->next) { if (item->item_type == USER_DATA_TYPE) { - user_data_type* p = (user_data_type*)item; + AidlParcelable* p = (AidlParcelable*)item; success &= types->AddParcelableType(p, filename); } else if (item->item_type == INTERFACE_TYPE_BINDER) { - interface_type* c = (interface_type*)item; + AidlInterface* c = (AidlInterface*)item; success &= types->AddBinderType(c, filename); } else { LOG(FATAL) << "internal error"; @@ -198,7 +198,7 @@ bool gather_types(const std::string& filename, } int check_types(const string& filename, - interface_type* c, + AidlInterface* c, TypeNamespace* types) { int err = 0; @@ -234,7 +234,7 @@ int check_types(const string& filename, } void generate_dep_file(const JavaOptions& options, - const document_item_type* items, + const AidlDocumentItem* items, const std::vector<std::unique_ptr<AidlImport>>& imports) { /* we open the file in binary mode to ensure that the same output is * generated on all platforms !! @@ -333,14 +333,14 @@ string generate_outputFileName2(const JavaOptions& options, } string generate_outputFileName(const JavaOptions& options, - const document_item_type* items) { + const AidlDocumentItem* items) { // items has already been checked to have only one interface. if (items->item_type == INTERFACE_TYPE_BINDER) { - interface_type* type = (interface_type*)items; + AidlInterface* type = (AidlInterface*)items; return generate_outputFileName2(options, type->name, type->package); } else if (items->item_type == USER_DATA_TYPE) { - user_data_type* type = (user_data_type*)items; + AidlParcelable* type = (AidlParcelable*)items; return generate_outputFileName2(options, type->name, type->package); } @@ -400,12 +400,11 @@ int parse_preprocessed_file(const string& filename, TypeNamespace* types) { //printf("%s:%d:...%s...%s...%s...\n", filename.c_str(), lineno, // type, packagename, classname); - document_item_type* doc; + AidlDocumentItem* doc; if (0 == strcmp("parcelable", type)) { - user_data_type* parcl = new user_data_type(); - memset(parcl, 0, sizeof(user_data_type)); - parcl->document_item.item_type = USER_DATA_TYPE; + AidlParcelable* parcl = new AidlParcelable(); + parcl->item_type = USER_DATA_TYPE; parcl->keyword_token.lineno = lineno; parcl->keyword_token.data = cpp_strdup(type); parcl->package = packagename ? cpp_strdup(packagename) : NULL; @@ -414,12 +413,11 @@ int parse_preprocessed_file(const string& filename, TypeNamespace* types) { parcl->semicolon_token.lineno = lineno; parcl->semicolon_token.data = cpp_strdup(";"); parcl->parcelable = true; - doc = (document_item_type*)parcl; + doc = (AidlDocumentItem*)parcl; } else if (0 == strcmp("interface", type)) { - interface_type* iface = new interface_type(); - memset(iface, 0, sizeof(interface_type)); - iface->document_item.item_type = INTERFACE_TYPE_BINDER; + AidlInterface* iface = new AidlInterface(); + iface->item_type = INTERFACE_TYPE_BINDER; iface->interface_token.lineno = lineno; iface->interface_token.data = cpp_strdup(type); iface->package = packagename ? cpp_strdup(packagename) : NULL; @@ -429,7 +427,7 @@ int parse_preprocessed_file(const string& filename, TypeNamespace* types) { iface->open_brace_token.data = cpp_strdup("{"); iface->close_brace_token.lineno = lineno; iface->close_brace_token.data = cpp_strdup("}"); - doc = (document_item_type*)iface; + doc = (AidlDocumentItem*)iface; } else { fprintf(stderr, "%s:%d: bad type in line: %s\n", @@ -518,7 +516,7 @@ int load_and_validate_aidl(const std::vector<std::string> preprocessed_files, const std::string& input_file_name, const IoDelegate& io_delegate, TypeNamespace* types, - interface_type** returned_interface, + AidlInterface** returned_interface, std::vector<std::unique_ptr<AidlImport>>* returned_imports) { int err = 0; @@ -536,7 +534,7 @@ int load_and_validate_aidl(const std::vector<std::string> preprocessed_files, return 1; } - document_item_type* parsed_doc = p.GetDocument(); + AidlDocumentItem* parsed_doc = p.GetDocument(); // We could in theory declare parcelables in the same file as the interface. // In practice, those parcelables would have to have the same name as // the interface, since this was originally written to support Java, with its @@ -549,7 +547,7 @@ int load_and_validate_aidl(const std::vector<std::string> preprocessed_files, cerr << "aidl expects exactly one interface per input file"; return 1; } - interface_type* interface = (interface_type*)parsed_doc; + AidlInterface* interface = (AidlInterface*)parsed_doc; err |= check_filename(input_file_name.c_str(), interface->package, &interface->name); @@ -626,7 +624,7 @@ int load_and_validate_aidl(const std::vector<std::string> preprocessed_files, int compile_aidl_to_cpp(const CppOptions& options, const IoDelegate& io_delegate) { - interface_type* interface = nullptr; + AidlInterface* interface = nullptr; std::vector<std::unique_ptr<AidlImport>> imports; unique_ptr<cpp::TypeNamespace> types(new cpp::TypeNamespace()); int err = internals::load_and_validate_aidl( @@ -648,7 +646,7 @@ int compile_aidl_to_cpp(const CppOptions& options, int compile_aidl_to_java(const JavaOptions& options, const IoDelegate& io_delegate) { - interface_type* interface = nullptr; + AidlInterface* interface = nullptr; std::vector<std::unique_ptr<AidlImport>> imports; unique_ptr<java::JavaTypeNamespace> types(new java::JavaTypeNamespace()); int err = internals::load_and_validate_aidl( @@ -662,7 +660,7 @@ int compile_aidl_to_java(const JavaOptions& options, if (err != 0) { return err; } - document_item_type* parsed_doc = (document_item_type*)interface; + AidlDocumentItem* parsed_doc = (AidlDocumentItem*)interface; string output_file_name = options.output_file_name_; // if needed, generate the output file name from the base folder @@ -698,10 +696,10 @@ int preprocess_aidl(const JavaOptions& options, Parser p{io_delegate}; if (!p.ParseFile(options.files_to_preprocess_[i])) return 1; - document_item_type* doc = p.GetDocument(); + AidlDocumentItem* doc = p.GetDocument(); string line; if (doc->item_type == USER_DATA_TYPE) { - user_data_type* parcelable = (user_data_type*)doc; + AidlParcelable* parcelable = (AidlParcelable*)doc; if (parcelable->parcelable) { line = "parcelable "; } @@ -712,7 +710,7 @@ int preprocess_aidl(const JavaOptions& options, line += parcelable->name.data; } else { line = "interface "; - interface_type* iface = (interface_type*)doc; + AidlInterface* iface = (AidlInterface*)doc; if (iface->package) { line += iface->package; line += '.'; @@ -39,7 +39,7 @@ int load_and_validate_aidl(const std::vector<std::string> preprocessed_files, const std::string& input_file_name, const IoDelegate& io_delegate, TypeNamespace* types, - interface_type** returned_interface, + AidlInterface** returned_interface, std::vector<std::unique_ptr<AidlImport>>* returned_imports); } // namespace internals diff --git a/aidl_language.h b/aidl_language.h index 708c813..186b22a 100644 --- a/aidl_language.h +++ b/aidl_language.h @@ -134,36 +134,54 @@ class AidlMethod { }; enum { - USER_DATA_TYPE = 12, - INTERFACE_TYPE_BINDER + USER_DATA_TYPE = 12, + INTERFACE_TYPE_BINDER }; -struct document_item_type { - unsigned item_type; - struct document_item_type* next; +class AidlDocumentItem : public AidlNode { + public: + AidlDocumentItem() = default; + virtual ~AidlDocumentItem() = default; + + AidlDocumentItem* next; + unsigned item_type; + + private: + DISALLOW_COPY_AND_ASSIGN(AidlDocumentItem); }; +class AidlParcelable : public AidlDocumentItem { + public: + AidlParcelable() = default; + virtual ~AidlParcelable() = default; + + buffer_type keyword_token; // only the first one + char* package; + buffer_type name; + buffer_type semicolon_token; + bool parcelable; -struct user_data_type { - document_item_type document_item; - buffer_type keyword_token; // only the first one - char* package; - buffer_type name; - buffer_type semicolon_token; - bool parcelable; + private: + DISALLOW_COPY_AND_ASSIGN(AidlParcelable); }; -struct interface_type { - document_item_type document_item; - buffer_type interface_token; - bool oneway; - buffer_type oneway_token; - char* package; - buffer_type name; - buffer_type open_brace_token; - std::vector<std::unique_ptr<AidlMethod>>* methods; - buffer_type close_brace_token; - buffer_type* comments_token; // points into this structure, DO NOT DELETE +class AidlInterface : public AidlDocumentItem { + public: + explicit AidlInterface() = default; + virtual ~AidlInterface() = default; + + buffer_type interface_token; + bool oneway; + buffer_type oneway_token; + char* package; + buffer_type name; + buffer_type open_brace_token; + std::vector<std::unique_ptr<AidlMethod>>* methods; + buffer_type close_brace_token; + buffer_type* comments_token; // points into this structure, DO NOT DELETE + + private: + DISALLOW_COPY_AND_ASSIGN(AidlInterface); }; @@ -181,13 +199,13 @@ class AidlImport : public AidlNode { unsigned GetLine() const { return line_; } const AidlDocumentItem* GetDocument() { return document_.get(); }; void SetDocument(AidlDocumentItem* doc) { - document_.reset(doc); + document_ = std::unique_ptr<AidlDocumentItem>(doc); } void SetFilename(const std::string& filename) { filename_ = filename; } private: - std::unique_ptr<document_item_type> document_; + std::unique_ptr<AidlDocumentItem> document_; std::string from_; std::string filename_; std::string needed_class_; @@ -211,12 +229,12 @@ class Parser { const std::string& Package() const { return package_; } void *Scanner() const { return scanner_; } - void SetDocument(document_item_type *items) { document_ = items; }; + void SetDocument(AidlDocumentItem *items) { document_ = items; }; void AddImport(std::vector<std::string>* terms, unsigned line); void SetPackage(std::vector<std::string>* terms); - document_item_type *GetDocument() const { return document_; } + AidlDocumentItem *GetDocument() const { return document_; } const std::vector<std::unique_ptr<AidlImport>>& GetImports() { return imports_; } void ReleaseImports(std::vector<std::unique_ptr<AidlImport>>* ret) { @@ -230,7 +248,7 @@ class Parser { std::string filename_; std::string package_; void *scanner_ = nullptr; - document_item_type* document_ = nullptr; + AidlDocumentItem* document_ = nullptr; std::vector<std::unique_ptr<AidlImport>> imports_; std::unique_ptr<std::string> raw_buffer_; YY_BUFFER_STATE buffer_; diff --git a/aidl_language_y.y b/aidl_language_y.y index 400d694..426c23a 100644 --- a/aidl_language_y.y +++ b/aidl_language_y.y @@ -30,9 +30,9 @@ using android::aidl::cpp_strdup; AidlMethod* method; std::vector<std::unique_ptr<AidlMethod>>* methods; std::vector<std::string>* strvec; - interface_type* interface_obj; - user_data_type* user_data; - document_item_type* document_item; + AidlInterface* interface_obj; + AidlParcelable* user_data; + AidlDocumentItem* document_item; } %token<buffer> IDENTIFIER IDVALUE GENERIC PARCELABLE ONEWAY INTERFACE ';' '{' '}' @@ -70,117 +70,98 @@ import { ps->AddImport($2, @1.begin.line); }; package_name - : IDENTIFIER - { + : IDENTIFIER { $$ = new std::vector<std::string>(); $$->push_back($1.data); } | package_name '.' IDENTIFIER { $$->push_back($3.data); }; -document_items: - { $$ = NULL; } - | document_items declaration { - if ($2 == NULL) { - // error cases only - $$ = $1; - } else { - document_item_type* p = $1; - while (p && p->next) { - p=p->next; - } - if (p) { - p->next = (document_item_type*)$2; - $$ = $1; - } else { - $$ = (document_item_type*)$2; - } - } - } - | document_items error { - fprintf(stderr, "%s:%d: syntax error don't know what to do with \"%s\"\n", - ps->FileName().c_str(), - $2.lineno, $2.data); - $$ = $1; - } - ; - -declaration: - parcelable_decl { $$ = (document_item_type*)$1; } - | interface_decl { $$ = (document_item_type*)$1; } - ; +document_items + : { $$ = NULL; } + | document_items declaration { + $$ = $1; + AidlDocumentItem **pos = &$$; + while (*pos) + pos = &(*pos)->next; + if ($2) + *pos = $2; + } + | document_items error { + fprintf(stderr, "%s:%d: syntax error don't know what to do with \"%s\"\n", + ps->FileName().c_str(), + $2.lineno, $2.data); + $$ = $1; + }; -parcelable_decl: - PARCELABLE IDENTIFIER ';' { - user_data_type* b = new user_data_type(); - b->document_item.item_type = USER_DATA_TYPE; - b->document_item.next = NULL; - b->keyword_token = $1; - b->name = $2; - b->package = - cpp_strdup(ps->Package().c_str()); - b->semicolon_token = $3; - b->parcelable = true; - $$ = b; - } - | PARCELABLE ';' { - fprintf(stderr, "%s:%d syntax error in parcelable declaration. Expected type name.\n", - ps->FileName().c_str(), $1.lineno); - $$ = NULL; - } - | PARCELABLE error ';' { - fprintf(stderr, "%s:%d syntax error in parcelable declaration. Expected type name, saw \"%s\".\n", - ps->FileName().c_str(), $2.lineno, $2.data); - $$ = NULL; - } - ; +declaration + : parcelable_decl + { $$ = $1; } + | interface_decl + { $$ = $1; }; -interface_header: - INTERFACE { - interface_type* c = new interface_type(); - c->document_item.item_type = INTERFACE_TYPE_BINDER; - c->document_item.next = NULL; - c->interface_token = $1; - c->oneway = false; - memset(&c->oneway_token, 0, sizeof(buffer_type)); - c->comments_token = &c->interface_token; - $$ = c; - } - | ONEWAY INTERFACE { - interface_type* c = new interface_type(); - c->document_item.item_type = INTERFACE_TYPE_BINDER; - c->document_item.next = NULL; - c->interface_token = $2; - c->oneway = true; - c->oneway_token = $1; - c->comments_token = &c->oneway_token; - $$ = c; - } - ; +parcelable_decl + : PARCELABLE IDENTIFIER ';' { + AidlParcelable* b = new AidlParcelable(); + b->item_type = USER_DATA_TYPE; + b->keyword_token = $1; + b->name = $2; + b->package = cpp_strdup(ps->Package().c_str()); + b->semicolon_token = $3; + b->parcelable = true; + $$ = b; + } + | PARCELABLE ';' { + fprintf(stderr, "%s:%d syntax error in parcelable declaration. Expected type name.\n", + ps->FileName().c_str(), $1.lineno); + $$ = NULL; + } + | PARCELABLE error ';' { + fprintf(stderr, "%s:%d syntax error in parcelable declaration. Expected type name, saw \"%s\".\n", + ps->FileName().c_str(), $2.lineno, $2.data); + $$ = NULL; + }; -interface_decl: - interface_header IDENTIFIER '{' methods '}' { - interface_type* c = $1; - c->name = $2; - c->package = - cpp_strdup(ps->Package().c_str()); - c->open_brace_token = $3; - c->methods = $4; - c->close_brace_token = $5; - $$ = c; - } - | INTERFACE error '{' methods '}' { - fprintf(stderr, "%s:%d: syntax error in interface declaration. Expected type name, saw \"%s\"\n", - ps->FileName().c_str(), $2.lineno, $2.data); - $$ = NULL; - } - | INTERFACE error '}' { - fprintf(stderr, "%s:%d: syntax error in interface declaration. Expected type name, saw \"%s\"\n", - ps->FileName().c_str(), $2.lineno, $2.data); - $$ = NULL; - } +interface_header + : INTERFACE { + AidlInterface* c = new AidlInterface(); + c->item_type = INTERFACE_TYPE_BINDER; + c->interface_token = $1; + c->oneway = false; + memset(&c->oneway_token, 0, sizeof(buffer_type)); + c->comments_token = &c->interface_token; + $$ = c; + } + | ONEWAY INTERFACE { + AidlInterface* c = new AidlInterface(); + c->item_type = INTERFACE_TYPE_BINDER; + c->interface_token = $2; + c->oneway = true; + c->oneway_token = $1; + c->comments_token = &c->oneway_token; + $$ = c; + }; - ; +interface_decl + : interface_header IDENTIFIER '{' methods '}' { + AidlInterface* c = $1; + c->name = $2; + c->package = cpp_strdup(ps->Package().c_str()); + c->open_brace_token = $3; + c->methods = $4; + c->close_brace_token = $5; + $$ = c; + } + | INTERFACE error '{' methods '}' { + fprintf(stderr, "%s:%d: syntax error in interface declaration. Expected type name, saw \"%s\"\n", + ps->FileName().c_str(), $2.lineno, $2.data); + $$ = NULL; + } + | INTERFACE error '}' { + fprintf(stderr, "%s:%d: syntax error in interface declaration. Expected type name, saw \"%s\"\n", + ps->FileName().c_str(), $2.lineno, $2.data); + $$ = NULL; + }; methods : @@ -273,14 +254,6 @@ direction #include <ctype.h> #include <stdio.h> -void init_buffer_type(buffer_type* buf, int lineno) -{ - buf->lineno = lineno; - buf->token = 0; - buf->data = NULL; - buf->extra = NULL; -} - void yy::parser::error(const yy::parser::location_type& l, const std::string& errstr) { ps->ReportError(errstr); diff --git a/generate_cpp.cpp b/generate_cpp.cpp index e9a3aaa..1ce0868 100644 --- a/generate_cpp.cpp +++ b/generate_cpp.cpp @@ -103,7 +103,7 @@ unique_ptr<CppNamespace> NestInNamespaces(unique_ptr<Declaration> decl) { enum class ClassNames { BASE, CLIENT, SERVER, INTERFACE }; -string ClassName(const interface_type& interface, ClassNames type) { +string ClassName(const AidlInterface& interface, ClassNames type) { string c_name = interface.name.Literal(); if (c_name.length() >= 2 && c_name[0] == 'I' && isupper(c_name[1])) @@ -126,19 +126,19 @@ string ClassName(const interface_type& interface, ClassNames type) { } unique_ptr<Document> BuildClientSource(const TypeNamespace& types, - const interface_type& parsed_doc) { + const AidlInterface& parsed_doc) { unique_ptr<CppNamespace> ns{new CppNamespace{"android"}}; return unique_ptr<Document>{new CppSource{ {}, std::move(ns)}}; } unique_ptr<Document> BuildServerSource(const TypeNamespace& types, - const interface_type& parsed_doc) { + const AidlInterface& parsed_doc) { unique_ptr<CppNamespace> ns{new CppNamespace{"android"}}; return unique_ptr<Document>{new CppSource{ {}, std::move(ns)}}; } unique_ptr<Document> BuildInterfaceSource(const TypeNamespace& types, - const interface_type& parsed_doc) { + const AidlInterface& parsed_doc) { const string i_name = ClassName(parsed_doc, ClassNames::INTERFACE); const string bp_name = ClassName(parsed_doc, ClassNames::CLIENT); vector<string> include_list{i_name + ".h", bp_name + ".h"}; @@ -159,7 +159,7 @@ unique_ptr<Document> BuildInterfaceSource(const TypeNamespace& types, } unique_ptr<Document> BuildClientHeader(const TypeNamespace& types, - const interface_type& parsed_doc) { + const AidlInterface& parsed_doc) { const string i_name = ClassName(parsed_doc, ClassNames::INTERFACE); const string bp_name = ClassName(parsed_doc, ClassNames::CLIENT); @@ -192,7 +192,7 @@ unique_ptr<Document> BuildClientHeader(const TypeNamespace& types, } unique_ptr<Document> BuildServerHeader(const TypeNamespace& types, - const interface_type& parsed_doc) { + const AidlInterface& parsed_doc) { const string i_name = ClassName(parsed_doc, ClassNames::INTERFACE); const string bn_name = ClassName(parsed_doc, ClassNames::SERVER); @@ -222,7 +222,7 @@ unique_ptr<Document> BuildServerHeader(const TypeNamespace& types, } unique_ptr<Document> BuildInterfaceHeader(const TypeNamespace& types, - const interface_type& parsed_doc) { + const AidlInterface& parsed_doc) { unique_ptr<ClassDecl> if_class{ new ClassDecl{ClassName(parsed_doc, ClassNames::INTERFACE), "public android::IInterface"}}; @@ -262,7 +262,7 @@ using namespace internals; bool GenerateCpp(const CppOptions& options, const TypeNamespace& types, - const interface_type& parsed_doc) { + const AidlInterface& parsed_doc) { bool success = true; success &= GenerateCppForFile(options.ClientCppFileName(), diff --git a/generate_cpp.h b/generate_cpp.h index a09c874..8dc152b 100644 --- a/generate_cpp.h +++ b/generate_cpp.h @@ -27,7 +27,7 @@ namespace cpp { bool GenerateCpp(const CppOptions& options, const cpp::TypeNamespace& types, - const interface_type& parsed_doc); + const AidlInterface& parsed_doc); } // namespace cpp } // namespace aidl diff --git a/generate_cpp_unittest.cpp b/generate_cpp_unittest.cpp index 91a1354..f6bb7c1 100644 --- a/generate_cpp_unittest.cpp +++ b/generate_cpp_unittest.cpp @@ -34,11 +34,11 @@ namespace aidl { namespace cpp { namespace internals { unique_ptr<Document> BuildInterfaceSource(const TypeNamespace& types, - const interface_type& parsed_doc); + const AidlInterface& parsed_doc); unique_ptr<Document> BuildClientHeader(const TypeNamespace& types, - const interface_type& parsed_doc); + const AidlInterface& parsed_doc); unique_ptr<Document> BuildInterfaceHeader(const TypeNamespace& types, - const interface_type& parsed_doc); + const AidlInterface& parsed_doc); } namespace { @@ -115,13 +115,13 @@ IMPLEMENT_META_INTERFACE(PingResponder, "IPingResponder"); class TrivialInterfaceASTTest : public ::testing::Test { protected: - interface_type* Parse() { + AidlInterface* Parse() { FakeIoDelegate io_delegate; io_delegate.SetFileContents("IPingResponder.aidl", kTrivialInterfaceAIDL); cpp::TypeNamespace types; - interface_type* ret = nullptr; + AidlInterface* ret = nullptr; std::vector<std::unique_ptr<AidlImport>> imports; int err = ::android::aidl::internals::load_and_validate_aidl( {}, // no preprocessed files @@ -149,7 +149,7 @@ class TrivialInterfaceASTTest : public ::testing::Test { }; TEST_F(TrivialInterfaceASTTest, GeneratesClientHeader) { - interface_type* interface = Parse(); + AidlInterface* interface = Parse(); ASSERT_NE(interface, nullptr); TypeNamespace types; unique_ptr<Document> doc = internals::BuildClientHeader(types, *interface); @@ -157,7 +157,7 @@ TEST_F(TrivialInterfaceASTTest, GeneratesClientHeader) { } TEST_F(TrivialInterfaceASTTest, GeneratesInterfaceHeader) { - interface_type* interface = Parse(); + AidlInterface* interface = Parse(); ASSERT_NE(interface, nullptr); TypeNamespace types; unique_ptr<Document> doc = internals::BuildInterfaceHeader(types, *interface); @@ -165,7 +165,7 @@ TEST_F(TrivialInterfaceASTTest, GeneratesInterfaceHeader) { } TEST_F(TrivialInterfaceASTTest, GeneratesInterfaceSource) { - interface_type* interface = Parse(); + AidlInterface* interface = Parse(); ASSERT_NE(interface, nullptr); TypeNamespace types; unique_ptr<Document> doc = internals::BuildInterfaceSource(types, *interface); diff --git a/generate_java.cpp b/generate_java.cpp index 3d780d7..d71f8cc 100644 --- a/generate_java.cpp +++ b/generate_java.cpp @@ -49,11 +49,11 @@ namespace java { int generate_java(const string& filename, const string& originalSrc, - interface_type* iface, JavaTypeNamespace* types) + AidlInterface* iface, JavaTypeNamespace* types) { Class* cl; - if (iface->document_item.item_type == INTERFACE_TYPE_BINDER) { + if (iface->item_type == INTERFACE_TYPE_BINDER) { cl = generate_binder_interface_class(iface, types); } diff --git a/generate_java.h b/generate_java.h index 5affbf1..2f06323 100644 --- a/generate_java.h +++ b/generate_java.h @@ -17,10 +17,10 @@ namespace java { class JavaTypeNamespace; int generate_java(const string& filename, const string& originalSrc, - interface_type* iface, java::JavaTypeNamespace* types); + AidlInterface* iface, java::JavaTypeNamespace* types); android::aidl::java::Class* generate_binder_interface_class( - const interface_type* iface, java::JavaTypeNamespace* types); + const AidlInterface* iface, java::JavaTypeNamespace* types); } // namespace java diff --git a/generate_java_binder.cpp b/generate_java_binder.cpp index b7ae470..1dc5dc7 100644 --- a/generate_java_binder.cpp +++ b/generate_java_binder.cpp @@ -514,7 +514,7 @@ generate_interface_descriptors(StubClass* stub, ProxyClass* proxy, } Class* -generate_binder_interface_class(const interface_type* iface, +generate_binder_interface_class(const AidlInterface* iface, JavaTypeNamespace* types) { const InterfaceType* interfaceType = static_cast<const InterfaceType*>( diff --git a/type_cpp.cpp b/type_cpp.cpp index b4f8ab3..6f80845 100644 --- a/type_cpp.cpp +++ b/type_cpp.cpp @@ -61,14 +61,14 @@ TypeNamespace::TypeNamespace() { new Type("double", "double", "readDouble", "writeDouble")); } -bool TypeNamespace::AddParcelableType(const user_data_type* p, +bool TypeNamespace::AddParcelableType(const AidlParcelable* p, const string& filename) { // TODO Support parcelables b/23600712 LOG(ERROR) << "Passing parcelables in unimplemented in C++ generation."; return true; } -bool TypeNamespace::AddBinderType(const interface_type* b, +bool TypeNamespace::AddBinderType(const AidlInterface* b, const string& filename) { // TODO Support passing binders b/24470875 LOG(ERROR) << "Passing binders is unimplemented in C++ generation."; @@ -64,9 +64,9 @@ class TypeNamespace : public ::android::aidl::TypeNamespace { TypeNamespace(); virtual ~TypeNamespace() = default; - bool AddParcelableType(const user_data_type* p, + bool AddParcelableType(const AidlParcelable* p, const std::string& filename) override; - bool AddBinderType(const interface_type* b, + bool AddBinderType(const AidlInterface* b, const std::string& filename) override; bool AddContainerType(const std::string& type_name) override; diff --git a/type_java.cpp b/type_java.cpp index bd1b700..8953adc 100644 --- a/type_java.cpp +++ b/type_java.cpp @@ -955,7 +955,7 @@ const Type* JavaTypeNamespace::Find(const char* package, return Find(s); } -bool JavaTypeNamespace::AddParcelableType(const user_data_type* p, +bool JavaTypeNamespace::AddParcelableType(const AidlParcelable* p, const std::string& filename) { Type* type = new UserDataType(this, p->package ? p->package : "", p->name.data, false, @@ -963,7 +963,7 @@ bool JavaTypeNamespace::AddParcelableType(const user_data_type* p, return Add(type); } -bool JavaTypeNamespace::AddBinderType(const interface_type* b, +bool JavaTypeNamespace::AddBinderType(const AidlInterface* b, const std::string& filename) { // for interfaces, add the stub, proxy, and interface types. Type* type = diff --git a/type_java.h b/type_java.h index fc2b33d..39a3d8e 100644 --- a/type_java.h +++ b/type_java.h @@ -404,9 +404,9 @@ class JavaTypeNamespace : public TypeNamespace { JavaTypeNamespace(); virtual ~JavaTypeNamespace(); - bool AddParcelableType(const user_data_type* p, + bool AddParcelableType(const AidlParcelable* p, const string& filename) override; - bool AddBinderType(const interface_type* b, + bool AddBinderType(const AidlInterface* b, const string& filename) override; bool AddContainerType(const string& type_name) override; diff --git a/type_java_unittest.cpp b/type_java_unittest.cpp index bba0c88..7fa05c6 100644 --- a/type_java_unittest.cpp +++ b/type_java_unittest.cpp @@ -29,13 +29,12 @@ namespace aidl { namespace java { namespace { -user_data_type* MakeFakeUserDataType(const std::string& package, +AidlParcelable* MakeFakeUserDataType(const std::string& package, const std::string& class_name) { // This leaks memory, like all usages of these structs. // See b/24410295 - user_data_type* parcl = new user_data_type(); - memset(parcl, 0, sizeof(user_data_type)); - parcl->document_item.item_type = USER_DATA_TYPE; + AidlParcelable* parcl = new AidlParcelable(); + parcl->item_type = USER_DATA_TYPE; parcl->package = cpp_strdup(package.c_str()); parcl->name.data = cpp_strdup(class_name.c_str()); return parcl; diff --git a/type_namespace.h b/type_namespace.h index ee4b29b..4c0d15f 100644 --- a/type_namespace.h +++ b/type_namespace.h @@ -43,9 +43,9 @@ class ValidatableType { class TypeNamespace { public: // Load this TypeNamespace with user defined types. - virtual bool AddParcelableType(const user_data_type* p, + virtual bool AddParcelableType(const AidlParcelable* p, const std::string& filename) = 0; - virtual bool AddBinderType(const interface_type* b, + virtual bool AddBinderType(const AidlInterface* b, const std::string& filename) = 0; // We dynamically create container types as we discover them in the parse // tree. Returns false iff this is an invalid type. Silently discards |