Normalize all existing files to LF

This commit is contained in:
Youmu Liu
2026-03-06 18:31:11 +08:00
parent 0a0af53af1
commit 2149bbeede
323 changed files with 113191 additions and 113191 deletions
@@ -1,55 +1,55 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ExpBuiltinType"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Data;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
internal sealed class ExpBuiltinType : ExpTypeSource
{
private Type _marshalType;
internal ExpBuiltinType(string name, Type origin)
: base(name, ScriptSourceTransmitter.Empty)
{
_marshalType = origin;
}
public override void Analyse()
{
return;
}
// A method convert value to CLR type
// Used for direct running rather than compiling to C# code.
}
}
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ExpBuiltinType"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.Data;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
internal sealed class ExpBuiltinType : ExpTypeSource
{
private Type _marshalType;
internal ExpBuiltinType(string name, Type origin)
: base(name, ScriptSourceTransmitter.Empty)
{
_marshalType = origin;
}
public override void Analyse()
{
return;
}
// A method convert value to CLR type
// Used for direct running rather than compiling to C# code.
}
}
+192 -192
View File
@@ -1,192 +1,192 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ExpCollection"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpCollectionBase : ExpInstantiableElement, IEnumerable<ExpElementInstance>
{
protected internal string _accurateType;
protected ExpCollectionBase(string accurateType)
{
_accurateType = accurateType;
}
public override ExpElementType ElementType => ExpElementType.Collection;
public abstract int Count { get; }
public sealed override IScriptSourceProvider SourceProvider => ScriptSourceTransmitter.Empty;
public string MemberType
{
get => _accurateType;
}
public override void Analyse()
{
return;
}
public abstract IEnumerator<ExpElementInstance> GetEnumerator();
public override bool TryGetMember(string name, out ExpSyntaxNode memberNode)
{
memberNode = ExpSyntaxNode.Empty;
return false;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
public class ExpArray : ExpCollectionBase
{
private ExpElementInstance[] _collection;
public ExpArray(string accurateType) : base(accurateType) { }
public ExpElementInstance this[int index]
{
get { return _collection[index]; }
set
{
if (value.TypeName != MemberType) {
throw new ExpInvalidCollectionMemberTypeException(value, this);
}
_collection[index] = value;
}
}
public override int Count => _collection.Length;
public override string Name => ExpressCompile.PoolString("ARRAY");
public override ExpSyntaxNode CreateInstanceNode(Token t)
{
throw new NotImplementedException();
}
public override IEnumerator<ExpElementInstance> GetEnumerator()
{
return ((IEnumerable<ExpElementInstance>)_collection)
.GetEnumerator();
}
}
public class ExpBag : ExpCollectionBase
{
private ConcurrentBag<ExpElementInstance> _collection = new ConcurrentBag<ExpElementInstance>(
);
public ExpBag(string accurateType) : base(accurateType) { }
public override int Count => _collection.Count;
public override string Name => ExpressCompile.PoolString("BAG");
public override ExpSyntaxNode CreateInstanceNode(Token t)
{
throw new NotImplementedException();
}
public override IEnumerator<ExpElementInstance> GetEnumerator()
{
return _collection.GetEnumerator();
}
}
public sealed class ExpList : ExpCollectionBase
{
private List<ExpElementInstance> _collection = new List<ExpElementInstance>();
public ExpList(string accurateType) : base(accurateType) { }
public override int Count => _collection.Count;
public override string Name => ExpressCompile.PoolString("LIST");
public override ExpSyntaxNode CreateInstanceNode(Token t)
{
throw new NotImplementedException();
}
public override IEnumerator<ExpElementInstance> GetEnumerator()
{
return _collection.GetEnumerator();
}
}
public class ExpSet : ExpCollectionBase
{
private HashSet<ExpElementInstance> _collection = new();
public ExpSet(string accurateType) : base(accurateType) { }
public override int Count => _collection.Count;
public override string Name => ExpressCompile.PoolString("SET");
public void Add(ExpElementInstance token)
{
if (token.TypeName != MemberType) {
throw new ExpInvalidCollectionMemberTypeException(token, this);
}
_collection.Add(token);
}
public override ExpSyntaxNode CreateInstanceNode(Token t)
{
throw new NotImplementedException();
}
public sealed override IEnumerator<ExpElementInstance> GetEnumerator()
{
return ((IEnumerable<ExpElementInstance>)_collection)
.GetEnumerator();
}
}
}
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ExpCollection"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpCollectionBase : ExpInstantiableElement, IEnumerable<ExpElementInstance>
{
protected internal string _accurateType;
protected ExpCollectionBase(string accurateType)
{
_accurateType = accurateType;
}
public override ExpElementType ElementType => ExpElementType.Collection;
public abstract int Count { get; }
public sealed override IScriptSourceProvider SourceProvider => ScriptSourceTransmitter.Empty;
public string MemberType
{
get => _accurateType;
}
public override void Analyse()
{
return;
}
public abstract IEnumerator<ExpElementInstance> GetEnumerator();
public override bool TryGetMember(string name, out ExpSyntaxNode memberNode)
{
memberNode = ExpSyntaxNode.Empty;
return false;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
public class ExpArray : ExpCollectionBase
{
private ExpElementInstance[] _collection;
public ExpArray(string accurateType) : base(accurateType) { }
public ExpElementInstance this[int index]
{
get { return _collection[index]; }
set
{
if (value.TypeName != MemberType) {
throw new ExpInvalidCollectionMemberTypeException(value, this);
}
_collection[index] = value;
}
}
public override int Count => _collection.Length;
public override string Name => ExpressCompile.PoolString("ARRAY");
public override ExpSyntaxNode CreateInstanceNode(Token t)
{
throw new NotImplementedException();
}
public override IEnumerator<ExpElementInstance> GetEnumerator()
{
return ((IEnumerable<ExpElementInstance>)_collection)
.GetEnumerator();
}
}
public class ExpBag : ExpCollectionBase
{
private ConcurrentBag<ExpElementInstance> _collection = new ConcurrentBag<ExpElementInstance>(
);
public ExpBag(string accurateType) : base(accurateType) { }
public override int Count => _collection.Count;
public override string Name => ExpressCompile.PoolString("BAG");
public override ExpSyntaxNode CreateInstanceNode(Token t)
{
throw new NotImplementedException();
}
public override IEnumerator<ExpElementInstance> GetEnumerator()
{
return _collection.GetEnumerator();
}
}
public sealed class ExpList : ExpCollectionBase
{
private List<ExpElementInstance> _collection = new List<ExpElementInstance>();
public ExpList(string accurateType) : base(accurateType) { }
public override int Count => _collection.Count;
public override string Name => ExpressCompile.PoolString("LIST");
public override ExpSyntaxNode CreateInstanceNode(Token t)
{
throw new NotImplementedException();
}
public override IEnumerator<ExpElementInstance> GetEnumerator()
{
return _collection.GetEnumerator();
}
}
public class ExpSet : ExpCollectionBase
{
private HashSet<ExpElementInstance> _collection = new();
public ExpSet(string accurateType) : base(accurateType) { }
public override int Count => _collection.Count;
public override string Name => ExpressCompile.PoolString("SET");
public void Add(ExpElementInstance token)
{
if (token.TypeName != MemberType) {
throw new ExpInvalidCollectionMemberTypeException(token, this);
}
_collection.Add(token);
}
public override ExpSyntaxNode CreateInstanceNode(Token t)
{
throw new NotImplementedException();
}
public sealed override IEnumerator<ExpElementInstance> GetEnumerator()
{
return ((IEnumerable<ExpElementInstance>)_collection)
.GetEnumerator();
}
}
}
@@ -1,129 +1,129 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ExpCollectionInstance"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpCollectionInstanceBase : ExpSyntaxNode
{
protected internal (int min, int max) _range;
protected internal ExpElementType _memberType;
protected ExpCollectionInstanceBase(Token source) : base(source) { }
public abstract ExpCollectionBase CollectionValue { get; }
public ExpElementType MemberType
{
get => _memberType;
}
public override ExpSyntaxNode Left => null!;
public override ExpSyntaxNode Right => null!;
public int MinCapacity => _range.min;
public int MaxCapacity => _range.max;
}
public sealed class ExpSetInstance : ExpCollectionInstanceBase
{
private ExpSet _collection;
public ExpSetInstance(Token source, ExpSet set)
: base(source)
{
_collection = set;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpBagInstance : ExpCollectionInstanceBase
{
private ExpBag _collection;
public ExpBagInstance(Token source, ExpBag bag)
: base(source)
{
_collection = bag;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpListInstance : ExpCollectionInstanceBase
{
private ExpList _collection;
public ExpListInstance(Token source, ExpList list)
: base(source)
{
_collection = list;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpArrayInstance : ExpCollectionInstanceBase
{
private ExpArray _collection;
public ExpArrayInstance(Token source, ExpArray array)
: base(source)
{
_collection = array;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => _collection;
}
}
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ExpCollectionInstance"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpCollectionInstanceBase : ExpSyntaxNode
{
protected internal (int min, int max) _range;
protected internal ExpElementType _memberType;
protected ExpCollectionInstanceBase(Token source) : base(source) { }
public abstract ExpCollectionBase CollectionValue { get; }
public ExpElementType MemberType
{
get => _memberType;
}
public override ExpSyntaxNode Left => null!;
public override ExpSyntaxNode Right => null!;
public int MinCapacity => _range.min;
public int MaxCapacity => _range.max;
}
public sealed class ExpSetInstance : ExpCollectionInstanceBase
{
private ExpSet _collection;
public ExpSetInstance(Token source, ExpSet set)
: base(source)
{
_collection = set;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpBagInstance : ExpCollectionInstanceBase
{
private ExpBag _collection;
public ExpBagInstance(Token source, ExpBag bag)
: base(source)
{
_collection = bag;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpListInstance : ExpCollectionInstanceBase
{
private ExpList _collection;
public ExpListInstance(Token source, ExpList list)
: base(source)
{
_collection = list;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpArrayInstance : ExpCollectionInstanceBase
{
private ExpArray _collection;
public ExpArrayInstance(Token source, ExpArray array)
: base(source)
{
_collection = array;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => _collection;
}
}
+129 -129
View File
@@ -1,129 +1,129 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ExpLogic"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Script.Express
{
public enum ExpLogicValue
{
True,
False,
Unknown
}
public struct ExpLogic
{
public static readonly ExpLogic False = new ExpLogic(ExpLogicValue.False);
public static readonly ExpLogic True = new ExpLogic(ExpLogicValue.True);
public static readonly ExpLogic Unknown = new ExpLogic(ExpLogicValue.Unknown);
private readonly ExpLogicValue _value;
public ExpLogic(ExpLogicValue value)
{
_value = value;
}
public bool IsTrue => _value == ExpLogicValue.True;
public bool IsFalse => _value == ExpLogicValue.False;
public bool IsUnknown => _value == ExpLogicValue.Unknown;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ToBoolean()
{
return _value == ExpLogicValue.True;
}
public override string ToString() => _value.ToString();
public static bool TryParse(ReadOnlySpan<char> value, out ExpLogic result)
{
if (Enum.TryParse<ExpLogicValue>(value, out ExpLogicValue e))
{
result = new ExpLogic(e);
return true;
}
result = default;
return false;
}
// NOT !
public static ExpLogic operator !(ExpLogic a)
{
return a.IsTrue ? False : a.IsFalse ? True : Unknown;
}
// AND &
public static ExpLogic operator &(ExpLogic a, ExpLogic b)
{
if (a.IsFalse || b.IsFalse) {
return False;
}
if (a.IsUnknown || b.IsUnknown) {
return Unknown;
}
return True;
}
// XOR ^
public static ExpLogic operator ^(ExpLogic a, ExpLogic b)
{
if (a.IsUnknown || b.IsUnknown) {
return Unknown;
}
return (a.IsTrue ^ b.IsTrue) ? True : False;
}
// OR |
public static ExpLogic operator |(ExpLogic a, ExpLogic b)
{
if (a.IsTrue || b.IsTrue) {
return True;
}
if (a.IsUnknown || b.IsUnknown) {
return Unknown;
}
return False;
}
}
}
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ExpLogic"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Script.Express
{
public enum ExpLogicValue
{
True,
False,
Unknown
}
public struct ExpLogic
{
public static readonly ExpLogic False = new ExpLogic(ExpLogicValue.False);
public static readonly ExpLogic True = new ExpLogic(ExpLogicValue.True);
public static readonly ExpLogic Unknown = new ExpLogic(ExpLogicValue.Unknown);
private readonly ExpLogicValue _value;
public ExpLogic(ExpLogicValue value)
{
_value = value;
}
public bool IsTrue => _value == ExpLogicValue.True;
public bool IsFalse => _value == ExpLogicValue.False;
public bool IsUnknown => _value == ExpLogicValue.Unknown;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ToBoolean()
{
return _value == ExpLogicValue.True;
}
public override string ToString() => _value.ToString();
public static bool TryParse(ReadOnlySpan<char> value, out ExpLogic result)
{
if (Enum.TryParse<ExpLogicValue>(value, out ExpLogicValue e))
{
result = new ExpLogic(e);
return true;
}
result = default;
return false;
}
// NOT !
public static ExpLogic operator !(ExpLogic a)
{
return a.IsTrue ? False : a.IsFalse ? True : Unknown;
}
// AND &
public static ExpLogic operator &(ExpLogic a, ExpLogic b)
{
if (a.IsFalse || b.IsFalse) {
return False;
}
if (a.IsUnknown || b.IsUnknown) {
return Unknown;
}
return True;
}
// XOR ^
public static ExpLogic operator ^(ExpLogic a, ExpLogic b)
{
if (a.IsUnknown || b.IsUnknown) {
return Unknown;
}
return (a.IsTrue ^ b.IsTrue) ? True : False;
}
// OR |
public static ExpLogic operator |(ExpLogic a, ExpLogic b)
{
if (a.IsTrue || b.IsTrue) {
return True;
}
if (a.IsUnknown || b.IsUnknown) {
return Unknown;
}
return False;
}
}
}