@@ -55,8 +55,12 @@ namespace CodeGen.Engine
5555
5656 private static loopProcessors, @Dictionary<string, Action<LoopNode, FileNode, IEnumerable<LoopNode>, ITreeNodeVisitor>>
5757
58+ ;;; <summary>
59+ ;;; Constructor
60+ ;;; </summary>
5861 static method LoopExpander
5962 proc
63+ ;; Declare the methods responsible for processing each type of loop
6064
6165 loopProcessors = new Dictionary<string, Action<LoopNode, FileNode, IEnumerable<LoopNode>, ITreeNodeVisitor>>()
6266
@@ -107,10 +111,17 @@ namespace CodeGen.Engine
107111 required in loopContext, @IEnumerable<LoopNode>
108112 required in visitor, @ITreeNodeVisitor
109113 proc
114+ ;; Lookup the processing method for the loop needing to be processed
110115 if (loopProcessors.ContainsKey(node.OpenToken.Value)) then
116+ begin
117+ ;; And call it
111118 loopProcessors[node.OpenToken.Value](node, tpl, loopContext, visitor)
119+ end
112120 else
113- throw new ApplicationException(String.Format("CODEGEN BUG: LoopExpander doesn't define a processor for <{0}>!", node.OpenToken.Value))
121+ begin
122+ ;; Not found (CodeGen bug)
123+ throw new ApplicationException(String.Format("CODEGEN BUG: LoopExpander doesn't define a loop processor method for <{0}>!", node.OpenToken.Value))
124+ end
114125 endmethod
115126
116127 private static method processFieldLoop, void
@@ -139,7 +150,7 @@ namespace CodeGen.Engine
139150 data ix, int
140151 for ix from 0 thru currentStructure.Fields.Count - 1
141152 begin
142- loop.CurrentField = currentStructure.Fields[ix]
153+ loop.SetCurrentField( currentStructure.Fields[ix])
143154 loop.CurrentIndex = ix
144155 expander.Visit(node.Body)
145156 end
@@ -1006,17 +1017,17 @@ namespace CodeGen.Engine
10061017 data loop = ^as(node, SelectionLoopNode)
10071018 data context = template.Context
10081019
1009- if (outerLoop.CurrentField .SelectionList.Count > 0)
1020+ if (outerLoop.GetCurrentField() .SelectionList.Count > 0)
10101021 begin
1011- loop.MaxIndex = outerLoop.CurrentField .SelectionList.Count - 1
1012- loop.CurrentField = outerLoop.CurrentField
1022+ loop.MaxIndex = outerLoop.GetCurrentField() .SelectionList.Count - 1
1023+ loop.CurrentField = outerLoop.GetCurrentField()
10131024
10141025 context.CurrentTask.DebugLog(String.Format(" - {0,-30} -> {1} selections", string.Format("<{0}>", loop.OpenToken.Value), loop.MaxIndex + 1))
10151026
10161027 data ix, int
1017- for ix from 0 thru outerLoop.CurrentField .SelectionList.Count - 1
1028+ for ix from 0 thru outerLoop.GetCurrentField() .SelectionList.Count - 1
10181029 begin
1019- loop.CurrentSelection = outerLoop.CurrentField .SelectionList[ix]
1030+ loop.CurrentSelection = outerLoop.GetCurrentField() .SelectionList[ix]
10201031 loop.CurrentIndex = ix
10211032
10221033 expander.Visit(node.Body)
0 commit comments