1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12:21 +02:00

Fixed attribs for properties, renamed SkipAccessCheckAttribute

This commit is contained in:
Brian Fiete 2019-12-01 14:40:17 -08:00
parent 9c44273737
commit 04a46850d6
19 changed files with 162 additions and 58 deletions

View file

@ -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"}}

View file

@ -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
{
}

View file

@ -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
}

View file

@ -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"]

View file

@ -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"}}

View file

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

View file

@ -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"

View file

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

View file

@ -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
{
}

View file

@ -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
}

View file

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

View file

@ -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 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)
{
int b = 234;
//Recurse_C
int c = 345;
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()
{
/*Self.[Checked]GetVal();
Self.[Unchecked]GetVal();
GetVal2();*/
int a = gArr[1];
a = gArr[[Unchecked]2];
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
}
}

View file

@ -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();
}

View file

@ -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;
}
}

View file

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

View file

@ -385,7 +385,6 @@ public:
BfTypeDef* mFriendAttributeTypeDef;
BfTypeDef* mCheckedAttributeTypeDef;
BfTypeDef* mUncheckedAttributeTypeDef;
BfTypeDef* mSkipAccessCheckAttributeTypeDef;
BfTypeDef* mStaticInitAfterAttributeTypeDef;
BfTypeDef* mStaticInitPriorityAttributeTypeDef;
BfTypeDef* mTestAttributeTypeDef;

View file

@ -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,6 +13795,7 @@ BfTypedValue BfExprEvaluator::GetResult(bool clearResult, bool resolveGenericTyp
if (mPropSrc != NULL)
mModule->UpdateExprSrcPos(mPropSrc);
if ((mPropGetMethodFlags & BfGetMethodInstanceFlag_Friend) == 0)
CheckPropFail(matchedMethod, methodInstance.mMethodInstance);
PerformCallChecks(methodInstance.mMethodInstance, mPropSrc);
@ -13802,6 +13811,7 @@ BfTypedValue BfExprEvaluator::GetResult(bool clearResult, bool resolveGenericTyp
if ((mPropDefBypassVirtual) && (mPropTarget.mType != methodInstance.mMethodInstance->GetOwner()))
mPropTarget = mModule->Cast(mPropSrc, mOrigPropTarget, methodInstance.mMethodInstance->GetOwner());
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);
}
);

View file

@ -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;

View file

@ -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