Daily update on 20250407-000601 by Nitload Youmu. Additional Message : Repeat block analyzer complete, need unit test. collection processor, builtin function, procedure caller and element source parser will be implemented
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -33,6 +33,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Channels;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
@@ -44,46 +45,13 @@ namespace StgSharp.Script.Express
|
||||
|
||||
internal ExpRepeatNode(
|
||||
Token source,
|
||||
ExpNode operationBegin,
|
||||
ExpElementInstance variable,
|
||||
ExpNode begin,
|
||||
ExpNode end )
|
||||
: base( source )
|
||||
{
|
||||
ExpNode increment;
|
||||
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any )
|
||||
{
|
||||
case ExpNodeFlag.BuiltinType_Real:
|
||||
increment = new ExpRealNumberNode(
|
||||
new Token(
|
||||
ExpressCompile.PoolString( "1.0f" ), source.Line, -1,
|
||||
TokenFlag.Number ),
|
||||
1.0f, isLiteral: true );
|
||||
break;
|
||||
case ExpNodeFlag.BuiltinType_Int:
|
||||
increment = new ExpIntNode(
|
||||
new Token(
|
||||
ExpressCompile.PoolString( "1" ), source.Line, -1, TokenFlag.Number ),
|
||||
1, isLiteral: true );
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException( "Int or Real", "otherwise" );
|
||||
}
|
||||
_begin = begin;
|
||||
_variable = variable;
|
||||
_end = end;
|
||||
_increment = increment;
|
||||
_nodeFlag = ExpNodeFlag.Branch_Repeat;
|
||||
_operationBegin = operationBegin;
|
||||
}
|
||||
|
||||
internal ExpRepeatNode(
|
||||
Token source,
|
||||
ExpNode operationBegin,
|
||||
ExpElementInstance variable,
|
||||
ExpNode begin,
|
||||
ExpNode end,
|
||||
ExpNode increment )
|
||||
ExpNode increment,
|
||||
ExpNode operationBegin,
|
||||
ExpNode untilRule,
|
||||
ExpNode whileRule )
|
||||
: base( source )
|
||||
{
|
||||
if( variable.NodeFlag != begin.NodeFlag || begin.NodeFlag != end.NodeFlag || ( increment !=
|
||||
@@ -91,13 +59,35 @@ namespace StgSharp.Script.Express
|
||||
increment.NodeFlag ) ) {
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull( increment );
|
||||
_begin = begin;
|
||||
if( ExpNode.IsNullOrEmpty( increment ) )
|
||||
{
|
||||
switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any )
|
||||
{
|
||||
case ExpNodeFlag.BuiltinType_Real:
|
||||
increment = new ExpRealNumberNode(
|
||||
new Token(
|
||||
ExpressCompile.PoolString( "1.0f" ), source.Line, -1,
|
||||
TokenFlag.Number ),
|
||||
1.0f, isLiteral: true );
|
||||
break;
|
||||
case ExpNodeFlag.BuiltinType_Int:
|
||||
increment = new ExpIntNode(
|
||||
new Token(
|
||||
ExpressCompile.PoolString( "1" ), source.Line, -1,
|
||||
TokenFlag.Number ),
|
||||
1, isLiteral: true );
|
||||
break;
|
||||
default:
|
||||
throw new ExpInvalidTypeException( "Int or Real", "otherwise" );
|
||||
}
|
||||
}
|
||||
_variable = variable;
|
||||
_begin = begin;
|
||||
_end = end;
|
||||
_increment = increment;
|
||||
_nodeFlag = ExpNodeFlag.Branch_Repeat;
|
||||
_operationBegin = operationBegin;
|
||||
_untilRule = untilRule;
|
||||
_whileRule = whileRule;
|
||||
}
|
||||
|
||||
public override ExpNode Left => throw new NotImplementedException();
|
||||
@@ -111,45 +101,40 @@ namespace StgSharp.Script.Express
|
||||
_operationBegin.AppendNode( node );
|
||||
}
|
||||
|
||||
public static ExpRepeatNode Create(
|
||||
Token t,
|
||||
ExpElementInstance repeatVariable,
|
||||
ExpNode begin,
|
||||
ExpNode end,
|
||||
ExpNode repeatBody )
|
||||
{
|
||||
string typename = repeatVariable.NodeFlag.ToString();
|
||||
ExpRepeatNode ret = new ExpRepeatNode( t, repeatBody, repeatVariable, begin, end, null )
|
||||
{
|
||||
/*
|
||||
* 0 increment variable type
|
||||
* 1: variable name
|
||||
* 2: beginning value
|
||||
* 3: ending value
|
||||
* 4: increment
|
||||
* 5: body
|
||||
*/
|
||||
CodeConvertTemplate = $$"""
|
||||
for({{0}} {{1}} = {{2}}; {{1}} <= {{3}}; {{1}} += {{4}})
|
||||
{
|
||||
{{5}}
|
||||
}
|
||||
"""
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an AST node for repeat expression in EXPRESS language. The loop does not has
|
||||
/// WHILE and UNTIL regulation.
|
||||
/// </summary>
|
||||
/// <param name="t">
|
||||
/// Position of the loop
|
||||
/// </param>
|
||||
/// <param name="repeatVariable">
|
||||
///
|
||||
/// </param>
|
||||
/// <param name="begin">
|
||||
///
|
||||
/// </param>
|
||||
/// <param name="end">
|
||||
///
|
||||
/// </param>
|
||||
/// <param name="repeatBody">
|
||||
///
|
||||
/// </param>
|
||||
/// <returns>
|
||||
///
|
||||
/// </returns>
|
||||
public static ExpRepeatNode Create(
|
||||
Token t,
|
||||
ExpElementInstance repeatVariable,
|
||||
ExpNode begin,
|
||||
ExpNode end,
|
||||
ExpNode increment,
|
||||
ExpNode whileRule,
|
||||
ExpNode untilRule,
|
||||
ExpNode body )
|
||||
{
|
||||
ExpRepeatNode ret = new ExpRepeatNode( t, body, repeatVariable, begin, end, increment )
|
||||
ExpNode untilRule = ExpBoolNode.False( null );
|
||||
ExpNode whileRule = ExpBoolNode.True( null );
|
||||
ExpRepeatNode ret = new ExpRepeatNode(
|
||||
t, repeatVariable, begin, end, increment, body, whileRule, untilRule )
|
||||
{
|
||||
/*
|
||||
* 0 increment variable type
|
||||
@@ -166,7 +151,44 @@ namespace StgSharp.Script.Express
|
||||
{
|
||||
if(!( {{6}} )) break;
|
||||
{{5}}
|
||||
if(!( {{7}} )) break;
|
||||
if( {{7}} ) break;
|
||||
}
|
||||
"""
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ExpRepeatNode Create(
|
||||
Token t,
|
||||
ExpElementInstance repeatVariable,
|
||||
ExpNode begin,
|
||||
ExpNode end,
|
||||
ExpNode increment,
|
||||
ExpNode whileRule,
|
||||
ExpNode untilRule,
|
||||
ExpNode body )
|
||||
{
|
||||
whileRule = IsNullOrEmpty( whileRule ) ? ExpBoolNode.True( t ) : whileRule;
|
||||
untilRule = IsNullOrEmpty( untilRule ) ? ExpBoolNode.False( t ) : untilRule;
|
||||
ExpRepeatNode ret = new ExpRepeatNode(
|
||||
t, repeatVariable, begin, end, increment, body, whileRule, untilRule )
|
||||
{
|
||||
/*
|
||||
* 0 increment variable type
|
||||
* 1: variable name
|
||||
* 2: beginning value
|
||||
* 3: ending value
|
||||
* 4: increment
|
||||
* 5: body
|
||||
* 6: while
|
||||
* 7: until
|
||||
*/
|
||||
CodeConvertTemplate = $$"""
|
||||
for({{0}} {{1}} = {{2}}; {{1}} <= {{3}}; {{1}} += {{4}})
|
||||
{
|
||||
if(!( {{6}} )) break;
|
||||
{{5}}
|
||||
if( {{7}} ) break;
|
||||
}
|
||||
"""
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user