Skip to content

Commit 30a2e2a

Browse files
committed
Added a new field loop expression <IF RELATION> that can be used to determine whether the current field is associated with the only segment of a relations FROM key. In other words, whether there is a direct outbound relation from the field to another structure.
Added a new generic expression <IF ENUMS> that can be used to determine whether any enumerations are defined in the repository. Changed the way that CodeGen behaves while processing various types of loops. Previously, if certain types of loop had no supporting data, then an error would be generated and code generation would fail. For example, if a key loop was encountered when processing a structure that had no keys, code generation would fail. Now code generation will continue, and the loop in question will be ignored. The loops affected by this change are key loops, unique key loops, alternate key loops, unique alternate key loops, primary key blocks, unique key blocks, relation loops, enumeration loops, structure enumeration loops, and file loops. Added a new command line option -elf which overrides the behavior described in the previous item, reverting to the original behavior of failing if a loop is encountered with no supporting data.
1 parent b73fb7a commit 30a2e2a

File tree

9 files changed

+208
-103
lines changed

9 files changed

+208
-103
lines changed

CodeGen/CodeGen.dbl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,14 @@ proc
460460
endusing
461461
end
462462

463+
;;-------------------------------------------------------------------------
464+
;;Should code generation fail if empty loops are encountered?
465+
466+
if (ok && CommandLineParser.Parse("elf"))
467+
begin
468+
taskSet.EmptyLoopFail = true
469+
end
470+
463471
;;-------------------------------------------------------------------------
464472
;;Do we have a custom database type specified?
465473
;;If not the default will be SqlDatabaseType.SQLServer.

CodeGen/Usage.dbl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ proc
187187
Console.WriteLine(" starting CodeGen from batch files.")
188188
Console.WriteLine("")
189189

190+
;;Limit for text -------------------------------------------------------------------------------
191+
Console.WriteLine(" -elf Restores the original CodeGen behavior failing if certain types of")
192+
Console.WriteLine(" loop are encountered with no supporting data. For example, if a key")
193+
Console.WriteLine(" loop is encountered when processing a structure with no keys.")
194+
Console.WriteLine("")
195+
190196
;;Limit for text -------------------------------------------------------------------------------
191197
Console.WriteLine(" -f [o] [l] [t] [r] [w]")
192198
Console.WriteLine(" Override default field loop processing rules.")

CodeGenEngine/CodeGenTaskSet.dbl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ namespace CodeGen.Engine
142142
;;; </summary>
143143
public readwrite property EchoCommands, Boolean
144144

145+
;;; <summary>
146+
;;; This option restores the original CodeGen behavior of causing a failure if
147+
;;; certain types of loop are encountered with no supporting data. For example, if
148+
;;; a key loop is encountered when processing a structure with no keys.
149+
;;; Setting this property to true is equivalent to using the -elf command line option.
150+
;;; </summary>
151+
public readwrite property EmptyLoopFail, Boolean
152+
145153
;;; <summary>
146154
;;; List the names of the output files generated.
147155
;;; Setting this property to true is equivalent to using the -lf command line option.

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorFieldLoop.dbl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ namespace CodeGen.Engine
228228
fieldLoopExpressionEvaluators.Add("RANGE", evaluateFieldRange)
229229
fieldLoopExpressionEvaluators.Add("READONLY", evaluateFieldReadOnly)
230230
fieldLoopExpressionEvaluators.Add("READWRITE", evaluateFieldReadWrite)
231+
fieldLoopExpressionEvaluators.Add("RELATION", evaluateFieldRelation)
231232
fieldLoopExpressionEvaluators.Add("REPORT", evaluateFieldReport)
232233
fieldLoopExpressionEvaluators.Add("REPORT_CENTER", evaluateFieldReportCenter)
233234
fieldLoopExpressionEvaluators.Add("REPORT_LEFT", evaluateFieldReportLeft)
@@ -2220,6 +2221,30 @@ namespace CodeGen.Engine
22202221
mreturn EvaluateFieldLoopExpression(tkn, template, loops, doEvaluate)
22212222
endmethod
22222223

2224+
private static method evaluateFieldRelation, boolean
2225+
tkn, @Token
2226+
template, @FileNode
2227+
loops, @IEnumerable<LoopNode>
2228+
endparams
2229+
proc
2230+
lambda doEvaluate(str, field, index)
2231+
begin
2232+
;;Return true if the field is associated with the only segment of a relations FROM key
2233+
data rel, @RpsRelation
2234+
foreach rel in str.Relations
2235+
begin
2236+
;;Is this relations FROM KEY based on the current field?
2237+
data fromKey, @RpsKey, str.Keys.FirstOrDefault(lambda(k) { k.Segments.Count==1 && k.Segments[0].SegmentType==RpsKeySegmentType.Field && k.Segments[0].field==field.Name })
2238+
if (fromKey != ^null)
2239+
begin
2240+
mreturn true
2241+
end
2242+
end
2243+
mreturn false
2244+
end
2245+
mreturn EvaluateFieldLoopExpression(tkn, template, loops, doEvaluate)
2246+
endmethod
2247+
22232248
private static method evaluateFieldReport, boolean
22242249
tkn, @Token
22252250
template, @FileNode

CodeGenEngine/ExpressionEvaluators/ExpressionEvaluatorGeneric.dbl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace CodeGen.Engine
6969
genericExpressionEvaluators.Add("DATABASE_POSTGRESQL", evaluateDatabase)
7070
genericExpressionEvaluators.Add("DATABASE_SQLSERVER", evaluateDatabase)
7171
genericExpressionEvaluators.Add("DEBUG_LOGGING", evaluateVerboseLogging)
72+
genericExpressionEvaluators.Add("ENUMS", evaluateEnums)
7273
genericExpressionEvaluators.Add("FIELD_PREFIX", evaluateFieldPrefix)
7374
genericExpressionEvaluators.Add("FIELD_SUBSET", evaluateFieldSubset)
7475
genericExpressionEvaluators.Add("MULTIPLE_STRUCTURES", evaluateMultipleStructures)
@@ -78,7 +79,7 @@ namespace CodeGen.Engine
7879
genericExpressionEvaluators.Add("VERBOSE_LOGGING", evaluateVerboseLogging)
7980

8081
;;Structure expressions
81-
82+
8283
genericExpressionEvaluators.Add("STRUCTURE_ASCII", evaluateStructureAscii)
8384
genericExpressionEvaluators.Add("STRUCTURE_FILES", evaluateStructureFiles)
8485
genericExpressionEvaluators.Add("STRUCTURE_HAS_UNIQUE_KEY", evaluateStructureHasUniqueKey)
@@ -286,6 +287,15 @@ namespace CodeGen.Engine
286287
mreturn (template.Context.VerboseLoggingEnabled)
287288
endmethod
288289

290+
private static method evaluateEnums, boolean
291+
tkn, @Token
292+
template, @FileNode
293+
loops, @IEnumerable<LoopNode>
294+
endparams
295+
proc
296+
mreturn (template.Context.Repository != ^null ? (template.Context.Repository.Enumerations.Count > 0) : false)
297+
endmethod
298+
289299
;; -------------------------------------------------------------------------------------------------------------------------------
290300
;; Structure expressions
291301

0 commit comments

Comments
 (0)