Revert "Revert "Add Reference type""

This reverts commit 6f2f2c026b0b6e372194794e171208a91d74f852.

Reason for revert: mac build problem could be easily fixed

Mac build failure was caused by not declaring template specialization
in header file. Unfortunately, it cannot be easily declared there,
as that would cause cyclic declaration.

The reason why Reference<T>(Reference<O>) constructor could get only
unresolved references is because there is no way to check that the
requested conversion is valid (without specialization or rtti).

However, the appeared messy solution is to be deleted with moving
lookup calls outside of the parser.

Test: builds, hidl_test
Test: builds on mac

Change-Id: Icb24e2ad52563f659e758a186d90e414ab7f1c59
diff --git a/Location.h b/Location.h
index 84dfc0e..994b03e 100644
--- a/Location.h
+++ b/Location.h
@@ -17,27 +17,28 @@
 #ifndef LOCATION_H_
 #define LOCATION_H_
 
-#include <iostream>
 #include <stdint.h>
+#include <iostream>
 #include <string>
 
 // Mimics for yy::location and yy::position
 namespace android {
 
 struct Position {
+    Position() = default;
     Position(std::string f, size_t l, size_t c)
             : mFilename(f), mLine(l), mColumn(c) {}
     inline const std::string &filename() const { return mFilename; }
     inline size_t line() const { return mLine; }
     inline size_t column() const { return mColumn; }
 
-private:
+   private:
     // File name to which this position refers.
-    const std::string mFilename;
+    std::string mFilename;
     // Current line number.
-    const size_t mLine;
+    size_t mLine;
     // Current column number.
-    const size_t mColumn;
+    size_t mColumn;
 };
 
 inline std::ostream& operator<< (std::ostream& ostr, const Position& pos) {
@@ -48,20 +49,30 @@
 }
 
 struct Location {
-    Location (Position begin, Position end)
-            : mBegin(begin), mEnd(end) {}
-    inline const Position &begin() const { return mBegin; }
-    inline const Position &end() const { return mEnd; }
+    Location() = default;
+    Location(const Position& begin, const Position& end) { setLocation(begin, end); }
 
-    inline static Location startOf(const std::string &path) {
+    void setLocation(const Position& begin, const Position& end) {
+        mIsValid = true;
+        mBegin = begin;
+        mEnd = end;
+    }
+
+    bool isValid() const { return mIsValid; }
+    const Position& begin() const { return mBegin; }
+    const Position& end() const { return mEnd; }
+
+    static Location startOf(const std::string& path) {
         return Location(Position(path, 1, 1), Position(path, 1, 1));
     }
 
-private:
+   private:
+    bool mIsValid = false;
+
     // Beginning of the located region.
-    const Position mBegin;
+    Position mBegin;
     // End of the located region.
-    const Position mEnd;
+    Position mEnd;
 };
 
 inline std::ostream& operator<< (std::ostream& ostr, const Location& loc) {