Skip to content

Commit

Permalink
Remove unnecessary code and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-bucev committed Jun 6, 2024
1 parent 91e8b2e commit cb639c2
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 94 deletions.
12 changes: 8 additions & 4 deletions BackendAst/DAstACN.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ let createSequenceOfFunction (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInserted
let oct_sqf_external_field_fix_size = lm.acn.sqf_external_field_fix_size
let external_field = lm.acn.sqf_external_field
let fixedSize = lm.uper.seqOf_FixedSize
let varSize = lm.uper.seqOf_VarSize
let varSize = lm.acn.seqOf_VarSize

let ii = t.id.SequenceOfLevel + 1

Expand Down Expand Up @@ -1254,15 +1254,15 @@ let createSequenceOfFunction (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInserted
match o.isFixedSize with
| true -> None
| false ->
let funcBody = varSize pp access td i "" o.minSize.acn o.maxSize.acn nSizeInBits child.acnMinSizeInBits nIntItemMaxSize 0I childInitExpr errCode.errCodeName absOffset remBits lvl ix offset introSnap codec
let funcBody = varSize pp access td i "" o.minSize.acn o.maxSize.acn nSizeInBits child.acnMinSizeInBits nIntItemMaxSize 0I childInitExpr errCode.errCodeName absOffset remBits lvl ix offset introSnap callAux codec
Some ({AcnFuncBodyResult.funcBody = funcBody; errCodes = [errCode]; localVariables = lv@nStringLength; bValIsUnReferenced= false; bBsIsUnReferenced=false; resultExpr=resultExpr; typeEncodingKind=None; auxiliaries=auxiliaries})

| Some internalItem ->
let childErrCodes = internalItem.errCodes
let ret, localVariables =
match o.isFixedSize with
| true -> fixedSize pp td i internalItem.funcBody o.minSize.acn child.acnMinSizeInBits nIntItemMaxSize 0I childInitExpr codec, nStringLength
| false -> varSize pp access td i internalItem.funcBody o.minSize.acn o.maxSize.acn nSizeInBits child.acnMinSizeInBits nIntItemMaxSize 0I childInitExpr errCode.errCodeName absOffset remBits lvl ix offset introSnap codec, nStringLength
| false -> varSize pp access td i internalItem.funcBody o.minSize.acn o.maxSize.acn nSizeInBits child.acnMinSizeInBits nIntItemMaxSize 0I childInitExpr errCode.errCodeName absOffset remBits lvl ix offset introSnap callAux codec, nStringLength
let typeEncodingKind = internalItem.typeEncodingKind |> Option.map (fun tpe -> TypeEncodingKind.SequenceOfEncodingType (tpe, o.acnEncodingClass))
Some ({AcnFuncBodyResult.funcBody = ret; errCodes = errCode::childErrCodes; localVariables = lv@(internalItem.localVariables@localVariables); bValIsUnReferenced= false; bBsIsUnReferenced=false; resultExpr=resultExpr; typeEncodingKind=typeEncodingKind; auxiliaries=internalItem.auxiliaries @ auxiliaries})

Expand Down Expand Up @@ -1944,7 +1944,11 @@ let createSequenceFunction (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInsertedFi
| Some v ->
let defInit= child.Type.initFunction.initByAsn1Value childP (mapValue v).kind
sequence_default_child pp (lm.lg.getAccess p.arg) childName childContent.funcBody defInit existVar childContent.resultExpr childTypeDef soSaveBitStrmPosStatement codec
Some childBody, childContent.localVariables, childContent.errCodes, childContent.resultExpr, childContent.typeEncodingKind, childContent.auxiliaries, ns2
let lvs =
match child.Optionality with
| Some Asn1AcnAst.AlwaysAbsent -> []
| _ -> childContent.localVariables
Some childBody, lvs, childContent.errCodes, childContent.resultExpr, childContent.typeEncodingKind, childContent.auxiliaries, ns2

let optAux, theCombinedBody =
if presentWhenStmts.IsNone && childBody.IsNone then [], None
Expand Down
35 changes: 8 additions & 27 deletions BackendAst/DAstUPer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -617,26 +617,6 @@ let createSequenceOfFunction (r:Asn1AcnAst.AstRoot) (lm:LanguageMacros) (codec:C
let internalItem =
chFunc.funcBody childNestingScope ({p with arg = lm.lg.getArrayItem p.arg i child.isIA5String})

let sqfProofGen = {
SequenceOfLikeProofGen.acnOuterMaxSize = nestingScope.acnOuterMaxSize
uperOuterMaxSize = nestingScope.uperOuterMaxSize
nestingLevel = nestingScope.nestingLevel
nestingIx = nestingScope.nestingIx
acnMaxOffset = nestingScope.acnOffset
uperMaxOffset = nestingScope.uperOffset
typeInfo = {
uperMaxSizeBits = child.uperMaxSizeInBits
acnMaxSizeBits = child.acnMaxSizeInBits
typeKind = internalItem |> Option.bind (fun i -> i.typeEncodingKind)
}
nestingScope = nestingScope
cs = p
encDec = internalItem |> Option.map (fun i -> i.funcBody)
elemDecodeFn = None // TODO: elemDecodeFn
ixVariable = i
}
let auxiliaries, callAux = lm.lg.generateSequenceOfLikeAuxiliaries ACN (SqOf o) sqfProofGen codec

let absOffset = nestingScope.uperOffset
let remBits = nestingScope.uperOuterMaxSize - nestingScope.uperOffset
let lvl = max 0I (nestingScope.nestingLevel - 1I)
Expand All @@ -650,10 +630,10 @@ let createSequenceOfFunction (r:Asn1AcnAst.AstRoot) (lm:LanguageMacros) (codec:C
| _ when o.maxSize.uper < 65536I && o.maxSize.uper=o.minSize.uper -> None
| _ when o.maxSize.uper < 65536I && o.maxSize.uper<>o.minSize.uper ->
let funcBody = varSize pp access td i "" o.minSize.uper o.maxSize.uper nSizeInBits child.uperMinSizeInBits nIntItemMaxSize 0I childInitExpr errCode.errCodeName absOffset remBits lvl ix offset introSnap codec
Some ({UPERFuncBodyResult.funcBody = funcBody; errCodes = [errCode]; localVariables = lv@nStringLength; bValIsUnReferenced=false; bBsIsUnReferenced=false; resultExpr=resultExpr; typeEncodingKind=None; auxiliaries = auxiliaries})
Some ({UPERFuncBodyResult.funcBody = funcBody; errCodes = [errCode]; localVariables = lv@nStringLength; bValIsUnReferenced=false; bBsIsUnReferenced=false; resultExpr=resultExpr; typeEncodingKind=None; auxiliaries = []})
| _ ->
let funcBody, localVariables = handleFragmentation lm p codec errCode ii ( o.uperMaxSizeInBits) o.minSize.uper o.maxSize.uper "" nIntItemMaxSize false false
Some ({UPERFuncBodyResult.funcBody = funcBody; errCodes = [errCode]; localVariables = localVariables; bValIsUnReferenced=false; bBsIsUnReferenced=false; resultExpr=resultExpr; typeEncodingKind=None; auxiliaries = auxiliaries})
Some ({UPERFuncBodyResult.funcBody = funcBody; errCodes = [errCode]; localVariables = localVariables; bValIsUnReferenced=false; bBsIsUnReferenced=false; resultExpr=resultExpr; typeEncodingKind=None; auxiliaries = []})
| Some internalItem ->
let childErrCodes = internalItem.errCodes
let internalItemBody =
Expand All @@ -668,7 +648,7 @@ let createSequenceOfFunction (r:Asn1AcnAst.AstRoot) (lm:LanguageMacros) (codec:C
| _ when o.maxSize.uper < 65536I && o.maxSize.uper<>o.minSize.uper -> varSize pp access td i internalItemBody o.minSize.uper o.maxSize.uper nSizeInBits child.uperMinSizeInBits nIntItemMaxSize 0I childInitExpr errCode.errCodeName absOffset remBits lvl ix offset introSnap codec, nStringLength
| _ -> handleFragmentation lm p codec errCode ii ( o.uperMaxSizeInBits) o.minSize.uper o.maxSize.uper internalItemBody nIntItemMaxSize false false
let typeEncodingKind = internalItem.typeEncodingKind |> Option.map (fun tpe -> TypeEncodingKind.SequenceOfEncodingType (tpe, o.acnEncodingClass))
Some ({UPERFuncBodyResult.funcBody = ret; errCodes = errCode::childErrCodes; localVariables = lv@(localVariables@internalItem.localVariables); bValIsUnReferenced=false; bBsIsUnReferenced=false; resultExpr=resultExpr; typeEncodingKind=typeEncodingKind; auxiliaries=internalItem.auxiliaries @ auxiliaries})
Some ({UPERFuncBodyResult.funcBody = ret; errCodes = errCode::childErrCodes; localVariables = lv@(localVariables@internalItem.localVariables); bValIsUnReferenced=false; bBsIsUnReferenced=false; resultExpr=resultExpr; typeEncodingKind=typeEncodingKind; auxiliaries=internalItem.auxiliaries})
| Some baseFuncName ->
let pp, resultExpr = adaptArgumentPtr lm codec p
let funcBodyContent = callBaseTypeFunc lm pp baseFuncName codec
Expand Down Expand Up @@ -745,17 +725,18 @@ let createSequenceFunction (r:Asn1AcnAst.AstRoot) (lm:LanguageMacros) (codec:Com
uperOffset = nestingScope.uperOffset + s.uperAccBits
parents = (p, t) :: nestingScope.parents}
let chFunc = child.Type.getUperFunction codec
let newArg = lm.lg.getSeqChild p.arg childName child.Type.isIA5String child.Optionality.IsSome
let newArg = if lm.lg.usesWrappedOptional && newArg.isOptional && codec = Encode then newArg.asLast else newArg
let childP = {p with arg = newArg}
let childSel = lm.lg.getSeqChild p.arg childName child.Type.isIA5String child.Optionality.IsSome
let childP =
let newArg = if lm.lg.usesWrappedOptional && childSel.isOptional && codec = Encode then childSel.asLast else childSel
{p with arg = newArg}
let childContentResult = chFunc.funcBody childNestingScope childP
let existVar =
match codec, lm.lg.decodingKind with
| Decode, Copy -> Some (ToC (child._c_name + "_exist"))
| _ -> None

let typeInfo = {uperMaxSizeBits=child.uperMaxSizeInBits; acnMaxSizeBits=child.acnMaxSizeInBits; typeKind=childContentResult |> Option.bind (fun c -> c.typeEncodingKind)}
let props = {info = Some (Asn1Child child).toAsn1AcnAst; sel=Some childP.arg; uperMaxOffset=s.uperAccBits; acnMaxOffset=s.acnAccBits; typeInfo=typeInfo; typeKind = Asn1AcnTypeKind.Asn1 child.Type.Kind.baseKind}
let props = {info = Some (Asn1Child child).toAsn1AcnAst; sel=Some childSel; uperMaxOffset=s.uperAccBits; acnMaxOffset=s.acnAccBits; typeInfo=typeInfo; typeKind = Asn1AcnTypeKind.Asn1 child.Type.Kind.baseKind}
let newAcc = {childIx=s.childIx + 1I; uperAccBits=s.uperAccBits + child.uperMaxSizeInBits; acnAccBits=s.acnAccBits + child.acnMaxSizeInBits}

match childContentResult with
Expand Down
1 change: 1 addition & 0 deletions CommonTypes/AbstractMacros.fs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ Generated by the C stg macros with the following command
abstract member Acn_IA5String_CharIndex_External_Field_Determinant : p:string -> sErrCode:string -> nAsn1Max:BigInteger -> sExtFld:string -> td:FE_StringTypeDefinition -> nCharSize:BigInteger -> nRemainingBits:BigInteger -> codec:Codec -> string;
abstract member oct_external_field : sTypedefName:string -> p:string -> sAcc:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> bIsUnsigned:bool -> nAlignSize:BigInteger -> sErrCode:string -> codec:Codec -> string;
abstract member oct_external_field_fix_size : sTypedefName:string -> p:string -> sAcc:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> bIsUnsigned:bool -> nAlignSize:BigInteger -> sErrCode:string -> codec:Codec -> string;
abstract member seqOf_VarSize : p:string -> sAcc:string -> sTasName:string -> i:string -> sInternalItem:string -> nSizeMin:BigInteger -> nSizeMax:BigInteger -> nSizeInBits:BigInteger -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> nAlignSize:BigInteger -> sChildInitExpr:string -> sErrCode:string -> nAbsOffset:BigInteger -> nRemainingMinBits:BigInteger -> nLevel:BigInteger -> nIx:BigInteger -> nOffset:BigInteger -> bIntroSnap:bool -> soCallAux:string option -> codec:Codec -> string;
abstract member sqf_external_field : sTypeDefName:string -> p:string -> sAcc:string -> i:string -> sInternalItem:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> bIsUnsigned:bool -> nAlignSize:BigInteger -> sErrCode:string -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> sChildInitExpr:string -> bIntroSnap:bool -> soCallAux:string option -> codec:Codec -> string;
abstract member sqf_external_field_fix_size : sTypeDefName:string -> p:string -> sAcc:string -> i:string -> sInternalItem:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> bIsUnsigned:bool -> nAlignSize:BigInteger -> sErrCode:string -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> sChildInitExpr:string -> bIntroSnap:bool -> soCallAux:string option -> codec:Codec -> string;
abstract member oct_sqf_null_terminated : p:string -> sAcc:string -> i:string -> sInternalItem:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> arruNullBytes:seq<byte> -> nBitPatternLength:BigInteger -> sErrCode:string -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> codec:Codec -> string;
Expand Down
1 change: 0 additions & 1 deletion CommonTypes/AcnGenericTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ and ChildSpec = {
name : StringLoc
childEncodingSpec : AcnTypeEncodingSpec
asn1Type : AcnParamType option // if present then it indicates an ACN inserted type
inserted : bool // For ACN inserted types, whether this child comes from an insertion in the current TAS, false if it is from the original TAS
argumentList : RelativePath list
comments : string list
}
Expand Down
4 changes: 4 additions & 0 deletions CommonTypes/CommonTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ type Selection = {
if this.path.IsEmpty then this.receiverType
else (List.last this.path).selectionType

member this.dropLast: Selection =
if this.path.IsEmpty then this
else {this with path = List.initial this.path}

member this.isOptional: bool =
(not this.path.IsEmpty) &&
match List.last this.path with
Expand Down
17 changes: 7 additions & 10 deletions FrontEndAst/AcnCreateFromAntlr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -684,14 +684,12 @@ let rec private mergeAcnEncodingSpecs (thisType:AcnTypeEncodingSpec option) (bas
let e2 = baseType.children |> Seq.tryFind(fun x -> x.name = nm)
match e1, e2 with
| None, None -> None
| None, Some x ->
Some {x with inserted = false}
| Some x, None ->
Some {x with inserted = true}
| None, Some x -> Some x
| Some x, None -> Some x
| Some thisChild, Some baseChild ->
match mergeAcnEncodingSpecs (Some thisChild.childEncodingSpec) (Some baseChild.childEncodingSpec) with
| Some combinedEncodingSpec ->
Some ({name = nm; childEncodingSpec = combinedEncodingSpec; asn1Type = thisChild.asn1Type; inserted = true; argumentList = thisChild.argumentList; comments=thisChild.comments})
Some ({name = nm; childEncodingSpec = combinedEncodingSpec; asn1Type = thisChild.asn1Type; argumentList = thisChild.argumentList; comments=thisChild.comments})
| None -> None)

Some {AcnTypeEncodingSpec.acnProperties = mergedProperties; children = mergedChildren; loc = thisType.loc; comments = thisType.comments; position=thisType.position; antlrSubTree=thisType.antlrSubTree}
Expand Down Expand Up @@ -1037,7 +1035,7 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (m:Asn1Ast.Asn1Mo
let _, acnUperMaxSizeInBits = uPER.getSizeableTypeSize minSize.acn maxSize.acn newChType.acnMinSizeInBits

let alignment = tryGetProp combinedProperties (fun x -> match x with ALIGNTONEXT e -> Some e | _ -> None)
let (acnEncodingClass: SizeableAcnEncodingClass), acnMinSizeInBits, acnMaxSizeInBits= AcnEncodingClasses.GetSequenceOfEncodingClass alignment loc acnProperties uperMinSizeInBits uperMaxSizeInBits minSize.acn maxSize.acn newChType.acnMinSizeInBits newChType.acnMaxSizeInBits hasNCount
let acnEncodingClass, acnMinSizeInBits, acnMaxSizeInBits= AcnEncodingClasses.GetSequenceOfEncodingClass alignment loc acnProperties uperMinSizeInBits uperMaxSizeInBits minSize.acn maxSize.acn newChType.acnMinSizeInBits newChType.acnMaxSizeInBits hasNCount

let newKind = {SequenceOf.child=newChType; acnProperties = acnProperties; cons = cons; withcons = wcons;minSize=minSize; maxSize =maxSize; uperMaxSizeInBits = uperMaxSizeInBits; uperMinSizeInBits=uperMinSizeInBits; acnEncodingClass = acnEncodingClass; acnMinSizeInBits = acnMinSizeInBits; acnMaxSizeInBits=acnMaxSizeInBits; typeDef=typeDef}
SequenceOf newKind, us2
Expand Down Expand Up @@ -1146,7 +1144,7 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (m:Asn1Ast.Asn1Mo
| Some xx ->
//let tdprm = {GetTypeDefinition_arg.asn1TypeKind = t.Kind; loc = t.Location; curPath = (curPath@[SEQ_CHILD c.Name.Value]); typeDefPath = (typeDefPath@[SEQ_CHILD c.Name.Value]); inheritInfo =None ; typeAssignmentInfo = None; rtlFnc = None}
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; inserted = cc.inserted; Comments = cc.comments |> Seq.toArray}), us1
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 @@ -1176,7 +1174,7 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (m:Asn1Ast.Asn1Mo
match acnChild.asn1Type with
| Some xx ->
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; inserted = false; Comments = acnChild.comments |> Seq.toArray}), nest
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 Expand Up @@ -1393,8 +1391,7 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (m:Asn1Ast.Asn1Mo
let typeDef, us1 = getReferenceTypeDefinition asn1 t {tfdArg with typeDefPath = newTypeDefPath} us
let hasChildren, hasAcnProps =
match acnType with
| None ->
false, false
| None -> false, false
| Some acnEncSpec ->
let b1 = acnEncSpec.children.Length > 0
let b2 =acnEncSpec.acnProperties.Length>0
Expand Down
2 changes: 1 addition & 1 deletion FrontEndAst/AcnGenericCreateFromAntlr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ let rec private createTypeEncodingSpec integerSizeInBytes (allAcnFiles: CommonT
return e
}

return {ChildSpec.name = name; childEncodingSpec= childEncodingSpec; asn1Type=asn1Type; argumentList=argumentList; inserted = false; comments = comments |> Seq.toList}
return {ChildSpec.name = name; childEncodingSpec= childEncodingSpec; asn1Type=asn1Type; argumentList=argumentList; comments = comments |> Seq.toList}
}
childrenList.Children |> List.traverseResultM createChild
| None -> Ok []
Expand Down
Loading

0 comments on commit cb639c2

Please sign in to comment.