AidlNode: delete copy constructor

So that it's easier to add invariants to these object's destructors.

Bug: 201584220
Test: aidl_unittests
Change-Id: Id152501cc8067743b73f52299588e3cd48b39144
diff --git a/aidl.cpp b/aidl.cpp
index adbb371..298aede 100644
--- a/aidl.cpp
+++ b/aidl.cpp
@@ -309,7 +309,7 @@
 
     void Check(const AidlAnnotatable& annotatable, AidlAnnotation::TargetContext context) {
       for (const auto& annot : annotatable.GetAnnotations()) {
-        if (!annot.CheckContext(context)) {
+        if (!annot->CheckContext(context)) {
           success = false;
         }
       }
diff --git a/aidl_checkapi.cpp b/aidl_checkapi.cpp
index ae3b63b..42f2bc7 100644
--- a/aidl_checkapi.cpp
+++ b/aidl_checkapi.cpp
@@ -86,11 +86,11 @@
       AidlAnnotation::Type::SUPPRESS_WARNINGS,
   };
   vector<string> annotations;
-  for (const AidlAnnotation& annotation : node.GetAnnotations()) {
-    if (kIgnoreAnnotations.find(annotation.GetType()) != kIgnoreAnnotations.end()) {
+  for (const auto& annotation : node.GetAnnotations()) {
+    if (kIgnoreAnnotations.find(annotation->GetType()) != kIgnoreAnnotations.end()) {
       continue;
     }
-    auto annotation_string = annotation.ToString();
+    auto annotation_string = annotation->ToString();
     // adding @Deprecated (with optional args) is okay
     if (StartsWith(annotation_string, "@JavaPassthrough(annotation=\"@Deprecated")) {
       continue;
diff --git a/aidl_language.cpp b/aidl_language.cpp
index e694212..5b94f9b 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -352,13 +352,13 @@
   }
 }
 
-static const AidlAnnotation* GetAnnotation(const vector<AidlAnnotation>& annotations,
-                                           AidlAnnotation::Type type) {
+static const AidlAnnotation* GetAnnotation(
+    const vector<std::unique_ptr<AidlAnnotation>>& annotations, AidlAnnotation::Type type) {
   for (const auto& a : annotations) {
-    if (a.GetType() == type) {
-      AIDL_FATAL_IF(a.Repeatable(), a)
+    if (a->GetType() == type) {
+      AIDL_FATAL_IF(a->Repeatable(), a)
           << "Trying to get a single annotation when it is repeatable.";
-      return &a;
+      return a.get();
     }
   }
   return nullptr;
@@ -463,16 +463,17 @@
 
 bool AidlAnnotatable::CheckValid(const AidlTypenames&) const {
   for (const auto& annotation : GetAnnotations()) {
-    if (!annotation.CheckValid()) {
+    if (!annotation->CheckValid()) {
       return false;
     }
   }
 
   std::map<AidlAnnotation::Type, AidlLocation> declared;
   for (const auto& annotation : GetAnnotations()) {
-    const auto& [iter, inserted] = declared.emplace(annotation.GetType(), annotation.GetLocation());
-    if (!inserted && !annotation.Repeatable()) {
-      AIDL_ERROR(this) << "'" << annotation.GetName()
+    const auto& [iter, inserted] =
+        declared.emplace(annotation->GetType(), annotation->GetLocation());
+    if (!inserted && !annotation->Repeatable()) {
+      AIDL_ERROR(this) << "'" << annotation->GetName()
                        << "' is repeated, but not allowed. Previous location: " << iter->second;
       return false;
     }
@@ -484,7 +485,7 @@
 string AidlAnnotatable::ToString() const {
   vector<string> ret;
   for (const auto& a : annotations_) {
-    ret.emplace_back(a.ToString());
+    ret.emplace_back(a->ToString());
   }
   std::sort(ret.begin(), ret.end());
   return Join(ret, " ");
@@ -1199,11 +1200,6 @@
     cpp_header_ = cpp_header_.substr(1, cpp_header_.length() - 2);
   }
 }
-template <typename T>
-AidlParameterizable<T>::AidlParameterizable(const AidlParameterizable& other) {
-  // Copying is not supported if it has type parameters.
-  AIDL_FATAL_IF(other.IsGeneric(), AIDL_LOCATION_HERE);
-}
 
 template <typename T>
 bool AidlParameterizable<T>::CheckValid() const {
diff --git a/aidl_language.h b/aidl_language.h
index 205e354..acd1caf 100644
--- a/aidl_language.h
+++ b/aidl_language.h
@@ -144,9 +144,10 @@
  public:
   AidlNode(const AidlLocation& location, const Comments& comments = {});
 
-  AidlNode(const AidlNode&) = default;
   virtual ~AidlNode() = default;
 
+  AidlNode(AidlNode&) = delete;
+  AidlNode& operator=(AidlNode&) = delete;
   AidlNode(AidlNode&&) = delete;
   AidlNode& operator=(AidlNode&&) = delete;
 
@@ -188,9 +189,6 @@
 
   virtual const AidlNode& AsAidlNode() const = 0;
 
- protected:
-  AidlParameterizable(const AidlParameterizable&);
-
  private:
   unique_ptr<std::vector<T>> type_params_;
   static_assert(std::is_same<T, unique_ptr<AidlTypeSpecifier>>::value ||
@@ -259,7 +257,6 @@
       std::map<std::string, std::shared_ptr<AidlConstantValue>> parameter_list,
       const Comments& comments);
 
-  AidlAnnotation(const AidlAnnotation&) = default;
   AidlAnnotation(AidlAnnotation&&) = default;
   virtual ~AidlAnnotation() = default;
   bool CheckValid() const;
@@ -328,11 +325,9 @@
  public:
   AidlAnnotatable(const AidlLocation& location, const Comments& comments);
 
-  AidlAnnotatable(const AidlAnnotatable&) = default;
-  AidlAnnotatable(AidlAnnotatable&&) = default;
   virtual ~AidlAnnotatable() = default;
 
-  void Annotate(vector<AidlAnnotation>&& annotations) {
+  void Annotate(vector<std::unique_ptr<AidlAnnotation>>&& annotations) {
     for (auto& annotation : annotations) {
       annotations_.emplace_back(std::move(annotation));
     }
@@ -360,16 +355,16 @@
   // e.g) "@JavaDerive(toString=true) @RustDerive(Clone=true, Copy=true)"
   std::string ToString() const;
 
-  const vector<AidlAnnotation>& GetAnnotations() const { return annotations_; }
+  const vector<std::unique_ptr<AidlAnnotation>>& GetAnnotations() const { return annotations_; }
   bool CheckValid(const AidlTypenames&) const;
   void TraverseChildren(std::function<void(const AidlNode&)> traverse) const override {
     for (const auto& annot : GetAnnotations()) {
-      traverse(annot);
+      traverse(*annot);
     }
   }
 
  private:
-  vector<AidlAnnotation> annotations_;
+  vector<std::unique_ptr<AidlAnnotation>> annotations_;
 };
 
 // AidlTypeSpecifier represents a reference to either a built-in type,
@@ -443,8 +438,6 @@
   void DispatchVisit(AidlVisitor& v) const override { v.Visit(*this); }
 
  private:
-  AidlTypeSpecifier(const AidlTypeSpecifier&) = default;
-
   const string unresolved_name_;
   string fully_qualified_name_;
   mutable bool is_array_;
diff --git a/aidl_language_y.yy b/aidl_language_y.yy
index c7c7287..7b068a6 100644
--- a/aidl_language_y.yy
+++ b/aidl_language_y.yy
@@ -74,7 +74,7 @@
     AidlAnnotation* annotation;
     AidlAnnotationParameter* param;
     std::map<std::string, std::shared_ptr<AidlConstantValue>>* param_list;
-    std::vector<AidlAnnotation>* annotation_list;
+    std::vector<std::unique_ptr<AidlAnnotation>>* annotation_list;
     AidlTypeSpecifier* type;
     AidlArgument* arg;
     AidlArgument::Direction direction;
@@ -272,7 +272,7 @@
 
     if ($1->size() > 0 && $$ != nullptr) {
       // copy comments from annotation to decl
-      $$->SetComments($1->begin()->GetComments());
+      $$->SetComments($1->begin()->get()->GetComments());
       $$->Annotate(std::move(*$1));
     }
 
@@ -553,7 +553,7 @@
 constant_decl
  : annotation_list CONST type identifier '=' const_expr ';' {
     if ($1->size() > 0) {
-      $3->SetComments($1->begin()->GetComments());
+      $3->SetComments($1->begin()->get()->GetComments());
     } else {
       $3->SetComments($2->GetComments());
     }
@@ -618,7 +618,7 @@
     delete $2;
   }
  | annotation_list ONEWAY type identifier '(' arg_list ')' ';' {
-    const auto& comments = ($1->size() > 0) ? $1->begin()->GetComments() : $2->GetComments();
+    const auto& comments = ($1->size() > 0) ? $1->begin()->get()->GetComments() : $2->GetComments();
     $$ = new AidlMethod(loc(@4), true, $3, $4->GetText(), $6, comments);
     $3->Annotate(std::move(*$1));
     delete $1;
@@ -636,7 +636,7 @@
     delete $7;
   }
  | annotation_list ONEWAY type identifier '(' arg_list ')' '=' INTVALUE ';' {
-    const auto& comments = ($1->size() > 0) ? $1->begin()->GetComments() : $2->GetComments();
+    const auto& comments = ($1->size() > 0) ? $1->begin()->get()->GetComments() : $2->GetComments();
     int32_t serial = 0;
     if (!android::base::ParseInt($9->GetText(), &serial)) {
         AIDL_ERROR(loc(@9)) << "Could not parse int value: " << $9->GetText();
@@ -680,7 +680,7 @@
  : annotation_list qualified_name {
     $$ = new AidlTypeSpecifier(loc(@2), $2->GetText(), false, nullptr, $2->GetComments());
     if (!$1->empty()) {
-      $$->SetComments($1->begin()->GetComments());
+      $$->SetComments($1->begin()->get()->GetComments());
       $$->Annotate(std::move(*$1));
     }
     delete $1;
@@ -736,12 +736,11 @@
 
 annotation_list
  :
-  { $$ = new std::vector<AidlAnnotation>(); }
+  { $$ = new std::vector<std::unique_ptr<AidlAnnotation>>(); }
  | annotation_list annotation
   {
     if ($2 != nullptr) {
-      $1->emplace_back(std::move(*$2));
-      delete $2;
+      $1->emplace_back(std::unique_ptr<AidlAnnotation>($2));
     }
     $$ = $1;
   };
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index fd64309..56faba5 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -1845,8 +1845,9 @@
   };
 
   auto set_nullable = [](std::unique_ptr<AidlTypeSpecifier>&& type) {
-    std::vector<AidlAnnotation> annotations;
-    annotations.emplace_back(*AidlAnnotation::Parse(AIDL_LOCATION_HERE, "nullable", {}, {}));
+    std::vector<std::unique_ptr<AidlAnnotation>> annotations;
+    annotations.emplace_back(std::unique_ptr<AidlAnnotation>(
+        AidlAnnotation::Parse(AIDL_LOCATION_HERE, "nullable", {}, {})));
     type->Annotate(std::move(annotations));
     return std::move(type);
   };
diff --git a/generate_java.cpp b/generate_java.cpp
index 34dd5e1..8bf0b0d 100644
--- a/generate_java.cpp
+++ b/generate_java.cpp
@@ -912,8 +912,8 @@
   }
 
   for (const auto& annotation : a.GetAnnotations()) {
-    if (annotation.GetType() == AidlAnnotation::Type::JAVA_PASSTHROUGH) {
-      result.emplace_back(annotation.ParamValue<std::string>("annotation").value());
+    if (annotation->GetType() == AidlAnnotation::Type::JAVA_PASSTHROUGH) {
+      result.emplace_back(annotation->ParamValue<std::string>("annotation").value());
     }
   }