Daily update on 20250314-044324 by Nitload Youmu. Additional Message : Change: Import all keywords and group them by application

Add: Process Token.Member by its detailed type

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-03-14 04:43:25 +08:00
parent 6222f8c8be
commit 9307d7d658
13 changed files with 426 additions and 70 deletions
@@ -103,17 +103,17 @@ namespace StgSharp.Script.Express
{
IEnumerable<KeyValuePair<string, ExpTypeSource>> builtinTypeSource = [
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Int ),
new ExpBuiltinType( KeyWord.Int, typeof( int ) ) ),
PoolString( KeyWord.Integer ),
new ExpBuiltinType( KeyWord.Integer, typeof( int ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Real ),
new ExpBuiltinType( KeyWord.Real, typeof( float ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Bool ),
new ExpBuiltinType( KeyWord.Bool, typeof( bool ) ) ),
PoolString( KeyWord.Boolean ),
new ExpBuiltinType( KeyWord.Boolean, typeof( bool ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.Logic ),
new ExpBuiltinType( KeyWord.Logic, typeof( ExpLogic ) ) ),
PoolString( KeyWord.Logical ),
new ExpBuiltinType( KeyWord.Logical, typeof( ExpLogic ) ) ),
new KeyValuePair<string, ExpTypeSource>(
PoolString( KeyWord.String ),
new ExpBuiltinType( KeyWord.String, typeof( string ) ) ),
@@ -50,7 +50,7 @@ namespace StgSharp.Script.Express
private static FrozenDictionary<string, ExpElementInstanceBase> _builtinConst;
private static FrozenDictionary<string, ExpTypeSource> _builtinType;
private static FrozenDictionary<string, ExpBinaryOperatorNode> _operators;
private static StringPool _compileStringCache;
private static StringPool _compileStringCache,_emptyCache;
internal static ConcurrentStringHashMultiplexer Multiplexer
{
@@ -88,20 +88,21 @@ namespace StgSharp.Script.Express
InitPrecedence();
_operatorsWithLetter = [
KeyWord.ADD,
KeyWord.SUB,
KeyWord.MUL,
KeyWord.DIV,
KeyWord.AND,
KeyWord.OR,
KeyWord.XOR,
KeyWord.ANDOR,
KeyWord.NOT,
KeyWord.Add,
KeyWord.Sub,
KeyWord.Mul,
KeyWord.Div,
KeyWord.And,
KeyWord.Or,
KeyWord.Xor,
KeyWord.AndOr,
KeyWord.Not,
];
ExpSchema_Nitload.Only
.TryGetType(
PoolString( KeyWord.Int ), out ExpTypeSource? _expInt );
PoolString( KeyWord.Integer ),
out ExpTypeSource? _expInt );
ExpInt = _expInt;
ExpSchema_Nitload.Only
@@ -111,9 +112,24 @@ namespace StgSharp.Script.Express
ExpReal = _expReal;
ExpSchema_Nitload.Only
.TryGetType(
PoolString( KeyWord.Bool ),
PoolString( KeyWord.Boolean ),
out ExpTypeSource? _expBool );
ExpBool = _expBool;
_emptyCache = new StringPool();
/*
foreach( string str in _compileStringCache ) {
_emptyCache.Add( str );
}
/**/
}
public static bool LetterIsKeyword( string str )
{
if( char.IsLetter( str[ 0 ] ) ) {
return _keywordSet.Contains( str );
}
return true;
}
public static bool LetterIsOperator( string str )
+293 -30
View File
@@ -40,8 +40,12 @@ namespace StgSharp.Script.Express
public static partial class ExpCompile
{
private static HashSet<string> _keywordSet;
private static void PoolKeywords()
{
_keywordSet = new();
FieldInfo[] fields = typeof( KeyWord ).GetFields(
BindingFlags.Public );
ParallelLoopResult result = Parallel.ForEach(
@@ -49,6 +53,7 @@ namespace StgSharp.Script.Express
if( field.FieldType == typeof( string ) && field.GetValue(
null ) is string str ) {
_compileStringCache.GetOrAdd( str );
_keywordSet.Add( str );
}
} );
while( !result.IsCompleted ) { }
@@ -57,36 +62,294 @@ namespace StgSharp.Script.Express
public static class KeyWord
{
public const string Int = "INTAGER",
Real = "REAL",
Bool = "BOOLEAN",
String = "STRING",
Logic = "LOGIC",
Binary = "BINARY",
Constant = "CONSTANT",
AND = "AND",
OR = "OR",
XOR = "XOR",
ADD = "+",
SUB = "-",
MUL = "*",
DIV = "/",
NOT = "NOT",
NotEqual = "<>",
Assignment = ":=",
Equal = "=",
Mod = "MOD",
Self = "SELF",
Pi = "PI",
True = "TRUE",
False = "FALSE",
Insert = "INSERT",
Remove = "REMOVE",
ANDOR = "ANDOR",
GetIndex = "[",
UnaryPlus = "+",
UnaryMinus = "-",
Exp = "**";
public static readonly HashSet<string> ScopeBlock = new HashSet<string> {
EndAlias, EndCase, EndConstant, EndEntity, EndFunction, EndIf, EndLocal, EndProcedure, EndRepeat, EndRule, EndSchema, EndSubtypeConstraint, EndType
};
public static readonly HashSet<string> Symbols = [
Dot, Comma, Semicolon, Colon, Percent, Apostrophe,
Backslash, IndexOf, RightBracket, LeftBrace,
RightBrace, Pipe, LeftParen, RightParen, LeftAsterisk,
Assignment, DoublePipe, ExpSymbole, CommentSingleLine,
CommentStart, CommentEnd, ColonEqualColon, ColonNotEqualColon
];
#region Basic Data Type
public const string Array = "ARRAY";
public const string Bag = "BAG";
public const string Binary = "BINARY";
public const string Boolean = "BOOLEAN";
public const string Enumeration = "ENUMERATION";
public const string Integer = "INTEGER";
public const string List = "LIST";
public const string Logical = "LOGICAL";
public const string Number = "NUMBER";
public const string Of = "OF";
public const string Real = "REAL";
public const string Set = "SET";
public const string String = "STRING";
#endregion
#region Flow Control
public const string Begin = "BEGIN";
public const string Case = "CASE";
public const string Else = "ELSE";
public const string End = "END";
public const string For = "FOR";
public const string If = "IF";
public const string Otherwise = "OTHERWISE";
public const string Repeat = "REPEAT";
public const string Return = "RETURN";
public const string Skip = "SKIP";
public const string Then = "THEN";
public const string To = "TO";
public const string Until = "UNTIL";
public const string While = "WHILE";
#endregion
#region Declarations
public const string Constant = "CONSTANT";
public const string Derive = "DERIVE";
public const string Entity = "ENTITY";
public const string Extensible = "EXTENSIBLE";
public const string Fixed = "FIXED";
public const string Function = "FUNCTION";
public const string Generic = "GENERIC";
public const string GenericEntity = "GENERIC_ENTITY";
public const string Inverse = "INVERSE";
public const string Local = "LOCAL";
public const string Procedure = "PROCEDURE";
public const string Rule = "RULE";
public const string Schema = "SCHEMA";
public const string Type = "TYPE";
public const string Var = "VAR";
#endregion
#region Constraints Inheritance
public const string Oneof = "ONEOF";
public const string Optional = "OPTIONAL";
public const string Subtype = "SUBTYPE";
public const string SubtypeConstraint = "SUBTYPE CONSTRAINT";
public const string Supertype = "SUPERTYPE";
public const string TotalOver = "TOTAL OVER";
public const string Unique = "UNIQUE";
public const string Where = "WHERE";
#endregion
#region Scope
public const string EndAlias = "END_ALIAS";
public const string EndCase = "END_CASE";
public const string EndConstant = "END_CONSTANT";
public const string EndEntity = "END_ENTITY";
public const string EndFunction = "END_FUNCTION";
public const string EndIf = "END_IF";
public const string EndLocal = "END_LOCAL";
public const string EndProcedure = "END_PROCEDURE";
public const string EndRepeat = "END_REPEAT";
public const string EndRule = "END_RULE";
public const string EndSchema = "END_SCHEMA";
public const string EndSubtypeConstraint = "END_SUBTYPE CONSTRAINT";
public const string EndType = "END_TYPE";
#endregion
#region Index and Ref
public const string Query = "QUERY";
public const string Reference = "REFERENCE";
public const string Select = "SELECT";
#endregion
#region Modifiers Attributes
public const string Abstract = "ABSTRACT";
public const string Aggregate = "AGGREGATE";
public const string As = "AS";
public const string BasedOn = "BASED ON";
public const string By = "BY";
public const string Escape = "ESCAPE";
public const string From = "FROM";
public const string Use = "USE";
public const string With = "WITH";
#endregion
#region Aliasing
public const string Alias = "ALIAS";
public const string Renamed = "RENAMED";
#endregion
#region Operator
public const string And = "AND";
public const string AndOr = "ANDOR";
public const string Div = "DIV";
public const string In = "IN";
public const string Like = "LIKE";
public const string Mod = "MOD";
public const string Not = "NOT";
public const string Or = "OR";
public const string Xor = "XOR";
#endregion
#region Constants
public const string QuestionMark = "?";
public const string Self = "SELF";
public const string Const = "CONST";
public const string E = "E";
public const string Pi = "PI";
public const string False = "FALSE";
public const string True = "TRUE";
public const string Unknown = "UNKNOWN";
#endregion
#region Functions
public const string Abs = "ABS";
public const string Acos = "ACOS";
public const string Asin = "ASIN";
public const string Atan = "ATAN";
public const string Blength = "BLENGTH";
public const string Cos = "COS";
public const string Exists = "EXISTS";
public const string Exp = "EXP";
public const string Format = "FORMAT";
public const string Hibound = "HIBOUND";
public const string Hiindex = "HIINDEX";
public const string Length = "LENGTH";
public const string Lobound = "LObound";
public const string Log = "LOG";
public const string Log2 = "LOG2";
public const string Log10 = "LOG10";
public const string Loindex = "LOINDEX";
public const string Nvl = "NVL";
public const string Odd = "ODD";
public const string Rolesof = "ROLESOF";
public const string Sin = "SIN";
public const string Sizeof = "SIZEOF";
public const string Sqrt = "SQRT";
public const string Tan = "TAN";
public const string Typeof = "TYPEOF";
public const string Usedin = "USEDIN";
public const string Value = "VALUE";
public const string ValueIn = "VALUE IN";
public const string ValueUnique = "VALUE UNIQUE";
#endregion
#region Procedure
public const string Insert = "INSERT";
public const string Remove = "REMOVE";
#endregion
#region Symbols
public const string Dot = ".";
public const string Comma = ",";
public const string Semicolon = ";";
public const string Colon = ":";
public const string Mul = "*";
public const string Add = "+";
public const string UnaryPlus = "+";
public const string Sub = "-";
public const string UnaryMinus = "-";
public const string Equal = "=";
public const string Percent = "%";
public const string Apostrophe = "'";
public const string Backslash = "\\";
public const string Slash = "/";
public const string LessThan = "<";
public const string GreaterThan = ">";
public const string IndexOf = "[";
public const string RightBracket = "]";
public const string LeftBrace = "{";
public const string RightBrace = "}";
public const string Pipe = "|";
public const string EConstant = "E";
public const string LeftParen = "(";
public const string RightParen = ")";
public const string LessThanOrEqual = "<=";
public const string NotEqual = "<>";
public const string GreaterThanOrEqual = ">=";
public const string LeftAsterisk = "<*";
public const string Assignment = ":=";
public const string DoublePipe = "||";
public const string ExpSymbole = "**";
public const string CommentSingleLine = "--";
public const string CommentStart = "(*";
public const string CommentEnd = "*)";
public const string ColonEqualColon = ":=:";
public const string ColonNotEqualColon = ":<>:";
#endregion
public static readonly HashSet<string> DataTypes = [
Array, Bag, Binary, Boolean, Enumeration, Integer, List, Logical, Number, Of, Real, Set, String
];
public static readonly HashSet<string> FlowControl = [
Begin, Case, Else, End, For, If, Otherwise, Repeat, Return, Skip, Then, To, Until, While
];
public static readonly HashSet<string> Declarations = [
Constant, Derive, Entity, Extensible, Fixed, Function, Generic,
GenericEntity, Inverse, Local, Procedure, Rule, Schema, Type, Var
];
public static readonly HashSet<string> ConstraintsInheritance = [
Oneof, Optional, Subtype, SubtypeConstraint, Supertype, TotalOver, Unique, Where
];
public static readonly HashSet<string> QueryReference = [
Query, Reference, Select
];
public static readonly HashSet<string> ModifiersAttributes = [
Abstract, Aggregate, As, BasedOn, By, Escape, Fixed, From, Use, With
];
public static readonly HashSet<string> Aliasing = [
Alias, Renamed
];
public static readonly HashSet<string> Operators = [
And, AndOr, Div, In, Like, Mod, Not, Or, Xor,
Add, Sub, Mul, Slash, Equal, NotEqual,
LessThan, GreaterThan, LessThanOrEqual, GreaterThanOrEqual
];
public static readonly HashSet<string> Literals = [
QuestionMark, Self, Const, E, Pi, False, True, Unknown
];
public static readonly HashSet<string> InternalFunctions = [
Abs, Acos, Asin, Atan, Blength, Cos, Exists, Exp,
Format, Hibound, Hiindex, Length, Lobound, Log,
Log2, Log10, Loindex, Nvl, Odd, Rolesof, Sin,
Sizeof, Sqrt, Tan, Typeof, Usedin, Value,
ValueIn, ValueUnique
];
public static readonly HashSet<string> InternalProcess = [
Insert, Remove
];
}
@@ -0,0 +1,77 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpCollectionIndexNode.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpCollectionIndexNode : ExpNode
{
private ExpCollectionInstanceBase _collection;
private ExpNode _indexExpression;
private ExpCollectionIndexNode(
Token source,
ExpCollectionInstanceBase instance,
ExpNode indexExpression )
: base( source )
{
_collection = instance;
_indexExpression = indexExpression;
CodeConvertTemplate = @"{0}[{1}]";
}
public override ExpNode Left => _collection;
public override ExpNode Right => _indexExpression;
public override IExpElementSource EqualityTypeConvert => _collection.EqualityTypeConvert;
public static ExpCollectionIndexNode Create(
Token source,
ExpCollectionInstanceBase instance,
ExpNode indexExpression )
{
if( !indexExpression.IsNumber ) {
throw new ExpInvalidTypeException(
"Number", indexExpression.EqualityTypeConvert.Name );
}
return new ExpCollectionIndexNode(
source, instance, indexExpression );
}
}
}
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpLiteralGenericNode.cs"
// file="ExpLiteralNode.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
@@ -51,12 +51,13 @@ namespace StgSharp.Script.Express
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.Int, out ExpTypeSource? type ) ?
ExpCompile.KeyWord.Integer,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public int Value => _value;
public override string TypeName => ExpCompile.KeyWord.Int;
public override string TypeName => ExpCompile.KeyWord.Integer;
}
@@ -100,7 +101,8 @@ namespace StgSharp.Script.Express
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.Bool, out ExpTypeSource? type ) ?
ExpCompile.KeyWord.Boolean,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
public override string TypeName => EqualityTypeConvert.Name;
@@ -147,7 +149,7 @@ namespace StgSharp.Script.Express
public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema
.TryGetType(
ExpCompile.KeyWord.Logic,
ExpCompile.KeyWord.Logical,
out ExpTypeSource? type ) ?
type : throw new ExpCompileNotInitializedException();
@@ -32,6 +32,7 @@ using CommunityToolkit.HighPerformance.Buffers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
@@ -53,16 +53,16 @@ namespace StgSharp.Script.Express
ExpNode left = GetNextOperandCache();
ExpNode right = GetNextOperandCache();
switch( t.Value ) {
case ExpCompile.KeyWord.ADD:
case ExpCompile.KeyWord.Add:
node = ExpBinaryOperatorNode.Add( t, left, right );
return true;
case ExpCompile.KeyWord.SUB:
case ExpCompile.KeyWord.Sub:
node = ExpBinaryOperatorNode.Sub( t, left, right );
return true;
case ExpCompile.KeyWord.MUL:
case ExpCompile.KeyWord.Mul:
node = ExpBinaryOperatorNode.Mul( t, left, right );
return true;
case ExpCompile.KeyWord.DIV:
case ExpCompile.KeyWord.Div:
node = ExpBinaryOperatorNode.Div( t, left, right );
return true;
case ExpCompile.KeyWord.Equal:
@@ -88,7 +88,7 @@ namespace StgSharp.Script.Express
case ExpCompile.KeyWord.UnaryMinus:
node = ExpUnaryOperatorNode.UnaryMinus( t, operand );
return true;
case ExpCompile.KeyWord.NOT:
case ExpCompile.KeyWord.Not:
node = ExpUnaryOperatorNode.UnaryNot( t, operand );
return true;
default:
+1 -4
View File
@@ -169,10 +169,7 @@ namespace StgSharp.Script.Express
} else if( t.Value == ExpKeyWord.False ) {
_cache.PushOperand( new ExpBoolNode( t, false ) );
return true;
} else if( true ) {
throw new NotImplementedException();
}
return false;
} else if( ExpCompile.LetterIsKeyword( t.Value ) ) { }
}
/**/
+4 -4
View File
@@ -77,10 +77,10 @@ namespace StgSharp.Script.Express
}
/// <summary>
/// <para> Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// <para>Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// begins with part of multi-line comment will automatically remove the comment part, but
/// beginning with a full multi-line comment will not causing removing. </para> <para>(*Just
/// Like The Comment Here*) Will Not Be Removed</para>
/// beginning with a full multi-line comment will not causing removing.</para> <para> (*Just
/// Like The Comment Here*) Will Not Be Removed </para>
/// </summary>
/// <returns></returns>
public unsafe ReadOnlySpan<char> ReadLine()
@@ -267,7 +267,7 @@ namespace StgSharp.Script.Express
string str = ExpCompile.PoolString(
source[ ..( end - begin ) ] );
TokenFlag flag;
if( ReferenceEquals( str, ExpCompile.KeyWord.NOT ) ) {
if( ReferenceEquals( str, ExpCompile.KeyWord.Not ) ) {
flag = TokenFlag.Symbol_Unary;
} else {
flag = ExpCompile.LetterIsOperator( str ) ?
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9647c2c68a768a1d0a5a05cc1279d046403c4641")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6222f8c8be57d511d2ec40523717e20b87fcff9d")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/9647c2c68a768a1d0a5a05cc1279d046403c4641/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/6222f8c8be57d511d2ec40523717e20b87fcff9d/*"}}