RefType is no more, 1) simplify, 2) repeat
diff --git a/AST.cpp b/AST.cpp
index 651b14a..d10a3ef 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -4,7 +4,6 @@
#include "Formatter.h"
#include "FQName.h"
#include "HandleType.h"
-#include "RefType.h"
#include "Scope.h"
#include <android-base/logging.h>
@@ -168,7 +167,7 @@
return true;
}
-RefType *AST::lookupType(const char *name) {
+Type *AST::lookupType(const char *name) {
FQName fqName(name);
CHECK(fqName.isValid());
@@ -184,7 +183,7 @@
Type *type = mScopePath[i]->lookupType(name);
if (type != NULL) {
- return new RefType(type);
+ return type->ref();
}
}
}
@@ -193,10 +192,10 @@
// LOG(INFO) << "lookupType now looking for " << fqName.string();
- RefType *resultType = mCoordinator->lookupType(fqName);
+ Type *resultType = mCoordinator->lookupType(fqName);
if (resultType) {
- if (!resultType->referencedType()->isInterface()) {
+ if (!resultType->isInterface()) {
// Non-interface types are declared in the associated types header.
FQName typesName(fqName.package(), fqName.version(), "types");
mImportedNames.insert(typesName);
diff --git a/AST.h b/AST.h
index 8dfaa69..7f9ca5c 100644
--- a/AST.h
+++ b/AST.h
@@ -17,7 +17,6 @@
struct Method;
struct NamedType;
struct TypedVar;
-struct RefType;
struct Scope;
struct AST {
@@ -44,7 +43,7 @@
// Look up a type by FQName, "pure" names, i.e. those without package
// or version are first looked up in the current scope chain.
// After that lookup proceeds to imports.
- RefType *lookupType(const char *name);
+ Type *lookupType(const char *name);
// Takes dot-separated path components to a type possibly inside this AST.
// Name resolution goes from root scope downwards, i.e. the path must be
diff --git a/Android.mk b/Android.mk
index 3c6e843..abdaacf 100644
--- a/Android.mk
+++ b/Android.mk
@@ -20,7 +20,6 @@
Interface.cpp \
Method.cpp \
NamedType.cpp \
- RefType.cpp \
ScalarType.cpp \
Scope.cpp \
StringType.cpp \
diff --git a/Coordinator.cpp b/Coordinator.cpp
index f1cc47f..86309f3 100644
--- a/Coordinator.cpp
+++ b/Coordinator.cpp
@@ -1,7 +1,6 @@
#include "Coordinator.h"
#include "AST.h"
-#include "RefType.h"
#include <android-base/logging.h>
@@ -135,7 +134,7 @@
return packagePath;
}
-RefType *Coordinator::lookupType(const FQName &fqName) const {
+Type *Coordinator::lookupType(const FQName &fqName) const {
// Fully qualified.
CHECK(fqName.isFullyQualified());
@@ -158,7 +157,7 @@
Type *type = ast->lookupTypeInternal(fqName.name());
if (type != NULL) {
- return new RefType(type);
+ return type->ref();
}
}
@@ -171,7 +170,7 @@
Type *type = ast->lookupTypeInternal(fqName.name());
if (type != NULL) {
- return new RefType(type);
+ return type->ref();
}
}
}
diff --git a/Coordinator.h b/Coordinator.h
index bc74932..6cb8901 100644
--- a/Coordinator.h
+++ b/Coordinator.h
@@ -11,7 +11,7 @@
struct AST;
struct FQName;
-struct RefType;
+struct Type;
struct Coordinator {
Coordinator(const std::string &interfacesPath);
@@ -19,7 +19,7 @@
AST *parse(const FQName &fqName);
- RefType *lookupType(const FQName &fqName) const;
+ Type *lookupType(const FQName &fqName) const;
std::string getPackagePath(
const FQName &fqName, bool relative = false) const;
diff --git a/RefType.cpp b/RefType.cpp
deleted file mode 100644
index 2e530c3..0000000
--- a/RefType.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-#include "RefType.h"
-
-#include "Formatter.h"
-
-namespace android {
-
-RefType::RefType(Type *type)
- : mReferencedType(type) {
-}
-
-const ScalarType *RefType::resolveToScalarType() const {
- return mReferencedType->resolveToScalarType();
-}
-
-const Type *RefType::referencedType() const {
- return mReferencedType;
-}
-
-bool RefType::isInterface() const {
- return mReferencedType->isInterface();
-}
-
-std::string RefType::getCppType(StorageMode mode, std::string *extra) const {
- return mReferencedType->getCppType(mode, extra);
-}
-
-void RefType::emitReaderWriter(
- Formatter &out,
- const std::string &name,
- const std::string &parcelObj,
- bool parcelObjIsPointer,
- bool isReader,
- ErrorMode mode) const {
- mReferencedType->emitReaderWriter(
- out, name, parcelObj, parcelObjIsPointer, isReader, mode);
-}
-
-void RefType::emitReaderWriterEmbedded(
- Formatter &out,
- const std::string &name,
- bool nameIsPointer,
- const std::string &parcelObj,
- bool parcelObjIsPointer,
- bool isReader,
- ErrorMode mode,
- const std::string &parentName,
- const std::string &offsetText) const {
- mReferencedType->emitReaderWriterEmbedded(
- out,
- name,
- nameIsPointer,
- parcelObj,
- parcelObjIsPointer,
- isReader,
- mode,
- parentName,
- offsetText);
-}
-
-bool RefType::needsEmbeddedReadWrite() const {
- return mReferencedType->needsEmbeddedReadWrite();
-}
-
-bool RefType::resultNeedsDeref() const {
- return mReferencedType->resultNeedsDeref();
-}
-
-} // namespace android
-
diff --git a/RefType.h b/RefType.h
deleted file mode 100644
index 9d19532..0000000
--- a/RefType.h
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef REF_TYPE_H_
-
-#define REF_TYPE_H_
-
-#include "Type.h"
-
-namespace android {
-
-struct RefType : public Type {
- RefType(Type *type);
-
- const ScalarType *resolveToScalarType() const override;
-
- const Type *referencedType() const;
-
- bool isInterface() const override;
-
- std::string getCppType(StorageMode mode, std::string *extra) const override;
-
- void emitReaderWriter(
- Formatter &out,
- const std::string &name,
- const std::string &parcelObj,
- bool parcelObjIsPointer,
- bool isReader,
- ErrorMode mode) const override;
-
- void emitReaderWriterEmbedded(
- Formatter &out,
- const std::string &name,
- bool nameIsPointer,
- const std::string &parcelObj,
- bool parcelObjIsPointer,
- bool isReader,
- ErrorMode mode,
- const std::string &parentName,
- const std::string &offsetText) const override;
-
- bool needsEmbeddedReadWrite() const override;
- bool resultNeedsDeref() const override;
-
-private:
- Type *mReferencedType;
-
- DISALLOW_COPY_AND_ASSIGN(RefType);
-};
-
-} // namespace android
-
-#endif // REF_TYPE_H_
-
diff --git a/Type.h b/Type.h
index 8c95583..bf0b6c6 100644
--- a/Type.h
+++ b/Type.h
@@ -15,6 +15,8 @@
Type();
virtual ~Type();
+ Type *ref() { return this; }
+
virtual bool isScope() const;
virtual bool isInterface() const;
virtual const ScalarType *resolveToScalarType() const;
diff --git a/hidl-gen_l.ll b/hidl-gen_l.ll
index ad5446e..13ab222 100644
--- a/hidl-gen_l.ll
+++ b/hidl-gen_l.ll
@@ -18,7 +18,6 @@
#include "EnumType.h"
#include "HandleType.h"
#include "Method.h"
-#include "RefType.h"
#include "ScalarType.h"
#include "StringType.h"
diff --git a/hidl-gen_y.yy b/hidl-gen_y.yy
index 93988fe..857affa 100644
--- a/hidl-gen_y.yy
+++ b/hidl-gen_y.yy
@@ -7,7 +7,6 @@
#include "EnumType.h"
#include "Interface.h"
#include "Method.h"
-#include "RefType.h"
#include "TypeDef.h"
#include "VectorType.h"
@@ -298,7 +297,7 @@
YYERROR;
}
- $$ = new RefType(container);
+ $$ = container->ref();
}
;
@@ -352,7 +351,7 @@
YYERROR;
}
- $$ = new RefType(enumType);
+ $$ = enumType->ref();
}
| ENUM IDENTIFIER opt_storage_type '{' enum_values opt_comma '}'
{
@@ -361,7 +360,7 @@
YYERROR;
}
- $$ = new RefType(enumType);
+ $$ = enumType->ref();
}
;