Daily update on 20250310-064733 by Nitload Youmu. Additional Message : Change: Generic node removed, five non-generic node as replacement
Change: Preprocess to token scheduled, less dependency on type prediction, which put to LINK or C# compiling pase Design: the EXPRESS lang feature "FIXED" keyword not supported, builtin type binary not supported, not used in STEP AP203 and much too complex to make a full marshal implementation in C#. Add: Node generating method to generate literal node Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -43,16 +43,6 @@ namespace StgSharp.Script
|
|||||||
where TType: ITypeSource<TType>
|
where TType: ITypeSource<TType>
|
||||||
{
|
{
|
||||||
|
|
||||||
int Line
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Column
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
long NodeFlag
|
long NodeFlag
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ namespace StgSharp.Script
|
|||||||
public enum TokenFlag : int
|
public enum TokenFlag : int
|
||||||
{
|
{
|
||||||
|
|
||||||
|
None = 0,
|
||||||
Symbol_Unary = 1,
|
Symbol_Unary = 1,
|
||||||
Symbol_Binary = 2,
|
Symbol_Binary = 2,
|
||||||
Number = 3,
|
Number = 3,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace StgSharp.Script.Express
|
|||||||
protected internal (int min, int max) _range;
|
protected internal (int min, int max) _range;
|
||||||
protected internal ExpElementType _memberType;
|
protected internal ExpElementType _memberType;
|
||||||
|
|
||||||
protected ExpCollectionInstanceBase( string name ) : base( name ) { }
|
protected ExpCollectionInstanceBase( Token source ) : base( source ) { }
|
||||||
|
|
||||||
public abstract ExpCollectionBase CollectionValue
|
public abstract ExpCollectionBase CollectionValue
|
||||||
{
|
{
|
||||||
@@ -67,8 +67,8 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private ExpSet _collection;
|
private ExpSet _collection;
|
||||||
|
|
||||||
public ExpSetInstance( string name, ExpSet set, ExpSchema context )
|
public ExpSetInstance( Token source, ExpSet set )
|
||||||
: base( name )
|
: base( source )
|
||||||
{
|
{
|
||||||
_collection = set;
|
_collection = set;
|
||||||
}
|
}
|
||||||
@@ -85,8 +85,8 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private ExpBag _collection;
|
private ExpBag _collection;
|
||||||
|
|
||||||
public ExpBagInstance( string name, ExpBag bag, ExpSchema context )
|
public ExpBagInstance( Token source, ExpBag bag )
|
||||||
: base( name )
|
: base( source )
|
||||||
{
|
{
|
||||||
_collection = bag;
|
_collection = bag;
|
||||||
}
|
}
|
||||||
@@ -103,8 +103,8 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private ExpList _collection;
|
private ExpList _collection;
|
||||||
|
|
||||||
public ExpListInstance( string name, ExpList list, ExpSchema context )
|
public ExpListInstance( Token source, ExpList list )
|
||||||
: base( name )
|
: base( source )
|
||||||
{
|
{
|
||||||
_collection = list;
|
_collection = list;
|
||||||
}
|
}
|
||||||
@@ -121,11 +121,8 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private ExpArray _collection;
|
private ExpArray _collection;
|
||||||
|
|
||||||
public ExpArrayInstance(
|
public ExpArrayInstance( Token source, ExpArray array )
|
||||||
string name,
|
: base( source )
|
||||||
ExpArray array,
|
|
||||||
ExpSchema context )
|
|
||||||
: base( name )
|
|
||||||
{
|
{
|
||||||
_collection = array;
|
_collection = array;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,18 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public override string ToString() => _value.ToString();
|
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 !
|
// NOT !
|
||||||
public static ExpLogic operator !( ExpLogic a )
|
public static ExpLogic operator !( ExpLogic a )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
//-----------------------------------------------------------------------
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// file="BuiltinType.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 static partial class ExpCompile
|
||||||
|
{
|
||||||
|
|
||||||
|
public static ExpTypeSource ExpInt
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExpTypeSource ExpReal
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@ namespace StgSharp.Script.Express
|
|||||||
Name = "Nitload";
|
Name = "Nitload";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpSchema Only
|
internal static ExpSchema_Nitload Only
|
||||||
{
|
{
|
||||||
get => _onlyInstance;
|
get => _onlyInstance;
|
||||||
}
|
}
|
||||||
@@ -128,10 +128,12 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
ConstDict = new Dictionary<string, ExpElementInstanceBase>(
|
ConstDict = new Dictionary<string, ExpElementInstanceBase>(
|
||||||
Multiplexer ) {
|
Multiplexer ) {
|
||||||
{ PoolString( "PI" ), new ExpLiteralGenericNode<float>(
|
{ PoolString( "PI" ), new ExpRealNumberNode(
|
||||||
PoolString( "PI" ), MathF.PI ) },
|
new Token( PoolString( "PI" ), -1, -1, TokenFlag.Number ),
|
||||||
{ PoolString( "E" ), new ExpLiteralGenericNode<float>(
|
MathF.PI ) },
|
||||||
PoolString( "E" ), MathF.E ) },
|
{ PoolString( "E" ), new ExpRealNumberNode(
|
||||||
|
new Token( PoolString( "E" ), -1, -1, TokenFlag.Number ),
|
||||||
|
MathF.E ) },
|
||||||
}.ToFrozenDictionary();
|
}.ToFrozenDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ namespace StgSharp.Script.Express
|
|||||||
_compileStringCache = new StringPool();
|
_compileStringCache = new StringPool();
|
||||||
_multiplexer = new ConcurrentStringHashMultiplexer();
|
_multiplexer = new ConcurrentStringHashMultiplexer();
|
||||||
|
|
||||||
|
ExpSchema_Nitload.Only.Init();
|
||||||
|
|
||||||
PoolKeywords();
|
PoolKeywords();
|
||||||
InitPrecedence();
|
InitPrecedence();
|
||||||
|
|
||||||
@@ -96,6 +98,17 @@ namespace StgSharp.Script.Express
|
|||||||
KeyWord.ANDOR,
|
KeyWord.ANDOR,
|
||||||
KeyWord.NOT,
|
KeyWord.NOT,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
ExpSchema_Nitload.Only
|
||||||
|
.TryGetType(
|
||||||
|
PoolString( KeyWord.Int ), out ExpTypeSource? _expInt );
|
||||||
|
ExpInt = _expInt;
|
||||||
|
|
||||||
|
ExpSchema_Nitload.Only
|
||||||
|
.TryGetType(
|
||||||
|
PoolString( KeyWord.Real ),
|
||||||
|
out ExpTypeSource? _expReal );
|
||||||
|
ExpReal = _expReal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool LetterIsOperator( string str )
|
public static bool LetterIsOperator( string str )
|
||||||
|
|||||||
@@ -34,20 +34,6 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpEntity : ExpNode
|
|
||||||
{
|
|
||||||
|
|
||||||
public ExpEntity( string name, ExpSchema context ) : base( name ) { }
|
|
||||||
|
|
||||||
public override ExpNode Left => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public override ExpNode Right => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ExpEntitySource : ExpInstantiableElement
|
public class ExpEntitySource : ExpInstantiableElement
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -34,30 +34,6 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpFunction : ExpNode
|
|
||||||
{
|
|
||||||
|
|
||||||
private ExpFunctionSource _source;
|
|
||||||
|
|
||||||
private readonly ExpNode _return;
|
|
||||||
private readonly List<KeyValuePair<string, ExpNode>> _parameterList
|
|
||||||
= new List<KeyValuePair<string, ExpNode>>();
|
|
||||||
|
|
||||||
public ExpFunction( string name, ExpSchema context ) : base( name ) { }
|
|
||||||
|
|
||||||
public ExpElementType ElementType => ExpElementType.Function;
|
|
||||||
|
|
||||||
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
|
||||||
);
|
|
||||||
|
|
||||||
public override ExpNode Left => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public override ExpNode Right => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public void CallThisFunction( params ExpNode[] parameters ) { }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ExpFunctionSource : ExpImmutableElement
|
public class ExpFunctionSource : ExpImmutableElement
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private ExpRuleSource _source;
|
private ExpRuleSource _source;
|
||||||
|
|
||||||
public ExpRule( string name, ExpSchema context ) : base( name ) { }
|
public ExpRule( Token source ) : base( source ) { }
|
||||||
|
|
||||||
public object? value => throw new NotImplementedException();
|
public object? value => throw new NotImplementedException();
|
||||||
|
|
||||||
|
|||||||
@@ -35,23 +35,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpTypeInstance : ExpElementInstanceBase
|
public class ExpTypeSource : ExpInstantiableElement
|
||||||
{
|
|
||||||
|
|
||||||
public ExpTypeInstance( string name ) : base( name ) { }
|
|
||||||
|
|
||||||
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
|
||||||
);
|
|
||||||
|
|
||||||
public override ExpNode Left => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public override ExpNode Right => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public override string TypeName => throw new NotImplementedException();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ExpTypeSource : IExpElementSource
|
|
||||||
{
|
{
|
||||||
|
|
||||||
private ScriptSourceTransmitter _transmitter;
|
private ScriptSourceTransmitter _transmitter;
|
||||||
@@ -77,23 +61,23 @@ namespace StgSharp.Script.Express
|
|||||||
get => _isBuiltinType;
|
get => _isBuiltinType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpElementType ElementType => ExpElementType.Type;
|
public override ExpElementType ElementType => ExpElementType.Type;
|
||||||
|
|
||||||
public ExpTypeSource Void
|
public ExpTypeSource Void
|
||||||
{
|
{
|
||||||
get => ExpVoidType.Only;
|
get => ExpVoidType.Only;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IScriptSourceProvider SourceProvider => _transmitter;
|
public override IScriptSourceProvider SourceProvider => _transmitter;
|
||||||
|
|
||||||
public string Name => _name;
|
public override string Name => _name;
|
||||||
|
|
||||||
public virtual void Analyse()
|
public override void Analyse()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsConvertable( IExpElementSource targetType )
|
public override ExpNode CreateInstanceNode()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -45,7 +46,7 @@ namespace StgSharp.Script.Express
|
|||||||
private ExpNode _left;
|
private ExpNode _left;
|
||||||
private ExpNode _right;
|
private ExpNode _right;
|
||||||
|
|
||||||
private ExpBinaryOperatorNode( string name ) : base( name ) { }
|
private ExpBinaryOperatorNode( Token source ) : base( source ) { }
|
||||||
|
|
||||||
public override ExpInstantiableElement EqualityTypeConvert => _returnType;
|
public override ExpInstantiableElement EqualityTypeConvert => _returnType;
|
||||||
|
|
||||||
@@ -53,24 +54,28 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public override ExpNode Right => _right;
|
public override ExpNode Right => _right;
|
||||||
|
|
||||||
public static ExpBinaryOperatorNode Add( ExpNode left, ExpNode right )
|
public static ExpBinaryOperatorNode Add(
|
||||||
|
Token source,
|
||||||
|
ExpNode left,
|
||||||
|
ExpNode right )
|
||||||
{
|
{
|
||||||
if( !left.IsNumber && !right.IsNumber ) {
|
if( !left.IsNumber && !right.IsNumber ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
"Number", left.EqualityTypeConvert.Name );
|
"Number", left.EqualityTypeConvert.Name );
|
||||||
}
|
}
|
||||||
bool isFloat =
|
bool isFloat =
|
||||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
|
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
|
||||||
0;
|
0;
|
||||||
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.ADD )
|
return new ExpBinaryOperatorNode( source )
|
||||||
{
|
{
|
||||||
_returnType = isFloat ? null : null,
|
_returnType = isFloat ? ExpCompile.ExpReal : ExpCompile.ExpInt,
|
||||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||||
CodeConvertTemplate = "{0} + {1}",
|
CodeConvertTemplate = "{0} + {1}",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpBinaryOperatorNode Assign(
|
public static ExpBinaryOperatorNode Assign(
|
||||||
|
Token source,
|
||||||
ExpNode left,
|
ExpNode left,
|
||||||
ExpNode right )
|
ExpNode right )
|
||||||
{
|
{
|
||||||
@@ -79,7 +84,7 @@ namespace StgSharp.Script.Express
|
|||||||
left.EqualityTypeConvert.Name,
|
left.EqualityTypeConvert.Name,
|
||||||
right.EqualityTypeConvert.Name );
|
right.EqualityTypeConvert.Name );
|
||||||
}
|
}
|
||||||
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.Assignment )
|
return new ExpBinaryOperatorNode( source )
|
||||||
{
|
{
|
||||||
_returnType = ExpInstantiableElement.Void,
|
_returnType = ExpInstantiableElement.Void,
|
||||||
_nodeFlag = ExpNodeFlag.Operator_Binary | left._nodeFlag,
|
_nodeFlag = ExpNodeFlag.Operator_Binary | left._nodeFlag,
|
||||||
@@ -87,52 +92,61 @@ namespace StgSharp.Script.Express
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpBinaryOperatorNode Div( ExpNode left, ExpNode right )
|
public static ExpBinaryOperatorNode Div(
|
||||||
|
Token source,
|
||||||
|
ExpNode left,
|
||||||
|
ExpNode right )
|
||||||
{
|
{
|
||||||
if( !left.IsNumber && !right.IsNumber ) {
|
if( !left.IsNumber && !right.IsNumber ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
"Number", left.EqualityTypeConvert.Name );
|
"Number", left.EqualityTypeConvert.Name );
|
||||||
}
|
}
|
||||||
bool isFloat =
|
bool isFloat =
|
||||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
|
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
|
||||||
0;
|
0;
|
||||||
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.DIV )
|
return new ExpBinaryOperatorNode( source )
|
||||||
{
|
{
|
||||||
_returnType = isFloat ? null : null,
|
_returnType = isFloat ? ExpCompile.ExpReal : ExpCompile.ExpInt,
|
||||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||||
CodeConvertTemplate = "{0} / {1}",
|
CodeConvertTemplate = "{0} / {1}",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpBinaryOperatorNode Mul( ExpNode left, ExpNode right )
|
public static ExpBinaryOperatorNode Mul(
|
||||||
|
Token source,
|
||||||
|
ExpNode left,
|
||||||
|
ExpNode right )
|
||||||
{
|
{
|
||||||
if( !left.IsNumber && !right.IsNumber ) {
|
if( !left.IsNumber && !right.IsNumber ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
"Number", left.EqualityTypeConvert.Name );
|
"Number", left.EqualityTypeConvert.Name );
|
||||||
}
|
}
|
||||||
bool isFloat =
|
bool isFloat =
|
||||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
|
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
|
||||||
0;
|
0;
|
||||||
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.MUL )
|
return new ExpBinaryOperatorNode( source )
|
||||||
{
|
{
|
||||||
_returnType = isFloat ? null : null,
|
_returnType = isFloat ? ExpCompile.ExpReal : ExpCompile.ExpInt,
|
||||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||||
CodeConvertTemplate = "{0} * {1}",
|
CodeConvertTemplate = "{0} * {1}",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpBinaryOperatorNode Sub( ExpNode left, ExpNode right )
|
public static ExpBinaryOperatorNode Sub(
|
||||||
|
Token source,
|
||||||
|
ExpNode left,
|
||||||
|
ExpNode right )
|
||||||
{
|
{
|
||||||
if( !left.IsNumber && !right.IsNumber ) {
|
if( !left.IsNumber && !right.IsNumber ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
"Number", left.EqualityTypeConvert.Name );
|
"Number", left.EqualityTypeConvert.Name );
|
||||||
}
|
}
|
||||||
bool isFloat =
|
bool isFloat =
|
||||||
( left._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Float ) ==
|
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 || ( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) ==
|
||||||
0;
|
0;
|
||||||
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.SUB )
|
return new ExpBinaryOperatorNode( source )
|
||||||
{
|
{
|
||||||
_returnType = isFloat ? : null,
|
_returnType = isFloat ? ExpCompile.ExpReal : ExpCompile.ExpInt,
|
||||||
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
|
||||||
CodeConvertTemplate = "{0} - {1}",
|
CodeConvertTemplate = "{0} - {1}",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ namespace StgSharp.Script.Express
|
|||||||
private ExpInstantiableElement _element;
|
private ExpInstantiableElement _element;
|
||||||
|
|
||||||
public ExpElementInstanceNode(
|
public ExpElementInstanceNode(
|
||||||
string varName,
|
Token source,
|
||||||
ExpInstantiableElement element )
|
ExpInstantiableElement element )
|
||||||
: base( varName )
|
: base( source )
|
||||||
{
|
{
|
||||||
_element = element;
|
_element = element;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,13 +34,12 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.Script.Express.ExpAstNode
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpElementMemberNameNode : ExpNode
|
public class ExpElementMemberNameNode : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
public ExpElementMemberNameNode( string memberName )
|
public ExpElementMemberNameNode( Token source ) : base( source ) { }
|
||||||
: base( memberName ) { }
|
|
||||||
|
|
||||||
public override ExpNode Left => Empty;
|
public override ExpNode Left => Empty;
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,10 @@ namespace StgSharp.Script.Express
|
|||||||
private ExpNode _parameter;
|
private ExpNode _parameter;
|
||||||
|
|
||||||
public ExpFunctionCallingNode(
|
public ExpFunctionCallingNode(
|
||||||
|
Token source,
|
||||||
ExpFunctionSource function,
|
ExpFunctionSource function,
|
||||||
ExpNode firstParameter )
|
ExpNode firstParameter )
|
||||||
: base( $"{function.Name}_call" )
|
: base( source )
|
||||||
{
|
{
|
||||||
_function = function;
|
_function = function;
|
||||||
_parameter = firstParameter;
|
_parameter = firstParameter;
|
||||||
|
|||||||
@@ -44,12 +44,12 @@ namespace StgSharp.Script.Express
|
|||||||
private ExpNode _trueOpBegin ;
|
private ExpNode _trueOpBegin ;
|
||||||
|
|
||||||
public ExpIfNode(
|
public ExpIfNode(
|
||||||
string name,
|
Token source,
|
||||||
ExpSchema context,
|
ExpSchema context,
|
||||||
ExpNode rule,
|
ExpNode rule,
|
||||||
ExpNode rootOperationIfTrue,
|
ExpNode rootOperationIfTrue,
|
||||||
ExpNode rootOperationIfFalse )
|
ExpNode rootOperationIfFalse )
|
||||||
: base( name )
|
: base( source )
|
||||||
{
|
{
|
||||||
_rule = rule;
|
_rule = rule;
|
||||||
_trueOpBegin = rootOperationIfFalse;
|
_trueOpBegin = rootOperationIfFalse;
|
||||||
|
|||||||
@@ -44,9 +44,10 @@ namespace StgSharp.Script.Express
|
|||||||
private ExpNode _indexExpression;
|
private ExpNode _indexExpression;
|
||||||
|
|
||||||
private ExpIndexOfNode(
|
private ExpIndexOfNode(
|
||||||
|
Token source,
|
||||||
ExpCollectionInstanceBase instance,
|
ExpCollectionInstanceBase instance,
|
||||||
ExpNode indexExpression )
|
ExpNode indexExpression )
|
||||||
: base( ExpCompile.PoolString( "[" ) )
|
: base( source )
|
||||||
{
|
{
|
||||||
_collection = instance;
|
_collection = instance;
|
||||||
_indexExpression = indexExpression;
|
_indexExpression = indexExpression;
|
||||||
@@ -60,6 +61,7 @@ namespace StgSharp.Script.Express
|
|||||||
public override IExpElementSource EqualityTypeConvert => _collection.EqualityTypeConvert;
|
public override IExpElementSource EqualityTypeConvert => _collection.EqualityTypeConvert;
|
||||||
|
|
||||||
public static ExpIndexOfNode Create(
|
public static ExpIndexOfNode Create(
|
||||||
|
Token source,
|
||||||
ExpCollectionInstanceBase instance,
|
ExpCollectionInstanceBase instance,
|
||||||
ExpNode indexExpression )
|
ExpNode indexExpression )
|
||||||
{
|
{
|
||||||
@@ -67,7 +69,7 @@ namespace StgSharp.Script.Express
|
|||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
"Number", indexExpression.EqualityTypeConvert.Name );
|
"Number", indexExpression.EqualityTypeConvert.Name );
|
||||||
}
|
}
|
||||||
return new ExpIndexOfNode( instance, indexExpression );
|
return new ExpIndexOfNode( source, instance, indexExpression );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
//-----------------------------------------------------------------------
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// file="ExpInstanceReferenceNode.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 ExpInstanceReferenceNode : ExpNode
|
||||||
|
{
|
||||||
|
|
||||||
|
public override ExpNode Left => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public override ExpNode Right => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,71 +37,121 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpLiteralNode
|
public class ExpIntNode : ExpElementInstanceBase
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly IValueBox box;
|
private int _value;
|
||||||
|
|
||||||
}
|
public ExpIntNode( Token source, int value )
|
||||||
|
: base( source )
|
||||||
public class ExpLiteralGenericNode<T> : ExpElementInstanceBase
|
|
||||||
{
|
|
||||||
|
|
||||||
private readonly ExpBuiltinType _type;
|
|
||||||
private readonly T _value;
|
|
||||||
|
|
||||||
public ExpLiteralGenericNode( string name, T value )
|
|
||||||
: base( name )
|
|
||||||
{
|
{
|
||||||
_value = value;
|
_value = value;
|
||||||
switch( value ) {
|
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Type;
|
||||||
case float f:
|
}
|
||||||
ExpSchema.BuiltinSchema
|
|
||||||
|
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
|
||||||
.TryGetType(
|
.TryGetType(
|
||||||
ExpCompile.KeyWord.Real,
|
ExpCompile.KeyWord.Int, out ExpTypeSource? type ) ?
|
||||||
out ExpTypeSource? type );
|
type : throw new ExpCompileNotInitializedException();
|
||||||
_type = ( type as ExpBuiltinType )!;
|
|
||||||
_nodeFlag = ExpNodeFlag.BuiltinType_Float | ExpNodeFlag.Element_Const;
|
public int Value => _value;
|
||||||
break;
|
|
||||||
case int i:
|
public override string TypeName => ExpCompile.KeyWord.Int;
|
||||||
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 ExpNode Left => Empty;
|
public class ExpStringNode : ExpElementInstanceBase
|
||||||
|
{
|
||||||
|
|
||||||
public override ExpNode Right => throw new NotImplementedException();
|
private readonly string _value;
|
||||||
|
|
||||||
public override IExpElementSource EqualityTypeConvert => _type;
|
public ExpStringNode( Token source, string value )
|
||||||
|
: base( source )
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
_nodeFlag = ExpNodeFlag.BuiltinType_String | ExpNodeFlag.Element_Type;
|
||||||
|
}
|
||||||
|
|
||||||
public override string TypeName => _type.Name;
|
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
|
||||||
|
.TryGetType(
|
||||||
|
ExpCompile.KeyWord.String,
|
||||||
|
out ExpTypeSource? type ) ?
|
||||||
|
type : throw new ExpCompileNotInitializedException();
|
||||||
|
|
||||||
public T value => _value;
|
public override string TypeName => EqualityTypeConvert.Name;
|
||||||
|
|
||||||
|
public string Value => _value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ExpBoolNode : ExpElementInstanceBase
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly bool _value;
|
||||||
|
|
||||||
|
public ExpBoolNode( Token source, bool value )
|
||||||
|
: base( source )
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Element_Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Value => _value;
|
||||||
|
|
||||||
|
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
|
||||||
|
.TryGetType(
|
||||||
|
ExpCompile.KeyWord.Bool, out ExpTypeSource? type ) ?
|
||||||
|
type : throw new ExpCompileNotInitializedException();
|
||||||
|
|
||||||
|
public override string TypeName => EqualityTypeConvert.Name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ExpRealNumberNode : ExpElementInstanceBase
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly float _value;
|
||||||
|
|
||||||
|
public ExpRealNumberNode( Token source, float value )
|
||||||
|
: base( source )
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
_nodeFlag = ExpNodeFlag.BuiltinType_Real | ExpNodeFlag.Element_Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Value => _value;
|
||||||
|
|
||||||
|
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
|
||||||
|
.TryGetType(
|
||||||
|
ExpCompile.KeyWord.String,
|
||||||
|
out ExpTypeSource? type ) ?
|
||||||
|
type : throw new ExpCompileNotInitializedException();
|
||||||
|
|
||||||
|
public override string TypeName => EqualityTypeConvert.Name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ExpLogicValueNode : ExpElementInstanceBase
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly ExpLogic _value;
|
||||||
|
|
||||||
|
public ExpLogicValueNode( Token source, ExpLogic value )
|
||||||
|
: base( source )
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
_nodeFlag = ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.Element_Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpLogic Value => _value;
|
||||||
|
|
||||||
|
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
|
||||||
|
.TryGetType(
|
||||||
|
ExpCompile.KeyWord.Logic,
|
||||||
|
out ExpTypeSource? type ) ?
|
||||||
|
type : throw new ExpCompileNotInitializedException();
|
||||||
|
|
||||||
|
public override string TypeName => EqualityTypeConvert.Name;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,14 +46,13 @@ namespace StgSharp.Script.Express
|
|||||||
private ExpNode _operationBegin;
|
private ExpNode _operationBegin;
|
||||||
|
|
||||||
public ExpRepeatToken(
|
public ExpRepeatToken(
|
||||||
string name,
|
Token source,
|
||||||
ExpSchema context,
|
|
||||||
ExpNode operationBegin,
|
ExpNode operationBegin,
|
||||||
ExpElementInstanceBase variable,
|
ExpElementInstanceBase variable,
|
||||||
ExpElementInstanceBase begin,
|
ExpElementInstanceBase begin,
|
||||||
ExpElementInstanceBase end,
|
ExpElementInstanceBase end,
|
||||||
ExpElementInstanceBase increment )
|
ExpElementInstanceBase increment )
|
||||||
: base( name )
|
: base( source )
|
||||||
{
|
{
|
||||||
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag !=
|
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag !=
|
||||||
end.NodeFlag || ( increment != null && end.NodeFlag !=
|
end.NodeFlag || ( increment != null && end.NodeFlag !=
|
||||||
@@ -62,13 +61,19 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
if( increment == null ) {
|
if( increment == null ) {
|
||||||
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any ) {
|
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any ) {
|
||||||
case ExpNodeFlag.BuiltinType_Float:
|
case ExpNodeFlag.BuiltinType_Real:
|
||||||
increment = new ExpLiteralGenericNode<float>(
|
increment = new ExpLiteralGenericNode<float>(
|
||||||
$"{name}_defaultIncrement", 1.0f );
|
new Token(
|
||||||
|
ExpCompile.PoolString( "1.0f" ), source.Line,
|
||||||
|
-1, TokenFlag.Number ),
|
||||||
|
1.0f );
|
||||||
break;
|
break;
|
||||||
case ExpNodeFlag.BuiltinType_Int:
|
case ExpNodeFlag.BuiltinType_Int:
|
||||||
increment = new ExpLiteralGenericNode<int>(
|
increment = new ExpLiteralGenericNode<int>(
|
||||||
$"{name}_defaultIncrement", 1 );
|
new Token(
|
||||||
|
ExpCompile.PoolString( "1" ), source.Line, -1,
|
||||||
|
TokenFlag.Number ),
|
||||||
|
1 );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
|
|||||||
@@ -42,12 +42,11 @@ namespace StgSharp.Script.Express
|
|||||||
private ExpNode _target;
|
private ExpNode _target;
|
||||||
|
|
||||||
public ExpSwitchNode(
|
public ExpSwitchNode(
|
||||||
string name,
|
Token source,
|
||||||
ExpSchema context,
|
|
||||||
ExpNode target,
|
ExpNode target,
|
||||||
ExpNode defaultCase,
|
ExpNode defaultCase,
|
||||||
params (ExpNode label, ExpNode op)[] cases )
|
params (ExpNode label, ExpNode op)[] cases )
|
||||||
: base( name )
|
: base( source )
|
||||||
{
|
{
|
||||||
_target = target;
|
_target = target;
|
||||||
_default = defaultCase;
|
_default = defaultCase;
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private ExpNode _operand;
|
private ExpNode _operand;
|
||||||
|
|
||||||
private ExpUnaryOperatorNode( string name ) : base( name ) { }
|
private ExpUnaryOperatorNode( Token source ) : base( source ) { }
|
||||||
|
|
||||||
public ExpUnaryOperatorNode(
|
public ExpUnaryOperatorNode(
|
||||||
string name,
|
Token source,
|
||||||
ExpNode operand,
|
ExpNode operand,
|
||||||
ExpSchema context )
|
ExpSchema context )
|
||||||
: base( name )
|
: base( source )
|
||||||
{
|
{
|
||||||
_operand = operand;
|
_operand = operand;
|
||||||
}
|
}
|
||||||
@@ -58,44 +58,50 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public override IExpElementSource EqualityTypeConvert => _operand.EqualityTypeConvert;
|
public override IExpElementSource EqualityTypeConvert => _operand.EqualityTypeConvert;
|
||||||
|
|
||||||
public static ExpUnaryOperatorNode UnaryMinus( ExpNode operand )
|
public static ExpUnaryOperatorNode UnaryMinus(
|
||||||
|
Token source,
|
||||||
|
ExpNode operand )
|
||||||
{
|
{
|
||||||
if( !operand.IsNumber ) {
|
if( !operand.IsNumber ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
"Number", operand.EqualityTypeConvert.Name );
|
"Number", operand.EqualityTypeConvert.Name );
|
||||||
}
|
}
|
||||||
bool isFloat =
|
bool isFloat =
|
||||||
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0;
|
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
|
||||||
return new ExpUnaryOperatorNode( ExpCompile.KeyWord.SUB )
|
return new ExpUnaryOperatorNode( source )
|
||||||
{
|
{
|
||||||
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Number,
|
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Number,
|
||||||
CodeConvertTemplate = "- {0}",
|
CodeConvertTemplate = "- {0}",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpUnaryOperatorNode UnaryNot( ExpNode operand )
|
public static ExpUnaryOperatorNode UnaryNot(
|
||||||
|
Token source,
|
||||||
|
ExpNode operand )
|
||||||
{
|
{
|
||||||
if( ( operand._nodeFlag | ( ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.BuiltinType_Logic ) ) ==
|
if( ( operand._nodeFlag | ( ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.BuiltinType_Logic ) ) ==
|
||||||
0 ) {
|
0 ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
"Bool or Logic", operand.EqualityTypeConvert.Name );
|
"Bool or Logic", operand.EqualityTypeConvert.Name );
|
||||||
}
|
}
|
||||||
return new ExpUnaryOperatorNode( ExpCompile.KeyWord.NOT )
|
return new ExpUnaryOperatorNode( source )
|
||||||
{
|
{
|
||||||
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Logic,
|
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Logic,
|
||||||
CodeConvertTemplate = "! {0}",
|
CodeConvertTemplate = "! {0}",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpUnaryOperatorNode UnaryPlus( ExpNode operand )
|
public static ExpUnaryOperatorNode UnaryPlus(
|
||||||
|
Token source,
|
||||||
|
ExpNode operand )
|
||||||
{
|
{
|
||||||
if( !operand.IsNumber ) {
|
if( !operand.IsNumber ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
"Number", operand.EqualityTypeConvert.Name );
|
"Number", operand.EqualityTypeConvert.Name );
|
||||||
}
|
}
|
||||||
bool isFloat =
|
bool isFloat =
|
||||||
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0;
|
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
|
||||||
return new ExpUnaryOperatorNode( ExpCompile.KeyWord.SUB )
|
return new ExpUnaryOperatorNode( source )
|
||||||
{
|
{
|
||||||
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Number,
|
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Number,
|
||||||
CodeConvertTemplate = "+ {0}",
|
CodeConvertTemplate = "+ {0}",
|
||||||
|
|||||||
@@ -41,11 +41,11 @@ namespace StgSharp.Script.Express
|
|||||||
{
|
{
|
||||||
|
|
||||||
protected internal ExpNodeFlag _nodeFlag;
|
protected internal ExpNodeFlag _nodeFlag;
|
||||||
protected internal string _name;
|
protected internal Token _source;
|
||||||
|
|
||||||
protected ExpNode( string name )
|
protected ExpNode( Token source )
|
||||||
{
|
{
|
||||||
_name = name;
|
_source = source;
|
||||||
Next = this;
|
Next = this;
|
||||||
Previous = this;
|
Previous = this;
|
||||||
}
|
}
|
||||||
@@ -87,6 +87,10 @@ namespace StgSharp.Script.Express
|
|||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int Line => _source.Line;
|
||||||
|
|
||||||
|
public int Column => _source.Column;
|
||||||
|
|
||||||
public long NodeFlag => ( long )_nodeFlag;
|
public long NodeFlag => ( long )_nodeFlag;
|
||||||
|
|
||||||
public string CodeConvertTemplate
|
public string CodeConvertTemplate
|
||||||
@@ -114,9 +118,15 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||||
public static ExpNode NonOperation( string name )
|
public static ExpNode NonOperation( Token source )
|
||||||
{
|
{
|
||||||
return new ExpEmptyNode( name );
|
return new ExpEmptyNode( source.Line, source.Column );
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||||
|
public static ExpNode NonOperation( int line, int column )
|
||||||
|
{
|
||||||
|
return new ExpEmptyNode( line, column );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PrependNode( ExpNode previousNode )
|
public void PrependNode( ExpNode previousNode )
|
||||||
@@ -146,9 +156,11 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
internal static readonly ExpEmptyNode _only = new();
|
internal static readonly ExpEmptyNode _only = new();
|
||||||
|
|
||||||
public ExpEmptyNode() : base( string.Empty ) { }
|
public ExpEmptyNode() : base( Token.Empty ) { }
|
||||||
|
|
||||||
public ExpEmptyNode( string name ) : base( name ) { }
|
public ExpEmptyNode( int line, int column )
|
||||||
|
: base(
|
||||||
|
new Token( string.Empty, line, column, TokenFlag.None ) ) { }
|
||||||
|
|
||||||
public override ExpInstantiableElement EqualityTypeConvert => ExpInstantiableElement.Void;
|
public override ExpInstantiableElement EqualityTypeConvert => ExpInstantiableElement.Void;
|
||||||
|
|
||||||
|
|||||||
@@ -56,17 +56,36 @@ namespace StgSharp.Script.Express
|
|||||||
public abstract class ExpElementInstanceBase : ExpNode
|
public abstract class ExpElementInstanceBase : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
protected ExpElementInstanceBase( string name ) : base( name ) { }
|
protected ExpElementInstanceBase( Token source ) : base( source ) { }
|
||||||
|
|
||||||
public ExpElementType ElementType
|
public ExpElementType ElementType
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override ExpNode Left => Empty;
|
||||||
|
|
||||||
|
public override ExpNode Right => Empty;
|
||||||
|
|
||||||
public abstract string TypeName
|
public abstract string TypeName
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ExpElementInstanceBase CreateLiteral( Token t )
|
||||||
|
{
|
||||||
|
if( int.TryParse( t.Value, out int _int ) ) {
|
||||||
|
return new ExpIntNode( t, _int );
|
||||||
|
} else if( float.TryParse( t.Value, out float _float ) ) {
|
||||||
|
return new ExpRealNumberNode( t, _float );
|
||||||
|
} else if( bool.TryParse( t.Value, out bool _bool ) ) {
|
||||||
|
return new ExpBoolNode( t, _bool );
|
||||||
|
} else if( ExpLogic.TryParse( t.Value, out ExpLogic _logic ) ) {
|
||||||
|
return new ExpLogicValueNode( t, _logic );
|
||||||
|
} else {
|
||||||
|
return new ExpStringNode( t, t.Value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public ExpCaseNotFoundException( ExpSwitchNode token, ExpNode label )
|
public ExpCaseNotFoundException( ExpSwitchNode token, ExpNode label )
|
||||||
: base(
|
: base(
|
||||||
$"Attempt to read or write the label {label.Name} not exist in SWITCH expression {token.Name}" ) { }
|
$"Attempt to read or write the label at ({token.Line},{token.Column}), that does not exist in SWITCH expression at ({token.Line},{token.Column})" ) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,13 +66,13 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
//variable is one of these builtin type
|
//variable is one of these builtin type
|
||||||
BuiltinType_Int = 16384,
|
BuiltinType_Int = 16384,
|
||||||
BuiltinType_Float = 32768,
|
BuiltinType_Real = 32768,
|
||||||
BuiltinType_String = 65536,
|
BuiltinType_String = 65536,
|
||||||
BuiltinType_Boolean = 0x2000,
|
BuiltinType_Boolean = 0x2000,
|
||||||
BuiltinType_Binary = 0x4000,
|
BuiltinType_Binary = 0x4000,
|
||||||
BuiltinType_Logic = 0x8000,
|
BuiltinType_Logic = 0x8000,
|
||||||
BuiltinType_Number = BuiltinType_Float | BuiltinType_Int,
|
BuiltinType_Number = BuiltinType_Real | BuiltinType_Int,
|
||||||
BuiltinType_Any = BuiltinType_Int | BuiltinType_Float | BuiltinType_String | BuiltinType_Boolean | BuiltinType_Binary | BuiltinType_Logic,
|
BuiltinType_Any = BuiltinType_Int | BuiltinType_Real | BuiltinType_String | BuiltinType_Boolean | BuiltinType_Binary | BuiltinType_Logic,
|
||||||
|
|
||||||
//the token is root of a branch
|
//the token is root of a branch
|
||||||
Branch_If = 0x1_000,
|
Branch_If = 0x1_000,
|
||||||
|
|||||||
@@ -65,27 +65,23 @@ namespace StgSharp.Script.Express
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compile a parameter expression and add it to head of function parameter node list.
|
/// Compile a parameter expression and add it to head of function parameter node list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void MergeFunctionCallingParameter()
|
private void MergeFunctionCallingParameter( Token currentSeparator )
|
||||||
{
|
{
|
||||||
if( _cache.OperandAheadOfDepth == 1 ) {
|
if( _cache.OperandAheadOfDepth == 1 ) {
|
||||||
if( _cache.PopOperand( out Token t, out ExpNode? n ) ) {
|
if( _cache.PopOperand( out Token t, out ExpNode? n ) ) {
|
||||||
n!.PrependNode(
|
n!.PrependNode( ExpNode.NonOperation( currentSeparator ) );
|
||||||
ExpNode.NonOperation( PoolString( "FuncParam" ) ) );
|
|
||||||
} else {
|
} else {
|
||||||
switch( t.Flag ) {
|
switch( t.Flag ) {
|
||||||
case TokenFlag.Number:
|
case TokenFlag.Number:
|
||||||
if( int.TryParse( t.Value, out int intVal ) ) {
|
if( int.TryParse( t.Value, out int intVal ) ) {
|
||||||
n = new ExpLiteralGenericNode<int>(
|
n = new ExpIntNode( t, intVal );
|
||||||
t.Value, intVal );
|
|
||||||
} else if( float.TryParse(
|
} else if( float.TryParse(
|
||||||
t.Value, out float floatVal ) ) {
|
t.Value, out float floatVal ) ) {
|
||||||
n = new ExpLiteralGenericNode<float>(
|
n = new ExpRealNumberNode( t, floatVal );
|
||||||
t.Value, floatVal );
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TokenFlag.String:
|
case TokenFlag.String:
|
||||||
n = new ExpLiteralGenericNode<string>(
|
n = new ExpStringNode( t, t.Value );
|
||||||
t.Value, t.Value );
|
|
||||||
break;
|
break;
|
||||||
case TokenFlag.Member:
|
case TokenFlag.Member:
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// file="GenerateOperatorToken.cs"
|
// file="ExpNodeGenerator.Operator.cs"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
@@ -54,16 +54,16 @@ namespace StgSharp.Script.Express
|
|||||||
ExpNode right = GetNextOperandCache();
|
ExpNode right = GetNextOperandCache();
|
||||||
switch( t.Value ) {
|
switch( t.Value ) {
|
||||||
case ExpCompile.KeyWord.ADD:
|
case ExpCompile.KeyWord.ADD:
|
||||||
node = ExpBinaryOperatorNode.Add( left, right );
|
node = ExpBinaryOperatorNode.Add( t, left, right );
|
||||||
return true;
|
return true;
|
||||||
case ExpCompile.KeyWord.SUB:
|
case ExpCompile.KeyWord.SUB:
|
||||||
node = ExpBinaryOperatorNode.Sub( left, right );
|
node = ExpBinaryOperatorNode.Sub( t, left, right );
|
||||||
return true;
|
return true;
|
||||||
case ExpCompile.KeyWord.MUL:
|
case ExpCompile.KeyWord.MUL:
|
||||||
node = ExpBinaryOperatorNode.Mul( left, right );
|
node = ExpBinaryOperatorNode.Mul( t, left, right );
|
||||||
return true;
|
return true;
|
||||||
case ExpCompile.KeyWord.DIV:
|
case ExpCompile.KeyWord.DIV:
|
||||||
node = ExpBinaryOperatorNode.Div( left, right );
|
node = ExpBinaryOperatorNode.Div( t, left, right );
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
node = ExpNode.Empty;
|
node = ExpNode.Empty;
|
||||||
@@ -76,13 +76,13 @@ namespace StgSharp.Script.Express
|
|||||||
ExpNode operand = GetNextOperandCache();
|
ExpNode operand = GetNextOperandCache();
|
||||||
switch( t.Value ) {
|
switch( t.Value ) {
|
||||||
case ExpCompile.KeyWord.UnaryPlus:
|
case ExpCompile.KeyWord.UnaryPlus:
|
||||||
node = ExpUnaryOperatorNode.UnaryPlus( operand );
|
node = ExpUnaryOperatorNode.UnaryPlus( t, operand );
|
||||||
return true;
|
return true;
|
||||||
case ExpCompile.KeyWord.UnaryMinus:
|
case ExpCompile.KeyWord.UnaryMinus:
|
||||||
node = ExpUnaryOperatorNode.UnaryMinus( operand );
|
node = ExpUnaryOperatorNode.UnaryMinus( t, operand );
|
||||||
return true;
|
return true;
|
||||||
case ExpCompile.KeyWord.NOT:
|
case ExpCompile.KeyWord.NOT:
|
||||||
node = ExpUnaryOperatorNode.UnaryNot( operand );
|
node = ExpUnaryOperatorNode.UnaryNot( t, operand );
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
node = ExpNode.Empty;
|
node = ExpNode.Empty;
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ namespace StgSharp.Script.Express
|
|||||||
_cache.PushOperand( expToken );
|
_cache.PushOperand( expToken );
|
||||||
break;
|
break;
|
||||||
case TokenFlag.Separator_Single: //a , ; found
|
case TokenFlag.Separator_Single: //a , ; found
|
||||||
//if operator stack is not empty, convert all operators to node until meet a separator
|
// if operator stack is not empty, convert all operators to node until meet a same separator
|
||||||
|
// or OperandAheadOfSeparator property is less than certain value
|
||||||
break;
|
break;
|
||||||
case TokenFlag.Separator_Left: //a ( [ { found
|
case TokenFlag.Separator_Left: //a ( [ { found
|
||||||
_cache.PushOperator( expToken );
|
_cache.PushOperator( expToken );
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+df321a3bae3d97d043473f4595cc8d229d0f2722")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6f494f25eff44526a1e002d5ebeab8cf7b86a51d")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/df321a3bae3d97d043473f4595cc8d229d0f2722/*"}}
|
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/6f494f25eff44526a1e002d5ebeab8cf7b86a51d/*"}}
|
||||||
Reference in New Issue
Block a user