public bool ExpandMacro(int statementIdx, List <AssembleError> errorList) { StatementElement stmt = Statements[statementIdx]; Macrocall macrocall = stmt.Macrocall; //マクロ定義を有効なスコープと全セクションから検索する MacroDefinition macrodef; if (!FindMacrodef(macrocall.CallerName, out macrodef)) { errorList.Add(new AssembleError() { Title = "Macro expanding", Detail = "Macro definition '" + macrocall.CallerName + "' not found.", Position = this.AssemblePosition }); return(false); } //展開先のブロックを作成しする Block expandedBlock = new Block() { AssemblePosition = stmt.Macrocall.AssemblePosition, Name = stmt.Macrocall.CallerName + "_expanded", ParentBlock = this, RootCode = this.RootCode }; StatementElement expandedStmt = new StatementElement() { Type = enumStatementType.Block, Block = expandedBlock }; //マクロの内容をコピーする macrodef.CopyToBlock(expandedBlock); //置換を行う if (!expandedStmt.ReplaceByIdentifiers(macrodef.Arguments, macrocall.Operands, errorList)) { return(false); } //マクロ呼出しのラベルを展開先のブロックに設定する foreach (var lbl in macrocall.Labels) { var newLbl = lbl.Clone(expandedBlock.ParentBlock); expandedBlock.Labels.Add(newLbl); newLbl.SetLabelPlacedInfo(expandedBlock.PlacedInfo); } //マクロ呼出しを削除して展開先ブロックに置き換える Statements[statementIdx] = expandedStmt; return(true); }
public StatementElement Clone(Block parentBlock) { var res = new StatementElement() { Type = this.Type }; switch (this.Type) { case enumStatementType.Block: res.Block = this.Block.Clone(parentBlock); break; case enumStatementType.Instruction: res.Instruction = this.Instruction.Clone(parentBlock); break; case enumStatementType.Macrocall: res.Macrocall = this.Macrocall.Clone(parentBlock); break; } return(res); }
public void AddStatement(StatementElement Statement) { statements.Add(Statement); }