diff --git a/StgSharp.Common/PipeLine/CrossFramePipelineNode.cs b/StgSharp.Common/PipeLine/CrossFramePipelineNode.cs index 379d0fa7..d8946c6c 100644 --- a/StgSharp.Common/PipeLine/CrossFramePipelineNode.cs +++ b/StgSharp.Common/PipeLine/CrossFramePipelineNode.cs @@ -38,7 +38,7 @@ using System.Threading.Tasks; namespace StgSharp.PipeLine { - public class CrossFrameOperation : IConvertableToBlueprintNode + public class CrossFrameOperation : IConvertableToPipelineNode { private static string[] _inputName = ["TaskIn"]; diff --git a/StgSharp.Common/PipeLine/IConvertableToPipelineNode.cs b/StgSharp.Common/PipeLine/IConvertableToPipelineNode.cs new file mode 100644 index 00000000..59141828 --- /dev/null +++ b/StgSharp.Common/PipeLine/IConvertableToPipelineNode.cs @@ -0,0 +1,88 @@ +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +// file="IConvertableToPipelineNode.cs" +// Project: StgSharp +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the “Software”), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, +// and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and +// this permission notice shall be included in all copies +// or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, +// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH +// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Text; + +namespace StgSharp.PipeLine +{ + public delegate void PipelineNodeOperation( + in Dictionary input, + in Dictionary output ); + + public interface IConvertableToPipelineNode + { + + public IEnumerable InputInterfacesName { get; } + + public IEnumerable OutputInterfacesName { get; } + + PipelineNodeOperation Operation { get; } + + void NodeMain( + in Dictionary input, + in Dictionary output ); + + } + + internal class DefaultConvertableToBlueprintNode : IConvertableToPipelineNode + { + + private string[] _input; + private string[] _output; + private PipelineNodeOperation _execution; + + public DefaultConvertableToBlueprintNode( + PipelineNodeOperation execution, + string[] input, + string[] output ) + { + _input = input; + _output = output; + _execution = execution; + } + + public IEnumerable InputInterfacesName => _input; + + public IEnumerable OutputInterfacesName => _output; + + public PipelineNodeOperation Operation => _execution; + + public void NodeMain( + in Dictionary input, + in Dictionary output ) + { + _execution.Invoke( input, output ); + } + + } +} diff --git a/StgSharp.Common/PipeLine/PipeLineRunner.cs b/StgSharp.Common/PipeLine/PipeLineRunner.cs index 5ad3e64a..b4ee8c87 100644 --- a/StgSharp.Common/PipeLine/PipeLineRunner.cs +++ b/StgSharp.Common/PipeLine/PipeLineRunner.cs @@ -48,23 +48,23 @@ namespace StgSharp.PipeLine private static NodeRunner[] allAvailableTask = CreateBlueprintRunnerArray(); private static CancellationTokenSource cts = new CancellationTokenSource(); - private static ConcurrentStack blueprintInWaiting + private static ConcurrentStack pipelineInWaiting = new ConcurrentStack(); private static int _callingThread; private static SemaphoreSlim bpLock = new SemaphoreSlim( 0, 1 ); /// - /// Only the following occasions of calling are valid: 1. no bp is - /// running or the only bp is quitting.2. calling from the main thread or a - /// thread the current bp is running on. + /// Only the following occasions of calling are valid: 1. no bp is + /// running or the only bp is quitting. 2. calling from the main thread or a + /// thread the current bp is running on. /// internal static bool IsValidCalling { get { if( ( NodeRunner.CurrentBlueprint == null ) || //no bp running at all - ( ( blueprintInWaiting.IsEmpty ) && ( NodeRunner.CurrentBlueprint.IsRunning == - false ) ) ) + ( ( pipelineInWaiting.IsEmpty ) && ( NodeRunner.CurrentBlueprint.IsRunning == + false ) ) ) { // a bp is quitting //in case no bp is running @@ -104,7 +104,6 @@ namespace StgSharp.PipeLine if( InterruptAndRunNewBp( blueprint ) ) { while( InterruptAndRunNewBp( NodeRunner.CurrentBlueprint ) ) { } - ; } } else { @@ -113,7 +112,6 @@ namespace StgSharp.PipeLine { while( InterruptAndRunNewBp( NodeRunner.CurrentBlueprint ) ) { } } - bpLock.Release(); } Interlocked.Exchange( ref _callingThread, -1 ); @@ -143,19 +141,19 @@ namespace StgSharp.PipeLine foreach( NodeRunner task in allAvailableTask ) { task.Cts.Cancel(); } - foreach( PipelineScheduler bp in blueprintInWaiting ) { + foreach( PipelineScheduler bp in pipelineInWaiting ) { bp.Terminate(); } - blueprintInWaiting.Clear(); + pipelineInWaiting.Clear(); } internal static bool InterruptAndRunNewBp( PipelineScheduler newBp ) { - Debug.Assert( newBp != null ); + ArgumentNullException.ThrowIfNull( newBp ); if( ( newBp != NodeRunner.CurrentBlueprint ) && ( NodeRunner.CurrentBlueprint != null ) ) { //if a running bp exists - blueprintInWaiting.Push( NodeRunner.CurrentBlueprint ); + pipelineInWaiting.Push( NodeRunner.CurrentBlueprint ); } //load new bp to current bp @@ -188,7 +186,7 @@ namespace StgSharp.PipeLine } } ( NodeRunner.CurrentBlueprint.EndLayer as EndingNode )!.Run(); - return blueprintInWaiting.TryPeek( out NodeRunner.CurrentBlueprint ); + return pipelineInWaiting.TryPeek( out NodeRunner.CurrentBlueprint ); } private static NodeRunner[] CreateBlueprintRunnerArray() diff --git a/StgSharp.Common/PipeLine/PipelineScheduler.cs b/StgSharp.Common/PipeLine/PipelineScheduler.cs index b2878068..000eb3f7 100644 --- a/StgSharp.Common/PipeLine/PipelineScheduler.cs +++ b/StgSharp.Common/PipeLine/PipelineScheduler.cs @@ -32,6 +32,7 @@ using StgSharp.Stg; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.CompilerServices; using System.Threading; @@ -44,7 +45,7 @@ namespace StgSharp.PipeLine /// A sets of complex logic designed for running in multi threads environment. Warning: do not /// run a instance in multi threads more than once. /// - public partial class PipelineScheduler : IConvertableToBlueprintNode + public partial class PipelineScheduler : IConvertableToPipelineNode { private BeginningNode _beginning; @@ -94,7 +95,7 @@ namespace StgSharp.PipeLine public PipelineNodeOperation Operation { - get => ( this as IConvertableToBlueprintNode ).NodeMain; + get => ( this as IConvertableToPipelineNode ).NodeMain; } /**/ @@ -161,20 +162,10 @@ namespace StgSharp.PipeLine } } - public void Init() + public PipelineNode Create( [NotNull]IConvertableToPipelineNode body, string name ) { - foreach( KeyValuePair item in allNode ) - { - if( item.Value.IsNative ) - { - mainThreadNodeList.Add( item.Value ); - } else - { - globalNodeList.Add( item.Value ); - } - } - mainThreadNodeList.Sort(); - globalNodeList.Sort(); + PipelineNode node = new PipelineNode( name, body, false ); + return node; } [MethodImpl( MethodImplOptions.AggressiveInlining )] @@ -213,9 +204,9 @@ namespace StgSharp.PipeLine return false; } - void IConvertableToBlueprintNode.NodeMain( - in Dictionary input, - in Dictionary output ) + void IConvertableToPipelineNode.NodeMain( + in Dictionary input, + in Dictionary output ) { PipeLineRunner.Run( this ); PipelineNodeExport.SkipAll( output ); diff --git a/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.AssemblyInfo.cs b/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.AssemblyInfo.cs index c1038428..5b2fe53e 100644 --- a/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.AssemblyInfo.cs +++ b/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Common")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c29993fd8497704d2ddeab3e1a3f8bfa5caa8d90")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b618fdf7b5295b190dcc6b7168e038d1d5a11455")] [assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.sourcelink.json b/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.sourcelink.json index 4b461246..77b8f154 100644 --- a/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.sourcelink.json +++ b/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.sourcelink.json @@ -1 +1 @@ -{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/c29993fd8497704d2ddeab3e1a3f8bfa5caa8d90/*"}} \ No newline at end of file +{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/b618fdf7b5295b190dcc6b7168e038d1d5a11455/*"}} \ No newline at end of file diff --git a/StgSharp.Model/STEP/Reader/StepDataTokenReader.cs b/StgSharp.Model/STEP/Reader/StepDataTokenReader.cs new file mode 100644 index 00000000..494365bd --- /dev/null +++ b/StgSharp.Model/STEP/Reader/StepDataTokenReader.cs @@ -0,0 +1,112 @@ +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +// file="StepDataTokenReader.cs" +// Project: StgSharp +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the “Software”), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, +// and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and +// this permission notice shall be included in all copies +// or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, +// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH +// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +using StgSharp.Modeling.Step; +using StgSharp.Script; +using StgSharp.Script.Express; + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; + +namespace StgSharp.Modeling.Step +{ + public class StepDataTokenReader : IScriptTokenReader + { + + private ExpTokenReader _reader; + + private HashSet token1Hash = [ + "T","F","UNSPECIFIED" + ]; + private Queue _cache = new Queue(); + private StepDataSectionTransmitter _transmitter; + + public StepDataTokenReader( StepDataSectionTransmitter transmitter ) + { + _reader = new ExpTokenReader( transmitter ); + _reader.TokenReaderPreProcessor = new TokenPreReader(); + _transmitter = transmitter; + } + + public Token ReadToken() + { + return _reader.ReadToken(); + } + + public bool TryReadToken( out Token t ) + { + return _reader.TryReadToken( out t ); + } + + private class TokenPreReader : ExpTokenReaderPreProcessor + { + + private static Regex NextEnumPattern = GetNextEnumPattern(); + + public override bool Process( string codeLine, int line, ref int current, out Token t ) + { + ReadOnlySpan chars = codeLine.AsSpan( current ); + char c = chars[ 0 ]; + if( c != '.' ) + { + t = Token.Empty; + return false; + } + Match match = NextEnumPattern.Match( codeLine, current ); + if( match.Success ) + { + int begin = match.Groups[ "begin" ].Index; + int end = match.Groups[ "end" ].Length; + int rest = match.Groups[ "rets" ].Length; + current = rest; + t = new Token( match.Groups[ "begin" ].Value, line, begin, TokenFlag.Enum ); + return true; + } else + { + t = Token.Empty; + return false; + } + } + + [GeneratedRegex( + @"(?\.[A-Za-z_]+\.)(?\s*)(?\S*)", + RegexOptions.Singleline )] + private static extern Regex GetNextEnumPattern(); + + } + + } +} diff --git a/StgSharp.Model/STEP/StepEntityBase.cs b/StgSharp.Model/STEP/StepEntityBase.cs new file mode 100644 index 00000000..5094d842 --- /dev/null +++ b/StgSharp.Model/STEP/StepEntityBase.cs @@ -0,0 +1,65 @@ +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +// file="StepEntityBase.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 Microsoft.CodeAnalysis.CSharp.Syntax; + +using StgSharp.Math; +using StgSharp.Modeling.Step; +using StgSharp.PipeLine; +using StgSharp.Script.Express; + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.CompilerServices; + +namespace StgSharp.Modeling.Step +{ + public abstract class StepEntityBase : IExpMarshalType + { + + protected StepEntityBase( string name ) + { + Name = name; + } + + public int Id { get; protected set; } + + public abstract StepItemType ItemType { get; } + + public string Name { get; protected set; } + + public static StepUninitializedEntity Create( string name, ExpSyntaxNode node ) + { + return new StepUninitializedEntity( name, 0 ); + } + + } +} \ No newline at end of file diff --git a/StgSharp.Model/STEP/StepUncertainElement.cs b/StgSharp.Model/STEP/StepUncertainElement.cs new file mode 100644 index 00000000..48b1480d --- /dev/null +++ b/StgSharp.Model/STEP/StepUncertainElement.cs @@ -0,0 +1,197 @@ +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +// file="StepUncertainElement.cs" +// Project: StgSharp +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the ¡°Software¡±), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, +// and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and +// this permission notice shall be included in all copies +// or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED ¡°AS IS¡±, +// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH +// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +using StgSharp; +using StgSharp.PipeLine; +using StgSharp.Script; + +using StgSharp.Script.Express; + +using System; +using System.Collections.Generic; +using System.Diagnostics; + +namespace StgSharp.Modeling.Step +{ + public class StepUninitializedEntity : StepEntityBase, IConvertableToPipelineNode + { + + private ExpSyntaxNode data; + private int _id; + private StepModel _model; + private string _name; + + public StepUninitializedEntity( string name, int id ) + : base( name ) + { + _name = name; + _id = id; + } + + public int Id + { + get => _id; + } + + public override StepItemType ItemType => StepItemType.Unknown; + + public string Name + { + get => _name; + } + + internal static HashSet UnsupportedItemTypes { get; } = new HashSet(); + + public static StepUninitializedEntity Create( int id ) + { + return new StepUninitializedEntity( string.Empty, id ); + } + + public static StepUninitializedEntity Create( string name, ExpSyntaxNode node ) + { + return new StepUninitializedEntity( name, 0 ); + } + + public void Init( StepModel model, ExpSyntaxNode param ) + { + if( param is ExpFunctionCallingNode caller ) + { + string entityName = caller.FunctionCaller.Name; + ExpSyntaxNode p = caller.Right; + ExpNodeNextEnumerator e = p.ToEnumerator(); + } else + { + throw new ExpInvalidSyntaxException( + "Assigned syntax node is not a function caller." ); + } + } + + public void InitGeometry() + { + throw new NotImplementedException(); + } + + internal static StepEntityBase FromTypedParameter( + StepModel binder, + ExpSyntaxNode itemSyntax ) + { + StepEntityBase item = null!; + if( itemSyntax is ExpElementInitializingNode initNode ) + { + string name = initNode.EqualityTypeConvert.Name; + switch( name ) + { + case StepItemTypeExtensions.AdvancedFaceText: + item = StepAdvancedFace.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.Axis2Placement2DText: + item = StepAxis2Placement2D.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.Axis2Placement3DText: + item = StepAxis2Placement3D.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.BSplineCurveWithKnotsText: + item = StepBSplineCurveWithKnots.CreateFromSyntaxList( + binder, initNode.Right ); + break; + case StepItemTypeExtensions.CartesianPointText: + item = StepCartesianPoint.CreateFromSyntaxList( initNode.Right ); + break; + case StepItemTypeExtensions.CircleText: + item = StepCircle.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.CylindricalSurfaceText: + item = StepCylindricalSurface.CreateFromSyntaxList( binder, + initNode.Right ); + break; + case StepItemTypeExtensions.DirectionText: + item = StepDirection.CreateFromSyntaxList( initNode.Right ); + break; + case StepItemTypeExtensions.EdgeCurveText: + item = StepEdgeCurve.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.EdgeLoopText: + item = StepEdgeLoop.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.EllipseText: + item = StepEllipse.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.FaceBoundText: + item = StepFaceBound.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.FaceOuterBoundText: + item = StepFaceOuterBound.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.LineText: + item = StepLine.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.OrientedEdgeText: + item = StepOrientedEdge.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.PlaneText: + item = StepPlane.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.VectorText: + item = StepVector.CreateFromSyntaxList( binder, initNode.Right ); + break; + case StepItemTypeExtensions.VertexPointText: + item = StepVertexPoint.CreateFromSyntaxList( binder, initNode.Right ); + break; + default: + if( UnsupportedItemTypes.Add( name ) ) { + Debug.WriteLine( + $"Unsupported item {name} at {initNode.Line}, {initNode.Column}" ); + } + break; + } + } else + { + // TODO: + } + + return item; + } + + void IConvertableToPipelineNode.NodeMain( + in Dictionary input, + in Dictionary output ) + { + InitGeometry(); + PipelineNodeExport.SkipAll( output ); + } + + IEnumerable IConvertableToPipelineNode.InputInterfacesName => ["in"]; + + PipelineNodeOperation IConvertableToPipelineNode.Operation => ( this as IConvertableToPipelineNode ).NodeMain; + + IEnumerable IConvertableToPipelineNode.OutputInterfacesName => ["out"]; + + } +} \ No newline at end of file diff --git a/StgSharp.Model/STEP/SyntaxNode/StepExpEnumValueNode.cs b/StgSharp.Model/STEP/SyntaxNode/StepExpEnumValueNode.cs new file mode 100644 index 00000000..ceddd98f --- /dev/null +++ b/StgSharp.Model/STEP/SyntaxNode/StepExpEnumValueNode.cs @@ -0,0 +1,60 @@ +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +// file="StepExpEnumValueNode.cs" +// Project: StgSharp +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the “Software”), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, +// and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and +// this permission notice shall be included in all copies +// or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, +// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH +// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +using StgSharp.Script; +using StgSharp.Script.Express; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StgSharp.Modeling.Step +{ + internal class StepExpEnumValueNode : ExpSyntaxNode + { + + public StepExpEnumValueNode( Token source ) + : base( source ) + { + EnumValue = source.Value; + } + + public override ExpSyntaxNode Left => Empty; + + public override ExpSyntaxNode Right => Empty; + + public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(); + + public string EnumValue { get; private set; } + + } +} diff --git a/StgSharp.Model/StgSharp.Model.csproj b/StgSharp.Model/StgSharp.Model.csproj index 01aedcfb..4147ac04 100644 --- a/StgSharp.Model/StgSharp.Model.csproj +++ b/StgSharp.Model/StgSharp.Model.csproj @@ -12,8 +12,4 @@ - - - - diff --git a/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.AssemblyInfo.cs b/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.AssemblyInfo.cs index 2fbf6b9f..52577371 100644 --- a/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.AssemblyInfo.cs +++ b/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c29993fd8497704d2ddeab3e1a3f8bfa5caa8d90")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b618fdf7b5295b190dcc6b7168e038d1d5a11455")] [assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Model")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.sourcelink.json b/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.sourcelink.json index 2440bc0f..77b8f154 100644 --- a/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.sourcelink.json +++ b/StgSharp.Model/obj/x64/Debug/net8.0/StgSharp.Model.sourcelink.json @@ -1 +1 @@ -{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/2692495dc8460e1f60a2d073f162c5f526e1ba1b/*"}} \ No newline at end of file +{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/b618fdf7b5295b190dcc6b7168e038d1d5a11455/*"}} \ No newline at end of file diff --git a/StgSharp.Script/Common/Token.cs b/StgSharp.Script/Common/Token.cs index ca7e5176..3535722b 100644 --- a/StgSharp.Script/Common/Token.cs +++ b/StgSharp.Script/Common/Token.cs @@ -47,11 +47,7 @@ namespace StgSharp.Script public readonly string Value; public readonly TokenFlag Flag; - public Token( - string chars, - int lineNumber, - int columnNumber, - TokenFlag flag ) + public Token( string chars, int lineNumber, int columnNumber, TokenFlag flag ) { Value = chars; Line = lineNumber; @@ -83,6 +79,7 @@ namespace StgSharp.Script Separator_Right = 8, Index_Left = 9, Index_Right = 10, + Enum = 11 } } diff --git a/StgSharp.Script/Express/ExpAstNode/ExpElementInitializingNode.cs b/StgSharp.Script/Express/ExpAstNode/ExpElementInitializingNode.cs index 0a076b36..475bdd31 100644 --- a/StgSharp.Script/Express/ExpAstNode/ExpElementInitializingNode.cs +++ b/StgSharp.Script/Express/ExpAstNode/ExpElementInitializingNode.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; @@ -42,10 +43,10 @@ namespace StgSharp.Script.Express private ExpMetaRefNode _type; private ExpSyntaxNode _init; - public ExpElementInitializingNode( - Token source, - ExpMetaRefNode type, - ExpSyntaxNode initParameter ) + private ExpElementInitializingNode( + Token source, + ExpMetaRefNode type, + ExpSyntaxNode initParameter ) : base( source ) { _type = type; @@ -58,5 +59,15 @@ namespace StgSharp.Script.Express public override IExpElementSource EqualityTypeConvert => _type.SourceRef; + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public ExpElementInitializingNode InitializeElement( + Token source, + ExpMetaRefNode type, + ExpSyntaxNode init ) + { + ExpElementInitializingNode node = new ExpElementInitializingNode( source, type, init ); + return node; + } + } } diff --git a/StgSharp.Script/Express/ExpAstNode/ExpFunctionCallingNode.cs b/StgSharp.Script/Express/ExpAstNode/ExpFunctionCallingNode.cs index ad48078f..d81fd1fc 100644 --- a/StgSharp.Script/Express/ExpAstNode/ExpFunctionCallingNode.cs +++ b/StgSharp.Script/Express/ExpAstNode/ExpFunctionCallingNode.cs @@ -46,11 +46,14 @@ namespace StgSharp.Script.Express private ExpFunctionCallingNode( Token source, ExpFunctionSource function, - ExpSyntaxNode firstParameter ) + ExpSyntaxNode parameterEnumeration ) : base( source ) { + if( parameterEnumeration is ExpTupleNode tuple ) { + parameterEnumeration = tuple.Right; + } _function = function; - _parameter = firstParameter; + _parameter = parameterEnumeration; } public ExpFunctionSource FunctionCaller => _function; diff --git a/StgSharp.Script/Express/ExpAstNode/ExpTupleNode.cs b/StgSharp.Script/Express/ExpAstNode/ExpTupleNode.cs new file mode 100644 index 00000000..c90a04c9 --- /dev/null +++ b/StgSharp.Script/Express/ExpAstNode/ExpTupleNode.cs @@ -0,0 +1,69 @@ +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +// file="ExpTupleNode.cs" +// Project: StgSharp +// AuthorGroup: Nitload Space +// Copyright (c) Nitload Space. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the “Software”), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, +// and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and +// this permission notice shall be included in all copies +// or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, +// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH +// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace StgSharp.Script.Express +{ + public class ExpTupleNode : ExpSyntaxNode + { + + private ExpSyntaxNode node; + + private ExpTupleNode( ExpSyntaxNode node ) + : base( node._source ) + { + this.node = node; + } + + public override ExpSyntaxNode Left => Empty; + + public override ExpSyntaxNode Right => node; + + public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(); + + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static ExpTupleNode Pack( ExpSyntaxNode node ) + { + return new ExpTupleNode( node ); + } + + public ExpNodeNextEnumerator TupleAsEnumerator() + { + return node.ToEnumerator(); + } + + } +} diff --git a/StgSharp.Script/Express/ExpNodeNextEnumerator.cs b/StgSharp.Script/Express/ExpNodeNextEnumerator.cs index 7128c419..99e16e16 100644 --- a/StgSharp.Script/Express/ExpNodeNextEnumerator.cs +++ b/StgSharp.Script/Express/ExpNodeNextEnumerator.cs @@ -47,7 +47,6 @@ namespace StgSharp.Script.Express public static ExpNodeNextEnumerator AsCollectionEnumerator( this ExpSyntaxNode token ) { ExpNodeNextEnumerator enumerator = new ExpNodeNextEnumerator( token ); - enumerator.AssertEnumeratorCount( count ); IExpElementSource type = token.EqualityTypeConvert; while( enumerator.MoveNext() ) { @@ -107,6 +106,14 @@ namespace StgSharp.Script.Express } } + public void AssertEnumeratorCount( int min, int max ) + { + if( _begin.Count < min || _begin.Count > max ) { + throw new InvalidOperationException( + $"Enumerator count mismatch. Expected between {min} and {max}, but got {_begin.Count}." ); + } + } + public bool MoveNext() { ExpSyntaxNode next = _current.Next; diff --git a/StgSharp.Script/Express/ExpSyntaxAnalyzer.PrefixReverseAnalysing.cs b/StgSharp.Script/Express/ExpSyntaxAnalyzer.PrefixReverseAnalysing.cs index d2fac134..ba58bee7 100644 --- a/StgSharp.Script/Express/ExpSyntaxAnalyzer.PrefixReverseAnalysing.cs +++ b/StgSharp.Script/Express/ExpSyntaxAnalyzer.PrefixReverseAnalysing.cs @@ -66,6 +66,9 @@ namespace StgSharp.Script.Express } root = _cache.PackAllStatements(); + if( rightSeparator.Value == ")" ) { + root = ExpTupleNode.Pack( root ); + } _cache.DecreaseDepth(); if( IsSeparatorMatch( _cache.PeekOperator(), rightSeparator ) ) { diff --git a/StgSharp.Script/Express/ExpTokenReader.cs b/StgSharp.Script/Express/ExpTokenReader.cs new file mode 100644 index 00000000..094fcc60 --- /dev/null +++ b/StgSharp.Script/Express/ExpTokenReader.cs @@ -0,0 +1,452 @@ +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +// file="ExpTokenReader.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; + +using StgSharp.HighPerformance; + +using System; +using System.Linq; +using System.Text.RegularExpressions; + +namespace StgSharp.Script.Express +{ + public abstract class ExpTokenReaderPreProcessor + { + + public static ExpTokenReaderPreProcessor Default { get; } = new DefaultProcessor(); + + public abstract bool Process( string codeLine, int line, ref int current, out Token t ); + + private class DefaultProcessor : ExpTokenReaderPreProcessor + { + + public override bool Process( string codeLine, int line, ref int current, out Token t ) + { + t = Token.Empty; + return false; + } + + } + + } + + public partial class ExpTokenReader : IScriptTokenReader + { + + private const int + MultiLineEnd = 0x0029002A; // *) + + private const string TokenMark = "token", EndMark = "end", RestMark = "rest"; + + private bool _isReadingMultiLineComment; + private int _current, _lineNum; + private IScriptSourceProvider _provider; + + private Regex + _nextHashtagSymbolPattern = GetHashtagSymbolPattern() , + _nextWordTokenPattern = GetNextWordTokenPattern(), + _nextStringLiteralPattern = GetStringLiteralPattern(), + _nextNumberLiteralPattern = GetNumberLiteralPattern(), + _nextStringLiteralPatternWithSingle = GetStringLiteralPatternWithSingle(), + _skipBlankPattern = GetSkipBlankPattern(), + _nextSymbolPattern = GetSymbolPattern(); + private string _lineCache; + private Token _last; + + public ExpTokenReader( IScriptSourceProvider provider ) + { + _provider = provider; + _current = 0; + _lineCache = string.Empty; + _isReadingMultiLineComment = false; + } + + public bool IsEmpty + { + get => ( ( string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length ) ) && _provider.IsEmpty; + } + + public ExpTokenReaderPreProcessor TokenReaderPreProcessor { get; set; } = ExpTokenReaderPreProcessor.Default; + + public int LineNumber + { + get => _provider.Location; + } + + public unsafe ReadOnlySpan ReadLine() + { + bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length; + while( lineOver || _isReadingMultiLineComment ) + { + if( IsEmpty ) { + return ReadOnlySpan.Empty; + } + if( lineOver ) + { + do + { + _lineCache = _provider.ReadLine( out _lineNum ); + } while (string.IsNullOrEmpty( _lineCache )); + _current = 0; + } + if( _isReadingMultiLineComment ) + { + int index; + fixed( char* cPtr = _lineCache.AsSpan( _current ) ) { + index = UnsafeCompute.IndexOfCharPair( + cPtr, MultiLineEnd, _lineCache.Length ); + } + if( index == -1 ) + { + _lineCache = string.Empty; + } else + { + _isReadingMultiLineComment = false; + _current += index + 2; + } + } + lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length; + } + return _lineCache.AsSpan().Slice( _current ); + } + + public unsafe Token ReadToken() + { + int begin, end, rest; + readLine: + ReadOnlySpan source; + if( !TryReadLine( out source ) ) { + return Token.Empty; + } + if( TokenReaderPreProcessor.Process( _lineCache, LineNumber, ref _current, + out Token t ) ) { + return t; + } + char c = source[ 0 ]; + if( char.IsLetter( c ) ) + { + Match match = _nextWordTokenPattern.Match( _lineCache, _current ); + if( match.Success ) + { + begin = match.Groups[ TokenMark ].Index; + end = match.Groups[ EndMark ].Index; + rest = match.Groups[ RestMark ].Index; + _current = rest; + _last = new( + ExpressCompile.PoolString( source[ ..( end - begin ) ] ), _lineNum, begin, + TokenFlag.Member ); + return _last; + } else + { + throw new ExpInvalidCharException( _current ); + } + } else if( char.IsPunctuation( c ) || char.IsSymbol( c ) ) + { + Match match; + switch( c ) + { + case '#': + match = _nextHashtagSymbolPattern.Match( _lineCache, _current ); + if( match.Success ) + { + begin = match.Groups[ "token" ].Index; + end = match.Groups[ "end" ].Index; + rest = match.Groups[ "rest" ].Index; + _current = rest; + _last = new( + ExpressCompile.PoolString( source[ 1..( end - begin ) ] ), _lineNum, + begin, TokenFlag.Member ); + return _last; + } else + { + throw new ExpInvalidCharException( '#' ); + } + case '\'': + char cNext = source[ 1 ]; + if( cNext == '\'' ) //empty string + { + begin = _current; + _current += 2; + return new( string.Empty, _lineNum, begin, TokenFlag.String ); + } + match = _nextStringLiteralPatternWithSingle.Match( _lineCache, _current ); + if( match.Success ) + { + begin = match.Groups[ "token" ].Index; + end = match.Groups[ "end" ].Index; + rest = match.Groups[ "rest" ].Index; + _current = rest; + _last = new( + ExpressCompile.PoolString( source[ 1..( end - begin ) ] ), _lineNum, + begin, TokenFlag.String ); + return _last; + } else + { + throw new ExpInvalidCharException( '\"' ); + } + case '"': + cNext = source[ 1 ]; + if( cNext == '\"' ) //empty string + { + begin = _current; + _current += 2; + return new( string.Empty, _lineNum, begin, TokenFlag.String ); + } + match = _nextStringLiteralPattern.Match( _lineCache, _current ); + if( match.Success ) + { + begin = match.Groups[ "token" ].Index; + end = match.Groups[ "end" ].Index; + rest = match.Groups[ "rest" ].Index; + _current = rest; + _last = new( + ExpressCompile.PoolString( source[ 1..( end - begin ) ] ), _lineNum, + begin, TokenFlag.String ); + return _last; + } else + { + throw new ExpInvalidCharException( '\"' ); + } + case '(': + cNext = source[ 1 ]; + if( cNext == '*' ) + { + _isReadingMultiLineComment = true; + _current += 2; + goto readLine; + } else + { + begin = _current; + _current++; + _last = new( + ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin, + TokenFlag.Separator_Left ); + return _last; + } + case ')' or '}': + begin = _current; + _current++; + _last = new Token( + ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin, + TokenFlag.Separator_Right ); + return _last; + case '-': + + // 1. - number + // 2. -- comment + // 3. - number type param(UNARY) + // 4. param - param(BINARY) + cNext = source[ 1 ]; + if( char.IsNumber( cNext ) ) + { + match = _nextNumberLiteralPattern.Match( _lineCache, _current ); + if( match.Success ) + { + begin = match.Groups[ TokenMark ].Index; + end = match.Groups[ EndMark ].Index; + rest = match.Groups[ RestMark ].Index; + _current = rest; + return new( + ExpressCompile.PoolString( source[ ..( end - begin ) ] ), + _lineNum, begin, TokenFlag.Number ); + } else + { + throw new ExpInvalidCharException( _current ); + } + } else if( cNext == '-' ) + { + _lineCache = string.Empty; + _current = 0; + goto readLine; + } else + { + begin = _current; + _current++; + if( _last.Flag == TokenFlag.Member || _last.Flag == + TokenFlag.Index_Right || _last.Flag == TokenFlag.Separator_Right ) + { + _last = new( + ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin, + TokenFlag.Symbol_Binary ); + } else + { + _last = new( + ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin, + TokenFlag.Symbol_Unary ); + } + return _last; + } + case '{': + begin = _current; + _current++; + _last = new Token( + ExpressCompile.PoolString( "{" ), _lineNum, begin, + TokenFlag.Separator_Left ); + return _last; + case '[': + begin = _current; + _current++; + _last = new Token( + ExpressCompile.PoolString( "[" ), _lineNum, begin, + TokenFlag.Index_Left ); + return _last; + case ']': + begin = _current; + _current++; + _last = new Token( + ExpressCompile.PoolString( "]" ), _lineNum, begin, + TokenFlag.Index_Right ); + return _last; + case ';' or ',': + begin = _current; + _current++; + _last = new Token( + ExpressCompile.PoolString( source[ ..1 ] ), _lineNum, begin, + TokenFlag.Separator_Middle ); + return _last; + case ':': + match = _nextSymbolPattern.Match( _lineCache, _current ); + begin = match.Groups[ TokenMark ].Index; + end = match.Groups[ EndMark ].Index; + rest = match.Groups[ RestMark ].Index; + _current = rest; + if( end - begin == 1 ) + { + _last = new Token( + ExpressCompile.Keyword.Colon, _lineNum, begin, + TokenFlag.Separator_Middle ); + } else + { + _last = new Token( + ExpressCompile.PoolString( source[ ..( end - begin ) ] ), _lineNum, + begin, TokenFlag.Symbol_Binary ); + } + return _last; + case '+' or '/' or '\\' or '*' or '.': + match = _nextSymbolPattern.Match( _lineCache, _current ); + begin = match.Groups[ TokenMark ].Index; + end = match.Groups[ EndMark ].Index; + rest = match.Groups[ RestMark ].Index; + _current = rest; + _last = new Token( + ExpressCompile.PoolString( source[ ..( end - begin ) ] ), _lineNum, + begin, TokenFlag.Symbol_Binary ); + return _last; + case '=': + begin = _current; + _current++; + _last = new Token( + ExpressCompile.Keyword.Equal, _lineNum, begin, + TokenFlag.Symbol_Binary ); + return _last; + default: + throw new ExpInvalidCharException( c ); + } + } else if( char.IsNumber( c ) ) + { + Match match = _nextNumberLiteralPattern.Match( _lineCache, _current ); + if( match.Success ) + { + begin = match.Groups[ TokenMark ].Index; + end = match.Groups[ EndMark ].Index; + rest = match.Groups[ RestMark ].Index; + _current = rest; + string str = ExpressCompile.PoolString( source[ ..( end - begin ) ] ); + return new( str, _lineNum, begin, TokenFlag.Number ); + } else + { + throw new ExpInvalidCharException( _current ); + } + } else if( char.IsWhiteSpace( c ) ) + { + Match match = _skipBlankPattern.Match( _lineCache, _current ); + if( match.Success ) + { + rest = match.Groups[ RestMark ].Index; + _current = rest; + goto readLine; + } else + { + throw new ExpInvalidCharException( _current ); + } + } else + { + throw new ExpInvalidCharException( c ); + } + } + + public bool TryReadLine( out ReadOnlySpan line ) + { + line = ReadLine(); + return line != ReadOnlySpan.Empty; + } + + public bool TryReadToken( out Token t ) + { + t = ReadToken(); + return !IsEmpty; + } + + [GeneratedRegex( + @"(?#[0-9A-Za-z]+)(?\s*?)(?\S|$)", + RegexOptions.Singleline )] + private static partial Regex GetHashtagSymbolPattern(); + + [GeneratedRegex( + @"(?[a-zA-Z][a-zA-Z0-9_]*)(?\s*?)(?\S|$)", + RegexOptions.Singleline )] + private static partial Regex GetNextWordTokenPattern(); + + [GeneratedRegex( + @"(?-?\s*?[0-9]+(?:\.[0-9]*)?E?(?:[+-]?[0-9]+)?)(?\s*?)(?\S|$)", + RegexOptions.Singleline )] + private static partial Regex GetNumberLiteralPattern(); + + [GeneratedRegex( @"(?:\s+?)(?\S|$)", RegexOptions.Singleline )] + private static partial Regex GetSkipBlankPattern(); + + [GeneratedRegex( + @"(?"")(?>\\\\|\\""|(?!')[^""])*(?""|$)\s*?(?\S|$)", + RegexOptions.Singleline )] + private static partial Regex GetStringLiteralPattern(); + + [GeneratedRegex( + @"(?')(?>\\\\|\\'|''|(?!')[^'])*(?')\s*?(?\S|$)", + RegexOptions.Singleline )] + private static partial Regex GetStringLiteralPatternWithSingle(); + + [GeneratedRegex( + @"(?[:<>=+\-*\/]+)(?\s?)\s*?(?\S|$)", + RegexOptions.Singleline )] + private static partial Regex GetSymbolPattern(); + + } +} diff --git a/StgSharp.Script/Express/IExpMarshalType.cs b/StgSharp.Script/Express/IExpMarshalType.cs index a2b0fc1e..83f33dfb 100644 --- a/StgSharp.Script/Express/IExpMarshalType.cs +++ b/StgSharp.Script/Express/IExpMarshalType.cs @@ -36,10 +36,13 @@ using System.Threading.Tasks; namespace StgSharp.Script.Express { - public interface IExpMarshalType + public interface IExpMarshalType where TSelf: class { - static abstract TSelf Create( string name, ExpSyntaxNode node ); + static virtual TSelf Create( string name, ExpSyntaxNode node ) + { + return null; + } } } diff --git a/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs b/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs index 9958fd7a..1c90c81b 100644 --- a/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs +++ b/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs @@ -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+c29993fd8497704d2ddeab3e1a3f8bfa5caa8d90")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b618fdf7b5295b190dcc6b7168e038d1d5a11455")] [assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.sourcelink.json b/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.sourcelink.json index 4b461246..77b8f154 100644 --- a/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.sourcelink.json +++ b/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.sourcelink.json @@ -1 +1 @@ -{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/c29993fd8497704d2ddeab3e1a3f8bfa5caa8d90/*"}} \ No newline at end of file +{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/b618fdf7b5295b190dcc6b7168e038d1d5a11455/*"}} \ No newline at end of file diff --git a/StgSharpDebug/ExpLinearExpressionTest.cs b/StgSharpDebug/ExpLinearExpressionTest.cs index 28cc5572..18669c70 100644 --- a/StgSharpDebug/ExpLinearExpressionTest.cs +++ b/StgSharpDebug/ExpLinearExpressionTest.cs @@ -157,7 +157,7 @@ namespace StgSharp transmitter.WriteLine( line ); } transmitter.EndWriting(); - ExpSourceReader reader = new ExpSourceReader( transmitter ); + ExpTokenReader reader = new ExpTokenReader( transmitter ); /**/ ExpTestFuncSource func = new ExpTestFuncSource( "test", transmitter ); TestSchema testSchema = new TestSchema( func );