Changing enum autofill to use aidl file location instead of cpp

This location is printed when there are any issues with the aidl node.
In this case, when implicitly starting enumerators from 0 or implicitly
adding 1 to the next enumerator, we are now using the location of that
enumerator in the .aidl files instead of the .cpp file. This is intended
to give more useful information to the user.

Added a check to make sure we don't output internal file locations.

Test: atest aidl_unittests aidl_integration_test
Change-Id: I0b2b7a18e69c313668aea395a2a02a77ae27dfc1
diff --git a/aidl_language.h b/aidl_language.h
index 55bed95..97c8ba3 100644
--- a/aidl_language.h
+++ b/aidl_language.h
@@ -74,7 +74,16 @@
     int column;
   };
 
-  AidlLocation(const std::string& file, Point begin, Point end);
+  enum class Source {
+    // From internal aidl source code
+    INTERNAL = 0,
+    // From a parsed file
+    EXTERNAL = 1
+  };
+
+  AidlLocation(const std::string& file, Point begin, Point end, Source source);
+
+  bool IsInternal() const { return source_ == Source::INTERNAL; }
 
   friend std::ostream& operator<<(std::ostream& os, const AidlLocation& l);
   friend class AidlNode;
@@ -83,12 +92,11 @@
   const std::string file_;
   Point begin_;
   Point end_;
+  Source source_;
 };
 
-#define AIDL_LOCATION_HERE                   \
-  AidlLocation {                             \
-    __FILE__, {__LINE__, 0}, { __LINE__, 0 } \
-  }
+#define AIDL_LOCATION_HERE \
+  AidlLocation { __FILE__, {__LINE__, 0}, {__LINE__, 0}, AidlLocation::Source::INTERNAL }
 
 std::ostream& operator<<(std::ostream& os, const AidlLocation& l);
 
@@ -101,15 +109,15 @@
   AidlNode(AidlNode&&) = default;
   virtual ~AidlNode() = default;
 
-  // DO NOT ADD. This is intentionally omitted. Nothing should refer to the location
-  // for a functional purpose. It is only for error messages.
-  // NO const AidlLocation& GetLocation() const { return location_; } NO
-
-  // To be able to print AidlLocation (nothing else should use this information)
+  // To be able to print AidlLocation
   friend class AidlError;
   friend std::string android::aidl::mappings::dump_location(const AidlNode&);
   friend std::string android::aidl::java::dump_location(const AidlNode&);
 
+ protected:
+  // This should only be used to construct implicit nodes related to existing nodes
+  const AidlLocation& GetLocation() const { return location_; }
+
  private:
   std::string PrintLine() const;
   std::string PrintLocation() const;
@@ -120,9 +128,7 @@
 class AidlError {
  public:
   AidlError(bool fatal, const std::string& filename) : AidlError(fatal) { os_ << filename << ": "; }
-  AidlError(bool fatal, const AidlLocation& location) : AidlError(fatal) {
-    os_ << location << ": ";
-  }
+  AidlError(bool fatal, const AidlLocation& location);
   AidlError(bool fatal, const AidlNode& node) : AidlError(fatal, node.location_) {}
   AidlError(bool fatal, const AidlNode* node) : AidlError(fatal, *node) {}