Make all uses of AidlErrorLog include a location

File names and directory names are locations with line = 0 and column =
0.
This allows AidlErrorLog to check for INTERNAL locations being emitted
upon destruction. If that is true, AidlErrorLog will abort after
emitting to original offending log and aditional log saying this should
not happen.

Test: atest aidl_unittests aidl_intergration_test
Change-Id: I0c11b66acb1d22e43f397f3ea9e4c4c14e9f46fc
diff --git a/aidl_language.h b/aidl_language.h
index 86640e9..5f08504 100644
--- a/aidl_language.h
+++ b/aidl_language.h
@@ -82,9 +82,14 @@
   };
 
   AidlLocation(const std::string& file, Point begin, Point end, Source source);
+  AidlLocation(const std::string& file, Source source)
+      : AidlLocation(file, {0, 0}, {0, 0}, source) {}
 
   bool IsInternal() const { return source_ == Source::INTERNAL; }
 
+  // The first line of a file is line 1.
+  bool LocationKnown() const { return begin_.line != 0; }
+
   friend std::ostream& operator<<(std::ostream& os, const AidlLocation& l);
   friend class AidlNode;
 
@@ -127,9 +132,8 @@
 // Generic point for printing any error in the AIDL compiler.
 class AidlErrorLog {
  public:
-  AidlErrorLog(bool fatal, const std::string& filename) : AidlErrorLog(fatal) {
-    os_ << filename << ": ";
-  }
+  AidlErrorLog(bool fatal, const std::string& filename)
+      : AidlErrorLog(fatal, AidlLocation(filename, AidlLocation::Source::EXTERNAL)) {}
   AidlErrorLog(bool fatal, const AidlLocation& location);
   AidlErrorLog(bool fatal, const AidlNode& node) : AidlErrorLog(fatal, node.location_) {}
   AidlErrorLog(bool fatal, const AidlNode* node) : AidlErrorLog(fatal, *node) {}
@@ -139,6 +143,11 @@
   ~AidlErrorLog() {
     os_ << std::endl;
     if (fatal_) abort();
+    if (location_.IsInternal()) {
+      os_ << "Logging an internal location should not happen. Offending location: " << location_
+          << std::endl;
+      abort();
+    }
   }
 
   std::ostream& os_;
@@ -146,10 +155,11 @@
   static bool hadError() { return sHadError; }
 
  private:
-  AidlErrorLog(bool fatal);
 
   bool fatal_;
 
+  const AidlLocation location_;
+
   static bool sHadError;
 
   DISALLOW_COPY_AND_ASSIGN(AidlErrorLog);