-
Notifications
You must be signed in to change notification settings - Fork 8
/
RepositoryTools.dbl
768 lines (614 loc) · 40.8 KB
/
RepositoryTools.dbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
;;*****************************************************************************
;;
;; Title: RepositoryTools.dbl
;;
;; Type: Class
;;
;; Description: Tools for working with Repository structures.
;;
;; Date: 9th November 2007
;;
;; Author: Steve Ives, Synergex Professional Services Group
;; http://www.synergex.com
;;
;;*****************************************************************************
;;
;; Copyright (c) 2012, Synergex International, Inc.
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;;
;; * Redistributions of source code must retain the above copyright notice,
;; this list of conditions and the following disclaimer.
;;
;; * Redistributions in binary form must reproduce the above copyright notice,
;; this list of conditions and the following disclaimer in the documentation
;; and/or other materials provided with the distribution.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
;; POSSIBILITY OF SUCH DAMAGE.
;;
;;*****************************************************************************
import System
import System.Collections.Generic
import CodeGen.RepositoryAPI
namespace CodeGen.Engine
public enum ValidationContext
Ok ,0
Skipped
NoFieldsInStructure
FieldSizeIssue
endenum
public partial class RepositoryTools
public static method CheckStructure, boolean
required in context, @CodeGenContext
required in Struct , @RpsStructure
endparams
stack record
errContext, ValidationContext
endrecord
proc
mreturn RepositoryTools.CheckStructure(context,Struct,errContext)
endmethod
public static method CheckStructure, boolean
required in context, @CodeGenContext
required in Struct , @RpsStructure
required out ErrContext,ValidationContext
endparams
stack record
ErrStatus, boolean
endrecord
proc
ErrStatus = false
ErrContext = ValidationContext.Ok
;; ==========================================================================================
;; STRUCTURE VALIDATION
context.CurrentTask.DebugLog(" - Checking structure " + Struct.Name)
;; Make sure the structure has not been excluded with @NOCODEGEN
if (!ErrStatus)
begin
if ((Struct.UserText.ToUpper().Contains("@NOCODEGEN"))||(Struct.LongDescription.ToUpper().Contains("@NOCODEGEN")))
begin
context.CurrentTask.DebugLog(" - Structure " + Struct.Name + " is excluded from processing by @NOCODEGEN")
ErrStatus = true
ErrContext = ValidationContext.Skipped
end
end
;; Make sure the structure has fields
if (!ErrStatus && !Struct.Fields.Count)
begin
ErrStatus = context.CurrentTask.Errorlog("Structure " + Struct.Name + " has no fields")
ErrContext = ValidationContext.NoFieldsInStructure
end
;; Do we have any tags?
if (!ErrStatus && Struct.Tags.Count)
begin
;; Make sure it's a field=value tag
if (Struct.TagType!=RpsTagType.FieldAndValue)
context.CurrentTask.Log("WARNING: Structure "+Struct.Name+" has an unsupported record length tag. Tag loop tokens may not work!")
end
;; ==========================================================================================
;; FIELD FILTERS AND VALIDATION
;; The structure seems OK, now lets look at the fields
if (!ErrStatus)
begin
data ix, int, -1 ;Index within collection of main fields
while ((ix+=1)<Struct.Fields.Count)
begin
;; Get a handle on the current field
data Field, @RpsField, Struct.Fields[ix]
;; ==================================================================================
;; No decimal fields longer than D28
if (Field.DataType == RpsFieldDataType.Decimal && Field.Precision==0 && Field.Size > 28)
begin
;;ErrStatus = context.CurrentTask.ErrorLog(String.Format("Decimal field {0}.{1} exceeds the maximum size of D28!", Struct.Name, Field.Name))
;;ErrContext = ValidationContext.FieldSizeIssue
;;exitloop
end
;; ==================================================================================
;; No implied decimal fields longer than D56.28
if (Field.DataType == RpsFieldDataType.Decimal && Field.Precision > 0)
begin
if ((Field.Size-Field.Precision) > 28 || Field.Precision > 28)
begin
;;ErrStatus = context.CurrentTask.ErrorLog(String.Format("Implied decimal field {0}.{1} exceeds the maximum size of D56.28!", Struct.Name, Field.Name))
;;ErrContext = ValidationContext.FieldSizeIssue
;;exitloop
end
end
;; ==================================================================================
;; OVERLAYS & FIELD FILTERS
;; Exclude overlays (unless overridden) and apply optional field level filters
if (
& ((!String.IsNullOrWhiteSpace(Field.OverlaysField))&&!context.CurrentTask.IncludeOverlayFields)
& || ((Field.GroupType==RpsFieldGroup.Overlay)&&!context.CurrentTask.IncludeOverlayFields)
& || (!context.CurrentTask.IgnoreExcludeLanguage&&Field.ExcludedByLanguage)
& || (context.CurrentTask.HonorExcludeToolkit&&Field.ExcludedByToolkit)
& || (context.CurrentTask.HonorExcludeReportWriter&&Field.ExcludedByReportWriter)
& || (context.CurrentTask.HonorExcludeWeb&&Field.ExcludedByWeb)
& )
begin
context.CurrentTask.DevDebugLog("Removing field " + Field.OriginalName + " because of field filters")
Struct.Fields.RemoveAt(ix)
ix-=1
nextloop
end
;; ==================================================================================
;; SUBSET PROCESSING
;; If there is a subset specified then remove all fields that are not a member of that subset
if (!String.IsNullOrWhiteSpace(context.CurrentTask.Subset)) then
begin
data subSetString, String, string.Format("@SUB={0};",context.CurrentTask.Subset)
if (!Field.UserText.ToUpper().Contains(subSetString)&&!Field.LongDescription.ToUpper().Contains(subSetString))
begin
context.CurrentTask.DevDebugLog("Removing field " + Field.OriginalName + ", not a subset member")
Struct.Fields.RemoveAt(ix)
ix-=1
nextloop
end
end
else if (context.CurrentTask.SubsetFields.Count > 0)
begin
data subsetField, @Tuple<String, String>
data foundField, boolean, false
foreach subsetField in context.CurrentTask.SubsetFields
begin
if ((subsetField.Item1 == Struct.Name) && (subsetField.Item2 == Field.OriginalName))
begin
foundField = true
exitloop
end
end
if (foundField) then
context.CurrentTask.DevDebugLog("Retaining field " + Field.OriginalName + " as a subset member")
else
begin
context.CurrentTask.DevDebugLog("Removing field " + Field.OriginalName + ", not a subset member")
Struct.Fields.RemoveAt(ix)
ix-=1
nextloop
end
end
;; ==================================================================================
;; Look for the structures display field
if (!Struct.DisplayField)
if ((instr(1,Field.UserText.ToUpper(),"@CODEGEN_DISPLAY_FIELD"))||(instr(1,Field.LongDescription.ToUpper(),"@CODEGEN_DISPLAY_FIELD")))
Struct.DisplayField = Field.Name
;; ==================================================================================
;We have a field that we're keeping - set the FieldNumber property
Field.FieldNumber = ix+1
end
end
;; ==========================================================================================
;; FIELD PROCESSING
if (!ErrStatus)
begin
data ix ,int, -1 ;Index within collection of main fields
data gfix ,int ;Index within the fields of a group which is being processed
while ((ix+=1)<Struct.Fields.Count)
begin
;; Get a handle on the current field
data Field, @RpsField, Struct.Fields[ix]
; ;; To assist debugging by field name
; if (Field.Name == "")
; begin
; nop ;; Place a break point here!
; end
;; ==================================================================================
;; ARRAY PROCESSING
;; Expand out array fields
if (!context.CurrentTask.PreserveArrays)
begin
data contiguousArrayIndex = 0
if ((Field.ArrayDimension[1]>1)||(Field.ArrayDimension[2])||(Field.ArrayDimension[3])||(Field.ArrayDimension[4]))
begin
data fieldsAdded, int, 0
data bytesAdded, int, 0
data mask, a3, "XXX"
data al1, int
for al1 from 1 thru Field.ArrayDimension[1]
begin
if (Field.ArrayDimension[2]||Field.ArrayDimension[3]||Field.ArrayDimension[4]) then
begin
;;At least 2 levels
data al2, int
for al2 from 1 thru Field.ArrayDimension[2]
begin
if (Field.ArrayDimension[3]||Field.ArrayDimension[4]) then
begin
;;At least 3 levels
data al3, int
for al3 from 1 thru Field.ArrayDimension[3]
begin
if (Field.ArrayDimension[4]) then
begin
;;All 4 levels
data al4, int
for al4 from 1 thru Field.ArrayDimension[4]
begin
data newField4, @RpsField
data arrayIndex4, string
arrayIndex4 = "[" + %string(al1,mask(1:%trim(%string(Field.ArrayDimension[1])))) + "," + %string(al2,mask(1:%trim(%string(Field.ArrayDimension[2])))) + "," + %string(al3,mask(1:%trim(%string(Field.ArrayDimension[3])))) + "," + %string(al4,mask(1:%trim(%string(Field.ArrayDimension[4])))) + "]"
;; Start with a copy of the current field
newField4 = new RpsField(Field)
;; Change the necessary properties
newField4.Name = Field.Name + arrayIndex4
newField4.OriginalNameModified = Field.OriginalNameModified + arrayIndex4
newField4.AlternateName = Field.AlternateName + arrayIndex4
newField4.OdbcName = StringTools.OdbcName(newField4.Name)
if (context.CurrentTask.Tweaks != ^null && context.CurrentTask.Tweaks.Contains("SQL_NAME_CONTIGUOUS_ARRAY")) then
begin
contiguousArrayIndex+=1
newField4.SqlName = String.Format("{0}{1}",Field.Name,contiguousArrayIndex==1?"":%string(contiguousArrayIndex))
end
else
begin
newField4.SqlName = StringTools.SqlName(newField4.Name)
end
;; Note: BaseName doesn't change because of array expansion
if (Field.MappedField.Length)
newField4.MappedField = Field.MappedField + arrayIndex4
if (Field.Description)
newField4.Description = Field.Description + " " + %string(al1) + " " + %string(al2) + " " + %string(al3) + " " + %string(al4)
if (Field.ReportHeading)
newField4.ReportHeading = Field.ReportHeading + " #" + %string(al1) + " " + %string(al2) + " " + %string(al3) + " " + %string(al4)
newField4.StartPosition = Field.StartPosition + bytesAdded
bytesAdded+=Field.Size
;TODO: IF OVERLAYS ARE INCLUDED THEN NEED TO UPDATE OVERLAY OFFSET?
newField4.ArrayDimension[1] = 1
newField4.ArrayDimension[2] = 0
newField4.ArrayDimension[3] = 0
newField4.ArrayDimension[4] = 0
newField4.WasArrayElement = true
newField4.OriginalElement[1] = al1
newField4.OriginalElement[2] = al2
newField4.OriginalElement[3] = al3
newField4.OriginalElement[4] = al4
;; And add it to the fields collection
if ((ix+(fieldsAdded+=1))<=Struct.Fields.Count-1) then
Struct.Fields.Insert(ix+fieldsAdded,newField4)
else
Struct.Fields.Add(newField4)
end
end
else
begin
;;Only 3 levels
data newField3, @RpsField
data arrayIndex3, string
arrayIndex3 = "[" + %string(al1,mask(1:%trim(%string(Field.ArrayDimension[1])))) + "," + %string(al2,mask(1:%trim(%string(Field.ArrayDimension[2])))) + "," + %string(al3,mask(1:%trim(%string(Field.ArrayDimension[3])))) + "]"
;; Start with a copy of the current field
newField3 = new RpsField(Field)
;; Change the necessary properties
newField3.Name = Field.Name + arrayIndex3
newField3.OriginalNameModified = Field.OriginalNameModified + arrayIndex3
newField3.AlternateName = Field.AlternateName + arrayIndex3
newField3.OdbcName = StringTools.OdbcName(newField3.Name)
if (context.CurrentTask.Tweaks != ^null && context.CurrentTask.Tweaks.Contains("SQL_NAME_CONTIGUOUS_ARRAY")) then
begin
contiguousArrayIndex+=1
newField3.SqlName = String.Format("{0}{1}",Field.Name,contiguousArrayIndex==1?"":%string(contiguousArrayIndex))
end
else
begin
newField3.SqlName = StringTools.SqlName(newField3.Name)
end
;; Note: BaseName doesn't change because of array expansion
if (Field.MappedField)
newField3.MappedField = Field.MappedField + arrayIndex3
if (Field.Description)
newField3.Description = Field.Description + " " + %string(al1) + " " + %string(al2)+ " " + %string(al3)
if (Field.ReportHeading)
newField3.ReportHeading = Field.ReportHeading + " #" + %string(al1) + " " + %string(al2)+ " " + %string(al3)
newField3.StartPosition = Field.StartPosition + bytesAdded
bytesAdded+=Field.Size
;TODO: IF OVERLAYS ARE INCLUDED THEN NEED TO UPDATE OVERLAY OFFSET?
newField3.ArrayDimension[1] = 1
newField3.ArrayDimension[2] = 0
newField3.ArrayDimension[3] = 0
newField3.WasArrayElement = true
newField3.OriginalElement[1] = al1
newField3.OriginalElement[2] = al2
newField3.OriginalElement[3] = al3
;; And add it to the fields collection
if ((ix+(fieldsAdded+=1))<=Struct.Fields.Count-1) then
Struct.Fields.Insert(ix+fieldsAdded,newField3)
else
Struct.Fields.Add(newField3)
end
end
end
else
begin
;;2 levels
data newField2, @RpsField
data arrayIndex2, string
arrayIndex2 = "[" + %string(al1,mask(1:%trim(%string(Field.ArrayDimension[1])))) + "," + %string(al2,mask(1:%trim(%string(Field.ArrayDimension[2])))) + "]"
;; Start with a copy of the current field
newField2 = new RpsField(Field)
;; Change the necessary properties
newField2.Name = Field.Name + arrayIndex2
newField2.OriginalNameModified = Field.OriginalNameModified + arrayIndex2
newField2.AlternateName = Field.AlternateName + arrayIndex2
newField2.OdbcName = StringTools.OdbcName(newField2.Name)
if (context.CurrentTask.Tweaks != ^null && context.CurrentTask.Tweaks.Contains("SQL_NAME_CONTIGUOUS_ARRAY")) then
begin
contiguousArrayIndex+=1
newField2.SqlName = String.Format("{0}{1}",Field.Name,contiguousArrayIndex==1?"":%string(contiguousArrayIndex))
end
else
begin
newField2.SqlName = StringTools.SqlName(newField2.Name)
end
;; Note: BaseName doesn't change because of array expansion
if (Field.MappedField)
newField2.MappedField = Field.MappedField + arrayIndex2
if (Field.Description)
newField2.Description = Field.Description + " " + %string(al1) + " " + %string(al2)
if (Field.ReportHeading)
newField2.ReportHeading = Field.ReportHeading + " #" + %string(al1) + " " + %string(al2)
newField2.StartPosition = Field.StartPosition + bytesAdded
bytesAdded+=Field.Size
;TODO: IF OVERLAYS ARE INCLUDED THEN NEED TO UPDATE OVERLAY OFFSET???
newField2.ArrayDimension[1] = 1
newField2.ArrayDimension[2] = 0
newField2.WasArrayElement = true
newField2.OriginalElement[1] = al1
newField2.OriginalElement[2] = al2
;; And add it to the fields collection
if ((ix+(fieldsAdded+=1))<=Struct.Fields.Count-1) then
Struct.Fields.Insert(ix+fieldsAdded,newField2)
else
Struct.Fields.Add(newField2)
end
end
end
else
begin
;;Just one level
data newField1, @RpsField
data arrayIndex1, string
arrayIndex1 = "[" + %string(al1) + "]"
;; Start with a copy of the current field
newField1 = new RpsField(Field)
;; Change the necessary properties
newField1.Name = Field.Name + arrayIndex1
newField1.OriginalNameModified = Field.OriginalNameModified + arrayIndex1
newField1.AlternateName = Field.AlternateName + arrayIndex1
newField1.OdbcName = StringTools.OdbcName(newField1.Name)
if (context.CurrentTask.Tweaks != ^null && context.CurrentTask.Tweaks.Contains("SQL_NAME_CONTIGUOUS_ARRAY")) then
begin
contiguousArrayIndex+=1
newField1.SqlName = String.Format("{0}{1}",Field.Name,contiguousArrayIndex==1?"":%string(contiguousArrayIndex))
end
else
begin
newField1.SqlName = StringTools.SqlName(newField1.Name)
end
;; Note: BaseName doesn't change because of array expansion
if (Field.MappedField)
newField1.MappedField = Field.MappedField + arrayIndex1
if (Field.Description)
newField1.Description = Field.Description + " " + %string(al1)
if (Field.ReportHeading)
newField1.ReportHeading = Field.ReportHeading + " #" + %string(al1)
newField1.StartPosition = Field.StartPosition + bytesAdded
bytesAdded+=Field.Size
;TODO: IF OVERLAYS ARE INCLUDED THEN NEED TO UPDATE OVERLAY OFFSET???
newField1.ArrayDimension[1] = 1
newField1.WasArrayElement = true
newField1.OriginalElement[1] = al1
;; And add it to the fields collection
if ((ix+(fieldsAdded+=1))<=Struct.Fields.Count-1) then
Struct.Fields.Insert(ix+fieldsAdded,newField1)
else
Struct.Fields.Add(newField1)
end
end
;; Remove the array field from the structure
Struct.Fields.RemoveAt(ix)
;; And process the same index again, it's now the first field from the array
ix-=1
nextloop
end
end
;; ==================================================================================
;; GROUP PROCESSING
;; Is the field a group?
if (Field.GroupType==RpsFieldGroup.No)
nextloop
;; ----------------------------------------------------------------------------------
;; If we get here then we have one of four types of GROUP field:
;;
;; 1. Explicit GROUP (fields defined locally)
;; 2. Implicit GROUP (fields defined by another structure)
;;
;; And if the "include overlays" command line option (-f o) was used:
;;
;; 3. Explicit GROUP OVERLAY
;; 4. Implicit GROUP OVERLAY
;; Is it an explicit group and we've been told not to expand them?
if (Field.GroupType==RpsFieldGroup.Yes && String.IsNullOrWhiteSpace(Field.GroupStructure) && context.CurrentTask.ExplicitGroupNoExpand)
begin
Field.CsType = Field.Name
Field.CsDefault = String.Format("new {0}()",Field.Name)
Field.CsNumericConvert = ""
Field.VbType = Field.Name
Field.VbDefault = String.Format("New {0}()",Field.Name)
Field.SnType = String.Format("@{0}",Field.Name)
Field.SnDefault = String.Format("new {0}()",Field.Name)
Field.SqlType = String.Format("VARCHAR({0})",%string(Field.Size))
Field.OcType = "NSString"
Field.OcDefault = '@""'
Field.OcObject = true
nextloop
end
;; Is it an implicit group and we've been told not to expand them?
if ((!String.IsNullOrWhiteSpace(Field.GroupStructure))&&context.CurrentTask.ImplicitGroupNoExpand)
begin
Field.CsType = Field.GroupStructure
Field.CsDefault = String.Format("new {0}()",Field.GroupStructure)
Field.CsNumericConvert = ""
Field.VbType = Field.GroupStructure
Field.VbDefault = String.Format("New {0}()",Field.GroupStructure)
Field.SnType = String.Format("@{0}",Field.GroupStructure)
Field.SnDefault = String.Format("new {0}()",Field.GroupStructure)
Field.SqlType = String.Format("VARCHAR({0})",%string(Field.Size))
Field.OcType = "NSString"
Field.OcDefault = '@""'
Field.OcObject = true
nextloop
end
;; Flatten the group into individual fields
for gfix from 0 thru Field.GroupFields.Count-1
begin
data tmpName, string, ""
data tmpOrigName, string, ""
data tmpOrigNameModified, string, ""
data tmpAltName, string, ""
data tmpBaseName, string, ""
data Child, @RpsField
;; Start with the group field as defined
Child = Field.GroupFields[gfix]
;; Exclude overlays (unless overridden) and apply optional field level filters
if (
& ((!String.IsNullOrWhiteSpace(Child.OverlaysField))&&!context.CurrentTask.IncludeOverlayFields)
& || ((Field.GroupType==RpsFieldGroup.Overlay) &&!context.CurrentTask.IncludeOverlayFields)
& || (!context.CurrentTask.IgnoreExcludeLanguage && Field.ExcludedByLanguage)
& || (context.CurrentTask.HonorExcludeToolkit && Field.ExcludedByToolkit)
& || (context.CurrentTask.HonorExcludeReportWriter && Field.ExcludedByReportWriter)
& || (context.CurrentTask.HonorExcludeWeb && Field.ExcludedByWeb)
& )
nextloop
;;The child field is going to become part of the parent structure, so set its "FieldNumber" property to the same as the parent field
Child.FieldNumber = Field.FieldNumber
;; If not suppressed, and no repository member prefix is specified, prefix the name with the group field name
if (!context.CurrentTask.GroupFieldNoGroupPrefix)
begin
tmpName = Field.Name + "."
tmpOrigName = Field.OriginalName + "."
tmpOrigNameModified = Field.OriginalNameModified + "."
tmpAltName = Field.AlternateName + "."
;; BaseName uses Field.Name so we get array dimensions back
tmpBaseName = Field.Name + "."
end
;; If not suppressed, and the prefix is "used by compiler", or if the "GROUPPREFIXALWAYS" tweak
;; is being used, prefix the name with the repository group field prefix
if ((!context.CurrentTask.GroupFieldNoRpsPrefix && Field.CompilerUsesGroupMemberPrefix) || (context.CurrentTask.Tweaks != ^null && context.CurrentTask.Tweaks.Contains("GROUP_PREFIX_ALWAYS")))
begin
tmpName = tmpName + Field.GroupMemberPrefix
tmpOrigName = tmpOrigName + Field.GroupMemberPrefix
tmpOrigNameModified = tmpOrigNameModified + Field.GroupMemberPrefix
tmpAltName = tmpAltName + Field.GroupMemberPrefix
tmpBaseName = tmpBaseName + Field.GroupMemberPrefix
end
;; And then add the actual group field name
tmpName = tmpName + Child.Name
tmpOrigName = tmpOrigName + Child.OriginalName
tmpOrigNameModified = tmpOrigNameModified + Child.OriginalName
tmpAltName = tmpAltName + Child.AlternateName
tmpBaseName = tmpBaseName + Child.Name
;; Change the childs field name properties
Child.Name = tmpName
Child.OriginalName = tmpOrigName
Child.OriginalNameModified = tmpOrigNameModified
Child.AlternateName = tmpAltName
Child.BaseName = tmpBaseName
Child.SqlName = StringTools.SqlName(tmpName)
Child.OdbcName = StringTools.OdbcName(tmpName)
;; Update the fields position in the record. Group field psoitions in f_info are relative to the group.
Child.StartPosition = Field.StartPosition + Child.StartPosition - 1
;; Remove the fields GROUP information
Child.GroupType = RpsFieldGroup.No
Child.GroupStructure = String.Empty
Child.GroupFields = new RpsFieldCollection()
Child.GroupMemberPrefix = String.Empty
;TODO: IF OVERLAYS ARE INCLUDED THEN NEED TO UPDATE OVERLAY OFFSET. NOT SURE IF THIS IS EVEN FEASIBLE???
;TODO: BUG: There is a problem here because for nested groups the expanded fields are not being added back in the correct sequence
;; And add it to the fields collection
if ((ix+gfix+1)<=Struct.Fields.Count-1) then
Struct.Fields.Insert(ix+gfix+1,Child)
else
Struct.Fields.Add(Child)
end
;; Finally remove the group field from the structure
Struct.Fields.RemoveAt(ix)
;; And process this index again, because it's now the first field from the group
ix-=1
end
end
if (!ErrStatus)
begin
if (Struct.Fields.Count) then
begin
;;We have a valid structure with fields, and arrays and groups have been expanded. Set the "LogicalFieldNumber" properties.
data ix, int
for ix from 0 thru Struct.Fields.Count-1
Struct.Fields[ix].LogicalFieldNumber = ix+1
end
else
begin
ErrStatus = context.CurrentTask.Errorlog("After applying CodeGen rules structure " + Struct.Name + " has no remaining fields!")
ErrContext = ValidationContext.NoFieldsInStructure
end
end
if (!ErrStatus)
begin
;;Make sure that we don't have any duplicate SqlName values.
;;This can happen if two fields names only differ by underscores.
data existingSqlNames = new List<String>()
data ix = 0
repeat
begin
data fld = Struct.Fields[ix]
data nameToTest = fld.SqlName.Replace("_","")
if (!existingSqlNames.Contains(nameToTest)) then
existingSqlNames.Add(nameToTest)
else
begin
data ctr ,int ,1
repeat
begin
ctr += 1
nameToTest = String.Format("{0}{1}",fld.SqlName.Replace("_",""),ctr)
if (!existingSqlNames.Contains(nameToTest))
exitloop
end
existingSqlNames.Add(nameToTest)
fld.SqlName = nameToTest
end
;;Are we done?
if ((ix+=1) == Struct.Fields.Count)
exitloop
end
end
;;Check for special prompt processing rules
if (!ErrStatus)
begin
;;Check for the CODEGEN_STRIP_FROM_PROMPT environment variable
data stripData, String, Environment.GetEnvironmentVariable("CODEGEN_STRIP_FROM_PROMPT")
if (!String.IsNullOrWhiteSpace(stripData))
begin
;;stripData should be a double-quote delimited string, remove the quotes to leave the data to strip
stripData = stripData.Trim().Replace('"', '')
;;Remove the data from any prompts that it is found in
data tmpField, @RpsField
foreach tmpField in Struct.Fields
if (tmpField.Prompt.Contains(stripData))
tmpField.Prompt = tmpField.Prompt.Replace(stripData,"")
end
end
mreturn !ErrStatus
endmethod
endclass
endnamespace