/// <summary> /// Reset the <see cref="T:DotNetAsm.RepetitionHandler"/>. All processed lines will be cleared. /// </summary> public void Reset() { _processedLines.Clear(); _rootBlock.Entries.Clear(); _rootBlock.RepeatAmounts = 0; _currBlock = _rootBlock; }
/// <summary> /// Processes the <see cref="T:DotNetAsm.SourceLine"/> for repetitions, or within a repetition block. /// </summary> /// <param name="line">The <see cref="T:DotNetAsm.SourceLine"/> to process</param> public void Process(SourceLine line) { if (line.Instruction.Equals(".repeat", Controller.Options.StringComparison)) { if (string.IsNullOrEmpty(line.Operand)) { Controller.Log.LogEntry(line, ErrorStrings.TooFewArguments, line.Instruction); return; } if (string.IsNullOrEmpty(line.Label) == false) { Controller.Log.LogEntry(line, ErrorStrings.None); return; } if (_levels > 0) { var block = new RepetitionBlock { BackLink = _currBlock }; var entry = new RepetitionBlock.RepetitionEntry(null, block); _currBlock.Entries.Add(entry); _currBlock = block; } _levels++; _currBlock.RepeatAmounts = Controller.Evaluator.Eval(line.Operand, int.MinValue, uint.MaxValue); } else if (line.Instruction.Equals(".endrepeat", Controller.Options.StringComparison)) { if (_levels == 0) { Controller.Log.LogEntry(line, ErrorStrings.ClosureDoesNotCloseBlock, line.Instruction); } else if (string.IsNullOrEmpty(line.Operand) == false) { Controller.Log.LogEntry(line, ErrorStrings.TooManyArguments, line.Instruction); } else if (string.IsNullOrEmpty(line.Label) == false) { Controller.Log.LogEntry(line, ErrorStrings.None); } else { _levels--; _currBlock = _currBlock.BackLink; if (_levels == 0) { ProcessLines(_rootBlock); } } } else { var entry = new RepetitionBlock.RepetitionEntry(line, null); _currBlock.Entries.Add(entry); } }
/// <summary> /// Constructs an instance of a <see cref="T:DotNetAsm.RepetitionHandler"/> object. /// </summary> public RepetitionHandler() { Reserved.DefineType("Directives", ".repeat", ".endrepeat"); _currBlock = _rootBlock = new RepetitionBlock(); _levels = 0; _processedLines = new List <SourceLine>(); }
/// <summary> /// Constructs a <see cref="T:DotNetAsm.RepetitionHandler.RepetitionBlock.RepetitionEntry"/>. /// </summary> /// <param name="line">The <see cref="T:DotNetAsm.SourceLine "/> to add. This value can /// be null.</param> /// <param name="block">The <see cref="T:DotNetAsm.RepetitionHandler.RepetitionBlock"/> /// to link to. This value can be null.</param> public RepetitionEntry(SourceLine line, RepetitionBlock block) { if (line != null) { Line = line.Clone() as SourceLine; } else { Line = null; } LinkedBlock = block; }
/// <summary> /// Perform final processing on the processed lines of the <see cref="T:DotNetAsm.RepetitionHandler"/>. /// </summary> /// <param name="block">The <see cref="T:DotNetAsm.RepetitionHandler.RepetitionBlock"/> to process</param> void ProcessLines(RepetitionBlock block) { for (int i = 0; i < block.RepeatAmounts; i++) { foreach (var entry in block.Entries) { if (entry.LinkedBlock != null) { ProcessLines(entry.LinkedBlock); } else { _processedLines.Add(entry.Line.Clone() as SourceLine); } } } }