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

Made callstack aware of outer types vs namespaces. Colorized classview

This commit is contained in:
Brian Fiete 2019-12-11 12:54:50 -08:00
parent 33edbd18bb
commit b3cc0b5be4
9 changed files with 662 additions and 376 deletions

View file

@ -8,6 +8,7 @@ using Beefy.utils;
using Beefy;
using Beefy.gfx;
using Beefy.theme.dark;
using IDE.ui;
namespace IDE
{
@ -288,6 +289,276 @@ namespace IDE
g.Draw(DarkTheme.sDarkTheme.GetImage(.LockIcon), x, y);
}
}
public static void InsertColorChange(String str, int idx, uint32 color)
{
char8* insertChars = scope char8[5]*;
insertChars[0] = (char8)1;
*(uint32*)(insertChars + 1) = (color >> 1) & 0x7F7F7F7F;
str.Insert(idx, scope String(insertChars, 5));
}
public static void ModifyColorChange(String str, int idx, uint32 color)
{
char8* insertPos = str.Ptr + idx;
*(uint32*)(insertPos + 1) = (color >> 1) & 0x7F7F7F7F;
}
public enum CodeKind
{
Callstack,
Method,
Field,
Type
}
public static void ColorizeCodeString(String label, CodeKind codeKind)
{
//int q = 98;
int prevTypeColor = -1;
int prevStart = -1;
bool foundOpenParen = codeKind != .Callstack;
// Check to see if this is just a Mixin name, don't mistake for the bang that separates module name
bool awaitingBang = label.Contains('!') && !label.EndsWith("!");
bool awaitingParamName = false;
int chevronCount = 0;
int parenCount = 0;
int lastTopStart = -1;
int lastTopEnd = -1;
bool inSubtype = false;
bool IsIdentifierChar(char8 c)
{
return (c.IsLetterOrDigit) || (c == '_') || (c == '$') || (c == '@');
}
bool IsIdentifierStart(char8 c)
{
return (c.IsLetter) || (c == '_');
}
for (int32 i = 0; i < label.Length; i++)
{
char8 c = label[i];
if ((c == '0') && (i == 0))
break; // Don't colorize addresses
if ((c == '<') && (i == 0))
{
uint32 color = 0xFFA0A0A0;//SourceEditWidgetContent.sTextColors[(int)SourceElementType.Comment];
InsertColorChange(label, 0, color);
label.Append('\x02');
break;
}
if (awaitingBang)
{
if ((c == ':') || (c == '<'))
{
awaitingBang = false;
i = -1;
continue;
}
if (c == '!')
{
bool endNow = false;
if (i + 1 < label.Length)
{
char16 nextC = label[i + 1];
if ((nextC == '(') || (nextC == '='))
{
awaitingBang = false;
i = -1;
continue;
}
else if ((nextC == '0') || (nextC == '<'))
{
endNow = true; // Just a raw string
}
}
uint32 color = 0xFFA0A0A0;//SourceEditWidgetContent.sTextColors[(int)SourceElementType.Comment];
InsertColorChange(label, 0, color);
awaitingBang = false;
i += 5;
label.Insert(i, '\x02');
if (endNow)
{
InsertColorChange(label, i + 2, SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Method]);
break;
}
}
}
else if (c == '$')
{
uint32 color = 0xFF80A080;//SourceEditWidgetContent.sTextColors[(int)SourceElementType.Comment];
InsertColorChange(label, i, color);
i += 5;
}
else if (IsIdentifierChar(c))
{
if ((prevStart == -1) && (!awaitingParamName))
prevStart = i;
}
else
{
int setNamespaceIdx = -1;
if ((!inSubtype) && (prevTypeColor != -1))
{
setNamespaceIdx = prevTypeColor;
}
bool isSubtypeSplit = false;
char8 nextC = (i < label.Length - 1) ? label[i + 1] : 0;
// Check for internal '+' subtype encoding
if ((c == '+') && (IsIdentifierStart(nextC)))
{
isSubtypeSplit = true;
inSubtype = true;
label[i] = '.';
}
if (prevStart != -1)
{
//label.Insert(prevStart, SourceEditWidgetContent.sTextColors[(int)SourceElementType.TypeRef]);
/*uint32 color = SourceEditWidgetContent.sTextColors[
inSubtype ? (int32)SourceElementType.TypeRef : (int32)SourceElementType.Namespace
];*/
uint32 color = SourceEditWidgetContent.sTextColors[(int32)SourceElementType.TypeRef];
/*if ((c == '+') || (c == '('))
{
foundOpenParen = true;
color = SourceEditWidgetContent.sTextColors[(int)SourceElementType.Method];
}*/
if (chevronCount == 0)
{
lastTopStart = prevStart;
lastTopEnd = i;
}
prevTypeColor = prevStart;
InsertColorChange(label, prevStart, color);
i += 5;
label.Insert(i, '\x02');
prevStart = -1;
awaitingParamName = false;
i++;
}
if (c == ',')
awaitingParamName = false;
if ((c == ')') && (parenCount > 0))
parenCount--;
if ((c != '+') && (c != '.'))
{
inSubtype = false;
prevTypeColor = -1;
}
if ((c == '(') || ((c == '+') && (!isSubtypeSplit)))
setNamespaceIdx = -1;
if (setNamespaceIdx != -1)
ModifyColorChange(label, setNamespaceIdx, SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Namespace]);
if (isSubtypeSplit)
{
// Handled
}
else if ((c == '(') && ((i == 0) || (chevronCount > 0)))
{
parenCount++;
}
else if ((c == '(') || (c == '+'))
{
foundOpenParen = true;
if (lastTopStart != -1)
{
char8* insertChars = label.CStr() + lastTopStart;
uint32 color = SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Method];
*(uint32*)(insertChars + 1) = (color >> 1) & 0x7F7F7F7F;
}
else
{
int checkIdx = i - 1;
while (checkIdx > 0)
{
char8 checkC = label[checkIdx];
if (checkC == ':')
{
checkIdx++;
break;
}
checkIdx--;
}
if (checkIdx >= 0)
{
InsertColorChange(label, checkIdx, SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Method]);
i += 5;
}
}
}
if ((foundOpenParen) && (!awaitingParamName) && (chevronCount == 0))
{
if (c == ' ')
{
bool nextIsName = true;
int32 spaceCount = 0;
for (int32 checkIdx = i + 1; checkIdx < label.Length; checkIdx++)
{
char8 checkC = label[checkIdx];
if (checkC == ' ')
{
spaceCount++;
if (spaceCount > 1)
nextIsName = false;
}
if ((checkC == '<') || (checkC == '*') || (checkC == '['))
nextIsName = false;
if ((checkC == ',') || (checkC == ')'))
{
if (spaceCount > 0)
nextIsName = false;
break;
}
}
if (nextIsName)
awaitingParamName = true;
}
}
}
if (c == '<')
chevronCount++;
else if (c == '>')
chevronCount--;
}
if ((prevStart != -1) && (codeKind == .Type))
{
InsertColorChange(label, prevStart, SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Type]);
}
}
}
}

View file

@ -47,203 +47,6 @@ namespace IDE.ui
return new CallStackListViewItem();
}
static void InsertColorChange(String str, int idx, uint32 color)
{
char8* insertChars = scope char8[5]*;
insertChars[0] = (char8)1;
*(uint32*)(insertChars + 1) = (color >> 1) & 0x7F7F7F7F;
str.Insert(idx, scope String(insertChars, 5));
}
public static void ColorizeLocationString(String label, int line = -1)
{
int prevStart = -1;
bool foundOpenParen = false;
// Check to see if this is just a Mixin name, don't mistake for the bang that separates module name
bool awaitingBang = label.Contains('!') && !label.EndsWith("!");
bool awaitingParamName = false;
int chevronCount = 0;
int parenCount = 0;
int lastTopStart = -1;
int lastTopEnd = -1;
for (int32 i = 0; i < label.Length; i++)
{
char8 c = label[i];
if ((c == '0') && (i == 0))
break; // Don't colorize addresses
if ((c == '<') && (i == 0))
{
uint32 color = 0xFFA0A0A0;//SourceEditWidgetContent.sTextColors[(int)SourceElementType.Comment];
InsertColorChange(label, 0, color);
label.Append('\x02');
break;
}
if (awaitingBang)
{
if ((c == ':') || (c == '<'))
{
awaitingBang = false;
i = -1;
continue;
}
if (c == '!')
{
bool endNow = false;
if (i + 1 < label.Length)
{
char16 nextC = label[i + 1];
if ((nextC == '(') || (nextC == '='))
{
awaitingBang = false;
i = -1;
continue;
}
else if ((nextC == '0') || (nextC == '<'))
{
endNow = true; // Just a raw string
}
}
uint32 color = 0xFFA0A0A0;//SourceEditWidgetContent.sTextColors[(int)SourceElementType.Comment];
InsertColorChange(label, 0, color);
awaitingBang = false;
i += 5;
label.Insert(i, '\x02');
if (endNow)
{
InsertColorChange(label, i + 2, SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Method]);
break;
}
}
}
else if (c == '$')
{
uint32 color = 0xFF80A080;//SourceEditWidgetContent.sTextColors[(int)SourceElementType.Comment];
InsertColorChange(label, i, color);
i += 5;
}
else if ((c.IsLetterOrDigit) || (c == '_') || (c == '$') || (c == '@') /*|| (c == '>') || (c == '<') || (c == ':') || (c == '[') || (c == ']')*/)
{
if ((prevStart == -1) && (!awaitingParamName))
prevStart = i;
}
else
{
if (prevStart != -1)
{
//label.Insert(prevStart, SourceEditWidgetContent.sTextColors[(int)SourceElementType.TypeRef]);
uint32 color = SourceEditWidgetContent.sTextColors[(int32)SourceElementType.TypeRef];
/*if ((c == '+') || (c == '('))
{
foundOpenParen = true;
color = SourceEditWidgetContent.sTextColors[(int)SourceElementType.Method];
}*/
if (chevronCount == 0)
{
lastTopStart = prevStart;
lastTopEnd = i;
}
InsertColorChange(label, prevStart, color);
i += 5;
label.Insert(i, '\x02');
prevStart = -1;
awaitingParamName = false;
i++;
}
if (c == ',')
awaitingParamName = false;
if ((c == ')') && (parenCount > 0))
parenCount--;
if ((c == '(') && ((i == 0) || (chevronCount > 0)))
{
parenCount++;
}
else if ((c == '(') || (c == '+'))
{
foundOpenParen = true;
if (lastTopStart != -1)
{
char8* insertChars = label.CStr() + lastTopStart;
uint32 color = SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Method];
*(uint32*)(insertChars + 1) = (color >> 1) & 0x7F7F7F7F;
}
else
{
int checkIdx = i - 1;
while (checkIdx > 0)
{
char8 checkC = label[checkIdx];
if (checkC == ':')
{
checkIdx++;
break;
}
checkIdx--;
}
if (checkIdx >= 0)
{
InsertColorChange(label, checkIdx, SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Method]);
i += 5;
}
}
}
if ((foundOpenParen) && (!awaitingParamName) && (chevronCount == 0))
{
if (c == ' ')
{
bool nextIsName = true;
int32 spaceCount = 0;
for (int32 checkIdx = i + 1; checkIdx < label.Length; checkIdx++)
{
char8 checkC = label[checkIdx];
if (checkC == ' ')
{
spaceCount++;
if (spaceCount > 1)
nextIsName = false;
}
if ((checkC == '<') || (checkC == '*') || (checkC == '['))
nextIsName = false;
if ((checkC == ',') || (checkC == ')'))
{
if (spaceCount > 0)
nextIsName = false;
break;
}
}
if (nextIsName)
awaitingParamName = true;
}
}
}
if (c == '<')
chevronCount++;
else if (c == '>')
chevronCount--;
}
if (line != -1)
label.AppendF(" Line {0}", (int32)(line + 1));
}
public override void PopulateVirtualItem(DarkVirtualListViewItem listViewItem)
{
base.PopulateVirtualItem(listViewItem);
@ -267,7 +70,10 @@ namespace IDE.ui
String label = scope String(256);
DebugManager.FrameFlags frameFlags;
gApp.mDebugger.GetStackFrameInfo(listViewItem.mVirtualIdx, label, out addr, file, out hotIdx, out defLineStart, out defLineEnd, out line, out column, out language, out stackSize, out frameFlags);
ColorizeLocationString(label, line);
IDEUtils.ColorizeCodeString(label, .Callstack);
if (line != -1)
label.AppendF(" Line {0}", (int32)(line + 1));
listViewItem.Label = label;

View file

@ -19,6 +19,7 @@ namespace IDE.ui
public Object mRefObject;
public DataKind mKind;
public PendingEntry mMemberInfo ~ delete _;
public bool mProcessedLabel;
protected override float GetLabelOffset()
{
@ -44,7 +45,36 @@ namespace IDE.ui
public override void Draw(Graphics g)
{
if ((!mProcessedLabel) && (mLabel != null))
{
uint32 color = 0;
switch (mMemberInfo.mKind)
{
case .Globals:
/*color = SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Identifier];
color = Color.Mult(color, Color.Get(0.8f));*/
case .Namespace:
color = SourceEditWidgetContent.sTextColors[(int32)SourceElementType.Namespace];
case .Interface,
.Class,
.ValueType:
IDEUtils.ColorizeCodeString(mLabel, .Type);
case .Field,
.Property:
IDEUtils.ColorizeCodeString(mLabel, .Field);
case .Method:
IDEUtils.ColorizeCodeString(mLabel, .Method);
default:
}
if (color != 0)
IDEUtils.InsertColorChange(mLabel, 0, color);
mProcessedLabel = true;
}
base.Draw(g);
if (mRefObject != null)
{
bool hasChanged = false;
@ -203,8 +233,13 @@ namespace IDE.ui
{
if (((Object)val1 == null) || ((Object)val2 == null))
return ((Object)val1 == null) && ((Object)val2 == null);
if ((val1.mKind != val2.mKind) && ((val1.mKind != .Namespace) && (val2.mKind != .Namespace)))
return false;
if (val1.mKind != val2.mKind)
{
if ((val1.mKind == .Project) || (val2.mKind == .Project))
return false;
if ((val1.mKind != .Namespace) && (val2.mKind != .Namespace))
return false;
}
return (val1.mName == val2.mName);
}
@ -598,6 +633,8 @@ namespace IDE.ui
List<PendingEntry> partialRefs = scope List<PendingEntry>();
char8[] seps = scope char8[] ('.', '+');
for (var subStrRef in str.Split('\n'))
{
String param = scope String();
@ -656,6 +693,8 @@ namespace IDE.ui
kind = .Interface;
else if (cmd == 'c')
kind = .Class;
else if (cmd == 'g')
kind = .Globals;
if (parentEntry != null)
{
@ -677,7 +716,7 @@ namespace IDE.ui
}
int nameIdx = 0;
for (var subName in param.Split('.'))
for (var subName in param.Split(seps))
{
if (nameIdx < addIdx)
{
@ -687,10 +726,13 @@ namespace IDE.ui
String subNameStr = scope String();
bool isLast = subName.Ptr + subName.Length == param.Ptr + param.Length;
if (nameIdx == addIdx)
{
DataKind insertKind = isLast ? kind : .Namespace;
subNameStr.Reference(StringView(param, 0, @subName.MatchPos));
curEntry = mPendingInfo.mPendingRoot.AddChild(kind, subNameStr);
curEntry = mPendingInfo.mPendingRoot.AddChild(insertKind, subNameStr);
curEntry.mParent = curProject;
Debug.Assert(curProject != (Object)curEntry);
partialRefs.Add(curEntry);
@ -700,7 +742,6 @@ namespace IDE.ui
}
DataKind insertKind = kind;
bool isLast = subName.Ptr + subName.Length == param.Ptr + param.Length;
if (!isLast)
{
char8 nextChar = subName.Ptr[subName.Length];
@ -803,6 +844,7 @@ namespace IDE.ui
childListViewItem.mRefObject = pendingEntry.mRefObject;
childListViewItem.mOpenOnDoubleClick = false;
childListViewItem.mKind = child.mKind;
childListViewItem.mProcessedLabel = false;
DeleteAndNullify!(childListViewItem.mMemberInfo);
//if (child.mFile != null)
{
@ -940,7 +982,10 @@ namespace IDE.ui
if (mWorkWait == -1)
{
if (mWantsSubmit)
{
mTypeLV.KeyDown(.Return, false);
mWantsSubmit = false;
}
}
}

View file

@ -447,7 +447,7 @@ namespace IDE.ui
subItem = (ThreadListViewItem)listViewItem.CreateSubItem(2);
label.Clear();
label.Append(elementData[2]);
CallStackListView.ColorizeLocationString(label);
IDEUtils.ColorizeCodeString(label, .Callstack);
subItem.Label = label;
subItem.mOnMouseDown.Add(new => ValueClicked);