Explorar o código

Fixed attribs for properties, renamed SkipAccessCheckAttribute

Brian Fiete %!s(int64=5) %!d(string=hai) anos
pai
achega
04a46850d6

+ 2 - 13
BeefBuild/BeefSpace.toml

@@ -1,15 +1,14 @@
 FileVersion = 1
 Projects = {BeefBuild = {Path = "."}, corlib = "*", Beefy2D = {Path = "../BeefLibs/Beefy2D"}, IDEHelper = {Path = "../IDEHelper"}, Debugger64 = {Path = "../Debugger64"}, BeefySysLib = {Path = "../BeefySysLib"}}
+Unlocked = ["corlib"]
 
 [Workspace]
 StartupProject = "BeefBuild"
 
 [Configs.Debug.Win32]
 Toolset = "GNU"
-BfOptimizationLevel = "O0"
 InitLocalVariables = true
 EmitObjectAccessCheck = false
-EnableCustodian = false
 EnableRealtimeLeakCheck = false
 AllocStackTraceDepth = 0
 ConfigSelections = {IDEHelper = {Enabled = false}}
@@ -25,24 +24,18 @@ EmitDebugInfo = "No"
 AllocStackTraceDepth = 0
 ConfigSelections = {IDEHelper = {Enabled = false}}
 
-[Configs.Release.Win64]
-
 [Configs.Release.Win64z]
 EnableObjectDebugFlags = true
 EmitObjectAccessCheck = true
-EnableCustodian = true
 EnableRealtimeLeakCheck = true
 AllocStackTraceDepth = 0
 
 [Configs.Debug-IDE.Win32]
 Toolset = "GNU"
-BfOptimizationLevel = "O0"
 EmitDebugInfo = "No"
-ArrayBoundsCheck = false
 EmitDynamicCastCheck = false
 EnableObjectDebugFlags = false
 EmitObjectAccessCheck = false
-EnableCustodian = false
 EnableRealtimeLeakCheck = false
 AllocStackTraceDepth = 0
 ConfigSelections = {corlib = {Config = "Debug"}, Beefy2D = {Config = "Debug"}, IDEHelper = {Config = "Debug"}, Debugger64 = {Config = "Debug"}, BeefySysLib = {Config = "Debug"}}
@@ -51,29 +44,25 @@ ConfigSelections = {corlib = {Config = "Debug"}, Beefy2D = {Config = "Debug"}, I
 Toolset = "GNU"
 BfOptimizationLevel = "O0"
 EmitDebugInfo = "No"
-ArrayBoundsCheck = false
 EmitDynamicCastCheck = false
 EnableObjectDebugFlags = false
 EmitObjectAccessCheck = false
-EnableCustodian = false
 EnableRealtimeLeakCheck = false
 ConfigSelections = {corlib = {Config = "Debug"}, Beefy2D = {Config = "Debug"}, IDEHelper = {Config = "Debug"}, Debugger64 = {Config = "Debug"}, BeefySysLib = {Config = "Debug"}}
 
 [Configs.Debug2.Win32]
 Toolset = "GNU"
-BfOptimizationLevel = "O0"
 EmitDebugInfo = "No"
-ArrayBoundsCheck = false
 EmitDynamicCastCheck = false
 EnableObjectDebugFlags = false
 EmitObjectAccessCheck = false
-EnableCustodian = false
 EnableRealtimeLeakCheck = false
 AllocStackTraceDepth = 0
 ConfigSelections = {corlib = {Config = "Debug"}, Beefy2D = {Config = "Debug"}, IDEHelper = {Config = "Debug"}, Debugger64 = {Config = "Debug"}, BeefySysLib = {Config = "Debug"}}
 
 [Configs.Debug2.Win64]
 PreprocessorMacros = ["NEWFONT"]
+BfOptimizationLevel = "O0"
 IntermediateType = "ObjectAndIRCode"
 ConfigSelections = {corlib = {Config = "Debug"}, Beefy2D = {Config = "Debug"}, IDEHelper = {Config = "Debug"}, Debugger64 = {Config = "Debug"}, BeefySysLib = {Config = "Debug"}}
 

+ 1 - 7
BeefLibs/corlib/src/Attribute.bf

@@ -132,12 +132,6 @@ namespace System
 	    
 	}
 
-	[AttributeUsage(.MemberAccess)]
-	public struct SkipAccessCheckAttribute : Attribute
-	{
-	    
-	}
-
 	[AttributeUsage(.Method | .Class | .Struct | .Enum)]
 	public struct OptimizeAttribute : Attribute
 	{
@@ -331,7 +325,7 @@ namespace System
 
 	/// Generally used as a per-method optimization, [DisableObjectAccessChecks] will avoid the runtime per-object-access
 	/// checks which by default are only applied in debug builds anyway.
-	[AttributeUsage(.Method/*, AlwaysIncludeTarget=true*/)]
+	[AttributeUsage(.Method | .MemberAccess)]
 	public struct DisableObjectAccessChecksAttribute : Attribute
 	{
 	}

+ 1 - 1
BeefLibs/corlib/src/Runtime.bf

@@ -159,7 +159,7 @@ namespace System
 			static void Object_GCMarkMembers(Object obj)
 			{
 #if BF_ENABLE_REALTIME_LEAK_CHECK
-				obj.[Friend, SkipAccessCheck]GCMarkMembers();
+				obj.[Friend, DisableObjectAccessChecks]GCMarkMembers();
 #endif
 			}
 

+ 2 - 2
IDE/BeefProj.toml

@@ -25,7 +25,7 @@ OtherLinkFlags = ""
 TargetDirectory = "$(WorkspaceDir)/dist"
 TargetName = "BeefIDE_d"
 OtherLinkFlags = "$(LinkFlags) Comdlg32.lib kernel32.lib user32.lib advapi32.lib shell32.lib IDEHelper64_d.lib"
-DebugCommandArguments = "-proddir=C:\\Beef\\IDE\\Tests\\Test1 -test=scripts\\Data01.txt -testNoExit"
+DebugCommandArguments = "-proddir=C:\\Beef\\IDE"
 DebugWorkingDirectory = "c:\\Beef\\IDE\\Tests\\EmptyTest"
 EnvironmentVars = ["_NO_DEBUG_HEAP=1"]
 
@@ -37,7 +37,7 @@ OtherLinkFlags = ""
 TargetDirectory = "$(WorkspaceDir)/dist"
 TargetName = "BeefIDE"
 OtherLinkFlags = "Comdlg32.lib kernel32.lib user32.lib advapi32.lib shell32.lib Beef042RT64.lib IDEHelper64.lib BeefySysLib64.lib"
-DebugCommandArguments = "-proddir=C:\\Beef\\IDE"
+DebugCommandArguments = "-proddir=C:\\Beef\\IDE\\Tests\\Test1 -test=scripts\\Data01.txt -testNoExit"
 DebugWorkingDirectory = "$(ProjectDir)\\dist"
 EnvironmentVars = ["_NO_DEBUG_HEAP=1"]
 

+ 1 - 0
IDE/BeefSpace.toml

@@ -100,6 +100,7 @@ AllowHotSwapping = false
 AllocStackTraceDepth = 0
 
 [Configs.Debug3.Win64]
+BfOptimizationLevel = "O0"
 IntermediateType = "ObjectAndIRCode"
 ConfigSelections = {Beefy2D = {Config = "Debug"}, IDEHelper = {Config = "Debug"}, Debugger64 = {Config = "Debug"}, BeefySysLib = {Config = "Debug"}}
 

+ 0 - 1
IDE/mintest/BeefProj.toml

@@ -5,7 +5,6 @@ Dependencies = {minlib = "*"}
 Name = "mintest"
 StartupObject = "Hey.Dude.Bro.TestClass"
 DefaultNamespace = "Mintest"
-Aliases = ["corlib"]
 
 [Platform.Windows]
 Description = "Mintest"

+ 3 - 0
IDE/mintest/BeefSpace.toml

@@ -11,6 +11,9 @@ InitLocalVariables = true
 IntermediateType = "ObjectAndIRCode"
 ConfigSelections = {mintest2 = {Enabled = false}}
 
+[[Configs.Debug.Win32.DistinctOptions]]
+Filter = "NoFrame"
+
 [Configs.Debug.Win64]
 IntermediateType = "ObjectAndIRCode"
 COptimizationLevel = "Og"

+ 1 - 0
IDE/mintest/minlib/BeefProj.toml

@@ -5,6 +5,7 @@ Dependencies = {}
 Name = "minlib"
 TargetType = "BeefLib"
 DefaultNamespace = ""
+Aliases = ["corlib"]
 
 [Configs.Debug.Win32]
 OtherLinkFlags = ""

+ 1 - 7
IDE/mintest/minlib/src/System/Attribute.bf

@@ -132,12 +132,6 @@ namespace System
 	    
 	}
 
-	[AttributeUsage(.MemberAccess)]
-	public struct SkipAccessCheckAttribute : Attribute
-	{
-	    
-	}
-
 	[AttributeUsage(.Method | .Class | .Struct | .Enum)]
 	public struct OptimizeAttribute : Attribute
 	{
@@ -337,7 +331,7 @@ namespace System
 	{
 	}
 
-	[AttributeUsage(.Method/*, AlwaysIncludeTarget=true*/)]
+	[AttributeUsage(.Method | .MemberAccess)]
 	public struct DisableObjectAccessChecksAttribute : Attribute
 	{
 	}

+ 1 - 1
IDE/mintest/minlib/src/System/Runtime.bf

@@ -159,7 +159,7 @@ namespace System
 			static void Object_GCMarkMembers(Object obj)
 			{
 #if BF_ENABLE_REALTIME_LEAK_CHECK
-				obj.[Friend, SkipAccessCheck]GCMarkMembers();
+				obj.[Friend, DisableObjectAccessChecks]GCMarkMembers();
 #endif
 			}
 

+ 8 - 0
IDE/mintest/minlib/src/System/String.bf

@@ -241,6 +241,14 @@ namespace System
 			}
 		}
 
+		private int PrivateLength
+		{
+		    get
+		    {
+		        return mLength;
+			}
+		}
+
         int32 AllocSize
         {
 			[Inline]

+ 101 - 8
IDE/mintest/src/main3.bf

@@ -195,15 +195,20 @@ struct Blurg
 
 	}*/
 
-	struct Base
+	public struct Base
 	{
 		int32 mA;
 		int64 mB;
 	}
 
-	struct Derived : Base
+	public struct Derived : Base
 	{
 		int8 mC;
+
+		public int GetC()
+		{
+			return mC + 10000;
+		}
 	}
 
 	static int[] gArr = new .(1, 2, 3, 4, 5, );
@@ -225,17 +230,105 @@ struct Blurg
 		return 3;
 	}
 
-	public static int32 Hey()
+	
+	public static void Test()
+	{
+		//Test_Start
+		Derived dr = .();
+		dr.GetC();
+		Int iVal = (.)123;
+
+		int q = 999;
+
+		//Test_End
+	}
+
+	public static void Test2(int aa, int bb, int cc)
+	{
+		//Test_Start
+		Derived dr2 = .();
+		Int iVal2 = (.)123;
+
+		int q2 = 999;
+
+		String str = scope .();
+
+		//Test_End
+	}
+
+	public static void Recurse(int a)
 	{
-		/*Self.[Checked]GetVal();
-		Self.[Unchecked]GetVal();
-		GetVal2();*/
+		int b = 234;
+		//Recurse_C
+		int c = 345;
 
-		int a = gArr[1];
-		a = gArr[[Unchecked]2];
+		if (a == 10)
+			return;
 
+		Recurse(a + 1);
+		int d = 100 + a;
+	}
+
+	public static void Test3()
+	{
+		//BreakpointTester_Test
+		int a = 0;
+		int b = 0;
+
+		while (a < 20)
+		{
+			//BreakpointTester_LoopA
+			a++;
+		}
+
+		//BreakpointTester_Recurse
+		Recurse(0);
+	}
+
+	public static void Test4()
+	{
+		//Test_Start
+		Derived dr = .();
+		Int iVal = (.)123;
+
+		int q = 999;
+
+		//Test_End
+	}
+
+	//[DisableObjectAccessChecks]
+	public static void Hey2()
+	{
+		String str = "Hey";
+		    //int len = str.[Friend, DisableObjectAccessChecks]PrivateLength;
+		int len = str.[DisableObjectAccessChecks]Length;
+		 //int len = str.[Friend]GetLength();
+	}				   
+
+	public static int32 Hey()
+	{
+		Hey2();
+		Test();
+		Test2(11, 22, 33);
+		Test3();
+		Test4();
+		NoFrame.Test();
 		return (int32)123;
 	}
 
 }
 
+
+class NoFrame
+{
+	public static void Test()
+	{
+		//Test_Start
+		Blurg.Derived dr = .();
+		Int iVal = (.)123;
+
+		int q = 999;
+
+		//Test_End
+	}
+}

+ 4 - 1
IDE/src/ui/ProjectPanel.bf

@@ -1151,7 +1151,10 @@ namespace IDE.ui
 				gApp.WithTabs(scope (tab) =>
 					{
 					    var sourceViewPanel = tab.mContent as SourceViewPanel;
-					    if ((sourceViewPanel != null) && (sourceViewPanel.mProjectSource.mProject == project))
+					    //if (sourceViewPanel?.mProjectSource?.mProject == project)
+						if	((sourceViewPanel != null) &&
+							 (sourceViewPanel.mProjectSource != null) &&
+							 (sourceViewPanel.mProjectSource.mProject == project))
 					    {
 					        sourceViewPanel.DetachFromProjectItem();
 					    }

+ 5 - 2
IDEHelper/Compiler/BfAutoComplete.cpp

@@ -1438,11 +1438,14 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken
 	if ((attrIdentifier = BfNodeDynCast<BfAttributedIdentifierNode>(memberName)))
 	{
 		memberName = attrIdentifier->mIdentifier;
-		if ((memberName == NULL) && (IsAutocompleteNode(attrIdentifier->mAttributes)))
+		if (IsAutocompleteNode(attrIdentifier->mAttributes))
 		{
 			auto bfParser = attrIdentifier->mAttributes->GetSourceData()->ToParser();			
 			int cursorIdx = bfParser->mCursorIdx;
-			isAutocompletingName = cursorIdx == attrIdentifier->mAttributes->GetSrcEnd();			
+			if (cursorIdx == attrIdentifier->mAttributes->GetSrcEnd())
+				isAutocompletingName = true;
+			else
+				return false;
 		}
 	}
 

+ 1 - 3
IDEHelper/Compiler/BfCompiler.cpp

@@ -417,7 +417,6 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly)
 	mReflectTypeInstanceTypeDef = NULL;
 	mReflectUnspecializedGenericType = NULL;
 	mSizedArrayTypeDef = NULL;
-	mSkipAccessCheckAttributeTypeDef = NULL;
 	mStaticInitAfterAttributeTypeDef = NULL;	
 	mStaticInitPriorityAttributeTypeDef = NULL;
 	mStringTypeDef = NULL;
@@ -5870,8 +5869,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
 	mReflectSpecializedGenericType = _GetRequiredType("System.Reflection.SpecializedGenericType");
 	mReflectTypeInstanceTypeDef = _GetRequiredType("System.Reflection.TypeInstance");
 	mReflectUnspecializedGenericType = _GetRequiredType("System.Reflection.UnspecializedGenericType");
-	mSizedArrayTypeDef = _GetRequiredType("System.SizedArray", 2);
-	mSkipAccessCheckAttributeTypeDef = _GetRequiredType("System.SkipAccessCheckAttribute");
+	mSizedArrayTypeDef = _GetRequiredType("System.SizedArray", 2);	
 	mStaticInitAfterAttributeTypeDef = _GetRequiredType("System.StaticInitAfterAttribute");
 	mStaticInitPriorityAttributeTypeDef = _GetRequiredType("System.StaticInitPriorityAttribute");
 	mStringTypeDef = _GetRequiredType("System.String");

+ 1 - 2
IDEHelper/Compiler/BfCompiler.h

@@ -384,8 +384,7 @@ public:
 	BfTypeDef* mDisableObjectAccessChecksAttributeTypeDef;
 	BfTypeDef* mFriendAttributeTypeDef;
 	BfTypeDef* mCheckedAttributeTypeDef;
-	BfTypeDef* mUncheckedAttributeTypeDef;
-	BfTypeDef* mSkipAccessCheckAttributeTypeDef;
+	BfTypeDef* mUncheckedAttributeTypeDef;	
 	BfTypeDef* mStaticInitAfterAttributeTypeDef;
 	BfTypeDef* mStaticInitPriorityAttributeTypeDef;	
 	BfTypeDef* mTestAttributeTypeDef;

+ 16 - 6
IDEHelper/Compiler/BfExprEvaluator.cpp

@@ -3441,7 +3441,7 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
 
 				bool doAccessCheck = true;
 
-				if ((mModule->mAttributeState != NULL) && (mModule->mAttributeState->mCustomAttributes != NULL) && (mModule->mAttributeState->mCustomAttributes->Contains(mModule->mCompiler->mSkipAccessCheckAttributeTypeDef)))
+				if ((mModule->mAttributeState != NULL) && (mModule->mAttributeState->mCustomAttributes != NULL) && (mModule->mAttributeState->mCustomAttributes->Contains(mModule->mCompiler->mDisableObjectAccessChecksAttributeTypeDef)))
 					doAccessCheck = false;
 
 				if (target.IsThis())
@@ -3583,6 +3583,14 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
 					if (isInlined)
 						mPropGetMethodFlags = (BfGetMethodInstanceFlags)(mPropGetMethodFlags | BfGetMethodInstanceFlag_ForceInline);
 
+					if ((mModule->mAttributeState != NULL) && (mModule->mAttributeState->mCustomAttributes != NULL))
+					{
+						if (mModule->mAttributeState->mCustomAttributes->Contains(mModule->mCompiler->mFriendAttributeTypeDef))
+							mPropGetMethodFlags = (BfGetMethodInstanceFlags)(mPropGetMethodFlags | BfGetMethodInstanceFlag_Friend);
+						if (mModule->mAttributeState->mCustomAttributes->Contains(mModule->mCompiler->mDisableObjectAccessChecksAttributeTypeDef))
+							mPropGetMethodFlags = (BfGetMethodInstanceFlags)(mPropGetMethodFlags | BfGetMethodInstanceFlag_DisableObjectAccessChecks);
+					}
+
 					if (mPropDef->mIsStatic)
 					{
 						if ((target) && ((flags & BfLookupFieldFlag_IsImplicitThis) == 0) && (!curCheckType->mTypeDef->IsGlobalsContainer()))
@@ -4800,7 +4808,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
 					if (!mModule->mCurMethodState->mMayNeedThisAccessCheck)
 						doAccessCheck = false;
 				}
-				if ((mModule->mAttributeState != NULL) && (mModule->mAttributeState->mCustomAttributes != NULL) && (mModule->mAttributeState->mCustomAttributes->Contains(mModule->mCompiler->mSkipAccessCheckAttributeTypeDef)))
+				if ((mModule->mAttributeState != NULL) && (mModule->mAttributeState->mCustomAttributes != NULL) && (mModule->mAttributeState->mCustomAttributes->Contains(mModule->mCompiler->mDisableObjectAccessChecksAttributeTypeDef)))
 					doAccessCheck = false;
 				if ((doAccessCheck) && (!isSkipCall))
 					mModule->EmitObjectAccessCheck(target);
@@ -11735,7 +11743,7 @@ BfAllocTarget BfExprEvaluator::ResolveAllocTarget(BfAstNode* allocNode, BfTokenN
 							if ((alignOverride & (alignOverride - 1)) == 0)
 								allocTarget.mAlignOverride = alignOverride;
 							else
-								mModule->Fail("Alignment must be a power of 2", attrib.mRef);							
+								mModule->Fail("Alignment must be a power of 2", attrib.GetRefNode());							
 						}
 					}
 				}
@@ -13787,7 +13795,8 @@ BfTypedValue BfExprEvaluator::GetResult(bool clearResult, bool resolveGenericTyp
 			if (mPropSrc != NULL)
 				mModule->UpdateExprSrcPos(mPropSrc);
 
-			CheckPropFail(matchedMethod, methodInstance.mMethodInstance);
+			if ((mPropGetMethodFlags & BfGetMethodInstanceFlag_Friend) == 0)
+				CheckPropFail(matchedMethod, methodInstance.mMethodInstance);
 			PerformCallChecks(methodInstance.mMethodInstance, mPropSrc);
 
 			if (methodInstance.mMethodInstance->IsSkipCall())
@@ -13802,7 +13811,8 @@ BfTypedValue BfExprEvaluator::GetResult(bool clearResult, bool resolveGenericTyp
 					if ((mPropDefBypassVirtual) && (mPropTarget.mType != methodInstance.mMethodInstance->GetOwner()))
 						mPropTarget = mModule->Cast(mPropSrc, mOrigPropTarget, methodInstance.mMethodInstance->GetOwner());
 
-					mModule->EmitObjectAccessCheck(mPropTarget);
+					if ((mPropGetMethodFlags & BfGetMethodInstanceFlag_DisableObjectAccessChecks) == 0)
+						mModule->EmitObjectAccessCheck(mPropTarget);
 					PushThis(mPropSrc, mPropTarget, methodInstance.mMethodInstance, args);
 				}
 
@@ -15512,7 +15522,7 @@ void BfExprEvaluator::DoMemberReference(BfMemberReferenceExpression* memberRefEx
 		if (attributeState.mCustomAttributes != NULL)
 		{
 			if (mPropDef != NULL)
-				attributeState.mTarget = BfAttributeTargets_Invocation;
+				attributeState.mTarget = (BfAttributeTargets)(attributeState.mTarget | BfAttributeTargets_Invocation);
 			mModule->ValidateCustomAttributes(attributeState.mCustomAttributes, attributeState.mTarget);
 		}		
 	);

+ 1 - 1
IDEHelper/Compiler/BfModule.cpp

@@ -9393,7 +9393,7 @@ void BfModule::ValidateCustomAttributes(BfCustomAttributes* customAttributes, Bf
 		if ((customAttribute.mType->mAttributeData->mAttributeTargets & attrTarget) == 0)
 		{
 			Fail(StrFormat("Attribute '%s' is not valid on this declaration type. It is only valid on %s.",
-				customAttribute.mRef->ToString().c_str(), GetAttributesTargetListString(customAttribute.mType->mAttributeData->mAttributeTargets).c_str()), customAttribute.mRef->mAttributeTypeRef);	// CS0592
+				customAttribute.GetRefNode()->ToString().c_str(), GetAttributesTargetListString(customAttribute.mType->mAttributeData->mAttributeTargets).c_str()), customAttribute.mRef->mAttributeTypeRef);	// CS0592
 		}		
 
 		customAttribute.mAwaitingValidation = false;

+ 11 - 2
IDEHelper/Compiler/BfResolvedTypeUtils.h

@@ -37,7 +37,7 @@ enum BfMethodNameFlags : uint8
 	BfMethodNameFlag_OmitTypeName = 2
 };
 
-enum BfGetMethodInstanceFlags : uint8
+enum BfGetMethodInstanceFlags : uint16
 {
 	BfGetMethodInstanceFlag_None = 0,
 	BfGetMethodInstanceFlag_UnspecializedPass = 1,
@@ -47,7 +47,9 @@ enum BfGetMethodInstanceFlags : uint8
 	BfGetMethodInstanceFlag_Unreified = 0x10,
 	BfGetMethodInstanceFlag_NoForceReification = 0x20,
 	BfGetMethodInstanceFlag_ResultNotUsed = 0x40,
-	BfGetMethodInstanceFlag_ForceInline = 0x80
+	BfGetMethodInstanceFlag_ForceInline = 0x80,
+	BfGetMethodInstanceFlag_Friend = 0x100,
+	BfGetMethodInstanceFlag_DisableObjectAccessChecks = 0x200,
 };
 
 class BfDependencyMap
@@ -2203,6 +2205,13 @@ public:
 	Array<BfCustomAttributeSetProperty> mSetProperties;
 	Array<BfCustomAttributeSetField> mSetField;
 	bool mAwaitingValidation;
+
+	BfAstNode* GetRefNode()
+	{
+		if (mRef->mAttributeTypeRef != NULL)
+			return mRef->mAttributeTypeRef;
+		return mRef;
+	}
 };
 
 class BfCustomAttributes