diff options
-rw-r--r-- | aidl.cpp | 81 | ||||
-rw-r--r-- | aidl_language.h | 14 | ||||
-rw-r--r-- | aidl_language_y.y | 25 |
3 files changed, 56 insertions, 64 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; diff --git a/aidl_language.h b/aidl_language.h index 5037c86..c910a37 100644 --- a/aidl_language.h +++ b/aidl_language.h @@ -29,7 +29,7 @@ struct extra_text_type { struct buffer_type { unsigned token; - char *data; + char* data; extra_text_type* extra; std::string Literal() const { @@ -74,7 +74,7 @@ class AidlArgument : public AidlNode { AidlArgument(AidlArgument::Direction direction, AidlType* type, std::string name, unsigned line); - AidlArgument(AidlType *type, std::string name, unsigned line); + AidlArgument(AidlType* type, std::string name, unsigned line); virtual ~AidlArgument() = default; Direction GetDirection() const { return direction_; } @@ -155,7 +155,6 @@ class AidlDocumentItem : public AidlNode { AidlDocumentItem() = default; virtual ~AidlDocumentItem() = default; - AidlDocumentItem* next = nullptr; unsigned item_type; private: @@ -172,6 +171,7 @@ class AidlParcelable : public AidlDocumentItem { unsigned GetLine() const { return line_; } const std::string& GetPackage() const { return package_; } + AidlParcelable* next = nullptr; private: std::string name_; unsigned line_; @@ -251,14 +251,14 @@ class Parser { bool FoundNoErrors() const { return error_ == 0; } const std::string& FileName() const { return filename_; } const std::string& Package() const { return package_; } - void *Scanner() const { return scanner_; } + void* Scanner() const { return scanner_; } - void SetDocument(AidlDocumentItem *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); - AidlDocumentItem *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) { @@ -271,7 +271,7 @@ class Parser { int error_ = 0; std::string filename_; std::string package_; - void *scanner_ = nullptr; + void* scanner_ = nullptr; AidlDocumentItem* document_ = nullptr; std::vector<std::unique_ptr<AidlImport>> imports_; std::unique_ptr<std::string> raw_buffer_; diff --git a/aidl_language_y.y b/aidl_language_y.y index a04802f..b62e9d5 100644 --- a/aidl_language_y.y +++ b/aidl_language_y.y @@ -32,7 +32,6 @@ using android::aidl::cpp_strdup; std::vector<std::string>* strvec; AidlInterface* interface_obj; AidlParcelable* user_data; - AidlDocumentItem* document_item; } %token<buffer> IDENTIFIER IDVALUE GENERIC INTERFACE ONEWAY @@ -40,8 +39,7 @@ using android::aidl::cpp_strdup; %token '(' ')' ',' '=' '[' ']' '<' '>' '.' '{' '}' ';' %token IN OUT INOUT PACKAGE IMPORT PARCELABLE -%type<document_item> document_items declaration -%type<user_data> parcelable_decl +%type<user_data> parcelable_decl parcelable_decls %type<methods> methods %type<interface_obj> interface_decl %type<method> method_decl @@ -55,7 +53,9 @@ using android::aidl::cpp_strdup; %type<buffer> error %% document - : package imports document_items + : package imports parcelable_decls + { ps->SetDocument($3); } + | package imports interface_decl { ps->SetDocument($3); }; package @@ -79,29 +79,24 @@ package_name | package_name '.' IDENTIFIER { $$->push_back($3.data); }; -document_items - : { $$ = NULL; } - | document_items declaration { +parcelable_decls + : + { $$ = NULL; } + | parcelable_decls parcelable_decl { $$ = $1; - AidlDocumentItem **pos = &$$; + AidlParcelable **pos = &$$; while (*pos) pos = &(*pos)->next; if ($2) *pos = $2; } - | document_items error { + | parcelable_decls error { fprintf(stderr, "%s:%d: syntax error don't know what to do with \"%s\"\n", ps->FileName().c_str(), @2.begin.line, $2.data); $$ = $1; }; -declaration - : parcelable_decl - { $$ = $1; } - | interface_decl - { $$ = $1; }; - parcelable_decl : PARCELABLE IDENTIFIER ';' { $$ = new AidlParcelable($2.data, @2.begin.line, ps->Package()); |