Daily update 2 on 20240228 by nitload youmu
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpBaseNode.cs"
|
||||
// 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 CommunityToolkit.HighPerformance.Buffers;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public abstract class ExpBaseNode : IASTNode<ExpBaseNode, IExpElementSource>
|
||||
{
|
||||
|
||||
protected internal ExpNodeFlag _nodeFlag;
|
||||
protected internal string _name;
|
||||
|
||||
protected ExpBaseNode( string name, ExpSchema context )
|
||||
{
|
||||
_name = name;
|
||||
NameSpace = context;
|
||||
Next = this;
|
||||
Previous = this;
|
||||
}
|
||||
|
||||
public bool IsNumber
|
||||
{
|
||||
get { return ( _nodeFlag | ExpNodeFlag.BuiltinType_Number ) != 0; }
|
||||
}
|
||||
|
||||
public abstract ExpBaseNode Left
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public static ExpBaseNode Empty
|
||||
{
|
||||
get => ExpEmptyNode._only;
|
||||
}
|
||||
|
||||
public ExpBaseNode Next
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public abstract ExpBaseNode Right
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public ExpBaseNode Previous
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ExpSchema NameSpace
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public abstract IExpElementSource EqualityTypeConvert
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public long NodeFlag => ( long )_nodeFlag;
|
||||
|
||||
public string CodeConvertTemplate
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public string Name => _name;
|
||||
|
||||
public virtual void AppendNode( ExpBaseNode nextToken )
|
||||
{
|
||||
Next.Previous = nextToken;
|
||||
nextToken.Next = Next;
|
||||
Next = nextToken;
|
||||
Next.Previous = this;
|
||||
}
|
||||
|
||||
public ExpNodeNextEnumerator GetEnumerator()
|
||||
{
|
||||
return new ExpNodeNextEnumerator( this );
|
||||
}
|
||||
|
||||
public static bool VerifyTypeConvertable(
|
||||
ExpBaseNode left,
|
||||
ExpBaseNode right )
|
||||
{
|
||||
IExpElementSource tLeft = left.EqualityTypeConvert,
|
||||
tRight = right.EqualityTypeConvert;
|
||||
if( tLeft == null || tRight == null ) {
|
||||
return false;
|
||||
}
|
||||
return tLeft.IsConvertable( tRight );
|
||||
}
|
||||
|
||||
protected void AssertSchemaInclude( ExpBaseNode expressionRoot )
|
||||
{
|
||||
if( expressionRoot.NameSpace != NameSpace && NameSpace.TryGetSchemaInclude(
|
||||
expressionRoot.NameSpace.Name, out _ ) ) {
|
||||
throw new ExpInvalidSchemaIncludeException(
|
||||
NameSpace, expressionRoot.NameSpace );
|
||||
}
|
||||
}
|
||||
|
||||
private class ExpEmptyNode : ExpBaseNode
|
||||
{
|
||||
|
||||
internal static readonly ExpEmptyNode _only = new();
|
||||
|
||||
public ExpEmptyNode()
|
||||
: base( string.Empty, ExpSchema.BuiltinSchema ) { }
|
||||
|
||||
public override ExpBaseNode Left => _only;
|
||||
|
||||
public override ExpBaseNode Right => _only;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpBinaryOperatorNode.cs"
|
||||
// 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.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpBinaryOperatorNode : ExpBaseNode
|
||||
{
|
||||
|
||||
private ExpBaseNode _left;
|
||||
private ExpBaseNode _right;
|
||||
private ExpTypeSource _returnType;
|
||||
|
||||
public ExpBinaryOperatorNode( string name ) : base( name, null! ) { }
|
||||
|
||||
public ExpBinaryOperatorNode(
|
||||
string source,
|
||||
ExpSchema context,
|
||||
ExpBaseNode left,
|
||||
ExpBaseNode right )
|
||||
: base( source, context )
|
||||
{
|
||||
if( !left.EqualityTypeConvert
|
||||
.IsConvertable( right.EqualityTypeConvert ) ) {
|
||||
throw new InvalidCastException(
|
||||
$"Cannot convert element {left.EqualityTypeConvert} to {right.EqualityTypeConvert}" );
|
||||
}
|
||||
_left = left;
|
||||
_right = right;
|
||||
}
|
||||
|
||||
public override ExpBaseNode Left => _left;
|
||||
|
||||
public override ExpBaseNode Right => _right;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => _returnType;
|
||||
|
||||
public static ExpBinaryOperatorNode Add(
|
||||
ExpBaseNode left,
|
||||
ExpBaseNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
"Number", left.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
|
||||
0;
|
||||
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.ADD )
|
||||
{
|
||||
_returnType = isFloat ? null : null,
|
||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "{0} + {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode Div(
|
||||
ExpBaseNode left,
|
||||
ExpBaseNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
"Number", left.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
|
||||
0;
|
||||
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.DIV )
|
||||
{
|
||||
_returnType = isFloat ? null : null,
|
||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "{0} / {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode Mul(
|
||||
ExpBaseNode left,
|
||||
ExpBaseNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
"Number", left.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
|
||||
0;
|
||||
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.MUL )
|
||||
{
|
||||
_returnType = isFloat ? null : null,
|
||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "{0} * {1}",
|
||||
};
|
||||
}
|
||||
|
||||
public static ExpBinaryOperatorNode Sub(
|
||||
ExpBaseNode left,
|
||||
ExpBaseNode right )
|
||||
{
|
||||
if( !left.IsNumber && !right.IsNumber ) {
|
||||
throw new ExpInvalidTypeException(
|
||||
"Number", left.EqualityTypeConvert.Name );
|
||||
}
|
||||
bool isFloat =
|
||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
|
||||
0;
|
||||
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.SUB )
|
||||
{
|
||||
_returnType = isFloat ? : null,
|
||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||
CodeConvertTemplate = "{0} - {1}",
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpFunctionCallingNode.cs"
|
||||
// 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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
internal class ExpFunctionCallingNode : ExpBaseNode
|
||||
{
|
||||
|
||||
private ExpBaseNode _parameter;
|
||||
private ExpFunctionSource _function;
|
||||
|
||||
public ExpFunctionCallingNode(
|
||||
string functionName,
|
||||
int line,
|
||||
int column,
|
||||
ExpSchema context,
|
||||
ExpBaseNode firstParameter )
|
||||
: base( $"{functionName}_{line}_{column}", context )
|
||||
{
|
||||
_parameter = firstParameter;
|
||||
if( !context.TryGetFunction( functionName, out _function ) ) {
|
||||
foreach( var item in context. ) { }
|
||||
}
|
||||
}
|
||||
|
||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpBaseNode Right => _parameter;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpIfNode.cs"
|
||||
// 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.Script.Express;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public sealed class ExpIfNode : ExpBaseNode
|
||||
{
|
||||
|
||||
private ExpBaseNode _falseOpBegin;
|
||||
private ExpBaseNode _rule;
|
||||
private ExpBaseNode _trueOpBegin ;
|
||||
|
||||
public ExpIfNode(
|
||||
string name,
|
||||
ExpSchema context,
|
||||
ExpBaseNode rule,
|
||||
ExpBaseNode rootOperationIfTrue,
|
||||
ExpBaseNode rootOperationIfFalse )
|
||||
: base( name, context )
|
||||
{
|
||||
_rule = rule;
|
||||
_trueOpBegin = rootOperationIfFalse;
|
||||
_falseOpBegin = rootOperationIfFalse;
|
||||
}
|
||||
|
||||
public override ExpBaseNode Left => _trueOpBegin;
|
||||
|
||||
public override ExpBaseNode Right => _falseOpBegin;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => null!;
|
||||
|
||||
public void AppendFalseOperation( ExpBaseNode expressionRoot )
|
||||
{
|
||||
AssertSchemaInclude( expressionRoot );
|
||||
_falseOpBegin.AppendNode( expressionRoot );
|
||||
}
|
||||
|
||||
public void AppendTrueOperation( ExpBaseNode expressionRoot )
|
||||
{
|
||||
AssertSchemaInclude( expressionRoot );
|
||||
_trueOpBegin.AppendNode( expressionRoot );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpIndexOfNode.cs"
|
||||
// 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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpIndexOfNode : ExpBaseNode
|
||||
{
|
||||
|
||||
private ExpBaseNode _indexExpression;
|
||||
|
||||
private ExpCollectionInstanceBase _collection;
|
||||
|
||||
public ExpIndexOfNode(
|
||||
ExpSchema context,
|
||||
ExpCollectionInstanceBase instance,
|
||||
ExpBaseNode indexExpression )
|
||||
: base( ExpCompile.PoolString( "[" ), context )
|
||||
{
|
||||
_collection = instance;
|
||||
_indexExpression = indexExpression;
|
||||
}
|
||||
|
||||
public override ExpBaseNode Left => _collection;
|
||||
|
||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpLiteralGenericNode.cs"
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpLiteralNode
|
||||
{
|
||||
|
||||
private readonly IValueBox box;
|
||||
|
||||
}
|
||||
|
||||
public class ExpLiteralGenericNode<T> : ExpElementInstanceBase
|
||||
{
|
||||
|
||||
private readonly ExpBuiltinType _type;
|
||||
private readonly T _value;
|
||||
|
||||
public ExpLiteralGenericNode( string name, ExpSchema context, T value )
|
||||
: base( name, context )
|
||||
{
|
||||
_value = value;
|
||||
switch( value ) {
|
||||
case float f:
|
||||
ExpSchema.BuiltinSchema
|
||||
.TryGetType(
|
||||
ExpCompile.KeyWord.Real,
|
||||
out ExpTypeSource? type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Float | ExpNodeFlag.Element_Const;
|
||||
break;
|
||||
case int i:
|
||||
ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpCompile.KeyWord.Int, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
|
||||
break;
|
||||
case BitArray b:
|
||||
ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpCompile.KeyWord.Binary, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Binary | ExpNodeFlag.Element_Const;
|
||||
break;
|
||||
case string s:
|
||||
ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpCompile.KeyWord.String, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
|
||||
break;
|
||||
case ExpLogic l:
|
||||
ExpSchema.BuiltinSchema
|
||||
.TryGetType( ExpCompile.KeyWord.Logic, out type );
|
||||
_type = ( type as ExpBuiltinType )!;
|
||||
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException(
|
||||
"Builtin Type", value!.GetType().Name );
|
||||
}
|
||||
}
|
||||
|
||||
public override ExpBaseNode Left => ExpBaseNode;
|
||||
|
||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => _type;
|
||||
|
||||
public override string TypeName => _type.Name;
|
||||
|
||||
public T value => _value;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpRepeatNode.cs"
|
||||
// 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.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpRepeatToken : ExpBaseNode
|
||||
{
|
||||
|
||||
private ExpBaseNode _operationBegin;
|
||||
|
||||
private ExpElementInstanceBase _variable, _begin, _end, _increment;
|
||||
|
||||
public ExpRepeatToken(
|
||||
string name,
|
||||
ExpSchema context,
|
||||
ExpBaseNode operationBegin,
|
||||
ExpElementInstanceBase variable,
|
||||
ExpElementInstanceBase begin,
|
||||
ExpElementInstanceBase end,
|
||||
ExpElementInstanceBase increment )
|
||||
: base( name, context )
|
||||
{
|
||||
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag !=
|
||||
end.NodeFlag || ( increment != null && end.NodeFlag !=
|
||||
increment.NodeFlag ) ) {
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
if( increment == null ) {
|
||||
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any ) {
|
||||
case ExpNodeFlag.BuiltinType_Float:
|
||||
increment = new ExpLiteralGenericNode<float>(
|
||||
$"{name}_defaultIncrement", context, 1.0f );
|
||||
break;
|
||||
case ExpNodeFlag.BuiltinType_Int:
|
||||
increment = new ExpLiteralGenericNode<int>(
|
||||
$"{name}_defaultIncrement", context, 1 );
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException(
|
||||
"Int or Real", "otherwise" );
|
||||
}
|
||||
}
|
||||
_begin = begin;
|
||||
_variable = variable;
|
||||
_end = end;
|
||||
_increment = increment;
|
||||
_nodeFlag = ExpNodeFlag.Branch_Repeat;
|
||||
_operationBegin = operationBegin;
|
||||
}
|
||||
|
||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpBaseNode Right => _operationBegin;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => null!;
|
||||
|
||||
public void AppendRepeatedOperation( ExpBaseNode node )
|
||||
{
|
||||
_operationBegin.AppendNode( node );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSwitchNode.cs"
|
||||
// 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 class ExpSwitchNode : ExpBaseNode
|
||||
{
|
||||
|
||||
private Dictionary<ExpBaseNode, ExpBaseNode> _cases;
|
||||
private ExpBaseNode _default;
|
||||
private ExpBaseNode _target;
|
||||
|
||||
public ExpSwitchNode(
|
||||
string name,
|
||||
ExpSchema context,
|
||||
ExpBaseNode target,
|
||||
ExpBaseNode defaultCase,
|
||||
params (ExpBaseNode label, ExpBaseNode op)[] cases )
|
||||
: base( name, context )
|
||||
{
|
||||
_target = target;
|
||||
_default = defaultCase;
|
||||
_cases = new Dictionary<ExpBaseNode, ExpBaseNode>();
|
||||
foreach( (ExpBaseNode label, ExpBaseNode op ) item in cases ) {
|
||||
if( item.op == null ) {
|
||||
_cases.Add( item.label, null! );
|
||||
} else {
|
||||
_cases.Add( item.label, item.op );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ExpBaseNode this[ ExpBaseNode index ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( _cases.TryGetValue( index, out ExpBaseNode? ret ) ) {
|
||||
return ret;
|
||||
}
|
||||
return _default;
|
||||
}
|
||||
}
|
||||
|
||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
||||
|
||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => null!;
|
||||
|
||||
public void AddOperationToDefault( ExpBaseNode expressionRoot )
|
||||
{
|
||||
if( expressionRoot != null ) {
|
||||
_default.AppendNode( expressionRoot );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an expression to certain <see langword="case" />. The added expression will be run
|
||||
/// at last.
|
||||
/// </summary>
|
||||
/// <param name="label"> Label of case to add operation </param>
|
||||
/// <param name="expressionRoot"> Root token of the expression to be added. </param>
|
||||
/// <exception cref="ExpCaseNotFoundException"> Cannot fine the case label in current witch expression. </exception>
|
||||
public void AppendOperationToCase(
|
||||
ExpBaseNode label,
|
||||
ExpBaseNode expressionRoot )
|
||||
{
|
||||
AssertSchemaInclude( expressionRoot );
|
||||
if( _cases.TryGetValue( label, out ExpBaseNode? op ) ) {
|
||||
op.AppendNode( expressionRoot );
|
||||
} else {
|
||||
throw new ExpCaseNotFoundException( this, label );
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsCase( ExpBaseNode token )
|
||||
{
|
||||
return _cases.ContainsKey( token );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpUnaryOperatorNode.cs"
|
||||
// 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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public class ExpUnaryOperatorNode : ExpBaseNode
|
||||
{
|
||||
|
||||
private ExpBaseNode _operand;
|
||||
|
||||
public ExpUnaryOperatorNode(
|
||||
string name,
|
||||
ExpBaseNode operand,
|
||||
ExpSchema context )
|
||||
: base( name, context )
|
||||
{
|
||||
_operand = operand;
|
||||
}
|
||||
|
||||
public override ExpBaseNode Left => null!;
|
||||
|
||||
public override ExpBaseNode Right => _operand;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => _operand.EqualityTypeConvert;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user