Make sure all nodes are visited.

Simple way to do this, gives us nice consistency properties (and it
guards against unintentional copies made of AidlNode objects, etc).

Bug: 201584220
Test: mma
Change-Id: Ie94c78ad5cad3e85d80f6cdae973b4bab79ac7d9
diff --git a/aidl_language.cpp b/aidl_language.cpp
index 03b9905..da62629 100644
--- a/aidl_language.cpp
+++ b/aidl_language.cpp
@@ -75,6 +75,24 @@
 }
 }  // namespace
 
+AidlNode::~AidlNode() {
+  if (!visited_) {
+    unvisited_locations_.push_back(location_);
+  }
+}
+
+void AidlNode::ClearUnvisitedNodes() {
+  unvisited_locations_.clear();
+}
+
+const std::vector<AidlLocation>& AidlNode::GetLocationsOfUnvisitedNodes() {
+  return unvisited_locations_;
+}
+
+void AidlNode::MarkVisited() const {
+  visited_ = true;
+}
+
 AidlNode::AidlNode(const AidlLocation& location, const Comments& comments)
     : location_(location), comments_(comments) {}
 
@@ -91,6 +109,8 @@
   return ss.str();
 }
 
+std::vector<AidlLocation> AidlNode::unvisited_locations_;
+
 static const AidlTypeSpecifier kStringType{AIDL_LOCATION_HERE, "String", false, nullptr,
                                            Comments{}};
 static const AidlTypeSpecifier kStringArrayType{AIDL_LOCATION_HERE, "String", true, nullptr,
@@ -1430,7 +1450,6 @@
                      << ". Backing type must be one of: " << Join(kBackingTypes, ", ");
     return false;
   }
-
   return true;
 }