浏览代码

Fixed properties debug evaluation and struct calls

Brian Fiete 5 年之前
父节点
当前提交
c28ed988b3

+ 13 - 0
IDE/Tests/Test1/scripts/Properties.txt

@@ -0,0 +1,13 @@
+ShowFile("src/Properties.bf")
+GotoText("//Test_Break")
+ToggleBreakpoint()
+RunWithCompiling()
+
+AssertEvalEquals("sb_a0", "{ mA=1100 mB=2101 }")
+AssertEvalEquals("sb_a1", "{ mA=2100 mB=3101 }")
+AssertEvalEquals("sc_a0", "{ mA=4200 mB=5201 }")
+AssertEvalEquals("sc_a1", "{ mA=6200 mB=7201 }")
+AssertEvalEquals("sc_b0", "{ mA=4200 mB=5201 mC=6202 }")
+AssertEvalEquals("sc_b1", "{ mA=7200 mB=8201 mC=9202 }")
+AssertEvalEquals("sc_c0", "{ mA=10200 mB=11201 mC=12202 mD=13203 }")
+AssertEvalEquals("sc_c1", "{ mA=14200 mB=15201 mC=16202 mD=17203 }")

+ 1 - 0
IDE/Tests/Test1/src/Program.bf

@@ -26,6 +26,7 @@ namespace IDETest
 			Multithread.Test();
 			Multithread02.Test();
 			MemoryBreakpointTester.Test();
+			Properties.Test();
 			SplatTester.Test();
 			Stepping_Scope.Test();
 			TypedPrimitives.Test();

+ 147 - 0
IDE/Tests/Test1/src/Properties.bf

@@ -0,0 +1,147 @@
+#pragma warning disable 168
+
+namespace IDETest
+{
+	class Properties
+	{
+		struct StructA
+		{
+			public float mA;
+			public float mB;
+		}
+
+		struct StructB
+		{
+			public float mA;
+			public float mB;
+			public float mC;
+
+			public StructA A0
+			{
+				get
+				{
+					StructA sa;
+					sa.mA = mA + 1000;
+					sa.mB = mB + 2000;
+					return sa;
+				}
+			}
+
+			public StructA A1
+			{
+				get mut
+				{
+					StructA sa;
+					sa.mA = mA + 2000;
+					sa.mB = mB + 3000;
+					return sa;
+				}
+			}
+		}
+
+		struct StructC
+		{
+			public float mA;
+			public float mB;
+			public float mC;
+			public float mD;
+
+			public StructA A0
+			{
+				get
+				{
+					StructA sa;
+					sa.mA = mA + 4000;
+					sa.mB = mB + 5000;
+					return sa;
+				}
+			}
+
+			public StructA A1
+			{
+				get mut
+				{
+					StructA sa;
+					sa.mA = mA + 6000;
+					sa.mB = mB + 7000;
+					return sa;
+				}
+			}
+
+			public StructB B0
+			{
+				get
+				{
+					StructB sb;
+					sb.mA = mA + 4000;
+					sb.mB = mB + 5000;
+					sb.mC = mC + 6000;
+					return sb;
+				}
+			}
+
+			public StructB B1
+			{
+				get mut
+				{
+					StructB sb;
+					sb.mA = mA + 7000;
+					sb.mB = mB + 8000;
+					sb.mC = mC + 9000;
+					return sb;
+				}
+			}
+
+			public StructC C0
+			{
+				get
+				{
+					StructC sc;
+					sc.mA = mA + 10000;
+					sc.mB = mB + 11000;
+					sc.mC = mC + 12000;
+					sc.mD = mD + 13000;
+					return sc;
+				}
+			}
+
+			public StructC C1
+			{
+				get mut
+				{
+					StructC sc;
+					sc.mA = mA + 14000;
+					sc.mB = mB + 15000;
+					sc.mC = mC + 16000;
+					sc.mD = mD + 17000;
+					return sc;
+				}
+			}
+		}
+
+		public static void Test()
+		{
+			StructB sb = .();
+			sb.mA = 100;
+			sb.mB = 101;
+			sb.mC = 102;
+			var sb_a0 = sb.A0;
+			var sb_a1 = sb.A1;
+
+			StructC sc = .();
+			sc.mA = 200;
+			sc.mB = 201;
+			sc.mC = 202;
+			sc.mD = 203;
+			var sc_a0 = sc.A0;
+			var sc_a1 = sc.A1;
+			var sc_b0 = sc.B0;
+			var sc_b1 = sc.B1;
+			var sc_c0 = sc.C0;
+			var sc_c1 = sc.C1;
+
+			//Test_Break
+			int a = 123;
+		}
+	}
+}

+ 1 - 1
IDE/Tests/Test1/src/bugs/Bug002.bf

@@ -16,7 +16,7 @@ class Bug002
 
 	public static void Test()
 	{
-		var strs = scope String[] {"aaa", "bbb", "ccc"};
+		var strs = scope String[] ("aaa", "bbb", "ccc");
 		//Bug002_DoTest
 		Parse(strs);
 	};

+ 3 - 0
IDEHelper/Compiler/BfModule.cpp

@@ -16291,6 +16291,9 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp
 				auto diType = mBfIRBuilder->DbgGetType(thisPtrType);
 				if (!thisType->IsValueType())
 					diType = mBfIRBuilder->DbgCreateArtificialType(diType);
+				else if (!paramVar->mIsSplat)
+					diType = mBfIRBuilder->DbgCreatePointerType(diType);
+					
 				diParams->push_back(diType);
 			}
 

+ 3 - 3
IDEHelper/Compiler/BfResolvedTypeUtils.cpp

@@ -690,10 +690,10 @@ int BfMethodInstance::GetStructRetIdx(bool forceStatic)
 			return 0;
 
 		if ((!HasThis()) || (forceStatic))
-			return 0;		
+			return 0;
 		if (!owner->IsValueType())
-			return 1;		
-		if ((mMethodDef->mIsMutating) || ((!AllowsSplatting()) && (!owner->GetLoweredType(BfTypeUsage_Parameter))))
+			return 1;
+		if ((mMethodDef->mIsMutating) || (!owner->IsSplattable()) || ((!AllowsThisSplatting()) && (!owner->GetLoweredType(BfTypeUsage_Parameter))))
 			return 1;
 		return 0;		
 	}

+ 27 - 9
IDEHelper/DbgExprEvaluator.cpp

@@ -2766,7 +2766,7 @@ DbgTypedValue DbgExprEvaluator::DoLookupField(BfAstNode* targetSrc, DbgTypedValu
 	for (int pass = 0; pass < 2; pass++)
 	{		
 		for (auto method : curCheckType->mMethodList)
-		{			
+		{
 			if (method->mName != NULL)
 			{
 				if (((method->mName[0] == 'g') || (method->mName[0] == 's')) &&
@@ -2788,15 +2788,17 @@ DbgTypedValue DbgExprEvaluator::DoLookupField(BfAstNode* targetSrc, DbgTypedValu
 								continue;
 						}
 
-						if (((!method->mHasThis) && (wantsStatic)) ||
+						DbgSubprogram*& subprogramRef = isGetter ? mPropGet : mPropSet;						
+
+						if ((subprogramRef == NULL) ||
+							((!method->mHasThis) && (wantsStatic)) ||
 							((method->mHasThis) && (!wantsStatic || allowImplicitThis)))
 						{
 							if ((method->mHasThis) && (allowImplicitThis) && (!target))
 							{
 								target = GetThis();
 							}
-
-							DbgSubprogram*& subprogramRef = isGetter ? mPropGet : mPropSet;
+							
 							if (subprogramRef == NULL)
 								subprogramRef = method;
 							else if ((method->mVTableLoc != -1) || (subprogramRef->mVTableLoc == -1))
@@ -6918,19 +6920,27 @@ DbgTypedValue DbgExprEvaluator::CreateCall(BfAstNode* targetSrc, DbgTypedValue t
 		argPushQueue.push_back(methodArg);
 	};
 
+	bool thisByValue = false;
 	int methodParamCount = method->mParams.Size();
+	if (methodParamCount > 0)
+	{
+		method->mParams;
+	}
+
 	if (method->mHasThis)
 	{
 		auto param = method->mParams[paramIdx];		
+		if ((param->mType != NULL) && (param->mType->IsValueType()))
+			thisByValue = true;
 
 		if (!target)
 		{
 			Fail(StrFormat("An object reference is required to invoke the non-static method '%s'", method->ToString().c_str()), targetSrc);
 			return DbgTypedValue();
 		}
-			
-		_PushArg(target, param);		
-		methodParamCount--;
+				
+		_PushArg(target, param);
+		methodParamCount--;		
 	}
 	else
 	{		
@@ -7143,7 +7153,7 @@ DbgTypedValue DbgExprEvaluator::CreateCall(BfAstNode* targetSrc, DbgTypedValue t
 			paramIdx++;
 		}		
 		argIdx++;
-	}	
+	}
 
 	return CreateCall(method, argPushQueue, bypassVirtual);
 }
@@ -7173,6 +7183,14 @@ DbgTypedValue DbgExprEvaluator::CreateCall(DbgSubprogram* method, SizedArrayImpl
 	if (method->mHasThis)
 		paramIdx--;
 
+	bool thisByValue = false;
+	if ((method->mHasThis) && (!method->mParams.IsEmpty()))
+	{
+		auto param = method->mParams[0];
+		if ((param->mType != NULL) && (param->mType->IsValueType()))
+			thisByValue = true;
+	}
+
 	DbgTypedValue compositeRetVal;
 	if (mDebugger->CheckNeedsSRetArgument(method->mReturnType))
 	{
@@ -7211,7 +7229,7 @@ DbgTypedValue DbgExprEvaluator::CreateCall(DbgSubprogram* method, SizedArrayImpl
 
 	if (compositeRetVal.mSrcAddress != 0)
 	{		
-		mDebugger->AddParamValue(0, method->mHasThis, &registers, compositeRetVal);
+		mDebugger->AddParamValue(0, method->mHasThis && !thisByValue, &registers, compositeRetVal);
 		paramIdx++;
 	}