refactor: remove AidlConstantReference::SetRefType

A constant reference is composed of <type>.<field>. But when <type> is
missing, <field> is looked up from the defining type (the current
scope).

e.g. enum Enum { A = 0, B = A }; // the second "A" refers to "Enum.A"

Previously, when <type> is missing, we create AidlTypeSpecifer for the
current scope type and set it as AidlConstantReference's type.
However, the purpose of AidlTypeSpecifier is to resolve it to a
AidlDefinedType to look up <field> from it.

In the above example, AidlTypeSpecifier("Enum") is created and resolved
to "Enum" type.

Because we already know the scope type, creating AidlTypeSpecifier and
resolve it again is meaningless.

When traversing AST, these manually created nodes should be skipped with
additional flags. (e.g. user_defined_xxx). Let's avoid creating AST
nodes manually.

Bug: none
Test: m aidl_unittests
Change-Id: I3965e571875c6b6a1c7c237f0b4628d362958d46
diff --git a/parser.cpp b/parser.cpp
index 15faed5..897efa0 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -66,28 +66,23 @@
   ConstantReferenceResolver(const AidlDefinedType* scope, const AidlTypenames& typenames,
                             TypeResolver& resolver, bool* success)
       : scope_(scope), typenames_(typenames), resolver_(resolver), success_(success) {}
-  void Visit(AidlConstantValue&) override {}
-  void Visit(AidlUnaryConstExpression&) override {}
-  void Visit(AidlBinaryConstExpression&) override {}
-  void Visit(AidlConstantReference& v) override {
+  void Visit(const AidlConstantValue&) override {}
+  void Visit(const AidlUnaryConstExpression&) override {}
+  void Visit(const AidlBinaryConstExpression&) override {}
+  void Visit(const AidlConstantReference& v) override {
     if (IsCircularReference(&v)) {
       *success_ = false;
       return;
     }
 
-    // when <type> is missing, we use a scope type
-    if (!v.GetRefType()) {
-      v.SetRefType(std::make_unique<AidlTypeSpecifier>(v.GetLocation(), scope_->GetCanonicalName(),
-                                                       false, nullptr, ""));
-    }
-    if (!v.GetRefType()->IsResolved()) {
+    if (v.GetRefType() && !v.GetRefType()->IsResolved()) {
       if (!resolver_(typenames_.GetDocumentFor(scope_), v.GetRefType().get())) {
         AIDL_ERROR(v.GetRefType()) << "Failed to resolve '" << v.GetRefType()->GetName() << "'";
         *success_ = false;
         return;
       }
     }
-    const AidlConstantValue* resolved = v.Resolve();
+    const AidlConstantValue* resolved = v.Resolve(scope_);
     if (!resolved) {
       AIDL_ERROR(v.GetRefType()) << "Failed to resolve '" << v.GetRefType()->GetName() << "'";
       *success_ = false;
@@ -108,7 +103,9 @@
 
   void Push(const AidlConstantReference* ref) {
     stack_.push_back({scope_, ref});
-    scope_ = ref->GetRefType()->GetDefinedType();
+    if (ref->GetRefType()) {
+      scope_ = ref->GetRefType()->GetDefinedType();
+    }
   }
 
   void Pop() {