diff --git a/BackendAst/DAstACN.fs b/BackendAst/DAstACN.fs index ddcbd0743..c64e75d47 100644 --- a/BackendAst/DAstACN.fs +++ b/BackendAst/DAstACN.fs @@ -1642,6 +1642,12 @@ let createSequenceFunction (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInsertedFi match codec with | Codec.Encode -> None, [], ns1 | Codec.Decode -> + let getExternaField (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInsertedFieldDependencies) asn1TypeIdWithDependency = + let filterDependency (d:AcnDependency) = + match d.dependencyKind with + | AcnDepPresenceBool -> true + | _ -> false + getExternaField0 r deps asn1TypeIdWithDependency filterDependency let extField = getExternaField r deps child.Type.id Some(sequence_presense_optChild_pres_bool p.arg.p (lm.lg.getAccess p.arg) (lm.lg.getAsn1ChildBackendName child) extField codec), [], ns1 | Some (PresenceWhenBoolExpression exp) -> diff --git a/BackendAst/DAstUtilFunctions.fs b/BackendAst/DAstUtilFunctions.fs index 3f0257bce..bbd1bba98 100644 --- a/BackendAst/DAstUtilFunctions.fs +++ b/BackendAst/DAstUtilFunctions.fs @@ -16,7 +16,12 @@ let getAccessFromScopeNodeList (ReferenceToType nodes) (childTypeIsString: bool | TA _ | PRM _ | VA _ -> raise(BugErrorException "getAccessFromScopeNodeList") - | SEQ_CHILD chName -> [], {pVal with arg = lm.lg.getSeqChild pVal.arg (ToC chName) childTypeIsString false} + | SEQ_CHILD (chName, isOptional) -> + let isPresent = + match isOptional with + | true ->[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) -> let chChildIsPresent = match ST.lang with diff --git a/CommonTypes/CommonTypes.fs b/CommonTypes/CommonTypes.fs index b03c8b713..2876a926b 100644 --- a/CommonTypes/CommonTypes.fs +++ b/CommonTypes/CommonTypes.fs @@ -340,7 +340,7 @@ type ScopeNode = | MD of string //MODULE | TA of string //TYPE ASSIGNMENT | VA of string //VALUE ASSIGNMENT - | SEQ_CHILD of string //SEQUENCE child + | SEQ_CHILD of string*bool //SEQUENCE child, is optional | CH_CHILD of string*string*string //CHOICE child, choice child present when name | PRM of string //ACN parameter | SQF //SEQUENCE OF CHILD @@ -388,7 +388,7 @@ type ScopeNode with | TA strVal | VA strVal | PRM strVal - | SEQ_CHILD strVal + | SEQ_CHILD (strVal,_) | CH_CHILD (strVal,_, _) -> strVal | SQF -> "#" member this.StrValue = this.AsString @@ -451,9 +451,9 @@ type ReferenceToType with member this.AcnAbsPath = match this with | ReferenceToType path -> path |> List.map (fun i -> i.StrValue) - member this.getSeqChildId (childName:string) = - match this with - | ReferenceToType path -> ReferenceToType (path@[SEQ_CHILD childName]) + //member this.getSeqChildId (childName:string) = + // match this with + // | ReferenceToType path -> ReferenceToType (path@[SEQ_CHILD childName]) member this.getSeqOfChildId = match this with | ReferenceToType path -> ReferenceToType (path@[SQF]) @@ -466,13 +466,13 @@ type ReferenceToType with | ReferenceToType ((MD mdName)::(TA tasName)::[]) -> ReferenceToType ((MD mdName)::(TA tasName)::[PRM paramName]) | _ -> raise(BugErrorException "Cannot add parameter here. Only within TAS scope") - member this.appendLongChildId (childRelativePath:string list) = - match this with - | ReferenceToType path -> - let newTail = - childRelativePath |> - List.map(fun s ->SEQ_CHILD s) - ReferenceToType (path@newTail) + //member this.appendLongChildId (childRelativePath:string list) = + // match this with + // | ReferenceToType path -> + // let newTail = + // childRelativePath |> + // List.map(fun s ->SEQ_CHILD s) + // ReferenceToType (path@newTail) member this.beginsWith (md:string) (ts:string)= match this with | ReferenceToType((MD mdName)::(TA tasName)::[]) -> mdName = md && tasName = ts @@ -481,7 +481,7 @@ type ReferenceToType with match this with | ReferenceToType path -> match path |> List.rev |> List.head with - | SEQ_CHILD name -> name + | SEQ_CHILD (name,_) -> name | CH_CHILD (name,_,_) -> name | _ -> raise (BugErrorException "error in lastitem") member this.parentTypeId = diff --git a/FrontEndAst/AcnCreateFromAntlr.fs b/FrontEndAst/AcnCreateFromAntlr.fs index 8dd180480..500cd4eb6 100644 --- a/FrontEndAst/AcnCreateFromAntlr.fs +++ b/FrontEndAst/AcnCreateFromAntlr.fs @@ -1175,20 +1175,25 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (m:Asn1Ast.Asn1Mo | [] -> None | x::_ -> Some x Some (Optional {Optional.defaultValue = opt.defaultValue ; acnPresentWhen = acnPresentWhen}) - + let isOptional = + match newOptionality with + | None -> false + | Some AlwaysAbsent + | Some (Optional _) -> true + | Some AlwaysPresent -> false match cc with | None -> - let newChild, us1 = mergeType asn1 acn m c.Type (curPath@[SEQ_CHILD c.Name.Value]) (typeDefPath@[SEQ_CHILD c.Name.Value]) (enmItemTypeDefPath@[SEQ_CHILD c.Name.Value]) None None [] childWithCons [] [] None None us + let newChild, us1 = mergeType asn1 acn m c.Type (curPath@[SEQ_CHILD (c.Name.Value, isOptional)]) (typeDefPath@[SEQ_CHILD (c.Name.Value, isOptional)]) (enmItemTypeDefPath@[SEQ_CHILD (c.Name.Value, isOptional)]) None None [] childWithCons [] [] None None us Asn1Child ({Asn1Child.Name = c.Name; _c_name = c.c_name; _scala_name = c.scala_name; _ada_name = c.ada_name; Type = newChild; Optionality = newOptionality;asn1Comments = c.Comments |> Seq.toList; acnComments=[]}), us1 | Some cc -> match cc.asn1Type with | None -> - let newChild, us1 = mergeType asn1 acn m c.Type (curPath@[SEQ_CHILD c.Name.Value]) (typeDefPath@[SEQ_CHILD c.Name.Value]) (enmItemTypeDefPath@[SEQ_CHILD c.Name.Value]) (Some cc.childEncodingSpec) None [] childWithCons cc.argumentList [] None None us + let newChild, us1 = mergeType asn1 acn m c.Type (curPath@[SEQ_CHILD (c.Name.Value, isOptional)]) (typeDefPath@[SEQ_CHILD (c.Name.Value, isOptional)]) (enmItemTypeDefPath@[SEQ_CHILD (c.Name.Value, isOptional)]) (Some cc.childEncodingSpec) None [] childWithCons cc.argumentList [] None None us Asn1Child ({Asn1Child.Name = c.Name; _c_name = c.c_name; _scala_name = c.scala_name; _ada_name = c.ada_name; Type = newChild; Optionality = newOptionality; asn1Comments = c.Comments |> Seq.toList; acnComments = cc.comments}), us1 | Some xx -> //let tdprm = {GetTypeDifition_arg.asn1TypeKind = t.Kind; loc = t.Location; curPath = (curPath@[SEQ_CHILD c.Name.Value]); typeDefPath = (typeDefPath@[SEQ_CHILD c.Name.Value]); inferitInfo =None ; typeAssignmentInfo = None; rtlFnc = None} - let newType, us1 = mapAcnParamTypeToAcnAcnInsertedType asn1 acn xx cc.childEncodingSpec.acnProperties (curPath@[SEQ_CHILD c.Name.Value]) us - AcnChild({AcnChild.Name = c.Name; id = ReferenceToType(curPath@[SEQ_CHILD c.Name.Value]); Type = newType; Comments = cc.comments |> Seq.toArray}), us1 + let newType, us1 = mapAcnParamTypeToAcnAcnInsertedType asn1 acn xx cc.childEncodingSpec.acnProperties (curPath@[SEQ_CHILD (c.Name.Value, isOptional)]) us + AcnChild({AcnChild.Name = c.Name; id = ReferenceToType(curPath@[SEQ_CHILD (c.Name.Value, isOptional)]); Type = newType; Comments = cc.comments |> Seq.toArray}), us1 let mergedChildren, chus = match acnType with @@ -1217,8 +1222,8 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (m:Asn1Ast.Asn1Mo | None -> match acnChild.asn1Type with | Some xx -> - let newType, nest = mapAcnParamTypeToAcnAcnInsertedType asn1 acn xx acnChild.childEncodingSpec.acnProperties (curPath@[SEQ_CHILD acnChild.name.Value]) st - AcnChild({AcnChild.Name = acnChild.name; id = ReferenceToType(curPath@[SEQ_CHILD acnChild.name.Value]); Type = newType; Comments = acnChild.comments |> Seq.toArray}), nest + let newType, nest = mapAcnParamTypeToAcnAcnInsertedType asn1 acn xx acnChild.childEncodingSpec.acnProperties (curPath@[SEQ_CHILD (acnChild.name.Value, false)]) st + AcnChild({AcnChild.Name = acnChild.name; id = ReferenceToType(curPath@[SEQ_CHILD (acnChild.name.Value, false)]); Type = newType; Comments = acnChild.comments |> Seq.toArray}), nest | None -> raise(SemanticError(acnChild.name.Location, (sprintf "invalid name %s" acnChild.name.Value)))) us1 diff --git a/FrontEndAst/CheckLongReferences.fs b/FrontEndAst/CheckLongReferences.fs index 298d4e8c5..b19e44d26 100644 --- a/FrontEndAst/CheckLongReferences.fs +++ b/FrontEndAst/CheckLongReferences.fs @@ -377,13 +377,19 @@ let rec private checkType (r:AstRoot) (tasPositions:Map) (p | ValResultOK expType -> ns | ValResultError (l,errMsg) -> raise(SemanticError(l, errMsg)) | _ -> ns - checkType r tasPositions (parents@[t]) (curentPath@[SEQ_CHILD ac.Name.Value]) ac.Type ns1 + let isOptional = + match ac.Optionality with + | Some (Optional _) -> true + | Some AlwaysAbsent -> true + | Some AlwaysPresent -> true + | None -> false + checkType r tasPositions (parents@[t]) (curentPath@[SEQ_CHILD (ac.Name.Value, isOptional)]) ac.Type ns1 ) curState | Choice ch -> let ns0 = checkChoicePresentWhen r tasPositions curState (parents) t ch visibleParameters let ns1 = choiceEnumReference r tasPositions ns0 (parents) t ch visibleParameters ch.acnProperties.enumDeterminant ch.children|> - List.fold (fun ns ac -> checkType r tasPositions (parents@[t]) (curentPath@[SEQ_CHILD ac.Name.Value]) ac.Type ns ) ns1 + List.fold (fun ns ac -> checkType r tasPositions (parents@[t]) (curentPath@[CH_CHILD (ac.Name.Value,ac.present_when_name,"")]) ac.Type ns ) ns1 | ReferenceType ref -> let dummy = ref.tasName let aaa = t.id.AsString diff --git a/FrontEndAst/FE_TypeDefinition.fs b/FrontEndAst/FE_TypeDefinition.fs index 3509fd021..2e153d456 100644 --- a/FrontEndAst/FE_TypeDefinition.fs +++ b/FrontEndAst/FE_TypeDefinition.fs @@ -64,7 +64,7 @@ let getProposedTypeDefName (us:Asn1AcnMergeState) l (id:ReferenceToType) = match id with | ReferenceToType path -> match path |> List.rev |> List.head with - | SEQ_CHILD name -> name, name + | SEQ_CHILD (name,_) -> name, name | CH_CHILD (name,_,_) -> name, name | TA name -> us.args.TypePrefix + name, name | SQF -> "elem", "elem" diff --git a/FrontEndAst/MapParamAstToNonParamAst.fs b/FrontEndAst/MapParamAstToNonParamAst.fs index a406daf81..6a12c1343 100644 --- a/FrontEndAst/MapParamAstToNonParamAst.fs +++ b/FrontEndAst/MapParamAstToNonParamAst.fs @@ -49,7 +49,15 @@ let visitRefType (md:string) (ts:string) : UserDefinedTypeScope= // {UserDefinedTypeScope.typeID=[MD md; VA vs]; asn1TypeName=None; asn1VarName=Some vs;varID=[]} let visitSeqChild (s:UserDefinedTypeScope) (ch:ParameterizedAsn1Ast.ChildInfo) : UserDefinedTypeScope= - s@[SEQ_CHILD ch.Name.Value] + let isOptional = + match ch.Optionality with + | None -> false + | Some(ParameterizedAsn1Ast.AlwaysAbsent) -> true + | Some(ParameterizedAsn1Ast.AlwaysPresent) -> false + | Some(ParameterizedAsn1Ast.Optional) -> true + | Some(ParameterizedAsn1Ast.Default(_)) -> true + + s@[SEQ_CHILD (ch.Name.Value, isOptional )] let visitChoiceChild (s:UserDefinedTypeScope) (ch:ParameterizedAsn1Ast.ChildInfo) : UserDefinedTypeScope= s@[CH_CHILD (ch.Name.Value, ToC2 ch.Name.Value, "")] diff --git a/StgC/acn_c.stg b/StgC/acn_c.stg index 3793246b7..9a6024fb2 100644 --- a/StgC/acn_c.stg +++ b/StgC/acn_c.stg @@ -677,7 +677,7 @@ sequence_presense_optChild_pres_acn_expression_decode(p, sAcc, sChName, sAcnExpr sequence_presense_optChild_pres_bool_encode(p, sAcc, sChName, sExtFldName) ::= "" sequence_presense_optChild_pres_bool_decode(p, sAcc, sChName, sExtFldName) ::= << -

exist. = ? 1 : 0; +

exist. = ? 1 : 0; >> sequence_presense_optChild_pres_int_encode(p, sAcc, sChName, sExtFldName, nIntVal) ::= ""