From 2f1ab0697fb91187de0584184eb0df2468cb4886 Mon Sep 17 00:00:00 2001 From: usr3-1415 <11031787+usr3-1415@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:55:48 +0200 Subject: [PATCH] #289 --- BackendAst/DAstUtilFunctions.fs | 2 +- FrontEndAst/Language.fs | 6 +++- StgAda/LangGeneric_a.fs | 2 ++ StgAda/acn_a.stg | 2 +- StgC/LangGeneric_c.fs | 5 ++- StgScala/LangGeneric_scala.fs | 5 +++ asn1scc/Program.fs | 2 +- .../acn/21-PresentWhenExpression/002.acn | 17 +++++++++ .../acn/21-PresentWhenExpression/002.asn1 | 36 +++++++++++++++++++ 9 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 v4Tests/test-cases/acn/21-PresentWhenExpression/002.acn create mode 100644 v4Tests/test-cases/acn/21-PresentWhenExpression/002.asn1 diff --git a/BackendAst/DAstUtilFunctions.fs b/BackendAst/DAstUtilFunctions.fs index bbd1bba98..917f720cd 100644 --- a/BackendAst/DAstUtilFunctions.fs +++ b/BackendAst/DAstUtilFunctions.fs @@ -19,7 +19,7 @@ let getAccessFromScopeNodeList (ReferenceToType nodes) (childTypeIsString: bool | SEQ_CHILD (chName, isOptional) -> let isPresent = match isOptional with - | true ->[sprintf "%s%sexist.%s" pVal.arg.p (lm.lg.getAccess pVal.arg) chName] + | true -> [lm.lg.getSeqChildIsPresent pVal.arg chName] //[sprintf "%s%sexist.%s" pVal.arg.p (lm.lg.getAccess pVal.arg) chName] | false -> [] isPresent, {pVal with arg = lm.lg.getSeqChild pVal.arg (ToC chName) childTypeIsString false} | CH_CHILD (chName,pre_name, chParent) -> diff --git a/FrontEndAst/Language.fs b/FrontEndAst/Language.fs index b93a1d826..364aacd30 100644 --- a/FrontEndAst/Language.fs +++ b/FrontEndAst/Language.fs @@ -103,7 +103,11 @@ type ILangGeneric () = abstract member getSequenceTypeDefinition :Map -> FE_SequenceTypeDefinition abstract member getSizeableTypeDefinition : Map -> FE_SizeableTypeDefinition - abstract member getSeqChild : FuncParamType -> string -> bool -> bool -> FuncParamType; + abstract member getSeqChild : FuncParamType -> string -> bool -> bool -> FuncParamType + + //return a string that contains code with a boolean expression that is true if the child is present + abstract member getSeqChildIsPresent : FuncParamType -> string -> string + abstract member getChChild : FuncParamType -> string -> bool -> FuncParamType; abstract member getLocalVariableDeclaration : LocalVariable -> string; abstract member getLongTypedefName : TypeDefintionOrReference -> string; diff --git a/StgAda/LangGeneric_a.fs b/StgAda/LangGeneric_a.fs index c0b355c99..ad13a40f3 100644 --- a/StgAda/LangGeneric_a.fs +++ b/StgAda/LangGeneric_a.fs @@ -212,6 +212,8 @@ type LangGeneric_a() = let encRtl = []//match r.args.encodings |> Seq.exists(fun e -> e = UPER || e = ACN || e = XER) with true -> [] | false -> ["adaasn1rtl.encoding"] encRtl@uperRtl@acnRtl@xerRtl |> List.distinct + override this.getSeqChildIsPresent (fpt:FuncParamType) (childName:string) = + sprintf "%s%sexist.%s = 1" fpt.p (this.getAccess fpt) childName override this.getSeqChild (fpt:FuncParamType) (childName:string) (childTypeIsString: bool) (removeDots: bool) = let newPath = sprintf "%s.%s" fpt.p childName diff --git a/StgAda/acn_a.stg b/StgAda/acn_a.stg index a5d99590a..6950cba8b 100644 --- a/StgAda/acn_a.stg +++ b/StgAda/acn_a.stg @@ -1271,7 +1271,7 @@ end case; checkAccessPath(arrsCheckPaths, sUpdateStatement) ::= << -if () then +if () then end if; >> diff --git a/StgC/LangGeneric_c.fs b/StgC/LangGeneric_c.fs index ffe56531a..23845b074 100644 --- a/StgC/LangGeneric_c.fs +++ b/StgC/LangGeneric_c.fs @@ -192,7 +192,10 @@ type LangGeneric_c() = override this.allowsSrcFilesWithNoFunctions = true override this.requiresValueAssignmentsInSrcFile = true override this.supportsStaticVerification = false - + + override this.getSeqChildIsPresent (fpt:FuncParamType) (childName:string) = + sprintf "%s%sexist.%s" fpt.p (this.getAccess fpt) childName + override this.getSeqChild (fpt:FuncParamType) (childName:string) (childTypeIsString: bool) (removeDots: bool) = let newPath = sprintf "%s%s%s" fpt.p (this.getAccess fpt) childName if childTypeIsString then (FIXARRAY newPath) else (VALUE newPath) diff --git a/StgScala/LangGeneric_scala.fs b/StgScala/LangGeneric_scala.fs index d03b1dae8..99c634330 100644 --- a/StgScala/LangGeneric_scala.fs +++ b/StgScala/LangGeneric_scala.fs @@ -5,6 +5,7 @@ open DAst open FsUtils open Language open System.IO +open System let getAccess_scala (fpt:FuncParamType) = match fpt with @@ -196,6 +197,10 @@ type LangGeneric_scala() = override this.requiresValueAssignmentsInSrcFile = true override this.supportsStaticVerification = false + override this.getSeqChildIsPresent (fpt:FuncParamType) (childName:string) = + //sprintf "%s%sexist.%s = 1" fpt.p (this.getAccess fpt) childName + raise (NotImplementedException()) + override this.getSeqChild (fpt:FuncParamType) (childName:string) (childTypeIsString: bool) (removeDots: bool) = let newPath = sprintf "%s%s%s" fpt.p (this.getAccess fpt) childName let newPath = if removeDots then (ToC newPath) else newPath diff --git a/asn1scc/Program.fs b/asn1scc/Program.fs index 538739a4e..8fa560ef3 100644 --- a/asn1scc/Program.fs +++ b/asn1scc/Program.fs @@ -108,7 +108,7 @@ let printVersion () = //let fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location); //let version = fvi.FileVersion; - let version = "4.5.0.22" + let version = "4.5.0.23" printfn "asn1scc version %s\n" version () diff --git a/v4Tests/test-cases/acn/21-PresentWhenExpression/002.acn b/v4Tests/test-cases/acn/21-PresentWhenExpression/002.acn new file mode 100644 index 000000000..c1e868605 --- /dev/null +++ b/v4Tests/test-cases/acn/21-PresentWhenExpression/002.acn @@ -0,0 +1,17 @@ +TEST-CASE DEFINITIONS ::= BEGIN + +MyChoiceEnum [size 32, encoding pos-int, endianness big, encode-values] + +MyTopMostSeq [] +{ + myDeterminant MyChoiceEnum [], + myBool1 BOOLEAN [], + myBool2 BOOLEAN [], + myChoice1 [present-when myBool1], + myChoice2 [present-when myBool2] +} + +MyChoice [determinant theDeterminant] + +END + diff --git a/v4Tests/test-cases/acn/21-PresentWhenExpression/002.asn1 b/v4Tests/test-cases/acn/21-PresentWhenExpression/002.asn1 new file mode 100644 index 000000000..1349bb8b7 --- /dev/null +++ b/v4Tests/test-cases/acn/21-PresentWhenExpression/002.asn1 @@ -0,0 +1,36 @@ +TEST-CASE DEFINITIONS AUTOMATIC TAGS::= BEGIN + +MyChoiceEnum ::= ENUMERATED +{ + choice1 (1), + choice2 (2) +} + +MyTopMostSeq ::= SEQUENCE +{ + myChoice1 MyChoice OPTIONAL, + myChoice2 MyChoice OPTIONAL +} + +MyChoice ::= CHOICE +{ + choice1 MyTuple, + choice2 INTEGER +} + +MyTuple ::= SEQUENCE +{ + fst INTEGER, + snd INTEGER +} + +myTest MyTopMostSeq ::= { + + myChoice1 choice1 : { fst 4, snd 2 } + +} + +END + + +--TCFS 002.acn