Ver Fonte

Support for top-level internal protection, autocomplete internal fixes

Brian Fiete há 3 anos atrás
pai
commit
870c9914be

+ 13 - 8
IDEHelper/Compiler/BfAutoComplete.cpp

@@ -586,8 +586,13 @@ void BfAutoComplete::AddTypeDef(BfTypeDef* typeDef, const StringImpl& filter, bo
 	}
 	}
 }
 }
 
 
-bool BfAutoComplete::CheckProtection(BfProtection protection, bool allowProtected, bool allowPrivate)
+bool BfAutoComplete::CheckProtection(BfProtection protection, BfTypeDef* typeDef, bool allowProtected, bool allowPrivate)
 {
 {
+	if ((protection == BfProtection_Internal) && (typeDef != NULL))
+	{
+		return mModule->CheckProtection(protection, typeDef, allowProtected, allowPrivate);			
+	}
+
 	return (mHasFriendSet) || (protection == BfProtection_Public) ||
 	return (mHasFriendSet) || (protection == BfProtection_Public) ||
 		((protection == BfProtection_Protected) && (allowProtected)) ||
 		((protection == BfProtection_Protected) && (allowProtected)) ||
 		((protection == BfProtection_Private) && (allowPrivate));
 		((protection == BfProtection_Private) && (allowPrivate));
@@ -609,7 +614,7 @@ void BfAutoComplete::AddInnerTypes(BfTypeInstance* typeInst, const StringImpl& f
 {	
 {	
 	for (auto innerType : typeInst->mTypeDef->mNestedTypes)
 	for (auto innerType : typeInst->mTypeDef->mNestedTypes)
 	{
 	{
-		if (CheckProtection(innerType->mProtection, allowProtected, allowPrivate))
+		if (CheckProtection(innerType->mProtection, innerType, allowProtected, allowPrivate))
 			AddTypeDef(innerType, filter);
 			AddTypeDef(innerType, filter);
 	}	
 	}	
 
 
@@ -633,7 +638,7 @@ void BfAutoComplete::AddCurrentTypes(BfTypeInstance* typeInst, const StringImpl&
 				continue;
 				continue;
 		}
 		}
 
 
-	 	if (CheckProtection(nestedTypeDef->mProtection, allowProtected, allowPrivate))
+	 	if (CheckProtection(nestedTypeDef->mProtection, nestedTypeDef, allowProtected, allowPrivate))
 	 		AddTypeDef(nestedTypeDef, filter, onlyAttribute);
 	 		AddTypeDef(nestedTypeDef, filter, onlyAttribute);
 	}
 	}
 
 
@@ -887,7 +892,7 @@ void BfAutoComplete::AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeIn
 		if (fieldDef->mIsNoShow)
 		if (fieldDef->mIsNoShow)
 			continue;
 			continue;
 		
 		
-		if ((fieldDef->mIsStatic) && (CheckProtection(fieldDef->mProtection, allowProtected, allowPrivate)))
+		if ((fieldDef->mIsStatic) && (CheckProtection(fieldDef->mProtection, fieldDef->mDeclaringType, allowProtected, allowPrivate)))
 		{
 		{
 			if (!mModule->CanCast(BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), fieldInst.mResolvedType), selfType))
 			if (!mModule->CanCast(BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), fieldInst.mResolvedType), selfType))
 				continue;
 				continue;
@@ -920,7 +925,7 @@ void BfAutoComplete::AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeIn
 
 
 		bool canUseMethod;
 		bool canUseMethod;
 		canUseMethod = (methodDef->mMethodType == BfMethodType_Normal) || (methodDef->mMethodType == BfMethodType_Mixin);		
 		canUseMethod = (methodDef->mMethodType == BfMethodType_Normal) || (methodDef->mMethodType == BfMethodType_Mixin);		
-		canUseMethod &= CheckProtection(methodDef->mProtection, allowProtected, allowPrivate);
+		canUseMethod &= CheckProtection(methodDef->mProtection, methodDef->mDeclaringType, allowProtected, allowPrivate);
 		
 		
 		if (methodDef->mMethodType != BfMethodType_Normal)
 		if (methodDef->mMethodType != BfMethodType_Normal)
 			continue;
 			continue;
@@ -973,7 +978,7 @@ void BfAutoComplete::AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeIn
 		if (methodInstance->mReturnType != selfType)
 		if (methodInstance->mReturnType != selfType)
 			continue;
 			continue;
 
 
-		if (CheckProtection(propDef->mProtection, allowProtected, allowPrivate))
+		if (CheckProtection(propDef->mProtection, propDef->mDeclaringType, allowProtected, allowPrivate))
 		{
 		{
 			if (propDef->HasExplicitInterface())
 			if (propDef->HasExplicitInterface())
 				continue;
 				continue;
@@ -1038,7 +1043,7 @@ void BfAutoComplete::AddEnumTypeMembers(BfTypeInstance* typeInst, const StringIm
 		auto fieldDef = fieldInst.GetFieldDef();
 		auto fieldDef = fieldInst.GetFieldDef();
 		if ((fieldDef != NULL) && (fieldDef->mIsConst) && 
 		if ((fieldDef != NULL) && (fieldDef->mIsConst) && 
 			((fieldInst.mResolvedType == typeInst) || (fieldInst.mIsEnumPayloadCase)) && 
 			((fieldInst.mResolvedType == typeInst) || (fieldInst.mIsEnumPayloadCase)) && 
-			(CheckProtection(fieldDef->mProtection, allowProtected, allowPrivate)))
+			(CheckProtection(fieldDef->mProtection, fieldDef->mDeclaringType, allowProtected, allowPrivate)))
 		{
 		{
 			if ((!typeInst->IsTypeMemberIncluded(fieldDef->mDeclaringType, activeTypeDef, mModule)) ||
 			if ((!typeInst->IsTypeMemberIncluded(fieldDef->mDeclaringType, activeTypeDef, mModule)) ||
 				(!typeInst->IsTypeMemberAccessible(fieldDef->mDeclaringType, activeTypeDef)))
 				(!typeInst->IsTypeMemberAccessible(fieldDef->mDeclaringType, activeTypeDef)))
@@ -1088,7 +1093,7 @@ void BfAutoComplete::AddExtensionMethods(BfTypeInstance* targetType, BfTypeInsta
 			continue;
 			continue;
 		
 		
 		bool canUseMethod = true;		
 		bool canUseMethod = true;		
-		canUseMethod &= CheckProtection(methodDef->mProtection, allowProtected, allowPrivate);
+		canUseMethod &= CheckProtection(methodDef->mProtection, methodDef->mDeclaringType, allowProtected, allowPrivate);
 		
 		
 		auto methodInstance = mModule->GetRawMethodInstanceAtIdx(extensionContainer, methodDef->mIdx);
 		auto methodInstance = mModule->GetRawMethodInstanceAtIdx(extensionContainer, methodDef->mIdx);
 		if (methodInstance == NULL)
 		if (methodInstance == NULL)

+ 1 - 1
IDEHelper/Compiler/BfAutoComplete.h

@@ -179,7 +179,7 @@ public:
 	int mDefTypeGenericParamIdx;
 	int mDefTypeGenericParamIdx;
 
 
 public:	
 public:	
-	bool CheckProtection(BfProtection protection, bool allowProtected, bool allowPrivate);
+	bool CheckProtection(BfProtection protection, BfTypeDef* typeDef, bool allowProtected, bool allowPrivate);
 	String GetFilter(BfAstNode* node);
 	String GetFilter(BfAstNode* node);
 	const char* GetTypeName(BfType* type);
 	const char* GetTypeName(BfType* type);
 	int GetCursorIdx(BfAstNode* node);
 	int GetCursorIdx(BfAstNode* node);

+ 3 - 1
IDEHelper/Compiler/BfDefBuilder.cpp

@@ -1449,7 +1449,9 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
 	mCurTypeDef->mProtection = (outerTypeDef == NULL) ? BfProtection_Public : BfProtection_Private;	
 	mCurTypeDef->mProtection = (outerTypeDef == NULL) ? BfProtection_Public : BfProtection_Private;	
 	if (typeDeclaration->mProtectionSpecifier != NULL)
 	if (typeDeclaration->mProtectionSpecifier != NULL)
 	{
 	{
-		if ((outerTypeDef == NULL) && (typeDeclaration->mProtectionSpecifier->GetToken() != BfToken_Public))
+		if ((outerTypeDef == NULL) && 
+			(typeDeclaration->mProtectionSpecifier->GetToken() != BfToken_Public) &&
+			(typeDeclaration->mProtectionSpecifier->GetToken() != BfToken_Internal))
 		{
 		{
 			//CS1527
 			//CS1527
 			Fail("Elements defined in a namespace cannot be explicitly declared as private or protected", typeDeclaration->mProtectionSpecifier);
 			Fail("Elements defined in a namespace cannot be explicitly declared as private or protected", typeDeclaration->mProtectionSpecifier);

+ 6 - 0
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -8499,6 +8499,12 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy
 	
 	
 	populateModule->PopulateType(resolvedTypeRef, populateType);
 	populateModule->PopulateType(resolvedTypeRef, populateType);
 	
 	
+	if ((typeInstance != NULL) && (typeInstance->mTypeDef != NULL) && (typeInstance->mTypeDef->mProtection == BfProtection_Internal) && (typeInstance->mTypeDef->mOuterType == NULL))
+	{
+		if (!CheckProtection(typeInstance->mTypeDef->mProtection, typeInstance->mTypeDef, false, false))
+			Fail(StrFormat("'%s' is inaccessible due to its protection level", TypeToString(typeInstance).c_str()), typeRef); // CS0122
+	}
+
 	if ((populateType > BfPopulateType_Identity) && (!ResolveTypeResult_Validate(typeRef, resolvedTypeRef)))
 	if ((populateType > BfPopulateType_Identity) && (!ResolveTypeResult_Validate(typeRef, resolvedTypeRef)))
 		return NULL;	
 		return NULL;