diff --git a/BeefLibs/corlib/src/Collections/Dictionary.bf b/BeefLibs/corlib/src/Collections/Dictionary.bf index 32fca56a..7313d931 100644 --- a/BeefLibs/corlib/src/Collections/Dictionary.bf +++ b/BeefLibs/corlib/src/Collections/Dictionary.bf @@ -258,21 +258,9 @@ namespace System.Collections public bool ContainsValue(TValue value) { - if (value == null) + for (int_cosize i = 0; i < mCount; i++) { - for (int_cosize i = 0; i < mCount; i++) - { - if (mEntries[i].mHashCode >= 0 && mEntries[i].mValue == null) return true; - } - } - else - { - //TODO: IMPORTANT! - /*EqualityComparer c = EqualityComparer.Default; - for (int i = 0; i < count; i++) - { - if (entries[i].hashCode >= 0 && c.Equals(entries[i].value, value)) return true; - }*/ + if (mEntries[i].mHashCode >= 0 && mEntries[i].mValue == null) return true; } return false; } diff --git a/BeefLibs/corlib/src/Collections/List.bf b/BeefLibs/corlib/src/Collections/List.bf index 605cb723..90423812 100644 --- a/BeefLibs/corlib/src/Collections/List.bf +++ b/BeefLibs/corlib/src/Collections/List.bf @@ -930,6 +930,59 @@ namespace System.Collections } } + extension List where T : String + { + public bool Contains(T item, StringComparison comparison) + { + if (item == null) + { + for (int i = 0; i < mSize; i++) + if (mItems[i] == null) + return true; + return false; + } + else + { + for (int i = 0; i < mSize; i++) + if (mItems[i].Equals(item, comparison)) + return true; + return false; + } + } + + public int IndexOf(T item, StringComparison comparison) + { + for (int i = 0; i < mSize; i++) + if (mItems[i].Equals(item, comparison)) + return i; + return -1; + } + + public int IndexOf(T item, int index, StringComparison comparison) + { + for (int i = index; i < mSize; i++) + if (mItems[i].Equals(item, comparison)) + return i; + return -1; + } + + public int IndexOf(T item, int index, int count, StringComparison comparison) + { + for (int i = index; i < index + count; i++) + if (mItems[i].Equals(item, comparison)) + return i; + return -1; + } + + public int LastIndexOf(T item, StringComparison comparison) + { + for (int i = mSize - 1; i >= 0; i--) + if (mItems[i].Equals(item, comparison)) + return i; + return -1; + } + } + class ListWithAlloc : List { IRawAllocator mAlloc; diff --git a/BeefLibs/corlib/src/Diagnostics/Check.bf b/BeefLibs/corlib/src/Diagnostics/Check.bf index 0b26b71c..b041f6fb 100644 --- a/BeefLibs/corlib/src/Diagnostics/Check.bf +++ b/BeefLibs/corlib/src/Diagnostics/Check.bf @@ -1,6 +1,6 @@ namespace System.Diagnostics { - class Check + static class Check { [Unchecked, SkipCall] diff --git a/BeefLibs/corlib/src/Diagnostics/Contracts/Contracts.bf b/BeefLibs/corlib/src/Diagnostics/Contracts/Contracts.bf index e14d5a0c..e5f7d80c 100644 --- a/BeefLibs/corlib/src/Diagnostics/Contracts/Contracts.bf +++ b/BeefLibs/corlib/src/Diagnostics/Contracts/Contracts.bf @@ -1,6 +1,6 @@ namespace System.Diagnostics.Contracts { - class Contract + static class Contract { public enum ContractFailureKind { diff --git a/BeefLibs/corlib/src/Diagnostics/Debug.bf b/BeefLibs/corlib/src/Diagnostics/Debug.bf index d4df7bd4..fe45865b 100644 --- a/BeefLibs/corlib/src/Diagnostics/Debug.bf +++ b/BeefLibs/corlib/src/Diagnostics/Debug.bf @@ -1,6 +1,6 @@ namespace System.Diagnostics { - class Debug + static class Debug { #if !DEBUG [SkipCall] diff --git a/BeefLibs/corlib/src/IO/File.bf b/BeefLibs/corlib/src/IO/File.bf index a3ae6cf2..06d6abd7 100644 --- a/BeefLibs/corlib/src/IO/File.bf +++ b/BeefLibs/corlib/src/IO/File.bf @@ -23,7 +23,7 @@ namespace System.IO case FileReadError(FileReadError); } - class File + static class File { public static Result ReadAll(StringView path, List outData) { diff --git a/BeefLibs/corlib/src/IO/Stream.bf b/BeefLibs/corlib/src/IO/Stream.bf index 6798c4aa..00e8bab5 100644 --- a/BeefLibs/corlib/src/IO/Stream.bf +++ b/BeefLibs/corlib/src/IO/Stream.bf @@ -97,10 +97,10 @@ namespace System.IO } } - //Read sized string from stream - public Result ReadStrSized32(int64 size, String output) + /// Read sized string from stream + public Result ReadStrSized32(int size, String output) { - if (size <= 0) + if (size < 0) return .Err; for (int64 i = 0; i < size; i++) @@ -115,7 +115,13 @@ namespace System.IO return .Ok; } - //Reads null terminated ASCII string from the stream. Null terminator is read from stream but isn't appended to output string + public Result ReadStrSized32(String output) + { + int size = Try!(Read()); + return ReadStrSized32(size, output); + } + + /// Reads null terminated ASCII string from the stream. Null terminator is read from stream but isn't appended to output string public Result ReadStrC(String output) { Result char0; diff --git a/BeefLibs/corlib/src/Runtime.bf b/BeefLibs/corlib/src/Runtime.bf index 96ae54fc..564b032c 100644 --- a/BeefLibs/corlib/src/Runtime.bf +++ b/BeefLibs/corlib/src/Runtime.bf @@ -6,7 +6,7 @@ using System.Threading; namespace System { [StaticInitPriority(100)] - class Runtime + static class Runtime { const int32 cVersion = 8; diff --git a/BeefLibs/corlib/src/System.bf b/BeefLibs/corlib/src/System.bf index def9c456..9289da0a 100644 --- a/BeefLibs/corlib/src/System.bf +++ b/BeefLibs/corlib/src/System.bf @@ -227,6 +227,26 @@ static } } + public static mixin DeleteContainerAndDisposeItems(var container) + { + if (container != null) + { + for (var value in container) + value.Dispose(); + delete container; + } + } + + public static mixin ClearAndDisposeItems(var container) + { + if (container != null) + { + for (var value in container) + value.Dispose(); + container.Clear(); + } + } + public static mixin DeleteAndNullify(var val) { delete val; diff --git a/BeefLibs/corlib/src/Text/UTF16.bf b/BeefLibs/corlib/src/Text/UTF16.bf index 4a4953f2..5ab1fc6d 100644 --- a/BeefLibs/corlib/src/Text/UTF16.bf +++ b/BeefLibs/corlib/src/Text/UTF16.bf @@ -1,7 +1,7 @@ using System.Diagnostics; namespace System.Text { - public class UTF16 + public static class UTF16 { public enum EncodeError { diff --git a/BeefLibs/corlib/src/Text/UTF8.bf b/BeefLibs/corlib/src/Text/UTF8.bf index 4df4c7f9..0dce24ae 100644 --- a/BeefLibs/corlib/src/Text/UTF8.bf +++ b/BeefLibs/corlib/src/Text/UTF8.bf @@ -1,7 +1,7 @@ using System.Diagnostics; namespace System.Text { - class UTF8 + static class UTF8 { public const int8[256] sTrailingBytesForUTF8 = .( diff --git a/BeefLibs/corlib/src/Type.bf b/BeefLibs/corlib/src/Type.bf index 73d6acf1..d8b60c6c 100644 --- a/BeefLibs/corlib/src/Type.bf +++ b/BeefLibs/corlib/src/Type.bf @@ -683,13 +683,7 @@ namespace System namespace System.Reflection { - public struct TypeId : int32 - { - public Type ToType() - { - return Type.[Friend]sTypes[(int32)this]; - } - } + public struct TypeId : int32 {} [Ordered, AlwaysInclude(AssumeInstantiated=true)] public class TypeInstance : Type @@ -1137,7 +1131,7 @@ namespace System.Reflection public Type GetGenericArg(int argIdx) { - return mResolvedTypeRefs[argIdx].ToType(); + return Type.GetType(mResolvedTypeRefs[argIdx]); } public override void GetFullName(String strBuffer) diff --git a/IDE/src/ui/SourceEditWidgetContent.bf b/IDE/src/ui/SourceEditWidgetContent.bf index cbef21bb..784a2484 100644 --- a/IDE/src/ui/SourceEditWidgetContent.bf +++ b/IDE/src/ui/SourceEditWidgetContent.bf @@ -2758,7 +2758,7 @@ namespace IDE.ui return; } - if (mIsReadOnly) + if (CheckReadOnly()) { base.KeyChar(keyChar); return; diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp index b8253306..c38c5c8f 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp @@ -1208,7 +1208,8 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, { returnType = module->mBfIRBuilder->MapType(mReturnType); } - + + bool hasExplicitThis = false; for (int paramIdx = -1; paramIdx < GetParamCount(); paramIdx++) { BfType* checkType = NULL; @@ -1223,13 +1224,25 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, else { if (HasExplicitThis()) + { checkType = GetParamType(0); + + //TODO(BCF): Breaks tests + //hasExplicitThis = true; + } else checkType = GetOwner(); } } else { + if (hasExplicitThis) + { + // We already looked at this + hasExplicitThis = false; + continue; + } + checkType = GetParamType(paramIdx); }