Skip to content

Commit 0fb87eb

Browse files
committed
Change field loop node "current field" to a stack to enable fugure support for nested GROUPS.
1 parent 9551431 commit 0fb87eb

8 files changed

Lines changed: 66 additions & 22 deletions

File tree

CodeGenEngine/CodeGenContext.dbl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,21 @@ namespace CodeGen.Engine
7070
.region "Task Context"
7171

7272
public readwrite property ExtendedRepositoryProperties, @Dictionary<string, Dictionary<string, object>>, new Dictionary<string, Dictionary<string, Object>>()
73+
7374
;;Main repository context
7475
public readwrite property Properties, @ConcurrentDictionary<Object, Object>, new ConcurrentDictionary<Object, Object>()
76+
7577
;;; <summary>
7678
;;; Exposes the structures BEING PROCESSED to the parser environment
7779
;;; </summary>
7880
public readwrite property Structures, @RpsStructureCollection
81+
7982
;;; <summary>
8083
;;; Exposes the full repository to the parser environment
8184
;;; </summary>
8285
public readwrite property Repository, @Repository
8386

84-
;;; <summary>
85-
;;; Current repository structure in use
86-
;;; </summary>
87-
public property CurrentStructure, @Stack<RpsStructure>
88-
method get
89-
proc
90-
mreturn mCurrentStructure
91-
end
92-
endproperty
87+
;; Access to the current structure is only via various public methods (below)
9388
private mCurrentStructure, @Stack<RpsStructure>
9489

9590
;;Other context

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorFieldLoop.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ namespace CodeGen.Engine
293293
begin
294294
;;We're in a field loop
295295
str = template.Context.GetCurrentStructure()
296-
field = ((@FieldLoopNode)loop).CurrentField
296+
field = ((@FieldLoopNode)loop).GetCurrentField()
297297
index = ((@FieldLoopNode)loop).CurrentIndex
298298
end
299299
else if (loop .is. RelationSegmentLoopNode) then

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorStructure.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace CodeGen.Engine
8282
endparams
8383
proc
8484
;;This is to trap the possible use of structure expressions in parameter loops, but with non-structure parameters
85-
if (template.Context.CurrentStructure == ^null)
85+
if (template.Context.GetCurrentStructure() == ^null)
8686
begin
8787
throw new ApplicationException(String.Format("Attempt to use structure expression <IF {0}> with no current structure!",tkn.Value))
8888
end

CodeGenEngine/LoopExpander.dbl

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

CodeGenEngine/TokenExpanders/TokenExpanderFieldLoop.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ namespace CodeGen.Engine
213213
begin
214214
;;We're in a field loop
215215
str = currentStructure
216-
fld = ((@FieldLoopNode)loop).CurrentField
216+
fld = ((@FieldLoopNode)loop).GetCurrentField()
217217
end
218218
else if (loop .is. RelationSegmentLoopNode) then
219219
begin

CodeGenEngine/TokenExpanders/TokenExpanderStructure.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ namespace CodeGen.Engine
115115
endparams
116116
proc
117117
;;This is to trap the possible use of structure tokens in parameter loops, but with non-structure parameters
118-
if (template.Context.CurrentStructure == ^null)
118+
if (template.Context.GetCurrentStructure() == ^null)
119119
begin
120120
throw new ApplicationException(String.Format("Attempt to use structure token <{0}> with no current structure!",tkn.Value))
121121
end

CodeGenEngine/TreeExpander.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ namespace CodeGen.Engine
570570
else
571571
begin
572572
;; No, we'll be going with a default output file name
573-
if (node.Context.CurrentStructure == ^null) then
573+
if (node.Context.GetCurrentStructure() == ^null) then
574574
node.OutputFileName = String.Format("{0}.dbl", node.Context.CurrentTemplateBaseName.ToLower())
575575
else
576576
node.OutputFileName = String.Format("{0}_{1}.dbl", node.Context.GetCurrentStructure().Name.ToLower(), node.Context.CurrentTemplateBaseName.ToLower())

CodeGenEngine/TreeNodes.dbl

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,45 @@ namespace CodeGen.Engine
105105
;;; Represents a field loop token in a template file.
106106
;;; </summary>
107107
public class FieldLoopNode extends LoopNode
108-
public CurrentField, @RpsField
108+
109+
private mCurrentField, @Stack<RpsField>, new Stack<RpsField>()
110+
111+
public method SetCurrentField, void
112+
required in aField, @RpsField
113+
proc
114+
using mCurrentField.Count select
115+
(0),
116+
mCurrentField.Push(aField)
117+
(),
118+
begin
119+
mCurrentField.Pop()
120+
mCurrentField.Push(aField)
121+
end
122+
endusing
123+
endmethod
124+
125+
public method GetCurrentField, @RpsField
126+
proc
127+
mreturn mCurrentField.Count > 0 ? mCurrentField.Peek() : ^null
128+
endmethod
129+
130+
public method AddNestedField, void
131+
required in aField, @RpsField
132+
proc
133+
if (mCurrentField.Count > 0) then
134+
mCurrentField.Push(aField)
135+
else
136+
throw new ApplicationException("Can't add nested field when no main field is being processed!")
137+
endmethod
138+
139+
public method RemoveNestedField, void
140+
proc
141+
if (mCurrentField.Count > 1) then
142+
mCurrentField.Pop()
143+
else
144+
throw new ApplicationException("No nested field to remove!")
145+
endmethod
146+
109147
endclass
110148

111149
;;; <summary>

0 commit comments

Comments
 (0)