Skip to content

Commit 9551431

Browse files
committed
Changed CodeGenContext.CurrentStructure from @RpsStructure to @stack<RpsStructure> in preparation for adding nested GROUP support to field loops.
1 parent 5f714b9 commit 9551431

35 files changed

Lines changed: 254 additions & 145 deletions

CodeGenEngine/CodeGenContext.dbl

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,23 @@ namespace CodeGen.Engine
8181
;;; </summary>
8282
public readwrite property Repository, @Repository
8383

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
93+
private mCurrentStructure, @Stack<RpsStructure>
94+
8495
;;Other context
8596

8697
public readwrite property Buttons, @WscButtonCollection
8798
public readwrite property Counter1, int
8899
public readwrite property Counter2, int
89100
public readwrite property CurrentFileIndex, int
90-
public readwrite property CurrentStructure, @RpsStructure
91101
public readwrite property CurrentTask, @CodeGenTask
92102
public readwrite property CurrentTemplate, String
93103

@@ -123,7 +133,7 @@ namespace CodeGen.Engine
123133
Counter1 = 0
124134
Counter2 = 0
125135
CurrentFileIndex = 0
126-
CurrentStructure = ^null
136+
mCurrentStructure = ^null
127137
CurrentTask = ^null
128138
CurrentTemplate = String.Empty
129139
FileDefinition = ^null
@@ -206,6 +216,85 @@ namespace CodeGen.Engine
206216

207217
.region "Public methods"
208218

219+
public method SetCurrentStructure, void
220+
required in aStructure, @RpsStructure
221+
proc
222+
if (mCurrentStructure == ^null) then
223+
begin
224+
mCurrentStructure = new Stack<RpsStructure>()
225+
mCurrentStructure.Push(aStructure)
226+
end
227+
else
228+
begin
229+
using mCurrentStructure.Count select
230+
(0),
231+
mCurrentStructure.Push(aStructure)
232+
(1),
233+
begin
234+
mCurrentStructure.Clear()
235+
mCurrentStructure.Push(aStructure)
236+
end
237+
(),
238+
begin
239+
throw new ApplicationException("Current structure can't be set when a nested structure is being processed!")
240+
end
241+
endusing
242+
end
243+
endmethod
244+
245+
public method GetCurrentStructure, @RpsStructure
246+
proc
247+
if (mCurrentStructure == ^null || mCurrentStructure.Count==0) then
248+
begin
249+
mreturn ^null
250+
end
251+
else
252+
begin
253+
mreturn mCurrentStructure.Peek()
254+
end
255+
endmethod
256+
257+
public method ClearCurrentStructure, void
258+
proc
259+
if (mCurrentStructure!=^null)
260+
begin
261+
using mCurrentStructure.Count select
262+
(0),
263+
nop
264+
(1),
265+
mCurrentStructure.Clear()
266+
(),
267+
nop
268+
endusing
269+
end
270+
end
271+
272+
public method AddNestedStructure, void
273+
required in aStructure, @RpsStructure
274+
proc
275+
if (mCurrentStructure == ^null || mCurrentStructure.Count==0) then
276+
begin
277+
throw new ApplicationException("Can't add a nested structure when no structure is being processed!")
278+
end
279+
else
280+
begin
281+
mCurrentStructure.Push(aStructure)
282+
end
283+
endmethod
284+
285+
public method RemoveNestedStructure, void
286+
required in aStructure, @RpsStructure
287+
proc
288+
if (mCurrentStructure == ^null || mCurrentStructure.Count<=1) then
289+
begin
290+
throw new ApplicationException("No nested structure to remove!")
291+
end
292+
else
293+
begin
294+
mCurrentStructure.Pop()
295+
end
296+
endmethod
297+
209298
public property VerboseLoggingEnabled, boolean
210299
method get
211300
proc

CodeGenEngine/CodeGenerator.dbl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ namespace CodeGen.Engine
16781678
begin
16791679
;;Set the initial context to the first structure. This isn't required for <STRUCTURE_LOOP> but will ensure that
16801680
;;the default context is <STRUCTURE#1> if <STRUCTURE_LOOP> is not used.
1681-
context.CurrentStructure = context.Structures[0]
1681+
context.SetCurrentStructure(context.Structures[0])
16821682

16831683
;;Generate the code
16841684
errStatus = expandTreeToCode(tree)
@@ -1698,7 +1698,7 @@ namespace CodeGen.Engine
16981698
else
16991699
begin
17001700
;;Set structure context
1701-
context.CurrentStructure = context.Structures[ix]
1701+
context.SetCurrentStructure(context.Structures[ix])
17021702

17031703
;;Set the file reference to use
17041704
context.CurrentFileIndex = context.StructureFileIndex[ix]
@@ -1737,7 +1737,7 @@ namespace CodeGen.Engine
17371737
data errStatus = false
17381738

17391739
if (context.Structures.Count > 0 && !context.MultiStructureMode)
1740-
context.CurrentTask.VerboseLog(String.Format(" - Processing structure {0}",context.CurrentStructure.Name))
1740+
context.CurrentTask.VerboseLog(String.Format(" - Processing structure {0}",context.GetCurrentStructure().Name))
17411741

17421742
;;Create a stream for the TreeExpander to write the generated code to
17431743
disposable data generatedCode = new StringWriter()

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorEnumLoop.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace CodeGen.Engine
8282
proc
8383
lambda isEnumLoop(node) node .is. EnumLoopNode
8484
data loop, @EnumLoopNode, ^as(loops.First(isEnumLoop), EnumLoopNode)
85-
mreturn specific(template.Context.CurrentStructure, template.Context.Repository.Enumerations, loop.CurrentEnumeration, loop.CurrentIndex)
85+
mreturn specific(template.Context.GetCurrentStructure(), template.Context.Repository.Enumerations, loop.CurrentEnumeration, loop.CurrentIndex)
8686
endmethod
8787

8888
;; -------------------------------------------------------------------------------------------------------------------------------

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorEnumMemberLoop.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace CodeGen.Engine
8484
proc
8585
lambda isEnumMemberLoop(node) node .is. EnumMemberLoopNode
8686
data loop, @EnumMemberLoopNode, ^as(loops.First(isEnumMemberLoop), EnumMemberLoopNode)
87-
mreturn specific(template.Context.CurrentStructure, loop.CurrentEnumeration, loop.CurrentMember, loop.CurrentIndex)
87+
mreturn specific(template.Context.GetCurrentStructure(), loop.CurrentEnumeration, loop.CurrentMember, loop.CurrentIndex)
8888
endmethod
8989

9090
;; -------------------------------------------------------------------------------------------------------------------------------

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorFieldLoop.dbl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ namespace CodeGen.Engine
292292
if (loop .is. FieldLoopNode) then
293293
begin
294294
;;We're in a field loop
295-
296-
str = template.Context.CurrentStructure
295+
str = template.Context.GetCurrentStructure()
297296
field = ((@FieldLoopNode)loop).CurrentField
298297
index = ((@FieldLoopNode)loop).CurrentIndex
299298
end
@@ -306,7 +305,7 @@ namespace CodeGen.Engine
306305
data relationLoop, @RelationLoopNode, ^as(loops.First(isRelationLoop), @RelationLoopNode)
307306

308307
;;Determine which structure we're dealing with, based on the TYPE of relation segment loop (FROM_KEY_SEGMENT_LOOP or TO_KEY_SEGMENT_LOOP)
309-
str = loop.OpenToken.Value.StartsWith("FROM_KEY_SEGMENT_LOOP") ? template.Context.CurrentStructure : relationLoop.ToStructure
308+
str = loop.OpenToken.Value.StartsWith("FROM_KEY_SEGMENT_LOOP") ? template.Context.GetCurrentStructure() : relationLoop.ToStructure
310309

311310
;;Now get a handle on the full definition of the key segment we're dealing with
312311
data segment, @RpsKeySegment, ((@RelationSegmentLoopNode)loop).CurrentSegment
@@ -322,7 +321,7 @@ namespace CodeGen.Engine
322321
begin
323322
;;We're in a regular key segment loop
324323
;;Get handles on the current structure, field, and index
325-
str = template.Context.CurrentStructure
324+
str = template.Context.GetCurrentStructure()
326325
field = ((@SegmentLoopNode)loop).CurrentField
327326
index = ((@SegmentLoopNode)loop).CurrentIndex
328327
end

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorFieldSelectionLoop.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace CodeGen.Engine
8181
proc
8282
lambda isSelectionLoop(node) node .is. SelectionLoopNode
8383
data loop, @SelectionLoopNode, ^as(loops.First(isSelectionLoop), SelectionLoopNode)
84-
mreturn specific(template.Context.CurrentStructure, loop.CurrentField, loop.CurrentSelection, loop.CurrentIndex)
84+
mreturn specific(template.Context.GetCurrentStructure(), loop.CurrentField, loop.CurrentSelection, loop.CurrentIndex)
8585
endmethod
8686

8787
;; -------------------------------------------------------------------------------------------------------------------------------

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorFileLoop.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ namespace CodeGen.Engine
117117
proc
118118
lambda isFileLoop(node) node .is. FileLoopNode
119119
data loop, @FileLoopNode, ^as(loops.First(isFileLoop), FileLoopNode)
120-
mreturn specific(template.Context.CurrentStructure.Files, loop.CurrentFile, loop.CurrentIndex)
120+
mreturn specific(template.Context.GetCurrentStructure().Files, loop.CurrentFile, loop.CurrentIndex)
121121
endmethod
122122

123123
;; -------------------------------------------------------------------------------------------------------------------------------

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorKeyLoop.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace CodeGen.Engine
102102
proc
103103
lambda isKeyLoop(node) node .is. KeyLoopNode
104104
data loop, @KeyLoopNode, ^as(loops.First(isKeyLoop), KeyLoopNode)
105-
mreturn specific(template.Context.CurrentStructure, loop.CurrentKey, loop.CurrentIndex, loop)
105+
mreturn specific(template.Context.GetCurrentStructure(), loop.CurrentKey, loop.CurrentIndex, loop)
106106
endmethod
107107

108108
;; -------------------------------------------------------------------------------------------------------------------------------

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorKeySegmentLoop.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ namespace CodeGen.Engine
271271
lambda isSegmentLoop(node) node .is. SegmentLoopNode
272272
data loop, @SegmentLoopNode, ^as(loops.First(isSegmentLoop), SegmentLoopNode)
273273

274-
mreturn specific(template.Context.CurrentStructure, loop.CurrentKey, loop.CurrentSegment, loop.CurrentIndex, loop.CurrentField)
274+
mreturn specific(template.Context.GetCurrentStructure(), loop.CurrentKey, loop.CurrentSegment, loop.CurrentIndex, loop.CurrentField)
275275

276276
endmethod
277277

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorRelationLoop.dbl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace CodeGen.Engine
129129
proc
130130
lambda isRelationLoop(node) node .is. RelationLoopNode
131131
data loop, @RelationLoopNode, ^as(loops.First(isRelationLoop), RelationLoopNode)
132-
mreturn specific(template.Context, template.Context.CurrentStructure, loop.CurrentRelation, loop.CurrentIndex, loop.FromKey, loop.ToStructure, loop.ToKey)
132+
mreturn specific(template.Context, template.Context.GetCurrentStructure(), loop.CurrentRelation, loop.CurrentIndex, loop.FromKey, loop.ToStructure, loop.ToKey)
133133
endmethod
134134

135135
;; -------------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)