Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
usr3-1415 committed Jan 21, 2024
1 parent 21786bb commit 994489c
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 26 deletions.
6 changes: 6 additions & 0 deletions BackendAst/DAstACN.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
7 changes: 6 additions & 1 deletion BackendAst/DAstUtilFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions CommonTypes/CommonTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand All @@ -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
Expand All @@ -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 =
Expand Down
19 changes: 12 additions & 7 deletions FrontEndAst/AcnCreateFromAntlr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions FrontEndAst/CheckLongReferences.fs
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,19 @@ let rec private checkType (r:AstRoot) (tasPositions:Map<ReferenceToType,int>) (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
Expand Down
2 changes: 1 addition & 1 deletion FrontEndAst/FE_TypeDefinition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion FrontEndAst/MapParamAstToNonParamAst.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")]
Expand Down
2 changes: 1 addition & 1 deletion StgC/acn_c.stg
Original file line number Diff line number Diff line change
Expand Up @@ -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) ::= <<
<p><sAcc>exist.<sChName> = <sExtFldName> ? 1 : 0;
<p><sAcc>exist.<sChName> = <sExtFldName> ? 1 : 0;
>>

sequence_presense_optChild_pres_int_encode(p, sAcc, sChName, sExtFldName, nIntVal) ::= ""
Expand Down

0 comments on commit 994489c

Please sign in to comment.