Skip to content

Commit

Permalink
Added two new parameter loop expansion tokens <PARAMETER_MAXVALUE> an…
Browse files Browse the repository at this point in the history
…d <PARAMETER_MINVALUE>. Also added a tagloop expansion token <TAGLOOP_TAG_VALUE_QUOTED>.
  • Loading branch information
SteveIves committed Oct 13, 2023
1 parent fb619b0 commit ca493ea
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 2 deletions.
94 changes: 92 additions & 2 deletions CodeGenEngine/TokenExpanders/TokenExpanderParameterLoop.dbl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ namespace CodeGen.Engine
parameterLoopTokenExpanders.Add("PARAMETER_SIZE", expandParameterSize)
parameterLoopTokenExpanders.Add("PARAMETER_PRECISION", expandParameterPrecision)
parameterLoopTokenExpanders.Add("PARAMETER_ENUM", expandParameterEnum)
parameterLoopTokenExpanders.Add("PARAMETER_MAXVALUE", expandParameterMaxValue)
parameterLoopTokenExpanders.Add("PARAMETER_MINVALUE", expandParameterMinValue)
parameterLoopTokenExpanders.Add("PARAMETER_STRUCTURE", expandParameterStructure)
parameterLoopTokenExpanders.Add("PARAMETER_STRUCTURE_NOPLURAL", expandParameterStructure)
parameterLoopTokenExpanders.Add("PARAMETER_STRUCTURE_PLURAL", expandParameterStructure)
Expand Down Expand Up @@ -631,7 +633,10 @@ namespace CodeGen.Engine
if (template.Context.CurrentTask.Tweaks != ^null && template.Context.CurrentTask.Tweaks.Contains("PARAMDEFSTR"))
begin
strPrefix = "str"
strName = StringTools.PascalCase(param.StructureName.EndsWith("S") ? param.StructureName.Substring(0,param.StructureName.Length-1) : param.StructureName)
if (template.Context.CurrentTask.NoCustomPluralization) then
strName = StringTools.PascalCase(param.StructureName)
else
strName = StringTools.PascalCase(param.StructureName.EndsWith("S") ? param.StructureName.Substring(0,param.StructureName.Length-1) : param.StructureName)
end
mreturn String.Format("{0}{1}{2}",arraySpec,strPrefix,strName)
end
Expand Down Expand Up @@ -700,7 +705,10 @@ namespace CodeGen.Engine
if (template.Context.CurrentTask.Tweaks != ^null && template.Context.CurrentTask.Tweaks.Contains("PARAMDEFSTR"))
begin
strPrefix = "str"
strName = StringTools.PascalCase(param.StructureName.EndsWith("S") ? param.StructureName.Substring(0,param.StructureName.Length-1) : param.StructureName)
if (template.Context.CurrentTask.NoCustomPluralization) then
strName = StringTools.PascalCase(param.StructureName)
else
strName = StringTools.PascalCase(param.StructureName.EndsWith("S") ? param.StructureName.Substring(0,param.StructureName.Length-1) : param.StructureName)
end
mreturn String.Format("{0}{1}",strPrefix,strName)
end
Expand Down Expand Up @@ -764,6 +772,88 @@ namespace CodeGen.Engine
mreturn ExpandParameterLoopToken(tkn, template, loops, doExpand)
endmethod

private static method expandParameterMaxValue, string
tkn, @Token
template, @FileNode
loops, @IEnumerable<LoopNode>
endparams
proc
lambda doExpand(catalog,iface,meth,param)
begin
data maxValue = String.Empty
data nines, a28, "9999999999999999999999999999"
using param.Type select
(ParameterType.Decimal),
begin
maxValue = nines(1:param.Size)
end
(ParameterType.Integer),
begin
using param.Size select
(1),
maxValue = "127"
(2),
maxValue = "32767"
(4),
maxValue = "2147483647"
(8),
maxValue = "9223372036854775807"
endusing
end
(ParameterType.ImpliedDecimal),
begin
maxValue = String.Format("{0}.{1}",nines(1:param.Size-param.Precision),nines(1:param.Precision))
end
(),
nop
endusing

mreturn maxValue
end
mreturn ExpandParameterLoopToken(tkn, template, loops, doExpand)
endmethod

private static method expandParameterMinValue, string
tkn, @Token
template, @FileNode
loops, @IEnumerable<LoopNode>
endparams
proc
lambda doExpand(catalog,iface,meth,param)
begin
data minValue = String.Empty
data nines, a28, "9999999999999999999999999999"
using param.Type select
(ParameterType.Decimal),
begin
minValue = String.Format("-{0}",nines(1:param.Size))
end
(ParameterType.Integer),
begin
using param.Size select
(1),
minValue = "-128"
(2),
minValue = "-32768"
(4),
minValue = "-2147483648"
(8),
minValue = "-9223372036854775808"
endusing
end
(ParameterType.ImpliedDecimal),
begin
minValue = String.Format("-{0}.{1}",nines(1:param.Size-param.Precision),nines(1:param.Precision))
end
(),
nop
endusing

mreturn minValue
end
mreturn ExpandParameterLoopToken(tkn, template, loops, doExpand)
endmethod

private static method expandParameterStructure, string
tkn, @Token
template, @FileNode
Expand Down
43 changes: 43 additions & 0 deletions CodeGenEngine/TokenExpanders/TokenExpanderTagLoop.dbl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace CodeGen.Engine
tagLoopTokenExpanders.Add("TAGLOOP_SEQUENCE", expandTagSequence)
tagLoopTokenExpanders.Add("TAGLOOP_TAG_NAME", expandTagName)
tagLoopTokenExpanders.Add("TAGLOOP_TAG_VALUE", expandTagValue)
tagLoopTokenExpanders.Add("TAGLOOP_TAG_VALUE_QUOTED", expandTagValueQuoted)

endmethod

Expand Down Expand Up @@ -432,6 +433,48 @@ namespace CodeGen.Engine
mreturn ExpandTagLoopToken(tkn, template, loops, doExpand)
endmethod

private static method expandTagValueQuoted, string
tkn, @Token
template, @FileNode
loops, @IEnumerable<LoopNode>
endparams
proc
lambda doExpand(str, tag, index)
begin
data value, string, ""
data field, @RpsField
foreach field in str.Fields
begin
if (field.OriginalName == tag.Field)
begin
using (field.DataType) select
(RpsFieldDataType.Alpha, RpsFieldDataType.User),
begin
data tmplen, int, field.Size
if (tmplen > 15)
tmplen = 15
if (tag.ComparisonValue.Length > 0) then
begin
data tmpval, a15, tag.ComparisonValue
value = String.Format("""{0}""", tmpval(1:tmplen))
end
else
begin
data spaces, a15, " " ;15 is the max length of a tag comparison in RPS
value = String.Format("""{0}""", spaces(1:tmplen))
end
end
(),
value = String.Format("""{0}""",tag.ComparisonValue)
endusing
exitloop
end
end
mreturn value
end
mreturn ExpandTagLoopToken(tkn, template, loops, doExpand)
endmethod

endclass

endnamespace
3 changes: 3 additions & 0 deletions CodeGenEngine/Tokenizer.dbl
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ namespace CodeGen.Engine
& { new TokenMeta() {Name = "TAGLOOP_SEQUENCE", TypeOfToken = TokenType.TagLoop, IsPaired = false, Validity = TokenValidity.TagLoop, RequiresRepository = true} },
& { new TokenMeta() {Name = "TAGLOOP_TAG_NAME", TypeOfToken = TokenType.TagLoop, IsPaired = false, Validity = TokenValidity.TagLoop, RequiresRepository = true} },
& { new TokenMeta() {Name = "TAGLOOP_TAG_VALUE", TypeOfToken = TokenType.TagLoop, IsPaired = false, Validity = TokenValidity.TagLoop, RequiresRepository = true} },
& { new TokenMeta() {Name = "TAGLOOP_TAG_VALUE_QUOTED", TypeOfToken = TokenType.TagLoop, IsPaired = false, Validity = TokenValidity.TagLoop, RequiresRepository = true} },
&
& { new TokenMeta() {Name = "WINDOW_HEIGHT", TypeOfToken = TokenType.Window, IsPaired = false, Validity = TokenValidity.Anywhere} },
& { new TokenMeta() {Name = "WINDOW_HEIGHTPX", TypeOfToken = TokenType.Window, IsPaired = false, Validity = TokenValidity.Anywhere} },
Expand Down Expand Up @@ -618,6 +619,8 @@ namespace CodeGen.Engine
& { makeTokenMeta_UpperLower("PARAMETER_DIRECTION", TokenType.ParameterLoop, TokenValidity.ParameterLoop, false) },
& { makeTokenMeta_UpperLower("PARAMETER_DIRECTION_PAD", TokenType.ParameterLoop, TokenValidity.ParameterLoop, false) },
& { new TokenMeta() {Name = "PARAMETER_ENUM", TypeOfToken = TokenType.ParameterLoop, IsPaired = false, Validity = TokenValidity.ParameterLoop, RequiresRepository = false} },
& { new TokenMeta() {Name = "PARAMETER_MAXVALUE", TypeOfToken = TokenType.ParameterLoop, IsPaired = false, Validity = TokenValidity.ParameterLoop, RequiresRepository = false} },
& { new TokenMeta() {Name = "PARAMETER_MINVALUE", TypeOfToken = TokenType.ParameterLoop, IsPaired = false, Validity = TokenValidity.ParameterLoop, RequiresRepository = false} },
& { makeTokenMeta_AllVariants("PARAMETER_NAME", TokenType.ParameterLoop, TokenValidity.ParameterLoop, false) },
& { new TokenMeta() {Name = "PARAMETER_NUMBER", TypeOfToken = TokenType.ParameterLoop, IsPaired = false, Validity = TokenValidity.ParameterLoop, RequiresRepository = false} },
& { new TokenMeta() {Name = "PARAMETER_PASS_BY", TypeOfToken = TokenType.ParameterLoop, IsPaired = false, Validity = TokenValidity.ParameterLoop, RequiresRepository = false} },
Expand Down
Binary file modified Documentation/CodeGen.chm
Binary file not shown.
Binary file modified Documentation/CodeGen.hsmx
Binary file not shown.

0 comments on commit ca493ea

Please sign in to comment.