aboutsummaryrefslogtreecommitdiff
path: root/aidl_language_y.yy
diff options
context:
space:
mode:
authorJiyong Park <jiyong@google.com>2020-07-20 20:52:38 +0900
committerTreehugger Robot <treehugger-gerrit@google.com>2020-07-22 03:01:59 +0000
commit8e79b7f1387bee1e269286cdb5ad930c43bab8fb (patch)
tree4de3120692b77ab9afe0559d60db7489dddeb162 /aidl_language_y.yy
parent720a3cc4a8b540e30b543e06ee48ab160fbd8d9c (diff)
downloadaidl-8e79b7f1387bee1e269286cdb5ad930c43bab8fb.tar.gz
Change the ownership of AidlDefinedType objects
Previously, AidlDefinedType objects were directly owned by the AidlTypenames object, although an AidlDefinedType is conceptually a part of the AidlDocument object wheere the AidlDefinedType is found. At the time, AidlDocument merely have references to AidlDefinedTypes that it (conceptually) owns. This change fixes the wrong ownership relationship. Now, the ownership hierarchy is: AIdlTypenames -> AidlDocument -> AidlDefinedType. The ownership is enforced by keeping AidlDocument and AidlDefinedType using std::unique_ptr, and making them non-copyable and non-movable. This change also alters the way AidlDefinedType objects are returned from the load_and_validate_aidl function. Previously, we simply returned the references (pointers) that were stored in the AidlDocument via an out param. Now, the client of the function can get the objects via typenames.MainDocument().DefinedTypes(). Bug: 160367901 Test: aidl_unittests Change-Id: If3fcd2acaccce3a484e6329f8fa68bb959b743be
Diffstat (limited to 'aidl_language_y.yy')
-rw-r--r--aidl_language_y.yy16
1 files changed, 3 insertions, 13 deletions
diff --git a/aidl_language_y.yy b/aidl_language_y.yy
index f0b174a9..c1bf77f8 100644
--- a/aidl_language_y.yy
+++ b/aidl_language_y.yy
@@ -96,21 +96,11 @@ AidlLocation loc(const yy::parser::location_type& l) {
std::vector<std::string>* type_params;
std::vector<std::unique_ptr<AidlImport>>* imports;
AidlImport* import;
- std::vector<AidlDefinedType*>* declarations;
+ std::vector<std::unique_ptr<AidlDefinedType>>* declarations;
}
%destructor { } <character>
%destructor { } <direction>
-// TODO(b/160367901) remove this.
-%destructor {
- // decl is std::vector<AidlDefinedType*>. When deleting it,
- // we should first delete AidlDefinedType objects in it.
- // Otherwise, there would be memory leaks.
- for (auto* t: *($$)) {
- delete(t);
- }
- delete ($$);
-} decls
%destructor { delete ($$); } <*>
%token<token> ANNOTATION "annotation"
@@ -196,7 +186,7 @@ AidlLocation loc(const yy::parser::location_type& l) {
document
: package imports decls
- { ps->SetDocument(std::make_unique<AidlDocument>(loc(@1), *$2, *$3));
+ { ps->SetDocument(std::make_unique<AidlDocument>(loc(@1), *$2, std::move(*$3)));
delete $2;
delete $3;
}
@@ -254,7 +244,7 @@ qualified_name
decls
: decl
- { $$ = new std::vector<AidlDefinedType*>();
+ { $$ = new std::vector<std::unique_ptr<AidlDefinedType>>();
if ($1 != nullptr) {
$$->emplace_back($1);
}