void ProcessApplyFrag(MIApply apply, FileData fd, MIFragment frag, List <VariablesBlock> local) { const String fcn = "ProcessApplyMacro"; if (apply.Parameters.Count != 0) { String fullMsg = $"{apply.SourceFile}, line {apply.LineNumber} Fragment {apply.Name} takes no parameters."; fullMsg += this.ApplyLongStackTrace(); this.ConversionError(ClassName, fcn, fullMsg); return; } bool firstFlag = false; if (this.appliedMacros.Contains(apply.Name) == false) { this.appliedMacros.Add(apply.Name); firstFlag = true; } if ((frag.OnceFlag == true) && (firstFlag == false)) { return; } if (this.incompatibleMacros.Contains(apply.Name)) { String fullMsg = $"{apply.SourceFile}, line {apply.LineNumber} {apply.Name} has been marked as incompatible with this profile"; fullMsg += this.ApplyLongStackTrace(); this.ConversionError(ClassName, fcn, fullMsg); return; } VariablesBlock localVb = StartNewFrag(frag, out String name); List <VariablesBlock> fragLocal = new List <VariablesBlock>(); fragLocal.AddRange(local); fragLocal.Insert(0, localVb); FileData macroData = fd; this.applyStack.Push(apply); // this is for stack tracing during errors this.Process(frag.Items, macroData, fragLocal); this.applyStack.Pop(); }
void ProcessApply(MIApply apply, FileData fd, List <VariablesBlock> variableBlocks) { const String fcn = "ProcessApply"; List <VariablesBlock> local = new List <VariablesBlock>(); local.AddRange(variableBlocks); apply.ApplyCount += 1; if ((apply.OnceFlag) && (apply.ApplyCount > 1)) { return; } //Debug.Assert(apply.Name.EndsWith("DefineFragment") == false); if (this.MacroMgr.TryGetItem(apply.Usings, apply.Name, out MIApplicable applicableItem) == false) { String fullMsg = $"{apply.SourceFile}, line {apply.LineNumber} Macro {apply.Name} not found."; fullMsg += this.ApplyLongStackTrace(); this.ConversionError(ClassName, fcn, fullMsg); return; } switch (applicableItem) { case MIMacro macro: this.ProcessApplyMacro(apply, fd, macro, local); break; case MIFragment frag: this.ProcessApplyFrag(apply, fd, frag, local); break; default: throw new NotImplementedException(); } }
void ProcessApplyMacro(MIApply apply, FileData fd, MIMacro macro, List <VariablesBlock> local) { const String fcn = "ProcessApplyMacro"; if (macro.Parameters.Count != apply.Parameters.Count) { String fullMsg = $"{apply.SourceFile}, line {apply.LineNumber} Macro {apply.Name} requires {macro.Parameters.Count} parameters, called with {apply.Parameters.Count}."; fullMsg += this.ApplyLongStackTrace(); this.ConversionError(ClassName, fcn, fullMsg); return; } macro.AppliedFlag = true; bool firstFlag = false; if (this.appliedMacros.Contains(apply.Name) == false) { this.appliedMacros.Add(apply.Name); firstFlag = true; } if ((macro.OnceFlag == true) && (firstFlag == false)) { return; } if (this.incompatibleMacros.Contains(apply.Name)) { String fullMsg = $"{apply.SourceFile}, line {apply.LineNumber} Macro {apply.Name} has been marked as incompatible with this profile"; fullMsg += this.ApplyLongStackTrace(); this.ConversionError(ClassName, fcn, fullMsg); return; } local.Insert(0, macro.ApplicableVariables); VariablesBlock vbParameters = new VariablesBlock(); for (Int32 i = 0; i < apply.Parameters.Count; i++) { String pName = macro.Parameters[i]; String pValue = apply.Parameters[i]; if (this.variableBlocks != null) { pValue = this.variableBlocks.ReplaceText(pValue); } vbParameters.Add(pName, pValue); } vbParameters.Add("%ApplySourceFile%", apply.SourceFile.Replace("\\", "/")); vbParameters.Add("%ApplyLineNumber%", apply.LineNumber.ToString()); local.Insert(0, vbParameters); FileData macroData = fd; if (String.IsNullOrEmpty(macro.Redirect) == false) { if (this.skipRedirects == true) { return; } this.GetFileData(macro.Redirect, local, out macroData); } this.applyStack.Push(apply); // this is for stack tracing during errors vbParameters.Add("%ApplyStackFrame%", this.ApplyShortStackTrace().Replace("\\", "/")); this.Process(macro.Items, macroData, local); this.applyStack.Pop(); }