diff --git a/bin/Debug/netcoreapp3.1/SimpleLanguage.dll b/bin/Debug/netcoreapp3.1/SimpleLanguage.dll index 54dcbe0..f9911db 100644 Binary files a/bin/Debug/netcoreapp3.1/SimpleLanguage.dll and b/bin/Debug/netcoreapp3.1/SimpleLanguage.dll differ diff --git a/bin/Debug/netcoreapp3.1/SimpleLanguage.exe b/bin/Debug/netcoreapp3.1/SimpleLanguage.exe index 81e1926..849e246 100644 Binary files a/bin/Debug/netcoreapp3.1/SimpleLanguage.exe and b/bin/Debug/netcoreapp3.1/SimpleLanguage.exe differ diff --git a/bin/Debug/netcoreapp3.1/SimpleLanguage.pdb b/bin/Debug/netcoreapp3.1/SimpleLanguage.pdb index b3b400e..d03fc58 100644 Binary files a/bin/Debug/netcoreapp3.1/SimpleLanguage.pdb and b/bin/Debug/netcoreapp3.1/SimpleLanguage.pdb differ diff --git a/source/Compile/FileMeta/FileMetaMemberMethod.cs b/source/Compile/FileMeta/FileMetaMemberMethod.cs index f4b74c4..a260c77 100644 --- a/source/Compile/FileMeta/FileMetaMemberMethod.cs +++ b/source/Compile/FileMeta/FileMetaMemberMethod.cs @@ -279,6 +279,10 @@ public bool ParseFunction(List nodeList) Console.WriteLine("Error 解析位置 Token: " + m_Token?.ToLexemeAllString() ); return false; } + if( isError ) + { + Console.WriteLine("ParseFunction 解析函数"); + } m_VirtualOverrideToken = virtualToken; m_PermissionToken = permissionToken; m_StaticToken = staticToken; diff --git a/source/Core/MetaCommon.cs b/source/Core/MetaCommon.cs index 779f4b4..44e3481 100644 --- a/source/Core/MetaCommon.cs +++ b/source/Core/MetaCommon.cs @@ -1093,9 +1093,9 @@ public MetaFunctionCall GetMetaFunctionCall() return mfc; } } - else if( m_CallNodeType == ECallNodeType.NewClass ) - { - } + //else if( m_CallNodeType == ECallNodeType.NewClass ) + //{ + //} return null; } public MetaType GetMetaDefineType() @@ -1493,7 +1493,7 @@ private void CreateCallLinkNode() Console.WriteLine("Error 连接串没有找到合适的节点 360!!!"); } } - public int GetCodeFileLine() { return 0; } + public Token GetToken() { return null; } public bool Parse( AllowUseConst _useConst ) { allowUseConst = new AllowUseConst(_useConst); diff --git a/source/Core/MetaExpressBase.cs b/source/Core/MetaExpressBase.cs index b906bef..1f8dde8 100644 --- a/source/Core/MetaExpressBase.cs +++ b/source/Core/MetaExpressBase.cs @@ -52,8 +52,7 @@ public virtual int opLevel protected MetaClass m_OwnerMetaClass = null; protected MetaBlockStatements m_OwnerMetaBlockStatements = null; protected MetaType m_MetaDefineType = null; - public virtual int GetCodeFileLine() { return 0; } - public virtual string GetFilePath() { return ""; } + public virtual Token GetToken() { return null; } public virtual int CalcParseLevel(int level) { return level; } public virtual void CalcReturnType() { } public virtual void Parse(AllowUseConst auc) { } diff --git a/source/Core/MetaExpressCalllink.cs b/source/Core/MetaExpressCalllink.cs index 9998071..85aba4f 100644 --- a/source/Core/MetaExpressCalllink.cs +++ b/source/Core/MetaExpressCalllink.cs @@ -36,7 +36,7 @@ public override void Parse( AllowUseConst auc ) m_MetaCallLink.Parse( auc ); } } - public override int GetCodeFileLine() { if (m_MetaCallLink != null) { return m_MetaCallLink.GetCodeFileLine(); } else return 0; } + public override Token GetToken() { return m_MetaCallLink.GetToken(); } public override int CalcParseLevel(int level) { if (m_MetaCallLink != null) diff --git a/source/Core/MetaExpressConst.cs b/source/Core/MetaExpressConst.cs index 386544a..7a2bb43 100644 --- a/source/Core/MetaExpressConst.cs +++ b/source/Core/MetaExpressConst.cs @@ -114,7 +114,7 @@ public override MetaType GetReturnMetaDefineType() { return m_MetaDefineType; } - MetaType mdt = null; + //MetaType mdt = null; MetaClass mc = CoreMetaClassManager.GetMetaClassByEType(eType); MetaInputTemplateCollection mitc = new MetaInputTemplateCollection(); if( eType == EType.Array ) @@ -129,7 +129,7 @@ public override MetaType GetReturnMetaDefineType() } return m_MetaDefineType; } - public override int GetCodeFileLine() { if (m_FileMetaConstValueTerm?.token != null) { return m_FileMetaConstValueTerm.token.sourceBeginLine; } else return 0; } + public override Token GetToken() { return m_FileMetaConstValueTerm?.token; } public void ComputeAddRight(MetaConstExpressNode right) { switch (right.eType) diff --git a/source/Core/MetaExpressNewObject.cs b/source/Core/MetaExpressNewObject.cs index f8acd8f..3eb811c 100644 --- a/source/Core/MetaExpressNewObject.cs +++ b/source/Core/MetaExpressNewObject.cs @@ -703,13 +703,13 @@ private void Init() } } } - public override int GetCodeFileLine() + public override Token GetToken() { if(m_FileMetaConstValueTerm != null) { - return m_FileMetaConstValueTerm.token.sourceBeginLine; + return m_FileMetaConstValueTerm.token; } - return base.GetCodeFileLine(); + return base.GetToken(); } public override void Parse(AllowUseConst auc) { diff --git a/source/Core/MetaExpressOperator.cs b/source/Core/MetaExpressOperator.cs index d914ce8..041353d 100644 --- a/source/Core/MetaExpressOperator.cs +++ b/source/Core/MetaExpressOperator.cs @@ -306,13 +306,13 @@ public void SetRight(MetaExpressNode _right) { m_Right = _right; } - public override int GetCodeFileLine() + public override Token GetToken() { if (m_FileMetaBaseTerm != null) { - return m_FileMetaBaseTerm.token.sourceBeginLine; + return m_FileMetaBaseTerm.token; } - return base.GetCodeFileLine(); + return base.GetToken(); } public override void Parse(AllowUseConst auc) { diff --git a/source/Core/MetaMemberFunction.cs b/source/Core/MetaMemberFunction.cs index 50cbfee..226c0fc 100644 --- a/source/Core/MetaMemberFunction.cs +++ b/source/Core/MetaMemberFunction.cs @@ -226,13 +226,13 @@ public override void SetDeep(int deep) m_Deep = deep; m_MetaBlockStatements?.SetDeep(deep); } - public override int GetCodeFileLine() + public override Token GetToken() { if( m_FileMetaMemberFunction?.finalToken != null ) { - return m_FileMetaMemberFunction.finalToken.sourceBeginLine; + return m_FileMetaMemberFunction.finalToken; } - return base.GetCodeFileLine(); + return base.GetToken(); } public bool IsEqualWithMMFByNameAndParam( MetaMemberFunction mmf ) { diff --git a/source/Core/MetaParam.cs b/source/Core/MetaParam.cs index c73749f..4a008d1 100644 --- a/source/Core/MetaParam.cs +++ b/source/Core/MetaParam.cs @@ -268,13 +268,13 @@ public MetaDefineParam( string _name, MetaClass ownerMC, MetaBlockStatements mbs m_MetaVariable.SetFromMetaDefineParamCreate(this); m_MetaVariable.isArgument = true; } - public int GetCodeFileLine() + public Compile.Token GetToken() { if(m_FileMetaParamter != null ) { - return m_FileMetaParamter.token.sourceBeginLine; + return m_FileMetaParamter.token; } - return 0; + return null; } public override void Parse() { @@ -742,6 +742,10 @@ public MetaClass GetMaxLevelMetaClassType() } } } + if(isAllSame ) + { + Console.WriteLine("全都相似"); + } return mc; } public override string ToFormatString() diff --git a/source/Core/MetaVariable.cs b/source/Core/MetaVariable.cs index 3a671ef..21239a0 100644 --- a/source/Core/MetaVariable.cs +++ b/source/Core/MetaVariable.cs @@ -6,6 +6,7 @@ // Description: all variable 's define, if it's iterator style then use IteratorMetaVariable, other custom same style! //**************************************************************************** +using SimpleLanguage.Compile; using SimpleLanguage.Core.SelfMeta; using SimpleLanguage.Core.Statements; using System; @@ -129,21 +130,21 @@ public virtual string ToStatementString() { return ""; } - public virtual int GetCodeFileLine() + public virtual Token GetToken() { if(m_FromMetaNewStatementsCreate != null ) { - return m_FromMetaNewStatementsCreate.GetCodeFileLine(); + return m_FromMetaNewStatementsCreate.GetToken(); } if( m_FromMetaDefineParamCreate != null ) { - return m_FromMetaDefineParamCreate.GetCodeFileLine(); + return m_FromMetaDefineParamCreate.GetToken(); } if(m_FromExpressNodeCreate != null ) { - return m_FromExpressNodeCreate.GetCodeFileLine(); + return m_FromExpressNodeCreate.GetToken(); } - return 0; + return null; } public override string ToFormatString() { diff --git a/source/Core/Statements/MetaNewStatements.cs b/source/Core/Statements/MetaNewStatements.cs index 58578f8..85b0dc6 100644 --- a/source/Core/Statements/MetaNewStatements.cs +++ b/source/Core/Statements/MetaNewStatements.cs @@ -54,21 +54,21 @@ public MetaNewStatements( MetaBlockStatements mbs, FileMetaCallSyntax callSyntax m_OwnerMetaBlockStatements.AddOnlyNameMetaVariable(m_Name); Parse(); } - public int GetCodeFileLine() + public Compile.Token GetToken() { if (m_FileMetaDefineVariableSyntax != null) { - return m_FileMetaDefineVariableSyntax.token.sourceBeginLine; + return m_FileMetaDefineVariableSyntax.token; } if (m_FileMetaOpAssignSyntax != null) { - return m_FileMetaOpAssignSyntax.assignToken.sourceBeginLine; + return m_FileMetaOpAssignSyntax.assignToken; } if (m_FileMetaCallSyntax != null) { - return m_FileMetaCallSyntax.token.sourceBeginLine; + return m_FileMetaCallSyntax.token; } - return 0; + return null; } private void Parse() { diff --git a/source/IR/IRBase.cs b/source/IR/IRBase.cs index 6a679a0..60d7dfd 100644 --- a/source/IR/IRBase.cs +++ b/source/IR/IRBase.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Xml.Linq; namespace SimpleLanguage.IR { @@ -29,18 +30,33 @@ protected IRBase( IRMethod irMethod ) } public void AddIRData( IRData irData ) { + if( irData == null ) + { + return; + } m_IRDataList.Add(irData); } - public virtual void SetCodeFileLine( int line ) + public void AddIRRangeData( IEnumerable ienumData ) { - + foreach( var v in ienumData ) + { + if (v == null) + { + continue; + } + m_IRDataList.Add(v); + } } public virtual string ToIRString() { StringBuilder sb = new StringBuilder(); - for( int i = 0; i < m_IRDataList.Count; i++ ) + for (int i = 0; i < m_IRDataList.Count; i++) { + if (this.m_IRDataList[i] == null) + { + continue; + } sb.AppendLine(m_IRDataList[i].ToString()); } return sb.ToString(); diff --git a/source/IR/IRBrach.cs b/source/IR/IRBrach.cs index 4da82d0..0560afe 100644 --- a/source/IR/IRBrach.cs +++ b/source/IR/IRBrach.cs @@ -6,37 +6,39 @@ // Description: //**************************************************************************** +using SimpleLanguage.Compile; using SimpleLanguage.Compile.CoreFileMeta; using SimpleLanguage.Core; using SimpleLanguage.IR; using SimpleLanguage.VM; using System; using System.Collections.Generic; +using System.IO; using System.Text; namespace SimpleLanguage.IR { public class IRBranch : IRBase { - public IRData brData = new IRData(); + public IRData data = new IRData(); public IRBranch( IRMethod _irMethod, EIROpCode type, IRData brIRData ) { - brData.opCode = type; - brData.opValue = brData; + data.opCode = type; + data.opValue = brIRData; + AddIRData( data ); } public void SetOpValue(IRData opValue) { - brData.opValue = opValue; + data.opValue = opValue; } - public override void SetCodeFileLine(int line) + public void SetDebugInfoByToken(Token token) { - brData.line = line; + data.SetDebugInfoByToken(token); } public override string ToIRString() { StringBuilder sb = new StringBuilder(); - sb.Append("branch"); sb.Append(base.ToIRString()); return sb.ToString(); @@ -44,12 +46,12 @@ public override string ToIRString() } public class IRLabel : IRBase { - IRData labelIRData = new IRData(); + IRData data = new IRData(); public IRLabel(IRMethod _irMethod, string _label, bool isGogo ) { - labelIRData = new IRData(); - labelIRData.opCode = isGogo ? EIROpCode.Label : EIROpCode.BrLabel; - labelIRData.opValue = _label; + data = new IRData(); + data.opCode = isGogo ? EIROpCode.Label : EIROpCode.BrLabel; + data.opValue = _label; } public override string ToIRString() { diff --git a/source/IR/IRCall.cs b/source/IR/IRCall.cs index b4202b9..1759791 100644 --- a/source/IR/IRCall.cs +++ b/source/IR/IRCall.cs @@ -20,7 +20,7 @@ public class IRCallFunction : IRBase MetaFunctionCall m_MetaFunctionCall = null; public int paramCount { get; set; } = 0; public bool target { get; set; } = false; - public IRCallFunction(IRMethod _irMethod, MetaFunctionCall mfc) + public IRCallFunction(IRMethod _irMethod, MetaFunctionCall mfc) : base(_irMethod) { m_MetaFunctionCall = mfc; Parse(); @@ -32,7 +32,7 @@ void Parse() { MetaInputParam mip = m_MetaFunctionCall.metaInputParamCollection.metaParamList[j] as MetaInputParam; IRExpress irexpress = new IRExpress(m_IRMethod, mip.express); - IRDataList.AddRange(irexpress.IRDataList); + AddIRRangeData(irexpress.IRDataList); } MetaFunction mf = m_MetaFunctionCall.function; if (mf is MetaMemberFunction) @@ -43,16 +43,16 @@ void Parse() IRData data = new IRData(); data.opCode = EIROpCode.CallCSharpMethod; data.opValue = this; - data.line = mmf.GetCodeFileLine(); - IRDataList.Add(data); + data.SetDebugInfoByToken( mmf.GetToken() ); + AddIRData(data); return; } } IRData datacall = new IRData(); datacall.opCode = EIROpCode.Call; datacall.opValue = m_MetaFunctionCall; - datacall.line = mf.GetCodeFileLine(); - IRDataList.Add(datacall); + datacall.SetDebugInfoByToken( mf.GetToken() ); + AddIRData(datacall); } public System.Object InvokeCSharp( Object target, Object[] csParamObjs) { @@ -169,3 +169,100 @@ public string ToIRString() } } } + +namespace SimpleLanguage.Core +{ + public partial class MetaCallLink + { + private IRMethod m_IRMethod = null; + public List irList = new List(); + + public void ParseToIRDataList(IRMethod _irMethod) + { + m_IRMethod = _irMethod; + + var cnlist = callNodeList; + for (int i = 0; i < cnlist.Count; i++) + { + var cnode = cnlist[i]; + if (cnode.callNodeType == ECallNodeType.ConstValue) + { + IRExpress data = new IRExpress( _irMethod, cnode.constValue); + irList.Add(data); + } + else if (cnode.callNodeType == ECallNodeType.VariableName) + { + MetaVariable mv = cnode.GetMetaVariable(); + IRLoadVariable irVar = new IRLoadVariable(m_IRMethod, mv); + irList.Add(irVar); + } + else if (cnode.callNodeType == ECallNodeType.MemberVariableName) + { + MetaMemberVariable mmv = cnode.GetMetaMemeberVariable(); + + IRLoadVariable irVar = new IRLoadVariable(IRManager.instance, mmv); + irList.Add(irVar); + } + else if (cnode.callNodeType == ECallNodeType.FunctionName) + { + var mfc = cnode.GetMetaFunctionCall(); + IRCallFunction irCallFun = new IRCallFunction(m_IRMethod, mfc); + irList.Add(irCallFun); + } + else if (cnode.callNodeType == ECallNodeType.This) + { + IRCallFunction data = new IRCallFunction( _irMethod, cnode.GetMetaFunctionCall() ); + irList.Add(data); + } + else if (cnode.callNodeType == ECallNodeType.Base) + { + IRCallFunction data = new IRCallFunction(_irMethod, cnode.GetMetaFunctionCall()); + irList.Add(data); + } + } + } + public void ParseToIRDataListByIRManager(IRManager _irManager) + { + var cnlist = callNodeList; + for (int i = 0; i < cnlist.Count; i++) + { + var cnode = cnlist[i]; + if (cnode.callNodeType == ECallNodeType.ConstValue) + { + IRExpress data = new IRExpress(_irManager, cnode.constValue); + irList.Add(data); + } + else if (cnode.callNodeType == ECallNodeType.VariableName) + { + MetaVariable mv = cnode.GetMetaVariable(); + IRLoadVariable irVar = new IRLoadVariable(m_IRMethod, mv); + irList.Add(irVar); + } + else if (cnode.callNodeType == ECallNodeType.MemberVariableName) + { + MetaMemberVariable mmv = cnode.GetMetaMemeberVariable(); + IRLoadVariable irVar = new IRLoadVariable(m_IRMethod, mmv); + irList.Add(irVar); + } + else if (cnode.callNodeType == ECallNodeType.FunctionName) + { + var mfc = cnode.GetMetaFunctionCall(); + IRCallFunction irCallFun = new IRCallFunction(m_IRMethod, mfc); + irList.Add(irCallFun); + } + } + } + + public string ToIRString() + { + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < irList.Count; i++ ) + { + sb.AppendLine(irList[i].ToIRString()); + + }; + return sb.ToString(); + } + } +} diff --git a/source/IR/IRExpress.cs b/source/IR/IRExpress.cs index 93e12c3..7e75a5b 100644 --- a/source/IR/IRExpress.cs +++ b/source/IR/IRExpress.cs @@ -37,7 +37,7 @@ public void CreateIRDataOne(MetaExpressNode node) IRData irdata = new IRData(); irdata.opCode = IRManager.GetConstIROpCode(mcn.eType); irdata.opValue = mcn.value; - irdata.line = mcn.GetCodeFileLine(); + irdata.SetDebugInfoByToken( mcn.GetToken() ); AddIRData(irdata); } break; @@ -56,7 +56,7 @@ public void CreateIRDataOne(MetaExpressNode node) CreateIRDataOne(leftNode); CreateIRDataOne(rightNode); var signData = CreateLeftAndRightIRData(moen.opSign); - signData.line = moen.GetCodeFileLine(); + signData.SetDebugInfoByToken( moen.GetToken() ); AddIRData(signData); } break; @@ -64,14 +64,17 @@ public void CreateIRDataOne(MetaExpressNode node) { if( m_IRManager != null ) { - //mcn.metaCallLink.ParseToIRDataListByIRManager(m_IRManager); + mcn.metaCallLink.ParseToIRDataListByIRManager(m_IRManager); } else { - //mcn.metaCallLink.ParseToIRDataList(m_IRMethod); + mcn.metaCallLink.ParseToIRDataList(m_IRMethod); + } + var list = mcn.metaCallLink.irList; + for( int i = 0; i < list.Count; i++ ) + { + m_IRDataList.AddRange(list[i].IRDataList); } - //var list = mcn.metaCallLink.irDataList; - //m_IRDataList.AddRange(list); } break; default: diff --git a/source/IR/IRManager.cs b/source/IR/IRManager.cs index dfaeb39..461ae46 100644 --- a/source/IR/IRManager.cs +++ b/source/IR/IRManager.cs @@ -6,31 +6,56 @@ // Description: //**************************************************************************** +using SimpleLanguage.Compile; using SimpleLanguage.Core; using SimpleLanguage.VM; using System; using System.Collections.Generic; +using System.IO; +using System.Numerics; using System.Text; namespace SimpleLanguage.IR { + public struct DebugInfo + { + public string path; + public int beginLine; + public int beginChar; + public int endLine; + public int endChar; + } public class IRData { public int id = 0; public EIROpCode opCode; //指令类型 public object opValue; //指令值 public int index; //索引 - public string path; //文件路径 - public int line; //运行行 + public DebugInfo debugInfo; //调试信息 public IRData() { + } + public void SetDebugInfoByValue( DebugInfo info ) + { + debugInfo = info; + } + public void SetDebugInfoByToken( Token token ) + { + if(token != null ) + { + debugInfo.path = token.path; + debugInfo.beginLine = token.sourceBeginLine; + debugInfo.beginChar = token.sourceBeginChar; + debugInfo.endLine = token.sourceEndLine; + debugInfo.endChar = token.sourceEndChar; + } } public override string ToString() { StringBuilder m_StringBuilder = new StringBuilder(); - m_StringBuilder.Append( path + " " + line.ToString() + " [" + opCode.ToString() + "] index:[" + index.ToString() + "]"); + m_StringBuilder.Append(debugInfo.path + " " + debugInfo.beginLine.ToString() + " [" + opCode.ToString() + "] index:[" + index.ToString() + "]"); if (opValue != null) m_StringBuilder.Append( " val:[" +opValue.ToString() + "] "); return m_StringBuilder.ToString(); diff --git a/source/IR/IRMethod.cs b/source/IR/IRMethod.cs index 6474dd3..be04da1 100644 --- a/source/IR/IRMethod.cs +++ b/source/IR/IRMethod.cs @@ -133,7 +133,10 @@ public void Parse() return; } mbs.ParseAllIRStatements(); - IRDataList.AddRange(mbs.GetIRDataList()); + for( int i = 0; i < mbs.irStatements.Count; i++ ) + { + IRDataList.AddRange(mbs.irStatements[i].IRDataList); + } for( int i = 0; i < m_LabelList.Count; i++ ) { diff --git a/source/IR/IRNop.cs b/source/IR/IRNop.cs index 67e80ad..5877433 100644 --- a/source/IR/IRNop.cs +++ b/source/IR/IRNop.cs @@ -15,11 +15,10 @@ namespace SimpleLanguage.IR public class IRNop : IRBase { public IRData nopData = new IRData(); - public IRNop( IRMethod irMethod ) + public IRNop( IRMethod irMethod ):base( irMethod ) { - m_IRMethod = irMethod; nopData.opCode = EIROpCode.Nop; - nopData.line = 0; + m_IRDataList.Add( nopData ); } public override string ToIRString() { diff --git a/source/IR/IRStatements/IRBlockStatements.cs b/source/IR/IRStatements/IRBlockStatements.cs index a82eed3..99815c9 100644 --- a/source/IR/IRStatements/IRBlockStatements.cs +++ b/source/IR/IRStatements/IRBlockStatements.cs @@ -19,7 +19,7 @@ public partial class MetaBlockStatements public override void ParseIRStatements() { IRNop insNode = new IRNop(irMethod); - insNode.nopData.line = m_FileMetaBlockSyntax.token.sourceBeginLine; + insNode.nopData.SetDebugInfoByToken( m_FileMetaBlockSyntax.token ); m_IRStatements.Add(insNode); } public void ParseAllIRStatements() @@ -27,7 +27,7 @@ public void ParseAllIRStatements() IRNop insNode = new IRNop(this.m_OwnerMetaFunction.irMethod); if (m_FileMetaBlockSyntax?.token != null) { - insNode.nopData.line = m_FileMetaBlockSyntax.token.sourceBeginLine; + insNode.nopData.SetDebugInfoByToken( m_FileMetaBlockSyntax.token ); } m_IRStatements.Add(insNode); @@ -35,28 +35,10 @@ public void ParseAllIRStatements() while (mbs != null) { mbs.ParseIRStatements(); + m_IRStatements.AddRange(mbs.irStatements); mbs = mbs.nextMetaStatements; } } - public List GetIRDataList() - { - List irDataList = new List(); - - foreach( var v in m_IRStatements ) - { - irDataList.AddRange(v.IRDataList); - } - MetaStatements mbs = m_NextMetaStatements; - while (mbs != null) - { - foreach (var v in mbs.irStatements) - { - irDataList.AddRange(v.IRDataList); - } - mbs = mbs.nextMetaStatements; - } - return irDataList; - } public override string ToIRString() { StringBuilder sb = new StringBuilder(); diff --git a/source/IR/IRStatements/IRBreakContinueGoStatements.cs b/source/IR/IRStatements/IRBreakContinueGoStatements.cs index 611c2b1..f626c31 100644 --- a/source/IR/IRStatements/IRBreakContinueGoStatements.cs +++ b/source/IR/IRStatements/IRBreakContinueGoStatements.cs @@ -25,17 +25,16 @@ public override void ParseIRStatements() m_IRStatements.Add(irBrach); if (m_FileMetaKeyOnlySyntax.token != null ) { - irBrach.brData.line = m_FileMetaKeyOnlySyntax.token.sourceBeginLine; + irBrach.data.SetDebugInfoByToken( m_FileMetaKeyOnlySyntax.token ); } - irMethod.AddLabelDict(irBrach.brData); - m_IRStatements.Add( irBrach ); + irMethod.AddLabelDict(irBrach.data); if (m_ForStatements != null ) { - irBrach.brData.opValue = m_ForStatements.endIRData.nopData; + irBrach.data.opValue = m_ForStatements.endIRData.nopData; } else if( m_WhileStatements != null ) { - irBrach.brData.opValue = m_WhileStatements.endData; + irBrach.data.opValue = m_WhileStatements.endData; } } public override string ToIRString() @@ -57,17 +56,17 @@ public override void ParseIRStatements() irBrach = new IRBranch(irMethod, EIROpCode.Br, null ); if (m_FileMetaKeyOnlySyntax.token != null) { - irBrach.SetCodeFileLine( m_FileMetaKeyOnlySyntax.token.sourceBeginLine ); + irBrach.SetDebugInfoByToken( m_FileMetaKeyOnlySyntax.token ); } - irMethod.AddLabelDict(irBrach.brData); + irMethod.AddLabelDict(irBrach.data); m_IRStatements.Add(irBrach); if (m_ForStatements != null) { - irBrach.brData.opValue = m_ForStatements.forStartIRData; + irBrach.data.opValue = m_ForStatements.forStartIRData; } else if (m_WhileStatements != null) { - irBrach.brData.opValue = m_WhileStatements.endData; + irBrach.data.opValue = m_WhileStatements.endData; } } public override string ToIRString() diff --git a/source/IR/IRStatements/IRCallStatements.cs b/source/IR/IRStatements/IRCallStatements.cs index 3363dbd..5e2b8e0 100644 --- a/source/IR/IRStatements/IRCallStatements.cs +++ b/source/IR/IRStatements/IRCallStatements.cs @@ -18,13 +18,12 @@ public partial class MetaCallStatements { public override void ParseIRStatements() { - //m_MetaCallLink.ParseToIRDataList(irMethod); - //m_IRStatements.AddRange(m_MetaCallLink); + m_MetaCallLink.ParseToIRDataList(irMethod); + m_IRStatements.AddRange(m_MetaCallLink.irList); } public override string ToIRString() { - //return m_MetaCallLink.ToIRString(); - return base.ToIRString(); + return m_MetaCallLink.ToIRString(); } } } diff --git a/source/IR/IRStatements/IRIfStatements.cs b/source/IR/IRStatements/IRIfStatements.cs index c0b81b9..d12aeb5 100644 --- a/source/IR/IRStatements/IRIfStatements.cs +++ b/source/IR/IRStatements/IRIfStatements.cs @@ -25,8 +25,8 @@ public partial class MetaElseIfStatements public List conditionStatList = new List(); public List thenStatList = new List(); - public IRBranch brBrach = null; - public IRBranch ifBreach = null; + public IRBranch ifEndBrach = null; + public IRBranch ifFalseBreach = null; public IRNop startNop = null; private IRExpress m_IrExpress = null; @@ -37,7 +37,7 @@ public void ParseIRStatements( IRMethod _irMethod ) if (m_IfElseState == IfElseState.If || m_IfElseState == IfElseState.ElseIf ) { - startNop.nopData.line = m_FinalExpress.GetCodeFileLine(); + startNop.nopData.SetDebugInfoByToken( m_FinalExpress.GetToken() ); m_IrExpress = new IRExpress(_irMethod, m_FinalExpress); conditionStatList.Add(m_IrExpress); @@ -45,28 +45,28 @@ public void ParseIRStatements( IRMethod _irMethod ) if (m_MetaAssignManager?.isNeedSetMetaVariable == true) { IRStoreVariable storeLocal = new IRStoreVariable(_irMethod, m_BoolConditionVariable); - storeLocal.irStoreData.line = m_BoolConditionVariable.GetCodeFileLine(); + storeLocal.data.SetDebugInfoByToken( m_BoolConditionVariable.GetToken() ); conditionStatList.Add(storeLocal); IRLoadVariable loadLocal = new IRLoadVariable(_irMethod, m_BoolConditionVariable); - loadLocal.irLoadData.line = m_BoolConditionVariable.GetCodeFileLine(); + loadLocal.data.SetDebugInfoByToken( m_BoolConditionVariable.GetToken() ); conditionStatList.Add(loadLocal); } - ifBreach = new IRBranch( _irMethod, EIROpCode.BrFalse, null ); - ifBreach.SetCodeFileLine( m_IfOrElseIfKeySyntax.token.sourceBeginLine ); - conditionStatList.Add(ifBreach); + ifFalseBreach = new IRBranch( _irMethod, EIROpCode.BrFalse, null ); + ifFalseBreach.SetDebugInfoByToken( m_IfOrElseIfKeySyntax.token ); + conditionStatList.Add(ifFalseBreach); - _irMethod.AddLabelDict(ifBreach.brData); + _irMethod.AddLabelDict(ifFalseBreach.data); } m_ThenMetaStatements.ParseAllIRStatements(); - //thenStatList.AddRange(m_ThenMetaStatements.irDataList); + thenStatList.AddRange(m_ThenMetaStatements.irStatements); - brBrach = new IRBranch(_irMethod, EIROpCode.Br, null ); - _irMethod.AddLabelDict(brBrach.brData); - - thenStatList.Add(brBrach); + ifEndBrach = new IRBranch(_irMethod, EIROpCode.Br, null ); + ifEndBrach.data.index = -1; + _irMethod.AddLabelDict(ifEndBrach.data); + thenStatList.Add(ifEndBrach); } public string ToIRString() @@ -102,23 +102,23 @@ public override void ParseIRStatements() m_IRStatements.AddRange(meis.thenStatList); } - IRNop nopIR = new IRNop( irMethod ); - m_IRStatements.Add(nopIR); + IRNop ifEndIRNop = new IRNop( irMethod ); + m_IRStatements.Add(ifEndIRNop); for ( int i = 0; i < m_MetaElseIfStatements.Count; i++ ) { var meis = m_MetaElseIfStatements[i]; - meis.brBrach.brData.opValue = nopIR; + meis.ifEndBrach.data.opValue = ifEndIRNop; - if (meis.ifBreach != null) + if (meis.ifFalseBreach != null) { if( i < m_MetaElseIfStatements.Count - 1 ) { - meis.ifBreach.brData.opValue = m_MetaElseIfStatements[i + 1].startNop.nopData; + meis.ifFalseBreach.data.opValue = m_MetaElseIfStatements[i + 1].startNop.nopData; } else if( i == m_MetaElseIfStatements.Count - 1 ) { - meis.ifBreach.brData.opValue = nopIR; + meis.ifFalseBreach.data.opValue = ifEndIRNop; } } } diff --git a/source/IR/IRStatements/IRNewStatements.cs b/source/IR/IRStatements/IRNewStatements.cs index 264d9e6..2409be9 100644 --- a/source/IR/IRStatements/IRNewStatements.cs +++ b/source/IR/IRStatements/IRNewStatements.cs @@ -37,6 +37,10 @@ public override void ParseIRStatements() } IRStoreVariable irStoreVar = new IRStoreVariable(irMethod, m_MetaVariable); + if(m_FileMetaOpAssignSyntax != null ) + { + irStoreVar.data.SetDebugInfoByToken(m_FileMetaOpAssignSyntax.assignToken); + } m_IRStatements.Add(irStoreVar); if ( mnoen!= null ) @@ -81,7 +85,13 @@ public override string ToIRString() StringBuilder sb = new StringBuilder(); sb.Append("#new var "); - sb.AppendLine(m_MetaVariable.ToFormatString() + "#"); + sb.Append(m_MetaVariable.ToFormatString() ); + if(m_ExpressNode != null ) + { + sb.Append( " = " + m_ExpressNode.ToFormatString()); + } + sb.AppendLine(" #"); + sb.AppendLine("{"); for (int i = 0; i < m_IRStatements.Count; i++) { diff --git a/source/IR/IRStatements/IRStatements.cs b/source/IR/IRStatements/IRStatements.cs index 95d9952..e31b9c1 100644 --- a/source/IR/IRStatements/IRStatements.cs +++ b/source/IR/IRStatements/IRStatements.cs @@ -24,13 +24,12 @@ public IRMethod irMethod protected List m_IRStatements = new List(); public virtual void ParseIRStatements() - { + { } public virtual string ToIRString() { StringBuilder sb = new StringBuilder(); - sb.AppendLine("parseIR"); sb.AppendLine("{"); for (int i = 0; i < m_IRStatements.Count; i++) { diff --git a/source/IR/IRStatements/IRWhileStatements.cs b/source/IR/IRStatements/IRWhileStatements.cs index 516da21..b589c56 100644 --- a/source/IR/IRStatements/IRWhileStatements.cs +++ b/source/IR/IRStatements/IRWhileStatements.cs @@ -56,7 +56,7 @@ public override void ParseIRStatements() ifIRData = new IRBranch(irMethod, EIROpCode.BrFalse, endIRData.nopData); m_IRStatements.Add(ifIRData); - irMethod.AddLabelDict(ifIRData.brData); + irMethod.AddLabelDict(ifIRData.data); } if (m_StepStatements != null) { @@ -68,7 +68,7 @@ public override void ParseIRStatements() } brIRData = new IRBranch(irMethod, EIROpCode.Br, forStartIRData.nopData ); - irMethod.AddLabelDict(brIRData.brData); + irMethod.AddLabelDict(brIRData.data); m_IRStatements.Add(brIRData); m_IRStatements.Add(endIRData); @@ -117,14 +117,9 @@ public override string ToIRString() } if (m_StepStatements != null) { - for (int i = 0; i < deep + 1; i++) - { - sb.Append(Global.tabChar); - } sb.Append(m_StepStatements.ToIRString()); } - - sb.Append(m_ThenMetaStatements?.nextMetaStatements?.ToIRString()); + sb.Append(m_ThenMetaStatements?.ToIRString()); } else { diff --git a/source/IR/IRVariable.cs b/source/IR/IRVariable.cs index bedd2c1..dcdcf6d 100644 --- a/source/IR/IRVariable.cs +++ b/source/IR/IRVariable.cs @@ -17,39 +17,37 @@ namespace SimpleLanguage.IR { public class IRLoadVariable : IRBase { - public IRData irLoadData = new IRData(); - MetaVariable m_MetaVariable = null; + public IRData data = new IRData(); public IRLoadVariable(IRManager _irManager, MetaMemberVariable mmv) { - m_MetaVariable = mmv; if (mmv.isStatic) { - irLoadData.opCode = EIROpCode.LoadStaticField; - irLoadData.index = _irManager.GetStaticVariableIndex(mmv); - m_IRDataList.Add(irLoadData); + data.opCode = EIROpCode.LoadStaticField; + data.index = _irManager.GetStaticVariableIndex(mmv); + m_IRDataList.Add(data); } else { - irLoadData.opCode = EIROpCode.LoadNotStaticField; - irLoadData.index = mmv.ownerMetaClass.metaClassData.GetMemberVariableIndex(mmv); - m_IRDataList.Add(irLoadData); + data.opCode = EIROpCode.LoadNotStaticField; + data.index = mmv.ownerMetaClass.metaClassData.GetMemberVariableIndex(mmv); + m_IRDataList.Add(data); } } public IRLoadVariable(IRMethod _irMethod, MetaVariable mv) : base(_irMethod) { if (mv.isArgument) { - irLoadData.opCode = EIROpCode.LoadArgument; - irLoadData.line = mv.GetCodeFileLine(); - irLoadData.index = m_IRMethod.GetArgumentIndex(mv); - m_IRDataList.Add(irLoadData); + data.opCode = EIROpCode.LoadArgument; + data.SetDebugInfoByToken( mv.GetToken() ); + data.index = m_IRMethod.GetArgumentIndex(mv); + m_IRDataList.Add(data); } else { - irLoadData.opCode = EIROpCode.LoadLocal; - irLoadData.line = mv.GetCodeFileLine(); - irLoadData.index = m_IRMethod.GetLocalVariableIndex(mv); - m_IRDataList.Add(irLoadData); + data.opCode = EIROpCode.LoadLocal; + data.SetDebugInfoByToken( mv.GetToken() ); + data.index = m_IRMethod.GetLocalVariableIndex(mv); + m_IRDataList.Add(data); } } public override string ToIRString() @@ -59,37 +57,39 @@ public override string ToIRString() } public class IRStoreVariable : IRBase { - public IRData irStoreData = new IRData(); - MetaVariable m_MetaVariable = null; + public IRData data = new IRData(); public IRStoreVariable( IRMethod _irMethod, MetaMemberVariable mmv) { - m_MetaVariable = mmv; - IRExpress irexp = new IRExpress(_irMethod, mmv.express); m_IRDataList.AddRange(irexp.IRDataList); - irStoreData.opCode = EIROpCode.StoreNotStaticField; - irStoreData.index = mmv.ownerMetaClass.metaClassData.GetMemberVariableIndex(mmv); - m_IRDataList.Add(irStoreData); + data.opCode = EIROpCode.StoreNotStaticField; + data.index = mmv.ownerMetaClass.metaClassData.GetMemberVariableIndex(mmv); + m_IRDataList.Add(data); } public IRStoreVariable(IRMethod _irMethod, MetaVariable mv) : base(_irMethod) { if (mv.isArgument) { - irStoreData.opCode = EIROpCode.LoadArgument; - irStoreData.index = m_IRMethod.GetArgumentIndex(mv); - m_IRDataList.Add(irStoreData); + data.opCode = EIROpCode.LoadArgument; + data.index = m_IRMethod.GetArgumentIndex(mv); + m_IRDataList.Add(data); } else { - irStoreData.opCode = EIROpCode.StoreLocal; - irStoreData.index = m_IRMethod.GetLocalVariableIndex(mv); - m_IRDataList.Add(irStoreData); + data.opCode = EIROpCode.StoreLocal; + data.index = m_IRMethod.GetLocalVariableIndex(mv); + m_IRDataList.Add(data); } } public override string ToIRString() { - return base.ToIRString(); + StringBuilder sb = new StringBuilder(); + for( int i = 0; i < m_IRDataList.Count; i++ ) + { + sb.AppendLine(m_IRDataList[i].ToString()); + } + return sb.ToString(); } } } \ No newline at end of file