Daily update on 20251020-041041 by Nitload Youmu. Additional Message : Code cleanup and new design of parallel (maybe THE THENTH VERSION? Tough work!).

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-10-20 04:10:41 +08:00
parent 1927f4fdf3
commit 547ba80a01
141 changed files with 5475 additions and 6175 deletions
@@ -1,33 +1,30 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.Common.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// -----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.Common"
// 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:
// 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.
//
// 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 System;
@@ -45,7 +42,7 @@ namespace StgSharp.Script.Express
public partial class ExpSyntaxAnalyzer
{
private bool IsSeparatorMatch( Token leftSperator, Token rightSeparator )
private bool IsSeparatorMatch(Token leftSperator, Token rightSeparator)
{
return leftSperator.Value switch
{
@@ -57,215 +54,215 @@ namespace StgSharp.Script.Express
};
}
private bool TryAppendIndexLeft( Token t )
private bool TryAppendIndexLeft(Token t)
{
if( t.Flag != TokenFlag.Index_Left ) {
if (t.Flag != TokenFlag.Index_Left) {
return false;
}
if( _cache.TryPeekOperand( out bool isNode, out _, out ExpSyntaxNode? node ) )
if (_cache.TryPeekOperand(out bool isNode, out _, out ExpSyntaxNode? node))
{
if( node.EqualityTypeConvert is not ExpCollectionBase ) {
ExpInvalidSyntaxException.ThrowNonCollectionIndex( t );
if (node.EqualityTypeConvert is not ExpCollectionBase) {
ExpInvalidSyntaxException.ThrowNonCollectionIndex(t);
}
}
_cache.PushOperator( t );
_cache.IncreaseDepth( ( int )ExpCompileStateCode.CollectionIndex );
_cache.PushOperator(t);
_cache.IncreaseDepth((int)ExpCompileStateCode.CollectionIndex);
return true;
}
private bool TryAppendIndexRight( Token t )
private bool TryAppendIndexRight(Token t)
{
if( t.Flag != TokenFlag.Index_Right ) {
if (t.Flag != TokenFlag.Index_Right) {
return false;
}
//reverse building
ClosePrefixReverse( t );
// reverse building
ClosePrefixReverse(t);
//make index node
_cache.PopOperand( out _, out ExpSyntaxNode? expNode );
if( !_cache.PopOperand( out Token colleToken, out ExpSyntaxNode? colleNode ) ) { }
// make index node
_cache.PopOperand(out _, out ExpSyntaxNode? expNode);
if (!_cache.PopOperand(out Token colleToken, out ExpSyntaxNode? colleNode)) { }
_cache.PushOperand(
ExpCollectionIndexNode.Create(
t, ( colleNode as ExpCollectionInstanceBase )!, expNode ) );
t, (colleNode as ExpCollectionInstanceBase)!, expNode));
return true;
}
private bool TryAppendMember( Token t )
private bool TryAppendMember(Token t)
{
if( t.Flag != TokenFlag.Member ) {
if (t.Flag != TokenFlag.Member) {
return false;
}
if( TryParseConstant( t ) ) {
if (TryParseConstant(t)) {
return true;
}
if( TryParseFunction( t ) ) {
if (TryParseFunction(t)) {
return true;
}
if( TryParseInstance( t ) ) {
if (TryParseInstance(t)) {
return true;
}
if( TryParseKeyword( t ) ) {
if (TryParseKeyword(t)) {
return true;
}
if( TryParseElementName( t ) ) {
if (TryParseElementName(t)) {
return true;
}
//Many thing miss here
_cache.PushOperand( ExpElementMemberNameNode.Create( t ) );
// Many thing miss here
_cache.PushOperand(ExpElementMemberNameNode.Create(t));
return true;
}
private bool TryAppendMiddleSeparator( Token t )
private bool TryAppendMiddleSeparator(Token t)
{
if( t.Flag != TokenFlag.Separator_Middle ) {
if (t.Flag != TokenFlag.Separator_Middle) {
return false;
}
while( _cache.OperatorAheadOfDepth > 0 )
while (_cache.OperatorAheadOfDepth > 0)
{
_cache.TryPopOperator( out Token op );
ExpSyntaxNode node = ConvertAndPushOneOperator( op );
_cache.TryPopOperator(out Token op);
ExpSyntaxNode node = ConvertAndPushOneOperator(op);
}
switch( _cache.OperandAheadOfDepth )
switch (_cache.OperandAheadOfDepth)
{
case 0:
if( t.Value == ";" ) {
if (t.Value == ";") {
return true;
}
_cache.StatementsInDepth.Push( ExpSyntaxNode.Empty );
_cache.StatementsInDepth.Push(ExpSyntaxNode.Empty);
goto case 1;
case 1:
_cache.PopOperand( out _, out ExpSyntaxNode? statement );
_cache.StatementsInDepth.Push( statement );
_cache.PopOperand(out _, out ExpSyntaxNode? statement);
_cache.StatementsInDepth.Push(statement);
return true;
default:
ExpInvalidSyntaxException.ThrowNoOperator( t );
ExpInvalidSyntaxException.ThrowNoOperator(t);
break;
}
return true;
}
private bool TryAppendNumAndStrLiteral( Token t )
private bool TryAppendNumAndStrLiteral(Token t)
{
if( ( t.Flag & ( TokenFlag.String | TokenFlag.Number ) ) == 0 ) {
if ((t.Flag & (TokenFlag.String | TokenFlag.Number)) == 0) {
return false;
}
_cache.PushOperand( ExpElementInstance.CreateLiteral( t ) );
_cache.PushOperand(ExpElementInstance.CreateLiteral(t));
return true;
}
private bool TryAppendPrefixSeparator( Token t )
private bool TryAppendPrefixSeparator(Token t)
{
if( t.Flag != TokenFlag.Separator_Left ) {
if (t.Flag != TokenFlag.Separator_Left) {
return false;
}
_cache.PushOperator( t );
_cache.IncreaseDepth( ( int )ExpCompileStateCode.Common );
_cache.PushOperator(t);
_cache.IncreaseDepth((int)ExpCompileStateCode.Common);
return true;
}
private bool TryAppendPrefixSeparatorEnd( Token t )
private bool TryAppendPrefixSeparatorEnd(Token t)
{
if( t.Flag != TokenFlag.Separator_Right ) {
if (t.Flag != TokenFlag.Separator_Right) {
return false;
}
ClosePrefixReverse( t );
ClosePrefixReverse(t);
return true;
}
private bool TryAppendSymbol( Token t )
private bool TryAppendSymbol(Token t)
{
if( ( t.Flag & ( TokenFlag.Symbol_Unary | TokenFlag.Symbol_Binary ) ) == 0 ) {
if ((t.Flag & (TokenFlag.Symbol_Unary | TokenFlag.Symbol_Binary)) == 0) {
return false;
}
int cmp = -1;
processPrecedence:
if( _cache.TryPeekOperator( out Token tmp ) )
if (_cache.TryPeekOperator(out Token tmp))
{
cmp = CompareOperatorPrecedence( t, tmp );
if( cmp >= 0 )
cmp = CompareOperatorPrecedence(t, tmp);
if (cmp >= 0)
{
_cache.PopOperator();
ExpSyntaxNode node = ConvertAndPushOneOperator( tmp );
ExpSyntaxNode node = ConvertAndPushOneOperator(tmp);
goto processPrecedence;
}
}
_cache.PushOperator( t );
_cache.PushOperator(t);
return true;
}
private bool TryParseConstant( Token t )
private bool TryParseConstant(Token t)
{
switch( t.Value )
switch (t.Value)
{
case ExpKeyword.E:
_cache.PushOperand( new ExpRealNumberNode( t, MathF.E, true ) );
_cache.PushOperand(new ExpRealNumberNode(t, MathF.E, true));
return true;
case ExpKeyword.Pi:
_cache.PushOperand( new ExpRealNumberNode( t, MathF.PI, true ) );
_cache.PushOperand(new ExpRealNumberNode(t, MathF.PI, true));
return true;
default:
if( ExpElementInstance.TryCreateLiteral( t, out ExpElementInstance? node ) )
if (ExpElementInstance.TryCreateLiteral(t, out ExpElementInstance? node))
{
_cache.PushOperand( node );
_cache.PushOperand(node);
return true;
}
return false;
}
}
private bool TryParseElementName( Token t )
private bool TryParseElementName(Token t)
{
if( _context.TryGetType( t.Value, out ExpTypeSource? type ) )
if (_context.TryGetType(t.Value, out ExpTypeSource? type))
{
_cache.PushOperand( ExpMetaRefNode.RefType( t, type ) );
_cache.PushOperand(ExpMetaRefNode.RefType(t, type));
return true;
}
if( _context.TryGetEntity( t.Value, out ExpEntitySource? entity ) )
if (_context.TryGetEntity(t.Value, out ExpEntitySource? entity))
{
_cache.PushOperand( ExpMetaRefNode.RefEntity( t, entity ) );
_cache.PushOperand(ExpMetaRefNode.RefEntity(t, entity));
return true;
}
return false;
}
private bool TryParseFunction( Token t )
private bool TryParseFunction(Token t)
{
if( ExpKeyword.BuiltinFunctions.Contains( t.Value ) )
if (ExpKeyword.BuiltinFunctions.Contains(t.Value))
{
_cache.PushOperator( t );
_cache.PushOperator(t);
return true;
} else if( _context.TryGetFunction( t.Value, out ExpFunctionSource? f ) )
} else if (_context.TryGetFunction(t.Value, out ExpFunctionSource? f))
{
_cache.PushOperand( t );
_cache.PushOperand(t);
return true;
}
return false;
}
private bool TryParseInstance( Token t )
private bool TryParseInstance(Token t)
{
if( _local.TryGetMember( t.Value,
out ExpSyntaxNode? node ) &&
node is ExpElementInstance instance )
if (_local.TryGetMember(t.Value,
out ExpSyntaxNode? node) &&
node is ExpElementInstance instance)
{
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
_cache.PushOperand(ExpInstanceReferenceNode.MakeReferenceFrom(t, instance));
return true;
} else if( _tempVariableInLoops.TryGetValue( t.Value, out instance! ) )
} else if (_tempVariableInLoops.TryGetValue(t.Value, out instance!))
{
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
_cache.PushOperand(ExpInstanceReferenceNode.MakeReferenceFrom(t, instance));
return true;
} else if( _cache.IsLastAddedOperator )
} else if (_cache.IsLastAddedOperator)
{
if( _cache.PeekOperand( out _,
out ExpSyntaxNode? typenode ) &&
typenode is ExpMetaRefNode typeRef )
if (_cache.PeekOperand(out _,
out ExpSyntaxNode? typenode) &&
typenode is ExpMetaRefNode typeRef)
{
_cache.PopOperand( out _, out _ );
_local.AddMember( t.Value, typeRef.SourceRef.CreateInstanceNode( t ) );
_cache.PopOperand(out _, out _);
_local.AddMember(t.Value, typeRef.SourceRef.CreateInstanceNode(t));
} else
{
return false;
@@ -274,15 +271,15 @@ namespace StgSharp.Script.Express
return false;
}
private bool TryParseKeyword( Token t )
private bool TryParseKeyword(Token t)
{
switch( t.Value )
switch (t.Value)
{
case ExpKeyword.Return:
_cache.PushOperator( t );
_cache.PushOperator(t);
return true;
case ExpKeyword.Skip:
_cache.PushOperand( ExpProcedureControlNode.Skip( t ) );
_cache.PushOperand(ExpProcedureControlNode.Skip(t));
return true;
default:
return false;