소스 검색

Improved handling of opaque types

Brian Fiete 8 달 전
부모
커밋
16371ab07c
3개의 변경된 파일37개의 추가작업 그리고 26개의 파일을 삭제
  1. 28 24
      IDEHelper/Compiler/BfDefBuilder.cpp
  2. 6 1
      IDEHelper/Compiler/BfModuleTypeUtils.cpp
  3. 3 1
      IDEHelper/Compiler/BfResolvedTypeUtils.cpp

+ 28 - 24
IDEHelper/Compiler/BfDefBuilder.cpp

@@ -1263,6 +1263,7 @@ BfFieldDef* BfDefBuilder::AddField(BfTypeDef* typeDef, BfTypeReference* fieldTyp
 BfMethodDef* BfDefBuilder::AddMethod(BfTypeDef* typeDef, BfMethodType methodType, BfProtection protection, bool isStatic, const StringImpl& name, bool addedAfterEmit)
 {
 	BF_ASSERT(typeDef->mTypeCode != BfTypeCode_TypeAlias);
+	BF_ASSERT(!typeDef->mIsOpaque);
 
 	auto methodDef = new BfMethodDef();
 	methodDef->mIdx = (int)typeDef->mMethods.size();
@@ -2293,27 +2294,30 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
 		needsDynamicCastMethod = false;
 	}
 
-	if (((mCurTypeDef->mTypeCode == BfTypeCode_Object) || (mCurTypeDef->mTypeCode == BfTypeCode_Inferred)) &&
-		(!mCurTypeDef->mIsStatic) && (ctorClear == NULL))
+	if (!mCurTypeDef->mIsOpaque)
 	{
-		auto methodDef = AddMethod(mCurTypeDef, BfMethodType_CtorClear, BfProtection_Private, false, "", mIsComptime);
-		methodDef->mIsMutating = true;
-	}
+		if (((mCurTypeDef->mTypeCode == BfTypeCode_Object) || (mCurTypeDef->mTypeCode == BfTypeCode_Inferred)) &&
+			(!mCurTypeDef->mIsStatic) && (ctorClear == NULL))
+		{
+			auto methodDef = AddMethod(mCurTypeDef, BfMethodType_CtorClear, BfProtection_Private, false, "", mIsComptime);
+			methodDef->mIsMutating = true;
+		}
 
-	if ((needsDtor) && (dtor == NULL))
-	{
-		auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Dtor, BfProtection_Public, false, "", mIsComptime);
-	}
+		if ((needsDtor) && (dtor == NULL))
+		{
+			auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Dtor, BfProtection_Public, false, "", mIsComptime);
+		}
 
-	if ((needsStaticDtor) && (staticDtor == NULL))
-	{
-		auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Dtor, BfProtection_Public, true, "", mIsComptime);
-	}
+		if ((needsStaticDtor) && (staticDtor == NULL))
+		{
+			auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Dtor, BfProtection_Public, true, "", mIsComptime);
+		}
 
-	if ((needsStaticInit) && (staticCtor == NULL))
-	{
-		auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Ctor, BfProtection_Public, true, "", mIsComptime);
-	}	
+		if ((needsStaticInit) && (staticCtor == NULL))
+		{
+			auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Ctor, BfProtection_Public, true, "", mIsComptime);
+		}
+	}
 
 	bool makeCtorPrivate = hasCtor;
 
@@ -2322,7 +2326,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
 	if (mCurTypeDef->mTypeCode == BfTypeCode_Extension)
 		needsDefaultCtor = false;
 
-	if ((needsDefaultCtor) && ((!hasDefaultCtor)))
+	if ((needsDefaultCtor) && (!hasDefaultCtor) && (!mCurTypeDef->mIsOpaque))
 	{
 		BfProtection prot = hasCtor ? BfProtection_Hidden : BfProtection_Public;
 		if (mCurTypeDef->mName == mSystem->mEmptyAtom)
@@ -2340,7 +2344,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
 
 	//TODO: Don't do this for the autocomplete pass
 	if ((needsDynamicCastMethod) && (mCurTypeDef->mTypeCode != BfTypeCode_Interface) && (mCurTypeDef->mTypeCode != BfTypeCode_Extension) &&
-		(!mCurTypeDef->mIsStatic) && (!isAutocomplete) && (!isAlias))
+		(!mCurTypeDef->mIsStatic) && (!isAutocomplete) && (!isAlias) && (!mCurTypeDef->mIsOpaque))
 	{
 		AddDynamicCastMethods(mCurTypeDef);
 	}
@@ -2361,7 +2365,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
 	if (isPayloadEnum)
 		hasNonStaticField = true;
 
-	if (mCurTypeDef->mTypeCode != BfTypeCode_Interface)
+	if ((mCurTypeDef->mTypeCode != BfTypeCode_Interface) && (!mCurTypeDef->mIsOpaque))
 	{
 		if ((hasStaticField) && (staticMarkMethod == NULL))
 		{
@@ -2389,7 +2393,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
 	if (toStringMethod != NULL)
 		wantsToString = false;
 
-	if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (!isPayloadEnum) && (getUnderlyingMethod == NULL))
+	if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (!isPayloadEnum) && (getUnderlyingMethod == NULL) && (!mCurTypeDef->mIsOpaque))
 	{
 		auto methodDef = new BfMethodDef();
 		mCurTypeDef->mMethods.push_back(methodDef);
@@ -2447,7 +2451,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
 		}
 	}
 
-	if (wantsToString)
+	if ((wantsToString) && (!mCurTypeDef->mIsOpaque))
 	{
 		auto methodDef = new BfMethodDef();
 		mCurTypeDef->mMethods.push_back(methodDef);
@@ -2463,7 +2467,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
 		methodDef->mAddedAfterEmit = mIsComptime;
 	}
 
-	if ((needsEqualsMethod) && (equalsMethod == NULL) && (equalsOpMethod == NULL))
+	if ((needsEqualsMethod) && (equalsMethod == NULL) && (equalsOpMethod == NULL) && (!mCurTypeDef->mIsOpaque))
 	{
 		auto methodDef = new BfMethodDef();
 		mCurTypeDef->mMethods.push_back(methodDef);
@@ -2478,7 +2482,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
 		methodDef->mAddedAfterEmit = mIsComptime;
 	}
 
-	if ((needsEqualsMethod) && (strictEqualsMethod == NULL))
+	if ((needsEqualsMethod) && (strictEqualsMethod == NULL) && (!mCurTypeDef->mIsOpaque))
 	{
 		auto methodDef = new BfMethodDef();
 		mCurTypeDef->mMethods.push_back(methodDef);

+ 6 - 1
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -5475,7 +5475,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
 			{
 				auto resolvedFieldType = fieldInstance->GetResolvedType();
 				if ((!typeInstance->IsBoxed()) && (fieldDef != NULL))
-				{					
+				{
 					if (fieldDef->mUsingProtection != BfProtection_Hidden) 
 					{
 						auto fieldDecl = fieldDef->GetFieldDeclaration();
@@ -5743,6 +5743,11 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
 					}
 				}
 
+				if ((resolvedFieldType->IsOpaque()) && (!IsInSpecializedGeneric()))
+					Fail(StrFormat("Invalid use of opaque type '%s' in field '%s.%s'",
+						TypeToString(resolvedFieldType).c_str(), TypeToString(mCurTypeInstance).c_str(), fieldDef->mName.c_str()),
+						fieldDef->mTypeRef, true);
+
 				if ((!typeInstance->IsSpecializedType()) && (!typeInstance->IsOnDemand()) && (fieldDef != NULL) && (!CheckDefineMemberProtection(fieldDef->mProtection, resolvedFieldType)))
 				{
 					//CS0052

+ 3 - 1
IDEHelper/Compiler/BfResolvedTypeUtils.cpp

@@ -2751,7 +2751,9 @@ bool BfTypeInstance::IsValuelessType()
 		return false;
 	}
 	if (mTypeDef->mIsOpaque)
-		return false;
+	{
+		return true;
+	}
 
 	BF_ASSERT((mDefineState >= BfTypeDefineState_Defined) || (mTypeFailed));
 	BF_ASSERT(mInstSize >= 0);