Daily update on 20250330-080745 by Nitload Youmu. Additional Message : CASEOF block in full function, next is Collection operation, relative keywords processing and REPEAT block.
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -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+36b6ad5a526ca6ef66d826f614e8476a99fe52f7")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+17a226c20653a1c92f6a3b420d6388c31f6a8c1e")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Model")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/36b6ad5a526ca6ef66d826f614e8476a99fe52f7/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/17a226c20653a1c92f6a3b420d6388c31f6a8c1e/*"}}
|
||||
@@ -29,6 +29,7 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@@ -37,27 +38,75 @@ namespace StgSharp.Script.Express
|
||||
public class ExpSwitchNode : ExpNode
|
||||
{
|
||||
|
||||
private Dictionary<ExpNode, ExpNode> _cases;
|
||||
private ExpNode _default;
|
||||
private ExpNode _target;
|
||||
|
||||
private FrozenDictionary<ExpNode, ExpNode> _cases;
|
||||
|
||||
public ExpSwitchNode(
|
||||
Token source,
|
||||
ExpNode target,
|
||||
ExpNode defaultCase,
|
||||
params (ExpNode label, ExpNode op)[] cases )
|
||||
Token source,
|
||||
ExpNode target,
|
||||
ExpNode defaultCase,
|
||||
params (ExpNode label, ExpNode op)[] cases )
|
||||
: base( source )
|
||||
{
|
||||
_target = target;
|
||||
_default = defaultCase;
|
||||
_cases = new Dictionary<ExpNode, ExpNode>();
|
||||
foreach( (ExpNode label, ExpNode op ) item in cases ) {
|
||||
if( item.op == null ) {
|
||||
_cases.Add( item.label, null! );
|
||||
} else {
|
||||
_cases.Add( item.label, item.op );
|
||||
Dictionary<ExpNode, ExpNode> casesDic = new Dictionary<ExpNode, ExpNode>();
|
||||
foreach( (ExpNode label, ExpNode op ) item in cases )
|
||||
{
|
||||
if( item.op == null )
|
||||
{
|
||||
casesDic.Add( item.label, null! );
|
||||
} else
|
||||
{
|
||||
casesDic.Add( item.label, item.op );
|
||||
}
|
||||
}
|
||||
_cases = casesDic.ToFrozenDictionary();
|
||||
|
||||
|
||||
string str = @"switch( {0} ){";
|
||||
StringBuilder codeFormatBuilder = new StringBuilder();
|
||||
codeFormatBuilder.AppendLine( str );
|
||||
for( int i = 0; i < casesDic.Count; i++ )
|
||||
{
|
||||
int index = i * 2 + 1;
|
||||
codeFormatBuilder.AppendLine(
|
||||
$$"""
|
||||
case {{{index}}}:
|
||||
{{{index + 1}}}
|
||||
break;
|
||||
""" );
|
||||
}
|
||||
CodeConvertTemplate = codeFormatBuilder.ToString();
|
||||
}
|
||||
|
||||
public ExpSwitchNode(
|
||||
Token source,
|
||||
ExpNode target,
|
||||
ExpNode defaultCase,
|
||||
IDictionary<ExpNode, ExpNode> cases )
|
||||
: base( source )
|
||||
{
|
||||
_target = target;
|
||||
_default = defaultCase;
|
||||
_cases = cases.ToFrozenDictionary();
|
||||
|
||||
string str = @"switch( {0} ){";
|
||||
StringBuilder codeFormatBuilder = new StringBuilder();
|
||||
codeFormatBuilder.AppendLine( str );
|
||||
for( int i = 0; i < cases.Count; i++ )
|
||||
{
|
||||
int index = i * 2 + 1;
|
||||
codeFormatBuilder.AppendLine(
|
||||
$$"""
|
||||
case {{{index}}}:
|
||||
{{{index + 1}}}
|
||||
break;
|
||||
""" );
|
||||
}
|
||||
CodeConvertTemplate = codeFormatBuilder.ToString();
|
||||
}
|
||||
|
||||
public ExpNode this[ ExpNode index ]
|
||||
@@ -71,37 +120,12 @@ namespace StgSharp.Script.Express
|
||||
}
|
||||
}
|
||||
|
||||
public override ExpNode Left => throw new NotImplementedException();
|
||||
public override ExpNode Left => Empty;
|
||||
|
||||
public override ExpNode Right => throw new NotImplementedException();
|
||||
public override ExpNode Right => Empty;
|
||||
|
||||
public override IExpElementSource EqualityTypeConvert => null!;
|
||||
|
||||
public void AddOperationToDefault( ExpNode expressionRoot )
|
||||
{
|
||||
if( expressionRoot != null ) {
|
||||
_default.AppendNode( expressionRoot );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an expression to certain <see langword="case" />. The added expression will be run
|
||||
/// at last.
|
||||
/// </summary>
|
||||
/// <param name="label"> Label of case to add operation </param>
|
||||
/// <param name="expressionRoot"> Root token of the expression to be added. </param>
|
||||
/// <exception cref="ExpCaseNotFoundException"> Cannot fine the case label in current witch expression. </exception>
|
||||
public void AppendOperationToCase(
|
||||
ExpNode label,
|
||||
ExpNode expressionRoot )
|
||||
{
|
||||
if( _cases.TryGetValue( label, out ExpNode? op ) ) {
|
||||
op.AppendNode( expressionRoot );
|
||||
} else {
|
||||
throw new ExpCaseNotFoundException( this, label );
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsCase( ExpNode token )
|
||||
{
|
||||
return _cases.ContainsKey( token );
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpSyntaxAnalyzer.CaseOf.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.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public partial class ExpSyntaxAnalyzer
|
||||
{
|
||||
|
||||
private bool AppendToken_CaseOf( Token t )
|
||||
{
|
||||
Token op;
|
||||
ExpNode root;
|
||||
switch( t.Value )
|
||||
{
|
||||
case ExpKeyword.Case:
|
||||
CaseOfStateCache state = new CaseOfStateCache( t );
|
||||
_cache.CurrentDepthMark.StateCache = state;
|
||||
state.CurrentState = t.Value;
|
||||
return true;
|
||||
case ExpKeyword.Of:
|
||||
state = _cache.StateOfCurrentDepth<CaseOfStateCache>();
|
||||
while( _cache.TryPopOperator( out op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
_cache.PopOperand( out _, out root );
|
||||
state.CaseExpression = root;
|
||||
state.CurrentState = t.Value;
|
||||
return true;
|
||||
case ":":
|
||||
state = _cache.StateOfCurrentDepth<CaseOfStateCache>();
|
||||
if( state.CurrentState != ExpKeyword.Of && state.CurrentState !=
|
||||
ExpKeyword.Otherwise )
|
||||
{
|
||||
root = _cache.PackAllStatements();
|
||||
state.CloseCurrentCase( root );
|
||||
}
|
||||
while( _cache.TryPopOperator( out op ) ) {
|
||||
ConvertAndPushOneOperator( op );
|
||||
}
|
||||
if( !_cache.PopOperand( out _, out root ) )
|
||||
{
|
||||
// sth wrong, case expression cannot generate;
|
||||
}
|
||||
state.CurrentCase = root;
|
||||
return true;
|
||||
case ExpKeyword.Otherwise:
|
||||
state = _cache.StateOfCurrentDepth<CaseOfStateCache>();
|
||||
root = _cache.PackAllStatements();
|
||||
state.CloseCurrentCase( root );
|
||||
state.CurrentState = t.Value;
|
||||
return true;
|
||||
case ExpKeyword.EndCase:
|
||||
state = _cache.StateOfCurrentDepth<CaseOfStateCache>();
|
||||
root = _cache.PackAllStatements();
|
||||
state.CloseCurrentCase( root );
|
||||
root = new ExpSwitchNode(
|
||||
state.Begin, state.CaseExpression, state.DefaultCase, state.Cases );
|
||||
_cache.DecreaseDepth();
|
||||
_cache.StatementsInDepth.Push( root );
|
||||
return true;
|
||||
default:
|
||||
AppendToken_common( t );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class CaseOfStateCache : ICompileDepthState
|
||||
{
|
||||
|
||||
public CaseOfStateCache( Token t )
|
||||
{
|
||||
Begin = t;
|
||||
}
|
||||
|
||||
public Dictionary<ExpNode, ExpNode> Cases { get; } = new Dictionary<ExpNode, ExpNode>();
|
||||
|
||||
public ExpNode CaseExpression { get; set; }
|
||||
|
||||
public ExpNode DefaultCase { get; set; }
|
||||
|
||||
public ExpNode CurrentCase { get; set; }
|
||||
|
||||
public string CurrentState { get; set; }
|
||||
|
||||
public Token Begin { get; init; }
|
||||
|
||||
public void CloseCurrentCase( ExpNode root )
|
||||
{
|
||||
Cases.Add( CurrentCase, root );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,6 @@ namespace StgSharp.Script.Express
|
||||
state.ExpressionIfFalse );
|
||||
_cache.DecreaseDepth();
|
||||
_cache.StatementsInDepth.Push( ifNode );
|
||||
_cache.PushOperand( ifNode );
|
||||
return true;
|
||||
default:
|
||||
AppendToken_common( t );
|
||||
|
||||
@@ -84,6 +84,9 @@ namespace StgSharp.Script.Express
|
||||
case ExpCompileStateCode.IfBranch:
|
||||
AppendToken_IfBranch( expToken );
|
||||
break;
|
||||
case ExpCompileStateCode.CaseBranch:
|
||||
AppendToken_CaseOf( expToken );
|
||||
break;
|
||||
default:
|
||||
AppendToken_common( expToken );
|
||||
break;
|
||||
|
||||
@@ -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+36b6ad5a526ca6ef66d826f614e8476a99fe52f7")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+17a226c20653a1c92f6a3b420d6388c31f6a8c1e")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/36b6ad5a526ca6ef66d826f614e8476a99fe52f7/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/17a226c20653a1c92f6a3b420d6388c31f6a8c1e/*"}}
|
||||
@@ -126,11 +126,15 @@ namespace StgSharp
|
||||
(**)
|
||||
a := b + (c + d) - a;
|
||||
IF a = b THEN
|
||||
a := a * e;
|
||||
a := a * a;
|
||||
ELSE
|
||||
a := c * e;
|
||||
a := c * a;
|
||||
END_IF
|
||||
(**)
|
||||
CASE a OF
|
||||
1 : a := 1 + e ;
|
||||
OTHERWISE : a:=a;
|
||||
END_CASE
|
||||
""";
|
||||
|
||||
public static void ExpLinearExpressionTest()
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+36b6ad5a526ca6ef66d826f614e8476a99fe52f7")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+17a226c20653a1c92f6a3b420d6388c31f6a8c1e")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/36b6ad5a526ca6ef66d826f614e8476a99fe52f7/*"}}
|
||||
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/17a226c20653a1c92f6a3b420d6388c31f6a8c1e/*"}}
|
||||
Reference in New Issue
Block a user