add from giga-device, new branch added

This commit is contained in:
Nitload Youmu
2025-08-21 16:51:25 +08:00
commit 43bbc06bbb
1296 changed files with 264186 additions and 0 deletions
@@ -0,0 +1,60 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="AbstractSyntaxTree.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.Collections;
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Schema;
namespace StgSharp.Script
{
public sealed class AbstractSyntaxTree<TNode, TType> where TNode: ISyntaxNode<TNode, TType>
where TType: ITypeSource<TType>
{
private List<TNode> _allToken = new();
private TNode _root;
public int Count
{
get { return _allToken.Count; }
}
public TNode Root => _root;
public bool Contains( TNode node )
{
return _allToken.Contains( node );
}
}
}
+103
View File
@@ -0,0 +1,103 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="CodeLineHelper.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.Text;
namespace StgSharp.Script
{
public static class CodeLineHelper
{
public static string SliceAndTrim( this string line, int startIndex )
{
if( line == null ) {
throw new ArgumentNullException( nameof( line ) );
}
if( startIndex < 0 || startIndex >= line.Length ) {
throw new ArgumentOutOfRangeException( nameof( startIndex ) );
}
ReadOnlySpan<char> sourceSpan = line.AsSpan();
ReadOnlySpan<char> subSpan = sourceSpan.Slice( startIndex );
int start = 0;
while( start < subSpan.Length && char.IsWhiteSpace( subSpan[ start ] ) ) {
start++;
}
int end = subSpan.Length - 1;
while( end >= start && char.IsWhiteSpace( subSpan[ end ] ) ) {
end--;
}
if( start > end ) {
return string.Empty;
}
int finalLength = end - start + 1;
return new string( subSpan.Slice( start, finalLength ) );
}
public static string SliceAndTrim( this string line, int startIndex, int length )
{
if( line == null ) {
throw new ArgumentNullException( nameof( line ) );
}
if( startIndex < 0 || startIndex >= line.Length ) {
throw new ArgumentOutOfRangeException( nameof( startIndex ) );
}
if( length < 0 || startIndex + length > line.Length ) {
throw new ArgumentOutOfRangeException( nameof( length ) );
}
ReadOnlySpan<char> sourceSpan = line.AsSpan();
ReadOnlySpan<char> subSpan = sourceSpan.Slice( startIndex, length );
int start = 0;
while( start < subSpan.Length && char.IsWhiteSpace( subSpan[ start ] ) ) {
start++;
}
int end = subSpan.Length - 1;
while( end >= start && char.IsWhiteSpace( subSpan[ end ] ) ) {
end--;
}
if( start > end ) {
return string.Empty;
}
int finalLength = end - start + 1;
return new string( subSpan.Slice( start, finalLength ) );
}
}
}
@@ -0,0 +1,80 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="CompileDepthState.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.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script
{
public interface ICompileDepthState
{
string CurrentState { get; set; }
}
public class CompileDepthMark
{
internal CompileDepthMark( int operatorBegin, int operandBegin, int usage )
{
OperatorBegin = operatorBegin;
OperandBegin = operandBegin;
Usage = usage;
}
internal CompileDepthMark(
int operatorBegin,
int operandBegin,
int usage,
ICompileDepthState stateCache )
{
OperatorBegin = operatorBegin;
OperandBegin = operandBegin;
Usage = usage;
StateCache = stateCache;
}
public bool IsBeginOfBlock { get; internal set; }
public ICompileDepthState StateCache { get; internal set; }
public int OperandBegin { get; internal set; }
public int OperatorBegin { get; internal set; }
public int Usage { get; internal set; }
}
}
+336
View File
@@ -0,0 +1,336 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="CompileStack.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.Collections;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script
{
public partial class CompileStack<TNode, TType> where TNode: ISyntaxNode<TNode, TType>
where TType: ITypeSource<TType>
{
private Token? _lastToken;
private TNode[] _nodeArray = new TNode[4];
private Token[] _operatorArray = new Token[4];
private Token[] _tokenArray = new Token[4];
private int _nodeCount,_tokenCount, _operatorCount;
private RandomAccessibleStack<CompileDepthMark> _depthStack = new RandomAccessibleStack<CompileDepthMark>(
);
private RandomAccessibleStack<OperandIndex> _isNode = new RandomAccessibleStack<OperandIndex>(
8 );
private Stack<Stack<TNode>> _statementCache = new Stack<Stack<TNode>>();
private TNode _lastNode;
public CompileStack()
{
_depthStack.Push( new CompileDepthMark( 0, 0, 0, null! ) );
_statementCache.Push( new Stack<TNode>() );
}
public bool IsLastAddedOperator { get; private set; }
public CompileDepthMark CurrentDepthMark
{
get => _depthStack.Peek();
}
public int Depth => _depthStack.Count;
public int OperandCount => _isNode.Count;
public int OperatorCount => _operatorCount;
public int OperatorAheadOfDepth
{
get => OperatorCount - _depthStack.Peek().OperatorBegin;
}
public int OperandAheadOfDepth
{
get => OperandCount - _depthStack.Peek().OperandBegin;
}
public Stack<TNode> StatementsInDepth
{
get => _statementCache.Peek();
}
public void DecreaseDepth()
{
CompileDepthMark mark = _depthStack.Pop();
Stack<TNode> statementsInDepth = _statementCache.Pop();
}
public bool GetOperandAt( Index i, out TNode operandNode, out Token operandToken )
{
OperandIndex index = _isNode[ i ];
if( index.IsNode )
{
operandNode = _nodeArray[ index.Index ];
operandToken = Token.Empty;
return true;
} else
{
operandToken = _tokenArray[ index.Index ];
operandNode = default!;
return false;
}
}
public bool GetOperandAt(
CompileDepthMark depth,
Index i,
out Token operandToken,
out TNode operandNode )
{
OperandIndex index = _isNode[ i ];
_depthStack.Contains( depth );
if( index.IsNode )
{
operandNode = _nodeArray[ index.Index ];
operandToken = Token.Empty;
return true;
} else
{
operandToken = _tokenArray[ index.Index ];
operandNode = default!;
return false;
}
}
public CompileDepthMark IncreaseDepth( int usage )
{
CompileDepthMark mark =
new CompileDepthMark( OperatorCount, OperandCount, usage );
_depthStack.Push( mark );
_statementCache.Push( new Stack<TNode>() );
return mark;
}
public TNode PackAllStatements()
{
if( StatementsInDepth.Count == 0 ) {
return TNode.Empty;
}
TNode end = StatementsInDepth.Peek();
TNode first = end;
while( StatementsInDepth.Count > 0 )
{
first = StatementsInDepth.Pop();
end.PrependNode( first );
end = first;
}
return first;
}
public bool PeekOperand( out Token t, out TNode n )
{
if( OperandAheadOfDepth <= 0 )
{
t = Token.Empty;
n = TNode.Empty;
return false;
}
if( _isNode.Pop().IsNode )
{
t = Token.Empty;
n = _nodeArray[ _nodeCount - 1 ];
return true;
} else
{
t = _tokenArray[ _tokenCount - 1 ];
n = TNode.Empty;
return false;
}
}
public Token PeekOperator()
{
if( OperatorAheadOfDepth > 0 ) {
return _operatorArray[ _operatorCount - 1 ];
}
return Token.Empty;
}
public bool PopOperand( out Token t, out TNode n )
{
if( OperandAheadOfDepth <= 0 )
{
t = Token.Empty;
n = TNode.Empty;
return false;
}
if( _isNode.Pop().IsNode )
{
t = Token.Empty;
n = _nodeArray[ --_nodeCount ];
return true;
} else
{
t = _tokenArray[ --_tokenCount ];
n = TNode.Empty;
return false;
}
}
public Token PopOperator()
{
if( OperatorAheadOfDepth > 0 )
{
_operatorCount--;
return _operatorArray[ _operatorCount ];
}
return Token.Empty;
}
public void PushOperand( TNode node )
{
if( _nodeArray.Length == _nodeCount ) {
Array.Resize( ref _nodeArray, _nodeArray.Length * 2 );
}
_nodeArray[ _nodeCount ] = node;
_isNode.Push( new( true, _nodeCount ) );
_nodeCount++;
IsLastAddedOperator = false;
}
public void PushOperand( Token token )
{
if( _tokenArray.Length == _tokenCount ) {
Array.Resize( ref _tokenArray, _tokenArray.Length * 2 );
}
_tokenArray[ _tokenCount ] = token;
_isNode.Push( new( false, _tokenCount ) );
_tokenCount++;
IsLastAddedOperator = false;
}
public void PushOperator( Token token )
{
if( _operatorArray.Length == _operatorCount ) {
Array.Resize( ref _operatorArray, _operatorArray.Length * 2 );
}
_operatorArray[ _operatorCount ] = token;
_operatorCount++;
IsLastAddedOperator = true;
}
public T StateOfCurrentDepth<T>() where T: class, ICompileDepthState
{
return ( CurrentDepthMark.StateCache as T )!;
}
public bool TryPeekOperand( out bool isNode, out Token t, out TNode n )
{
if( OperandAheadOfDepth <= 0 )
{
t = Token.Empty;
n = TNode.Empty;
isNode = false;
return false;
}
if( _isNode.Pop().IsNode )
{
t = Token.Empty;
n = _nodeArray[ _nodeCount - 1 ];
isNode = true;
return true;
} else
{
t = _tokenArray[ _tokenCount - 1 ];
n = TNode.Empty;
isNode = false;
return false;
}
}
public bool TryPeekOperator( out Token op )
{
if( OperatorAheadOfDepth > 0 )
{
op = _operatorArray[ _operatorCount - 1 ];
return true;
}
op = Token.Empty;
return false;
}
public bool TryPopOperand( out bool isNode, out Token t, out TNode n )
{
if( OperandAheadOfDepth <= 0 )
{
t = Token.Empty;
n = TNode.Empty;
isNode = false;
return false;
}
if( _isNode.Pop().IsNode )
{
t = Token.Empty;
n = _nodeArray[ --_nodeCount ];
isNode = true;
return true;
} else
{
t = _tokenArray[ --_tokenCount ];
n = TNode.Empty;
isNode = false;
return true;
}
}
public bool TryPopOperator( out Token op )
{
if( OperatorAheadOfDepth > 0 )
{
op = _operatorArray[ --_operatorCount ];
return true;
}
op = Token.Empty;
return false;
}
private record struct OperandIndex( bool IsNode, int Index );
}
}
@@ -0,0 +1,62 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IScriptSourceProvider.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.Text;
namespace StgSharp.Script
{
public interface IScriptSourceProvider
{
bool IsEmpty { get; }
int Location { get; }
void EndWriting();
string ReadLine();
string ReadLine( out int position );
/// <summary>
/// Return part of current provider.
/// </summary>
/// <param name="count">
/// Count of lines to be sliced
/// </param>
/// <returns>
///
/// </returns>
public IScriptSourceProvider Slice( int location, int count );
}
}
@@ -0,0 +1,43 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IScriptTokenReader.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Script
{
public interface IScriptTokenReader
{
bool IsEmpty { get; }
Token ReadToken();
bool TryReadToken( out Token t );
}
}
+39
View File
@@ -0,0 +1,39 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ISyntaxAnalyzer.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Script
{
public interface ISyntaxAnalyzer
{
void AppendToken( Token t );
}
}
+69
View File
@@ -0,0 +1,69 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ISyntaxNode.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.Collections;
using StgSharp.Script.Express;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace StgSharp.Script
{
public interface ISyntaxNode<TNode, TType> where TNode: ISyntaxNode<TNode, TType>
where TType: ITypeSource<TType>
{
long NodeFlag { get; }
string CodeConvertTemplate { get; }
TNode Previous { get; set; }
TNode Next { get; set; }
TNode Left { get; }
TNode Right { get; }
static abstract TNode Empty { get; }
Token Source { get; }
TType EqualityTypeConvert { get; }
void AppendNode( TNode nextToken );
void PrependNode( TNode previusNode );
}
}
+45
View File
@@ -0,0 +1,45 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ITypeSource.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script
{
public interface ITypeSource<in TConvert> where TConvert: ITypeSource<TConvert>
{
bool IsConvertable( TConvert targetType );
}
}
@@ -0,0 +1,155 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ScriptSourceTransmitter.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;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace StgSharp.Script
{
/// <summary>
/// Transmit a continuous part of script code to interpreter or compiler. This transmitter is
/// designed for single-thread-write and single-thread read. Any multi thread operation will
/// cause undefined behaviour.
/// </summary>
public class ScriptSourceTransmitter : IScriptSourceProvider
{
private static ScriptSourceTransmitter _empty = new ScriptSourceTransmitter(
string.Empty, 0, 0 )
{
_cache = [],
_buffer = []
};
private string[] _buffer;
private bool _isWriting = true;
private int _begin, _index;
private List<string> _cache;
private readonly string _completeMark;
internal ScriptSourceTransmitter( string[] buffer, int start )
{
_buffer = buffer;
_begin = start;
_isWriting = false;
}
public ScriptSourceTransmitter( string endMark, int start )
{
_cache = new List<string>();
_completeMark = endMark;
_begin = start;
_index = 0;
}
public ScriptSourceTransmitter( string endMark, int start, int capacity )
{
_cache = new List<string>( capacity );
_completeMark = endMark;
_begin = start;
_index = 0;
}
public bool IsEmpty => _isWriting ?
( _cache.Count == 0 ) : ( _buffer.Length == 0 ) || ( _index >= _buffer.Length );
public bool IsFrozen => !_isWriting;
public int Location => _begin + _index;
public static ScriptSourceTransmitter Empty => _empty;
public void EndWriting()
{
if( !_isWriting ) {
return;
}
_isWriting = false;
_buffer = _cache.ToArray();
_cache = null!;
}
public string ReadLine()
{
if( _isWriting ) {
throw new InvalidOperationException( "Cannot read before all writing operation." );
}
if( _index >= _buffer.Length ) {
return string.Empty;
}
string str = _buffer[ _index ];
_index++;
return str;
}
public string ReadLine( out int position )
{
if( _isWriting ) {
throw new InvalidOperationException( "Cannot read before all writing operation." );
}
if( _index >= _buffer.Length )
{
position = -1;
return string.Empty;
}
position = _begin + _index;
string str = _buffer[ _index ];
_index++;
return str;
}
public IScriptSourceProvider Slice( int location, int count )
{
ArgumentOutOfRangeException.ThrowIfLessThan( location, _begin );
ArgumentOutOfRangeException.ThrowIfGreaterThan(
location + count, _begin + _buffer.Length );
return new ScriptSourceTransmitter(
_buffer.AsSpan().Slice( location, count ).ToArray(), location );
}
public void WriteLine( string line )
{
if( !_isWriting ) {
return;
}
if( string.Equals( _completeMark, line ) )
{
EndWriting();
return;
}
_cache.Add( line );
}
}
}
+85
View File
@@ -0,0 +1,85 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Token.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
{
public readonly struct Token
{
private static Token EmptyToken = new Token();
public readonly int Column;
public readonly int Line;
public readonly string Value;
public readonly TokenFlag Flag;
public Token( string chars, int lineNumber, int columnNumber, TokenFlag flag )
{
Value = chars;
Line = lineNumber;
Column = columnNumber;
Flag = flag;
}
public static Token Empty => EmptyToken;
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public Token ReLocate( int line, int column )
{
return new Token( Value, line, column, Flag );
}
}
public enum TokenFlag : int
{
None = 0,
Symbol_Unary = 1,
Symbol_Binary = 2,
Number = 3,
String = 4,
Member = 5,
Separator_Middle = 6,
Separator_Left = 7,
Separator_Right = 8,
Index_Left = 9,
Index_Right = 10,
Enum = 11
}
}
@@ -0,0 +1,58 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpBuiltinType.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.Data;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
internal sealed class ExpBuiltinType : ExpTypeSource
{
private Type _marshalType;
internal ExpBuiltinType( string name, Type origin )
: base( name, ScriptSourceTransmitter.Empty )
{
_marshalType = origin;
}
public override void Analyse()
{
return;
}
//A method convert value to CLR type
//Used for direct running rather than compiling to C# code.
}
}
@@ -0,0 +1,195 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpCollection.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;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpCollectionBase : ExpInstantiableElement, IEnumerable<ExpElementInstance>
{
protected internal string _accurateType;
protected ExpCollectionBase( string accurateType )
{
_accurateType = accurateType;
}
public override ExpElementType ElementType => ExpElementType.Collection;
public abstract int Count { get; }
public override sealed IScriptSourceProvider SourceProvider => ScriptSourceTransmitter.Empty;
public string MemberType
{
get => _accurateType;
}
public override void Analyse()
{
return;
}
public abstract IEnumerator<ExpElementInstance> GetEnumerator();
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
{
memberNode = ExpSyntaxNode.Empty;
return false;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
public class ExpArray : ExpCollectionBase
{
private ExpElementInstance[] _collection;
public ExpArray( string accurateType ) : base( accurateType ) { }
public ExpElementInstance this[ int index ]
{
get { return _collection[ index ]; }
set
{
if( value.TypeName != MemberType ) {
throw new ExpInvalidCollectionMemberTypeException( value, this );
}
_collection[ index ] = value;
}
}
public override int Count => _collection.Length;
public override string Name => ExpressCompile.PoolString( "ARRAY" );
public override ExpSyntaxNode CreateInstanceNode( Token t )
{
throw new NotImplementedException();
}
public override IEnumerator<ExpElementInstance> GetEnumerator()
{
return ( ( IEnumerable<ExpElementInstance> )_collection )
.GetEnumerator();
}
}
public class ExpBag : ExpCollectionBase
{
private ConcurrentBag<ExpElementInstance> _collection = new ConcurrentBag<ExpElementInstance>(
);
public ExpBag( string accurateType ) : base( accurateType ) { }
public override int Count => _collection.Count;
public override string Name => ExpressCompile.PoolString( "BAG" );
public override ExpSyntaxNode CreateInstanceNode( Token t )
{
throw new NotImplementedException();
}
public override IEnumerator<ExpElementInstance> GetEnumerator()
{
return _collection.GetEnumerator();
}
}
public sealed class ExpList : ExpCollectionBase
{
private List<ExpElementInstance> _collection = new List<ExpElementInstance>();
public ExpList( string accurateType ) : base( accurateType ) { }
public override int Count => _collection.Count;
public override string Name => ExpressCompile.PoolString( "LIST" );
public override ExpSyntaxNode CreateInstanceNode( Token t )
{
throw new NotImplementedException();
}
public override IEnumerator<ExpElementInstance> GetEnumerator()
{
return _collection.GetEnumerator();
}
}
public class ExpSet : ExpCollectionBase
{
private HashSet<ExpElementInstance> _collection = new();
public ExpSet( string accurateType ) : base( accurateType ) { }
public override int Count => _collection.Count;
public override string Name => ExpressCompile.PoolString( "SET" );
public void Add( ExpElementInstance token )
{
if( token.TypeName != MemberType ) {
throw new ExpInvalidCollectionMemberTypeException( token, this );
}
_collection.Add( token );
}
public override ExpSyntaxNode CreateInstanceNode( Token t )
{
throw new NotImplementedException();
}
public override sealed IEnumerator<ExpElementInstance> GetEnumerator()
{
return ( ( IEnumerable<ExpElementInstance> )_collection )
.GetEnumerator();
}
}
}
@@ -0,0 +1,132 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpCollectionInstance.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.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpCollectionInstanceBase : ExpSyntaxNode
{
protected internal (int min, int max) _range;
protected internal ExpElementType _memberType;
protected ExpCollectionInstanceBase( Token source ) : base( source ) { }
public abstract ExpCollectionBase CollectionValue { get; }
public ExpElementType MemberType
{
get => _memberType;
}
public override ExpSyntaxNode Left => null!;
public override ExpSyntaxNode Right => null!;
public int MinCapacity => _range.min;
public int MaxCapacity => _range.max;
}
public sealed class ExpSetInstance : ExpCollectionInstanceBase
{
private ExpSet _collection;
public ExpSetInstance( Token source, ExpSet set )
: base( source )
{
_collection = set;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpBagInstance : ExpCollectionInstanceBase
{
private ExpBag _collection;
public ExpBagInstance( Token source, ExpBag bag )
: base( source )
{
_collection = bag;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpListInstance : ExpCollectionInstanceBase
{
private ExpList _collection;
public ExpListInstance( Token source, ExpList list )
: base( source )
{
_collection = list;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
}
public sealed class ExpArrayInstance : ExpCollectionInstanceBase
{
private ExpArray _collection;
public ExpArrayInstance( Token source, ExpArray array )
: base( source )
{
_collection = array;
}
public override ExpCollectionBase CollectionValue => _collection;
public override ExpInstantiableElement EqualityTypeConvert => _collection;
}
}
+132
View File
@@ -0,0 +1,132 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpLogic.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.Script.Express
{
public enum ExpLogicValue
{
True,
False,
Unknown
}
public struct ExpLogic
{
public static readonly ExpLogic False = new ExpLogic( ExpLogicValue.False );
public static readonly ExpLogic True = new ExpLogic( ExpLogicValue.True );
public static readonly ExpLogic Unknown = new ExpLogic( ExpLogicValue.Unknown );
private readonly ExpLogicValue _value;
public ExpLogic( ExpLogicValue value )
{
_value = value;
}
public bool IsTrue => _value == ExpLogicValue.True;
public bool IsFalse => _value == ExpLogicValue.False;
public bool IsUnknown => _value == ExpLogicValue.Unknown;
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public bool ToBoolean()
{
return _value == ExpLogicValue.True;
}
public override string ToString() => _value.ToString();
public static bool TryParse( ReadOnlySpan<char> value, out ExpLogic result )
{
if( Enum.TryParse<ExpLogicValue>( value, out ExpLogicValue e ) )
{
result = new ExpLogic( e );
return true;
}
result = default;
return false;
}
// NOT !
public static ExpLogic operator !( ExpLogic a )
{
return a.IsTrue ? False : a.IsFalse ? True : Unknown;
}
// AND &
public static ExpLogic operator &( ExpLogic a, ExpLogic b )
{
if( a.IsFalse || b.IsFalse ) {
return False;
}
if( a.IsUnknown || b.IsUnknown ) {
return Unknown;
}
return True;
}
// XOR ^
public static ExpLogic operator ^( ExpLogic a, ExpLogic b )
{
if( a.IsUnknown || b.IsUnknown ) {
return Unknown;
}
return ( a.IsTrue ^ b.IsTrue ) ? True : False;
}
// OR |
public static ExpLogic operator |( ExpLogic a, ExpLogic b )
{
if( a.IsTrue || b.IsTrue ) {
return True;
}
if( a.IsUnknown || b.IsUnknown ) {
return Unknown;
}
return False;
}
}
}
@@ -0,0 +1,51 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BuiltinType.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public static partial class ExpressCompile
{
public static ExpTypeSource ExpInt { get; private set; }
public static ExpTypeSource ExpReal { get; private set; }
public static ExpTypeSource ExpBool { get; private set; }
public static ExpTypeSource ExpString { get; private set; }
}
}
@@ -0,0 +1,135 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="DefaultSchema.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;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Linq;
using static StgSharp.Script.Express.ExpressCompile;
namespace StgSharp.Script.Express
{
public sealed partial class ExpSchema_Builtin : ExpSchema
{
private static readonly ExpSchema_Builtin _onlyInstance = new ExpSchema_Builtin();
private ExpSchema_Builtin()
: base()
{
Name = "Nitload";
}
internal static ExpSchema_Builtin Only
{
get => _onlyInstance;
}
public override void LoadFromSource( ExpSchemaSource source )
{
return;
}
public override bool TryGetConst( string name, out ExpElementInstance c )
{
return ConstDict.TryGetValue( name, out c );
}
public override bool TryGetEntity( string name, out ExpEntitySource e )
{
e = null;
return false;
}
public override bool TryGetFunction( string name, out ExpFunctionSource f )
{
return FunctionDict.TryGetValue( name, out f! );
}
public override bool TryGetProcedure( string name, out ExpProcedureSource p )
{
return ProcedureDict.TryGetValue( name, out p! );
}
public override bool TryGetRule( string name, out ExpRuleSource r )
{
r = null!;
return false;
}
public override bool TryGetSchemaInclude( string name, out ExpSchema include )
{
include = null!;
return false;
}
public override bool TryGetType( string name, out ExpTypeSource t )
{
return TypeDict.TryGetValue( name, out t );
}
internal void Init()
{
IEnumerable<KeyValuePair<string, ExpTypeSource>> builtinTypeSource = [
new KeyValuePair<string, ExpTypeSource>(
PoolString( Keyword.Integer ),
new ExpBuiltinType( Keyword.Integer, typeof( int ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( Keyword.Real ), new ExpBuiltinType( Keyword.Real, typeof( float ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( Keyword.Boolean ),
new ExpBuiltinType( Keyword.Boolean, typeof( bool ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( Keyword.Logical ),
new ExpBuiltinType( Keyword.Logical, typeof( ExpLogic ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( Keyword.String ),
new ExpBuiltinType( Keyword.String, typeof( string ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( Keyword.Binary ),
new ExpBuiltinType( Keyword.Binary, typeof( BitArray ) ) ),
];
TypeDict = new Dictionary<string, ExpTypeSource>( builtinTypeSource,
Multiplexer ).ToFrozenDictionary();
ConstDict = new Dictionary<string, ExpElementInstance>( Multiplexer ) {
{ PoolString( "PI" ), new ExpRealNumberNode(
new Token( PoolString( "PI" ), -1, -1, TokenFlag.Number ), MathF.PI, true ) },
{ PoolString( "E" ), new ExpRealNumberNode(
new Token( PoolString( "E" ), -1, -1, TokenFlag.Number ), MathF.E, true ) },
}.ToFrozenDictionary();
}
}
}
@@ -0,0 +1,156 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpCompile.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 StgSharp.Collections;
using System;
using System.Collections;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
namespace StgSharp.Script.Express
{
public static partial class ExpressCompile
{
private static string[] _operatorsWithLetter;
private static ConcurrentStringHashMultiplexer _multiplexer;
private static FrozenDictionary<string, ExpElementInstance> _builtinConst;
private static FrozenDictionary<string, ExpTypeSource> _builtinType;
private static FrozenDictionary<string, ExpBinaryOperatorNode> _operators;
private static StringPool _compileStringCache,_emptyCache;
internal static ConcurrentStringHashMultiplexer Multiplexer
{
get
{
if( _multiplexer == null ) {
throw new ExpCompileNotInitializedException();
}
return _multiplexer;
}
}
public static void ClearStringCache()
{
_compileStringCache.Reset();
}
public static void DeinitCompile()
{
_compileStringCache.Reset();
_compileStringCache = null!;
_multiplexer.Dispose();
_multiplexer = null!;
}
public static void InitCompile()
{
_compileStringCache = new StringPool();
_multiplexer = new ConcurrentStringHashMultiplexer();
ExpSchema_Builtin.Only.Init();
PoolKeywords();
InitPrecedence();
_operatorsWithLetter = [
Keyword.Add,
Keyword.Sub,
Keyword.Mul,
Keyword.Div,
Keyword.And,
Keyword.Or,
Keyword.Xor,
Keyword.AndOr,
Keyword.Not,
];
ExpSchema_Builtin.Only
.TryGetType(
PoolString( Keyword.Integer ), out ExpTypeSource? _expInt );
ExpInt = _expInt;
ExpSchema_Builtin.Only
.TryGetType( PoolString( Keyword.Real ), out ExpTypeSource? _expReal );
ExpReal = _expReal;
ExpSchema_Builtin.Only
.TryGetType(
PoolString( Keyword.Boolean ), out ExpTypeSource? _expBool );
ExpBool = _expBool;
ExpSchema_Builtin.Only
.TryGetType(
PoolString( Keyword.Boolean ), out ExpTypeSource? _expString );
ExpString = _expString;
_emptyCache = new StringPool();
/*
foreach( string str in _compileStringCache ) {
_emptyCache.Add( str );
}
/**/
}
public static bool LetterIsKeyword( string str )
{
if( char.IsLetter( str[ 0 ] ) ) {
return _keywordSet.Contains( str );
}
return true;
}
public static bool LetterIsOperator( string str )
{
if( char.IsLetter( str[ 0 ] ) ) {
return Array.IndexOf( _operatorsWithLetter, str ) != -1;
}
return true;
}
public static string PoolString( string str )
{
return _compileStringCache.GetOrAdd( str );
}
public static string PoolString( ReadOnlySpan<char> str )
{
return _compileStringCache.GetOrAdd( str );
}
}
}
@@ -0,0 +1,104 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpOperatorPrecedence.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.Frozen;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public static partial class ExpressCompile
{
public static bool TryGetOperatorPrecedence( string operatorName, out int precedence )
{
return _operatorPrecedence.TryGetValue( operatorName, out precedence );
}
public static bool TryGetSuperTypeOperatorPrecedence(
string operatorName,
out int precedence )
{
return _superTypeOperatorPrecedent.TryGetValue( operatorName, out precedence );
}
private static void InitPrecedence()
{
KeyValuePair<string, int>[] source = [
new KeyValuePair<string, int>( PoolString( "[" ), 1 ),
new KeyValuePair<string, int>( PoolString( "." ), 1 ),
new KeyValuePair<string, int>( PoolString( "\\" ), 1 ),
new KeyValuePair<string, int>( PoolString( "unary+" ), 2 ),
new KeyValuePair<string, int>( PoolString( "unary-" ), 2 ),
new KeyValuePair<string, int>( PoolString( "NOT" ), 2 ),
new KeyValuePair<string, int>( PoolString( "**" ), 3 ),
new KeyValuePair<string, int>( PoolString( "*" ), 4 ),
new KeyValuePair<string, int>( PoolString( "/" ), 4 ),
new KeyValuePair<string, int>( PoolString( "AND" ), 4 ),
new KeyValuePair<string, int>( PoolString( "MOD" ), 4 ),
new KeyValuePair<string, int>( PoolString( "DIV" ), 4 ),
new KeyValuePair<string, int>( PoolString( "||" ), 4 ),
new KeyValuePair<string, int>( PoolString( "+" ), 5 ),
new KeyValuePair<string, int>( PoolString( "-" ), 5 ),
new KeyValuePair<string, int>( PoolString( "OR" ), 5 ),
new KeyValuePair<string, int>( PoolString( "XOR" ), 5 ),
new KeyValuePair<string, int>( PoolString( "=" ), 6 ),
new KeyValuePair<string, int>( PoolString( "<>" ), 6 ),
new KeyValuePair<string, int>( PoolString( "<=" ), 6 ),
new KeyValuePair<string, int>( PoolString( ">=" ), 6 ),
new KeyValuePair<string, int>( PoolString( ">" ), 6 ),
new KeyValuePair<string, int>( PoolString( "<" ), 6 ),
new KeyValuePair<string, int>( PoolString( ":=:" ), 6 ),
new KeyValuePair<string, int>( PoolString( ":<>:" ), 6 ),
new KeyValuePair<string, int>( PoolString( "IN" ), 6 ),
new KeyValuePair<string, int>( PoolString( "LIKE" ), 6 ),
new KeyValuePair<string, int>( PoolString( Keyword.Assignment ), 7 )
];
_operatorPrecedence = new Dictionary<string, int>( source,
_multiplexer ).ToFrozenDictionary();
source = [
new KeyValuePair<string, int>( "ONEOF", 1 ),
new KeyValuePair<string, int>( "AND", 2 ),
new KeyValuePair<string, int>( "ANDOR", 3 ),
];
_superTypeOperatorPrecedent = new Dictionary<string, int>( source,
_multiplexer ).ToFrozenDictionary(
);
}
#pragma warning disable CS8618
private static FrozenDictionary<string, int> _superTypeOperatorPrecedent;
private static FrozenDictionary<string, int> _operatorPrecedence;
#pragma warning restore CS8618
}
}
@@ -0,0 +1,356 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="KeyWord.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.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public static partial class ExpressCompile
{
private static HashSet<string> _keywordSet;
private static void PoolKeywords()
{
_keywordSet = new();
FieldInfo[] fields = typeof( Keyword ).GetFields( BindingFlags.Public );
ParallelLoopResult result = Parallel.ForEach(
fields, static( field ) => {
if( field.FieldType == typeof( string ) && field.GetValue( null ) is string str )
{
_compileStringCache.GetOrAdd( str );
_keywordSet.Add( str );
}
} );
while( !result.IsCompleted ) { }
}
public static class Keyword
{
public static HashSet<string> ScopeBlock = new HashSet<string> {
EndAlias, EndCase, EndConstant, EndEntity, EndFunction, EndIf, EndLocal, EndProcedure, EndRepeat, EndRule, EndSchema, EndSubtypeConstraint, EndType
};
public static HashSet<string> Symbols = [
Dot, Comma, Semicolon, Colon, Percent, Apostrophe,
Backslash, IndexOf, RightBracket, LeftBrace,
RightBrace, Pipe, LeftParen, RightParen, LeftAsterisk,
Assignment, DoublePipe, ExpSymbol, CommentSingleLine,
CommentStart, CommentEnd, InstanceEqual, InstanceNotEqual
];
public static HashSet<string> DataTypes { get; } = [
Array, Bag, Binary, Boolean, Enumeration, Integer, List, Logical, Number, Of, Real, Set, String
];
public static HashSet<string> InternalProcess { get; } = [
Insert, Remove
];
public static HashSet<string> BuiltinFunctions { get; } = [
Abs, Acos, Asin, Atan, BLength, Cos, Exists, Exp,
Format, HiBound, HiIndex, Length, LoBound, Log,
Log2, Log10, LoIndex, Nvl, Odd, Rolesof, Sin,
Sizeof, Sqrt, Tan, Typeof, Usedin, Value,
ValueIn, ValueUnique
];
public static HashSet<string> Literals { get; } = [
QuestionMark, Self, Const, E, Pi, False, True, Unknown
];
public static HashSet<string> Operators { get; } = [
And, AndOr, Div, In, Like, Mod, Not, Or, Xor,
Add, Sub, Mul, Slash, Equal, NotEqual,
LessThan, GreaterThan, LessThanOrEqual, GreaterThanOrEqual
];
public static HashSet<string> Aliasing { get; } = [
Alias, Renamed
];
public static HashSet<string> ModifiersAttributes { get; } = [
Abstract, Aggregate, As, BasedOn, By, Escape, Fixed, From, Use, With
];
public static HashSet<string> QueryReference { get; } = [
Query, Reference, Select
];
public static HashSet<string> ConstraintsInheritance { get; } = [
Oneof, Optional, Subtype, SubtypeConstraint, Supertype, TotalOver, Unique, Where
];
public static HashSet<string> Declarations { get; } = [
Constant, Derive, Entity, Extensible, Fixed, Function, Generic,
GenericEntity, Inverse, Local, Procedure, Rule, Schema, Type, Var
];
public static HashSet<string> FlowControl { get; } = [
Begin, Case, Else, End, For, If, Otherwise, Repeat, Return, Skip, Then, To, Until, While
];
#region Basic Data Type
public const string Array = "ARRAY";
public const string Bag = "BAG";
public const string Binary = "BINARY";
public const string Boolean = "BOOLEAN";
public const string Enumeration = "ENUMERATION";
public const string Integer = "INTEGER";
public const string List = "LIST";
public const string Logical = "LOGICAL";
public const string Number = "NUMBER";
public const string Of = "OF";
public const string Real = "REAL";
public const string Set = "SET";
public const string String = "STRING";
#endregion
#region Flow Control
public const string Begin = "BEGIN";
public const string Case = "CASE";
public const string Else = "ELSE";
public const string End = "END";
public const string For = "FOR";
public const string If = "IF";
public const string Otherwise = "OTHERWISE";
public const string Repeat = "REPEAT";
public const string Return = "RETURN";
public const string Skip = "SKIP";
public const string Then = "THEN";
public const string To = "TO";
public const string Until = "UNTIL";
public const string While = "WHILE";
#endregion
#region Declarations
public const string Constant = "CONSTANT";
public const string Derive = "DERIVE";
public const string Entity = "ENTITY";
public const string Extensible = "EXTENSIBLE";
public const string Fixed = "FIXED";
public const string Function = "FUNCTION";
public const string Generic = "GENERIC";
public const string GenericEntity = "GENERIC_ENTITY";
public const string Inverse = "INVERSE";
public const string Local = "LOCAL";
public const string Procedure = "PROCEDURE";
public const string Rule = "RULE";
public const string Schema = "SCHEMA";
public const string Type = "TYPE";
public const string Var = "VAR";
#endregion
#region Constraints Inheritance
public const string Oneof = "ONEOF";
public const string Optional = "OPTIONAL";
public const string Subtype = "SUBTYPE";
public const string SubtypeConstraint = "SUBTYPE CONSTRAINT";
public const string Supertype = "SUPERTYPE";
public const string TotalOver = "TOTAL OVER";
public const string Unique = "UNIQUE";
public const string Where = "WHERE";
#endregion
#region Scope
public const string EndAlias = "END_ALIAS";
public const string EndCase = "END_CASE";
public const string EndConstant = "END_CONSTANT";
public const string EndEntity = "END_ENTITY";
public const string EndFunction = "END_FUNCTION";
public const string EndIf = "END_IF";
public const string EndLocal = "END_LOCAL";
public const string EndProcedure = "END_PROCEDURE";
public const string EndRepeat = "END_REPEAT";
public const string EndRule = "END_RULE";
public const string EndSchema = "END_SCHEMA";
public const string EndSubtypeConstraint = "END_SUBTYPE CONSTRAINT";
public const string EndType = "END_TYPE";
#endregion
#region Index and Ref
public const string Query = "QUERY";
public const string Reference = "REFERENCE";
public const string Select = "SELECT";
#endregion
#region Modifiers Attributes
public const string Abstract = "ABSTRACT";
public const string Aggregate = "AGGREGATE";
public const string As = "AS";
public const string BasedOn = "BASED ON";
public const string By = "BY";
public const string Escape = "ESCAPE";
public const string From = "FROM";
public const string Use = "USE";
public const string With = "WITH";
#endregion
#region Aliasing
public const string Alias = "ALIAS";
public const string Renamed = "RENAMED";
#endregion
#region Operator
public const string And = "AND";
public const string AndOr = "ANDOR";
public const string Div = "DIV";
public const string In = "IN";
public const string Like = "LIKE";
public const string Mod = "MOD";
public const string Not = "NOT";
public const string Or = "OR";
public const string Xor = "XOR";
#endregion
#region Constants
public const string QuestionMark = "?";
public const string Self = "SELF";
public const string Const = "CONST";
public const string E = "E";
public const string Pi = "PI";
public const string False = "FALSE";
public const string True = "TRUE";
public const string Unknown = "UNKNOWN";
#endregion
#region Functions
public const string Abs = "ABS";
public const string Acos = "ACOS";
public const string Asin = "ASIN";
public const string Atan = "ATAN";
public const string BLength = "BLENGTH";
public const string Cos = "COS";
public const string Exists = "EXISTS";
public const string Exp = "EXP";
public const string Format = "FORMAT";
public const string HiBound = "HIBOUND";
public const string HiIndex = "HIINDEX";
public const string Length = "LENGTH";
public const string LoBound = "LObound";
public const string Log = "LOG";
public const string Log2 = "LOG2";
public const string Log10 = "LOG10";
public const string LoIndex = "LOINDEX";
public const string Nvl = "NVL";
public const string Odd = "ODD";
public const string Rolesof = "ROLESOF";
public const string Sin = "SIN";
public const string Sizeof = "SIZEOF";
public const string Sqrt = "SQRT";
public const string Tan = "TAN";
public const string Typeof = "TYPEOF";
public const string Usedin = "USEDIN";
public const string Value = "VALUE";
public const string ValueIn = "VALUE IN";
public const string ValueUnique = "VALUE UNIQUE";
#endregion
#region Procedure
public const string Insert = "INSERT";
public const string Remove = "REMOVE";
#endregion
#region Symbols
public const string Dot = ".";
public const string Comma = ",";
public const string Semicolon = ";";
public const string Colon = ":";
public const string Mul = "*";
public const string Add = "+";
public const string UnaryPlus = "+";
public const string Sub = "-";
public const string UnaryMinus = "-";
public const string Equal = "=";
public const string Percent = "%";
public const string Apostrophe = "'";
public const string Backslash = "\\";
public const string Slash = "/";
public const string LessThan = "<";
public const string GreaterThan = ">";
public const string IndexOf = "[";
public const string LeftBracket = "[";
public const string RightBracket = "]";
public const string LeftBrace = "{";
public const string RightBrace = "}";
public const string Pipe = "|";
public const string EConstant = "E";
public const string LeftParen = "(";
public const string RightParen = ")";
public const string LessThanOrEqual = "<=";
public const string NotEqual = "<>";
public const string GreaterThanOrEqual = ">=";
public const string LeftAsterisk = "<*";
public const string Assignment = ":=";
public const string DoublePipe = "||";
public const string ExpSymbol = "**";
public const string CommentSingleLine = "--";
public const string CommentStart = "(*";
public const string CommentEnd = "*)";
public const string InstanceEqual = ":=:";
public const string InstanceNotEqual = ":<>:";
#endregion
}
}
}
+104
View File
@@ -0,0 +1,104 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpConst.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;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Script.Express
{
public sealed class ExpConstantCollectionSource : ExpImmutableElement
{
private Dictionary<string, ExpElementInstance> _constants;
private IScriptSourceProvider _sourceProvider;
public ExpConstantCollectionSource( IScriptSourceProvider sourceProvider )
{
_sourceProvider = sourceProvider;
_constants = new Dictionary<string, ExpElementInstance>( ExpressCompile.Multiplexer );
}
public override ExpElementType ElementType => ExpElementType.Const;
public override IScriptSourceProvider SourceProvider => _sourceProvider;
public override string Name
{
get => ExpressCompile.Keyword.Constant;
}
public override void Analyse()
{
throw new NotImplementedException();
}
public override ExpSyntaxNode MakeReference( params object[] options )
{
if( options.Length == 0 || options[ 0 ] is not string str ) {
return null!;
}
if( _constants.Count == 0 ) {
return null!;
}
if( _constants.TryGetValue( str, out ExpElementInstance? token ) ) {
return token;
}
return null!;
}
public bool TryGetConstant( string name, out ExpElementInstance instance )
{
return _constants.TryGetValue( name, out instance );
}
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
{
if( _constants.TryGetValue( name, out ExpElementInstance? node ) )
{
memberNode = node;
return true;
}
memberNode = ExpSyntaxNode.Empty;
return false;
}
internal void AddConstant( string name, ExpElementInstance value )
{
_constants.Add( name, value );
}
}
}
@@ -0,0 +1,72 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpEntity.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.Text;
namespace StgSharp.Script.Express
{
public class ExpEntitySource : ExpInstantiableElement
{
private AbstractSyntaxTree<ExpSyntaxNode, IExpElementSource> _expressionTree;
private ScriptSourceTransmitter _source;
private string _name;
public ExpEntitySource( string name, ScriptSourceTransmitter provider )
{
_name = name;
_source = provider;
}
public override ExpElementType ElementType => ExpElementType.Entity;
public override IScriptSourceProvider SourceProvider => _source;
public override string Name => _name;
public override void Analyse()
{
throw new NotImplementedException();
}
public override ExpSyntaxNode CreateInstanceNode( Token t )
{
throw new NotImplementedException();
}
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,97 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpFunction.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.Text;
namespace StgSharp.Script.Express
{
public class ExpFunctionSource : ExpImmutableElement
{
private ScriptSourceTransmitter _transmitter;
private string _name;
public ExpFunctionSource( string name, ScriptSourceTransmitter transmitter )
{
_name = name;
_transmitter = transmitter;
}
public Dictionary<string, ExpElementInstance> FuncParams { get; init; } = new Dictionary<string, ExpElementInstance>(
);
public Dictionary<string, ExpElementInstance> LocalVariables { get; init; } = new Dictionary<string, ExpElementInstance>(
);
public override ExpElementType ElementType => ExpElementType.Function;
public ExpInstantiableElement ReturningType { get; protected set; }
public override IScriptSourceProvider SourceProvider => _transmitter;
public override string Name => _name;
public string CallingFormat { get; private set; }
public override void Analyse()
{
throw new NotImplementedException();
/*
* generate parameter list,
* generate C# code
* generate calling syntax
*/
}
public override ExpSyntaxNode MakeReference( params object[] options )
{
throw new NotImplementedException();
}
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
{
if( FuncParams.TryGetValue( name, out ExpElementInstance? param ) )
{
memberNode = param;
return true;
}
if( LocalVariables.TryGetValue( name, out ExpElementInstance? variable ) )
{
memberNode = variable;
return true;
}
memberNode = ExpSyntaxNode.Empty;
return false;
}
}
}
@@ -0,0 +1,64 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpProcedureSource.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpProcedureSource : ExpImmutableElement
{
public override ExpElementType ElementType => ExpElementType.Procedure;
public override IScriptSourceProvider SourceProvider => throw new NotImplementedException();
public override string Name => throw new NotImplementedException();
public override void Analyse()
{
throw new NotImplementedException();
}
public override ExpSyntaxNode MakeReference( params object[] options )
{
throw new NotImplementedException();
}
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,94 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpRule.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.Data;
using System.Reflection.Metadata.Ecma335;
using System.Text;
namespace StgSharp.Script.Express
{
public class ExpRule : ExpElementInstance
{
private ExpRuleSource _source;
public ExpRule( Token source ) : base( source ) { }
public object? value => throw new NotImplementedException();
public override ExpInstantiableElement EqualityTypeConvert => throw new NotImplementedException(
);
public override ExpSyntaxNode Left => throw new NotImplementedException();
public override ExpSyntaxNode Right => throw new NotImplementedException();
public override string TypeName => _source.Name;
}
public class ExpRuleSource : ExpImmutableElement
{
private ScriptSourceTransmitter _transmitter;
private string _name;
public ExpRuleSource( string name, ScriptSourceTransmitter transmitter )
{
_name = name;
_transmitter = transmitter;
}
public override ExpElementType ElementType => ExpElementType.Rule;
public override IScriptSourceProvider SourceProvider => _transmitter;
public override string Name => _name;
public override void Analyse()
{
throw new NotImplementedException();
}
public override ExpSyntaxNode MakeReference( params object[] options )
{
throw new NotImplementedException();
}
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
{
memberNode = ExpSyntaxNode.Empty;
return false;
}
}
}
+116
View File
@@ -0,0 +1,116 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpType.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 System;
using System.Collections.Generic;
namespace StgSharp.Script.Express
{
public class ExpTypeSource : ExpInstantiableElement
{
private ScriptSourceTransmitter _transmitter;
private string _name;
protected bool _isBuiltinType;
protected ExpTypeSource( string name )
{
_name = name;
_transmitter = ScriptSourceTransmitter.Empty;
_isBuiltinType = true;
}
public ExpTypeSource( string name, ScriptSourceTransmitter transmitter )
{
_name = name;
_transmitter = transmitter;
_isBuiltinType = false;
}
public bool IsLanguageBuiltinType
{
get => _isBuiltinType;
}
public override ExpElementType ElementType => ExpElementType.Type;
public static ExpTypeSource Void
{
get => ExpVoidType.Only;
}
public override IScriptSourceProvider SourceProvider => _transmitter;
public override string Name => _name;
public override void Analyse()
{
throw new NotImplementedException();
}
public override ExpElementInstance CreateInstanceNode( Token t )
{
throw new NotImplementedException();
}
public static bool IsNullOrVoid( IExpElementSource type )
{
return type == null || type == ExpVoidType.Only;
}
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
{
memberNode = ExpSyntaxNode.Empty;
return false;
}
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;
}
}
}
}
@@ -0,0 +1,297 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpBinaryOperatorNode.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;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpBinaryOperatorNode : ExpSyntaxNode
{
private ExpInstantiableElement _returnType;
private ExpSyntaxNode _left;
private ExpSyntaxNode _right;
private ExpBinaryOperatorNode( Token source, ExpSyntaxNode left, ExpSyntaxNode right )
: base( source )
{
_left = left;
_right = right;
}
public override ExpInstantiableElement EqualityTypeConvert => _returnType;
public override ExpSyntaxNode Left => _left;
public override ExpSyntaxNode Right => _right;
public string Operator { get; private set; }
public static ExpBinaryOperatorNode Add(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 ||
( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} + {1}",
};
}
public static ExpBinaryOperatorNode Assign(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
source, left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpInstantiableElement.Void,
_nodeFlag = ExpNodeFlag.Operator_Binary | left._nodeFlag,
Operator = "=",
CodeConvertTemplate = "{0} = {1}",
};
}
public static ExpBinaryOperatorNode CompareInstanceEqual(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "!ReferenceEquals({0}, {1})",
};
}
public static ExpBinaryOperatorNode CompareInstanceNotEqual(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "ReferenceEquals({0}, {1})",
};
}
public static ExpBinaryOperatorNode ConvertElement(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( right is not ExpMetaRefNode metaRef ) {
throw new ExpInvalidTypeException(
source, "<source of element>", right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = metaRef.SourceRef,
_nodeFlag = ExpNodeFlag.Operator_Binary,
/*
* 0. instance to convert
* 1. target type
*/
CodeConvertTemplate = @"({0} as {1})"
};
}
public static ExpBinaryOperatorNode Div(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 ||
( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} / {1}",
};
}
public static ExpBinaryOperatorNode EqualTo(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
source, left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} == {1}",
};
}
public static ExpBinaryOperatorNode GreaterThan(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} > {1}",
};
}
public static ExpBinaryOperatorNode LessThan(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} < {1}",
};
}
public static ExpBinaryOperatorNode Mul(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 ||
( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} * {1}",
};
}
public static ExpBinaryOperatorNode NotEqualTo(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( left.EqualityTypeConvert != right.EqualityTypeConvert ) {
throw new ExpInvalidTypeException(
source, left.EqualityTypeConvert.Name, right.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} != {1}",
};
}
public static ExpBinaryOperatorNode SmallerThan(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = ExpressCompile.ExpBool,
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary,
CodeConvertTemplate = "{0} < {1}",
};
}
public static ExpBinaryOperatorNode Sub(
Token source,
ExpSyntaxNode left,
ExpSyntaxNode right )
{
if( !left.IsNumber && !right.IsNumber ) {
throw new ExpInvalidTypeException( source, "Number",
left.EqualityTypeConvert.Name );
}
bool isFloat =
( left._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0 ||
( right._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
return new ExpBinaryOperatorNode( source, left, right )
{
_returnType = isFloat ? ExpressCompile.ExpReal : ExpressCompile.ExpInt,
_nodeFlag = ExpNodeFlag.Operator_Binary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "{0} - {1}",
};
}
}
}
@@ -0,0 +1,76 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpCollectionIndexNode.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpCollectionIndexNode : ExpSyntaxNode
{
private ExpCollectionInstanceBase _collection;
private ExpSyntaxNode _indexExpression;
private ExpCollectionIndexNode(
Token source,
ExpCollectionInstanceBase instance,
ExpSyntaxNode indexExpression )
: base( source )
{
_collection = instance;
_indexExpression = indexExpression;
CodeConvertTemplate = @"{0}[{1}]";
}
public override ExpSyntaxNode Left => _collection;
public override ExpSyntaxNode Right => _indexExpression;
public override IExpElementSource EqualityTypeConvert => _collection.EqualityTypeConvert;
public static ExpCollectionIndexNode Create(
Token source,
ExpCollectionInstanceBase instance,
ExpSyntaxNode indexExpression )
{
if( !indexExpression.IsNumber ) {
throw new ExpInvalidTypeException(
source, "Number", indexExpression.EqualityTypeConvert.Name );
}
return new ExpCollectionIndexNode( source, instance, indexExpression );
}
}
}
@@ -0,0 +1,76 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpElementInitializingNode.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 ExpElementInitializingNode : ExpSyntaxNode
{
private ExpMetaRefNode _type;
private ExpSyntaxNode _init;
private ExpElementInitializingNode(
Token source,
ExpMetaRefNode type,
ExpSyntaxNode initParameter )
: base( source )
{
_type = type;
_init = initParameter;
}
public override ExpSyntaxNode Left => _type;
public override ExpSyntaxNode Right => _init;
public override IExpElementSource EqualityTypeConvert => _type.SourceRef;
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public ExpElementInitializingNode InitializeElement(
Token source,
ExpMetaRefNode type,
ExpSyntaxNode init )
{
if( init is ExpTupleNode tupleNode ) {
init = tupleNode.Right;
}
ExpElementInitializingNode node = new ExpElementInitializingNode( source, type, init );
return node;
}
}
}
@@ -0,0 +1,69 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpElementMemberNameNode.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpElementMemberNameNode : ExpSyntaxNode
{
internal ExpElementMemberNameNode( Token source )
: base( source )
{
_nodeFlag = ExpNodeFlag.Name_Operator;
CodeConvertTemplate = source.Value;
}
public override ExpSyntaxNode Left => Empty;
public override ExpSyntaxNode Right => Empty;
public override IExpElementSource EqualityTypeConvert
{
get
{
ExpSchema.BuiltinSchema
.TryGetType( ExpressCompile.Keyword.String, out ExpTypeSource? strType );
return strType;
}
}
public static ExpElementMemberNameNode Create( Token t )
{
return new ExpElementMemberNameNode( t );
}
}
}
@@ -0,0 +1,68 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpEnumLiteralNode.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 System;
namespace StgSharp.Script.Express
{
public class ExpEnumLiteralNode : ExpSyntaxNode
{
private ExpEnumLiteralNode( Token t ) : base( t ) { }
public override ExpSyntaxNode Left => Empty;
public override ExpSyntaxNode Right => Empty;
public override IExpElementSource EqualityTypeConvert => ExpInstantiableElement.Void;
public string Literal { get; private set; }
public static ExpEnumLiteralNode Create( Token t, Func<string, string> parser )
{
string l;
if( parser is null )
{
l = t.Value;
} else
{
l = parser( t.Value );
}
return new ExpEnumLiteralNode( t )
{
Literal = l,
CodeConvertTemplate = l
};
}
}
}
@@ -0,0 +1,84 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpFunctionCallingNode.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpFunctionCallingNode : ExpSyntaxNode
{
private ExpFunctionSource _function;
private ExpSyntaxNode _parameter;
private ExpFunctionCallingNode(
Token source,
ExpFunctionSource function,
ExpSyntaxNode parameterEnumeration )
: base( source )
{
if( parameterEnumeration is ExpTupleNode tuple ) {
parameterEnumeration = tuple.Right;
}
_function = function;
_parameter = parameterEnumeration;
}
public ExpFunctionSource FunctionCaller => _function;
public override ExpInstantiableElement EqualityTypeConvert => _function.ReturningType;
public override ExpSyntaxNode Left => Empty;
public override ExpSyntaxNode Right => _parameter;
public void AppendParameter( ExpSyntaxNode parameter )
{
_parameter.AppendNode( parameter );
}
public static ExpFunctionCallingNode CallFunction(
Token source,
ExpFunctionSource function,
ExpSyntaxNode param )
{
if( param is ExpTupleNode ) {
param = param.Right;
}
return new ExpFunctionCallingNode( source, function, param );
}
}
}
@@ -0,0 +1,98 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpIfNode.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.Express;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public sealed class ExpIfNode : ExpSyntaxNode
{
private ExpSyntaxNode _falseOpBegin;
private ExpSyntaxNode _rule;
private ExpSyntaxNode _trueOpBegin ;
public ExpIfNode( Token source, ExpSyntaxNode rule, ExpSyntaxNode trueOpBegin )
: base( source )
{
_rule = rule;
_trueOpBegin = trueOpBegin;
CodeConvertTemplate = ExpressCompile.PoolString(
"""
if ( {0} )
{
{1}
}
""" );
}
public ExpIfNode(
Token source,
ExpSyntaxNode rule,
ExpSyntaxNode rootOperationIfTrue,
ExpSyntaxNode rootOperationIfFalse )
: base( source )
{
_rule = rule;
_trueOpBegin = rootOperationIfFalse;
_falseOpBegin = rootOperationIfFalse;
CodeConvertTemplate = ExpressCompile.PoolString(
"""
if( {0} )
{
{1}
} else {
{2}
}
""" );
}
public override ExpSyntaxNode Left => _trueOpBegin;
public override ExpSyntaxNode Right => _falseOpBegin;
public override IExpElementSource EqualityTypeConvert => null!;
public void AppendFalseOperation( ExpSyntaxNode expressionRoot )
{
_falseOpBegin.AppendNode( expressionRoot );
}
public void AppendTrueOperation( ExpSyntaxNode expressionRoot )
{
_trueOpBegin.AppendNode( expressionRoot );
}
}
}
@@ -0,0 +1,66 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpInstanceMemberNode.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.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpInstanceMemberNode : ExpSyntaxNode
{
private ExpElementInstance _instance;
private ExpElementMemberNameNode _memberName;
private ExpSyntaxNode _member;
public ExpInstanceMemberNode(
Token source,
ExpElementInstance instance,
ExpElementMemberNameNode memberName )
: base( source )
{
_instance = instance;
_memberName = memberName;
_instance.TryGetMember( memberName.CodeConvertTemplate, out _member );
}
public override ExpSyntaxNode Left => _instance;
public override ExpSyntaxNode Right => _memberName;
public override IExpElementSource EqualityTypeConvert => _member.EqualityTypeConvert;
}
}
@@ -0,0 +1,85 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpInstanceReferenceNode.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 ExpInstanceReferenceNode : ExpSyntaxNode
{
internal ExpInstanceReferenceNode( Token source, ExpElementInstance instance )
: base( source )
{
OriginObject = instance;
_nodeFlag = ( OriginObject._nodeFlag | ( ExpNodeFlag.Name_Any | ExpNodeFlag.Collection_Any ) );
CodeConvertTemplate = source.Value;
}
internal ExpInstanceReferenceNode( Token source, ExpInstanceReferenceNode reference )
: base( source )
{
OriginObject = reference.OriginObject;
_nodeFlag = ( OriginObject._nodeFlag | ( ExpNodeFlag.Name_Any | ExpNodeFlag.Collection_Any ) );
CodeConvertTemplate = source.Value;
}
public ExpElementInstance OriginObject { get ; private set; }
public override ExpSyntaxNode Left => Empty;
public override ExpSyntaxNode Right => Empty;
public override IExpElementSource EqualityTypeConvert => OriginObject.EqualityTypeConvert;
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static ExpInstanceReferenceNode MakeReferenceFrom(
Token source,
ExpElementInstance instance )
{
/**/
if( instance.IsLiteral )
{
throw new ExpCompileException( source, "Cannot make reference to a literal." );
}
if( instance.CodeConvertTemplate != source.Value ) {
throw new ExpCompileException( source, "Token point at a wrong instance" );
}
/**/
return new ExpInstanceReferenceNode( source, instance );
}
}
}
@@ -0,0 +1,190 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpLiteralNode.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.Data;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace StgSharp.Script.Express
{
public class ExpIntNode : ExpElementInstance
{
private int _value;
public ExpIntNode( Token source, int value, bool isLiteral )
: base( source )
{
this.IsLiteral = isLiteral;
_value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Type;
CodeConvertTemplate = IsLiteral ? value.ToString() : source.Value;
}
public override IExpElementSource EqualityTypeConvert
{
get => ExpressCompile.ExpInt;
}
public int Value => _value;
public override string TypeName => ExpressCompile.Keyword.Integer;
}
public class ExpStringNode : ExpElementInstance
{
private readonly string _value;
public ExpStringNode( Token source, string value, bool isLiteral )
: base( source )
{
this.IsLiteral = IsLiteral;
_value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_String | ExpNodeFlag.Element_Type;
CodeConvertTemplate = IsLiteral ? $"\"{value}\"" : source.Value;
}
public override IExpElementSource EqualityTypeConvert
{
get => ExpressCompile.ExpString;
}
public override string TypeName => EqualityTypeConvert.Name;
public string Value => _value;
}
public interface IExpBooleanSyntax
{
bool Value { get; }
}
public class ExpBoolNode : ExpElementInstance, IExpBooleanSyntax
{
private readonly bool _value;
public ExpBoolNode( Token source, bool value, bool isLiteral )
: base( source )
{
this.IsLiteral = isLiteral;
_value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Element_Type;
CodeConvertTemplate = IsLiteral ? value.ToString() : source.Value;
}
public bool Value => _value;
public override IExpElementSource EqualityTypeConvert
{
get => ExpSchema.BuiltinSchema
.TryGetType( ExpressCompile.Keyword.Boolean, out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
}
public override string TypeName => EqualityTypeConvert.Name;
public static ExpBoolNode False( Token? t )
{
return new( t ?? new Token( "FALSE", 0, -1, TokenFlag.Member ), false,
isLiteral: true );
}
public static ExpBoolNode True( Token? t )
{
return new( t ?? new Token( "TRUE", 0, -1, TokenFlag.Member ), true, isLiteral: true );
}
}
public class ExpRealNumberNode : ExpElementInstance
{
private readonly float _value;
public ExpRealNumberNode( Token source, float value, bool isLiteral )
: base( source )
{
_value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Real | ExpNodeFlag.Element_Type;
CodeConvertTemplate = isLiteral ? $"{value:F8}f" : source.Value;
}
public float Value => _value;
public override IExpElementSource EqualityTypeConvert
{
get => ExpSchema.BuiltinSchema
.TryGetType( ExpressCompile.Keyword.String, out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
}
public override string TypeName => EqualityTypeConvert.Name;
}
public class ExpLogicValueNode : ExpElementInstance, IExpBooleanSyntax
{
private readonly ExpLogic _value;
public ExpLogicValueNode( Token source, ExpLogic value, bool isLiteral )
: base( source )
{
this.IsLiteral = isLiteral;
_value = value;
_nodeFlag = ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.Element_Type;
CodeConvertTemplate = isLiteral ? value.ToString() : source.Value;
}
public ExpLogic LogicValue => _value;
public override IExpElementSource EqualityTypeConvert
{
get => ExpSchema.BuiltinSchema
.TryGetType( ExpressCompile.Keyword.Logical, out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
}
public override string TypeName => EqualityTypeConvert.Name;
bool IExpBooleanSyntax.Value => _value.ToBoolean();
}
}
@@ -0,0 +1,88 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpMetaRefNode.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;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpMetaRefNode : ExpSyntaxNode
{
internal ExpMetaRefNode( Token source, ExpInstantiableElement element )
: base( source )
{
SourceRef = element;
}
public ExpInstantiableElement SourceRef { get; init; }
public override ExpSyntaxNode Left => Empty;
public override ExpSyntaxNode Right => Empty;
public override IExpElementSource EqualityTypeConvert => ExpInstantiableElement.Void;
public static ExpMetaRefNode RefEntity( Token position, ExpEntitySource entity )
{
if( position.Value != entity.Name ) {
throw new ExpCompileException(
position,
$"Meta data does not match, name of source to match is {entity.Name}, but token is {position.Value}" );
}
ExpMetaRefNode node = new ExpMetaRefNode( position, entity )
{
CodeConvertTemplate = entity.Name,
};
return node;
}
public static ExpMetaRefNode RefType( Token position, ExpTypeSource type )
{
if( position.Value != type.Name ) {
throw new ExpCompileException(
position,
$"Meta data does not match, name of source to match is {type.Name}, but token is {position.Value}" );
}
ExpMetaRefNode node = new ExpMetaRefNode( position, type )
{
CodeConvertTemplate = type.Name,
};
;
return node;
}
}
}
@@ -0,0 +1,81 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpProcedureCallingNode.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 ExpProcedureCallingNode : ExpSyntaxNode
{
private ExpSyntaxNode _params;
public ExpProcedureCallingNode(
Token source,
ExpProcedureSource caller,
ExpSyntaxNode param )
: base( source )
{
_params = param;
CalledProcedure = caller;
}
public ExpProcedureSource CalledProcedure { get; init; }
public override ExpSyntaxNode Left => Empty;
public override ExpSyntaxNode Right => _params;
public override IExpElementSource EqualityTypeConvert => ExpInstantiableElement.Void;
public static ExpProcedureCallingNode CallProcedure(
Token postion,
ExpProcedureSource caller,
ExpSyntaxNode input )
{
ExpProcedureCallingNode node = new ExpProcedureCallingNode( postion, caller, input )
{
/*
* 0. parameters
*/
CodeConvertTemplate = $$"""
{{caller.Name}}( {0} )
"""
};
return node;
}
}
}
@@ -0,0 +1,81 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpProcedureControlNode.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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Script.Express
{
public class ExpProcedureControlNode : ExpSyntaxNode
{
private ExpSyntaxNode _additional;
internal ExpProcedureControlNode( Token source ) : base( source ) { }
public override ExpSyntaxNode Left => Empty;
public override ExpSyntaxNode Right => _additional;
public override IExpElementSource EqualityTypeConvert => ExpTypeSource.Void;
public static ExpProcedureControlNode Return( Token t, ExpSyntaxNode valueToReturn )
{
if( t.Value != ExpKeyword.Return ) {
throw new InvalidCastException();
}
ExpProcedureControlNode ret = new ExpProcedureControlNode( t )
{
_additional = valueToReturn ?? Empty,
CodeConvertTemplate = IsNullOrEmpty( valueToReturn! ) ?
ExpKeyword.Return : "return {0}",
};
return ret;
}
public static ExpProcedureControlNode Skip( Token t )
{
ExpProcedureControlNode ret = new ExpProcedureControlNode( t )
{
_additional = Empty,
CodeConvertTemplate = "break"
};
return ret;
}
}
}
@@ -0,0 +1,125 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpRangeAndIndexNode.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.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpIndexNode : ExpSyntaxNode
{
private const string _codeTemplate = @"[{0}]";
private ExpSyntaxNode _index;
internal ExpIndexNode( Token t, ExpSyntaxNode node )
: base( t )
{
_index = node;
CodeConvertTemplate = _codeTemplate;
}
public override ExpSyntaxNode Left => _index;
public override ExpSyntaxNode Right => Empty;
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException();
public static ExpIndexNode IndexAt( Token position, ExpSyntaxNode expression )
{
ArgumentNullException.ThrowIfNull( expression );
if( ExpNodeFlag.BuiltinType_Int.IsNotInFlag( expression.NodeFlag ) ) {
throw new ExpInvalidTypeException(
position, "Integer", expression.EqualityTypeConvert.Name );
}
return new ExpIndexNode( position, expression );
}
}
public class ExpRangeNode : ExpSyntaxNode
{
private const string _codeTemplate = "[{0}..{1}]";
private ExpSyntaxNode _begin, _end;
internal ExpRangeNode( Token t, ExpSyntaxNode begin, ExpSyntaxNode end )
: base( t )
{
_begin = begin;
_end = end;
CodeConvertTemplate = _codeTemplate;
}
public override ExpSyntaxNode Left => _begin;
public override ExpSyntaxNode Right => _end;
public override IExpElementSource EqualityTypeConvert => ExpInstantiableElement.Void;
public static ExpRangeNode RangeNode(
Token position,
ExpSyntaxNode beginNode,
ExpSyntaxNode endNode )
{
ArgumentNullException.ThrowIfNull( beginNode );
ArgumentNullException.ThrowIfNull( endNode );
if( ExpNodeFlag.BuiltinType_Int.IsNotInFlag( beginNode.NodeFlag ) ) {
throw new ExpInvalidTypeException(
position, "Integer", beginNode.EqualityTypeConvert.Name );
}
if( ExpNodeFlag.BuiltinType_Int.IsNotInFlag( endNode.NodeFlag ) ) {
throw new ExpInvalidTypeException(
position, "Integer", endNode.EqualityTypeConvert.Name );
}
return new ExpRangeNode( position, beginNode, endNode );
}
}
public class ExpCollectionExpressionNode : ExpSyntaxNode
{
internal ExpCollectionExpressionNode( Token t, ExpTupleNode tupleNode ) : base( t ) { }
public override ExpSyntaxNode Left => throw new NotImplementedException();
public override ExpSyntaxNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException();
}
}
@@ -0,0 +1,200 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ExpRepeatNode.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.Serialization;
using System.Text;
using System.Threading.Channels;
namespace StgSharp.Script.Express
{
public class ExpRepeatNode : ExpSyntaxNode
{
private ExpElementInstance _variable;
private ExpSyntaxNode _begin, _end, _increment, _operationBegin,_untilRule,_whileRule;
internal ExpRepeatNode(
Token source,
ExpElementInstance variable,
ExpSyntaxNode begin,
ExpSyntaxNode end,
ExpSyntaxNode increment,
ExpSyntaxNode operationBegin,
ExpSyntaxNode untilRule,
ExpSyntaxNode whileRule)
: base(source)
{
if (variable.NodeFlag != begin.NodeFlag ||
begin.NodeFlag != end.NodeFlag ||
(increment != null && end.NodeFlag != increment.NodeFlag)) {
throw new InvalidCastException();
}
if (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(variable, "Int or Real", "otherwise");
}
}
_variable = variable;
_begin = begin;
_end = end;
_increment = increment!;
_operationBegin = operationBegin;
_untilRule = untilRule;
_whileRule = whileRule;
}
public override ExpSyntaxNode Left => throw new NotImplementedException();
public override ExpSyntaxNode Right => _operationBegin;
public override IExpElementSource EqualityTypeConvert => null!;
public void AppendRepeatedOperation(ExpSyntaxNode node)
{
_operationBegin.AppendNode(node);
}
/// <summary>
/// Create an AST node for repeat expression in EXPRESS language. The loop does not has
/// WHILE and UNTIL regulation.
/// </summary>
/// <param name="t">
/// AllocatorHandle of the loop.
/// </param>
/// <param name="repeatVariable">
/// The variable recording increment by step.
/// </param>
/// <param name="begin">
/// Beginning value of the loop.
/// </param>
/// <param name="end">
/// When <see href="repeatVariable" /> reach the value, the loop ends.
/// </param>
/// <param name="repeatBody">
/// Expressions to operate multiple times.
/// </param>
/// <returns>
/// A <see cref="ExpRepeatNode" /> representing the repeat expression.
/// </returns>
public static ExpRepeatNode Create(
Token t,
ExpInstanceReferenceNode repeatVariable,
ExpSyntaxNode begin,
ExpSyntaxNode end,
ExpSyntaxNode increment,
ExpSyntaxNode whileRule,
ExpSyntaxNode untilRule,
ExpSyntaxNode body)
{
untilRule = ExpBoolNode.False(null);
whileRule = ExpBoolNode.True(null);
ExpRepeatNode ret = new ExpRepeatNode(
t, repeatVariable.OriginObject, begin, end, increment, body, whileRule, untilRule)
{
/*
* 0: variable name
* 1: beginning value
* 2: ending value
* 3: increment
* 4: body
* 5: while
* 6: until
*/
CodeConvertTemplate = $$"""
for( {0} = {1}; {0} <= {2}; {0} += {3})
{
if(!( {5} )) break;
{4}
if( {6} ) break;
}
"""
};
return ret;
}
public static ExpRepeatNode Create(
Token t,
ExpElementInstance repeatVariable,
ExpSyntaxNode begin,
ExpSyntaxNode end,
ExpSyntaxNode increment,
ExpSyntaxNode whileRule,
ExpSyntaxNode untilRule,
ExpSyntaxNode 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: variable name
* 1: beginning value
* 2: ending value
* 3: increment
* 4: body
* 5: while
* 6: until
*/
CodeConvertTemplate = $$"""
for({{repeatVariable.TypeName}} {0} = {1}; {0} <= {2}; {0} += {3})
{
if(!( {5} )) break;
{4}
if( {6} ) break;
}
"""
};
return ret;
}
}
}
@@ -0,0 +1,136 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSwitchNode.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.Frozen;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public class ExpSwitchNode : ExpSyntaxNode
{
private ExpSyntaxNode _default;
private ExpSyntaxNode _target;
private FrozenDictionary<ExpSyntaxNode, ExpSyntaxNode> _cases;
public ExpSwitchNode(
Token source,
ExpSyntaxNode target,
ExpSyntaxNode defaultCase,
params (ExpSyntaxNode label, ExpSyntaxNode op)[] cases )
: base( source )
{
_target = target;
_default = defaultCase;
Dictionary<ExpSyntaxNode, ExpSyntaxNode> casesDic = new Dictionary<ExpSyntaxNode, ExpSyntaxNode>(
);
foreach( (ExpSyntaxNode label, ExpSyntaxNode 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,
ExpSyntaxNode target,
ExpSyntaxNode defaultCase,
IDictionary<ExpSyntaxNode, ExpSyntaxNode> 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 ExpSyntaxNode this[ ExpSyntaxNode index ]
{
get
{
if( _cases.TryGetValue( index, out ExpSyntaxNode? ret ) ) {
return ret;
}
return _default;
}
}
public override ExpSyntaxNode Left => Empty;
public override ExpSyntaxNode Right => Empty;
public override IExpElementSource EqualityTypeConvert => null!;
public bool ContainsCase( ExpSyntaxNode token )
{
return _cases.ContainsKey( token );
}
}
}
@@ -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 ExpNodePresidentEnumerator TupleAsEnumerator()
{
return node.ToPresidentEnumerator();
}
}
}
@@ -0,0 +1,103 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpUnaryOperatorNode.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpUnaryOperatorNode : ExpSyntaxNode
{
private ExpSyntaxNode _operand;
private ExpUnaryOperatorNode( Token source ) : base( source ) { }
public ExpUnaryOperatorNode( Token source, ExpSyntaxNode operand, ExpSchema context )
: base( source )
{
_operand = operand;
}
public override ExpSyntaxNode Left => null!;
public override ExpSyntaxNode Right => _operand;
public override IExpElementSource EqualityTypeConvert => _operand.EqualityTypeConvert;
public static ExpUnaryOperatorNode UnaryMinus( Token source, ExpSyntaxNode operand )
{
if( !operand.IsNumber ) {
throw new ExpInvalidTypeException(
source, "Number", operand.EqualityTypeConvert.Name );
}
bool isFloat =
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
return new ExpUnaryOperatorNode( source )
{
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "- {0}",
};
}
public static ExpUnaryOperatorNode UnaryNot( Token source, ExpSyntaxNode operand )
{
if( ( operand._nodeFlag | ( ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.BuiltinType_Logic ) ) ==
0 ) {
throw new ExpInvalidTypeException(
source, "Bool or Logic", operand.EqualityTypeConvert.Name );
}
return new ExpUnaryOperatorNode( source )
{
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Logic,
CodeConvertTemplate = "! {0}",
};
}
public static ExpUnaryOperatorNode UnaryPlus( Token source, ExpSyntaxNode operand )
{
if( !operand.IsNumber ) {
throw new ExpInvalidTypeException(
source, "Number", operand.EqualityTypeConvert.Name );
}
bool isFloat =
( operand._nodeFlag | ExpNodeFlag.BuiltinType_Real ) == 0;
return new ExpUnaryOperatorNode( source )
{
_nodeFlag = ExpNodeFlag.Operator_Unary | ExpNodeFlag.BuiltinType_Number,
CodeConvertTemplate = "+ {0}",
};
}
}
}
@@ -0,0 +1,155 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpSyntaxNode : ISyntaxNode<ExpSyntaxNode, IExpElementSource>
{
protected internal ExpNodeFlag _nodeFlag;
protected internal Token _source;
protected ExpSyntaxNode( Token source )
{
_source = source;
Next = this;
Previous = this;
}
public bool IsNumber
{
get { return ( _nodeFlag | ExpNodeFlag.BuiltinType_Number ) != 0; }
}
public abstract ExpSyntaxNode Left { get; }
public static ExpSyntaxNode Empty
{
get => ExpEmptyNode._only;
}
public ExpSyntaxNode Next { get; set; }
public abstract ExpSyntaxNode Right { get; }
public ExpSyntaxNode Previous { get; set; }
public abstract IExpElementSource EqualityTypeConvert { get; }
public int Line => _source.Line;
public int Column => _source.Column;
public long NodeFlag => ( long )_nodeFlag;
public string CodeConvertTemplate { get; init; }
public Token Source
{
get => _source;
}
public void AppendNode( ExpSyntaxNode nextNode )
{
Next.Previous = nextNode;
nextNode.Next = Next;
Next = nextNode;
Next.Previous = this;
}
public static bool IsNullOrEmpty( [AllowNull]ExpSyntaxNode node )
{
return node == ExpEmptyNode._only || node == null;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static ExpSyntaxNode NonOperation( Token source )
{
return new ExpEmptyNode( source.Line, source.Column );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static ExpSyntaxNode NonOperation( int line, int column )
{
return new ExpEmptyNode( line, column );
}
public void PrependNode( ExpSyntaxNode previousNode )
{
Previous.Next = previousNode;
previousNode.Previous = Previous;
Previous = previousNode;
previousNode.Next = this;
}
public static bool VerifyTypeConvertable( ExpSyntaxNode left, ExpSyntaxNode right )
{
IExpElementSource tLeft = left.EqualityTypeConvert,
tRight = right.EqualityTypeConvert;
if( tLeft is not ExpInstantiableElement tLeftIns ||
tRight is not ExpInstantiableElement tRightIns ) {
return false;
}
if( ExpInstantiableElement.IsNullOrVoid( tLeftIns ) ||
ExpInstantiableElement.IsNullOrVoid( tLeftIns ) ) {
return false;
}
return tLeft.IsConvertable( tRight );
}
private class ExpEmptyNode : ExpSyntaxNode
{
internal static readonly ExpEmptyNode _only = new();
public ExpEmptyNode() : base( Token.Empty ) { }
public ExpEmptyNode( int line, int column )
: base( new Token( string.Empty, line, column, TokenFlag.None ) ) { }
public override ExpInstantiableElement EqualityTypeConvert => ExpInstantiableElement.Void;
public override ExpSyntaxNode Left => _only;
public override ExpSyntaxNode Right => _only;
}
}
}
@@ -0,0 +1,133 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpElementInstance.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.IO;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Script.Express
{
[Flags]
public enum ExpElementType : int
{
Void = 0,
Const = 1,
Entity = 2,
Type = 4,
Function = 8,
Section = 16,
Expression = 32,
Rule = 64,
Procedure = 128,
Collection = 256,
}
public abstract class ExpElementInstance : ExpSyntaxNode
{
protected ExpElementInstance( Token source )
: base( source )
{
CodeConvertTemplate = source.Value;
}
public bool IsLiteral { get; init; }
public ExpElementType ElementType { get; }
public override ExpSyntaxNode Left => Empty;
public override ExpSyntaxNode Right => Empty;
public abstract string TypeName { get; }
public static ExpElementInstance CreateLiteral( Token t )
{
if( int.TryParse( t.Value, out int _int ) )
{
return new ExpIntNode( t, _int, true );
} else if( float.TryParse( t.Value, out float _float ) )
{
return new ExpRealNumberNode( t, _float, true );
} else if( bool.TryParse( t.Value, out bool _bool ) )
{
return new ExpBoolNode( t, _bool, true );
} else if( ExpLogic.TryParse( t.Value, out ExpLogic _logic ) )
{
return new ExpLogicValueNode( t, _logic, true );
} else
{
return new ExpStringNode( t, t.Value, true );
}
}
public ExpInstanceReferenceNode MakeReference( Token t )
{
return new ExpInstanceReferenceNode( t, this );
}
public static bool TryCreateLiteral( Token t, out ExpElementInstance instance )
{
if( int.TryParse( t.Value, out int _int ) )
{
instance = new ExpIntNode( t, _int, true );
return true;
} else if( float.TryParse( t.Value, out float _float ) )
{
instance = new ExpRealNumberNode( t, _float, true );
return true;
} else if( bool.TryParse( t.Value, out bool _bool ) )
{
instance = new ExpBoolNode( t, _bool, true );
return true;
} else if( ExpLogic.TryParse( t.Value, out ExpLogic _logic ) )
{
instance = new ExpLogicValueNode( t, _logic, true );
return true;
} else if( t.Flag == TokenFlag.String )
{
instance = new ExpStringNode( t, t.Value, true );
return true;
}
instance = null!;
return false;
}
public bool TryGetMember( string name, out ExpSyntaxNode node )
{
return EqualityTypeConvert.TryGetMember( name, out node );
}
}
}
+156
View File
@@ -0,0 +1,156 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpElmentSource.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public interface IExpElementSource : ITypeSource<IExpElementSource>
{
public ExpElementType ElementType { get; }
IScriptSourceProvider SourceProvider { get; }
string Name { get; }
public void AddMember( string name, ExpSyntaxNode memberNode );
public void Analyse();
public bool TryGetMember( string name, out ExpSyntaxNode memberNode );
}
public abstract class ExpInstantiableElement : IExpElementSource
{
private List<ExpInstantiableElement> _baseList = new List<ExpInstantiableElement>(),
_derivationList = new List<ExpInstantiableElement>();
public abstract ExpElementType ElementType { get; }
public static ExpInstantiableElement Void
{
get => ExpVoidElement.Only;
}
public abstract IScriptSourceProvider SourceProvider { get; }
public abstract string Name { get; }
public void AddMember( string name, ExpSyntaxNode memberNode )
{
throw new NotImplementedException();
}
public abstract void Analyse();
public abstract ExpSyntaxNode CreateInstanceNode( Token t );
public bool IsConvertable( IExpElementSource targetType )
{
if( targetType == null ) {
return false;
}
throw new NotImplementedException();
}
public static bool IsNullOrVoid( ExpInstantiableElement element )
{
return element == null || element == ExpVoidElement.Only;
}
public abstract bool TryGetMember( string name, out ExpSyntaxNode memberNode );
private sealed class ExpVoidElement : ExpInstantiableElement
{
private static readonly ExpVoidElement _only = new ExpVoidElement();
public override ExpElementType ElementType => ExpElementType.Void;
public static ExpVoidElement Only => _only;
public override IScriptSourceProvider SourceProvider => ScriptSourceTransmitter.Empty;
public override string Name => "void";
public override void Analyse()
{
return;
}
public override ExpSyntaxNode CreateInstanceNode( Token t )
{
return ExpSyntaxNode.Empty;
}
public override bool TryGetMember( string name, out ExpSyntaxNode memberNode )
{
memberNode = ExpSyntaxNode.Empty;
return false;
}
}
}
public abstract class ExpImmutableElement : IExpElementSource
{
public abstract ExpElementType ElementType { get; }
public abstract IScriptSourceProvider SourceProvider { get; }
public abstract string Name { get; }
public void AddMember( string name, ExpSyntaxNode memberNode )
{
throw new NotImplementedException();
}
public abstract void Analyse();
public bool IsConvertable( IExpElementSource targetType )
{
return false;
}
public abstract ExpSyntaxNode MakeReference( params object[] options );
public abstract bool TryGetMember( string name, out ExpSyntaxNode memberNode );
}
}
+187
View File
@@ -0,0 +1,187 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpExceptions.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.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace StgSharp.Script.Express
{
public class ExpException : Exception
{
private Token _pos;
public ExpException( string message ) : base( message ) { }
public ExpException( Token position, string message )
: base( $"Express compile error at {position.Line}-{position.Column}:\n{message}" )
{
_pos = position;
}
public ExpException( ExpSyntaxNode node, string message )
: base(
$"Express compile error at {node.Source.Line}-{node.Source.Column}:\n{message}" )
{
_pos = node._source;
}
}
public class ExpInvalidCharException : ExpException
{
public ExpInvalidCharException( char c ) : base( $"An unknown char {c} occurred." ) { }
public ExpInvalidCharException( int index )
: base( $"Cannot read a token from line at {index}" ) { }
}
public class ExpStringNotCloseException : ExpException
{
public ExpStringNotCloseException( int linenum )
: base( $"A string does not closed at end of line {linenum}." ) { }
}
public class ExpInvalidSyntaxException : ExpException
{
public ExpInvalidSyntaxException( string message ) : base( message ) { }
public static void ThrowNonCollectionIndex( Token t )
{
throw new ExpInvalidSyntaxException(
$"Use a collection indexer to a non-collection variable at line {t.Line} column {t.Column}" );
}
public static void ThrowNoOperator( Token t )
{
throw new ExpInvalidSyntaxException(
$"No operator but more than one operand before line {t.Line} column {t.Column}" );
}
}
public class ExpInvalidElementDeclareEndingExceptions : ExpException
{
public ExpInvalidElementDeclareEndingExceptions( string declaredName, string endedName )
: base(
$"The datatype is declared with name {declaredName} but ended with {endedName}" ) { }
}
public class ExpInvalidElementNameException : ExpException
{
public ExpInvalidElementNameException( string elementName, ExpSchema schema )
: base( $"Cannot find any element named {elementName} in {schema.Name}" ) { }
}
public class ExpInvalidTypeException : ExpException
{
public ExpInvalidTypeException( ExpSyntaxNode node, string required, string provided )
: base(
node,
$"Type {required} is required at position, but a {provided} instance is provided." ) { }
public ExpInvalidTypeException( Token t, string required, string provided )
: base(
t,
$"Type {required} is required at position, but a {provided} instance is provided." ) { }
}
public class ExpCaseNotFoundException : ArgumentOutOfRangeException
{
public ExpCaseNotFoundException( ExpSwitchNode token, ExpSyntaxNode label )
: base(
$"Attempt to read or write the label at ({token.Line},{token.Column}), that does not exist in SWITCH expression at ({token.Line},{token.Column})" ) { }
}
public class ExpInvalidCollectionMemberTypeException : InvalidCastException
{
public ExpInvalidCollectionMemberTypeException(
ExpElementInstance elementInstance,
ExpCollectionBase collection )
: base(
$"Attempt to add or remove an element of type: {elementInstance.ElementType} from a collection collects {collection.MemberType}" ) { }
}
public class ExpInvalidSchemaIncludeException : InvalidOperationException
{
public ExpInvalidSchemaIncludeException( ExpSchema context, ExpSchema source )
: base(
$"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 ExpElementLoadException : TypeLoadException
{
public ExpElementLoadException( string typeName, ExpSchema context )
: base(
$"Cannot find the element {typeName} in schema {context.Name} and its included schemas" ) { }
}
public class ExpCompileNotInitializedException : InvalidOperationException
{
public ExpCompileNotInitializedException()
: base( "Attempt to compile an EXPRESS script before the init of compiler." ) { }
}
public class ExpCompileException : ExpException
{
public ExpCompileException( Token pos, string message )
: base(
$"Compiler exception occur when processing token at line {pos.Line}, column {pos.Column}. Detailed message:{Environment.NewLine}{message} " ) { }
}
}
+124
View File
@@ -0,0 +1,124 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpNodeFlag.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.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
[EditorBrowsable( EditorBrowsableState.Never )]
public static class ExpNodeFlagHelper
{
public static bool IsInFlag( this ExpNodeFlag flag, long target )
{
return ( ( long )flag & target ) != 0;
}
public static bool IsInFlag( this ExpNodeFlag flag, ExpNodeFlag target )
{
return ( long )( flag & target ) != 0;
}
public static bool IsNotInFlag( this ExpNodeFlag flag, long target )
{
return ( ( long )flag & target ) == 0;
}
public static bool IsNotInFlag( this ExpNodeFlag flag, ExpNodeFlag target )
{
return ( long )( flag & target ) == 0;
}
}
[Flags]
public enum ExpNodeFlag : long
{
//string as name of non-builtin variables
None = 0,
Name_Element = 1,
Name_Param = 2,
Name_Block = 4,
Name_Keyword = 8,
Name_Operator = 16,
Name_Any = Name_Block | Name_Element | Name_Keyword | Name_Param | Name_Operator,
//any type of collections, also has NAME flag
Collection_Set = 32,
Collection_Bag = 64,
Collection_Array = 128,
Collection_List = 256,
Collection_Any = Collection_Set | Collection_Bag | Collection_Array | Collection_List,
//the variable is type of element, both builtin and non-builtin has this flag
Element_Const = 512,
Element_Entity = 1024,
Element_Type = 2048,
Element_Rule = 4096,
Element_Function = 8192,
Element_Any = Element_Entity | Element_Const | Element_Function | Element_Rule | Element_Type,
//variable is one of these builtin type
BuiltinType_Int = 16384,
BuiltinType_Real = 32768,
BuiltinType_String = 65536,
BuiltinType_Boolean = 0x2000,
BuiltinType_Binary = 0x4000,
BuiltinType_Logic = 0x8000,
BuiltinType_Number = BuiltinType_Real | BuiltinType_Int,
BuiltinType_Any = BuiltinType_Int | BuiltinType_Real | BuiltinType_String | BuiltinType_Boolean | BuiltinType_Binary | BuiltinType_Logic,
//the token is root of a branch
Branch_If = 0x1_000,
Branch_Switch = 0x2_0000,
Branch_Repeat = 0x4_0000,
Branch_Any = Branch_If | Branch_Repeat | Branch_Switch,
//the token is one of separators
Separator_Inline = 0x8_0000, //, or sth else
Separator_Line = 0x10_0000, //; or eth else
Separator_Block = 0x20_0000, //{}or sth else
Separator_Range = 0x40_0000, //()or sth else
Separator_Any = Separator_Inline | Separator_Line | Separator_Block | Separator_Range,
//the token is a kind of operator
Operator_Unary = 0x40_0000,
Operator_Binary = 0x80_0000,
Operator_SuperType = 0x100_0000,
Operator_Any = Operator_Unary | Operator_Binary | Operator_SuperType,
}
}
@@ -0,0 +1,200 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpNodeTempEnumerator.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 System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public static class ExpNodeNextEnumeratorExtensions
{
public static ExpNodeTempEnumerator AsCollectionEnumerator(
this ExpSyntaxNode token,
bool unpack )
{
ExpNodeTempEnumerator enumerator = new ExpNodeTempEnumerator( token, unpack );
IExpElementSource type = token.EqualityTypeConvert;
while( enumerator.MoveNext() )
{
if( enumerator. Current != type ) {
throw new InvalidCastException();
}
}
return enumerator;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static ExpNodePresidentEnumerator ToPresidentEnumerator( this ExpSyntaxNode node )
{
return new ExpNodePresidentEnumerator( node );
}
public static ExpNodePresidentEnumerator TupleToPresidentEnumerator(
this ExpSyntaxNode tuple )
{
return new ExpNodePresidentEnumerator( tuple.Right );
}
}
public class ExpNodePresidentEnumerator : IEnumerator<ExpSyntaxNode>
{
private int _index = -1;
private List<ExpSyntaxNode> _begin = new List<ExpSyntaxNode>();
public ExpNodePresidentEnumerator( ExpSyntaxNode token )
{
_begin.Add( token );
ExpSyntaxNode t = token;
while( !ReferenceEquals( t.Next, token ) && t.Next != null )
{
t = t.Next;
_begin.Add( t );
}
}
public ExpSyntaxNode this[ int index ]
{
get
{
ArgumentOutOfRangeException.ThrowIfNegative( index );
ArgumentOutOfRangeException.ThrowIfGreaterThan( index, _begin.Count );
return _begin[ index ];
}
}
public ExpSyntaxNode Current => _begin[ _index ];
public int Count => _begin.Count;
public void AssertEnumeratorCount( int count )
{
if( _begin.Count != count ) {
throw new InvalidOperationException(
$"Enumerator count mismatch. Expected {count}, but got {_begin.Count}." );
}
}
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 Span<ExpSyntaxNode> AsSpan()
{
return CollectionsMarshal.AsSpan( _begin );
}
public void Dispose()
{
return;
}
public bool MoveNext()
{
if( _index < _begin.Count - 1 )
{
_index++;
return true;
}
return false;
}
public void Reset()
{
_index = -1;
}
object IEnumerator.Current => this.Current;
}
public class ExpNodeTempEnumerator : IEnumerator<ExpSyntaxNode>
{
private ExpSyntaxNode? _current,_begin;
public ExpNodeTempEnumerator( ExpSyntaxNode node )
{
_current = null;
_begin = node;
}
public ExpNodeTempEnumerator( ExpSyntaxNode node, bool unpack )
{
_current = null;
_begin = unpack ? node.Right : node;
}
public ExpSyntaxNode Current => _current!;
public bool MoveNext()
{
if( _current == null )
{
_current = _begin;
return true;
}
ExpSyntaxNode next = _current.Next;
if( ReferenceEquals( next, _begin ) || next == null ) {
return false;
}
_current = next;
return true;
}
void IDisposable.Dispose()
{
return;
}
void IEnumerator.Reset()
{
_current = null;
}
object IEnumerator.Current => _current;
}
}
+109
View File
@@ -0,0 +1,109 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpPostProcessor.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;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpPostProcessor
{
private readonly string _interfaceName /*= typeof( )/**/;
private readonly string _sourcePath;
public string Process( string filePath )
{
Dictionary<string, string> factoryMethods = new Dictionary<string, string>();
FileStream file = File.OpenRead( filePath );
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText( File.ReadAllText( filePath ) );
CSharpCompilation compilation = CSharpCompilation.Create( "Analysis" )
.AddSyntaxTrees( syntaxTree )
.AddReferences(
MetadataReference.CreateFromFile(
typeof( object ).Assembly.Location ) );
INamedTypeSymbol? interfaceSymbol = compilation.GetTypeByMetadataName( _interfaceName );
if( interfaceSymbol == null ) {
throw new InvalidOperationException( $"Interface '{_interfaceName}' not found." );
}
SemanticModel semanticModel = compilation.GetSemanticModel( syntaxTree );
SyntaxNode root = syntaxTree.GetRoot();
IEnumerable<ClassDeclarationSyntax> classDeclarations = root.DescendantNodes()
.OfType<ClassDeclarationSyntax>(
)
.Where(
cls => cls.BaseList?.Types.Any(
t => SymbolEqualityComparer.Default
.Equals(
semanticModel.GetTypeInfo(
t.Type )
.Type,
interfaceSymbol ) ) ??
false );
foreach( ClassDeclarationSyntax classDeclaration in classDeclarations )
{
string className = classDeclaration.Identifier.Text;
IMethodSymbol? factoryMethod = interfaceSymbol.GetMembers()
.OfType<IMethodSymbol>()
.FirstOrDefault(
m => m.IsStatic &&
m.Name == "CreateInstance" );
if( factoryMethod != null ) {
factoryMethods[ className ] = $"() => {interfaceSymbol.Name}.CreateInstance()";
}
}
string code = "var factoryMethods = new Dictionary<string, Func<object>>\n{\n";
code += string.Join(
",\n", factoryMethods.Select( kvp => $" {{ \"{kvp.Key}\", {kvp.Value} }}" ) );
code += "\n};";
return code;
}
}
}
+88
View File
@@ -0,0 +1,88 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSchemaBase.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.Collections;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Linq;
namespace StgSharp.Script.Express
{
public abstract class ExpSchema
{
public static ExpSchema BuiltinSchema
{
get => ExpSchema_Builtin.Only;
}
public string Name { get; internal set; }
public abstract void LoadFromSource( ExpSchemaSource source );
public abstract bool TryGetConst( string name, out ExpElementInstance c );
public abstract bool TryGetEntity( string name, out ExpEntitySource e );
public abstract bool TryGetFunction( string name, out ExpFunctionSource f );
public abstract bool TryGetProcedure( string name, out ExpProcedureSource p );
public abstract bool TryGetRule( string name, out ExpRuleSource r );
public abstract bool TryGetSchemaInclude( string name, out ExpSchema include );
public abstract bool TryGetType( string name, out ExpTypeSource t );
#pragma warning disable CS8618
protected FrozenDictionary<string, ExpElementInstance> ConstDict { get; set; }
public IEnumerable<ExpSchema> IncludedSchema => IncludedSchema;
protected FrozenDictionary<string, ExpEntitySource> EntityDict { get; set; }
protected FrozenDictionary<string, ExpFunctionSource> FunctionDict { get; set; }
protected ConcurrentStringHashMultiplexer StringMultiplexer => ExpressCompile.Multiplexer;
protected ConcurrentDictionary<string, ExpProcedureSource> ProcedureDict { get; set; }
protected FrozenDictionary<string, ExpRuleSource> RuleDict { get; set; }
protected FrozenDictionary<string, ExpSchema> SchemaInclude { get; set; }
protected FrozenDictionary<string, ExpTypeSource> TypeDict { get; set; }
#pragma warning restore CS8618
}
}
@@ -0,0 +1,72 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSchemaSource.Compile.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public enum ExpressCompileOption
{
Default = 0,
Translate = 1,
Compile = 2,
}
public partial class ExpSchemaSource
{
public ExpSchema Compile( ExpressCompileOption option )
{
switch( option )
{
case ExpressCompileOption.Default:
return Compile_Translate( option );
case ExpressCompileOption.Translate:
return Compile_Translate( option );
case ExpressCompileOption.Compile:
throw new NotSupportedException();
default:
throw new ArgumentException();
}
}
internal GeneratedExpSchema Compile_Translate( ExpressCompileOption option )
{
throw new NotImplementedException();
}
}
}
+362
View File
@@ -0,0 +1,362 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSchemaSource.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.Collections;
using StgSharp.Graphics.OpenGL;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Text;
using System.Text.RegularExpressions;
namespace StgSharp.Script.Express
{
public partial class ExpSchemaSource
{
private static Regex
_constDefineBegin = GetConstDefineBegin(),
_constDefineEnd = GetConstDefineEnd(),
_schemaBegin = GetSchemaBegin(),
_schemaEnd = GetSchemaEnd(),
_entityDefineBegin = GetEntityDefineBegin(),
_entityDefineEnd = GetEntityDefineEnd(),
_typeDefineBegin = GetTypeDefineBegin(),
_typeDefineEnd = GetTypeDefineEnd(),
_functionDefineBegin = GetFunctionDefineBegin(),
_functionDefineEnd = GetFunctionDefineEnd(),
_ruleDefineBegin = GetRuleDefineBegin(),
_ruleDefineEnd = GetRuleDefineEnd();
private readonly GeneratedExpSchema _compileResult = new GeneratedExpSchema();
private List<IExpElementSource> _sourceCache = [];
private string name;
public ExpSchemaSource() { }
public List<IExpElementSource> Cache
{
get => _sourceCache;
}
public string Name
{
get => _compileResult.Name;
internal set => _compileResult.Name = value;
}
public ExpSchema Organize()
{
_compileResult.LoadFromSource( this );
return _compileResult;
}
public void ReadSchema( ExpFileSource reader )
{
string line = reader.ReadLine();
while( !_schemaBegin.IsMatch( line ) ) {
line = reader.ReadLine();
}
name = _schemaBegin.Match( line ).Groups[ "namespace" ].Value;
while( !_schemaEnd.IsMatch( line ) )
{
if( TryReadConst( line, reader, out IExpElementSource source ) )
{
_sourceCache.Add( source );
} else if( TryReadType( line, reader, out source ) )
{
_sourceCache.Add( source );
} else if( TryReadEntity( line, reader, out source ) )
{
_sourceCache.Add( source );
} else if( TryReadRule( line, reader, out source ) )
{
_sourceCache.Add( source );
} else if( TryReadFunction( line, reader, out source ) ) {
_sourceCache.Add( source );
}
line = reader.ReadLine();
}
}
public static bool TryReadSchema(
string firstLine,
ExpFileSource reader,
out ExpSchemaSource source )
{
if( !_schemaBegin.IsMatch( firstLine ) )
{
source = null!;
return false;
}
ExpSchemaSource _source = new ExpSchemaSource();
_source.name = _schemaBegin.Match( firstLine ).Groups[ "namespace" ].Value;
while( !_schemaEnd.IsMatch( firstLine ) )
{
if( _source.TryReadConst( firstLine, reader,
out IExpElementSource _elementSource ) )
{
_source._sourceCache.Add( _elementSource );
} else if( _source.TryReadType( firstLine, reader, out _elementSource ) )
{
_source._sourceCache.Add( _elementSource );
} else if( _source.TryReadEntity( firstLine, reader, out _elementSource ) )
{
_source._sourceCache.Add( _elementSource );
} else if( _source.TryReadRule( firstLine, reader, out _elementSource ) )
{
_source._sourceCache.Add( _elementSource );
} else if( _source.TryReadFunction( firstLine, reader, out _elementSource ) ) {
_source._sourceCache.Add( _elementSource );
}
firstLine = reader.ReadLine();
}
source = _source;
return true;
}
[GeneratedRegex( @"\s*CONSTANT" )]
private static partial Regex GetConstDefineBegin();
[GeneratedRegex( @"\s*END_CONSTANT;" )]
private static partial Regex GetConstDefineEnd();
[GeneratedRegex( @"\s*ENTITY\s*(?<TypeName>[A-Za-z0-9_]+)\s*", RegexOptions.Compiled )]
private static partial Regex GetEntityDefineBegin();
[GeneratedRegex(
@"\s*END_ENTITY;\s*--\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
RegexOptions.Compiled )]
private static partial Regex GetEntityDefineEnd();
[GeneratedRegex(
@"\s*FUNCTION\s*\s*(?<FunctionName>[a-zA-Z0-9_]+)\s*(?<Remaining>.*)",
RegexOptions.Compiled )]
private static partial Regex GetFunctionDefineBegin();
[GeneratedRegex(
@"\s*END_FUNCTION\s*;\s*--\s*(?<FunctionName>[a-zA-Z0-9_]+)",
RegexOptions.Compiled )]
private static partial Regex GetFunctionDefineEnd();
[GeneratedRegex(
@"\s*RULE\s*(?<RuleName>[a-zA-Z0-9_]+)\s*FOR\s*\((?<Target>[a-zA-Z0-9_]*(?:\s*\)\s*;)?)",
RegexOptions.Compiled )]
private static partial Regex GetRuleDefineBegin();
[GeneratedRegex(
@"\s*END_RULE\s*;\s*--\s*(?<RuleName>[A-Za-z0-9_]+)",
RegexOptions.Compiled )]
private static partial Regex GetRuleDefineEnd();
[GeneratedRegex( @"\s*SCHEMA\s*(?<namespace>[A-Za-z0-9_]+)\s?;" )]
private static partial Regex GetSchemaBegin();
[GeneratedRegex( @"END_SCHEMA;\s*--\s*(?<namespace>[A-Za-z0-9_]+)", RegexOptions.Compiled )]
private static partial Regex GetSchemaEnd();
[GeneratedRegex(
@"\s*TYPE\s+(?<TypeName>[A-Za-z0-9_]+)\s*=\s*(?<Remaining>[A-Z]+)",
RegexOptions.Compiled )]
private static partial Regex GetTypeDefineBegin();
[GeneratedRegex(
@"\s*END_TYPE\s*;\s*--\s*(?<TypeName>[a-zA-Z0-9_]+)",
RegexOptions.Compiled )]
private static partial Regex GetTypeDefineEnd();
private bool TryReadConst(
string firstLine,
ExpFileSource reader,
out IExpElementSource source )
{
Match match = _constDefineBegin.Match( firstLine );
if( match.Success )
{
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_CONSTANT", reader.Location );
ExpConstantCollectionSource _source = new ExpConstantCollectionSource( transmitter );
string line = reader.ReadLine();
while( !_constDefineEnd.IsMatch( line ) )
{
transmitter.WriteLine( line );
line = reader.ReadLine();
}
transmitter.WriteLine( "END_CONSTANT" );
source = _source;
return true;
}
source = null!;
return false;
}
private bool TryReadEntity(
string firstLine,
ExpFileSource reader,
out IExpElementSource source )
{
Match match = _entityDefineBegin.Match( firstLine );
if( match.Success )
{
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_ENTITY", reader.Location );
ExpEntitySource _source = new ExpEntitySource(
match.Groups[ "TypeName" ].ToString(), transmitter );
string line = reader.ReadLine();
match = _entityDefineEnd.Match( line );
while( !match.Success )
{
transmitter.WriteLine( line );
line = reader.ReadLine();
match = _entityDefineEnd.Match( line );
}
string endedName = match.Groups[ "TypeName" ].ToString();
if( !string.Equals( endedName, _source.Name ) ) {
throw new ExpInvalidElementDeclareEndingExceptions( _source.Name, endedName );
}
transmitter.WriteLine( "END_ENTITY" );
source = _source;
return true;
}
source = null!;
return false;
}
private bool TryReadFunction(
string firstLine,
ExpFileSource reader,
out IExpElementSource source )
{
Match match = _functionDefineBegin.Match( firstLine );
if( match.Success )
{
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_FUNCTION", reader.Location );
ExpFunctionSource _source = new ExpFunctionSource(
match.Groups[ "FunctionName" ].ToString(), transmitter );
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
string line = reader.ReadLine();
match = _functionDefineEnd.Match( line );
while( !match.Success )
{
transmitter.WriteLine( line );
line = reader.ReadLine();
match = _functionDefineEnd.Match( line );
}
string endedName = match.Groups[ "FunctionName" ].ToString();
if( !string.Equals( endedName, _source.Name ) ) {
throw new ExpInvalidElementDeclareEndingExceptions( _source.Name, endedName );
}
transmitter.WriteLine( "END_FUNCTION" );
source = _source;
return true;
}
source = null!;
return false;
}
private bool TryReadRule(
string firstLine,
ExpFileSource reader,
out IExpElementSource source )
{
Match match = _ruleDefineBegin.Match( firstLine );
if( match.Success )
{
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_RULE", reader.Location );
ExpRuleSource _source = new ExpRuleSource(
match.Groups[ "RuleName" ].ToString(), transmitter );
string target = match.Groups[ "Target" ].ToString();
if( !string.IsNullOrEmpty( target ) ) {
transmitter.WriteLine( target );
}
string line = reader.ReadLine();
match = _ruleDefineEnd.Match( line );
while( !match.Success )
{
transmitter.WriteLine( line );
line = reader.ReadLine();
match = _ruleDefineEnd.Match( line );
}
string endedName = match.Groups[ "RuleName" ].ToString();
if( !string.Equals( endedName, _source.Name ) ) {
throw new ExpInvalidElementDeclareEndingExceptions( _source.Name, endedName );
}
transmitter.WriteLine( "END_RULE" );
source = _source;
return true;
}
source = null!;
return false;
}
private bool TryReadType(
string firstLine,
ExpFileSource reader,
out IExpElementSource source )
{
Match match = _typeDefineBegin.Match( firstLine );
if( match.Success )
{
ScriptSourceTransmitter transmitter = new ScriptSourceTransmitter(
"END_ENTITY", reader.Location );
ExpTypeSource _source = new ExpTypeSource(
match.Groups[ "TypeName" ].ToString(), transmitter );
transmitter.WriteLine( match.Groups[ "Remaining" ].ToString() );
string line = reader.ReadLine();
match = _typeDefineEnd.Match( line );
while( !match.Success )
{
transmitter.WriteLine( line );
line = reader.ReadLine();
match = _typeDefineEnd.Match( line );
}
string endedName = match.Groups[ "TypeName" ].ToString();
if( !string.Equals( endedName, _source.Name ) ) {
throw new ExpInvalidElementDeclareEndingExceptions( _source.Name, endedName );
}
transmitter.WriteLine( "END_ENTITY" );
source = _source;
return true;
}
source = null!;
return false;
}
}
}
+126
View File
@@ -0,0 +1,126 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSource.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.IO;
using System.IO.MemoryMappedFiles;
using System.Text;
using System.Threading;
namespace StgSharp.Script.Express
{
public class ExpFileSource : IDisposable, IScriptSourceProvider
{
private bool disposedValue;
private FileStream _expFileStream;
private int _location;
private MemoryMappedFile _expMemoryMappedFile;
private MemoryMappedViewStream _expMemoryMappedStream;
private SemaphoreSlim readLineSemaphore = new SemaphoreSlim( 1, 1 );
private StreamReader _memoryReader;
public ExpFileSource( string path )
{
if( !File.Exists( path ) ) {
throw new FileNotFoundException();
}
_expFileStream = new FileStream( path, FileMode.Open, FileAccess.Read );
_expMemoryMappedFile = MemoryMappedFile.CreateFromFile(
_expFileStream, null, 0, MemoryMappedFileAccess.Read, HandleInheritability.None,
true );
_expMemoryMappedStream = _expMemoryMappedFile.CreateViewStream(
offset: 0, size: 0, access: MemoryMappedFileAccess.Read );
_memoryReader = new StreamReader( _expMemoryMappedStream );
}
public bool IsEmpty => _memoryReader.EndOfStream;
public int Location => _location;
// ~ExpFileSource()
// {
// Dispose(disposing: false);
// }
public void Dispose()
{
Dispose( disposing: true );
GC.SuppressFinalize( this );
}
public void EndWriting() { }
public string ReadLine()
{
readLineSemaphore.Wait();
string line = _memoryReader.ReadLine()!;
_location++;
readLineSemaphore.Release();
return line;
}
public string ReadLine( out int position )
{
throw new NotImplementedException();
}
public void ResetToBegin()
{
readLineSemaphore.Wait();
_expMemoryMappedStream.Seek( 0, SeekOrigin.Begin );
_location = 0;
readLineSemaphore.Release();
}
protected virtual void Dispose( bool disposing )
{
if( !disposedValue )
{
if( disposing )
{
_expFileStream.Dispose();
_expMemoryMappedFile.Dispose();
_expMemoryMappedStream.Dispose();
_memoryReader.Dispose();
}
disposedValue = true;
}
}
IScriptSourceProvider IScriptSourceProvider.Slice( int location, int count )
{
throw new NotSupportedException();
}
}
}
@@ -0,0 +1,132 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
ExpSyntaxNode 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<ExpSyntaxNode, ExpSyntaxNode> Cases { get; } = new Dictionary<ExpSyntaxNode, ExpSyntaxNode>(
);
public ExpSyntaxNode CaseExpression { get; set; }
public ExpSyntaxNode DefaultCase { get; set; }
public ExpSyntaxNode CurrentCase { get; set; }
public string CurrentState { get; set; }
public Token Begin { get; init; }
public void CloseCurrentCase( ExpSyntaxNode root )
{
Cases.Add( CurrentCase, root );
}
}
}
}
@@ -0,0 +1,293 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.Common.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 System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Schema;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Script.Express
{
public partial class ExpSyntaxAnalyzer
{
private bool IsSeparatorMatch( Token leftSperator, Token rightSeparator )
{
return leftSperator.Value switch
{
ExpKeyword.LeftBrace => rightSeparator.Value == ExpKeyword.RightBrace,
ExpKeyword.LeftParen => rightSeparator.Value == ExpKeyword.RightParen,
ExpKeyword.Comma => rightSeparator.Value == ExpKeyword.Comma,
ExpKeyword.Semicolon => rightSeparator.Value == ExpKeyword.Semicolon,
_ => false
};
}
private bool TryAppendIndexLeft( Token t )
{
if( t.Flag != TokenFlag.Index_Left ) {
return false;
}
if( _cache.TryPeekOperand( out bool isNode, out _, out ExpSyntaxNode? node ) )
{
if( node.EqualityTypeConvert is not ExpCollectionBase ) {
ExpInvalidSyntaxException.ThrowNonCollectionIndex( t );
}
}
_cache.PushOperator( t );
_cache.IncreaseDepth( ( int )ExpCompileStateCode.CollectionIndex );
return true;
}
private bool TryAppendIndexRight( Token t )
{
if( t.Flag != TokenFlag.Index_Right ) {
return false;
}
//reverse building
ClosePrefixReverse( t );
//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 ) );
return true;
}
private bool TryAppendMember( Token t )
{
if( t.Flag != TokenFlag.Member ) {
return false;
}
if( TryParseConstant( t ) ) {
return true;
}
if( TryParseFunction( t ) ) {
return true;
}
if( TryParseInstance( t ) ) {
return true;
}
if( TryParseKeyword( t ) ) {
return true;
}
if( TryParseElementName( t ) ) {
return true;
}
//Many thing miss here
_cache.PushOperand( ExpElementMemberNameNode.Create( t ) );
return true;
}
private bool TryAppendMiddleSeparator( Token t )
{
if( t.Flag != TokenFlag.Separator_Middle ) {
return false;
}
while( _cache.OperatorAheadOfDepth > 0 )
{
_cache.TryPopOperator( out Token op );
ExpSyntaxNode node = ConvertAndPushOneOperator( op );
}
switch( _cache.OperandAheadOfDepth )
{
case 0:
if( t.Value == ";" ) {
return true;
}
_cache.StatementsInDepth.Push( ExpSyntaxNode.Empty );
goto case 1;
case 1:
_cache.PopOperand( out _, out ExpSyntaxNode? statement );
_cache.StatementsInDepth.Push( statement );
return true;
default:
ExpInvalidSyntaxException.ThrowNoOperator( t );
break;
}
return true;
}
private bool TryAppendNumAndStrLiteral( Token t )
{
if( ( t.Flag & ( TokenFlag.String | TokenFlag.Number ) ) == 0 ) {
return false;
}
_cache.PushOperand( ExpElementInstance.CreateLiteral( t ) );
return true;
}
private bool TryAppendPrefixSeparator( Token t )
{
if( t.Flag != TokenFlag.Separator_Left ) {
return false;
}
_cache.PushOperator( t );
_cache.IncreaseDepth( ( int )ExpCompileStateCode.Common );
return true;
}
private bool TryAppendPrefixSeparatorEnd( Token t )
{
if( t.Flag != TokenFlag.Separator_Right ) {
return false;
}
ClosePrefixReverse( t );
return true;
}
private bool TryAppendSymbol( Token t )
{
if( ( t.Flag & ( TokenFlag.Symbol_Unary | TokenFlag.Symbol_Binary ) ) == 0 ) {
return false;
}
int cmp = -1;
processPrecedence:
if( _cache.TryPeekOperator( out Token tmp ) )
{
cmp = CompareOperatorPrecedence( t, tmp );
if( cmp >= 0 )
{
_cache.PopOperator();
ExpSyntaxNode node = ConvertAndPushOneOperator( tmp );
goto processPrecedence;
}
}
_cache.PushOperator( t );
return true;
}
private bool TryParseConstant( Token t )
{
switch( t.Value )
{
case ExpKeyword.E:
_cache.PushOperand( new ExpRealNumberNode( t, MathF.E, true ) );
return true;
case ExpKeyword.Pi:
_cache.PushOperand( new ExpRealNumberNode( t, MathF.PI, true ) );
return true;
default:
if( ExpElementInstance.TryCreateLiteral( t, out ExpElementInstance? node ) )
{
_cache.PushOperand( node );
return true;
}
return false;
}
}
private bool TryParseElementName( Token t )
{
if( _context.TryGetType( t.Value, out ExpTypeSource? type ) )
{
_cache.PushOperand( ExpMetaRefNode.RefType( t, type ) );
return true;
}
if( _context.TryGetEntity( t.Value, out ExpEntitySource? entity ) )
{
_cache.PushOperand( ExpMetaRefNode.RefEntity( t, entity ) );
return true;
}
return false;
}
private bool TryParseFunction( Token t )
{
if( ExpKeyword.BuiltinFunctions.Contains( t.Value ) )
{
_cache.PushOperator( t );
return true;
} else if( _context.TryGetFunction( t.Value, out ExpFunctionSource? f ) )
{
_cache.PushOperand( t );
return true;
}
return false;
}
private bool TryParseInstance( Token t )
{
if( _local.TryGetMember( t.Value,
out ExpSyntaxNode? node ) &&
node is ExpElementInstance instance )
{
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
return true;
} else if( _tempVariableInLoops.TryGetValue( t.Value, out instance! ) )
{
_cache.PushOperand( ExpInstanceReferenceNode.MakeReferenceFrom( t, instance ) );
return true;
} else if( _cache.IsLastAddedOperator )
{
if( _cache.PeekOperand( out _,
out ExpSyntaxNode? typenode ) &&
typenode is ExpMetaRefNode typeRef )
{
_cache.PopOperand( out _, out _ );
_local.AddMember( t.Value, typeRef.SourceRef.CreateInstanceNode( t ) );
} else
{
return false;
}
}
return false;
}
private bool TryParseKeyword( Token t )
{
switch( t.Value )
{
case ExpKeyword.Return:
_cache.PushOperator( t );
return true;
case ExpKeyword.Skip:
_cache.PushOperand( ExpProcedureControlNode.Skip( t ) );
return true;
default:
return false;
}
}
}
}
@@ -0,0 +1,69 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.DepthEnter.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.Diagnostics;
using System;
using System.Collections.Generic;
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
{
internal void AttemptEnterNewDepth( Token t )
{
switch( t.Value )
{
case ExpKeyword.If:
_cache.IncreaseDepth( ( int )ExpCompileStateCode.IfBranch );
return;
case ExpKeyword.Case:
_cache.IncreaseDepth( ( int )ExpCompileStateCode.CaseBranch );
return;
case ExpKeyword.Repeat:
_cache.IncreaseDepth( ( int )ExpCompileStateCode.RepeatLoop );
return;
case ExpKeyword.While:
_cache.IncreaseDepth( ( int )ExpCompileStateCode.UntilLoop );
return;
default:
break;
}
}
}
}
@@ -0,0 +1,56 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.ErrorProcess.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public partial class ExpSyntaxAnalyzer
{
public void ThrowCompileException( int errorCode )
{
switch( errorCode )
{
case 0 or 1:
return;
case TokenTypeNotMatch:
throw new Exception();
default:
break;
}
}
}
}
@@ -0,0 +1,131 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.If.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.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Script.Express
{
public partial class ExpSyntaxAnalyzer
{
private bool AppendToken_IfBranch( Token t )
{
switch( t.Value )
{
case ExpKeyword.If:
IfBranchStateCache state = new IfBranchStateCache();
_cache.CurrentDepthMark.StateCache = state;
state.CurrentState = t.Value;
return true;
case ExpKeyword.Then:
state = _cache.StateOfCurrentDepth<IfBranchStateCache>();
if( state.CurrentState == ExpKeyword.If )
{
while( _cache.TryPopOperator( out Token op ) ) {
ConvertAndPushOneOperator( op );
}
_cache.PopOperand( out _, out ExpSyntaxNode? node );
state.CurrentState = t.Value;
state.BoolExpression = node;
} else
{
throw new ExpCompileException(
t, $"Keyword {t.Value} should be after keyword {ExpKeyword.Then}" );
}
return true;
case ExpKeyword.Else:
state = _cache.StateOfCurrentDepth<IfBranchStateCache>();
if( state.CurrentState == ExpKeyword.Then )
{
ExpSyntaxNode node = _cache.PackAllStatements();
state.CurrentState = t.Value;
state.ExpressionIfTrue = node;
} else
{
throw new ExpCompileException(
t, $"Keyword {t.Value} should be after keyword {ExpKeyword.Then}" );
}
return true;
case ExpKeyword.EndIf:
state = _cache.StateOfCurrentDepth<IfBranchStateCache>();
if( state.CurrentState == ExpKeyword.Then )
{
ExpSyntaxNode trueNode = _cache.PackAllStatements();
state.CurrentState = t.Value;
state.ExpressionIfTrue = trueNode;
state.ExpressionIfFalse = ExpSyntaxNode.Empty;
} else if( state.CurrentState == ExpKeyword.Else )
{
ExpSyntaxNode falseNode = _cache.PackAllStatements();
state.CurrentState = t.Value;
state.ExpressionIfFalse = falseNode;
} else
{
throw new ExpCompileException(
t,
$"Keyword {t.Value} should be after keyword {ExpKeyword.Then} or {ExpKeyword.Else}" );
}
ExpIfNode ifNode = new ExpIfNode(
state.Begin, state.BoolExpression, state.ExpressionIfTrue,
state.ExpressionIfFalse );
_cache.DecreaseDepth();
_cache.StatementsInDepth.Push( ifNode );
return true;
default:
AppendToken_Common( t );
return true;
}
}
private class IfBranchStateCache : ICompileDepthState
{
public ExpSyntaxNode BoolExpression { get; set; }
public ExpSyntaxNode ExpressionIfTrue { get; set; }
public ExpSyntaxNode ExpressionIfFalse { get; set; }
public string CurrentState { get; set; }
public Token Begin { get; set; }
}
}
}
@@ -0,0 +1,181 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.OperatorParser.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.Text;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Script.Express
{
public partial class ExpSyntaxAnalyzer
{
public int CompareOperatorPrecedence( Token left, Token right )
{
ExpressCompile.TryGetOperatorPrecedence( left.Value, out int leftPrecedence );
ExpressCompile.TryGetOperatorPrecedence( right.Value, out int rightPrecedence );
return leftPrecedence - rightPrecedence;
}
public bool TryGenerateUnaryNode( Token t, out ExpSyntaxNode node )
{
ExpSyntaxNode operand = GetNextOperandCache();
switch( t.Value )
{
case ExpKeyword.UnaryPlus:
node = ExpUnaryOperatorNode.UnaryPlus( t, operand );
return true;
case ExpKeyword.UnaryMinus:
node = ExpUnaryOperatorNode.UnaryMinus( t, operand );
return true;
case ExpKeyword.Not:
node = ExpUnaryOperatorNode.UnaryNot( t, operand );
return true;
default:
node = ExpSyntaxNode.Empty;
return false;
}
}
/// <summary>
/// WARNING: This method cannot process INDEXOF, FUNCTION CALLING, LOOP and any ENDING
/// SYMBOLS.
/// </summary>
private ExpSyntaxNode ConvertAndPushOneOperator( Token op )
{
switch( op.Flag )
{
case TokenFlag.Symbol_Unary:
TryGenerateUnaryNode( op, out ExpSyntaxNode? node );
_cache.PushOperand( node );
return node;
case TokenFlag.Symbol_Binary:
TryGenerateBinaryNode( op, out node );
_cache.PushOperand( node );
return node;
case TokenFlag.Member:
if( _context.TryGetFunction( op.Value, out ExpFunctionSource? f ) )
{
if( !_cache.PopOperand( out Token t, out ExpSyntaxNode? p ) )
{
node = ExpFunctionCallingNode.CallFunction( op, f, p );
return node;
} else
{
throw new ExpCompileException(
t,
"An ExpNode for function calling is needed, but a token was popped" );
}
} else if( _context.TryGetProcedure( op.Value, out ExpProcedureSource? p ) )
{
if( !_cache.PopOperand( out Token t, out ExpSyntaxNode? param ) )
{
node = ExpProcedureCallingNode.CallProcedure( op, p, param );
return node;
} else
{
throw new ExpCompileException(
t,
"An ExpNode for function calling is needed, but a token was popped" );
}
} else if( ExpSchema.BuiltinSchema.TryGetFunction( op.Value, out f ) )
{
if( !_cache.PopOperand( out Token t, out ExpSyntaxNode? param ) )
{
node = ExpFunctionCallingNode.CallFunction( op, f, param );
return node;
} else
{
throw new ExpCompileException(
t,
"An ExpNode for function calling is needed, but a token was popped" );
}
} else
{
throw new NotImplementedException();
//uncertain case here
}
default:
throw new NotImplementedException();
}
}
private bool TryGenerateBinaryNode( Token t, out ExpSyntaxNode node )
{
ExpSyntaxNode right = GetNextOperandCache();
ExpSyntaxNode left = GetNextOperandCache();
switch( t.Value )
{
case ExpKeyword.Add:
node = ExpBinaryOperatorNode.Add( t, left, right );
return true;
case ExpKeyword.Sub:
node = ExpBinaryOperatorNode.Sub( t, left, right );
return true;
case ExpKeyword.Mul:
node = ExpBinaryOperatorNode.Mul( t, left, right );
return true;
case ExpKeyword.Div:
node = ExpBinaryOperatorNode.Div( t, left, right );
return true;
case ExpKeyword.Equal:
node = ExpBinaryOperatorNode.EqualTo( t, left, right );
return true;
case ExpKeyword.NotEqual:
node = ExpBinaryOperatorNode.NotEqualTo( t, left, right );
return true;
case ExpKeyword.GreaterThan:
node = ExpBinaryOperatorNode.GreaterThan( t, left, right );
return true;
case ExpKeyword.LessThan:
node = ExpBinaryOperatorNode.LessThan( t, left, right );
return true;
case ExpKeyword.Assignment:
node = ExpBinaryOperatorNode.Assign( t, left, right );
return true;
case ExpKeyword.InstanceEqual:
node = ExpBinaryOperatorNode.CompareInstanceEqual( t, left, right );
return true;
case ExpKeyword.InstanceNotEqual:
node = ExpBinaryOperatorNode.CompareInstanceNotEqual( t, left, right );
return true;
default:
node = ExpSyntaxNode.Empty;
return false;
}
}
}
}
@@ -0,0 +1,123 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.RangeAndIndex.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.Operations;
using System;
using System.Collections.Generic;
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 void AppendToken_RangeAndIndex( Token t )
{
ExpSyntaxNode root;
switch( t.Value )
{
case "[":
RangeAndIndexState state = new RangeAndIndexState();
state.CurrentState = t.Value;
_cache.CurrentDepthMark.StateCache = state;
break;
case "]":
state = _cache.StateOfCurrentDepth<RangeAndIndexState>();
//Generate range or index object
if( _cache.StatementsInDepth.Count != 0 )
{
throw new ExpInvalidSyntaxException(
"Range and index syntax error: expected one statement to define range beginning." );
}
ReverseAnalyzeStatement();
root = _cache.StatementsInDepth.Pop();
if( ExpNodeFlag.BuiltinType_Int.IsNotInFlag( root.NodeFlag ) ) {
throw new ExpInvalidTypeException(
root, "integer", root.EqualityTypeConvert?.Name ?? string.Empty );
}
if( state.CurrentState == "[" ) { } else { }
break;
case ":":
state = _cache.StateOfCurrentDepth<RangeAndIndexState>();
if( state.CurrentState != "[" ) {
throw new ExpInvalidSyntaxException(
"Range and index syntax error: wrong position of :" );
}
if( _cache.StatementsInDepth.Count != 0 ) {
throw new ExpInvalidSyntaxException(
"Range and index syntax error: expected one statement to define range beginning." );
}
ReverseAnalyzeStatement();
root = _cache.StatementsInDepth.Pop();
if( ExpNodeFlag.BuiltinType_Int.IsNotInFlag( root.NodeFlag ) ) {
throw new ExpInvalidTypeException(
root, "integer", root.EqualityTypeConvert?.Name ?? string.Empty );
}
state.RangeStart = root;
break;
default:
state = _cache.StateOfCurrentDepth<RangeAndIndexState>();
if( t.Value == "?" )
{
switch( state.CurrentState )
{
case ":":
_cache.PushOperand( new ExpIntNode( t, int.MaxValue, true ) );
break;
case "[":
_cache.PushOperand( new ExpIntNode( t, int.MaxValue, true ) );
break;
default:
throw new ExpInvalidSyntaxException(
"Range and index syntax error: \"?\" can only be used in range or index" );
}
}
AppendToken_Common( t );
break;
}
}
private class RangeAndIndexState : ICompileDepthState
{
public ExpSyntaxNode RangeStart { get; set; }
public string CurrentState { get; set; } = string.Empty;
}
}
}
@@ -0,0 +1,289 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.RepeatLoop.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 System;
using System.Collections.Generic;
using System.ComponentModel.Design.Serialization;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Script.Express
{
public partial class ExpSyntaxAnalyzer
{
private Dictionary<string, ExpElementInstance> _tempVariableInLoops { get; }
= new Dictionary<string, ExpElementInstance>();
private bool AppendToken_RepeatLoop( Token t )
{
RepeatLoopState state = _cache.StateOfCurrentDepth<RepeatLoopState>();
if( state == null )
{
state = new RepeatLoopState( t );
_cache.CurrentDepthMark.StateCache = state;
state.CurrentState = t.Value;
return true;
}
switch( state.CurrentState )
{
case ExpKeyword.Repeat:
return TryParseRepeatVariable( state, t );
case ExpKeyword.To:
return TryParseRepeatEnding( state, t );
case ExpKeyword.By:
return TryParseRepeatVariable( state, t );
case ExpKeyword.Until:
return TryParseRepeatUntilRegulation( state, t );
case ExpKeyword.Assignment:
return TryParseRepeatBeginning( state, t );
case ExpKeyword.While:
return TryParseRepeatWhileRegulation( state, t );
case ExpKeyword.Semicolon:
if( t.Value != ExpKeyword.EndRepeat )
{
AppendToken_Common( t );
return true;
}
break;
default:
AppendToken_Common( t );
return false;
}
ExpSyntaxNode root = _cache.PackAllStatements();
state.Body = root;
_cache.DecreaseDepth();
if( ExpTypeSource.IsNullOrVoid( state.IncrementVariableType ) )
{
root = ExpRepeatNode.Create(
state.Position, state.IncrementVariable, state.Begin, state.End,
state.IncrementVariable, state.Body, state.UntilExpression,
state.WhileExpression );
} else
{
root = ExpRepeatNode.Create(
state.Position, state.IncrementVariable.OriginObject, state.Begin, state.End,
state.IncrementVariable, state.Body, state.UntilExpression,
state.WhileExpression );
}
_cache.StatementsInDepth.Push( root );
_tempVariableInLoops.Remove( state.IncrementVariable.CodeConvertTemplate );
return true;
}
private bool TryParseRepeatBeginning( RepeatLoopState state, Token t )
{
switch( t.Value )
{
case ExpKeyword.To:
state.CurrentState = ExpKeyword.To;
while( _cache.TryPopOperator( out Token op ) ) {
ConvertAndPushOneOperator( op );
}
_cache.PopOperand( out _, out ExpSyntaxNode? root );
state.Begin = root;
return true;
default:
AppendToken_Common( t );
return true;
}
}
private bool TryParseRepeatEnding( RepeatLoopState state, Token t )
{
switch( t.Value )
{
case ExpKeyword.By:
state.CurrentState = ExpKeyword.By;
break;
case ExpKeyword.Until:
state.CurrentState = ExpKeyword.Until;
break;
case ExpKeyword.While:
state.CurrentState = ExpKeyword.While;
break;
default:
AppendToken_Common( t );
return true;
}
while( _cache.TryPopOperator( out Token op ) ) {
ConvertAndPushOneOperator( op );
}
_cache.PopOperand( out _, out ExpSyntaxNode? root );
state.End = root;
return true;
}
private bool TryParseRepeatIncrement( RepeatLoopState state, Token t )
{
switch( t.Value )
{
case ExpKeyword.Semicolon:
state.CurrentState = ExpKeyword.Semicolon;
break;
case ExpKeyword.Until:
state.CurrentState = ExpKeyword.Until;
break;
case ExpKeyword.While:
state.CurrentState = ExpKeyword.While;
break;
default:
AppendToken_Common( t );
return true;
}
while( _cache.TryPopOperator( out Token op ) ) {
ConvertAndPushOneOperator( op );
}
_cache.PopOperand( out _, out ExpSyntaxNode? root );
state.StepIncrement = root;
return true;
}
private bool TryParseRepeatUntilRegulation( RepeatLoopState state, Token t )
{
switch( t.Value )
{
case ExpKeyword.Semicolon:
state.CurrentState = ExpKeyword.Semicolon;
break;
default:
AppendToken_Common( t );
return true;
}
while( _cache.TryPopOperator( out Token op ) ) {
ConvertAndPushOneOperator( op );
}
_cache.PopOperand( out _, out ExpSyntaxNode? root );
state.UntilExpression = root;
return true;
}
private bool TryParseRepeatVariable( RepeatLoopState state, Token t )
{
switch( t.Value )
{
case ExpKeyword.Integer:
state.IncrementVariableType = ExpressCompile.ExpInt;
return true;
case
ExpKeyword.Real:
state.IncrementVariableType = ExpressCompile.ExpReal;
return true;
case ExpKeyword.Assignment:
state.CurrentState = ExpKeyword.Assignment;
return true;
default:
if( ExpTypeSource.IsNullOrVoid( state.IncrementVariableType ) )
{
if( ( _local.TryGetMember( t.Value,
out ExpSyntaxNode? node ) &&
node is ExpElementInstance instance ) ||
_tempVariableInLoops.TryGetValue( t.Value, out instance ) )
{
state.IncrementVariable = ExpInstanceReferenceNode.MakeReferenceFrom(
t, instance );
return true;
} else
{
throw new ExpInvalidSyntaxException(
$"Variable {t.Value} is not declared or initialized." );
}
} else
{
ExpElementInstance variable = state.IncrementVariableType
.CreateInstanceNode( t );
_tempVariableInLoops.Add( t.Value, variable );
state.IncrementVariable = ExpInstanceReferenceNode.MakeReferenceFrom(
t, variable );
return true;
}
}
}
private bool TryParseRepeatWhileRegulation( RepeatLoopState state, Token t )
{
switch( t.Value )
{
case ExpKeyword.Until:
state.CurrentState = ExpKeyword.Until;
break;
default:
AppendToken_Common( t );
return true;
}
while( _cache.TryPopOperator( out Token op ) ) {
ConvertAndPushOneOperator( op );
}
_cache.PopOperand( out _, out ExpSyntaxNode? root );
state.WhileExpression = root;
return true;
}
private class RepeatLoopState : ICompileDepthState
{
public RepeatLoopState( Token t )
{
Position = t;
UntilExpression = ExpSyntaxNode.Empty;
WhileExpression = ExpSyntaxNode.Empty;
}
public ExpInstanceReferenceNode IncrementVariable { get; set; }
public ExpSyntaxNode StepIncrement { get; set; }
public ExpSyntaxNode Begin { get; set; }
public ExpSyntaxNode End { get; set; }
public ExpSyntaxNode UntilExpression { get; set; }
public ExpSyntaxNode WhileExpression { get; set; }
public ExpSyntaxNode Body { get; set; }
public ExpTypeSource IncrementVariableType { get; set; }
public string CurrentState { get; set; }
public Token Position { get; set; }
}
}
}
@@ -0,0 +1,94 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.ReverseAnalysing.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.ComponentModel.DataAnnotations;
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 void ClosePrefixReverse( Token rightSeparator )
{
ExpSyntaxNode root;
ReverseAnalyzeStatement();
root = _cache.PackAllStatements();
if( rightSeparator.Value == ")" ) {
root = ExpTupleNode.Pack( root );
}
_cache.DecreaseDepth();
if( IsSeparatorMatch( _cache.PeekOperator(), rightSeparator ) )
{
_cache.PopOperator();
_cache.PushOperand( root );
} else
{
throw new ExpCompileException(
rightSeparator, "Ending of block does not match its begging" );
}
}
private void ReverseAnalyzeStatement()
{
ExpSyntaxNode root;
if( _cache.OperatorAheadOfDepth == 0 )
{
switch( _cache.OperandAheadOfDepth )
{
case 1:
_cache.PopOperand( out _, out ExpSyntaxNode? statement );
_cache.StatementsInDepth.Push( statement );
break;
case 0:
_cache.StatementsInDepth.Push( ExpSyntaxNode.Empty );
break;
default:
throw new ExpInvalidSyntaxException(
"More than one operand but no operator provided." );
}
} else
{
while( _cache.TryPopOperator( out Token op ) ) {
ConvertAndPushOneOperator( op );
}
_cache.PopOperand( out _, out root );
_cache.StatementsInDepth.Push( root );
}
}
}
}
@@ -0,0 +1,183 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSyntaxAnalyzer.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.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Pipes;
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 : ISyntaxAnalyzer
{
private const int EndLine = 1;
private const int TokenGenerated = 0;
private const int TokenTypeNotMatch = -1;
private CompileStack<ExpSyntaxNode, IExpElementSource> _cache;
private ExpSchema _context;
private ExpSyntaxNode _lastStatement;
private IExpElementSource _local;
public ExpSyntaxAnalyzer()
{
_cache = new CompileStack<ExpSyntaxNode, IExpElementSource>();
}
public ExpSyntaxAnalyzer( ExpSchema context, IExpElementSource local )
{
_cache = new CompileStack<ExpSyntaxNode, IExpElementSource>();
ArgumentNullException.ThrowIfNull( context );
if( context is not ExpSchema_Builtin )
{
_context = context;
} else
{
throw new InvalidCastException( "Not a valid Schema type" );
}
_local = local;
}
/**/
public void AppendToken( Token expToken )
{
switch( ( ExpCompileStateCode )TryEnterBranch( expToken ).Usage )
{
case ExpCompileStateCode.IfBranch:
AppendToken_IfBranch( expToken );
break;
case ExpCompileStateCode.CaseBranch:
AppendToken_CaseOf( expToken );
break;
case ExpCompileStateCode.RepeatLoop:
AppendToken_RepeatLoop( expToken );
break;
default:
AppendToken_Common( expToken );
break;
}
}
public ExpSyntaxNode GetNextOperandCache()
{
if( _cache.PopOperand( out Token t, out ExpSyntaxNode? n ) )
{
return n;
} else
{
// process some rare case here
}
throw new NotImplementedException();
}
/// <summary>
/// Append a token to top of cache. This method will automatically convert token to node
/// if meets separators or operators.
/// </summary>
private void AppendToken_Common( Token expToken )
{
switch( expToken.Flag )
{
case TokenFlag.Symbol_Unary or TokenFlag.Symbol_Binary:
TryAppendSymbol( expToken );
break;
case TokenFlag.Number or TokenFlag.String:
ExpElementInstance node = ExpElementInstance.CreateLiteral( expToken );
_cache.PushOperand( node );
break;
case TokenFlag.Separator_Left:
TryAppendPrefixSeparator( expToken );
break;
case TokenFlag.Separator_Right:
TryAppendPrefixSeparatorEnd( expToken );
break;
case TokenFlag.Separator_Middle:
TryAppendMiddleSeparator( expToken );
break;
case TokenFlag.Index_Left:
TryAppendIndexLeft( expToken );
break;
case TokenFlag.Index_Right:
TryAppendIndexRight( expToken );
break;
case TokenFlag.Member:
TryAppendMember( expToken );
break;
default:
break;
}
}
private CompileDepthMark TryEnterBranch( Token t )
{
if( t.Flag == TokenFlag.String ) {
return _cache.CurrentDepthMark;
}
switch( t.Value )
{
case ExpKeyword.Case:
return _cache.IncreaseDepth( ( int )ExpCompileStateCode.CaseBranch );
case ExpKeyword.If:
return _cache.IncreaseDepth( ( int )ExpCompileStateCode.IfBranch );
case ExpKeyword.Repeat:
return _cache.IncreaseDepth( ( int )ExpCompileStateCode.RepeatLoop );
default:
return _cache.CurrentDepthMark;
}
}
/**/
public enum ExpCompileStateCode
{
Common,
ForLoop,
RepeatLoop,
UntilLoop,
IfBranch,
CaseBranch,
CollectionIndex,
}
}
}
+423
View File
@@ -0,0 +1,423 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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
_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<char> ReadLine()
{
bool lineOver = string.IsNullOrEmpty( _lineCache ) || _current >= _lineCache.Length;
while( lineOver || _isReadingMultiLineComment )
{
if( IsEmpty ) {
return ReadOnlySpan<char>.Empty;
}
if( lineOver )
{
do
{
_lineCache = _provider.ReadLine( out _lineNum );
} while (string.IsNullOrEmpty( _lineCache ) && !_provider.IsEmpty);
_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<char> 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 '\'':
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 '(':
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<char> line )
{
line = ReadLine();
return line != ReadOnlySpan<char>.Empty;
}
public bool TryReadToken( out Token t )
{
t = ReadToken();
return !IsEmpty;
}
[GeneratedRegex(
@"(?<token>[a-zA-Z][a-zA-Z0-9_]*)(?<end>\s*?)(?<rest>\S|$)",
RegexOptions.Singleline )]
private static partial Regex GetNextWordTokenPattern();
[GeneratedRegex(
@"(?<token>-?\s*?[0-9]+(?:\.[0-9]*)?E?(?:[+-]?[0-9]+)?)(?<end>\s*?)(?<rest>\S|$)",
RegexOptions.Singleline )]
private static partial Regex GetNumberLiteralPattern();
[GeneratedRegex( @"(?:\s+?)(?<rest>\S|$)", RegexOptions.Singleline )]
private static partial Regex GetSkipBlankPattern();
[GeneratedRegex(
@"(?<token>"")(?>\\\\|\\""|(?!')[^""])*(?<end>""|$)\s*?(?<rest>\S|$)",
RegexOptions.Singleline )]
private static partial Regex GetStringLiteralPattern();
[GeneratedRegex(
@"(?<token>')(?>\\\\|\\'|''|(?!')[^'])*(?<end>')\s*?(?<rest>\S|$)",
RegexOptions.Singleline )]
private static partial Regex GetStringLiteralPatternWithSingle();
[GeneratedRegex(
@"(?<token>[:<>=+\-*\/\.]+)(?<end>\s?)\s*?(?<rest>\S|$)",
RegexOptions.Singleline )]
private static partial Regex GetSymbolPattern();
}
}
@@ -0,0 +1,115 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GeneratedExpSchema.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.Helpers;
using StgSharp.Collections;
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
internal class GeneratedExpSchema : ExpSchema
{
public GeneratedExpSchema() { }
public static ExpSchema DefaultSchema
{
get => ExpSchema_Builtin.Only;
}
public ExpTypeSource GetExpType( string typeName )
{
if( BuiltinSchema.TryGetType( typeName, out ExpTypeSource? ret ) ) {
return ret;
}
if( TypeDict.TryGetValue( typeName, out ret ) ) {
return ret;
}
foreach( GeneratedExpSchema item in SchemaInclude.Values )
{
if( item.TypeDict.TryGetValue( typeName, out ret ) ) {
return ret;
}
}
throw new ExpElementLoadException( typeName, this );
}
public bool HasSchemaInclude( GeneratedExpSchema schema )
{
return SchemaInclude.ContainsKey( schema.Name );
}
public override void LoadFromSource( ExpSchemaSource source )
{
throw new NotImplementedException();
}
public override bool TryGetConst( string name, out ExpElementInstance c )
{
return ConstDict.TryGetValue( name, out c! );
}
public override bool TryGetEntity( string name, out ExpEntitySource e )
{
return EntityDict.TryGetValue( name, out e! );
}
public override bool TryGetFunction( string name, out ExpFunctionSource f )
{
return FunctionDict.TryGetValue( name, out f! );
}
public override bool TryGetProcedure( string name, out ExpProcedureSource p )
{
throw new NotImplementedException();
}
public override bool TryGetRule( string name, out ExpRuleSource r )
{
throw new NotImplementedException();
}
public override bool TryGetSchemaInclude( string name, out ExpSchema include )
{
throw new NotImplementedException();
}
public override bool TryGetType( string name, out ExpTypeSource element )
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,303 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IExpConvertableFrom.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.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
// Base interface with one generic parameter renamed to T0
public interface IExpConvertableFrom<T0> where T0: IExpConvertableFrom<T0>
{
void FromInstance( T0 entity );
bool IsConvertableTo( string entityTypeName );
}
// 2 generic parameters
public interface IExpConvertableFrom<T0, T1> : IExpConvertableFrom<T0>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
{
void FromInstance( T1 entity );
}
// 3 generic parameters
public interface IExpConvertableFrom<T0, T1, T2> : IExpConvertableFrom<T0, T1>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
{
void FromInstance( T2 entity );
}
// 4 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3> : IExpConvertableFrom<T0, T1, T2>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
{
void FromInstance( T3 entity );
}
// 5 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4> : IExpConvertableFrom<T0, T1, T2, T3>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
{
void FromInstance( T4 entity );
}
// 6 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5> : IExpConvertableFrom<T0, T1, T2, T3, T4>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
{
void FromInstance( T5 entity );
}
// 7 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
where T6: IExpConvertableFrom<T6>
{
void FromInstance( T6 entity );
}
// 8 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
where T6: IExpConvertableFrom<T6>
where T7: IExpConvertableFrom<T7>
{
void FromInstance( T7 entity );
}
// 9 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
where T6: IExpConvertableFrom<T6>
where T7: IExpConvertableFrom<T7>
where T8: IExpConvertableFrom<T8>
{
void FromInstance( T8 entity );
}
// 10 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
where T6: IExpConvertableFrom<T6>
where T7: IExpConvertableFrom<T7>
where T8: IExpConvertableFrom<T8>
where T9: IExpConvertableFrom<T9>
{
void FromInstance( T9 entity );
}
// 11 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
where T6: IExpConvertableFrom<T6>
where T7: IExpConvertableFrom<T7>
where T8: IExpConvertableFrom<T8>
where T9: IExpConvertableFrom<T9>
where T10: IExpConvertableFrom<T10>
{
void FromInstance( T10 entity );
}
// 12 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
where T6: IExpConvertableFrom<T6>
where T7: IExpConvertableFrom<T7>
where T8: IExpConvertableFrom<T8>
where T9: IExpConvertableFrom<T9>
where T10: IExpConvertableFrom<T10>
where T11: IExpConvertableFrom<T11>
{
void FromInstance( T11 entity );
}
// 13 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
where T6: IExpConvertableFrom<T6>
where T7: IExpConvertableFrom<T7>
where T8: IExpConvertableFrom<T8>
where T9: IExpConvertableFrom<T9>
where T10: IExpConvertableFrom<T10>
where T11: IExpConvertableFrom<T11>
where T12: IExpConvertableFrom<T12>
{
void FromInstance( T12 entity );
}
// 14 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
where T6: IExpConvertableFrom<T6>
where T7: IExpConvertableFrom<T7>
where T8: IExpConvertableFrom<T8>
where T9: IExpConvertableFrom<T9>
where T10: IExpConvertableFrom<T10>
where T11: IExpConvertableFrom<T11>
where T12: IExpConvertableFrom<T12>
where T13: IExpConvertableFrom<T13>
{
void FromInstance( T13 entity );
}
// 15 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
where T6: IExpConvertableFrom<T6>
where T7: IExpConvertableFrom<T7>
where T8: IExpConvertableFrom<T8>
where T9: IExpConvertableFrom<T9>
where T10: IExpConvertableFrom<T10>
where T11: IExpConvertableFrom<T11>
where T12: IExpConvertableFrom<T12>
where T13: IExpConvertableFrom<T13>
where T14: IExpConvertableFrom<T14>
{
void FromInstance( T14 entity );
}
// 16 generic parameters
public interface IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> : IExpConvertableFrom<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>
where T0: IExpConvertableFrom<T0>
where T1: IExpConvertableFrom<T1>
where T2: IExpConvertableFrom<T2>
where T3: IExpConvertableFrom<T3>
where T4: IExpConvertableFrom<T4>
where T5: IExpConvertableFrom<T5>
where T6: IExpConvertableFrom<T6>
where T7: IExpConvertableFrom<T7>
where T8: IExpConvertableFrom<T8>
where T9: IExpConvertableFrom<T9>
where T10: IExpConvertableFrom<T10>
where T11: IExpConvertableFrom<T11>
where T12: IExpConvertableFrom<T12>
where T13: IExpConvertableFrom<T13>
where T14: IExpConvertableFrom<T14>
where T15: IExpConvertableFrom<T15>
{
void FromInstance( T15 entity );
}
}
+20
View File
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StgSharp.Common\StgSharp.Common.csproj" />
</ItemGroup>
</Project>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,227 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v8.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v8.0": {
"StgSharp.Script/1.0.0": {
"dependencies": {
"CommunityToolkit.HighPerformance": "8.4.0",
"Microsoft.CodeAnalysis.CSharp": "4.13.0",
"StgSharp.Common": "1.0.0"
},
"runtime": {
"StgSharp.Script.dll": {}
}
},
"CommunityToolkit.HighPerformance/8.4.0": {
"runtime": {
"lib/net8.0/CommunityToolkit.HighPerformance.dll": {
"assemblyVersion": "8.4.0.0",
"fileVersion": "8.4.0.1"
}
}
},
"Microsoft.CodeAnalysis.Analyzers/3.11.0": {},
"Microsoft.CodeAnalysis.Common/4.13.0": {
"dependencies": {
"Microsoft.CodeAnalysis.Analyzers": "3.11.0",
"System.Collections.Immutable": "8.0.0",
"System.Reflection.Metadata": "8.0.0"
},
"runtime": {
"lib/net8.0/Microsoft.CodeAnalysis.dll": {
"assemblyVersion": "4.13.0.0",
"fileVersion": "4.1300.25.12011"
}
},
"resources": {
"lib/net8.0/cs/Microsoft.CodeAnalysis.resources.dll": {
"locale": "cs"
},
"lib/net8.0/de/Microsoft.CodeAnalysis.resources.dll": {
"locale": "de"
},
"lib/net8.0/es/Microsoft.CodeAnalysis.resources.dll": {
"locale": "es"
},
"lib/net8.0/fr/Microsoft.CodeAnalysis.resources.dll": {
"locale": "fr"
},
"lib/net8.0/it/Microsoft.CodeAnalysis.resources.dll": {
"locale": "it"
},
"lib/net8.0/ja/Microsoft.CodeAnalysis.resources.dll": {
"locale": "ja"
},
"lib/net8.0/ko/Microsoft.CodeAnalysis.resources.dll": {
"locale": "ko"
},
"lib/net8.0/pl/Microsoft.CodeAnalysis.resources.dll": {
"locale": "pl"
},
"lib/net8.0/pt-BR/Microsoft.CodeAnalysis.resources.dll": {
"locale": "pt-BR"
},
"lib/net8.0/ru/Microsoft.CodeAnalysis.resources.dll": {
"locale": "ru"
},
"lib/net8.0/tr/Microsoft.CodeAnalysis.resources.dll": {
"locale": "tr"
},
"lib/net8.0/zh-Hans/Microsoft.CodeAnalysis.resources.dll": {
"locale": "zh-Hans"
},
"lib/net8.0/zh-Hant/Microsoft.CodeAnalysis.resources.dll": {
"locale": "zh-Hant"
}
}
},
"Microsoft.CodeAnalysis.CSharp/4.13.0": {
"dependencies": {
"Microsoft.CodeAnalysis.Analyzers": "3.11.0",
"Microsoft.CodeAnalysis.Common": "4.13.0",
"System.Collections.Immutable": "8.0.0",
"System.Reflection.Metadata": "8.0.0"
},
"runtime": {
"lib/net8.0/Microsoft.CodeAnalysis.CSharp.dll": {
"assemblyVersion": "4.13.0.0",
"fileVersion": "4.1300.25.12011"
}
},
"resources": {
"lib/net8.0/cs/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "cs"
},
"lib/net8.0/de/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "de"
},
"lib/net8.0/es/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "es"
},
"lib/net8.0/fr/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "fr"
},
"lib/net8.0/it/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "it"
},
"lib/net8.0/ja/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "ja"
},
"lib/net8.0/ko/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "ko"
},
"lib/net8.0/pl/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "pl"
},
"lib/net8.0/pt-BR/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "pt-BR"
},
"lib/net8.0/ru/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "ru"
},
"lib/net8.0/tr/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "tr"
},
"lib/net8.0/zh-Hans/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "zh-Hans"
},
"lib/net8.0/zh-Hant/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "zh-Hant"
}
}
},
"Microsoft.CSharp/4.7.0": {},
"System.Collections.Immutable/8.0.0": {},
"System.Reflection.Metadata/8.0.0": {
"dependencies": {
"System.Collections.Immutable": "8.0.0"
}
},
"System.Runtime.CompilerServices.Unsafe/6.1.0": {},
"StgSharp.Common/1.0.0": {
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Runtime.CompilerServices.Unsafe": "6.1.0"
},
"runtime": {
"StgSharp.Common.dll": {
"assemblyVersion": "1.0.0.0",
"fileVersion": "1.0.0.0"
}
}
}
}
},
"libraries": {
"StgSharp.Script/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"CommunityToolkit.HighPerformance/8.4.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-flxspiBs0G/0GMp7IK2J2ijV9bTG6hEwFc/z6ekHqB6nwRJ4Ry2yLdx+TkbCUYFCl4XhABkAwomeKbT6zM2Zlg==",
"path": "communitytoolkit.highperformance/8.4.0",
"hashPath": "communitytoolkit.highperformance.8.4.0.nupkg.sha512"
},
"Microsoft.CodeAnalysis.Analyzers/3.11.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-v/EW3UE8/lbEYHoC2Qq7AR/DnmvpgdtAMndfQNmpuIMx/Mto8L5JnuCfdBYtgvalQOtfNCnxFejxuRrryvUTsg==",
"path": "microsoft.codeanalysis.analyzers/3.11.0",
"hashPath": "microsoft.codeanalysis.analyzers.3.11.0.nupkg.sha512"
},
"Microsoft.CodeAnalysis.Common/4.13.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-T8nRl4mAUY4mhdYM4U2ra2vP2EL+ol8Yqwo0gwC/V55vmlXq9NxdIkZJynTpTL1uX/jHijJ90AeOEx4lf7OwzQ==",
"path": "microsoft.codeanalysis.common/4.13.0",
"hashPath": "microsoft.codeanalysis.common.4.13.0.nupkg.sha512"
},
"Microsoft.CodeAnalysis.CSharp/4.13.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-BsH7Vijbj9IL7Fj4k/ysZSVyLGFqr75wmdFGwCKWJvSjnA1xwPaQ3hkB2BQdHOt5CpEYA6Q0I6Oo5sDTDHqHsg==",
"path": "microsoft.codeanalysis.csharp/4.13.0",
"hashPath": "microsoft.codeanalysis.csharp.4.13.0.nupkg.sha512"
},
"Microsoft.CSharp/4.7.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-pTj+D3uJWyN3My70i2Hqo+OXixq3Os2D1nJ2x92FFo6sk8fYS1m1WLNTs0Dc1uPaViH0YvEEwvzddQ7y4rhXmA==",
"path": "microsoft.csharp/4.7.0",
"hashPath": "microsoft.csharp.4.7.0.nupkg.sha512"
},
"System.Collections.Immutable/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-AurL6Y5BA1WotzlEvVaIDpqzpIPvYnnldxru8oXJU2yFxFUy3+pNXjXd1ymO+RA0rq0+590Q8gaz2l3Sr7fmqg==",
"path": "system.collections.immutable/8.0.0",
"hashPath": "system.collections.immutable.8.0.0.nupkg.sha512"
},
"System.Reflection.Metadata/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ptvgrFh7PvWI8bcVqG5rsA/weWM09EnthFHR5SCnS6IN+P4mj6rE1lBDC4U8HL9/57htKAqy4KQ3bBj84cfYyQ==",
"path": "system.reflection.metadata/8.0.0",
"hashPath": "system.reflection.metadata.8.0.0.nupkg.sha512"
},
"System.Runtime.CompilerServices.Unsafe/6.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-5o/HZxx6RVqYlhKSq8/zronDkALJZUT2Vz0hx43f0gwe8mwlM0y2nYlqdBwLMzr262Bwvpikeb/yEwkAa5PADg==",
"path": "system.runtime.compilerservices.unsafe/6.1.0",
"hashPath": "system.runtime.compilerservices.unsafe.6.1.0.nupkg.sha512"
},
"StgSharp.Common/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
@@ -0,0 +1,857 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>StgSharp.Common</name>
</assembly>
<members>
<member name="M:StgSharp.Commom.Collections.IBidirectionalDictionary`2.Contains(`1)">
<summary>
Determines whether the <see cref="T:StgSharp.Commom.Collections.IBidirectionalDictionary`2" />
contains the specified key.
</summary>
<param _label="key">
The value to locate in the <see cref="T:StgSharp.Commom.Collections.IBidirectionalDictionary`2" />.
</param>
<returns>
true if the <see cref="T:StgSharp.Commom.Collections.IBidirectionalDictionary`2" /> contains an
element with the specified key; otherwise, false.
</returns>
</member>
<member name="M:StgSharp.Commom.Collections.IBidirectionalDictionary`2.Contains(`0)">
<summary>
Determines whether the <see cref="T:StgSharp.Commom.Collections.IBidirectionalDictionary`2" />
contains the specified key.
</summary>
<param _label="key">
The value to locate in the <see cref="T:StgSharp.Commom.Collections.IBidirectionalDictionary`2" />.
</param>
<returns>
true if the <see cref="T:StgSharp.Commom.Collections.IBidirectionalDictionary`2" /> contains an
element with the specified key; otherwise, false.
</returns>
</member>
<member name="T:StgSharp.Collections.ListSegment`1">
<summary>
Part of a collection. This contains a direct reference to _origin collection, so all
change to _origin collection will be reflected in this object.
</summary>
<typeparam name="T">
</typeparam>
</member>
<member name="M:StgSharp.World.InitGL(System.Int32,System.Int32)">
<summary>
CustomizeInit an instance of OpenGL program, This method should be called before any
other World api.
</summary>
</member>
<member name="F:StgSharp.World.version">
<summary>
Version of current World platform. Main version represent in hundred's digit, and sub
version represent in ten's digit.
</summary>
</member>
<member name="M:StgSharp.World.WriteLog(System.String,StgSharp.LogType)">
<summary>
Write a log message to log file, and mark the _level of this message.
</summary>
<param _label="message">
A string contains information of how current evironment runs.
</param>
<param _label="logType">
The severity of current message.
</param>
</member>
<member name="T:StgSharp.Data.ValueBox`1">
<summary>
A class attempt to reduce cost of boxing, though still a bit slower than direct access to
_origin value type instance.
</summary>
<typeparam name="T">
Type of instance to be boxed.
</typeparam>
</member>
<member name="T:StgSharp.Internal.Serializer">
<summary>
A class contains a sets of methods to serialize several types
</summary>
</member>
<member name="T:StgSharp.Internal.Area">
<summary>
An independent storage area, used as the only folder type in root folder. Contains several
<see cref="T:StgSharp.Internal.SSD" /> files reference as virtual disc. Data is actually stored in <see
cref="T:StgSharp.Internal.SSD" />s in certain RAID mode.
</summary>
</member>
<member name="T:StgSharp.Internal.GLclampf">
<summary>
OpenGL numeric type. An IEEE-754 floating-point value, clamped to the range [0,1].
</summary>
</member>
<member name="T:StgSharp.Internal.GLclampd">
<summary>
OpenGL numeric type. An IEEE-754 double precision floating-point value, clamped to the
range [0,1].
</summary>
</member>
<member name="P:StgSharp.IEntity.X">
<summary>
X position of an enenmy entity
</summary>
</member>
<member name="P:StgSharp.IEntity.Y">
<summary>
Y position of an enemy entity
</summary>
</member>
<member name="P:StgSharp.IEntity.CollisionSensor">
<summary>
A sensor used for checking out if a bullet hit a player or something else
</summary>
</member>
<member name="P:StgSharp.IEntity.Location">
<summary>
A 2D vector presenting the position of an enemy entity, position can also be visited
by X, Y
</summary>
</member>
<member name="T:StgSharp.Geometries.UnusedVertexException">
<summary>
当几何体调用了过多的CalcVec方法时,产生UnusedVertexException异常
</summary>
</member>
<member name="F:StgSharp.Geometries.PartialPlainCoordinate.origin">
<summary>
The _origin of this coordinate.
</summary>
</member>
<member name="P:StgSharp.Geometries.PartialPlainCoordinate.axis_H">
<summary>
The horizontial axis of the coordinate. Point to the right direction.
</summary>
</member>
<member name="P:StgSharp.Geometries.PartialPlainCoordinate.axis_V">
<summary>
The vertical axis of the coordinate. Point to the top direction.
</summary>
</member>
<member name="T:StgSharp.Geometries.PlainGeometry">
<summary>
Plain geometry only contains straight sides.
</summary>
</member>
<member name="M:StgSharp.Geometries.Rectangle.MovCenter(System.UInt32)">
<summary>
Calculate movement to center
</summary>
<param _label="tick">
CurrentPipeline time tick
</param>
<returns>
</returns>
</member>
<member name="T:StgSharp.Geometries.Square">
<summary>
A square
</summary>
</member>
<member name="T:StgSharp.Math.Vec2">
<summary>
A two dimension vector defined by two elements. Vec2 in World are default used as colum
vector.
</summary>
</member>
<member name="M:StgSharp.Math.Linear.Orthogonalize(StgSharp.Math.Vec3@,StgSharp.Math.Vec3@)">
<summary>
Orthogonalize two <see cref="T:StgSharp.Math.Vec3" />s, let their length be 1 and perpendicular to
each other.
</summary>
<param _label="source">
</param>
<param _label="target">
</param>
</member>
<member name="M:StgSharp.Math.Scaler.ASin(System.Single)">
<summary>
Reurns the value of ArcSin(x)
</summary>
<param _label="x">
The sine value of the angle
</param>
<returns>
</returns>
<exception cref="T:System.ArgumentException">
</exception>
</member>
<member name="M:StgSharp.Math.Scaler.Exp(System.Single)">
<summary>
Get the value of E ^ x;
</summary>
<param _label="x">
</param>
<returns>
</returns>
</member>
<member name="M:StgSharp.Math.Scaler.Log(System.Single)">
<summary>
</summary>
<param _label="x">
</param>
<returns>
Returns the value of ln(x).
</returns>
</member>
<member name="M:StgSharp.Math.Scaler.Pow(System.Single,System.Single)">
<summary>
calculate the value of x^y
</summary>
<param _label="x">
</param>
<param _label="y">
</param>
<returns>
Returns the value of x^y
</returns>
</member>
<member name="M:StgSharp.Math.Scaler.LowProceisionRandom">
<summary>
returns a random float number between 0 and 1.
</summary>
<returns>
</returns>
</member>
<member name="M:StgSharp.Math.Scaler.Random``1">
<summary>
</summary>
<returns>
</returns>
</member>
<member name="M:StgSharp.Math.Scaler.RandomSeed">
<summary>
Generates a random seed in int value.
</summary>
<returns>
</returns>
</member>
<member name="T:StgSharp.Graphics.BufferObjectBase">
<summary>
Interface of all kinds OpenGL Buffer objects
</summary>
</member>
<member name="P:StgSharp.Graphics.BufferObjectBase.Item(System.Int32)">
<summary>
Get the only handle to one of the Object instance
</summary>
<param _label="index">
</param>
<returns>
</returns>
</member>
<member name="M:StgSharp.Graphics.BufferObjectBase.Bind(System.Int32)">
<summary>
Bind a Buffer instance to OpenGL
</summary>
<param _label="index">
Index of handle of the object in this instance to be bind
</param>
</member>
<member name="M:StgSharp.Graphics.BufferObjectBase.ToString">
<inheritdoc />
</member>
<member name="T:StgSharp.Graphics.glLoader">
<summary>
Function handler to load an opengl function by searching its _label.
</summary>
<param _label="name">
the _label of the Opengl function
</param>
<returns>
An Intptr value representing the pointer to the function
</returns>
</member>
<member name="P:StgSharp.Graphics.Image.PixelUpdateCount">
<summary>
Hash code of time pixels updated last time.
</summary>
</member>
<member name="T:StgSharp.Graphics.OpenGL.AutoTextureGL">
<summary>
A collection of a sets of OpenGL textures. The collection can automatically select one of
the texture with minimum costs to upgrade pixels to Buffer. Usually <see
cref="T:StgSharp.Graphics.OpenGL.AutoTextureGL" /> is used for <see cref="T:StgSharp.Graphics.IImageProvider" /> loading, but not for
target of <see cref="M:StgSharp.Graphics.OpenGL.OpenGLFunction.FrameBufferTexture2d(StgSharp.Graphics.OpenGL.FrameBufferTarget,System.UInt32,StgSharp.Graphics.OpenGL.Texture2DTarget,StgSharp.Graphics.OpenGL.GlHandle,System.Int32)" />.
</summary>
</member>
<member name="T:StgSharp.Graphics.OpenGL.ElementBuffer">
<summary>
A collection of handle to Element Buffer Object in OpenglFunc. Each <see langword="uint"
/> value indexed from instance of this class this is the only handle to one Element Buffer
Object.
</summary>
</member>
<member name="M:StgSharp.Graphics.OpenGL.FrameBuffer.Bind(System.Int32)">
<summary>
Bind the frame Buffer object with _label frame Buffer to the frame Buffer target
specified by target. <see langword="FrameBufferTarget.All" /> will be set as default
target.
</summary>
<param _label="index">
Index of object to be binded in handle set
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.FrameBuffer.Bind(StgSharp.Graphics.OpenGL.FrameBufferTarget,System.Int32)">
<summary>
Bind the frame Buffer object with _label frame Buffer to the frame Buffer target
specified by target. Target of this frame Buffer should be set manually.
</summary>
<param _label="target">
The frame Buffer target of the binding operation.
</param>
<param _label="index">
Index of object to be binded in handle set
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.TextureGL.LoadTexture(System.Int32,StgSharp.Graphics.Image)">
<summary>
Load an <see cref="T:StgSharp.Graphics.Image" /> to certain texture.
</summary>
<param _label="index">
</param>
<param _label="i">
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.VertexBuffer.Unbind">
<summary>
</summary>
</member>
<member name="M:StgSharp.Graphics.OpenGL.VertexBuffer.WriteMatrixData``1(System.Int32,``0,StgSharp.Graphics.OpenGL.BufferUsage)">
<summary>
Set _data to current vertex Buffer object
</summary>
<typeparam _label="TItem">
Type of bufferData
</typeparam>
<param _label="index">
Index to find certain VBO in this instance
</param>
<param _label="bufferData">
Data to write in
</param>
<param _label="usage">
How OpenGL use these _data, defined by <see cref="T:StgSharp.Graphics.OpenGL.BufferUsage" />
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.VertexBuffer.WriteScalerData``1(System.Int32,``0[],StgSharp.Graphics.OpenGL.BufferUsage)">
<summary>
Set _data to current vertex Buffer object
</summary>
<typeparam _label="TItem">
Type of bufferData
</typeparam>
<param _label="index">
Index to find certain VBO in this instance
</param>
<param _label="bufferArray">
Data to write in
</param>
<param _label="usage">
How OpenGL use these _data, defined by <see cref="T:StgSharp.Graphics.OpenGL.BufferUsage" />
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.VertexBuffer.WriteScalerData``1(System.Int32,System.ReadOnlySpan{``0},StgSharp.Graphics.OpenGL.BufferUsage)">
<summary>
Set _data to current vertex Buffer object
</summary>
<typeparam _label="TItem">
Type of bufferData
</typeparam>
<param _label="index">
Index to find certain VBO in this instance
</param>
<param _label="scalerSpan">
A <see cref="T:System.Span`1" /> of _data to write in
</param>
<param _label="usage">
How OpenGL use these _data, defined by <see cref="T:StgSharp.Graphics.OpenGL.BufferUsage" />
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.VertexBuffer.WriteVectorData``1(System.Int32,System.ReadOnlySpan{``0},StgSharp.Graphics.OpenGL.BufferUsage)">
<summary>
Set data to current vertex Buffer object
</summary>
<typeparam _label="TItem">
Type of bufferData
</typeparam>
<param _label="index">
Index to find certain VBO in this instance
</param>
<param _label="vectorSpan">
A <see cref="T:System.Span`1" /> of data to write in
</param>
<param _label="usage">
How OpenGL use these data, defined by <see cref="T:StgSharp.Graphics.OpenGL.BufferUsage" />
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.VertexBuffer.WriteVectorData``1(System.Int32,``0[],StgSharp.Graphics.OpenGL.BufferUsage)">
<summary>
Set _data to current vertex Buffer object
</summary>
<typeparam _label="TItem">
Type of bufferData
</typeparam>
<param _label="index">
Index to find certain VBO in this instance
</param>
<param _label="vectorArray">
A array of _data to write in
</param>
<param _label="usage">
How OpenGL use these _data, defined by <see cref="T:StgSharp.Graphics.OpenGL.BufferUsage" />
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.glManager.LoadGLfunc(System.String)">
<summary>
Get the function pointer of given OpenGL api _label
</summary>
<param _label="name">
ContextName of the OpenGL api
</param>
<returns>
The funtion pointer of the api in stream of <see cref="T:System.IntPtr" />
</returns>
</member>
<member name="M:StgSharp.Graphics.OpenGL.glManager.LoadOpenGLApiTo(System.IntPtr)">
<summary>
Load all supported OpenGL APIs and bind them to given <see cref="T:StgSharp.MVVM.ViewPort" />.
</summary>
<param _label="contextHandle">
The handle to current OpenGL viewPortDisplay
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.OpenGLFunction.BindFrameBuffer(StgSharp.Graphics.OpenGL.FrameBufferTarget,StgSharp.Graphics.OpenGL.GlHandle)">
<summary>
Bind a frame Buffer to a frame Buffer target Same function as <see
href="https://docs._gl/gl3/glBindFramebuffer"> glBindFramebuffer </see>.
</summary>
<param _label="target">
The frame Buffer target of the binding operation.
</param>
<param _label="handle">
The handle of the frame Buffer object to bind.
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.OpenGLFunction.DeleteRenderBuffer(StgSharp.Graphics.OpenGL.GlHandle)">
<summary>
Delete a render Buffer object Very simlilar function as <see
href="https://docs.gl/gl3/glDeleteRenderbuffers"> glDeleteRenderbuffers </see>. The
only deifference is that this mehtod can only delete one renderbuffer at the same
time.
</summary>
<param _label="bufferHandle">
Handle to Buffer to delete.
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.glRender.CreateElementBuffer(System.Int32)">
<summary>
Create a set of <see cref="T:StgSharp.Graphics.OpenGL.ElementBuffer" />.
</summary>
<param _label="count">
Amount of EBO to be created.
</param>
<returns>
</returns>
</member>
<member name="M:StgSharp.Graphics.OpenGL.glRender.CreateTexture(System.Int32)">
<summary>
Create a sets of <see cref="T:StgSharp.Graphics.OpenGL.TextureGL" />
</summary>
<param _label="count">
Amount of textures to be created.
</param>
<returns>
</returns>
</member>
<member name="M:StgSharp.Graphics.OpenGL.glRender.CreateVertexArray(System.Int32)">
<summary>
Create a set of <see cref="T:StgSharp.Graphics.OpenGL.VertexArray" />.
</summary>
<param _label="count">
Amount of VAO to be created.
</param>
<returns>
</returns>
</member>
<member name="M:StgSharp.Graphics.OpenGL.glRender.CreateVertexBuffer(System.Int32)">
<summary>
Create a set of <see cref="T:StgSharp.Graphics.OpenGL.VertexBuffer" />.
</summary>
<param _label="count">
Amount of Object to be created.
</param>
<returns>
</returns>
</member>
<member name="M:StgSharp.Graphics.OpenGL.glRender.InitializeContext">
<summary>
Initialize an opengl context and load all opengl functions.
</summary>
</member>
<member name="M:StgSharp.Graphics.OpenGL.glRender.MakeAsCurrentContext">
<summary>
Initialize an OpenGl viewPortDisplay if current form has not been binded to any
viewPortDisplay. and set the viewPortDisplay binded to current form as current OpenGL
viewPortDisplay.
</summary>
<exception cref="T:System.Exception">
Something goes wrong and World fails in creating a new OpenGL viewPortDisplay.
</exception>
</member>
<member name="M:StgSharp.Graphics.OpenGL.glRender.RenderEnd">
<inheritdoc />
</member>
<member name="M:StgSharp.Graphics.OpenGL.glRender.RenderStart">
<inheritdoc />
</member>
<member name="M:StgSharp.Graphics.OpenGL.glRender.CreateShaderProgram">
<summary>
Create an instance of <see cref="T:StgSharp.Graphics.OpenGL.Shader" /> program
</summary>
<returns>
New instance of <see cref="T:StgSharp.Graphics.OpenGL.Shader" /> instance.
</returns>
</member>
<member name="M:StgSharp.Graphics.OpenGL.Shader.AttachTo(System.Int32,StgSharp.Graphics.OpenGL.ShaderProgram)">
<summary>
Attach one shader code to a shader program.
</summary>
<param _label="target">
Shader program to attach
</param>
<param _label="index">
Index of shader code in current shader code set.
</param>
</member>
<member name="M:StgSharp.Graphics.OpenGL.ShaderProgram.#ctor(StgSharp.Graphics.OpenGL.glRender)">
<summary>
CustomizeInit a program with no shader attached.
</summary>
</member>
<member name="M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``1(System.String)">
<summary>
Get a uniform form current shader, the value type of the uniform should be provided.
</summary>
<param _label="name">
ContextName of the Uniform in shader code
</param>
<returns>
</returns>
</member>
<member name="M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``2(System.String)">
<summary>
Get a uniform form current shader, the value type of the uniform should be provided.
</summary>
<param _label="name">
ContextName of the Uniform in shader code
</param>
<returns>
</returns>
</member>
<member name="M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``3(System.String)">
<summary>
Get a uniform form current shader, the value type of the uniform should be provided.
</summary>
<param _label="name">
ContextName of the Uniform in shader code
</param>
<returns>
</returns>
</member>
<member name="M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``4(System.String)">
<summary>
Get a uniform form current shader, the value type of the uniform should be provided.
</summary>
<param _label="name">
ContextName of the Uniform in shader code
</param>
<returns>
</returns>
</member>
<member name="M:StgSharp.Graphics.OpenGL.ShaderProgram.Link">
<summary>
Link the shader to current viewPortDisplay.
</summary>
</member>
<member name="M:StgSharp.Graphics.OpenGL.ShaderProgram.Use">
<summary>
Let the current viewPortDisplay use this shader.
</summary>
</member>
<member name="M:StgSharp.Graphics.ShaderEdit.IglConvertable.DisplayGLtypeDefinition">
<summary>
</summary>
</member>
<member name="M:StgSharp.Graphics.ShaderEdit.IglConvertable.GainAllUniforms(StgSharp.Graphics.OpenGL.ShaderProgram,System.String[])">
<summary>
</summary>
</member>
<member name="M:StgSharp.Graphics.ShaderEdit.IglConvertable.GetConvertedGLtype">
<summary>
</summary>
<returns>
</returns>
</member>
<member name="M:StgSharp.Graphics.ShaderEdit.IglConvertable.SetAllUniforms">
<summary>
</summary>
</member>
<member name="M:StgSharp.Graphics.RenderStream.SetSizeLimit(System.Int32,System.Int32,System.Int32,System.Int32)">
<summary>
Set the size limit of current form
</summary>
<param _label="minWidth">
Minimum width of current form
</param>
<param _label="minHeight">
Minimum height of current form
</param>
<param _label="maxWidth">
Maximum width of current form
</param>
<param _label="maxHeight">
Maximum height of current form
</param>
</member>
<member name="M:StgSharp.Graphics.RenderStream.NativeCameraUniform(StgSharp.Graphics.OpenGL.ShaderProgram,System.String)">
<summary>
Get <see cref="T:StgSharp.Graphics.OpenGL.Uniform`1" />(TView is <see cref="T:StgSharp.Math.Matrix44" />) uniform from a shader.
This uniform will be used as projection matrix of this camera. Additionally, for
multi- shader rendering, each shader requires a uniform, so do not ignore return
value of this method.
</summary>
<param _label="source">
Shader using this camera
</param>
<param _label="name">
ContextName of projection camera named in shader
</param>
<returns>
<see cref="T:StgSharp.Graphics.OpenGL.Uniform`1" />(TView is <see cref="T:StgSharp.Math.Matrix44" />) representing projection
matrix in shader program.
</returns>
</member>
<member name="M:StgSharp.Graphics.RenderStream.RenderStart">
<summary>
Marking the start of current render operations, and set this renser context as
current.
</summary>
</member>
<member name="M:StgSharp.Graphics.RenderStream.RenderEnd">
<summary>
Marking the end of current render operations, and release the binding of this renser
context to current, making it available for another thread as current.
</summary>
</member>
<member name="M:StgSharp.Graphics.Camera.GainAllUniforms(StgSharp.Graphics.OpenGL.ShaderProgram,System.String[])">
<summary>
Get all uniform related to this <see cref="T:StgSharp.Graphics.Camera" />.
</summary>
<param _label="source">
Shader program requires this camera.
</param>
<param _label="uniformName">
ContextName of all related uniforms. If you fallow form from <see
cref="M:StgSharp.Graphics.ShaderEdit.IglConvertable.DisplayGLtypeDefinition" />
</param>
<exception cref="T:System.ArgumentException">
</exception>
</member>
<member name="P:StgSharp.Threading.ThreadHelper.EmptyThread">
<summary>
An individual thread doing nothing, and its <see cref="P:System.Threading.Thread.IsAlive" /> <see
langword="property" /> always returns false.
</summary>
</member>
<member name="M:StgSharp.MVVM.ViewModel.ViewModelBase.UseViewModel(System.String)">
<summary>
CustomizeInit this form and render it on screen, and respond with operation
</summary>
</member>
<member name="P:StgSharp.MVVM.ViewModel.ViewModelBase.Height">
<summary>
Height of this form, represent in <see cref="T:System.Int32" />
</summary>
</member>
<member name="P:StgSharp.MVVM.ViewModel.ViewModelBase.Width">
<summary>
Width of this form, represent in <see cref="T:System.Int32" />
</summary>
</member>
<member name="P:StgSharp.MVVM.ViewModel.ViewModelBase.Size">
<summary>
Width of this form, represent in <see cref="T:System.Int32" />
</summary>
</member>
<member name="M:StgSharp.MVVM.ViewModel.ViewModelBase.SetSizeLimit(StgSharp.Math.Vec2,StgSharp.Math.Vec2)">
<summary>
Set the size limit of current form
</summary>
<param _label="minSize">
Minimum size of current form. In form of a <see cref="T:StgSharp.Math.Vec2" /> of (width,height)
</param>
<param _label="maxSize">
Maximum size of current form. In form of a <see cref="T:StgSharp.Math.Vec2" /> of (width,height)
</param>
</member>
<member name="M:StgSharp.MVVM.ViewModel.ViewModelBase.SetSizeLimit(System.Int32,System.Int32,System.Int32,System.Int32)">
<summary>
Set the size limit of current form
</summary>
<param _label="minWidth">
Minimum width of current form
</param>
<param _label="minHeight">
Minimum height of current form
</param>
<param _label="maxWidth">
Maximum width of current form
</param>
<param _label="maxHeight">
Maximum height of current form
</param>
</member>
<member name="T:StgSharp.MVVM.ViewBase">
<summary>
ViewBase is the base type for all view types, providing context binding and control
element binding. A complete view should contain one complete <see cref="T:StgSharp.MVVM.ViewBase.ViewDesigner`1"
/>, <see cref="T:StgSharp.MVVM.ViewBase.ViewRender`1" />, and <see cref="!:ViewResponder" />, which provide
layout descriptions of control elements, user responses, and rendering implementations in
the view. Data between instances of <see cref="T:StgSharp.MVVM.ViewBase.ViewDesigner`1" />, <see
cref="T:StgSharp.MVVM.ViewBase.ViewRender`1" />, and <see cref="T:StgSharp.MVVM.ViewBase.ViewResponder`1" /> is shared through <see
cref="T:StgSharp.MVVM.ViewBase" />.
</summary>
</member>
<member name="M:StgSharp.MVVM.ViewBase.GetKeyStatus(StgSharp.KeyboardKey)">
<summary>
Get the status of a certain key on the keyboard.
</summary>
<param _label="key">
</param>
<returns>
<see cref="T:StgSharp.KeyStatus" /> representing if a key is pressed or released.
</returns>
</member>
<member name="T:StgSharp.MVVM.ViewBase.ViewDesigner`1">
<summary>
ViewDesigner provides descriptions of various controls in the view, binds the
controls to specific user actions and behaviors, and describes the layout and
interactions of each control.
</summary>
</member>
<member name="T:StgSharp.PipeLine.PipelineNode">
<summary>
</summary>
<risk>
Reset pipeline has risk, this operation is a direct operation to port in current node, the
port on the other node cannot get the change.
</risk>
</member>
<member name="M:StgSharp.PipeLine.PipeLineRunner.IsValidCalling">
<summary>
<para> Only the following occasions of calling are valid: </para> <para>1. no bp is
running or the only bp is quitting.</para><para>2. calling from the main thread or a
thread the current bp is running on. </para>
</summary>
</member>
<member name="T:StgSharp.PipeLine.PipelineScheduler">
<summary>
A sets of complex logic designed for running in multi threads environment. Warning: do not
run a <see cref="T:StgSharp.PipeLine.PipelineScheduler" /> instance in multi threads more than once.
</summary>
</member>
<member name="T:StgSharp.Timing.TimeSpanProvider">
<summary>
A microsecond-accuracy timer. It will refresh every a certain time span.
</summary>
</member>
<member name="M:StgSharp.Timing.TimeSpanProvider.#ctor(System.Int64,StgSharp.Timing.TimeSourceProviderBase)">
<summary>
Create a new <see cref="T:StgSharp.Timing.TimeSpanProvider" /> and define the length of time span.
Length of a single time span is defined in microseconds.
</summary>
<param _label="spanMicroSeconds">
</param>
<param _label="provider">
</param>
</member>
<member name="M:StgSharp.Timing.TimeSpanProvider.#ctor(System.Double,StgSharp.Timing.TimeSourceProviderBase)">
<summary>
Create a new <see cref="T:StgSharp.Timing.TimeSpanProvider" /> and define the length of time span.
Length of a single time span is defined in seconds.
</summary>
<param _label="spanSeconds">
</param>
<param _label="provider">
</param>
</member>
<member name="M:StgSharp.Timing.TimeSpanProvider.#ctor(System.Int64,System.Int64,StgSharp.Timing.TimeSourceProviderBase)">
<summary>
Create a new <see cref="T:StgSharp.Timing.TimeSpanProvider" /> and define the length of time span.
Length of a single time span is defined in microseconds.
</summary>
<param _label="spanLength">
</param>
<param _label="maxSpan">
</param>
<param _label="provider">
</param>
</member>
<member name="P:StgSharp.Timing.TimeSpanProvider.DefaultProvider">
<summary>
Time source provider provided in <see cref="T:StgSharp.World" /> internal framework.
</summary>
</member>
</members>
</doc>
@@ -0,0 +1,227 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v8.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v8.0": {
"StgSharp.Script/1.0.0": {
"dependencies": {
"CommunityToolkit.HighPerformance": "8.4.0",
"Microsoft.CodeAnalysis.CSharp": "4.13.0",
"StgSharp.Common": "1.0.0"
},
"runtime": {
"StgSharp.Script.dll": {}
}
},
"CommunityToolkit.HighPerformance/8.4.0": {
"runtime": {
"lib/net8.0/CommunityToolkit.HighPerformance.dll": {
"assemblyVersion": "8.4.0.0",
"fileVersion": "8.4.0.1"
}
}
},
"Microsoft.CodeAnalysis.Analyzers/3.11.0": {},
"Microsoft.CodeAnalysis.Common/4.13.0": {
"dependencies": {
"Microsoft.CodeAnalysis.Analyzers": "3.11.0",
"System.Collections.Immutable": "8.0.0",
"System.Reflection.Metadata": "8.0.0"
},
"runtime": {
"lib/net8.0/Microsoft.CodeAnalysis.dll": {
"assemblyVersion": "4.13.0.0",
"fileVersion": "4.1300.25.12011"
}
},
"resources": {
"lib/net8.0/cs/Microsoft.CodeAnalysis.resources.dll": {
"locale": "cs"
},
"lib/net8.0/de/Microsoft.CodeAnalysis.resources.dll": {
"locale": "de"
},
"lib/net8.0/es/Microsoft.CodeAnalysis.resources.dll": {
"locale": "es"
},
"lib/net8.0/fr/Microsoft.CodeAnalysis.resources.dll": {
"locale": "fr"
},
"lib/net8.0/it/Microsoft.CodeAnalysis.resources.dll": {
"locale": "it"
},
"lib/net8.0/ja/Microsoft.CodeAnalysis.resources.dll": {
"locale": "ja"
},
"lib/net8.0/ko/Microsoft.CodeAnalysis.resources.dll": {
"locale": "ko"
},
"lib/net8.0/pl/Microsoft.CodeAnalysis.resources.dll": {
"locale": "pl"
},
"lib/net8.0/pt-BR/Microsoft.CodeAnalysis.resources.dll": {
"locale": "pt-BR"
},
"lib/net8.0/ru/Microsoft.CodeAnalysis.resources.dll": {
"locale": "ru"
},
"lib/net8.0/tr/Microsoft.CodeAnalysis.resources.dll": {
"locale": "tr"
},
"lib/net8.0/zh-Hans/Microsoft.CodeAnalysis.resources.dll": {
"locale": "zh-Hans"
},
"lib/net8.0/zh-Hant/Microsoft.CodeAnalysis.resources.dll": {
"locale": "zh-Hant"
}
}
},
"Microsoft.CodeAnalysis.CSharp/4.13.0": {
"dependencies": {
"Microsoft.CodeAnalysis.Analyzers": "3.11.0",
"Microsoft.CodeAnalysis.Common": "4.13.0",
"System.Collections.Immutable": "8.0.0",
"System.Reflection.Metadata": "8.0.0"
},
"runtime": {
"lib/net8.0/Microsoft.CodeAnalysis.CSharp.dll": {
"assemblyVersion": "4.13.0.0",
"fileVersion": "4.1300.25.12011"
}
},
"resources": {
"lib/net8.0/cs/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "cs"
},
"lib/net8.0/de/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "de"
},
"lib/net8.0/es/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "es"
},
"lib/net8.0/fr/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "fr"
},
"lib/net8.0/it/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "it"
},
"lib/net8.0/ja/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "ja"
},
"lib/net8.0/ko/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "ko"
},
"lib/net8.0/pl/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "pl"
},
"lib/net8.0/pt-BR/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "pt-BR"
},
"lib/net8.0/ru/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "ru"
},
"lib/net8.0/tr/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "tr"
},
"lib/net8.0/zh-Hans/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "zh-Hans"
},
"lib/net8.0/zh-Hant/Microsoft.CodeAnalysis.CSharp.resources.dll": {
"locale": "zh-Hant"
}
}
},
"Microsoft.CSharp/4.7.0": {},
"System.Collections.Immutable/8.0.0": {},
"System.Reflection.Metadata/8.0.0": {
"dependencies": {
"System.Collections.Immutable": "8.0.0"
}
},
"System.Runtime.CompilerServices.Unsafe/6.1.0": {},
"StgSharp.Common/1.0.0": {
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Runtime.CompilerServices.Unsafe": "6.1.0"
},
"runtime": {
"StgSharp.Common.dll": {
"assemblyVersion": "1.0.0",
"fileVersion": "1.0.0.0"
}
}
}
}
},
"libraries": {
"StgSharp.Script/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"CommunityToolkit.HighPerformance/8.4.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-flxspiBs0G/0GMp7IK2J2ijV9bTG6hEwFc/z6ekHqB6nwRJ4Ry2yLdx+TkbCUYFCl4XhABkAwomeKbT6zM2Zlg==",
"path": "communitytoolkit.highperformance/8.4.0",
"hashPath": "communitytoolkit.highperformance.8.4.0.nupkg.sha512"
},
"Microsoft.CodeAnalysis.Analyzers/3.11.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-v/EW3UE8/lbEYHoC2Qq7AR/DnmvpgdtAMndfQNmpuIMx/Mto8L5JnuCfdBYtgvalQOtfNCnxFejxuRrryvUTsg==",
"path": "microsoft.codeanalysis.analyzers/3.11.0",
"hashPath": "microsoft.codeanalysis.analyzers.3.11.0.nupkg.sha512"
},
"Microsoft.CodeAnalysis.Common/4.13.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-T8nRl4mAUY4mhdYM4U2ra2vP2EL+ol8Yqwo0gwC/V55vmlXq9NxdIkZJynTpTL1uX/jHijJ90AeOEx4lf7OwzQ==",
"path": "microsoft.codeanalysis.common/4.13.0",
"hashPath": "microsoft.codeanalysis.common.4.13.0.nupkg.sha512"
},
"Microsoft.CodeAnalysis.CSharp/4.13.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-BsH7Vijbj9IL7Fj4k/ysZSVyLGFqr75wmdFGwCKWJvSjnA1xwPaQ3hkB2BQdHOt5CpEYA6Q0I6Oo5sDTDHqHsg==",
"path": "microsoft.codeanalysis.csharp/4.13.0",
"hashPath": "microsoft.codeanalysis.csharp.4.13.0.nupkg.sha512"
},
"Microsoft.CSharp/4.7.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-pTj+D3uJWyN3My70i2Hqo+OXixq3Os2D1nJ2x92FFo6sk8fYS1m1WLNTs0Dc1uPaViH0YvEEwvzddQ7y4rhXmA==",
"path": "microsoft.csharp/4.7.0",
"hashPath": "microsoft.csharp.4.7.0.nupkg.sha512"
},
"System.Collections.Immutable/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-AurL6Y5BA1WotzlEvVaIDpqzpIPvYnnldxru8oXJU2yFxFUy3+pNXjXd1ymO+RA0rq0+590Q8gaz2l3Sr7fmqg==",
"path": "system.collections.immutable/8.0.0",
"hashPath": "system.collections.immutable.8.0.0.nupkg.sha512"
},
"System.Reflection.Metadata/8.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ptvgrFh7PvWI8bcVqG5rsA/weWM09EnthFHR5SCnS6IN+P4mj6rE1lBDC4U8HL9/57htKAqy4KQ3bBj84cfYyQ==",
"path": "system.reflection.metadata/8.0.0",
"hashPath": "system.reflection.metadata.8.0.0.nupkg.sha512"
},
"System.Runtime.CompilerServices.Unsafe/6.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-5o/HZxx6RVqYlhKSq8/zronDkALJZUT2Vz0hx43f0gwe8mwlM0y2nYlqdBwLMzr262Bwvpikeb/yEwkAa5PADg==",
"path": "system.runtime.compilerservices.unsafe/6.1.0",
"hashPath": "system.runtime.compilerservices.unsafe.6.1.0.nupkg.sha512"
},
"StgSharp.Common/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
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+a24215351dc744a54eba06fb168de611dc5a335f")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -0,0 +1 @@
3d743b748ddd53aff7bc73dd4e95279a6908adc51bbde9e715c904a1d62ec396
@@ -0,0 +1,23 @@
is_global = true
build_property.TargetFramework = net8.0
build_property.TargetFramework = net8.0
build_property.TargetPlatformMinVersion =
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = StgSharp.Script
build_property.ProjectDir = D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.EffectiveAnalysisLevelStyle = 8.0
build_property.EnableCodeStyleSeverity =
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
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+e687473132786f419a48170313782d6779890c3d")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -0,0 +1 @@
4c7f817069768658fd11e2f809ae41e403d5cd4106134072df87718bc9fed9f4
@@ -0,0 +1,5 @@
is_global = true
build_property.RootNamespace = StgSharp.Script
build_property.ProjectDir = D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e687473132786f419a48170313782d6779890c3d")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -0,0 +1 @@
763989be4fc1c0038f6ed3f9723e1b5dc4f3d10b1809f46a2fcbee31212930ff
@@ -0,0 +1,5 @@
is_global = true
build_property.RootNamespace = StgSharp.Script
build_property.ProjectDir = D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\内核源代码\StgSharp.Script\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
@@ -0,0 +1,164 @@
{
"format": 1,
"restore": {
"D:\\PlatformDev\\StgSharp.Script\\StgSharp.Script.csproj": {}
},
"projects": {
"D:\\PlatformDev\\StgSharp.Common\\StgSharp.Common.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\PlatformDev\\StgSharp.Common\\StgSharp.Common.csproj",
"projectName": "StgSharp.Common",
"projectPath": "D:\\PlatformDev\\StgSharp.Common\\StgSharp.Common.csproj",
"packagesPath": "C:\\Users\\GF\\.nuget\\packages\\",
"outputPath": "D:\\PlatformDev\\StgSharp.Common\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\GF\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"C:\\Program Files\\dotnet\\library-packs": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.300"
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"Microsoft.CSharp": {
"target": "Package",
"version": "[4.7.0, )"
},
"System.Runtime.CompilerServices.Unsafe": {
"target": "Package",
"version": "[6.1.0, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.304/PortableRuntimeIdentifierGraph.json"
}
}
},
"D:\\PlatformDev\\StgSharp.Script\\StgSharp.Script.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\PlatformDev\\StgSharp.Script\\StgSharp.Script.csproj",
"projectName": "StgSharp.Script",
"projectPath": "D:\\PlatformDev\\StgSharp.Script\\StgSharp.Script.csproj",
"packagesPath": "C:\\Users\\GF\\.nuget\\packages\\",
"outputPath": "D:\\PlatformDev\\StgSharp.Script\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\GF\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"C:\\Program Files\\dotnet\\library-packs": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {
"D:\\PlatformDev\\StgSharp.Common\\StgSharp.Common.csproj": {
"projectPath": "D:\\PlatformDev\\StgSharp.Common\\StgSharp.Common.csproj"
}
}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.300"
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"CommunityToolkit.HighPerformance": {
"target": "Package",
"version": "[8.4.0, )"
},
"Microsoft.CodeAnalysis.CSharp": {
"target": "Package",
"version": "[4.13.0, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.304/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More