mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Fixes for large strings, multiple 'opposite' operators
This commit is contained in:
parent
1346e241db
commit
f266fe69d1
8 changed files with 110 additions and 34 deletions
|
@ -287,7 +287,7 @@ namespace Beefy.utils
|
|||
str.AppendF("Idx:{0}", mIdx);
|
||||
}
|
||||
|
||||
public bool TryGet(String name, out Object value)
|
||||
public bool TryGet(StringView name, out Object value)
|
||||
{
|
||||
var current = GetCurrent();
|
||||
if ((current == null) || (current.GetType() != typeof(NamedValues)))
|
||||
|
@ -316,7 +316,7 @@ namespace Beefy.utils
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool TryGet(String name, out NamedValues namedValues, out int keyIdx, out int valueIdx)
|
||||
public bool TryGet(StringView name, out NamedValues namedValues, out int keyIdx, out int valueIdx)
|
||||
{
|
||||
var current = GetCurrent();
|
||||
if ((current == null) || (current.GetType() != typeof(NamedValues)))
|
||||
|
@ -351,20 +351,20 @@ namespace Beefy.utils
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool Contains(String name)
|
||||
public bool Contains(StringView name)
|
||||
{
|
||||
Object value;
|
||||
return TryGet(name, out value);
|
||||
}
|
||||
|
||||
public Object Get(String name)
|
||||
public Object Get(StringView name)
|
||||
{
|
||||
Object value;
|
||||
TryGet(name, out value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public bool Get(String name, ref bool val)
|
||||
public bool Get(StringView name, ref bool val)
|
||||
{
|
||||
Object aVal = Get(name);
|
||||
if ((aVal == null) || (!(aVal is bool)))
|
||||
|
@ -373,7 +373,7 @@ namespace Beefy.utils
|
|||
return true;
|
||||
}
|
||||
|
||||
public void Get(String name, ref int32 val)
|
||||
public void Get(StringView name, ref int32 val)
|
||||
{
|
||||
Object obj = Get(name);
|
||||
if (obj == null)
|
||||
|
@ -385,7 +385,7 @@ namespace Beefy.utils
|
|||
}
|
||||
}
|
||||
|
||||
public void Get(String name, ref float val)
|
||||
public void Get(StringView name, ref float val)
|
||||
{
|
||||
Object obj = Get(name);
|
||||
if (obj == null)
|
||||
|
@ -398,7 +398,7 @@ namespace Beefy.utils
|
|||
}
|
||||
}
|
||||
|
||||
public void Get<T>(String name, ref T val) where T : Enum
|
||||
public void Get<T>(StringView name, ref T val) where T : Enum
|
||||
{
|
||||
Object obj = Get(name);
|
||||
if (obj == null)
|
||||
|
@ -414,7 +414,7 @@ namespace Beefy.utils
|
|||
val = parsedVal;
|
||||
}
|
||||
|
||||
public void Get(String name, String outString)
|
||||
public void Get(StringView name, String outString)
|
||||
{
|
||||
Object obj = Get(name);
|
||||
if (obj == null)
|
||||
|
@ -439,7 +439,7 @@ namespace Beefy.utils
|
|||
return mValues[mCurrent.mLastValue];
|
||||
}
|
||||
|
||||
public void GetString(String name, String outString, String theDefault = null)
|
||||
public void GetString(StringView name, String outString, String theDefault = null)
|
||||
{
|
||||
Object val = Get(name);
|
||||
|
||||
|
@ -650,23 +650,23 @@ namespace Beefy.utils
|
|||
DoAdd(ref mCurrent, new:mBumpAllocator box value);
|
||||
}
|
||||
|
||||
public void Add(String value)
|
||||
public void Add(StringView value)
|
||||
{
|
||||
DoAdd(ref mCurrent, (Object)new:mBumpAllocator String(value));
|
||||
}
|
||||
|
||||
public void Add<T>(String name, T value) where T : struct
|
||||
public void Add<T>(StringView name, T value) where T : struct
|
||||
{
|
||||
DoAdd(ref mCurrent, AllocStringView(name), new:mBumpAllocator box value);
|
||||
}
|
||||
|
||||
public void ConditionalAdd<T>(String name, T value) where T : var
|
||||
public void ConditionalAdd<T>(StringView name, T value) where T : var
|
||||
{
|
||||
if (value != default(T))
|
||||
Add(name, value);
|
||||
}
|
||||
|
||||
public void ConditionalAdd<T>(String name, T value, T defaultVal) where T : var
|
||||
public void ConditionalAdd<T>(StringView name, T value, T defaultVal) where T : var
|
||||
{
|
||||
if ((value != null) && (value != defaultVal))
|
||||
Add(name, value);
|
||||
|
@ -718,7 +718,7 @@ namespace Beefy.utils
|
|||
mNextValues.Add(-1);
|
||||
}
|
||||
|
||||
StringView AllocStringView(String str)
|
||||
StringView AllocStringView(StringView str)
|
||||
{
|
||||
int len = str.Length;
|
||||
char8* ptr = (char8*)mBumpAllocator.Alloc(len, 1);
|
||||
|
@ -726,20 +726,32 @@ namespace Beefy.utils
|
|||
return StringView(ptr, len);
|
||||
}
|
||||
|
||||
public void Add(String name, String value)
|
||||
public void Add(String name, StringView value)
|
||||
{
|
||||
DoAdd(ref mCurrent, AllocStringView(name), (Object)new:mBumpAllocator String(value));
|
||||
}
|
||||
|
||||
public void ConditionalAdd(String name, String value, String defaultVal)
|
||||
public void ConditionalAdd(StringView name, StringView value, StringView defaultVal)
|
||||
{
|
||||
if (value != defaultVal)
|
||||
if (!(value == defaultVal))
|
||||
DoAdd(ref mCurrent, AllocStringView(name), (Object)new:mBumpAllocator String(value));
|
||||
}
|
||||
|
||||
public void ConditionalAdd(String name, String value)
|
||||
public void ConditionalAdd(StringView name, String value, String defaultVal)
|
||||
{
|
||||
if ((value != null) && (value != ""))
|
||||
if (!(value == defaultVal))
|
||||
DoAdd(ref mCurrent, AllocStringView(name), (Object)new:mBumpAllocator String(value));
|
||||
}
|
||||
|
||||
public void ConditionalAdd(StringView name, StringView value)
|
||||
{
|
||||
if (!value.IsEmpty)
|
||||
DoAdd(ref mCurrent, AllocStringView(name), (Object)new:mBumpAllocator String(value));
|
||||
}
|
||||
|
||||
public void ConditionalAdd(StringView name, String value)
|
||||
{
|
||||
if ((value != null) && (!value.IsEmpty))
|
||||
DoAdd(ref mCurrent, AllocStringView(name), (Object)new:mBumpAllocator String(value));
|
||||
}
|
||||
|
||||
|
@ -787,7 +799,7 @@ namespace Beefy.utils
|
|||
}
|
||||
}
|
||||
|
||||
public IDisposable Open(String name)
|
||||
public IDisposable Open(StringView name)
|
||||
{
|
||||
if (mStructuredDisposeProxy == null)
|
||||
{
|
||||
|
|
|
@ -286,7 +286,7 @@ namespace System.Collections.Generic
|
|||
private void Insert(TKey key, TValue value, bool add)
|
||||
{
|
||||
if (mBuckets == null) Initialize(0);
|
||||
int_cosize hashCode = (int_cosize)key.GetHashCode() & 0x7FFFFFFF;
|
||||
int32 hashCode = (int32)key.GetHashCode() & 0x7FFFFFFF;
|
||||
int_cosize targetBucket = hashCode % (int_cosize)mBuckets.Count;
|
||||
|
||||
for (int_cosize i = mBuckets[targetBucket]; i >= 0; i = mEntries[i].mNext)
|
||||
|
@ -335,7 +335,7 @@ namespace System.Collections.Generic
|
|||
private bool Insert(TKey key, bool add, out TKey* keyPtr, out TValue* valuePtr)
|
||||
{
|
||||
if (mBuckets == null) Initialize(0);
|
||||
int_cosize hashCode = (int_cosize)key.GetHashCode() & 0x7FFFFFFF;
|
||||
int32 hashCode = (int32)key.GetHashCode() & 0x7FFFFFFF;
|
||||
int_cosize targetBucket = hashCode % (int_cosize)mBuckets.Count;
|
||||
|
||||
for (int_cosize i = mBuckets[targetBucket]; i >= 0; i = mEntries[i].mNext)
|
||||
|
@ -413,7 +413,7 @@ namespace System.Collections.Generic
|
|||
{
|
||||
if (newEntries[i].mHashCode != -1)
|
||||
{
|
||||
newEntries[i].mHashCode = (int_cosize)newEntries[i].mKey.GetHashCode() & 0x7FFFFFFF;
|
||||
newEntries[i].mHashCode = (int32)newEntries[i].mKey.GetHashCode() & 0x7FFFFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -445,7 +445,7 @@ namespace System.Collections.Generic
|
|||
if (mBuckets != null)
|
||||
{
|
||||
|
||||
int_cosize hashCode = (int_cosize)key.GetHashCode() & 0x7FFFFFFF;
|
||||
int32 hashCode = (int32)key.GetHashCode() & 0x7FFFFFFF;
|
||||
int_cosize bucket = hashCode % (int_cosize)mBuckets.Count;
|
||||
int_cosize last = -1;
|
||||
for (int_cosize i = mBuckets[bucket]; i >= 0; last = i,i = mEntries[i].mNext)
|
||||
|
|
|
@ -196,6 +196,24 @@ namespace System.Collections.Generic
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool ContainsWith<TAltKey>(TAltKey item) where TAltKey : IOpEquals<T>, IHashable
|
||||
{
|
||||
if (mBuckets != null)
|
||||
{
|
||||
int32 hashCode = (int32)item.GetHashCode() & Lower31BitMask;
|
||||
// see note at "HashSet" level describing why "- 1" appears in for loop
|
||||
for (int32 i = mBuckets[hashCode % mBuckets.Count] - 1; i >= 0; i = mSlots[i].mNext)
|
||||
{
|
||||
if (mSlots[i].mHashCode == hashCode && /*m_comparer.Equals*/(mSlots[i].mValue == item))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// either m_buckets is null or wasn't found
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Copy items in this hashset to array, starting at arrayIndex
|
||||
/// @param array array to add items to
|
||||
/// @param arrayIndex index to start at
|
||||
|
|
|
@ -4,7 +4,11 @@ using System.Collections.Generic;
|
|||
namespace System
|
||||
{
|
||||
// Collection size type
|
||||
#if BF_LARGE_COLLECTIONS
|
||||
typealias int_cosize = int64;
|
||||
#else
|
||||
typealias int_cosize = int32;
|
||||
#endif
|
||||
|
||||
[AlwaysInclude]
|
||||
static class CompilerSettings
|
||||
|
@ -17,6 +21,18 @@ namespace System
|
|||
public const bool cHasVDataExtender = true;
|
||||
public const int32 cVDataIntefaceSlotCount = 16;
|
||||
|
||||
#if BF_LARGE_STRINGS
|
||||
public const bool cHasLargeStrings = true;
|
||||
#else
|
||||
public const bool cHasLargeStrings = false;
|
||||
#endif
|
||||
|
||||
#if BF_LARGE_COLLECTIONS
|
||||
public const bool cHasLargeCollections = true;
|
||||
#else
|
||||
public const bool cHasLargeCollections = false;
|
||||
#endif
|
||||
|
||||
static this()
|
||||
{
|
||||
// This ensures this gets included in vdata
|
||||
|
|
|
@ -16493,7 +16493,7 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
|||
break;
|
||||
|
||||
bool foundExactMatch = false;
|
||||
BfOperatorDef* oppositeOperatorDef = NULL;
|
||||
Array<BfMethodDef*> oppositeOperatorDefs;
|
||||
|
||||
for (auto operatorDef : checkType->mTypeDef->mOperators)
|
||||
{
|
||||
|
@ -16512,14 +16512,17 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
|||
}
|
||||
}
|
||||
else if (operatorDef->mOperatorDeclaration->mBinOp == oppositeBinaryOp)
|
||||
oppositeOperatorDef = operatorDef;
|
||||
oppositeOperatorDefs.Add(operatorDef);
|
||||
}
|
||||
|
||||
if (((methodMatcher.mBestMethodDef == NULL) || (!foundExactMatch)) && (oppositeOperatorDef != NULL))
|
||||
if (((methodMatcher.mBestMethodDef == NULL) || (!foundExactMatch)) && (!oppositeOperatorDefs.IsEmpty()))
|
||||
{
|
||||
foundOp = true;
|
||||
if (methodMatcher.CheckMethod(checkType, oppositeOperatorDef, false))
|
||||
methodMatcher.mSelfType = entry.mSrcType;
|
||||
for (auto oppositeOperatorDef : oppositeOperatorDefs)
|
||||
{
|
||||
if (methodMatcher.CheckMethod(checkType, oppositeOperatorDef, false))
|
||||
methodMatcher.mSelfType = entry.mSrcType;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (methodMatcher.mBestMethodDef != NULL)
|
||||
|
|
|
@ -1153,10 +1153,29 @@ DbgTypedValue DbgExprEvaluator::GetBeefTypeById(int typeId)
|
|||
|
||||
void DbgExprEvaluator::BeefStringToString(addr_target addr, String& outStr)
|
||||
{
|
||||
mDebugTarget->GetCompilerSettings();
|
||||
int objectSize = mDebugTarget->mBfObjectSize;
|
||||
|
||||
int32 strLen = mDebugger->ReadMemory<int16>(addr + objectSize);
|
||||
addr_target charPtr = mDebugger->ReadMemory<addr_target>(addr + objectSize + 4 + 4);
|
||||
int32 strLen = 0;
|
||||
addr_target charPtr = 0;
|
||||
if (!mDebugTarget->mBfHasLargeStrings)
|
||||
{
|
||||
strLen = mDebugger->ReadMemory<int32>(addr + objectSize);
|
||||
int32 allocSizeAndFlags = mDebugger->ReadMemory<int32>(addr + objectSize + 4);
|
||||
if ((allocSizeAndFlags & 0x40000000) != 0)
|
||||
charPtr = mDebugger->ReadMemory<addr_target>(addr + objectSize + 4 + 4);
|
||||
else
|
||||
charPtr = addr + objectSize + 4 + 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
strLen = mDebugger->ReadMemory<int32>(addr + objectSize);
|
||||
int64 allocSizeAndFlags = mDebugger->ReadMemory<int64>(addr + objectSize + 8);
|
||||
if ((allocSizeAndFlags & 0x40000000'00000000LL) != 0)
|
||||
charPtr = mDebugger->ReadMemory<addr_target>(addr + objectSize + 8 + 8);
|
||||
else
|
||||
charPtr = addr + objectSize + 4 + 4;
|
||||
}
|
||||
|
||||
if ((strLen > 0) && (strLen < 4096))
|
||||
{
|
||||
|
|
|
@ -20,6 +20,8 @@ DebugTarget::DebugTarget(WinDebugger* debugger)
|
|||
mCheckedCompilerSettings = false;
|
||||
mBfObjectHasFlags = false;
|
||||
mBfObjectHasVDataExtender = false;
|
||||
mBfHasLargeStrings = false;
|
||||
mBfHasLargeCollections = false;
|
||||
mBfObjectVDataIntefaceSlotCount = -1;
|
||||
mBfObjectSize = -1;
|
||||
mDebugger = debugger;
|
||||
|
@ -887,6 +889,10 @@ void DebugTarget::GetCompilerSettings()
|
|||
mBfObjectHasFlags = member->mConstValue != 0;
|
||||
if (strcmp(member->mName, "cHasVDataExtender") == 0)
|
||||
mBfObjectHasVDataExtender = member->mConstValue != 0;
|
||||
if (strcmp(member->mName, "cHasLargeStrings") == 0)
|
||||
mBfHasLargeStrings = member->mConstValue != 0;
|
||||
if (strcmp(member->mName, "cHasLargeCollections") == 0)
|
||||
mBfHasLargeCollections = member->mConstValue != 0;
|
||||
if (strcmp(member->mName, "cVDataIntefaceSlotCount") == 0)
|
||||
mBfObjectVDataIntefaceSlotCount = (int)member->mConstValue;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ public:
|
|||
bool mCheckedCompilerSettings;
|
||||
bool mBfObjectHasFlags;
|
||||
bool mBfObjectHasVDataExtender;
|
||||
bool mBfHasLargeStrings;
|
||||
bool mBfHasLargeCollections;
|
||||
int mBfObjectVDataIntefaceSlotCount;
|
||||
int mBfObjectSize;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue