diff options
author | Casey Dahlin <sadmac@google.com> | 2015-10-12 19:23:40 -0700 |
---|---|---|
committer | Casey Dahlin <sadmac@google.com> | 2015-10-13 11:07:16 -0700 |
commit | 42727f851672ff8f3099db81fa21c969e553e150 (patch) | |
tree | ee3e7bf2002d68fc376bb8ecac9f6cdfd6b55814 /aidl.cpp | |
parent | ba52a2b86eb0639d18369c02edb7209ad05973a4 (diff) | |
download | android_system_tools_aidl-42727f851672ff8f3099db81fa21c969e553e150.tar.gz android_system_tools_aidl-42727f851672ff8f3099db81fa21c969e553e150.tar.bz2 android_system_tools_aidl-42727f851672ff8f3099db81fa21c969e553e150.zip |
Parse only one interface, only Parcelables are lists
This is a fixup of the change that was reverted in:
2d0179a123a3d212fdd9d1baa02ce473b688b360
We're encoding the restriction of only one interface per file directly in
to the grammar/type system now. This simplifies much.
Change-Id: Icaac11cb6121327066acd01952b8dec0cfbe9376
Test: Full android build
Bug: 24874768
Signed-off-by: Casey Dahlin <sadmac@google.com>
Diffstat (limited to 'aidl.cpp')
-rw-r--r-- | aidl.cpp | 81 |
1 files changed, 39 insertions, 42 deletions
@@ -67,10 +67,10 @@ namespace { const int kMinUserSetMethodId = 0; const int kMaxUserSetMethodId = 16777214; -int check_filename(const std::string& filename, - const std::string& package, - const std::string& name, - unsigned line) { +bool check_filename(const std::string& filename, + const std::string& package, + const std::string& name, + unsigned line) { const char* p; string expected; string fn; @@ -139,31 +139,28 @@ int check_filename(const std::string& filename, fprintf(stderr, "%s:%d interface %s should be declared in a file" " called %s.\n", filename.c_str(), line, name.c_str(), expected.c_str()); - return 1; } - return 0; + return valid; } -int check_filenames(const std::string& filename, const AidlDocumentItem* items) { - int err = 0; - while (items) { - if (items->item_type == USER_DATA_TYPE) { - const AidlParcelable* p = reinterpret_cast<const AidlParcelable*>(items); - err |= check_filename(filename, p->GetPackage(), p->GetName(), p->GetLine()); - } - else if (items->item_type == INTERFACE_TYPE_BINDER) { - const AidlInterface* c = reinterpret_cast<const AidlInterface*>(items); - err |= check_filename(filename, c->GetPackage(), c->GetName(), c->GetLine()); - } - else { - fprintf(stderr, "aidl: internal error unkown document type %d.\n", - items->item_type); - return 1; - } - items = items->next; - } - return err; +bool check_filenames(const std::string& filename, const AidlDocumentItem* items) { + if (! items) + return true; + + if (items->item_type == INTERFACE_TYPE_BINDER) { + const AidlInterface* c = reinterpret_cast<const AidlInterface*>(items); + return check_filename(filename, c->GetPackage(), c->GetName(), c->GetLine()); + } + + bool success = true; + + for (const AidlParcelable* p = reinterpret_cast<const AidlParcelable*>(items); + p; p = p->next) + success &= check_filename(filename, p->GetPackage(), p->GetName(), + p->GetLine()); + + return success; } char* rfind(char* str, char c) { @@ -182,17 +179,18 @@ bool gather_types(const std::string& filename, TypeNamespace* types) { bool success = true; - for (const AidlDocumentItem* item = all_items; item; item = item->next) { - if (item->item_type == USER_DATA_TYPE) { - const AidlParcelable* p = reinterpret_cast<const AidlParcelable*>(item); - success &= types->AddParcelableType(p, filename); - } else if (item->item_type == INTERFACE_TYPE_BINDER) { - const AidlInterface* c = reinterpret_cast<const AidlInterface*>(item); - success &= types->AddBinderType(c, filename); - } else { - LOG(FATAL) << "internal error"; - } + if (! all_items) + return true; + + if (all_items->item_type == INTERFACE_TYPE_BINDER) + return types->AddBinderType(reinterpret_cast<const AidlInterface *>(all_items), filename); + + for (const AidlParcelable* item = + reinterpret_cast<const AidlParcelable *>(all_items); + item; item = item->next) { + success &= types->AddParcelableType(item, filename); } + return success; } @@ -259,7 +257,6 @@ void generate_dep_file(const JavaOptions& options, if (to == NULL) { cerr << "Could not open " << fileName << endl; - printf("%m\n"); return; } @@ -523,15 +520,14 @@ int load_and_validate_aidl(const std::vector<std::string> preprocessed_files, // Since we can't have two distinct classes with the same name and package, // we can't actually declare parcelables in the same file. if (parsed_doc == nullptr || - parsed_doc->item_type != INTERFACE_TYPE_BINDER || - parsed_doc->next != nullptr) { + parsed_doc->item_type != INTERFACE_TYPE_BINDER) { cerr << "aidl expects exactly one interface per input file"; return 1; } AidlInterface* interface = reinterpret_cast<AidlInterface*>(parsed_doc); - err |= check_filename(input_file_name.c_str(), - interface->GetPackage(), interface->GetName(), - interface->GetLine()); + if (!check_filename(input_file_name.c_str(), interface->GetPackage(), + interface->GetName(), interface->GetLine())) + err |= 1; // parse the imports of the input file ImportResolver import_resolver{io_delegate, import_paths}; @@ -561,7 +557,8 @@ int load_and_validate_aidl(const std::vector<std::string> preprocessed_files, } import->SetDocument(p.GetDocument()); - err |= check_filenames(import->GetFilename(), import->GetDocument()); + if (!check_filenames(import->GetFilename(), import->GetDocument())) + err |= 1; } if (err != 0) { return err; |