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:
Nitload
2025-03-03 04:36:27 +08:00
parent d12bbbd873
commit 825e68853c
26 changed files with 440 additions and 238 deletions
@@ -37,7 +37,7 @@ using System.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpCollectionBase : ExpInstantiableElementBase, IEnumerable<ExpElementInstanceBase>
public abstract class ExpCollectionBase : ExpInstantiableElement, IEnumerable<ExpElementInstanceBase>
{
protected internal string _accurateType;
@@ -69,7 +69,7 @@ namespace StgSharp.Script.Express
public abstract IEnumerator<ExpElementInstanceBase> GetEnumerator();
public override sealed bool IsConvertable(
ExpInstantiableElementBase targetType )
ExpInstantiableElement targetType )
{
return false;
}
@@ -105,7 +105,7 @@ namespace StgSharp.Script.Express
public override string Name => ExpCompile.PoolString( "ARRAY" );
public override ExpBaseNode CreateInstanceNode()
public override ExpNode CreateInstanceNode()
{
throw new NotImplementedException();
}
@@ -130,7 +130,7 @@ namespace StgSharp.Script.Express
public override string Name => ExpCompile.PoolString( "BAG" );
public override ExpBaseNode CreateInstanceNode()
public override ExpNode CreateInstanceNode()
{
throw new NotImplementedException();
}
@@ -154,7 +154,7 @@ namespace StgSharp.Script.Express
public override string Name => ExpCompile.PoolString( "LIST" );
public override ExpBaseNode CreateInstanceNode()
public override ExpNode CreateInstanceNode()
{
throw new NotImplementedException();
}
@@ -186,7 +186,7 @@ namespace StgSharp.Script.Express
_collection.Add( token );
}
public override ExpBaseNode CreateInstanceNode()
public override ExpNode CreateInstanceNode()
{
throw new NotImplementedException();
}
@@ -34,18 +34,14 @@ using System.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpCollectionInstanceBase : ExpBaseNode
public abstract class ExpCollectionInstanceBase : ExpNode
{
protected internal (int min, int max) _range;
protected internal ExpElementType _memberType;
protected ExpCollectionInstanceBase( string name, ExpSchema context )
: base( name, context ) { }
public override ExpBaseNode Left => null!;
public override ExpBaseNode Right => null!;
: base( name ) { }
public abstract ExpCollectionBase CollectionValue
{
@@ -57,6 +53,10 @@ namespace StgSharp.Script.Express
get => _memberType;
}
public override ExpNode Left => null!;
public override ExpNode Right => null!;
public int MinCapacity => _range.min;
public int MaxCapacity => _range.max;
@@ -69,14 +69,14 @@ namespace StgSharp.Script.Express
private ExpSet _collection;
public ExpSetInstance( string name, ExpSet set, ExpSchema context )
: base( name, context )
: base( name )
{
_collection = set;
}
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;
public ExpBagInstance( string name, ExpBag bag, ExpSchema context )
: base( name, context )
: base( name )
{
_collection = bag;
}
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;
public ExpListInstance( string name, ExpList list, ExpSchema context )
: base( name, context )
: base( name )
{
_collection = list;
}
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,
ExpArray array,
ExpSchema context )
: base( name, context )
: base( name )
{
_collection = array;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElementBase EqualityTypeConvert => _collection;
public override ExpInstantiableElement EqualityTypeConvert => _collection;
}
}
+2 -2
View File
@@ -38,7 +38,7 @@ using System.Text;
namespace StgSharp.Script.Express
{
public sealed class ExpConstantCollectionSource : ExpImmutableElementBase
public sealed class ExpConstantCollectionSource : ExpImmutableElement
{
private Dictionary<string, ExpElementInstanceBase> _constants;
@@ -66,7 +66,7 @@ namespace StgSharp.Script.Express
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 ) {
return null!;
+7 -13
View File
@@ -34,25 +34,24 @@ using System.Text;
namespace StgSharp.Script.Express
{
public class ExpEntity : ExpBaseNode
public class ExpEntity : ExpNode
{
public ExpEntity( string name, ExpSchema context )
: base( name, context ) { }
public ExpEntity( string name, ExpSchema context ) : base( name ) { }
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 class ExpEntitySource : ExpInstantiableElementBase
public class ExpEntitySource : ExpInstantiableElement
{
private AbstractSyntaxTree<ExpBaseNode, IExpElementSource> _expressionTree;
private AbstractSyntaxTree<ExpNode, IExpElementSource> _expressionTree;
private ScriptSourceTransmitter _source;
private string _name;
@@ -73,12 +72,7 @@ namespace StgSharp.Script.Express
throw new NotImplementedException();
}
public override ExpBaseNode CreateInstanceNode()
{
throw new NotImplementedException();
}
public override bool IsConvertable( IExpElementSource targetType )
public override ExpNode CreateInstanceNode()
{
throw new NotImplementedException();
}
+13 -14
View File
@@ -34,32 +34,31 @@ using System.Text;
namespace StgSharp.Script.Express
{
public class ExpFunction : ExpBaseNode
public class ExpFunction : ExpNode
{
private readonly ExpBaseNode _return;
private ExpFunctionSource _source;
private readonly List<KeyValuePair<string, ExpBaseNode>> _parameterList
= new List<KeyValuePair<string, ExpBaseNode>>();
public ExpFunction( string name, ExpSchema context )
: base( name, context ) { }
private readonly ExpNode _return;
private readonly List<KeyValuePair<string, ExpNode>> _parameterList
= new List<KeyValuePair<string, ExpNode>>();
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public ExpFunction( string name, ExpSchema context ) : base( name ) { }
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;
@@ -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();
}
+8 -9
View File
@@ -41,23 +41,22 @@ namespace StgSharp.Script.Express
private ExpRuleSource _source;
public ExpRule( string name, ExpSchema context )
: base( name, context ) { }
public ExpRule( string name, ExpSchema context ) : base( name ) { }
public object? value => throw new NotImplementedException();
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override ExpInstantiableElementBase EqualityTypeConvert => throw new NotImplementedException(
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 => _source.Name;
}
public class ExpRuleSource : ExpImmutableElementBase
public class ExpRuleSource : ExpImmutableElement
{
private ScriptSourceTransmitter _transmitter;
@@ -80,7 +79,7 @@ namespace StgSharp.Script.Express
throw new NotImplementedException();
}
public override ExpBaseNode MakeReference( params object[] options )
public override ExpNode MakeReference( params object[] options )
{
throw new NotImplementedException();
}
+37 -8
View File
@@ -35,19 +35,18 @@ using System.Collections.Generic;
namespace StgSharp.Script.Express
{
public class ExpType : ExpElementInstanceBase
public class ExpTypeInstance : ExpElementInstanceBase
{
public ExpType( string name, ExpSchema context )
: base( name, context ) { }
public ExpTypeInstance( string name ) : base( name ) { }
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
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();
}
@@ -80,6 +79,11 @@ namespace StgSharp.Script.Express
public ExpElementType ElementType => ExpElementType.Type;
public ExpTypeSource Void
{
get => ExpVoidType.Only;
}
public IScriptSourceProvider SourceProvider => _transmitter;
public string Name => _name;
@@ -94,5 +98,30 @@ namespace StgSharp.Script.Express
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
{
public class ExpBinaryOperatorNode : ExpBaseNode
public class ExpBinaryOperatorNode : ExpNode
{
private ExpBaseNode _left;
private ExpBaseNode _right;
private ExpInstantiableElementBase _returnType;
private ExpInstantiableElement _returnType;
public ExpBinaryOperatorNode( string name ) : base( name, null! ) { }
private ExpNode _left;
private ExpNode _right;
public ExpBinaryOperatorNode(
string source,
ExpSchema context,
ExpBaseNode left,
ExpBaseNode right )
: base( source, context )
{
if( !left.EqualityTypeConvert
.IsConvertable( right.EqualityTypeConvert ) ) {
throw new InvalidCastException(
$"Cannot convert element {left.EqualityTypeConvert} to {right.EqualityTypeConvert}" );
}
_left = left;
_right = right;
}
private ExpBinaryOperatorNode( string name ) : base( name ) { }
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(
ExpBaseNode left,
ExpBaseNode right )
public static ExpBinaryOperatorNode Add( ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
@@ -88,8 +71,8 @@ namespace StgSharp.Script.Express
}
public static ExpBinaryOperatorNode Assign(
ExpBaseNode left,
ExpBaseNode right )
ExpNode left,
ExpNode right )
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
@@ -98,15 +81,13 @@ namespace StgSharp.Script.Express
}
return new ExpBinaryOperatorNode( ExpCompile.KeyWord.Assignment )
{
_returnType = ExpTypeSource.,
_returnType = ExpInstantiableElement.Void,
_nodeFlag = ExpNodeFlag.Operator_Binary | left._nodeFlag,
CodeConvertTemplate = "{0} & {1}",
};
}
public static ExpBinaryOperatorNode Div(
ExpBaseNode left,
ExpBaseNode right )
public static ExpBinaryOperatorNode Div( ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
@@ -123,9 +104,7 @@ namespace StgSharp.Script.Express
};
}
public static ExpBinaryOperatorNode Mul(
ExpBaseNode left,
ExpBaseNode right )
public static ExpBinaryOperatorNode Mul( ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
@@ -142,9 +121,7 @@ namespace StgSharp.Script.Express
};
}
public static ExpBinaryOperatorNode Sub(
ExpBaseNode left,
ExpBaseNode right )
public static ExpBinaryOperatorNode Sub( ExpNode left, ExpNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException(
@@ -36,32 +36,33 @@ using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
internal class ExpFunctionCallingNode : ExpBaseNode
internal class ExpFunctionCallingNode : ExpNode
{
private ExpBaseNode _parameter;
private ExpFunctionSource _function;
private ExpNode _parameter;
public ExpFunctionCallingNode(
string functionName,
int line,
int column,
ExpSchema context,
ExpBaseNode firstParameter )
: base( $"{functionName}_{line}_{column}", context )
ExpFunctionSource function,
ExpNode firstParameter )
: base( $"{function.Name}_call" )
{
_function = function;
_parameter = firstParameter;
if( !context.TryGetFunction( functionName, out _function ) ) {
foreach( var item in context. ) { }
}
}
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => _parameter;
public override ExpInstantiableElementBase EqualityTypeConvert => throw new NotImplementedException(
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
public override ExpNode Left => Empty;
public override ExpNode Right => _parameter;
public void AppendParameter( ExpNode parameter )
{
_parameter.AppendNode( parameter );
}
}
}
+19 -14
View File
@@ -36,41 +36,46 @@ using System.Text;
namespace StgSharp.Script.Express
{
public sealed class ExpIfNode : ExpBaseNode
public sealed class ExpIfNode : ExpNode
{
private ExpBaseNode _falseOpBegin;
private ExpBaseNode _rule;
private ExpBaseNode _trueOpBegin ;
private ExpNode _falseOpBegin;
private ExpNode _rule;
private ExpNode _trueOpBegin ;
public ExpIfNode(
string name,
ExpSchema context,
ExpBaseNode rule,
ExpBaseNode rootOperationIfTrue,
ExpBaseNode rootOperationIfFalse )
: base( name, context )
ExpNode rule,
ExpNode rootOperationIfTrue,
ExpNode rootOperationIfFalse )
: base( name )
{
_rule = rule;
_trueOpBegin = 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 void AppendFalseOperation( ExpBaseNode expressionRoot )
public void AppendFalseOperation( ExpNode expressionRoot )
{
AssertSchemaInclude( expressionRoot );
_falseOpBegin.AppendNode( expressionRoot );
}
public void AppendTrueOperation( ExpBaseNode expressionRoot )
public void AppendTrueOperation( ExpNode expressionRoot )
{
AssertSchemaInclude( expressionRoot );
_trueOpBegin.AppendNode( expressionRoot );
}
@@ -36,29 +36,29 @@ using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpIndexOfNode : ExpBaseNode
public class ExpIndexOfNode : ExpNode
{
private ExpBaseNode _indexExpression;
private ExpCollectionInstanceBase _collection;
private ExpNode _indexExpression;
public ExpIndexOfNode(
ExpSchema context,
ExpCollectionInstanceBase instance,
ExpBaseNode indexExpression )
: base( ExpCompile.PoolString( "[" ), context )
ExpNode indexExpression )
: base( ExpCompile.PoolString( "[" ) )
{
_collection = instance;
_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;
public ExpLiteralGenericNode( string name, ExpSchema context, T value )
: base( name, context )
: base( name )
{
_value = 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;
@@ -36,22 +36,24 @@ using System.Text;
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 ExpNode _operationBegin;
public ExpRepeatToken(
string name,
ExpSchema context,
ExpBaseNode operationBegin,
ExpNode operationBegin,
ExpElementInstanceBase variable,
ExpElementInstanceBase begin,
ExpElementInstanceBase end,
ExpElementInstanceBase increment )
: base( name, context )
: base( name )
{
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag !=
end.NodeFlag || ( increment != null && end.NodeFlag !=
@@ -81,13 +83,13 @@ namespace StgSharp.Script.Express
_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 void AppendRepeatedOperation( ExpBaseNode node )
public void AppendRepeatedOperation( ExpNode node )
{
_operationBegin.AppendNode( node );
}
@@ -34,25 +34,25 @@ using System.Text;
namespace StgSharp.Script.Express
{
public class ExpSwitchNode : ExpBaseNode
public class ExpSwitchNode : ExpNode
{
private Dictionary<ExpBaseNode, ExpBaseNode> _cases;
private ExpBaseNode _default;
private ExpBaseNode _target;
private Dictionary<ExpNode, ExpNode> _cases;
private ExpNode _default;
private ExpNode _target;
public ExpSwitchNode(
string name,
ExpSchema context,
ExpBaseNode target,
ExpBaseNode defaultCase,
params (ExpBaseNode label, ExpBaseNode op)[] cases )
: base( name, context )
ExpNode target,
ExpNode defaultCase,
params (ExpNode label, ExpNode op)[] cases )
: base( name )
{
_target = target;
_default = defaultCase;
_cases = new Dictionary<ExpBaseNode, ExpBaseNode>();
foreach( (ExpBaseNode label, ExpBaseNode op ) item in cases ) {
_cases = new Dictionary<ExpNode, ExpNode>();
foreach( (ExpNode label, ExpNode op ) item in cases ) {
if( item.op == null ) {
_cases.Add( item.label, null! );
} else {
@@ -61,24 +61,24 @@ namespace StgSharp.Script.Express
}
}
public ExpBaseNode this[ ExpBaseNode index ]
public ExpNode this[ ExpNode index ]
{
get
{
if( _cases.TryGetValue( index, out ExpBaseNode? ret ) ) {
if( _cases.TryGetValue( index, out ExpNode? ret ) ) {
return ret;
}
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 void AddOperationToDefault( ExpBaseNode expressionRoot )
public void AddOperationToDefault( ExpNode expressionRoot )
{
if( expressionRoot != null ) {
_default.AppendNode( expressionRoot );
@@ -93,18 +93,17 @@ namespace StgSharp.Script.Express
/// <param name="expressionRoot"> Root token of the expression to be added. </param>
/// <exception cref="ExpCaseNotFoundException"> Cannot fine the case label in current witch expression. </exception>
public void AppendOperationToCase(
ExpBaseNode label,
ExpBaseNode expressionRoot )
ExpNode label,
ExpNode expressionRoot )
{
AssertSchemaInclude( expressionRoot );
if( _cases.TryGetValue( label, out ExpBaseNode? op ) ) {
if( _cases.TryGetValue( label, out ExpNode? op ) ) {
op.AppendNode( expressionRoot );
} else {
throw new ExpCaseNotFoundException( this, label );
}
}
public bool ContainsCase( ExpBaseNode token )
public bool ContainsCase( ExpNode token )
{
return _cases.ContainsKey( token );
}
@@ -36,25 +36,42 @@ using System.Threading.Tasks;
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(
string name,
ExpBaseNode operand,
ExpNode operand,
ExpSchema context )
: base( name, context )
: base( name )
{
_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 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 )
: base( name, context ) { }
protected ExpElementInstanceBase( string name ) : base( name ) { }
public ExpElementType ElementType
{
+23 -15
View File
@@ -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
{
get;
}
public static ExpInstantiableElementBase Void
public static ExpInstantiableElement Void
{
get => ExpVoidElement.Only;
}
@@ -83,12 +87,22 @@ namespace StgSharp.Script.Express
public abstract void Analyse();
public abstract ExpBaseNode CreateInstanceNode();
public abstract ExpNode CreateInstanceNode();
public abstract bool IsConvertable(
ExpInstantiableElementBase targetType );
public bool IsConvertable( IExpElementSource 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();
@@ -106,22 +120,16 @@ namespace StgSharp.Script.Express
return;
}
public override ExpBaseNode CreateInstanceNode()
public override ExpNode CreateInstanceNode()
{
return default!;
}
public override bool IsConvertable(
ExpInstantiableElementBase targetType )
{
return false;
}
}
}
public abstract class ExpImmutableElementBase : IExpElementSource
public abstract class ExpImmutableElement : IExpElementSource
{
public abstract ExpElementType ElementType
@@ -146,7 +154,7 @@ namespace StgSharp.Script.Express
return false;
}
public abstract ExpBaseNode MakeReference( params object[] options );
public abstract ExpNode MakeReference( params object[] options );
}
}
+24 -20
View File
@@ -30,20 +30,14 @@
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
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
{
@@ -52,6 +46,9 @@ namespace StgSharp.Script.Express
}
/// <summary>
/// Exception when cannot reading a token from a line.
/// </summary>
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 endedName )
: 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
{
@@ -109,27 +115,25 @@ namespace StgSharp.Script.Express
ExpSchema context,
ExpSchema source )
: 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(
ExpSwitchNode token,
ExpBaseNode label )
public ExpElementLoadException( string typeName, ExpSchema context )
: 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(
$"Cannot find the type {typeName} in schema {context.Name} and its included schemas" ) { }
"Attempt to compile an EXPRESS script before the init of compiler." ) { }
}
}
+4 -4
View File
@@ -243,7 +243,7 @@ namespace StgSharp.Script.Express
}
string endedName = match.Groups[ "TypeName" ].ToString();
if( !string.Equals( endedName, _source.Name ) ) {
throw new ExpInvalidTypeDeclareEndingExceptions(
throw new ExpInvalidElementDeclareEndingExceptions(
_source.Name, endedName );
}
transmitter.WriteLine( "END_ENTITY" );
@@ -275,7 +275,7 @@ namespace StgSharp.Script.Express
}
string endedName = match.Groups[ "FunctionName" ].ToString();
if( !string.Equals( endedName, _source.Name ) ) {
throw new ExpInvalidTypeDeclareEndingExceptions(
throw new ExpInvalidElementDeclareEndingExceptions(
_source.Name, endedName );
}
transmitter.WriteLine( "END_FUNCTION" );
@@ -310,7 +310,7 @@ namespace StgSharp.Script.Express
}
string endedName = match.Groups[ "RuleName" ].ToString();
if( !string.Equals( endedName, _source.Name ) ) {
throw new ExpInvalidTypeDeclareEndingExceptions(
throw new ExpInvalidElementDeclareEndingExceptions(
_source.Name, endedName );
}
transmitter.WriteLine( "END_RULE" );
@@ -342,7 +342,7 @@ namespace StgSharp.Script.Express
}
string endedName = match.Groups[ "TypeName" ].ToString();
if( !string.Equals( endedName, _source.Name ) ) {
throw new ExpInvalidTypeDeclareEndingExceptions(
throw new ExpInvalidElementDeclareEndingExceptions(
_source.Name, endedName );
}
transmitter.WriteLine( "END_ENTITY" );
@@ -62,7 +62,7 @@ namespace StgSharp.Script.Express
return ret;
}
}
throw new ExpTypeNotFoundException( typeName, this );
throw new ExpElementLoadException( typeName, this );
}
public bool HasSchemaInclude( GeneratedExpSchema schema )
@@ -46,12 +46,12 @@ namespace StgSharp.Script.Express
private const int TokenGenerated = 0;
private const int TokenTypeNotMatch = -1;
private ExpBaseNode _lastStatement;
private ExpNode _lastStatement;
private GeneratedExpSchema _context;
private IExpElementSource _local;
private List<ExpBaseNode> _cache;
private Stack<ExpBaseNode> _operandsNode;
private List<ExpNode> _cache;
private Stack<ExpNode> _operandsNode;
private Stack<Token> _operandsToken;
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 );
}
public AbstractSyntaxTree<ExpBaseNode, IExpElementSource> CloseAndDispose(
public AbstractSyntaxTree<ExpNode, IExpElementSource> CloseAndDispose(
)
{
if( _operandsToken.Count != 0 ) {
// 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 ) {
case TokenFlag.Symbol_Unary:
@@ -134,7 +134,7 @@ namespace StgSharp.Script.Express
public int GetNextOperandCache(
out Token? token,
out ExpBaseNode? node )
out ExpNode? node )
{
if( _operandsNode.Count != 0 ) {
node = _operandsNode.Pop();
@@ -39,7 +39,7 @@ namespace StgSharp.Script.Express
public partial class ExpNodeGenerator
{
public ExpBaseNode GenerateUnaryToken( Token t )
public ExpNode GenerateUnaryToken( Token t )
{
switch( t.Value ) {
case ExpCompile.KeyWord.UnaryAdd:
@@ -37,13 +37,13 @@ using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpNodeNextEnumerator : IEnumerator<ExpBaseNode>
public class ExpNodeNextEnumerator : IEnumerator<ExpNode>
{
private ExpBaseNode _begin;
private ExpBaseNode _current;
private ExpNode _begin;
private ExpNode _current;
public ExpNodeNextEnumerator( ExpBaseNode token )
public ExpNodeNextEnumerator( ExpNode token )
{
_begin = token;
_current = token;
@@ -56,7 +56,7 @@ namespace StgSharp.Script.Express
bool IEnumerator.MoveNext()
{
ExpBaseNode next = _current.Next;
ExpNode next = _current.Next;
if( ReferenceEquals( next, _begin ) || next == null ) {
return false;
}
@@ -71,7 +71,7 @@ namespace StgSharp.Script.Express
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.AssemblyConfigurationAttribute("Debug")]
[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.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
+26
View File
@@ -28,8 +28,16 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.HighPerformance;
using StgSharp.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
@@ -42,5 +50,23 @@ namespace StgSharp
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;
}
}
}
}