瀏覽代碼

Reflect Filtered, extension attribs fix, generic arg BfAstNode

Brian Fiete 3 年之前
父節點
當前提交
361be9dc92

+ 2 - 1
IDE/src/BuildOptions.bf

@@ -71,7 +71,8 @@ namespace IDE
 			No,
 			IncludeType,
 			AssumeInstantiated,
-			IncludeAll
+			IncludeAll,
+			IncludeFiltered
 		}
 	}
 

+ 4 - 1
IDE/src/Compiler/BfSystem.bf

@@ -26,8 +26,9 @@ namespace IDE.Compiler
 			ReflectStaticMethods		= 0x800,
 			ReflectNonStaticMethods		= 0x1000,
 			ReflectConstructors			= 0x2000,
+			ReflectAlwaysIncludeFiltered= 0x4000,
 
-			All							= 0x3FFF
+			All							= 0x7FFF
 		};
 
 		[CallingConvention(.Stdcall), CLink]
@@ -401,6 +402,8 @@ namespace IDE.Compiler
 				orFlags |= .ReflectAssumeInstantiated;
 			case .IncludeAll:
 				orFlags |= .ReflectAlwaysIncludeType | .ReflectAlwaysIncludeAll | .ReflectAssumeInstantiated;
+			case .IncludeFiltered:
+				orFlags |= .ReflectAlwaysIncludeType | .ReflectAlwaysIncludeFiltered | .ReflectAssumeInstantiated;
 			}
 
 			SetFlag(typeOption.mReflectBoxing, .ReflectBoxing);

+ 1 - 1
IDEHelper/Compiler/BfAst.h

@@ -2534,7 +2534,7 @@ public:
 	BF_AST_TYPE(BfGenericInstanceTypeRef, BfElementedTypeRef);
 
 	BfTokenNode* mOpenChevron;
-	BfSizedArray<BfTypeReference*> mGenericArguments;	
+	BfSizedArray<BfAstNode*> mGenericArguments;	
 	BfSizedArray<ASTREF(BfAstNode*)> mCommas;
 	BfTokenNode* mCloseChevron;
 	int GetGenericArgCount()

+ 2 - 1
IDEHelper/Compiler/BfAutoComplete.cpp

@@ -2075,7 +2075,8 @@ void BfAutoComplete::CheckTypeRef(BfTypeReference* typeRef, bool mayBeIdentifier
 	{
 		CheckTypeRef(genericTypeRef->mElementType, mayBeIdentifier, isInExpression, onlyAttribute);
 		for (auto genericArg : genericTypeRef->mGenericArguments)
-			CheckTypeRef(genericArg, false, isInExpression, false);
+			CheckNode(genericArg);
+			//CheckTypeRef(genericArg, false, isInExpression, false);
 		return;
 	}
 

+ 1 - 1
IDEHelper/Compiler/BfCompiler.cpp

@@ -4365,7 +4365,7 @@ void BfCompiler::ProcessAutocompleteTempType()
 
 	if (tempTypeDef->mTypeDeclaration->mAttributes != NULL)
 	{
-		auto customAttrs = module->GetCustomAttributes(tempTypeDef);		
+		auto customAttrs = module->GetCustomAttributes(tempTypeDef);
 		delete customAttrs;
 	}
 	

+ 2 - 0
IDEHelper/Compiler/BfModule.cpp

@@ -11851,6 +11851,8 @@ BfCustomAttributes* BfModule::GetCustomAttributes(BfAttributeDirective* attribut
 
 BfCustomAttributes* BfModule::GetCustomAttributes(BfTypeDef* typeDef)
 {
+	BF_ASSERT(mCompiler->IsAutocomplete());
+
 	BfAttributeTargets attrTarget;
 	if (typeDef->mIsDelegate)
 		attrTarget = BfAttributeTargets_Delegate;

+ 3 - 3
IDEHelper/Compiler/BfModule.h

@@ -1727,7 +1727,7 @@ public:
 	BfGenericExtensionEntry* BuildGenericExtensionInfo(BfTypeInstance* genericTypeInst, BfTypeDef* partialTypeDef);
 	bool InitGenericParams(BfType* resolvedTypeRef);
 	bool FinishGenericParams(BfType* resolvedTypeRef);
-	bool ValidateGenericConstraints(BfTypeReference* typeRef, BfTypeInstance* genericTypeInstance, bool ignoreErrors);
+	bool ValidateGenericConstraints(BfAstNode* typeRef, BfTypeInstance* genericTypeInstance, bool ignoreErrors);
 	BfType* ResolveGenericMethodTypeRef(BfTypeReference* typeRef, BfMethodInstance* methodInstance, BfGenericParamInstance* genericParamInstance, BfTypeVector* methodGenericArgsOverride);
 	bool AreConstraintsSubset(BfGenericParamInstance* checkInner, BfGenericParamInstance* checkOuter);
 	bool CheckConstraintState(BfAstNode* refNode);
@@ -1852,7 +1852,7 @@ public:
 	BfTypeInstance* GetBaseType(BfTypeInstance* typeInst);
 	void HandleTypeGenericParamRef(BfAstNode* refNode, BfTypeDef* typeDef, int typeGenericParamIdx);
 	void HandleMethodGenericParamRef(BfAstNode* refNode, BfTypeDef* typeDef, BfMethodDef* methodDef, int typeGenericParamIdx);
-	bool ResolveTypeResult_Validate(BfTypeReference* typeRef, BfType* resolvedTypeRef);
+	bool ResolveTypeResult_Validate(BfAstNode* typeRef, BfType* resolvedTypeRef);
 	BfType* ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTypeRef, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags);
 	void ShowAmbiguousTypeError(BfAstNode* refNode, BfTypeDef* typeDef, BfTypeDef* otherTypeDef);
 	void ShowGenericArgCountError(BfAstNode* typeRef, int wantedGenericParams);	
@@ -1865,7 +1865,7 @@ public:
 	void CheckTypeRefFixit(BfAstNode* typeRef, const char* appendName = NULL);
 	void CheckIdentifierFixit(BfAstNode* node);
 	void TypeRefNotFound(BfTypeReference* typeRef, const char* appendName = NULL);
-	bool ValidateTypeWildcard(BfTypeReference* typeRef, bool isAttributeRef);	
+	bool ValidateTypeWildcard(BfAstNode* typeRef, bool isAttributeRef);	
 	void GetDelegateTypeRefAttributes(BfDelegateTypeRef* delegateTypeRef, BfCallingConvention& callingConvention);
 	BfType* ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0, int numGenericArgs = 0);
 	BfType* ResolveTypeRefAllowUnboundGenerics(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, bool resolveGenericParam = true);

+ 23 - 15
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -300,7 +300,7 @@ bool BfModule::FinishGenericParams(BfType* resolvedTypeRef)
 	return true;
 }
 
-bool BfModule::ValidateGenericConstraints(BfTypeReference* typeRef, BfTypeInstance* genericTypeInst, bool ignoreErrors)
+bool BfModule::ValidateGenericConstraints(BfAstNode* typeRef, BfTypeInstance* genericTypeInst, bool ignoreErrors)
 {
 	if ((mCurTypeInstance != NULL) && (mCurTypeInstance->IsTypeAlias()) && (mCurTypeInstance->IsGenericTypeInstance()))
 	{
@@ -1729,14 +1729,12 @@ BfTypeOptions* BfModule::GetTypeOptions(BfTypeDef* typeDef)
 					mergedTypeOptions.mOptimizationLevel = typeOptions.mOptimizationLevel;
 				if (typeOptions.mEmitDebugInfo != -1)
 					mergedTypeOptions.mEmitDebugInfo = typeOptions.mEmitDebugInfo;
-				
-				if (typeOptions.mReflectMethodFilters.IsEmpty())
-
+								
 				mergedTypeOptions.mOrFlags = (BfOptionFlags)(mergedTypeOptions.mOrFlags | typeOptions.mOrFlags);
 				mergedTypeOptions.mAndFlags = (BfOptionFlags)(mergedTypeOptions.mAndFlags | typeOptions.mOrFlags);
 
 				mergedTypeOptions.mAndFlags = (BfOptionFlags)(mergedTypeOptions.mAndFlags & typeOptions.mAndFlags);
-				mergedTypeOptions.mOrFlags = (BfOptionFlags)(mergedTypeOptions.mOrFlags & typeOptions.mAndFlags);
+				mergedTypeOptions.mOrFlags = (BfOptionFlags)(mergedTypeOptions.mOrFlags & typeOptions.mAndFlags);				
 				
 				if (mergedTypeOptions.HasReflectMethodFilters())
 				{
@@ -3835,7 +3833,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
 
 	if (!typeInstance->IsBoxed())
 	{
-		if ((typeInstance->mCustomAttributes == NULL) && (typeDef->mTypeDeclaration != NULL) && (typeDef->mTypeDeclaration->mAttributes != NULL))
+		if ((typeInstance->mCustomAttributes == NULL) && (typeDef->mTypeDeclaration != NULL) && (typeDef->HasCustomAttributes()))
 		{
 			BfAttributeTargets attrTarget;
 			if ((typeDef->mIsDelegate) || (typeDef->mIsFunction))
@@ -5411,8 +5409,12 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
 	}
 
 	bool typeOptionsIncludeAll = false;	
-	if (typeOptions != NULL)	
-		typeOptionsIncludeAll = typeOptions->Apply(typeOptionsIncludeAll, BfOptionFlags_ReflectAlwaysIncludeAll);			
+	bool typeOptionsIncludeFiltered = false;
+	if (typeOptions != NULL)
+	{
+		typeOptionsIncludeAll = typeOptions->Apply(typeOptionsIncludeAll, BfOptionFlags_ReflectAlwaysIncludeAll);
+		typeOptionsIncludeFiltered = typeOptions->Apply(typeOptionsIncludeAll, BfOptionFlags_ReflectAlwaysIncludeFiltered);
+	}
 
 	// Generate all methods. Pass 1
 	for (auto methodDef : typeDef->mMethods)
@@ -5543,6 +5545,8 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
 				implRequired = true;
 
 			if ((typeOptionsIncludeAll) && (ApplyTypeOptionMethodFilters(true, methodDef, typeOptions)))
+
+			if ((typeOptionsIncludeAll || typeOptionsIncludeFiltered) && (ApplyTypeOptionMethodFilters(typeOptionsIncludeAll, methodDef, typeOptions)))
 				implRequired = true;
 
 // 			if ((typeOptions != NULL) && (CheckTypeOptionMethodFilters(typeOptions, methodDef)))
@@ -7416,7 +7420,7 @@ BfType* BfModule::ResolveInnerType(BfType* outerType, BfAstNode* typeRef, BfPopu
 		{
 			for (auto genericArgTypeRef : genericTypeRef->mGenericArguments)
 			{
-				auto genericArgType = ResolveTypeRef(genericArgTypeRef, BfPopulateType_IdentityNoRemapAlias);
+				auto genericArgType = ResolveTypeRef(genericArgTypeRef, NULL, BfPopulateType_IdentityNoRemapAlias);
 				if (genericArgType == NULL)
 					return NULL;
 				genericArgs.push_back(genericArgType);
@@ -8426,7 +8430,7 @@ BfGenericParamInstance* BfModule::GetGenericParamInstance(BfGenericParamType* ty
 	return GetGenericTypeParamInstance(type->mGenericParamIdx);
 }
 
-bool BfModule::ResolveTypeResult_Validate(BfTypeReference* typeRef, BfType* resolvedTypeRef)
+bool BfModule::ResolveTypeResult_Validate(BfAstNode* typeRef, BfType* resolvedTypeRef)
 {
 	if ((typeRef == NULL) || (resolvedTypeRef == NULL))
 		return true;
@@ -9311,7 +9315,7 @@ void BfModule::TypeRefNotFound(BfTypeReference* typeRef, const char* appendName)
 	CheckTypeRefFixit(typeRef, appendName);
 }
 
-bool BfModule::ValidateTypeWildcard(BfTypeReference* typeRef, bool isAttributeRef)
+bool BfModule::ValidateTypeWildcard(BfAstNode* typeRef, bool isAttributeRef)
 {
 	if (typeRef == NULL)
 		return false;
@@ -10042,7 +10046,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
 						{
 							for (auto genericParamTypeRef : genericTypeRef->mGenericArguments)
 							{
-								auto genericParam = ResolveTypeRef(genericParamTypeRef, BfPopulateType_Declaration);
+								auto genericParam = ResolveTypeRef(genericParamTypeRef, NULL, BfPopulateType_Declaration);
 								if (genericParam == NULL)
 									return ResolveTypeResult(typeRef, NULL, populateType, resolveFlags);
 								genericArgs.push_back(genericParam);
@@ -10560,9 +10564,10 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
 		int wantNumGenericParams = genericTypeInstRef->GetGenericArgCount();
 		BfTypeDef* ambiguousTypeDef = NULL;
 
-		Array<BfTypeReference*> genericArguments;
+		Array<BfAstNode*> genericArguments;
 		std::function<void(BfTypeReference*)> _GetTypeRefs = [&](BfTypeReference* typeRef)
 		{
+			//TODO:GENERICS
 			if (auto elementedTypeRef = BfNodeDynCast<BfElementedTypeRef>(typeRef))
 			{
 				_GetTypeRefs(elementedTypeRef->mElementType);
@@ -10612,7 +10617,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
 
 		for (auto genericArgRef : genericArguments)
 		{
-			auto genericArg = ResolveTypeRef(genericArgRef, BfPopulateType_Identity, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_AllowGenericTypeParamConstValue | BfResolveTypeRefFlag_AllowGenericMethodParamConstValue));
+			auto genericArg = ResolveTypeRef(genericArgRef, NULL, BfPopulateType_Identity, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_AllowGenericTypeParamConstValue | BfResolveTypeRefFlag_AllowGenericMethodParamConstValue));
 			if ((genericArg == NULL) || (genericArg->IsVar()))
 			{				
 				mContext->mResolvedTypes.RemoveEntry(resolvedEntry);
@@ -11368,6 +11373,9 @@ BfTypeInstance* BfModule::GetUnspecializedTypeInstance(BfTypeInstance* typeInst)
 
 BfType* BfModule::ResolveTypeRef(BfAstNode* astNode, const BfSizedArray<BfTypeReference*>* genericArgs, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags)
 {
+	if (auto typeRef = BfNodeDynCast<BfTypeReference>(astNode))
+		return ResolveTypeRef(typeRef, populateType, resolveFlags);
+
 	if ((genericArgs == NULL) || (genericArgs->size() == 0))
 	{
 		if (auto identifier = BfNodeDynCast<BfIdentifierNode>(astNode))
@@ -11429,7 +11437,7 @@ BfType* BfModule::ResolveTypeRef(BfAstNode* astNode, const BfSizedArray<BfTypeRe
 		typeRef->mParent = genericInstanceTypeRef;
 #endif
 
-		BfDeferredAstSizedArray<BfTypeReference*> arguments(genericInstanceTypeRef->mGenericArguments, &alloc);
+		BfDeferredAstSizedArray<BfAstNode*> arguments(genericInstanceTypeRef->mGenericArguments, &alloc);
 
 		for (auto genericArg : *genericArgs)
 		{	

+ 1 - 1
IDEHelper/Compiler/BfReducer.cpp

@@ -5208,7 +5208,7 @@ BfTypeReference* BfReducer::DoCreateTypeRef(BfAstNode* firstNode, CreateTypeRefF
 				}
 
 				auto genericInstance = mAlloc->Alloc<BfGenericInstanceTypeRef>();
-				BfDeferredSizedArray<BfTypeReference*> genericArguments(genericInstance->mGenericArguments, mAlloc);
+				BfDeferredSizedArray<BfAstNode*> genericArguments(genericInstance->mGenericArguments, mAlloc);
 				BfDeferredAstSizedArray<BfAstNode*> commas(genericInstance->mCommas, mAlloc);
 				ReplaceNode(typeRef, genericInstance);
 				genericInstance->mOpenChevron = tokenNode;

+ 21 - 1
IDEHelper/Compiler/BfResolvedTypeUtils.cpp

@@ -3255,7 +3255,7 @@ int BfResolvedTypeSet::DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHa
 			BfTypeVector genericArgs;
 			for (auto genericArgTypeRef : genericInstTypeRef->mGenericArguments)
 			{
-				auto argType = ctx->mModule->ResolveTypeRef(genericArgTypeRef, BfPopulateType_Identity, ctx->mResolveFlags);
+				auto argType = ctx->mModule->ResolveTypeRef(genericArgTypeRef, NULL, BfPopulateType_Identity, ctx->mResolveFlags);
 				if (argType != NULL)
 					genericArgs.Add(argType);
 				else
@@ -3747,6 +3747,16 @@ int BfResolvedTypeSet::Hash(BfTypeReference* typeRef, LookupContext* ctx, BfHash
 	return HASH_MIX(hashVal, hashSeed);
 }
 
+int BfResolvedTypeSet::Hash(BfAstNode* typeRefNode, LookupContext* ctx, BfHashFlags flags, int hashSeed)
+{
+	if (auto typeRef = BfNodeDynCast<BfTypeReference>(typeRefNode))
+		return Hash(typeRef, ctx, flags, hashSeed);
+
+	BF_FATAL("Not supported");
+
+	return 0;
+}
+
 // These types can be from different contexts ("foreign" types) so we can't just compare ptrs
 bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx)
 {
@@ -4577,6 +4587,16 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfTypeReference* rhs, LookupContext*
 	return false;
 }
 
+bool BfResolvedTypeSet::Equals(BfType* lhs, BfAstNode* rhs, LookupContext* ctx)
+{
+	if (auto rhsTypeRef = BfNodeDynCast<BfTypeReference>(rhs))
+		return Equals(lhs, rhsTypeRef, ctx);
+
+	BF_FATAL("Illegal");
+
+	return false;
+}
+
 void BfResolvedTypeSet::RemoveEntry(BfResolvedTypeSet::Entry* entry)
 {
  	int hashIdx = (entry->mHash & 0x7FFFFFFF) % mHashSize;

+ 3 - 1
IDEHelper/Compiler/BfResolvedTypeUtils.h

@@ -1810,7 +1810,7 @@ class BfGenericTypeInfo
 public:
 	typedef Array<BfGenericTypeParamInstance*> GenericParamsVector;
 
-	Array<BfTypeReference*> mTypeGenericArgumentRefs;
+	Array<BfAstNode*> mTypeGenericArgumentRefs;
 	BfTypeVector mTypeGenericArguments;
 	GenericParamsVector mGenericParams;
 	BfGenericExtensionInfo* mGenericExtensionInfo;
@@ -2571,8 +2571,10 @@ public:
 	static int DirectHash(BfTypeReference* typeRef, LookupContext* ctx, BfHashFlags flags = BfHashFlag_None, int hashSeed = 0);
 	static int DoHash(BfTypeReference* typeRef, LookupContext* ctx, BfHashFlags flags, int& hashSeed);
 	static int Hash(BfTypeReference* typeRef, LookupContext* ctx, BfHashFlags flags = BfHashFlag_None, int hashSeed = 0);
+	static int Hash(BfAstNode* typeRefNode, LookupContext* ctx, BfHashFlags flags = BfHashFlag_None, int hashSeed = 0);
 	static bool Equals(BfType* lhs, BfType* rhs, LookupContext* ctx);	
 	static bool Equals(BfType* lhs, BfTypeReference* rhs, LookupContext* ctx);
+	static bool Equals(BfType* lhs, BfAstNode* rhs, LookupContext* ctx);
 	static bool Equals(BfType* lhs, BfTypeReference* rhs, BfTypeDef* rhsTypeDef, LookupContext* ctx);
 
 public:

+ 10 - 0
IDEHelper/Compiler/BfSystem.cpp

@@ -974,6 +974,16 @@ bool BfTypeDef::HasSource(BfSource* source)
 	return false;
 }
 
+bool BfTypeDef::HasCustomAttributes()
+{
+	if ((mTypeDeclaration != NULL) && (mTypeDeclaration->mAttributes != NULL))
+		return true;
+	for (auto& partial : mPartials)
+		if ((partial->mTypeDeclaration != NULL) && (partial->mTypeDeclaration->mAttributes != NULL))
+			return true;
+	return false;
+}
+
 //////////////////////////////////////////////////////////////////////////
 
 BfProject::BfProject()

+ 2 - 0
IDEHelper/Compiler/BfSystem.h

@@ -1136,6 +1136,7 @@ public:
 		return mTypeCode == BfTypeCode_Extension;
 	}
 	bool HasSource(BfSource* source);
+	bool HasCustomAttributes();
 };
 
 struct BfTypeDefMapFuncs : public MultiHashSetFuncs
@@ -1463,6 +1464,7 @@ enum BfOptionFlags
 	BfOptionFlags_ReflectStaticMethods		= 0x800,
 	BfOptionFlags_ReflectNonStaticMethods	= 0x1000,
 	BfOptionFlags_ReflectConstructors		= 0x2000,
+	BfOptionFlags_ReflectAlwaysIncludeFiltered = 0x4000,
 
 	BfOptionFlags_Reflect_MethodMask		= BfOptionFlags_ReflectStaticMethods | BfOptionFlags_ReflectNonStaticMethods | BfOptionFlags_ReflectConstructors,
 	BfOptionFlags_Mask = 0x3FFF