1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fixed constExprs with ints, hover for enum values, _ for enums

This commit is contained in:
Brian Fiete 2019-12-24 13:13:04 -08:00
parent 4087bf8e2a
commit 4dcd7f9c6a
21 changed files with 293 additions and 142 deletions

View file

@ -2193,7 +2193,7 @@ BFP_EXPORT void BFP_CALLTYPE BfpThread_GetIntRegisters(BfpThread* thread, intptr
{ {
CONTEXT ctx; CONTEXT ctx;
memset(&ctx, 0, sizeof(CONTEXT)); memset(&ctx, 0, sizeof(CONTEXT));
ctx.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS; ctx.ContextFlags = CONTEXT_INTEGER | CONTEXT_CONTROL;
BOOL success = ::GetThreadContext((HANDLE)thread, &ctx); BOOL success = ::GetThreadContext((HANDLE)thread, &ctx);
if (!success) if (!success)
{ {

View file

@ -34,7 +34,7 @@ typedef fd_set FD_SET;
USING_NS_BF; USING_NS_BF;
// All DLLs must use the same ABI version // All DLLs must use the same ABI version
#define BP_ABI_VERSION 2 #define BP_ABI_VERSION 3
BpManager* BpManager::sBpManager = NULL; BpManager* BpManager::sBpManager = NULL;
static bool gOwnsBpManager = false; static bool gOwnsBpManager = false;
@ -665,6 +665,7 @@ BpManager::BpManager() : mShutdownEvent(true), mTLSDtor(&FlsFreeFunc)
mSocket = INVALID_SOCKET; mSocket = INVALID_SOCKET;
mConnectState = BpConnectState_NotConnected; mConnectState = BpConnectState_NotConnected;
mThread = NULL; mThread = NULL;
mThreadId = 0;
mCurTick = 0; mCurTick = 0;
mCurThreadId = 0; mCurThreadId = 0;
mOutBlockSizeLeft = 0; mOutBlockSizeLeft = 0;
@ -890,6 +891,8 @@ void BpManager::FinishWorkThread()
void BpManager::ThreadProc() void BpManager::ThreadProc()
{ {
BfpThread_SetName(NULL, "BeefPerf", NULL);
if (!Connect()) if (!Connect())
{ {
mConnectState = BpConnectState_Failed; mConnectState = BpConnectState_Failed;
@ -1482,7 +1485,7 @@ BpResult BpManager::Init(const char* serverName, const char* sessionName)
mRootCmdTarget.Init(); mRootCmdTarget.Init();
mThread = BfpThread_Create(ThreadProcThunk, (void*)this, 64 * 1024, BfpThreadCreateFlag_StackSizeReserve); mThread = BfpThread_Create(ThreadProcThunk, (void*)this, 64 * 1024, BfpThreadCreateFlag_StackSizeReserve, &mThreadId);
return BpResult_Ok; return BpResult_Ok;
} }

View file

@ -195,6 +195,7 @@ public:
#endif #endif
SOCKET mSocket; SOCKET mSocket;
BfpThread* mThread; BfpThread* mThread;
BfpThreadId mThreadId;
String mServerName; String mServerName;
String mSessionName; String mSessionName;
String mSessionID; String mSessionID;

View file

@ -39,7 +39,7 @@ namespace IDE.Compiler
GetFixits, GetFixits,
GetTypeDefList, GetTypeDefList,
GetTypeDefInto, GetTypeDefInto,
GetVarType GetResultString
} }
public class ResolveParams public class ResolveParams
@ -62,6 +62,7 @@ namespace IDE.Compiler
public int32 mOutLineChar; public int32 mOutLineChar;
public String mNavigationData ~ delete _; public String mNavigationData ~ delete _;
public String mAutocompleteInfo ~ delete _; public String mAutocompleteInfo ~ delete _;
public String mResultString ~ delete _;
public WaitEvent mWaitEvent ~ delete _; public WaitEvent mWaitEvent ~ delete _;
public BfPassInstance mPassInstance ~ delete _; public BfPassInstance mPassInstance ~ delete _;

View file

@ -1335,7 +1335,7 @@ namespace IDE.ui
else else
{ {
mHoverWatch = new HoverWatch(); mHoverWatch = new HoverWatch();
if (mHoverWatch.Show(this, x, y, debugExpr)) if (mHoverWatch.Show(this, x, y, debugExpr, debugExpr))
{ {
mHoverWatch.mOpenMousePos = DarkTooltipManager.sLastRelMousePos; mHoverWatch.mOpenMousePos = DarkTooltipManager.sLastRelMousePos;
mHoverWatch.mEvalString.Set(debugExpr); // Set to old debugStr for comparison mHoverWatch.mEvalString.Set(debugExpr); // Set to old debugStr for comparison

View file

@ -63,7 +63,7 @@ namespace IDE.ui
if (mColumnIdx == 0) if (mColumnIdx == 0)
{ {
var hoverListView = (HoverListView)mListView; var hoverListView = (HoverListView)mListView;
if ((mWatchEntry.mResultType == WatchResultType.TypeClass) || (mWatchEntry.mResultType == WatchResultType.TypeValueType)) if ((mWatchEntry.mResultType.HasFlag(WatchResultType.TypeClass)) || (mWatchEntry.mResultType.HasFlag(WatchResultType.TypeValueType)))
return false; return false;
return mouseX < LabelX + hoverListView.mFont.GetWidth(mLabel) + GS!(2); return mouseX < LabelX + hoverListView.mFont.GetWidth(mLabel) + GS!(2);
} }
@ -226,8 +226,9 @@ namespace IDE.ui
} }
} }
public String mDisplayString = new String() ~ delete _;
public String mOrigEvalString = new String() ~ delete _;
public String mEvalString = new String() ~ delete _; public String mEvalString = new String() ~ delete _;
public String mOrigEvalString = new String() ~ delete _;
public TextPanel mTextPanel; public TextPanel mTextPanel;
public HoverListView mListView; public HoverListView mListView;
public Point mOpenMousePos; public Point mOpenMousePos;
@ -1382,7 +1383,7 @@ namespace IDE.ui
theEvent.mHandled = true; theEvent.mHandled = true;
} }
public HoverListViewItem Eval(String evalString, bool isPending) public HoverListViewItem Eval(String displayString, String evalString, bool isPending)
{ {
Debug.Assert(evalString != null); Debug.Assert(evalString != null);
mOrigEvalString.Set(evalString); mOrigEvalString.Set(evalString);
@ -1390,7 +1391,7 @@ namespace IDE.ui
mListView = CreateListView(); mListView = CreateListView();
else else
mListView.GetRoot().Clear(); mListView.GetRoot().Clear();
return DoListViewItem(mListView, null, evalString, evalString, isPending); return DoListViewItem(mListView, null, displayString, evalString, isPending);
} }
public void SetListView(HoverListView listView) public void SetListView(HoverListView listView)
@ -1405,7 +1406,7 @@ namespace IDE.ui
Close(); Close();
} }
public bool Show(TextPanel textPanel, float x, float y, String evalString) public bool Show(TextPanel textPanel, float x, float y, String displayString, String evalString)
{ {
if (mIsShown) if (mIsShown)
Clear(); Clear();
@ -1434,6 +1435,11 @@ namespace IDE.ui
if (mTextPanel.mHoverWatch != null) if (mTextPanel.mHoverWatch != null)
Debug.Assert(mTextPanel.mHoverWatch == this); Debug.Assert(mTextPanel.mHoverWatch == this);
mTextPanel.mHoverWatch = this; mTextPanel.mHoverWatch = this;
if (displayString == null)
mDisplayString.Clear();
else
mDisplayString.Set(displayString);
if (evalString == null) if (evalString == null)
mEvalString.Clear(); mEvalString.Clear();
else else
@ -1447,7 +1453,7 @@ namespace IDE.ui
if (evalString != null) if (evalString != null)
{ {
if (Eval(evalString, false).Failed) if (Eval(displayString, evalString, false).Failed)
{ {
if (mListView.mParent != null) if (mListView.mParent != null)
mListView.RemoveSelf(); mListView.RemoveSelf();
@ -1529,7 +1535,7 @@ namespace IDE.ui
widgetWindow.mRootWidget = null; // Detach root widgetWindow.mRootWidget = null; // Detach root
//Debug.WriteLine("Hoverwatch showing"); //Debug.WriteLine("Hoverwatch showing");
mClosed = false; mClosed = false;
Show(sourceViewPanel, mOrigX, mOrigY, mOrigEvalString); Show(sourceViewPanel, mOrigX, mOrigY, mDisplayString, mOrigEvalString);
sourceViewPanel.mHoverWatch = this; sourceViewPanel.mHoverWatch = this;
for (int32 listIdx = 0; listIdx < openYList.Count; listIdx++) for (int32 listIdx = 0; listIdx < openYList.Count; listIdx++)

View file

@ -198,7 +198,7 @@ namespace IDE.ui
hoverWatch.mAllowSideEffects = true; hoverWatch.mAllowSideEffects = true;
hoverWatch.mOrigEvalString.Set(mImmediateWidget.mResultHoverWatch.mOrigEvalString); hoverWatch.mOrigEvalString.Set(mImmediateWidget.mResultHoverWatch.mOrigEvalString);
hoverWatch.SetListView(mImmediateWidget.mResultHoverWatch.mListView); hoverWatch.SetListView(mImmediateWidget.mResultHoverWatch.mListView);
hoverWatch.Show(mImmediateWidget.mPanel, mX + GS!(2), mY + GS!(3), null); hoverWatch.Show(mImmediateWidget.mPanel, mX + GS!(2), mY + GS!(3), null, null);
hoverWatch.mRehupEvent.Add(new () => hoverWatch.mRehupEvent.Add(new () =>
{ {
mImmediateWidget.RehupResult(); mImmediateWidget.RehupResult();
@ -316,7 +316,7 @@ namespace IDE.ui
{ {
// Is a continuation // Is a continuation
if (mLastEvalString != null) if (mLastEvalString != null)
result = mResultHoverWatch.Eval(mLastEvalString, true); result = mResultHoverWatch.Eval(mLastEvalString, mLastEvalString, true);
gApp.mIsImmediateDebugExprEval = true; gApp.mIsImmediateDebugExprEval = true;
} }
else else
@ -341,7 +341,7 @@ namespace IDE.ui
gApp.mScriptManager.QueueCommands(StringView(cmdText, 1), "Immediate", .NoLines | .NoWait); gApp.mScriptManager.QueueCommands(StringView(cmdText, 1), "Immediate", .NoLines | .NoWait);
} }
else else
result = mResultHoverWatch.Eval(cmdText, false); result = mResultHoverWatch.Eval(cmdText, cmdText, false);
mLastTextVersionId = mEditWidgetContent.mData.mCurTextVersionId; mLastTextVersionId = mEditWidgetContent.mData.mCurTextVersionId;
gApp.mIsImmediateDebugExprEval = true; gApp.mIsImmediateDebugExprEval = true;
} }

View file

@ -67,7 +67,7 @@ namespace IDE.ui
//hoverWatch.SetListView(mImmediateWidget.mResultHoverWatch.mListView); //hoverWatch.SetListView(mImmediateWidget.mResultHoverWatch.mListView);
//hoverWatch.Show(mTextPanel, mX + 2, mY + 3, evalStr); //hoverWatch.Show(mTextPanel, mX + 2, mY + 3, evalStr);
hoverWatch.mOpenMousePos = DarkTooltipManager.sLastRelMousePos; hoverWatch.mOpenMousePos = DarkTooltipManager.sLastRelMousePos;
hoverWatch.Show(mOutputPanel, mX, mY, evalStr); hoverWatch.Show(mOutputPanel, mX, mY, evalStr, evalStr);
mOutputPanel.mHoverWatch = hoverWatch; mOutputPanel.mHoverWatch = hoverWatch;
} }
} }

View file

@ -1609,9 +1609,9 @@ namespace IDE.ui
{ {
resolveParams.mNavigationData = new String(autocompleteInfo); resolveParams.mNavigationData = new String(autocompleteInfo);
} }
else if (resolveType == ResolveType.GetVarType) else if (resolveType == ResolveType.GetResultString)
{ {
resolveParams.mTypeDef = new String(autocompleteInfo); resolveParams.mResultString = new String(autocompleteInfo);
} }
else if (resolveType == ResolveType.GetCurrentLocation) else if (resolveType == ResolveType.GetCurrentLocation)
{ {
@ -4819,7 +4819,33 @@ namespace IDE.ui
if (debugExpr != null) if (debugExpr != null)
triedShow = true; triedShow = true;
if ((debugExpr == null) || (isOverMessage) || (!mHoverWatch.Show(this, x, y, debugExpr))) bool didShow = false;
//if ((debugExpr == "var") || (debugExpr == "let"))
String origDebugExpr = null;
if ((debugExpr != null) || (isOverMessage))
{
let resolveParams = scope ResolveParams();
resolveParams.mOverrideCursorPos = (int32)textIdx;
Classify(ResolveType.GetResultString, resolveParams);
if (!String.IsNullOrEmpty(resolveParams.mResultString))
{
origDebugExpr = scope:: String();
origDebugExpr.Set(debugExpr);
debugExpr.Set(resolveParams.mResultString);
}
if (!triedShow)
{
mHoverWatch.Show(this, x, y, debugExpr, debugExpr);
triedShow = true;
}
}
if ((!didShow) &&
((debugExpr == null) || (isOverMessage) || (!mHoverWatch.Show(this, x, y, origDebugExpr ?? debugExpr, debugExpr))))
{ {
#if IDE_C_SUPPORT #if IDE_C_SUPPORT
if ((mIsClang) && (textIdx != -1)) if ((mIsClang) && (textIdx != -1))
@ -4918,7 +4944,7 @@ namespace IDE.ui
if (showMouseoverString != null) if (showMouseoverString != null)
{ {
triedShow = true; triedShow = true;
mHoverWatch.Show(this, x, y, showMouseoverString); mHoverWatch.Show(this, x, y, showMouseoverString, showMouseoverString);
if (debugExpr != null) if (debugExpr != null)
mHoverWatch.mEvalString.Set(debugExpr); // Set to old debugStr for comparison mHoverWatch.mEvalString.Set(debugExpr); // Set to old debugStr for comparison
} }
@ -4928,25 +4954,6 @@ namespace IDE.ui
} }
if (!hasHoverWatchOpen) if (!hasHoverWatchOpen)
mHoverWatch.mOpenMousePos = DarkTooltipManager.sLastRelMousePos; mHoverWatch.mOpenMousePos = DarkTooltipManager.sLastRelMousePos;
if ((debugExpr == "var") || (debugExpr == "let"))
{
let resolveParams = scope ResolveParams();
resolveParams.mOverrideCursorPos = (int32)textIdx;
Classify(ResolveType.GetVarType, resolveParams);
if (resolveParams.mTypeDef != null)
{
debugExpr.Set(resolveParams.mTypeDef);
if (!debugExpr.IsEmpty)
debugExpr.Insert(0, ":");
}
if (!triedShow)
{
mHoverWatch.Show(this, x, y, debugExpr);
triedShow = true;
}
}
} }
// Not used? // Not used?

View file

@ -128,7 +128,7 @@ namespace IDE.ui
{ {
base.MouseDown(x, y, btn, btnCount); base.MouseDown(x, y, btn, btnCount);
if (x >= mListView.mParent.mWidth - LabelX - GS!(34)) if ((x >= mListView.mParent.mWidth - LabelX - GS!(34)) && (mParentItem != null))
{ {
PopupCallStackPanel(); PopupCallStackPanel();
} }

View file

@ -16,16 +16,16 @@ namespace IDE.ui
{ {
public enum WatchResultType public enum WatchResultType
{ {
None, None = 0,
Value, Value = 1,
Int, Int = 2,
MM128, MM128 = 4,
Object, Object = 8,
Pointer, Pointer = 0x10,
TypeClass, TypeClass = 0x20,
TypeValueType, TypeValueType = 0x40,
Namespace, Namespace = 0x80,
Text Text = 0x100
} }
public class WatchEntry public class WatchEntry
@ -54,6 +54,18 @@ namespace IDE.ui
public int32 mSeriesFirstVersion = -1; public int32 mSeriesFirstVersion = -1;
public int32 mSeriesVersion = -1; public int32 mSeriesVersion = -1;
public bool IsConstant
{
get
{
if (mEvalStr.IsEmpty)
return true;
if (mEvalStr[0].IsNumber)
return true;
return false;
}
}
public bool ParseCmd(List<StringView> cmd) public bool ParseCmd(List<StringView> cmd)
{ {
switch (scope String(cmd[0])) switch (scope String(cmd[0]))
@ -62,25 +74,25 @@ namespace IDE.ui
switch (scope String(cmd[1])) switch (scope String(cmd[1]))
{ {
case "object": case "object":
mResultType = WatchResultType.Object; mResultType |= WatchResultType.Object;
return true; return true;
case "pointer": case "pointer":
mResultType = WatchResultType.Pointer; mResultType |= WatchResultType.Pointer;
return true; return true;
case "class": case "class":
mResultType = WatchResultType.TypeClass; mResultType |= WatchResultType.TypeClass;
return true; return true;
case "valuetype": case "valuetype":
mResultType = WatchResultType.TypeValueType; mResultType |= WatchResultType.TypeValueType;
return true; return true;
case "namespace": case "namespace":
mResultType = WatchResultType.Namespace; mResultType |= WatchResultType.Namespace;
return true; return true;
case "int": case "int":
mResultType = WatchResultType.Int; mResultType |= WatchResultType.Int;
return true; return true;
case "mm128": case "mm128":
mResultType = WatchResultType.MM128; mResultType |= WatchResultType.MM128;
return true; return true;
} }
break; break;
@ -1131,26 +1143,26 @@ namespace IDE.ui
{ {
imageIdx = .RedDot; imageIdx = .RedDot;
} }
else if (mWatchEntry.mResultType == WatchResultType.Object) else if (mWatchEntry.mResultType.HasFlag(WatchResultType.Object))
{ {
if (mWatchEntry.mIsDeleted) if (mWatchEntry.mIsDeleted)
imageIdx = .IconObjectDeleted; imageIdx = .IconObjectDeleted;
else else
imageIdx = .IconObject; imageIdx = .IconObject;
} }
else if (mWatchEntry.mResultType == WatchResultType.TypeClass) else if (mWatchEntry.mResultType.HasFlag(WatchResultType.TypeClass))
{ {
imageIdx = .Type_Class; imageIdx = .Type_Class;
} }
else if (mWatchEntry.mResultType == WatchResultType.TypeValueType) else if (mWatchEntry.mResultType.HasFlag(WatchResultType.TypeValueType))
{ {
imageIdx = .Type_ValueType; imageIdx = .Type_ValueType;
} }
else if (mWatchEntry.mResultType == WatchResultType.Namespace) else if (mWatchEntry.mResultType.HasFlag(WatchResultType.Namespace))
{ {
imageIdx = .Namespace; imageIdx = .Namespace;
} }
else if (mWatchEntry.mResultType == WatchResultType.Pointer) else if (mWatchEntry.mResultType.HasFlag(WatchResultType.Pointer))
{ {
imageIdx = .IconPointer; imageIdx = .IconPointer;
} }
@ -2587,9 +2599,9 @@ namespace IDE.ui
public static bool AddDisplayTypeMenu(String label, Menu menu, WatchResultType watchResultType, String referenceId, bool includeDefault) public static bool AddDisplayTypeMenu(String label, Menu menu, WatchResultType watchResultType, String referenceId, bool includeDefault)
{ {
bool isInt = watchResultType == WatchResultType.Int; bool hasInt = watchResultType.HasFlag(WatchResultType.Int);
bool isMM128 = watchResultType == WatchResultType.MM128; bool hasMM128 = watchResultType.HasFlag(WatchResultType.MM128);
bool canSetFormat = isInt || isMM128; bool canSetFormat = hasInt || hasMM128;
var debugger = IDEApp.sApp.mDebugger; var debugger = IDEApp.sApp.mDebugger;
DebugManager.IntDisplayType intDisplayType; DebugManager.IntDisplayType intDisplayType;
@ -2606,7 +2618,7 @@ namespace IDE.ui
Menu parentItem = menu.AddItem(label); Menu parentItem = menu.AddItem(label);
//anItem.mIconImage = DarkTheme.sDarkTheme.GetImage(DarkTheme.ImageIdx.Check); //anItem.mIconImage = DarkTheme.sDarkTheme.GetImage(DarkTheme.ImageIdx.Check);
if (isInt) if (hasInt)
{ {
for (DebugManager.IntDisplayType i = default; i < DebugManager.IntDisplayType.COUNT; i++) for (DebugManager.IntDisplayType i = default; i < DebugManager.IntDisplayType.COUNT; i++)
{ {
@ -2622,8 +2634,9 @@ namespace IDE.ui
new () => SetDisplayType(referenceId, toType, mmDisplayType)); new () => SetDisplayType(referenceId, toType, mmDisplayType));
} }
} }
else if (isMM128)
{ if (hasMM128)
{
for (DebugManager.MmDisplayType i = default; i < DebugManager.MmDisplayType.COUNT; i++) for (DebugManager.MmDisplayType i = default; i < DebugManager.MmDisplayType.COUNT; i++)
{ {
var toType = i; var toType = i;
@ -2677,49 +2690,52 @@ namespace IDE.ui
if (watchEntry.mReferenceId != null) if (watchEntry.mReferenceId != null)
AddDisplayTypeMenu("Watch Display", menu, listViewItem.mWatchEntry.mResultType, watchEntry.mReferenceId, true); AddDisplayTypeMenu("Watch Display", menu, listViewItem.mWatchEntry.mResultType, watchEntry.mReferenceId, true);
anItem = menu.AddItem("Break When Value Changes"); if (!watchEntry.IsConstant)
if (watchEntry.mMemoryBreakpointAddr == 0)
{ {
anItem.mOnMenuItemSelected.Add(new (evt) => anItem = menu.AddItem("Break When Value Changes");
{ if (watchEntry.mMemoryBreakpointAddr == 0)
String evalStr = scope String(); {
CompactChildExpression(listViewItem, evalStr); anItem.mOnMenuItemSelected.Add(new (evt) =>
evalStr.Insert(0, "&");
gApp.mBreakpointPanel.CreateMemoryBreakpoint(evalStr);
gApp.MarkDirty();
});
}
else
{
anItem.mIconImage = DarkTheme.sDarkTheme.GetImage(.Check);
anItem.mOnMenuItemSelected.Add(new (evt) =>
{
for (int breakIdx < gApp.mDebugger.mBreakpointList.Count)
{ {
let breakpoint = gApp.mDebugger.mBreakpointList[breakIdx]; String evalStr = scope String();
if (breakpoint.mMemoryAddress == watchEntry.mMemoryBreakpointAddr) CompactChildExpression(listViewItem, evalStr);
evalStr.Insert(0, "&");
gApp.mBreakpointPanel.CreateMemoryBreakpoint(evalStr);
gApp.MarkDirty();
});
}
else
{
anItem.mIconImage = DarkTheme.sDarkTheme.GetImage(.Check);
anItem.mOnMenuItemSelected.Add(new (evt) =>
{
for (int breakIdx < gApp.mDebugger.mBreakpointList.Count)
{ {
gApp.mDebugger.DeleteBreakpoint(breakpoint); let breakpoint = gApp.mDebugger.mBreakpointList[breakIdx];
gApp.RefreshWatches(); if (breakpoint.mMemoryAddress == watchEntry.mMemoryBreakpointAddr)
breakIdx--; {
gApp.mDebugger.DeleteBreakpoint(breakpoint);
gApp.RefreshWatches();
breakIdx--;
}
} }
} });
});
let configItem = menu.AddItem("Configure Breakpoint"); let configItem = menu.AddItem("Configure Breakpoint");
configItem.mOnMenuItemSelected.Add(new (evt) => configItem.mOnMenuItemSelected.Add(new (evt) =>
{
for (int breakIdx < gApp.mDebugger.mBreakpointList.Count)
{ {
let breakpoint = gApp.mDebugger.mBreakpointList[breakIdx]; for (int breakIdx < gApp.mDebugger.mBreakpointList.Count)
if (breakpoint.mMemoryAddress == watchEntry.mMemoryBreakpointAddr)
{ {
ConditionDialog dialog = new ConditionDialog(); let breakpoint = gApp.mDebugger.mBreakpointList[breakIdx];
dialog.Init(breakpoint); if (breakpoint.mMemoryAddress == watchEntry.mMemoryBreakpointAddr)
dialog.PopupWindow(listView.mWidgetWindow); {
ConditionDialog dialog = new ConditionDialog();
dialog.Init(breakpoint);
dialog.PopupWindow(listView.mWidgetWindow);
}
} }
} });
}); }
} }
if (watchEntry.mResultType == .Pointer) if (watchEntry.mResultType == .Pointer)

View file

@ -1543,7 +1543,7 @@ const char* Beefy::BfGetOpName(BfBinaryOp binOp)
case BfBinaryOp_Add: return "+"; case BfBinaryOp_Add: return "+";
case BfBinaryOp_Subtract: return "-"; case BfBinaryOp_Subtract: return "-";
case BfBinaryOp_Multiply: return "*"; case BfBinaryOp_Multiply: return "*";
case BfBinaryOp_Divide: return "\\"; case BfBinaryOp_Divide: return "/";
case BfBinaryOp_Modulus: return "%"; case BfBinaryOp_Modulus: return "%";
case BfBinaryOp_BitwiseAnd: return "&"; case BfBinaryOp_BitwiseAnd: return "&";
case BfBinaryOp_BitwiseOr: return "|"; case BfBinaryOp_BitwiseOr: return "|";

View file

@ -460,6 +460,9 @@ void BfAutoComplete::AddMethod(BfMethodDeclaration* methodDecl, const StringImpl
void BfAutoComplete::AddTypeDef(BfTypeDef* typeDef, const StringImpl& filter, bool onlyAttribute) void BfAutoComplete::AddTypeDef(BfTypeDef* typeDef, const StringImpl& filter, bool onlyAttribute)
{ {
if (typeDef->mTypeDeclaration == NULL)
return;
StringT<64> name(typeDef->mName->ToString()); StringT<64> name(typeDef->mName->ToString());
if (name == "@") if (name == "@")
return; return;
@ -576,6 +579,11 @@ void BfAutoComplete::AddTypeMembers(BfTypeInstance* typeInst, bool addStatic, bo
auto activeTypeDef = mModule->GetActiveTypeDef(); auto activeTypeDef = mModule->GetActiveTypeDef();
if ((addStatic) && (mModule->mCurMethodInstance == NULL) && (typeInst->IsEnum()))
{
AddEntry(AutoCompleteEntry("valuetype", "_"), filter);
}
#define CHECK_STATIC(staticVal) ((staticVal && addStatic) || (!staticVal && addNonStatic)) #define CHECK_STATIC(staticVal) ((staticVal && addStatic) || (!staticVal && addNonStatic))
mModule->PopulateType(typeInst, BfPopulateType_Data); mModule->PopulateType(typeInst, BfPopulateType_Data);
@ -2178,13 +2186,41 @@ void BfAutoComplete::CheckVarResolution(BfAstNode* varTypeRef, BfType* resolvedT
} }
} }
if (mResolveType == BfResolveType_GetVarType) if (mResolveType == BfResolveType_GetResultString)
{ {
mVarTypeName = mModule->TypeToString(resolvedType); mResultString = ":";
mResultString += mModule->TypeToString(resolvedType);
} }
} }
} }
void BfAutoComplete::CheckResult(BfAstNode* node, const BfTypedValue& typedValue)
{
if (mResolveType != BfResolveType_GetResultString)
return;
if (!IsAutocompleteNode(node))
return;
if (!typedValue.mValue.IsConst())
return;
if (typedValue.mType->IsPointer())
return;
if (typedValue.mType->IsObject())
return;
auto constant = mModule->mBfIRBuilder->GetConstant(typedValue.mValue);
if (BfIRConstHolder::IsInt(constant->mTypeCode))
{
mResultString = StrFormat("%lld", constant->mInt64);
}
else if (BfIRConstHolder::IsFloat(constant->mTypeCode))
{
mResultString = StrFormat("%f", constant->mDouble);
}
}
void BfAutoComplete::CheckLocalDef(BfIdentifierNode* identifierNode, BfLocalVariable* varDecl) void BfAutoComplete::CheckLocalDef(BfIdentifierNode* identifierNode, BfLocalVariable* varDecl)
{ {
CheckLocalRef(identifierNode, varDecl); CheckLocalRef(identifierNode, varDecl);

View file

@ -170,7 +170,7 @@ public:
MethodMatchInfo* mMethodMatchInfo; MethodMatchInfo* mMethodMatchInfo;
bool mIsCapturingMethodMatchInfo; bool mIsCapturingMethodMatchInfo;
String mDefaultSelection; String mDefaultSelection;
String mVarTypeName; String mResultString;
String mDocumentationEntryName; String mDocumentationEntryName;
BfAstNode* mGetDefinitionNode; BfAstNode* mGetDefinitionNode;
BfResolveType mResolveType; BfResolveType mResolveType;
@ -238,6 +238,7 @@ public:
void CheckMethod(BfMethodDeclaration* methodDeclaration, bool isLocalMethod); void CheckMethod(BfMethodDeclaration* methodDeclaration, bool isLocalMethod);
void CheckProperty(BfPropertyDeclaration* propertyDeclaration); void CheckProperty(BfPropertyDeclaration* propertyDeclaration);
void CheckVarResolution(BfAstNode* varTypeRef, BfType* resolvedTypeRef); void CheckVarResolution(BfAstNode* varTypeRef, BfType* resolvedTypeRef);
void CheckResult(BfAstNode* node, const BfTypedValue& typedValue);
void CheckLocalDef(BfIdentifierNode* identifierNode, BfLocalVariable* varDecl); void CheckLocalDef(BfIdentifierNode* identifierNode, BfLocalVariable* varDecl);
void CheckLocalRef(BfIdentifierNode* identifierNode, BfLocalVariable* varDecl); void CheckLocalRef(BfIdentifierNode* identifierNode, BfLocalVariable* varDecl);
void CheckFieldRef(BfIdentifierNode* identifierNode, BfFieldInstance* fieldInst); void CheckFieldRef(BfIdentifierNode* identifierNode, BfFieldInstance* fieldInst);
@ -246,6 +247,7 @@ public:
bool CheckFixit(BfAstNode* node); bool CheckFixit(BfAstNode* node);
void FixitAddMember(BfTypeInstance* typeInst, BfType* fieldType, const StringImpl& fieldName, bool isStatic, BfTypeInstance* referencedFrom); void FixitAddMember(BfTypeInstance* typeInst, BfType* fieldType, const StringImpl& fieldName, bool isStatic, BfTypeInstance* referencedFrom);
}; };
NS_BF_END NS_BF_END

View file

@ -3393,7 +3393,7 @@ void BfCompiler::VisitSourceExteriorNodes()
auto _CheckParser = [&](BfParser* parser) auto _CheckParser = [&](BfParser* parser)
{ {
if (parser->mNextRevision != NULL) while (parser->mNextRevision != NULL)
parser = parser->mNextRevision; parser = parser->mNextRevision;
if (parser->mAwaitingDelete) if (parser->mAwaitingDelete)
return; return;
@ -3819,19 +3819,34 @@ void BfCompiler::ProcessAutocompleteTempType()
} }
} }
if ((autoComplete->mIsGetDefinition) && (fieldDef->mFieldDeclaration != NULL) && (autoComplete->IsAutocompleteNode(fieldDef->mFieldDeclaration->mNameNode))) if (((autoComplete->mIsGetDefinition) || (autoComplete->mResolveType == BfResolveType_GetResultString)) &&
(fieldDef->mFieldDeclaration != NULL) && (autoComplete->IsAutocompleteNode(fieldDef->mFieldDeclaration->mNameNode)))
{ {
for (int i = 0; i < (int)actualTypeDef->mFields.size(); i++) for (int i = 0; i < (int)actualTypeDef->mFields.size(); i++)
{ {
auto actualFieldDef = actualTypeDef->mFields[i]; auto actualFieldDef = actualTypeDef->mFields[i];
if (actualFieldDef->mName == fieldDef->mName) if (actualFieldDef->mName == fieldDef->mName)
{ {
autoComplete->mDefType = actualTypeDef; if (autoComplete->mIsGetDefinition)
autoComplete->mDefField = actualFieldDef; {
autoComplete->mDefType = actualTypeDef;
autoComplete->mDefField = actualFieldDef;
autoComplete->SetDefinitionLocation(fieldDef->mFieldDeclaration->mNameNode); autoComplete->SetDefinitionLocation(fieldDef->mFieldDeclaration->mNameNode);
autoComplete->mInsertStartIdx = fieldDef->mFieldDeclaration->mNameNode->GetSrcStart(); autoComplete->mInsertStartIdx = fieldDef->mFieldDeclaration->mNameNode->GetSrcStart();
autoComplete->mInsertEndIdx = fieldDef->mFieldDeclaration->mNameNode->GetSrcEnd(); autoComplete->mInsertEndIdx = fieldDef->mFieldDeclaration->mNameNode->GetSrcEnd();
}
else if (autoComplete->mResolveType == BfResolveType_GetResultString)
{
auto fieldInstance = &typeInst->mFieldInstances[actualFieldDef->mIdx];
if (fieldInstance->mConstIdx != -1)
{
auto constant = typeInst->mConstHolder->GetConstantById(fieldInstance->mConstIdx);
auto retVal = module->ConstantToCurrent(constant, typeInst->mConstHolder, typeInst);
BfTypedValue typedValue = BfTypedValue(retVal, typeInst);
autoComplete->CheckResult(fieldDef->GetRefNode(), typedValue);
}
}
break; break;
} }
} }
@ -3847,7 +3862,7 @@ void BfCompiler::ProcessAutocompleteTempType()
{ {
module->ResolveConstField(typeInst, NULL, fieldDef); module->ResolveConstField(typeInst, NULL, fieldDef);
} }
if (fieldDef->mInitializer == NULL) if (fieldDef->mInitializer == NULL)
{ {
if (BfNodeIsA<BfVarTypeReference>(fieldDef->mTypeRef)) if (BfNodeIsA<BfVarTypeReference>(fieldDef->mTypeRef))
@ -6682,9 +6697,9 @@ void BfCompiler::GenerateAutocompleteInfo()
if (autoComplete->mResolveType == BfResolveType_GetNavigationData) if (autoComplete->mResolveType == BfResolveType_GetNavigationData)
return; // Already handled return; // Already handled
if (autoComplete->mResolveType == BfResolveType_GetVarType) if (autoComplete->mResolveType == BfResolveType_GetResultString)
{ {
autoCompleteResultString = autoComplete->mVarTypeName; autoCompleteResultString = autoComplete->mResultString;
return; return;
} }

View file

@ -2940,6 +2940,40 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
} }
} }
if ((mModule->mCurMethodInstance == NULL) && (mModule->mCurTypeInstance->IsEnum()))
{
if (findName == "_")
{
BfFieldDef* resolvingFieldDef = NULL;
auto checkTypeState = mModule->mContext->mCurTypeState;
while (checkTypeState != NULL)
{
if (checkTypeState->mCurFieldDef != NULL)
{
if (checkTypeState->mTypeInstance == mModule->mCurTypeInstance)
resolvingFieldDef = checkTypeState->mCurFieldDef;
}
checkTypeState = checkTypeState->mPrevState;
}
if ((resolvingFieldDef != NULL) && (resolvingFieldDef->mIdx > 0))
{
auto enumType = mModule->mCurTypeInstance;
if (!enumType->mFieldInstances.IsEmpty())
{
auto fieldInstance = &mModule->mCurTypeInstance->mFieldInstances[resolvingFieldDef->mIdx - 1];
if ((fieldInstance->mConstIdx != -1) &&
(fieldInstance->mResolvedType == mModule->mCurTypeInstance))
{
auto foreignConst = enumType->mConstHolder->GetConstantById(fieldInstance->mConstIdx);
auto retVal = mModule->ConstantToCurrent(foreignConst, enumType->mConstHolder, enumType);
return BfTypedValue(retVal, enumType);
}
}
}
}
}
BfTypedValue thisValue = mModule->GetThis(); BfTypedValue thisValue = mModule->GetThis();
bool forcedIFaceLookup = false; bool forcedIFaceLookup = false;

View file

@ -3523,14 +3523,26 @@ BfTypedValue BfModule::GetFieldInitializerValue(BfFieldInstance* fieldInstance,
else if (fieldDef->mIsConst) else if (fieldDef->mIsConst)
{ {
BfTypeState typeState; BfTypeState typeState;
typeState.mTypeInstance = mCurTypeInstance;
typeState.mCurTypeDef = fieldDef->mDeclaringType; typeState.mCurTypeDef = fieldDef->mDeclaringType;
typeState.mCurFieldDef = fieldDef;
SetAndRestoreValue<BfTypeState*> prevTypeState(mContext->mCurTypeState, &typeState); SetAndRestoreValue<BfTypeState*> prevTypeState(mContext->mCurTypeState, &typeState);
BfConstResolver constResolver(this); BfConstResolver constResolver(this);
if (fieldType->IsVar()) if (fieldType->IsVar())
return constResolver.Resolve(initializer); return constResolver.Resolve(initializer);
else else
return constResolver.Resolve(initializer, fieldType); {
BfConstResolveFlags resolveFlags = BfConstResolveFlag_None;
if ((mCompiler->mResolvePassData != NULL) && (mCurTypeInstance->IsEnum()) && (fieldDef->IsEnumCaseEntry()) &&
(mCompiler->mResolvePassData->mAutoCompleteTempTypes.Contains(fieldDef->mDeclaringType)))
{
// We avoid doing the cast here because the value we're typing may not be in the range of the current
// auto-created underlying type and it will cause an 'error flash'. We defer errors until the full resolve for that purpose
resolveFlags = BfConstResolveFlag_NoCast;
}
return constResolver.Resolve(initializer, fieldType, resolveFlags);
}
} }
if (fieldType->IsVar()) if (fieldType->IsVar())

View file

@ -2964,18 +2964,40 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
} }
} }
for (auto& fieldInstanceRef : typeInstance->mFieldInstances) ///
{ {
auto fieldInstance = &fieldInstanceRef; Dictionary<int64, BfFieldDef*> valueMap;
if (!fieldInstance->mFieldIncluded)
continue; for (auto& fieldInstanceRef : typeInstance->mFieldInstances)
auto fieldDef = fieldInstance->GetFieldDef(); {
if (fieldDef == NULL) auto fieldInstance = &fieldInstanceRef;
continue; if (!fieldInstance->mFieldIncluded)
if ((fieldInstance->mConstIdx == -1) && (fieldDef->mIsConst)) continue;
{ auto fieldDef = fieldInstance->GetFieldDef();
SetAndRestoreValue<BfFieldDef*> prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef); if (fieldDef == NULL)
typeInstance->mModule->ResolveConstField(typeInstance, fieldInstance, fieldDef); continue;
if ((fieldInstance->mConstIdx == -1) && (fieldDef->mIsConst))
{
SetAndRestoreValue<BfFieldDef*> prevTypeRef(mContext->mCurTypeState->mCurFieldDef, fieldDef);
typeInstance->mModule->ResolveConstField(typeInstance, fieldInstance, fieldDef);
auto underlyingType = fieldInstance->mResolvedType->GetUnderlyingType();
if ((fieldDef->IsEnumCaseEntry()) && (fieldInstance->mConstIdx != -1) && (underlyingType->IsIntegral()))
{
auto foreignConst = typeInstance->mConstHolder->GetConstantById(fieldInstance->mConstIdx);
BfFieldDef** fieldDefPtr;
if (valueMap.TryAdd(foreignConst->mInt64, NULL, &fieldDefPtr))
{
*fieldDefPtr = fieldDef;
}
else
{
auto error = Warn(0, StrFormat("Enum value '%lld' for field '%s' is not unique", foreignConst->mInt64, fieldDef->mName.c_str()), fieldDef->GetRefNode(), true);
if (error != NULL)
mCompiler->mPassInstance->MoreInfo(StrFormat("This value was previously used for field '%s'", (*fieldDefPtr)->mName.c_str()), (*fieldDefPtr)->GetRefNode());
}
}
}
} }
} }
@ -8997,7 +9019,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
if (explicitCast) if (explicitCast)
{ {
// TypedPrimitive -> Primitive // TypedPrimitive -> Primitive
if ((typedVal.mType->IsTypedPrimitive()) && (toType->IsPrimitiveType())) if ((typedVal.mType->IsTypedPrimitive()) && (!typedVal.mType->IsFunction()) && (toType->IsPrimitiveType()))
{ {
auto fromTypedPrimitiveType = typedVal.mType->ToTypeInstance(); auto fromTypedPrimitiveType = typedVal.mType->ToTypeInstance();
auto primTypedVal = BfTypedValue(typedVal.mValue, fromTypedPrimitiveType->mFieldInstances.back().mResolvedType, typedVal.IsAddr()); auto primTypedVal = BfTypedValue(typedVal.mValue, fromTypedPrimitiveType->mFieldInstances.back().mResolvedType, typedVal.IsAddr());
@ -9006,7 +9028,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
} }
// TypedPrimitive -> TypedPrimitive // TypedPrimitive -> TypedPrimitive
if ((typedVal.mType->IsTypedPrimitive()) && (toType->IsTypedPrimitive())) if ((typedVal.mType->IsTypedPrimitive()) && (!typedVal.mType->IsFunction()) && (toType->IsTypedPrimitive()))
{ {
auto fromTypedPrimitiveType = typedVal.mType->ToTypeInstance(); auto fromTypedPrimitiveType = typedVal.mType->ToTypeInstance();
auto toTypedPrimitiveType = toType->ToTypeInstance(); auto toTypedPrimitiveType = toType->ToTypeInstance();

View file

@ -20,7 +20,7 @@ enum BfResolveType
BfResolveType_GetFixits, BfResolveType_GetFixits,
BfResolveType_GetTypeDefList, BfResolveType_GetTypeDefList,
BfResolveType_GetTypeDefInto, BfResolveType_GetTypeDefInto,
BfResolveType_GetVarType, BfResolveType_GetResultString,
}; };
class BfLocalVariable; class BfLocalVariable;

View file

@ -2198,7 +2198,7 @@ int BfResolvedTypeSet::Hash(BfType* type, LookupContext* ctx, bool allowRef)
else if (type->IsConstExprValue()) else if (type->IsConstExprValue())
{ {
BfConstExprValueType* constExprValueType = (BfConstExprValueType*)type; BfConstExprValueType* constExprValueType = (BfConstExprValueType*)type;
int hashVal = ((int)constExprValueType->mValue.mTypeCode << 17) ^ (constExprValueType->mValue.mInt32 << 3) ^ HASH_CONSTTYPE; int hashVal = (constExprValueType->mValue.mInt32 << 17) ^ HASH_CONSTTYPE;
int elemHash = Hash(constExprValueType->mType, ctx); int elemHash = Hash(constExprValueType->mType, ctx);
hashVal = ((hashVal ^ elemHash) << 5) - hashVal; hashVal = ((hashVal ^ elemHash) << 5) - hashVal;
return hashVal; return hashVal;
@ -2897,8 +2897,7 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx)
BfConstExprValueType* lhsConstExprValueType = (BfConstExprValueType*)lhs; BfConstExprValueType* lhsConstExprValueType = (BfConstExprValueType*)lhs;
BfConstExprValueType* rhsConstExprValueType = (BfConstExprValueType*)rhs; BfConstExprValueType* rhsConstExprValueType = (BfConstExprValueType*)rhs;
return (lhsConstExprValueType->mType == rhsConstExprValueType->mType) && return (lhsConstExprValueType->mType == rhsConstExprValueType->mType) &&
(lhsConstExprValueType->mValue.mTypeCode == rhsConstExprValueType->mValue.mTypeCode) &&
(lhsConstExprValueType->mValue.mInt64 == rhsConstExprValueType->mValue.mInt64); (lhsConstExprValueType->mValue.mInt64 == rhsConstExprValueType->mValue.mInt64);
} }
else else

View file

@ -1404,11 +1404,8 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD
{ {
unresolvedType = ResolveTypeRef(varDecl->mTypeRef, BfPopulateType_Data, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_NoResolveGenericParam | BfResolveTypeRefFlag_AllowRef)); unresolvedType = ResolveTypeRef(varDecl->mTypeRef, BfPopulateType_Data, (BfResolveTypeRefFlags)(BfResolveTypeRefFlag_NoResolveGenericParam | BfResolveTypeRefFlag_AllowRef));
if (unresolvedType == NULL) if (unresolvedType == NULL)
unresolvedType = mContext->mBfObjectType; // Fake an object unresolvedType = GetPrimitiveType(BfTypeCode_Var);
//resolvedType = ResolveGenericType(unresolvedType); resolvedType = unresolvedType;
resolvedType = unresolvedType;
if (unresolvedType == NULL)
resolvedType = mContext->mBfObjectType; // Fake an object
} }
auto _CheckConst = [&] auto _CheckConst = [&]
@ -1417,7 +1414,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD
{ {
auto constant = mBfIRBuilder->GetConstant(initValue.mValue); auto constant = mBfIRBuilder->GetConstant(initValue.mValue);
// NullPtr is standin for GlobalVar during autocomplete // NullPtr is stand-in for GlobalVar during autocomplete
if ((constant->mConstType == BfConstType_GlobalVar) || if ((constant->mConstType == BfConstType_GlobalVar) ||
(constant->mTypeCode == BfTypeCode_NullPtr)) (constant->mTypeCode == BfTypeCode_NullPtr))
{ {
@ -3114,7 +3111,7 @@ void BfModule::VisitCodeBlock(BfBlock* block)
if ((!autoComplete->mIsAutoComplete) || if ((!autoComplete->mIsAutoComplete) ||
(autoComplete->mResolveType == BfResolveType_GetCurrentLocation) || (autoComplete->mResolveType == BfResolveType_GetCurrentLocation) ||
(autoComplete->mResolveType == BfResolveType_GetFixits) || (autoComplete->mResolveType == BfResolveType_GetFixits) ||
(autoComplete->mResolveType == BfResolveType_GetVarType) || (autoComplete->mResolveType == BfResolveType_GetResultString) ||
(autoComplete->mResolveType == BfResolveType_GetSymbolInfo) || (autoComplete->mResolveType == BfResolveType_GetSymbolInfo) ||
(autoComplete->mResolveType == BfResolveType_ShowFileSymbolReferences)) (autoComplete->mResolveType == BfResolveType_ShowFileSymbolReferences))
wantsAllLocalMethods = false; wantsAllLocalMethods = false;