From c28ed988b3815b9951e3d5b8b5d2f98ca86dc1e0 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Tue, 29 Sep 2020 11:58:07 -0700 Subject: [PATCH] Fixed properties debug evaluation and struct calls --- IDE/Tests/Test1/scripts/Properties.txt | 13 ++ IDE/Tests/Test1/src/Program.bf | 1 + IDE/Tests/Test1/src/Properties.bf | 147 +++++++++++++++++++++ IDE/Tests/Test1/src/bugs/Bug002.bf | 2 +- IDEHelper/Compiler/BfModule.cpp | 3 + IDEHelper/Compiler/BfResolvedTypeUtils.cpp | 6 +- IDEHelper/DbgExprEvaluator.cpp | 36 +++-- 7 files changed, 195 insertions(+), 13 deletions(-) create mode 100644 IDE/Tests/Test1/scripts/Properties.txt create mode 100644 IDE/Tests/Test1/src/Properties.bf diff --git a/IDE/Tests/Test1/scripts/Properties.txt b/IDE/Tests/Test1/scripts/Properties.txt new file mode 100644 index 00000000..23c31aa0 --- /dev/null +++ b/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 }") diff --git a/IDE/Tests/Test1/src/Program.bf b/IDE/Tests/Test1/src/Program.bf index 28b07036..7db5c7da 100644 --- a/IDE/Tests/Test1/src/Program.bf +++ b/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(); diff --git a/IDE/Tests/Test1/src/Properties.bf b/IDE/Tests/Test1/src/Properties.bf new file mode 100644 index 00000000..c400a707 --- /dev/null +++ b/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; + } + } +} diff --git a/IDE/Tests/Test1/src/bugs/Bug002.bf b/IDE/Tests/Test1/src/bugs/Bug002.bf index 5b0e0a88..f81acfc0 100644 --- a/IDE/Tests/Test1/src/bugs/Bug002.bf +++ b/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); }; diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 7b512386..145ca132 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/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); } diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp index aad6e6a7..6fa92d59 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp +++ b/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; } diff --git a/IDEHelper/DbgExprEvaluator.cpp b/IDEHelper/DbgExprEvaluator.cpp index 495e937a..b7ad1a12 100644 --- a/IDEHelper/DbgExprEvaluator.cpp +++ b/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, ®isters, compositeRetVal); + mDebugger->AddParamValue(0, method->mHasThis && !thisByValue, ®isters, compositeRetVal); paramIdx++; }