Normalize all existing files to LF
This commit is contained in:
@@ -1,258 +1,258 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpBinaryOperatorNode"
|
||||
// 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}",
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpBinaryOperatorNode"
|
||||
// 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}",
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpCollectionIndexNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpCollectionIndexNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpElementInitializingNode"
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpElementInitializingNode"
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpElementMemberNameNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpElementMemberNameNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpEnumLiteralNode"
|
||||
// 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
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpEnumLiteralNode"
|
||||
// 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
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,75 +1,75 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpFunctionCallingNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpFunctionCallingNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +1,95 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpIfNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpIfNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpInstanceMemberNode"
|
||||
// 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;
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpInstanceMemberNode"
|
||||
// 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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpInstanceReferenceNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpInstanceReferenceNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,187 +1,187 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpLiteralNode"
|
||||
// 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();
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpLiteralNode"
|
||||
// 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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,85 +1,85 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpMetaRefNode"
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpMetaRefNode"
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpProcedureCallingNode"
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpProcedureCallingNode"
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpProcedureControlNode"
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpProcedureControlNode"
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,119 +1,119 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpRangeAndIndexNode"
|
||||
// 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();
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpRangeAndIndexNode"
|
||||
// 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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,198 +1,198 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpRepeatNode"
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpRepeatNode"
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,133 +1,133 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpSwitchNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpSwitchNode"
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpTupleNode"
|
||||
// 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpTupleNode"
|
||||
// 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,99 +1,99 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpUnaryOperatorNode"
|
||||
// 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}",
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ExpUnaryOperatorNode"
|
||||
// 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}",
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,149 +1,149 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="_ExpNode"
|
||||
// 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="_ExpNode"
|
||||
// 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user