From 29c748bcb3c7550599aef11bce2c7d62a837bbd3 Mon Sep 17 00:00:00 2001 From: kamaba233 Date: Mon, 20 May 2024 13:34:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=AF=BB=E5=8F=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SimpleLanguage.csproj | 4 +- md/data.md | 19 +- md/enum.md | 61 ++- .../FileMeta/FileMetaMemberVariable.cs | 161 +++++++- source/Compile/Parse/LexerParse.cs | 3 + source/Compile/Parse/StructParseFrame.cs | 14 +- source/Core/BaseMetaClass/TypeMetaClass.cs | 2 +- source/Core/MetaExpressConst.cs | 33 +- source/Core/MetaMemberVariable.cs | 371 ++++++++++-------- source/Core/MetaVariable.cs | 2 +- source/Define.cs | 2 + source/Project/ProjectParse.cs | 58 ++- 12 files changed, 476 insertions(+), 254 deletions(-) diff --git a/SimpleLanguage.csproj b/SimpleLanguage.csproj index df2398d..8fae483 100644 --- a/SimpleLanguage.csproj +++ b/SimpleLanguage.csproj @@ -17,10 +17,13 @@ + + + @@ -37,7 +40,6 @@ - diff --git a/md/data.md b/md/data.md index d50543c..940cdcd 100644 --- a/md/data.md +++ b/md/data.md @@ -21,6 +21,7 @@ data Book #定义数据 author= ["Lif", "Paper", "Mango"]; buy = [ + #这种的是用来说明,匿名对象的数组 { time="2022-12-12"; price=25; @@ -34,7 +35,23 @@ data Book #定义数据 price=22; sex = 1; } - ] + ], + sell = + [ + #这种的是用来说明 相同带类名的数组 + data1(){ + time = "111"; + price = 20; + }, + data1(){ + time = "222"; + price = 30; + } + ], + sell2 = + { + #这种的主要是配合的匿名类 + } } AD { diff --git a/md/enum.md b/md/enum.md index 93e77f4..7de33a3 100644 --- a/md/enum.md +++ b/md/enum.md @@ -27,64 +27,53 @@ MixColor Green = 0.0f; Blue = 0.0f; } -const enum ConstColor +enum EColor { - Red = 0xff0000; - Green = 0x00ff00; - Blue = 0x0000ff; + enum Red = 0xff0000; + enum Green = 0x00ff00; + enum Blue = 0x0000ff; - MixColor1 = MixColor(){Red=0.9f, Green = 0.1f, Blue = 0.01f }; - MixColor2 = MixColor(){Red=0.4f, Green = 0.22f, Blue = 0.7f }; -} -enum Option -{ - T Some; - None; + F090101 = MixColor(){Red=0.9f, Green = 0.1f, Blue = 0.01f }; + F040207 = MixColor(){Red=0.4f, Green = 0.22f, Blue = 0.7f }; } ProjectEnter { static Main() { - for b3 in GameState + for b3 in EColor { + int index = b3.index; + string name = b3.name; + string value = b3.ToString(); Console.Write("Book3: " + b3 ); - } - - Book3 b3 = Book3.A1; - Book3 b3_3 = Book3.A1( 20 ); - - book = Book.B1({ i2 = 20, url = "mas" }); - switch book + } + cc = EColor.Red + switch cc { - case Book.B1 b1 + case EColor.Red + { + Console.Write( "red" ); + } + case EColor.Green { - Console.Write( "bi2:" + b1.i2 ); + Console.Write("green") + } + default{ + Console.write("default") } } - Book eb = Book.B(); - if eb == Book.B + if cc == EColor.Blue { - Console.Write( eb.ToString() ); + Console.Write( cc.ToString() ); } - Option op = Option.Some("hello"); - switch op{ - case Option.Some sot: - { - Console.Write("something=" + sot.ToString() ); - } - } } } ``` ### 枚举的使用方式 - 通过enum字段字义该类为数据类型,并且,使用 {}, name = "val"等方式进行赋值,一般{}指的是匿名类 -- 可以在enum前边使用const关键字,进行锁定,不允许修改内容 -- enum使用方式,例: enum E1{ value1 = 1; value2 = 2; value3 = {a = 10} E1 e1 = E1.value1;的方式直接使用。 -- enum 如果不使用const 可以对其的值进行修改, 例 E1 e1 = E1.value1( 20 ); 如果const,则语句报错. -- enum 中支持动态类型,使用{}表示,内容必须有值,不能为空,否则报错,赋值与普通自带类型相同, E1 e1 = E1.value3( {a=20} );的方法赋值。 -- 使用T模版类型,与普通传值一样,但在switch中,有带类型判断。 +- enum使用方式,例: enum E1{ value1 = 1; value2 = 2; value3 = {a = 10}} E1 e1 = E1.value1;的方式直接使用。 - for可以对enum直接进行遍历,遍历是enum的定义名称。 - switch 可以对enum的定义名称,甚至是定义名称下的值进行匹配。 - 在enum定义名称中,自带一个index字段,表明其位置,可以在 e1.index的方法查看其值,与定义的value值是不相同的,当然也可以值index来做序列号等作用。 \ No newline at end of file diff --git a/source/Compile/FileMeta/FileMetaMemberVariable.cs b/source/Compile/FileMeta/FileMetaMemberVariable.cs index 139a6b6..f91e068 100644 --- a/source/Compile/FileMeta/FileMetaMemberVariable.cs +++ b/source/Compile/FileMeta/FileMetaMemberVariable.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Text; using SimpleLanguage.Compile.Parse; +using static SimpleLanguage.Compile.CoreFileMeta.FileMetaMemberVariable; namespace SimpleLanguage.Compile.CoreFileMeta { @@ -168,7 +169,7 @@ public enum EMemberDataType NoNameClass, Array, KeyValue, - Value, + ConstVariable, } public FileMetaClassDefine classDefineRef => m_ClassDefineRef; @@ -185,13 +186,13 @@ public enum EMemberDataType private Token m_StaticToken = null; private FileMetaBaseTerm m_Express; public List fileMetaMemberVariable => m_FileMetaMemberVariableList; - public FileMetaConstValueTerm fileMetaConstValue => m_FileMetaConstValue; + //public FileMetaConstValueTerm fileMetaConstValue => m_FileMetaConstValue; public FileMetaCallTerm fileMetaCallTermValue => m_FileMetaCallTermValue; public EMemberDataType DataType => m_MemberDataType; private List m_FileMetaMemberVariableList = new List(); private EMemberDataType m_MemberDataType = EMemberDataType.None; - private FileMetaConstValueTerm m_FileMetaConstValue = null; + //private FileMetaConstValueTerm m_FileMetaConstValue = null; private FileMetaCallTerm m_FileMetaCallTermValue = null; private List m_NodeList = null; @@ -203,29 +204,125 @@ public FileMetaMemberVariable( FileMeta fm, List list) ParseBuildMetaVariable(); } + public FileMetaMemberVariable( FileMeta fm, Node brace ) + { + //分析 {}中的内容,一般用于解析匿名函数 + m_FileMeta = fm; + m_Token = brace.token; + + + List list2 = new List(); + for ( int i = 0; i < brace.childList.Count; i++ ) + { + Node c = brace.childList[i]; + if( c.nodeType == ENodeType.LineEnd || c.nodeType == ENodeType.SemiColon ) + { + if( list2.Count == 0 ) + { + continue; + } + FileMetaMemberVariable cfm = new FileMetaMemberVariable(m_FileMeta, list2); + list2 = new List(); + + AddFileMemberVariable(cfm); + continue; + } + list2.Add(c); + } + } public FileMetaMemberVariable(FileMeta fm, Node _beforeNode, Node _afterNode, EMemberDataType dataType) { m_MemberDataType = dataType; m_FileMeta = fm; + m_Token = _beforeNode.token; + bool isParseBuild = true; if (dataType == EMemberDataType.NameClass) { - m_Token = _beforeNode.token; + } + else if( dataType == EMemberDataType.NoNameClass ) + { + isParseBuild = false; + + int type = -1; + List < Node > list = new List < Node >(); + for (int index = 0; index < _beforeNode.childList.Count; index++) + { + var curNode = _beforeNode.childList[index]; + if (curNode.nodeType == ENodeType.LineEnd + || curNode.nodeType == ENodeType.SemiColon + || curNode.nodeType == ENodeType.Comma) + { + if(list.Count == 0 ) + { + continue; + } + FileMetaMemberVariable fmmd = new FileMetaMemberVariable(m_FileMeta, list ); + + AddFileMemberVariable(fmmd); + + list = new List(); + continue; + } + if (curNode.nodeType == ENodeType.IdentifierLink) //aaa(){},aaa(){} + { + + } + if (curNode.nodeType == ENodeType.Brace) //Class1 [{},{}] + { + if (type == 2 || type == 3) + { + Console.WriteLine("Error Data数据中 []中,不支持该类型的数据" + curNode?.token?.ToLexemeAllString()); + continue; + } + + type = 1; + + FileMetaMemberVariable fmmd = new FileMetaMemberVariable(m_FileMeta, curNode, null, EMemberDataType.NoNameClass); + + AddFileMemberVariable(fmmd); + } + else if (curNode?.nodeType == ENodeType.Bracket) // [[],[]] + { + if (type == 1 || type == 2) + { + Console.WriteLine("Error Data数据中 []中,不支持该类型的数据" + curNode?.token?.ToLexemeAllString()); + continue; + } + + type = 3; + + FileMetaMemberVariable fmmd = new FileMetaMemberVariable(m_FileMeta, curNode, null, FileMetaMemberVariable.EMemberDataType.Array); + + AddFileMemberVariable(fmmd); + } + else if( curNode?.nodeType == ENodeType.IdentifierLink + || curNode?.nodeType == ENodeType.Assign + || curNode?.nodeType == ENodeType.ConstValue + ) + { + list.Add(curNode); + } + } } else if (dataType == EMemberDataType.KeyValue) { - m_Token = _beforeNode.token; - m_FileMetaConstValue = new FileMetaConstValueTerm(m_FileMeta, _afterNode.token); + m_Express = new FileMetaConstValueTerm(m_FileMeta, _afterNode.token); } else if (dataType == EMemberDataType.Array) { - m_Token = _beforeNode.token; } - else if (dataType == EMemberDataType.Value) + else if (dataType == EMemberDataType.ConstVariable ) { - m_FileMetaConstValue = new FileMetaConstValueTerm(m_FileMeta, _beforeNode.token); + m_Express = new FileMetaConstValueTerm(m_FileMeta, _beforeNode.token); } + + if(isParseBuild ) + { + ParseBuildMetaVariable(); + } + } public bool ParseBuildMetaVariable() @@ -276,10 +373,13 @@ public bool ParseBuildMetaVariable() if(afterNodeList[0].nodeType == ENodeType.Bracket ) { + m_MemberDataType = EMemberDataType.Array; ParseBracketContrent(afterNodeList[0]); } else { + m_MemberDataType = EMemberDataType.ConstVariable; + //m_FileMetaConstValue = new FileMetaConstValueTerm(m_FileMeta, _beforeNode.token); m_Express = FileMetatUtil.CreateFileMetaExpress(m_FileMeta, afterNodeList, FileMetaTermExpress.EExpressType.MemberVariable); } @@ -287,10 +387,13 @@ public bool ParseBuildMetaVariable() } public void ParseBracketContrent(Node pnode) { + int type = -1; for ( int index = 0; index < pnode.childList.Count; index++ ) { var curNode = pnode.childList[index]; - if( curNode.nodeType == ENodeType.LineEnd || curNode.nodeType == ENodeType.SemiColon ) + if( curNode.nodeType == ENodeType.LineEnd + || curNode.nodeType == ENodeType.SemiColon + || curNode.nodeType == ENodeType.Comma) { continue; } @@ -300,18 +403,42 @@ public void ParseBracketContrent(Node pnode) } if (curNode.nodeType == ENodeType.Brace) //Class1 [{},{}] { - FileMetaMemberVariable fmmd = new FileMetaMemberVariable(m_FileMeta, curNode, null, FileMetaMemberVariable.EMemberDataType.NoNameClass); + if( type == 2 || type == 3 ) + { + Console.WriteLine("Error Data数据中 []中,不支持该类型的数据" + curNode?.token?.ToLexemeAllString()); + continue; + } + + type = 1; + + FileMetaMemberVariable fmmd = new FileMetaMemberVariable(m_FileMeta, curNode, null, EMemberDataType.NoNameClass ); AddFileMemberVariable(fmmd); } else if (curNode.nodeType == ENodeType.ConstValue) // ["stringValue","Stvlue"] { - FileMetaMemberVariable fmmd = new FileMetaMemberVariable(m_FileMeta, curNode, null, FileMetaMemberVariable.EMemberDataType.Value); + if (type == 1 || type == 3) + { + Console.WriteLine("Error Data数据中 []中,不支持该类型的数据" + curNode?.token?.ToLexemeAllString()); + continue; + } + + type = 2; + + FileMetaMemberVariable fmmd = new FileMetaMemberVariable(m_FileMeta, curNode, null, FileMetaMemberVariable.EMemberDataType.ConstVariable ); AddFileMemberVariable(fmmd); } else if (curNode?.nodeType == ENodeType.Bracket) // [[],[]] { + if (type == 1 || type == 2 ) + { + Console.WriteLine("Error Data数据中 []中,不支持该类型的数据" + curNode?.token?.ToLexemeAllString()); + continue; + } + + type = 3; + FileMetaMemberVariable fmmd = new FileMetaMemberVariable(m_FileMeta, curNode, null, FileMetaMemberVariable.EMemberDataType.Array); AddFileMemberVariable(fmmd); @@ -557,7 +684,7 @@ public override string ToFormatString() EPermission permis = CompilerUtil.GetPerMissionByString(m_PermissionToken?.lexeme.ToString()); if( permis == EPermission.Null ) { - sb.Append("_public"); + sb.Append("_public "); } else { @@ -613,7 +740,7 @@ public override string ToFormatString() for (int i = 0; i < deep; i++) sb.Append(Global.tabChar); sb.Append(name + " = "); - sb.Append(m_FileMetaConstValue.ToFormatString()); + sb.Append(m_Express.ToFormatString()); sb.Append(";"); } else if (m_MemberDataType == EMemberDataType.Array) @@ -632,9 +759,11 @@ public override string ToFormatString() sb.Append("]"); sb.Append(";"); } - else if (m_MemberDataType == EMemberDataType.Value) + else if (m_MemberDataType == EMemberDataType.ConstVariable ) { - sb.Append(m_FileMetaConstValue.ToFormatString()); + sb.Append(m_ClassDefineRef?.ToFormatString()); + sb.Append( name + " = "); + sb.Append(m_Express?.ToFormatString()); } diff --git a/source/Compile/Parse/LexerParse.cs b/source/Compile/Parse/LexerParse.cs index 0220b96..ba0dd1c 100644 --- a/source/Compile/Parse/LexerParse.cs +++ b/source/Compile/Parse/LexerParse.cs @@ -1366,6 +1366,9 @@ void ReadIdentifier() case "label": tokenType = ETokenType.Label; break; + case "let": + tokenType = ETokenType.Let; + break; case "global": tokenType = ETokenType.Global; break; diff --git a/source/Compile/Parse/StructParseFrame.cs b/source/Compile/Parse/StructParseFrame.cs index 1d7f4d6..4b81049 100644 --- a/source/Compile/Parse/StructParseFrame.cs +++ b/source/Compile/Parse/StructParseFrame.cs @@ -902,7 +902,7 @@ public void ParseNamespace( Node pnode ) } } - + /* public void ParseParContrent(Node pnode) { // [] ߵ @@ -923,7 +923,7 @@ public void ParseParContrent(Node pnode) } else if (curNode.nodeType == ENodeType.ConstValue) // ["stringValue","Stvlue"] { - FileMetaMemberVariable fmmd = new FileMetaMemberVariable(m_FileMeta, curNode, null, FileMetaMemberVariable.EMemberDataType.Value); + //FileMetaMemberVariable fmmd = new FileMetaMemberVariable(m_FileMeta, curNode, null, FileMetaMemberVariable.EMemberDataType.Value); //currentNodeInfo.codeData.AddFileMemberData(fmmd); @@ -967,7 +967,6 @@ public void ParseParContrent(Node pnode) //ParseDataNode(bracketNode); ParseCommon(bracketNode); } - void AddFileMetaMemberVariable( Node pnode, List nodeList ) { FileMetaMemberVariable cpv = new FileMetaMemberVariable(m_FileMeta, nodeList); @@ -976,6 +975,7 @@ void AddFileMetaMemberVariable( Node pnode, List nodeList ) ParseCommon(pnode); } + */ void AddFileMetaFunctionVariable(Node pnode, Node blockNode, List nodeList ) { FileMetaMemberFunction cpf = new FileMetaMemberFunction(m_FileMeta, nodeList); @@ -985,8 +985,6 @@ void AddFileMetaFunctionVariable(Node pnode, Node blockNode, List nodeList ParseSyntax(blockNode); m_CurrentNodeInfoStack.Pop(); - - ParseCommon(pnode); } void AddFileMetaClasss(Node pnode, Node blockNode, List nodeList) { @@ -1004,10 +1002,8 @@ void AddFileMetaClasss(Node pnode, Node blockNode, List nodeList) } m_CurrentNodeInfoStack.Pop(); - - ParseCommon(pnode); } - public void ParseClass(Node pnode ) + public void ParseClass( Node pnode ) { Node braceNode = pnode.blockNode; @@ -1043,6 +1039,7 @@ public void ParseClass(Node pnode ) nodeList.Add(curNode); AddFileMetaClasss(pnode, curNode.blockNode, nodeList); + nodeList.Clear(); } else if (nextNode?.nodeType == ENodeType.Par) //Class1() { @@ -1059,6 +1056,7 @@ public void ParseClass(Node pnode ) curNode.blockNode = next2Node; nodeList.Add(curNode); AddFileMetaFunctionVariable(pnode, curNode.blockNode, nodeList); + nodeList.Clear(); } } else if (nextNode?.nodeType == ENodeType.Angle) //Class1<> diff --git a/source/Core/BaseMetaClass/TypeMetaClass.cs b/source/Core/BaseMetaClass/TypeMetaClass.cs index fa271c8..7027219 100644 --- a/source/Core/BaseMetaClass/TypeMetaClass.cs +++ b/source/Core/BaseMetaClass/TypeMetaClass.cs @@ -21,7 +21,7 @@ public TypeMetaClass() : base(DefaultObject.Type.ToString()) } public static MetaClass CreateMetaClass() { - MetaClass mc = new ByteMetaClass(); + MetaClass mc = new TypeMetaClass(); ClassManager.instance.AddMetaClass(mc, ModuleManager.instance.coreModule); return mc; } diff --git a/source/Core/MetaExpressConst.cs b/source/Core/MetaExpressConst.cs index 0dc9562..fbbc461 100644 --- a/source/Core/MetaExpressConst.cs +++ b/source/Core/MetaExpressConst.cs @@ -81,12 +81,22 @@ public class MetaConstExpressNode : MetaExpressNode private FileMetaConstValueTerm m_FileMetaConstValueTerm = null; public object value { get; set; } = null; + + public MetaClass m_MetaClass = null; public MetaConstExpressNode(FileMetaConstValueTerm fmct ) { m_FileMetaConstValueTerm = fmct; Parse1(fmct.token.GetEType(), fmct.token.lexeme); } + public MetaConstExpressNode( MetaDynamicClass mdc ) + { + eType = EType.Class; + + m_MetaClass = mdc; + + value = mdc; + } public MetaConstExpressNode(EType etype, object val) { Parse1(etype, val); @@ -119,19 +129,30 @@ public override MetaType GetReturnMetaDefineType() { m_MetaDefineType = new MetaType(CoreMetaClassManager.objectMetaClass); } + if (eType == EType.Class ) + { + m_MetaDefineType = new MetaType(m_MetaClass); + } else { MetaClass mc = CoreMetaClassManager.GetMetaClassByEType(eType); - MetaInputTemplateCollection mitc = new MetaInputTemplateCollection(); - if (eType == EType.Array) + + if( mc == null ) { - MetaType mitp = new MetaType(CoreMetaClassManager.int32MetaClass); - mitc.AddMetaTemplateParamsList(mitp); - m_MetaDefineType = new MetaType(mc, mitc); } else { - m_MetaDefineType = new MetaType(mc); + MetaInputTemplateCollection mitc = new MetaInputTemplateCollection(); + if (eType == EType.Array) + { + MetaType mitp = new MetaType(CoreMetaClassManager.int32MetaClass); + mitc.AddMetaTemplateParamsList(mitp); + m_MetaDefineType = new MetaType(mc, mitc); + } + else + { + m_MetaDefineType = new MetaType(mc); + } } } return m_MetaDefineType; diff --git a/source/Core/MetaMemberVariable.cs b/source/Core/MetaMemberVariable.cs index efab188..04847e2 100644 --- a/source/Core/MetaMemberVariable.cs +++ b/source/Core/MetaMemberVariable.cs @@ -10,9 +10,11 @@ using SimpleLanguage.Core.SelfMeta; using System; using System.Collections.Generic; +using System.Net.Mime; using System.Reflection; using System.Text; using System.Xml.Linq; +using static SimpleLanguage.Core.MetaBraceOrBracketStatementsContent; namespace SimpleLanguage.Core { @@ -21,6 +23,7 @@ public enum EMemberDataType None, ConstValue, MemberData, + MemberArray, } //public partial class MetaMemberData : MetaVariable //{ @@ -365,12 +368,8 @@ public partial class MetaMemberVariable : MetaVariable, IComparable m_Express as MetaConstExpressNode; - //public Dictionary metaMemberDataDict => m_MetaMemberDataDict; - //private FileMetaMemberData m_FileMetaMemeberData = null; private EMemberDataType m_MemberDataType = EMemberDataType.None; - //private int m_Index = -1; - private bool m_End = false; //protected Dictionary m_MetaMemberDataDict = new Dictionary(); @@ -400,6 +399,165 @@ public MetaMemberVariable( MetaClass ownerMc, string _name, MetaTemplate mt ) SetOwnerMetaClass(ownerMc); } + //public MetaMemberVariable(MetaMemberVariable parentNode, FileMetaMemberVariable fmmv, int _index) + //{ + // m_Name = m_FileMetaMemeberVariable.name; + // m_FromType = EFromType.Manual; + // m_Index = _index; + // m_DefineMetaType = new MetaType(CoreMetaClassManager.objectMetaClass); + // SetOwnerMetaClass(parentNode.ownerMetaClass); + // isConst = parentNode.isConst; + + // m_FileMetaMemeberVariable = fmmv; + // m_IsEnumValue = false; + // m_Name = fmmv.name; + // m_Index = _index; + // fmmv.SetMetaMemberVariable(this); + // m_FromType = EFromType.Code; + // m_DefineMetaType = new MetaType(CoreMetaClassManager.objectMetaClass); + // isStatic = m_FileMetaMemeberVariable?.staticToken != null; + // if (isStatic) + // { + // Console.WriteLine("Error ENum中,不允许有静态关键字,而是全部是静态关键字!!"); + // } + // if (m_FileMetaMemeberVariable.permissionToken != null) + // { + // permission = CompilerUtil.GetPerMissionByString(m_FileMetaMemeberVariable.permissionToken?.lexeme.ToString()); + // } + + // //SetOwnerMetaClass(mc); + + // Parse(); + //} + //public MetaMemberData GetMemberDataByName(string name) + //{ + // if (m_MetaMemberDataDict.ContainsKey(name)) + // { + // return m_MetaMemberDataDict[name]; + // } + // return null; + //} + //public bool AddMetaMemberData(MetaMemberData mmd) + //{ + // if (m_MetaMemberDataDict.ContainsKey(mmd.name)) + // { + // return false; + // } + // m_MetaMemberDataDict.Add(mmd.name, mmd); + // return true; + //} + //public override void Parse() + //{ + // if (m_FileMetaMemeberData != null) + // { + // switch (m_FileMetaMemeberData.DataType) + // { + // case FileMetaMemberData.EMemberDataType.NameClass: // data Data{ childData{} } + // { + // m_Name = m_FileMetaMemeberData.name; + // m_MemberDataType = EMemberDataType.MemberData; + // } + // break; + // case FileMetaMemberData.EMemberDataType.Array: // data Data{ childArray[ ] } + // { + // m_Name = m_FileMetaMemeberData.name; + // m_MemberDataType = EMemberDataType.MemberData; + // } + // break; + // case FileMetaMemberData.EMemberDataType.NoNameClass: // data Data{ childArray{ {}, {} } } + // { + // m_Name = m_Index.ToString(); + // m_MemberDataType = EMemberDataType.MemberData; + // } + // break; + // case FileMetaMemberData.EMemberDataType.KeyValue: // data Data{ childArray{ a = 1; b = 2 } } + // { + // m_Name = m_FileMetaMemeberData.name; + // m_MemberDataType = EMemberDataType.ConstValue; + // m_Express = new MetaConstExpressNode(m_FileMetaMemeberData.fileMetaConstValue); + // } + // break; + // case FileMetaMemberData.EMemberDataType.Value: + // { + // m_Name = m_Index.ToString(); + // m_MemberDataType = EMemberDataType.ConstValue; + // m_Express = new MetaConstExpressNode(m_FileMetaMemeberData.fileMetaConstValue); + // } + // break; + // case FileMetaMemberData.EMemberDataType.Data: + // { + // m_Name = m_FileMetaMemeberData.name; + // m_MemberDataType = EMemberDataType.MemberData; + // m_Express = new MetaCallExpressNode(m_FileMetaMemeberData.fileMetaCallTermValue.callLink, null, null); + // m_Express.Parse(new AllowUseConst()); + // m_DefineMetaType = m_Express.GetReturnMetaDefineType(); + // if (m_DefineMetaType == null) + // { + // Console.WriteLine("Error 在生成Data时,没有找到." + m_FileMetaMemeberData.fileMetaCallTermValue.ToTokenString()); + // return; + // } + // var mc = m_Express.GetReturnMetaClass(); + // MetaData refMD = mc as MetaData; + // if (refMD != null) + // { + // CopyByMetaData(refMD); + // } + // else + // { + // Console.WriteLine("Error 在生成Data时,发现不是Data数据!!"); + // } + // } + // break; + // } + // } + //} + //public MetaMemberData Copy() + //{ + // var newMMD = new MetaMemberData(m_OwnerMetaClass as MetaData); + // newMMD.m_Name = m_Name; + // newMMD.m_MemberDataType = m_MemberDataType; + // if (m_MemberDataType == EMemberDataType.MemberData) + // { + // foreach (var v in m_MetaMemberDataDict) + // { + // newMMD.AddMetaMemberData(v.Value.Copy()); + // } + // } + // else if (m_MemberDataType == EMemberDataType.ConstValue) + // { + // newMMD.m_Express = m_Express; + // } + // return newMMD; + //} + //public void CopyByMetaData(MetaData md) + //{ + // MetaData curMD = m_OwnerMetaClass as MetaData; + // foreach (var v in md.metaMemberDataDict) + // { + // if (v.Value.IsIncludeMetaData(curMD)) + // { + // Console.WriteLine("Error 当前有循环引用数量现象,请查正!!" + md.allName); + // continue; + // } + // var newMMD = v.Value.Copy(); + // this.AddMetaMemberData(newMMD); + // } + //} + //public bool IsIncludeMetaData(MetaData md) + //{ + // if (md == null) return false; + + // MetaData belongMD = m_OwnerMetaClass as MetaData; + // if (belongMD != null) + // { + // if (belongMD == md) + // { + // return true; + // } + // } + + // return false; + //} public MetaMemberVariable(MetaClass mc, string _name, MetaClass _defineTypeClass ) { m_Name = _name; @@ -453,6 +611,10 @@ public override void Parse() { m_DefineMetaType = new MetaType(m_FileMetaMemeberVariable.classDefineRef, ownerMetaClass ); } + else + { + + } } } public void UpdateGenMemberVariable() @@ -523,7 +685,14 @@ public virtual void CalcParseLevel() } public void CreateExpress() { - m_Express = CreateExpressNodeInClassMetaVariable(); + if( m_FileMetaMemeberVariable.DataType == FileMetaMemberVariable.EMemberDataType.Array ) + { + ParseChildMemberData(); + } + else + { + m_Express = CreateExpressNodeInClassMetaVariable(); + } } public void CalcReturnType() { @@ -669,7 +838,7 @@ void CalcDefineClassType() } public MetaExpressNode SimulateExpressRun(MetaExpressNode node) { - MetaExpressNode newnode = null; + MetaExpressNode newnode = node; if ( node is MetaCallExpressNode ) { MetaCallExpressNode mcen = node as MetaCallExpressNode; @@ -904,162 +1073,56 @@ public int GetInt(string name, int defaultValue = 0) } return defaultValue; } - public MetaMemberVariable(MetaMemberVariable parentNode, FileMetaMemberVariable fmmd, int _index, bool isEnd = false) - { - m_Index = _index; - m_End = isEnd; - m_FileMetaMemeberVariable = fmmd; - m_DefineMetaType = new MetaType(CoreMetaClassManager.objectMetaClass); - SetOwnerMetaClass(parentNode.ownerMetaClass); - isConst = parentNode.isConst; - - Parse(); - } - //public MetaMemberData GetMemberDataByName(string name) - //{ - // if (m_MetaMemberDataDict.ContainsKey(name)) - // { - // return m_MetaMemberDataDict[name]; - // } - // return null; - //} - //public bool AddMetaMemberData(MetaMemberData mmd) - //{ - // if (m_MetaMemberDataDict.ContainsKey(mmd.name)) - // { - // return false; - // } - // m_MetaMemberDataDict.Add(mmd.name, mmd); - // return true; - //} - //public override void Parse() - //{ - // if (m_FileMetaMemeberData != null) - // { - // switch (m_FileMetaMemeberData.DataType) - // { - // case FileMetaMemberData.EMemberDataType.NameClass: // data Data{ childData{} } - // { - // m_Name = m_FileMetaMemeberData.name; - // m_MemberDataType = EMemberDataType.MemberData; - // } - // break; - // case FileMetaMemberData.EMemberDataType.Array: // data Data{ childArray[ ] } - // { - // m_Name = m_FileMetaMemeberData.name; - // m_MemberDataType = EMemberDataType.MemberData; - // } - // break; - // case FileMetaMemberData.EMemberDataType.NoNameClass: // data Data{ childArray{ {}, {} } } - // { - // m_Name = m_Index.ToString(); - // m_MemberDataType = EMemberDataType.MemberData; - // } - // break; - // case FileMetaMemberData.EMemberDataType.KeyValue: // data Data{ childArray{ a = 1; b = 2 } } - // { - // m_Name = m_FileMetaMemeberData.name; - // m_MemberDataType = EMemberDataType.ConstValue; - // m_Express = new MetaConstExpressNode(m_FileMetaMemeberData.fileMetaConstValue); - // } - // break; - // case FileMetaMemberData.EMemberDataType.Value: - // { - // m_Name = m_Index.ToString(); - // m_MemberDataType = EMemberDataType.ConstValue; - // m_Express = new MetaConstExpressNode(m_FileMetaMemeberData.fileMetaConstValue); - // } - // break; - // case FileMetaMemberData.EMemberDataType.Data: - // { - // m_Name = m_FileMetaMemeberData.name; - // m_MemberDataType = EMemberDataType.MemberData; - // m_Express = new MetaCallExpressNode(m_FileMetaMemeberData.fileMetaCallTermValue.callLink, null, null); - // m_Express.Parse(new AllowUseConst()); - // m_DefineMetaType = m_Express.GetReturnMetaDefineType(); - // if (m_DefineMetaType == null) - // { - // Console.WriteLine("Error 在生成Data时,没有找到." + m_FileMetaMemeberData.fileMetaCallTermValue.ToTokenString()); - // return; - // } - // var mc = m_Express.GetReturnMetaClass(); - // MetaData refMD = mc as MetaData; - // if (refMD != null) - // { - // CopyByMetaData(refMD); - // } - // else - // { - // Console.WriteLine("Error 在生成Data时,发现不是Data数据!!"); - // } - // } - // break; - // } - // } - //} - //public MetaMemberData Copy() - //{ - // var newMMD = new MetaMemberData(m_OwnerMetaClass as MetaData); - // newMMD.m_Name = m_Name; - // newMMD.m_MemberDataType = m_MemberDataType; - // if (m_MemberDataType == EMemberDataType.MemberData) - // { - // foreach (var v in m_MetaMemberDataDict) - // { - // newMMD.AddMetaMemberData(v.Value.Copy()); - // } - // } - // else if (m_MemberDataType == EMemberDataType.ConstValue) - // { - // newMMD.m_Express = m_Express; - // } - // return newMMD; - //} - //public void CopyByMetaData(MetaData md) - //{ - // MetaData curMD = m_OwnerMetaClass as MetaData; - // foreach (var v in md.metaMemberDataDict) - // { - // if (v.Value.IsIncludeMetaData(curMD)) - // { - // Console.WriteLine("Error 当前有循环引用数量现象,请查正!!" + md.allName); - // continue; - // } - // var newMMD = v.Value.Copy(); - // this.AddMetaMemberData(newMMD); - // } - //} - //public bool IsIncludeMetaData(MetaData md) - //{ - // if (md == null) return false; - - // MetaData belongMD = m_OwnerMetaClass as MetaData; - // if (belongMD != null) - // { - // if (belongMD == md) - // { - // return true; - // } - // } - - // return false; - //} public void ParseChildMemberData() { int count = m_FileMetaMemeberVariable.fileMetaMemberVariable.Count; - for (int i = 0; i < count; i++) - { - MetaMemberVariable mmd = new MetaMemberVariable(this, m_FileMetaMemeberVariable.fileMetaMemberVariable[i], i, i == count - 1); - if (AddMetaVariable(mmd)) + if(m_FileMetaMemeberVariable.DataType == FileMetaMemberVariable.EMemberDataType.Array ) + { + for (int i = 0; i < count; i++) { - this.AddMetaBase(mmd.name, mmd); + var fmmv = m_FileMetaMemeberVariable.fileMetaMemberVariable[i]; + + MetaDynamicClass mdc = new MetaDynamicClass(fmmv.GetHashCode().ToString()); + + for( int j = 0; j < fmmv.fileMetaMemberVariable.Count; j++ ) + { + MetaMemberVariable mmv = new MetaMemberVariable(mdc, fmmv.fileMetaMemberVariable[j] as FileMetaMemberVariable, false); - mmd.ParseChildMemberData(); + mmv.Parse(); + mmv.ParseChildMemberData(); + mmv.CalcDefineClassType(); + + mdc.AddMetaMemberVariable(mmv); + } + m_Express = new MetaConstExpressNode( mdc ); } - else + } + else if( m_FileMetaMemeberVariable.DataType == FileMetaMemberVariable.EMemberDataType.ConstVariable ) + { + CreateExpress(); + } + else if( m_FileMetaMemeberVariable.DataType == FileMetaMemberVariable.EMemberDataType.KeyValue ) + { + + } + else + { + for (int i = 0; i < count; i++) { - Console.WriteLine("Error 命名有重名!!"); + var fmmv = m_FileMetaMemeberVariable.fileMetaMemberVariable[i]; + + MetaDynamicClass mdc = new MetaDynamicClass(i.GetHashCode().ToString()); + + MetaMemberVariable mmd = new MetaMemberVariable(mdc, fmmv, false); + if (AddMetaVariable(mmd)) + { + this.AddMetaBase(mmd.name, mmd); + } + else + { + Console.WriteLine("Error 命名有重名!!"); + } } } } diff --git a/source/Core/MetaVariable.cs b/source/Core/MetaVariable.cs index 6151aab..11df261 100644 --- a/source/Core/MetaVariable.cs +++ b/source/Core/MetaVariable.cs @@ -23,7 +23,7 @@ public class MetaVariable : MetaBase public bool isGlobal { get; set; } = false; public bool isArray { - get { return m_DefineMetaType.isArray; } + get { return m_DefineMetaType != null ? m_DefineMetaType.isArray : false ; } } public MetaType metaDefineType => m_DefineMetaType; diff --git a/source/Define.cs b/source/Define.cs index 8d93966..b7241e9 100644 --- a/source/Define.cs +++ b/source/Define.cs @@ -205,6 +205,8 @@ public enum ETokenType Get, /// set Set, + /// let + Let, /// new //New, /// partial diff --git a/source/Project/ProjectParse.cs b/source/Project/ProjectParse.cs index da5e067..fc395ea 100644 --- a/source/Project/ProjectParse.cs +++ b/source/Project/ProjectParse.cs @@ -34,21 +34,21 @@ public class CompileFileDataUnit public ECompileState compileState { get; set; } public int priority { get; set; } - public CompileFileDataUnit(MetaMemberVariable mmv) + public CompileFileDataUnit(MetaDynamicClass mdc) { - //var findPath = mmd.GetString("path", true); - //if (findPath == null) - //{ - // Console.Write("ProjectConfig еCompileFileDatapathڵ!!"); - // return; - //} - //path = findPath; - //var findOption = mmd.GetFileMetaMemberDataByName("option"); - //var findGroup = mmd.GetFileMetaMemberDataByName("group"); + var findPath = mdc.GetMetaMemberVariableByName("path"); + if (findPath == null) + { + Console.Write("ProjectConfig еCompileFileDatapathڵ!!"); + return; + } + path = findPath.constExpressNode.ToTokenString(); + var findOption = mdc.GetMetaMemberVariableByName("option"); + var findGroup = mdc.GetMetaMemberVariableByName("group"); //group = findGroup?.fileMetaConstValue?.token?.lexeme.ToString(); - //var findTag = fmmd.GetFileMetaMemberDataByName("tag"); + var findTag = mdc.GetMetaMemberVariableByName("tag"); //tag = findTag?.fileMetaConstValue?.token?.lexeme.ToString(); - //var findIgnore = fmmd.GetFileMetaMemberDataByName("ignore"); + var findIgnore = mdc.GetMetaMemberVariableByName("ignore"); //object obj = findIgnore?.fileMetaConstValue?.token?.lexeme; //if (obj != null && (bool)obj == true) @@ -57,20 +57,20 @@ public CompileFileDataUnit(MetaMemberVariable mmv) //} //else //{ - // compileState = ECompileState.Default; + compileState = ECompileState.Default; //} } } public List compileFileDataUnitList = new List(); - //public void Parse(MetaMemberData mmd) - //{ - // foreach (var v in mmd.metaMemberDataDict) - // { - // compileFileDataUnitList.Add(new CompileFileDataUnit(v.Value)); - // } - //} + public void Parse(MetaMemberVariable mmd) + { + foreach (var v in mmd.childrenNameNodeDict ) + { + compileFileDataUnitList.Add(new CompileFileDataUnit(v.Value as MetaDynamicClass)); + } + } } public class CompileOptionData { @@ -356,7 +356,7 @@ public void Parse(MetaMemberVariable mmd) return; } } - public class MemberSetData + public class MemorySetData { public void Parse(MetaMemberVariable mmd) { @@ -396,7 +396,7 @@ public ProjectData(string _name, bool isConst) : base(_name ) public ExportDllData exportDllData { get; set; } = new ExportDllData(); public CompileModuleData compileModuleData { get; set; } = new CompileModuleData(); public ImportModuleData importModuleData { get; set; } = new ImportModuleData(); - public MemberSetData memberSetData { get; set; } = new MemberSetData(); + public MemorySetData memorySetData { get; set; } = new MemorySetData(); public void ParseFileMetaDataMemeberData(FileMetaClass fmc) { @@ -420,16 +420,14 @@ public void ParseFileMetaDataMemeberData(FileMetaClass fmc) { mmd.SetName(mmd.name + "__repeat__"); } + //mmd.metaDefineType = AddMetaMemberVariable(mmd); - mmd.ParseChildMemberData(); + mmd.CreateExpress(); + mmd.CalcReturnType(); ParseBlockNode(mmd); } - if (fmc.memberVariableList.Count > 0 || fmc.memberFunctionList.Count > 0) - { - Console.WriteLine("Error DataвVariable Function!!"); - } } public void ParseBlockNode(MetaMemberVariable mmd) @@ -455,7 +453,7 @@ public void ParseBlockNode(MetaMemberVariable mmd) break; case "compileFileList": { - //compileFileData.Parse(mmd); + compileFileData.Parse(mmd); } break; case "compileOption": @@ -498,9 +496,9 @@ public void ParseBlockNode(MetaMemberVariable mmd) exportDllData.Parse(mmd); } break; - case "memberSet": + case "memorySet": { - memberSetData.Parse(mmd); + memorySetData.Parse(mmd); } break; }