Daily update on 20250303-043627 by Nitload Youmu. Additional Message : remove node dependency to context, node instance ctor switched to factory mode,
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -37,7 +37,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public abstract class ExpCollectionBase : ExpInstantiableElementBase, IEnumerable<ExpElementInstanceBase>
|
public abstract class ExpCollectionBase : ExpInstantiableElement, IEnumerable<ExpElementInstanceBase>
|
||||||
{
|
{
|
||||||
|
|
||||||
protected internal string _accurateType;
|
protected internal string _accurateType;
|
||||||
@@ -69,7 +69,7 @@ namespace StgSharp.Script.Express
|
|||||||
public abstract IEnumerator<ExpElementInstanceBase> GetEnumerator();
|
public abstract IEnumerator<ExpElementInstanceBase> GetEnumerator();
|
||||||
|
|
||||||
public override sealed bool IsConvertable(
|
public override sealed bool IsConvertable(
|
||||||
ExpInstantiableElementBase targetType )
|
ExpInstantiableElement targetType )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public override string Name => ExpCompile.PoolString( "ARRAY" );
|
public override string Name => ExpCompile.PoolString( "ARRAY" );
|
||||||
|
|
||||||
public override ExpBaseNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public override string Name => ExpCompile.PoolString( "BAG" );
|
public override string Name => ExpCompile.PoolString( "BAG" );
|
||||||
|
|
||||||
public override ExpBaseNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public override string Name => ExpCompile.PoolString( "LIST" );
|
public override string Name => ExpCompile.PoolString( "LIST" );
|
||||||
|
|
||||||
public override ExpBaseNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ namespace StgSharp.Script.Express
|
|||||||
_collection.Add( token );
|
_collection.Add( token );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,18 +34,14 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public abstract class ExpCollectionInstanceBase : ExpBaseNode
|
public abstract class ExpCollectionInstanceBase : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
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, ExpSchema context )
|
protected ExpCollectionInstanceBase( string name, ExpSchema context )
|
||||||
: base( name, context ) { }
|
: base( name ) { }
|
||||||
|
|
||||||
public override ExpBaseNode Left => null!;
|
|
||||||
|
|
||||||
public override ExpBaseNode Right => null!;
|
|
||||||
|
|
||||||
public abstract ExpCollectionBase CollectionValue
|
public abstract ExpCollectionBase CollectionValue
|
||||||
{
|
{
|
||||||
@@ -57,6 +53,10 @@ namespace StgSharp.Script.Express
|
|||||||
get => _memberType;
|
get => _memberType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override ExpNode Left => null!;
|
||||||
|
|
||||||
|
public override ExpNode Right => null!;
|
||||||
|
|
||||||
public int MinCapacity => _range.min;
|
public int MinCapacity => _range.min;
|
||||||
|
|
||||||
public int MaxCapacity => _range.max;
|
public int MaxCapacity => _range.max;
|
||||||
@@ -69,14 +69,14 @@ namespace StgSharp.Script.Express
|
|||||||
private ExpSet _collection;
|
private ExpSet _collection;
|
||||||
|
|
||||||
public ExpSetInstance( string name, ExpSet set, ExpSchema context )
|
public ExpSetInstance( string name, ExpSet set, ExpSchema context )
|
||||||
: base( name, context )
|
: base( name )
|
||||||
{
|
{
|
||||||
_collection = set;
|
_collection = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpCollectionBase CollectionValue => _collection;
|
public override ExpCollectionBase CollectionValue => _collection;
|
||||||
|
|
||||||
public override ExpInstantiableElementBase EqualityTypeConvert => throw new NotImplementedException(
|
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -87,14 +87,14 @@ namespace StgSharp.Script.Express
|
|||||||
private ExpBag _collection;
|
private ExpBag _collection;
|
||||||
|
|
||||||
public ExpBagInstance( string name, ExpBag bag, ExpSchema context )
|
public ExpBagInstance( string name, ExpBag bag, ExpSchema context )
|
||||||
: base( name, context )
|
: base( name )
|
||||||
{
|
{
|
||||||
_collection = bag;
|
_collection = bag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpCollectionBase CollectionValue => _collection;
|
public override ExpCollectionBase CollectionValue => _collection;
|
||||||
|
|
||||||
public override ExpInstantiableElementBase EqualityTypeConvert => throw new NotImplementedException(
|
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -105,14 +105,14 @@ namespace StgSharp.Script.Express
|
|||||||
private ExpList _collection;
|
private ExpList _collection;
|
||||||
|
|
||||||
public ExpListInstance( string name, ExpList list, ExpSchema context )
|
public ExpListInstance( string name, ExpList list, ExpSchema context )
|
||||||
: base( name, context )
|
: base( name )
|
||||||
{
|
{
|
||||||
_collection = list;
|
_collection = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpCollectionBase CollectionValue => _collection;
|
public override ExpCollectionBase CollectionValue => _collection;
|
||||||
|
|
||||||
public override ExpInstantiableElementBase EqualityTypeConvert => throw new NotImplementedException(
|
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -126,14 +126,14 @@ namespace StgSharp.Script.Express
|
|||||||
string name,
|
string name,
|
||||||
ExpArray array,
|
ExpArray array,
|
||||||
ExpSchema context )
|
ExpSchema context )
|
||||||
: base( name, context )
|
: base( name )
|
||||||
{
|
{
|
||||||
_collection = array;
|
_collection = array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpCollectionBase CollectionValue => _collection;
|
public override ExpCollectionBase CollectionValue => _collection;
|
||||||
|
|
||||||
public override ExpInstantiableElementBase EqualityTypeConvert => _collection;
|
public override ExpInstantiableElement EqualityTypeConvert => _collection;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public sealed class ExpConstantCollectionSource : ExpImmutableElementBase
|
public sealed class ExpConstantCollectionSource : ExpImmutableElement
|
||||||
{
|
{
|
||||||
|
|
||||||
private Dictionary<string, ExpElementInstanceBase> _constants;
|
private Dictionary<string, ExpElementInstanceBase> _constants;
|
||||||
@@ -66,7 +66,7 @@ namespace StgSharp.Script.Express
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode MakeReference( params object[] options )
|
public override ExpNode MakeReference( params object[] options )
|
||||||
{
|
{
|
||||||
if( options.Length == 0 || options[ 0 ] is not string str ) {
|
if( options.Length == 0 || options[ 0 ] is not string str ) {
|
||||||
return null!;
|
return null!;
|
||||||
|
|||||||
@@ -34,25 +34,24 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpEntity : ExpBaseNode
|
public class ExpEntity : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
public ExpEntity( string name, ExpSchema context )
|
public ExpEntity( string name, ExpSchema context ) : base( name ) { }
|
||||||
: base( name, context ) { }
|
|
||||||
|
|
||||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
public override ExpNode Left => throw new NotImplementedException();
|
||||||
|
|
||||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
public override ExpNode Right => throw new NotImplementedException();
|
||||||
|
|
||||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExpEntitySource : ExpInstantiableElementBase
|
public class ExpEntitySource : ExpInstantiableElement
|
||||||
{
|
{
|
||||||
|
|
||||||
private AbstractSyntaxTree<ExpBaseNode, IExpElementSource> _expressionTree;
|
private AbstractSyntaxTree<ExpNode, IExpElementSource> _expressionTree;
|
||||||
private ScriptSourceTransmitter _source;
|
private ScriptSourceTransmitter _source;
|
||||||
private string _name;
|
private string _name;
|
||||||
|
|
||||||
@@ -73,12 +72,7 @@ namespace StgSharp.Script.Express
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode()
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool IsConvertable( IExpElementSource targetType )
|
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,32 +34,31 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpFunction : ExpBaseNode
|
public class ExpFunction : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ExpBaseNode _return;
|
|
||||||
|
|
||||||
private ExpFunctionSource _source;
|
private ExpFunctionSource _source;
|
||||||
private readonly List<KeyValuePair<string, ExpBaseNode>> _parameterList
|
|
||||||
= new List<KeyValuePair<string, ExpBaseNode>>();
|
|
||||||
|
|
||||||
public ExpFunction( string name, ExpSchema context )
|
private readonly ExpNode _return;
|
||||||
: base( name, context ) { }
|
private readonly List<KeyValuePair<string, ExpNode>> _parameterList
|
||||||
|
= new List<KeyValuePair<string, ExpNode>>();
|
||||||
|
|
||||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
public ExpFunction( string name, ExpSchema context ) : base( name ) { }
|
||||||
|
|
||||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public ExpElementType ElementType => ExpElementType.Function;
|
public ExpElementType ElementType => ExpElementType.Function;
|
||||||
|
|
||||||
public override ExpInstantiableElementBase EqualityTypeConvert => throw new NotImplementedException(
|
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||||
);
|
);
|
||||||
|
|
||||||
public void CallThisFunction( params ExpBaseNode[] parameters ) { }
|
public override ExpNode Left => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public override ExpNode Right => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public void CallThisFunction( params ExpNode[] parameters ) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExpFunctionSource : ExpImmutableElementBase
|
public class ExpFunctionSource : ExpImmutableElement
|
||||||
{
|
{
|
||||||
|
|
||||||
private ScriptSourceTransmitter _transmitter;
|
private ScriptSourceTransmitter _transmitter;
|
||||||
@@ -95,7 +94,7 @@ namespace StgSharp.Script.Express
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode MakeReference( params object[] options )
|
public override ExpNode MakeReference( params object[] options )
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,23 +41,22 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
private ExpRuleSource _source;
|
private ExpRuleSource _source;
|
||||||
|
|
||||||
public ExpRule( string name, ExpSchema context )
|
public ExpRule( string name, ExpSchema context ) : base( name ) { }
|
||||||
: base( name, context ) { }
|
|
||||||
|
|
||||||
public object? value => throw new NotImplementedException();
|
public object? value => throw new NotImplementedException();
|
||||||
|
|
||||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||||
|
|
||||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public override ExpInstantiableElementBase EqualityTypeConvert => throw new NotImplementedException(
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public override ExpNode Left => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public override ExpNode Right => throw new NotImplementedException();
|
||||||
|
|
||||||
public override string TypeName => _source.Name;
|
public override string TypeName => _source.Name;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExpRuleSource : ExpImmutableElementBase
|
public class ExpRuleSource : ExpImmutableElement
|
||||||
{
|
{
|
||||||
|
|
||||||
private ScriptSourceTransmitter _transmitter;
|
private ScriptSourceTransmitter _transmitter;
|
||||||
@@ -80,7 +79,7 @@ namespace StgSharp.Script.Express
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode MakeReference( params object[] options )
|
public override ExpNode MakeReference( params object[] options )
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,19 +35,18 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpType : ExpElementInstanceBase
|
public class ExpTypeInstance : ExpElementInstanceBase
|
||||||
{
|
{
|
||||||
|
|
||||||
public ExpType( string name, ExpSchema context )
|
public ExpTypeInstance( string name ) : base( name ) { }
|
||||||
: base( name, context ) { }
|
|
||||||
|
|
||||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||||
|
|
||||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public override IExpElementSource 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 override string TypeName => throw new NotImplementedException();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -80,6 +79,11 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public ExpElementType ElementType => ExpElementType.Type;
|
public ExpElementType ElementType => ExpElementType.Type;
|
||||||
|
|
||||||
|
public ExpTypeSource Void
|
||||||
|
{
|
||||||
|
get => ExpVoidType.Only;
|
||||||
|
}
|
||||||
|
|
||||||
public IScriptSourceProvider SourceProvider => _transmitter;
|
public IScriptSourceProvider SourceProvider => _transmitter;
|
||||||
|
|
||||||
public string Name => _name;
|
public string Name => _name;
|
||||||
@@ -94,5 +98,30 @@ namespace StgSharp.Script.Express
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsNullOrVoid( IExpElementSource type )
|
||||||
|
{
|
||||||
|
return type == null || type == ExpVoidType.Only;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ExpVoidType : ExpTypeSource
|
||||||
|
{
|
||||||
|
|
||||||
|
private static readonly ExpVoidType _onlyInstance = new ExpVoidType(
|
||||||
|
);
|
||||||
|
|
||||||
|
private ExpVoidType() : base( string.Empty ) { }
|
||||||
|
|
||||||
|
public static ExpVoidType Only
|
||||||
|
{
|
||||||
|
get => _onlyInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Analyse()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,40 +37,23 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpBinaryOperatorNode : ExpBaseNode
|
public class ExpBinaryOperatorNode : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
private ExpBaseNode _left;
|
private ExpInstantiableElement _returnType;
|
||||||
private ExpBaseNode _right;
|
|
||||||
private ExpInstantiableElementBase _returnType;
|
|
||||||
|
|
||||||
public ExpBinaryOperatorNode( string name ) : base( name, null! ) { }
|
private ExpNode _left;
|
||||||
|
private ExpNode _right;
|
||||||
|
|
||||||
public ExpBinaryOperatorNode(
|
private ExpBinaryOperatorNode( string name ) : base( name ) { }
|
||||||
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 ExpInstantiableElement EqualityTypeConvert => _returnType;
|
||||||
|
|
||||||
public override ExpBaseNode Right => _right;
|
public override ExpNode Left => _left;
|
||||||
|
|
||||||
public override ExpInstantiableElementBase EqualityTypeConvert => _returnType;
|
public override ExpNode Right => _right;
|
||||||
|
|
||||||
public static ExpBinaryOperatorNode Add(
|
public static ExpBinaryOperatorNode Add( ExpNode left, ExpNode right )
|
||||||
ExpBaseNode left,
|
|
||||||
ExpBaseNode right )
|
|
||||||
{
|
{
|
||||||
if( !left.IsNumber && !right.IsNumber ) {
|
if( !left.IsNumber && !right.IsNumber ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
@@ -88,8 +71,8 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ExpBinaryOperatorNode Assign(
|
public static ExpBinaryOperatorNode Assign(
|
||||||
ExpBaseNode left,
|
ExpNode left,
|
||||||
ExpBaseNode right )
|
ExpNode right )
|
||||||
{
|
{
|
||||||
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
|
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
@@ -98,15 +81,13 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.Assignment )
|
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.Assignment )
|
||||||
{
|
{
|
||||||
_returnType = ExpTypeSource.,
|
_returnType = ExpInstantiableElement.Void,
|
||||||
_nodeFlag = ExpNodeFlag.Operator_Binary | left._nodeFlag,
|
_nodeFlag = ExpNodeFlag.Operator_Binary | left._nodeFlag,
|
||||||
CodeConvertTemplate = "{0} & {1}",
|
CodeConvertTemplate = "{0} & {1}",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpBinaryOperatorNode Div(
|
public static ExpBinaryOperatorNode Div( ExpNode left, ExpNode right )
|
||||||
ExpBaseNode left,
|
|
||||||
ExpBaseNode right )
|
|
||||||
{
|
{
|
||||||
if( !left.IsNumber && !right.IsNumber ) {
|
if( !left.IsNumber && !right.IsNumber ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
@@ -123,9 +104,7 @@ namespace StgSharp.Script.Express
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpBinaryOperatorNode Mul(
|
public static ExpBinaryOperatorNode Mul( ExpNode left, ExpNode right )
|
||||||
ExpBaseNode left,
|
|
||||||
ExpBaseNode right )
|
|
||||||
{
|
{
|
||||||
if( !left.IsNumber && !right.IsNumber ) {
|
if( !left.IsNumber && !right.IsNumber ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
@@ -142,9 +121,7 @@ namespace StgSharp.Script.Express
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpBinaryOperatorNode Sub(
|
public static ExpBinaryOperatorNode Sub( ExpNode left, ExpNode right )
|
||||||
ExpBaseNode left,
|
|
||||||
ExpBaseNode right )
|
|
||||||
{
|
{
|
||||||
if( !left.IsNumber && !right.IsNumber ) {
|
if( !left.IsNumber && !right.IsNumber ) {
|
||||||
throw new ExpInvalidTypeException(
|
throw new ExpInvalidTypeException(
|
||||||
|
|||||||
@@ -36,32 +36,33 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
internal class ExpFunctionCallingNode : ExpBaseNode
|
internal class ExpFunctionCallingNode : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
private ExpBaseNode _parameter;
|
|
||||||
private ExpFunctionSource _function;
|
private ExpFunctionSource _function;
|
||||||
|
|
||||||
|
private ExpNode _parameter;
|
||||||
|
|
||||||
public ExpFunctionCallingNode(
|
public ExpFunctionCallingNode(
|
||||||
string functionName,
|
ExpFunctionSource function,
|
||||||
int line,
|
ExpNode firstParameter )
|
||||||
int column,
|
: base( $"{function.Name}_call" )
|
||||||
ExpSchema context,
|
|
||||||
ExpBaseNode firstParameter )
|
|
||||||
: base( $"{functionName}_{line}_{column}", context )
|
|
||||||
{
|
{
|
||||||
|
_function = function;
|
||||||
_parameter = firstParameter;
|
_parameter = firstParameter;
|
||||||
if( !context.TryGetFunction( functionName, out _function ) ) {
|
|
||||||
foreach( var item in context. ) { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
|
||||||
|
|
||||||
public override ExpBaseNode Right => _parameter;
|
|
||||||
|
|
||||||
public override ExpInstantiableElementBase EqualityTypeConvert => throw new NotImplementedException(
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public override ExpNode Left => Empty;
|
||||||
|
|
||||||
|
public override ExpNode Right => _parameter;
|
||||||
|
|
||||||
|
public void AppendParameter( ExpNode parameter )
|
||||||
|
{
|
||||||
|
_parameter.AppendNode( parameter );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,41 +36,46 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public sealed class ExpIfNode : ExpBaseNode
|
public sealed class ExpIfNode : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
private ExpBaseNode _falseOpBegin;
|
private ExpNode _falseOpBegin;
|
||||||
private ExpBaseNode _rule;
|
private ExpNode _rule;
|
||||||
private ExpBaseNode _trueOpBegin ;
|
private ExpNode _trueOpBegin ;
|
||||||
|
|
||||||
public ExpIfNode(
|
public ExpIfNode(
|
||||||
string name,
|
string name,
|
||||||
ExpSchema context,
|
ExpSchema context,
|
||||||
ExpBaseNode rule,
|
ExpNode rule,
|
||||||
ExpBaseNode rootOperationIfTrue,
|
ExpNode rootOperationIfTrue,
|
||||||
ExpBaseNode rootOperationIfFalse )
|
ExpNode rootOperationIfFalse )
|
||||||
: base( name, context )
|
: base( name )
|
||||||
{
|
{
|
||||||
_rule = rule;
|
_rule = rule;
|
||||||
_trueOpBegin = rootOperationIfFalse;
|
_trueOpBegin = rootOperationIfFalse;
|
||||||
_falseOpBegin = rootOperationIfFalse;
|
_falseOpBegin = rootOperationIfFalse;
|
||||||
|
CodeConvertTemplate = """
|
||||||
|
if( {0} ) {
|
||||||
|
{1}
|
||||||
|
} else {
|
||||||
|
{2}
|
||||||
|
}
|
||||||
|
""";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode Left => _trueOpBegin;
|
public override ExpNode Left => _trueOpBegin;
|
||||||
|
|
||||||
public override ExpBaseNode Right => _falseOpBegin;
|
public override ExpNode Right => _falseOpBegin;
|
||||||
|
|
||||||
public override IExpElementSource EqualityTypeConvert => null!;
|
public override IExpElementSource EqualityTypeConvert => null!;
|
||||||
|
|
||||||
public void AppendFalseOperation( ExpBaseNode expressionRoot )
|
public void AppendFalseOperation( ExpNode expressionRoot )
|
||||||
{
|
{
|
||||||
AssertSchemaInclude( expressionRoot );
|
|
||||||
_falseOpBegin.AppendNode( expressionRoot );
|
_falseOpBegin.AppendNode( expressionRoot );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AppendTrueOperation( ExpBaseNode expressionRoot )
|
public void AppendTrueOperation( ExpNode expressionRoot )
|
||||||
{
|
{
|
||||||
AssertSchemaInclude( expressionRoot );
|
|
||||||
_trueOpBegin.AppendNode( expressionRoot );
|
_trueOpBegin.AppendNode( expressionRoot );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,29 +36,29 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpIndexOfNode : ExpBaseNode
|
public class ExpIndexOfNode : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
private ExpBaseNode _indexExpression;
|
|
||||||
|
|
||||||
private ExpCollectionInstanceBase _collection;
|
private ExpCollectionInstanceBase _collection;
|
||||||
|
|
||||||
|
private ExpNode _indexExpression;
|
||||||
|
|
||||||
public ExpIndexOfNode(
|
public ExpIndexOfNode(
|
||||||
ExpSchema context,
|
ExpSchema context,
|
||||||
ExpCollectionInstanceBase instance,
|
ExpCollectionInstanceBase instance,
|
||||||
ExpBaseNode indexExpression )
|
ExpNode indexExpression )
|
||||||
: base( ExpCompile.PoolString( "[" ), context )
|
: base( ExpCompile.PoolString( "[" ) )
|
||||||
{
|
{
|
||||||
_collection = instance;
|
_collection = instance;
|
||||||
_indexExpression = indexExpression;
|
_indexExpression = indexExpression;
|
||||||
|
CodeConvertTemplate = @"{0}[{1}]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode Left => _collection;
|
public override ExpNode Left => _collection;
|
||||||
|
|
||||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
public override ExpNode Right => _indexExpression;
|
||||||
|
|
||||||
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
|
public override IExpElementSource EqualityTypeConvert => _collection.EqualityTypeConvert;
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace StgSharp.Script.Express
|
|||||||
private readonly T _value;
|
private readonly T _value;
|
||||||
|
|
||||||
public ExpLiteralGenericNode( string name, ExpSchema context, T value )
|
public ExpLiteralGenericNode( string name, ExpSchema context, T value )
|
||||||
: base( name, context )
|
: base( name )
|
||||||
{
|
{
|
||||||
_value = value;
|
_value = value;
|
||||||
switch( value ) {
|
switch( value ) {
|
||||||
@@ -93,9 +93,9 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode Left => Empty;
|
public override ExpNode Left => Empty;
|
||||||
|
|
||||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
public override ExpNode Right => throw new NotImplementedException();
|
||||||
|
|
||||||
public override IExpElementSource EqualityTypeConvert => _type;
|
public override IExpElementSource EqualityTypeConvert => _type;
|
||||||
|
|
||||||
|
|||||||
@@ -36,22 +36,24 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpRepeatToken : ExpBaseNode
|
public class ExpRepeatToken : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
private ExpBaseNode _operationBegin;
|
//TODO: Current code cannot represent full functionality defined in ISO10303, need rewrite.
|
||||||
|
|
||||||
private ExpElementInstanceBase _variable, _begin, _end, _increment;
|
private ExpElementInstanceBase _variable, _begin, _end, _increment;
|
||||||
|
|
||||||
|
private ExpNode _operationBegin;
|
||||||
|
|
||||||
public ExpRepeatToken(
|
public ExpRepeatToken(
|
||||||
string name,
|
string name,
|
||||||
ExpSchema context,
|
ExpSchema context,
|
||||||
ExpBaseNode operationBegin,
|
ExpNode operationBegin,
|
||||||
ExpElementInstanceBase variable,
|
ExpElementInstanceBase variable,
|
||||||
ExpElementInstanceBase begin,
|
ExpElementInstanceBase begin,
|
||||||
ExpElementInstanceBase end,
|
ExpElementInstanceBase end,
|
||||||
ExpElementInstanceBase increment )
|
ExpElementInstanceBase increment )
|
||||||
: base( name, context )
|
: base( name )
|
||||||
{
|
{
|
||||||
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 !=
|
||||||
@@ -81,13 +83,13 @@ namespace StgSharp.Script.Express
|
|||||||
_operationBegin = operationBegin;
|
_operationBegin = operationBegin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
public override ExpNode Left => throw new NotImplementedException();
|
||||||
|
|
||||||
public override ExpBaseNode Right => _operationBegin;
|
public override ExpNode Right => _operationBegin;
|
||||||
|
|
||||||
public override IExpElementSource EqualityTypeConvert => null!;
|
public override IExpElementSource EqualityTypeConvert => null!;
|
||||||
|
|
||||||
public void AppendRepeatedOperation( ExpBaseNode node )
|
public void AppendRepeatedOperation( ExpNode node )
|
||||||
{
|
{
|
||||||
_operationBegin.AppendNode( node );
|
_operationBegin.AppendNode( node );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,25 +34,25 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpSwitchNode : ExpBaseNode
|
public class ExpSwitchNode : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
private Dictionary<ExpBaseNode, ExpBaseNode> _cases;
|
private Dictionary<ExpNode, ExpNode> _cases;
|
||||||
private ExpBaseNode _default;
|
private ExpNode _default;
|
||||||
private ExpBaseNode _target;
|
private ExpNode _target;
|
||||||
|
|
||||||
public ExpSwitchNode(
|
public ExpSwitchNode(
|
||||||
string name,
|
string name,
|
||||||
ExpSchema context,
|
ExpSchema context,
|
||||||
ExpBaseNode target,
|
ExpNode target,
|
||||||
ExpBaseNode defaultCase,
|
ExpNode defaultCase,
|
||||||
params (ExpBaseNode label, ExpBaseNode op)[] cases )
|
params (ExpNode label, ExpNode op)[] cases )
|
||||||
: base( name, context )
|
: base( name )
|
||||||
{
|
{
|
||||||
_target = target;
|
_target = target;
|
||||||
_default = defaultCase;
|
_default = defaultCase;
|
||||||
_cases = new Dictionary<ExpBaseNode, ExpBaseNode>();
|
_cases = new Dictionary<ExpNode, ExpNode>();
|
||||||
foreach( (ExpBaseNode label, ExpBaseNode op ) item in cases ) {
|
foreach( (ExpNode label, ExpNode op ) item in cases ) {
|
||||||
if( item.op == null ) {
|
if( item.op == null ) {
|
||||||
_cases.Add( item.label, null! );
|
_cases.Add( item.label, null! );
|
||||||
} else {
|
} else {
|
||||||
@@ -61,24 +61,24 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpBaseNode this[ ExpBaseNode index ]
|
public ExpNode this[ ExpNode index ]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if( _cases.TryGetValue( index, out ExpBaseNode? ret ) ) {
|
if( _cases.TryGetValue( index, out ExpNode? ret ) ) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return _default;
|
return _default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode Left => throw new NotImplementedException();
|
public override ExpNode Left => throw new NotImplementedException();
|
||||||
|
|
||||||
public override ExpBaseNode Right => throw new NotImplementedException();
|
public override ExpNode Right => throw new NotImplementedException();
|
||||||
|
|
||||||
public override IExpElementSource EqualityTypeConvert => null!;
|
public override IExpElementSource EqualityTypeConvert => null!;
|
||||||
|
|
||||||
public void AddOperationToDefault( ExpBaseNode expressionRoot )
|
public void AddOperationToDefault( ExpNode expressionRoot )
|
||||||
{
|
{
|
||||||
if( expressionRoot != null ) {
|
if( expressionRoot != null ) {
|
||||||
_default.AppendNode( expressionRoot );
|
_default.AppendNode( expressionRoot );
|
||||||
@@ -93,18 +93,17 @@ namespace StgSharp.Script.Express
|
|||||||
/// <param name="expressionRoot"> Root token of the expression to be added. </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>
|
/// <exception cref="ExpCaseNotFoundException"> Cannot fine the case label in current witch expression. </exception>
|
||||||
public void AppendOperationToCase(
|
public void AppendOperationToCase(
|
||||||
ExpBaseNode label,
|
ExpNode label,
|
||||||
ExpBaseNode expressionRoot )
|
ExpNode expressionRoot )
|
||||||
{
|
{
|
||||||
AssertSchemaInclude( expressionRoot );
|
if( _cases.TryGetValue( label, out ExpNode? op ) ) {
|
||||||
if( _cases.TryGetValue( label, out ExpBaseNode? op ) ) {
|
|
||||||
op.AppendNode( expressionRoot );
|
op.AppendNode( expressionRoot );
|
||||||
} else {
|
} else {
|
||||||
throw new ExpCaseNotFoundException( this, label );
|
throw new ExpCaseNotFoundException( this, label );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ContainsCase( ExpBaseNode token )
|
public bool ContainsCase( ExpNode token )
|
||||||
{
|
{
|
||||||
return _cases.ContainsKey( token );
|
return _cases.ContainsKey( token );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,25 +36,42 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpUnaryOperatorNode : ExpBaseNode
|
public class ExpUnaryOperatorNode : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
private ExpBaseNode _operand;
|
private ExpNode _operand;
|
||||||
|
|
||||||
|
private ExpUnaryOperatorNode( string name ) : base( name ) { }
|
||||||
|
|
||||||
public ExpUnaryOperatorNode(
|
public ExpUnaryOperatorNode(
|
||||||
string name,
|
string name,
|
||||||
ExpBaseNode operand,
|
ExpNode operand,
|
||||||
ExpSchema context )
|
ExpSchema context )
|
||||||
: base( name, context )
|
: base( name )
|
||||||
{
|
{
|
||||||
_operand = operand;
|
_operand = operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode Left => null!;
|
public override ExpNode Left => null!;
|
||||||
|
|
||||||
public override ExpBaseNode Right => _operand;
|
public override ExpNode Right => _operand;
|
||||||
|
|
||||||
public override IExpElementSource EqualityTypeConvert => _operand.EqualityTypeConvert;
|
public override IExpElementSource EqualityTypeConvert => _operand.EqualityTypeConvert;
|
||||||
|
|
||||||
|
public static ExpUnaryOperatorNode UnaryNotNegation( ExpNode operand )
|
||||||
|
{
|
||||||
|
if( !operand.IsNumber ) {
|
||||||
|
throw new ExpInvalidTypeException(
|
||||||
|
"Number", operand.EqualityTypeConvert.Name );
|
||||||
|
}
|
||||||
|
bool isFloat =
|
||||||
|
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Float ) == 0;
|
||||||
|
return new ExpUnaryOperatorNode( ExpCompile.KeyWord.SUB )
|
||||||
|
{
|
||||||
|
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Number,
|
||||||
|
CodeConvertTemplate = "- {0}",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
//-----------------------------------------------------------------------
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// file="_ExpNode.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 ExpNode : IASTNode<ExpNode, IExpElementSource>
|
||||||
|
{
|
||||||
|
|
||||||
|
protected internal ExpNodeFlag _nodeFlag;
|
||||||
|
protected internal string _name;
|
||||||
|
|
||||||
|
protected ExpNode( string name )
|
||||||
|
{
|
||||||
|
_name = name;
|
||||||
|
Next = this;
|
||||||
|
Previous = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsNumber
|
||||||
|
{
|
||||||
|
get { return ( _nodeFlag | ExpNodeFlag.BuiltinType_Number ) != 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract ExpNode Left
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExpNode Empty
|
||||||
|
{
|
||||||
|
get => ExpEmptyNode._only;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpNode Next
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract ExpNode Right
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpNode Previous
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract IExpElementSource EqualityTypeConvert
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long NodeFlag => ( long )_nodeFlag;
|
||||||
|
|
||||||
|
public string CodeConvertTemplate
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name => _name;
|
||||||
|
|
||||||
|
public virtual void AppendNode( ExpNode nextToken )
|
||||||
|
{
|
||||||
|
Next.Previous = nextToken;
|
||||||
|
nextToken.Next = Next;
|
||||||
|
Next = nextToken;
|
||||||
|
Next.Previous = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpNodeNextEnumerator GetEnumerator()
|
||||||
|
{
|
||||||
|
return new ExpNodeNextEnumerator( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsNullOrEmpty( ExpNode node )
|
||||||
|
{
|
||||||
|
return node == ExpEmptyNode._only || node == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool VerifyTypeConvertable( ExpNode left, ExpNode right )
|
||||||
|
{
|
||||||
|
IExpElementSource tLeft = left.EqualityTypeConvert,
|
||||||
|
tRight = right.EqualityTypeConvert;
|
||||||
|
if( tLeft == null || tRight == null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return tLeft.IsConvertable( tRight );
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ExpEmptyNode : ExpNode
|
||||||
|
{
|
||||||
|
|
||||||
|
internal static readonly ExpEmptyNode _only = new();
|
||||||
|
|
||||||
|
public ExpEmptyNode() : base( string.Empty ) { }
|
||||||
|
|
||||||
|
public override ExpInstantiableElement EqualityTypeConvert => ExpInstantiableElement.Void;
|
||||||
|
|
||||||
|
public override ExpNode Left => _only;
|
||||||
|
|
||||||
|
public override ExpNode Right => _only;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,11 +53,10 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class ExpElementInstanceBase : ExpBaseNode
|
public abstract class ExpElementInstanceBase : ExpNode
|
||||||
{
|
{
|
||||||
|
|
||||||
protected ExpElementInstanceBase( string name, ExpSchema context )
|
protected ExpElementInstanceBase( string name ) : base( name ) { }
|
||||||
: base( name, context ) { }
|
|
||||||
|
|
||||||
public ExpElementType ElementType
|
public ExpElementType ElementType
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,15 +58,19 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class ExpInstantiableElementBase : IExpElementSource
|
public abstract class ExpInstantiableElement : IExpElementSource
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private List<ExpInstantiableElement> _baseList = new List<ExpInstantiableElement>(
|
||||||
|
),
|
||||||
|
_derivationList = new List<ExpInstantiableElement>();
|
||||||
|
|
||||||
public abstract ExpElementType ElementType
|
public abstract ExpElementType ElementType
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExpInstantiableElementBase Void
|
public static ExpInstantiableElement Void
|
||||||
{
|
{
|
||||||
get => ExpVoidElement.Only;
|
get => ExpVoidElement.Only;
|
||||||
}
|
}
|
||||||
@@ -83,12 +87,22 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public abstract void Analyse();
|
public abstract void Analyse();
|
||||||
|
|
||||||
public abstract ExpBaseNode CreateInstanceNode();
|
public abstract ExpNode CreateInstanceNode();
|
||||||
|
|
||||||
public abstract bool IsConvertable(
|
public bool IsConvertable( IExpElementSource targetType )
|
||||||
ExpInstantiableElementBase targetType );
|
{
|
||||||
|
if( targetType == null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
private sealed class ExpVoidElement : ExpInstantiableElementBase
|
public static bool IsNullOrVoid( ExpInstantiableElement element )
|
||||||
|
{
|
||||||
|
return element == null || element == ExpVoidElement.Only;
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class ExpVoidElement : ExpInstantiableElement
|
||||||
{
|
{
|
||||||
|
|
||||||
private static readonly ExpVoidElement _only = new ExpVoidElement();
|
private static readonly ExpVoidElement _only = new ExpVoidElement();
|
||||||
@@ -106,22 +120,16 @@ namespace StgSharp.Script.Express
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ExpBaseNode CreateInstanceNode()
|
public override ExpNode CreateInstanceNode()
|
||||||
{
|
{
|
||||||
return default!;
|
return default!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsConvertable(
|
|
||||||
ExpInstantiableElementBase targetType )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class ExpImmutableElementBase : IExpElementSource
|
public abstract class ExpImmutableElement : IExpElementSource
|
||||||
{
|
{
|
||||||
|
|
||||||
public abstract ExpElementType ElementType
|
public abstract ExpElementType ElementType
|
||||||
@@ -146,7 +154,7 @@ namespace StgSharp.Script.Express
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract ExpBaseNode MakeReference( params object[] options );
|
public abstract ExpNode MakeReference( params object[] options );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,20 +30,14 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpCompileNotInitializedException : InvalidOperationException
|
|
||||||
{
|
|
||||||
|
|
||||||
public ExpCompileNotInitializedException()
|
|
||||||
: base(
|
|
||||||
"Attempt to compile an EXPRESS script before the init of compiler." ) { }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ExpInvalidCharException : Exception
|
public class ExpInvalidCharException : Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -52,6 +46,9 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Exception when cannot reading a token from a line.
|
||||||
|
/// </summary>
|
||||||
public class ExpInvalidTokenException : Exception
|
public class ExpInvalidTokenException : Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -60,10 +57,10 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExpInvalidTypeDeclareEndingExceptions : Exception
|
public class ExpInvalidElementDeclareEndingExceptions : Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
public ExpInvalidTypeDeclareEndingExceptions(
|
public ExpInvalidElementDeclareEndingExceptions(
|
||||||
string declaredName,
|
string declaredName,
|
||||||
string endedName )
|
string endedName )
|
||||||
: base(
|
: base(
|
||||||
@@ -91,6 +88,15 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ExpCaseNotFoundException : ArgumentOutOfRangeException
|
||||||
|
{
|
||||||
|
|
||||||
|
public ExpCaseNotFoundException( ExpSwitchNode token, ExpNode label )
|
||||||
|
: base(
|
||||||
|
$"Attempt to read or write the label {label.Name} not exist in SWITCH expression {token.Name}" ) { }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public class ExpInvalidCollectionMemberTypeException : InvalidCastException
|
public class ExpInvalidCollectionMemberTypeException : InvalidCastException
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -109,27 +115,25 @@ namespace StgSharp.Script.Express
|
|||||||
ExpSchema context,
|
ExpSchema context,
|
||||||
ExpSchema source )
|
ExpSchema source )
|
||||||
: base(
|
: base(
|
||||||
$"Attempted to reference an EXPRESS language expression in the current schema context '{context.Name}', " + $"but this expression comes from another schema '{source.Name}' that has not been included." ) { }
|
$"Attempted to refer to an EXPRESS language expression in the current schema context '{context.Name}', but this expression comes from another schema '{source.Name}' that has not been included." ) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExpCaseNotFoundException : ArgumentOutOfRangeException
|
public class ExpElementLoadException : TypeLoadException
|
||||||
{
|
{
|
||||||
|
|
||||||
public ExpCaseNotFoundException(
|
public ExpElementLoadException( string typeName, ExpSchema context )
|
||||||
ExpSwitchNode token,
|
|
||||||
ExpBaseNode label )
|
|
||||||
: base(
|
: base(
|
||||||
$"Attempt to read or write the label {label.Name} not exist in SWITCH expression {token.Name}" ) { }
|
$"Cannot find the element {typeName} in schema {context.Name} and its included schemas" ) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExpTypeNotFoundException : Exception
|
public class ExpCompileNotInitializedException : InvalidOperationException
|
||||||
{
|
{
|
||||||
|
|
||||||
public ExpTypeNotFoundException( string typeName, ExpSchema context )
|
public ExpCompileNotInitializedException()
|
||||||
: base(
|
: base(
|
||||||
$"Cannot find the type {typeName} in schema {context.Name} and its included schemas" ) { }
|
"Attempt to compile an EXPRESS script before the init of compiler." ) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
string endedName = match.Groups[ "TypeName" ].ToString();
|
string endedName = match.Groups[ "TypeName" ].ToString();
|
||||||
if( !string.Equals( endedName, _source.Name ) ) {
|
if( !string.Equals( endedName, _source.Name ) ) {
|
||||||
throw new ExpInvalidTypeDeclareEndingExceptions(
|
throw new ExpInvalidElementDeclareEndingExceptions(
|
||||||
_source.Name, endedName );
|
_source.Name, endedName );
|
||||||
}
|
}
|
||||||
transmitter.WriteLine( "END_ENTITY" );
|
transmitter.WriteLine( "END_ENTITY" );
|
||||||
@@ -275,7 +275,7 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
string endedName = match.Groups[ "FunctionName" ].ToString();
|
string endedName = match.Groups[ "FunctionName" ].ToString();
|
||||||
if( !string.Equals( endedName, _source.Name ) ) {
|
if( !string.Equals( endedName, _source.Name ) ) {
|
||||||
throw new ExpInvalidTypeDeclareEndingExceptions(
|
throw new ExpInvalidElementDeclareEndingExceptions(
|
||||||
_source.Name, endedName );
|
_source.Name, endedName );
|
||||||
}
|
}
|
||||||
transmitter.WriteLine( "END_FUNCTION" );
|
transmitter.WriteLine( "END_FUNCTION" );
|
||||||
@@ -310,7 +310,7 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
string endedName = match.Groups[ "RuleName" ].ToString();
|
string endedName = match.Groups[ "RuleName" ].ToString();
|
||||||
if( !string.Equals( endedName, _source.Name ) ) {
|
if( !string.Equals( endedName, _source.Name ) ) {
|
||||||
throw new ExpInvalidTypeDeclareEndingExceptions(
|
throw new ExpInvalidElementDeclareEndingExceptions(
|
||||||
_source.Name, endedName );
|
_source.Name, endedName );
|
||||||
}
|
}
|
||||||
transmitter.WriteLine( "END_RULE" );
|
transmitter.WriteLine( "END_RULE" );
|
||||||
@@ -342,7 +342,7 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
string endedName = match.Groups[ "TypeName" ].ToString();
|
string endedName = match.Groups[ "TypeName" ].ToString();
|
||||||
if( !string.Equals( endedName, _source.Name ) ) {
|
if( !string.Equals( endedName, _source.Name ) ) {
|
||||||
throw new ExpInvalidTypeDeclareEndingExceptions(
|
throw new ExpInvalidElementDeclareEndingExceptions(
|
||||||
_source.Name, endedName );
|
_source.Name, endedName );
|
||||||
}
|
}
|
||||||
transmitter.WriteLine( "END_ENTITY" );
|
transmitter.WriteLine( "END_ENTITY" );
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ namespace StgSharp.Script.Express
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new ExpTypeNotFoundException( typeName, this );
|
throw new ExpElementLoadException( typeName, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasSchemaInclude( GeneratedExpSchema schema )
|
public bool HasSchemaInclude( GeneratedExpSchema schema )
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ namespace StgSharp.Script.Express
|
|||||||
private const int TokenGenerated = 0;
|
private const int TokenGenerated = 0;
|
||||||
private const int TokenTypeNotMatch = -1;
|
private const int TokenTypeNotMatch = -1;
|
||||||
|
|
||||||
private ExpBaseNode _lastStatement;
|
private ExpNode _lastStatement;
|
||||||
|
|
||||||
private GeneratedExpSchema _context;
|
private GeneratedExpSchema _context;
|
||||||
private IExpElementSource _local;
|
private IExpElementSource _local;
|
||||||
private List<ExpBaseNode> _cache;
|
private List<ExpNode> _cache;
|
||||||
private Stack<ExpBaseNode> _operandsNode;
|
private Stack<ExpNode> _operandsNode;
|
||||||
private Stack<Token> _operandsToken;
|
private Stack<Token> _operandsToken;
|
||||||
private Stack<Token> _operators;
|
private Stack<Token> _operators;
|
||||||
|
|
||||||
@@ -90,21 +90,21 @@ namespace StgSharp.Script.Express
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CacheNextOperandNode( ExpBaseNode node )
|
public void CacheNextOperandNode( ExpNode node )
|
||||||
{
|
{
|
||||||
_operandsNode.Push( node );
|
_operandsNode.Push( node );
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractSyntaxTree<ExpBaseNode, IExpElementSource> CloseAndDispose(
|
public AbstractSyntaxTree<ExpNode, IExpElementSource> CloseAndDispose(
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if( _operandsToken.Count != 0 ) {
|
if( _operandsToken.Count != 0 ) {
|
||||||
// convert rest to AST
|
// convert rest to AST
|
||||||
}
|
}
|
||||||
return new AbstractSyntaxTree<ExpBaseNode, IExpElementSource>();
|
return new AbstractSyntaxTree<ExpNode, IExpElementSource>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpBaseNode GenerateNode( Token t )
|
public ExpNode GenerateNode( Token t )
|
||||||
{
|
{
|
||||||
switch( t.Flag ) {
|
switch( t.Flag ) {
|
||||||
case TokenFlag.Symbol_Unary:
|
case TokenFlag.Symbol_Unary:
|
||||||
@@ -134,7 +134,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
public int GetNextOperandCache(
|
public int GetNextOperandCache(
|
||||||
out Token? token,
|
out Token? token,
|
||||||
out ExpBaseNode? node )
|
out ExpNode? node )
|
||||||
{
|
{
|
||||||
if( _operandsNode.Count != 0 ) {
|
if( _operandsNode.Count != 0 ) {
|
||||||
node = _operandsNode.Pop();
|
node = _operandsNode.Pop();
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace StgSharp.Script.Express
|
|||||||
public partial class ExpNodeGenerator
|
public partial class ExpNodeGenerator
|
||||||
{
|
{
|
||||||
|
|
||||||
public ExpBaseNode GenerateUnaryToken( Token t )
|
public ExpNode GenerateUnaryToken( Token t )
|
||||||
{
|
{
|
||||||
switch( t.Value ) {
|
switch( t.Value ) {
|
||||||
case ExpCompile.KeyWord.UnaryAdd:
|
case ExpCompile.KeyWord.UnaryAdd:
|
||||||
|
|||||||
@@ -37,13 +37,13 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace StgSharp.Script.Express
|
namespace StgSharp.Script.Express
|
||||||
{
|
{
|
||||||
public class ExpNodeNextEnumerator : IEnumerator<ExpBaseNode>
|
public class ExpNodeNextEnumerator : IEnumerator<ExpNode>
|
||||||
{
|
{
|
||||||
|
|
||||||
private ExpBaseNode _begin;
|
private ExpNode _begin;
|
||||||
private ExpBaseNode _current;
|
private ExpNode _current;
|
||||||
|
|
||||||
public ExpNodeNextEnumerator( ExpBaseNode token )
|
public ExpNodeNextEnumerator( ExpNode token )
|
||||||
{
|
{
|
||||||
_begin = token;
|
_begin = token;
|
||||||
_current = token;
|
_current = token;
|
||||||
@@ -56,7 +56,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
bool IEnumerator.MoveNext()
|
bool IEnumerator.MoveNext()
|
||||||
{
|
{
|
||||||
ExpBaseNode next = _current.Next;
|
ExpNode next = _current.Next;
|
||||||
if( ReferenceEquals( next, _begin ) || next == null ) {
|
if( ReferenceEquals( next, _begin ) || next == null ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ namespace StgSharp.Script.Express
|
|||||||
|
|
||||||
object IEnumerator.Current => throw new NotImplementedException();
|
object IEnumerator.Current => throw new NotImplementedException();
|
||||||
|
|
||||||
ExpBaseNode IEnumerator<ExpBaseNode>.Current => throw new NotImplementedException(
|
ExpNode IEnumerator<ExpNode>.Current => throw new NotImplementedException(
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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+b4b90da372efaff79c7c1c950ce22e7bb13223cb")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d12bbbd873ec13306fdfa5255965188674ed417c")]
|
||||||
[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")]
|
||||||
|
|||||||
@@ -28,8 +28,16 @@
|
|||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
using StgSharp.Graphics;
|
||||||
|
using StgSharp.HighPerformance;
|
||||||
|
|
||||||
|
using StgSharp.Internal;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp
|
namespace StgSharp
|
||||||
{
|
{
|
||||||
@@ -42,5 +50,23 @@ namespace StgSharp
|
|||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class NewRender : ViewRender<ViewMain>
|
||||||
|
{
|
||||||
|
|
||||||
|
public NewRender( ViewMain view ) : base( view ) { }
|
||||||
|
|
||||||
|
public override void CustomizedInitialize()
|
||||||
|
{
|
||||||
|
Binding.Stream = CreateRenderStream<ParticleRenderStream>();
|
||||||
|
Render[ "only".AsLabel() ] = Binding.Stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool ValidateInitializing()
|
||||||
|
{
|
||||||
|
return Binding.Stream != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user