Skip to content

Commit

Permalink
calculate maxAlignment
Browse files Browse the repository at this point in the history
  • Loading branch information
usr3-1415 committed Jan 6, 2025
1 parent f5678c8 commit b90cc19
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 48 deletions.
37 changes: 25 additions & 12 deletions FrontEndAst/AcnCreateFromAntlr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,12 +1027,17 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (typeIdsSet : Map
(inheritInfo : InheritanceInfo option)
(typeAssignmentInfo : AssignmentInfo option)
(us:Asn1AcnMergeState) : (Asn1Type*Asn1AcnMergeState)=

let maxAlignmentOf (aligns: AcnAlignment option list): AcnAlignment option =
aligns |> List.maxBy (fun a -> a |> Option.map (fun a -> a.nbBits) |> Option.defaultValue 0I)

let acnProps =
match acnType with
| None -> []
| Some x -> x.acnProperties
let acnErrLoc = acnType |> Option.map(fun x -> x.loc)
let combinedProperties = acnProps
let alignment = tryGetProp combinedProperties (fun x -> match x with ALIGNTONEXT e -> Some e | _ -> None)
let allCons = t.Constraints@refTypeCons@withCons
let debug = ReferenceToType curPath
//if debug.AsString.EndsWith "ALPHA-DELETE-DIAGNOSTIC-PARAMETER-REPORT-STRUCTURES-GENERIC" then
Expand Down Expand Up @@ -1147,14 +1152,15 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (typeIdsSet : Map
let uperMinSizeInBits, _ = uPER.getSizeableTypeSize minSize.uper maxSize.uper newChType.uperMinSizeInBits
let _, uperMaxSizeInBits = uPER.getSizeableTypeSize minSize.uper maxSize.uper newChType.uperMaxSizeInBits

let alignment = tryGetProp combinedProperties (fun x -> match x with ALIGNTONEXT e -> Some e | _ -> None)
let acnEncodingClass, acnMinSizeInBits, acnMaxSizeInBits= AcnEncodingClasses.GetSequenceOfEncodingClass alignment loc acnProperties uperMinSizeInBits uperMaxSizeInBits minSize.acn maxSize.acn newChType.acnMinSizeInBits newChType.acnMaxSizeInBits hasNCount
// (acnAlignment : AcnGenericTypes.AcnAlignment option) (child : Asn1AcnAst.Asn1Type) (childType: DAst.Asn1Type)
let maxAlignment = maxAlignmentOf [alignment; newChType.maxAlignment]

let definitionOrRef =
lms |> List.map(fun (l,lm) ->
(l, DAstTypeDefinition.createSequenceOf_u lm (ReferenceToType curPath) typeDef acnMinSizeInBits acnMaxSizeInBits minSize maxSize acnEncodingClass alignment newChType)) |> Map.ofList
(l, DAstTypeDefinition.createSequenceOf_u lm (ReferenceToType curPath) typeDef acnMinSizeInBits acnMaxSizeInBits minSize maxSize acnEncodingClass alignment maxAlignment newChType)) |> Map.ofList

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; acnArgs=acnArgsSubsted; typeDef=typeDef; definitionOrRef=definitionOrRef}
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; acnArgs=acnArgsSubsted; typeDef=typeDef; definitionOrRef=definitionOrRef; maxAlignment=maxAlignment}
SequenceOf newKind, us2
| Asn1Ast.Sequence children ->
let childrenNameConstraints = allCons |> List.choose(fun c -> match c with Asn1Ast.WithComponentsConstraint (_,w) -> Some w| _ -> None) |> List.collect id
Expand Down Expand Up @@ -1326,13 +1332,16 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (typeIdsSet : Map
}

let acnArgsSubsted = substAcnArgs acnParamSubst acnArgs
// (acnProperties : AcnGenericTypes.SequenceAcnProperties) (acnMaxSizeInBits : BigInteger) (children:SeqChildInfo list) =

let childrenAlignemts = mergedChildren |> List.map(fun c -> match c with Asn1Child c -> c.Type.maxAlignment | AcnChild c -> c.Type.acnAlignment)
let maxAlignment = maxAlignmentOf (alignment::childrenAlignemts)

let definitionOrRef =
lms |> List.map(fun (l,lm) ->
let acnAlignment = tryGetProp combinedProperties (fun x -> match x with ALIGNTONEXT e -> Some e | _ -> None)
(l, DAstTypeDefinition.createSequence_u asn1.args lm typeDef (ReferenceToType curPath) acnAlignment acnProperties acnMinSizeInBits acnMaxSizeInBits mergedChildren)) |> Map.ofList
(l, DAstTypeDefinition.createSequence_u asn1.args lm typeDef (ReferenceToType curPath) acnAlignment maxAlignment acnProperties acnMinSizeInBits acnMaxSizeInBits mergedChildren)) |> Map.ofList

Sequence ({Sequence.children = mergedChildren; acnProperties=acnProperties; cons=cons; withcons = wcons;uperMaxSizeInBits=uperBitMaskSize+uperMaxChildrenSize; uperMinSizeInBits=uperBitMaskSize+uperMinChildrenSize;acnMaxSizeInBits=acnMaxSizeInBits;acnMinSizeInBits=acnMinSizeInBits; acnArgs=acnArgsSubsted; typeDef=typeDef; definitionOrRef=definitionOrRef}), chus
Sequence ({Sequence.children = mergedChildren; acnProperties=acnProperties; cons=cons; withcons = wcons;uperMaxSizeInBits=uperBitMaskSize+uperMaxChildrenSize; uperMinSizeInBits=uperBitMaskSize+uperMinChildrenSize;acnMaxSizeInBits=acnMaxSizeInBits;acnMinSizeInBits=acnMinSizeInBits; acnArgs=acnArgsSubsted; typeDef=typeDef; definitionOrRef=definitionOrRef; maxAlignment=maxAlignment}), chus
| Asn1Ast.Choice children ->
let childrenNameConstraints = t.Constraints@refTypeCons |> List.choose(fun c -> match c with Asn1Ast.WithComponentsConstraint (_,w) -> Some w| _ -> None) |> List.collect id
let myVisibleConstraints = t.Constraints@refTypeCons
Expand Down Expand Up @@ -1447,7 +1456,6 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (typeIdsSet : Map
let minChildSize = mergedChildren |> List.map(fun x -> x.Type.uperMinSizeInBits) |> Seq.min
let maxChildSize = mergedChildren |> List.map(fun x -> x.Type.uperMaxSizeInBits) |> Seq.max

let alignment = tryGetProp combinedProperties (fun x -> match x with ALIGNTONEXT e -> Some e | _ -> None)
let acnMinSizeInBits, acnMaxSizeInBits = AcnEncodingClasses.GetChoiceEncodingClass mergedChildren alignment t.Location acnProperties
// TODO: Voir si cela ne prove pas de dup? + SequenceOf
// let detArg = acnType |> Option.bind (fun acnType -> acnType.acnProperties |> List.tryFindMap (fun prop ->
Expand All @@ -1456,15 +1464,18 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (typeIdsSet : Map
// | _ -> None))
// let detArgSubsted = detArg |> Option.map (fun detArg -> substAcnArg acnParamSubst detArg)
let allAcnArgsSubsted = substAcnArgs acnParamSubst acnArgs
// let allAcnArgsSubsted = acnArgsSubsted @ (detArgSubsted |> Option.toList)

let childrenAlignemts = mergedChildren |> List.map(fun c -> c.Type.maxAlignment)
let maxAlignment = maxAlignmentOf (alignment::childrenAlignemts)

let definitionOrRef =
lms |> List.map(fun (l,lm) ->
let acnAlignment = tryGetProp combinedProperties (fun x -> match x with ALIGNTONEXT e -> Some e | _ -> None)
(l, DAstTypeDefinition.createChoice_u asn1.args typeIdsSet lm typeDef (ReferenceToType curPath) acnProperties acnAlignment acnMinSizeInBits acnMaxSizeInBits mergedChildren)) |> Map.ofList
(l, DAstTypeDefinition.createChoice_u asn1.args typeIdsSet lm typeDef (ReferenceToType curPath) acnProperties acnAlignment maxAlignment acnMinSizeInBits acnMaxSizeInBits mergedChildren)) |> Map.ofList

Choice ({Choice.children = mergedChildren; acnProperties = acnProperties; cons=cons; withcons = wcons;
uperMaxSizeInBits=indexSize+maxChildSize; uperMinSizeInBits=indexSize+minChildSize; acnMinSizeInBits =acnMinSizeInBits;
acnMaxSizeInBits=acnMaxSizeInBits; acnParameters = acnParameters; acnArgs = allAcnArgsSubsted; acnLoc = acnLoc; typeDef=typeDef; definitionOrRef=definitionOrRef}), chus
acnMaxSizeInBits=acnMaxSizeInBits; acnParameters = acnParameters; acnArgs = allAcnArgsSubsted; acnLoc = acnLoc; typeDef=typeDef; definitionOrRef=definitionOrRef; maxAlignment=maxAlignment}), chus

| Asn1Ast.ReferenceType rf ->
let acnArguments = acnArgs
Expand Down Expand Up @@ -1522,7 +1533,6 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (typeIdsSet : Map
let toByte sizeInBits =
sizeInBits/8I + (if sizeInBits % 8I = 0I then 0I else 1I)

let alignment = tryGetProp combinedProperties (fun x -> match x with ALIGNTONEXT e -> Some e | _ -> None)

let uperMinSizeInBits, uperMaxSizeInBits, acnMinSizeInBits, acnMaxSizeInBits, encodingOptions =
match rf.refEnc with
Expand Down Expand Up @@ -1555,8 +1565,11 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (typeIdsSet : Map
let acnEncodingClass, acnMinSizeInBits, acnMaxSizeInBits= AcnEncodingClasses.GetOctetStringEncodingClass alignment loc acnProperties uperMinSizeInBits uperMaxSizeInBits minSize.acn maxSize.acn hasNCount

uperMinSizeInBits, uperMaxSizeInBits, acnMinSizeInBits, acnMaxSizeInBits, (Some {EncodeWithinOctetOrBitStringProperties.acnEncodingClass = acnEncodingClass; octOrBitStr = ContainedInOctString; minSize = minSize; maxSize=maxSize})

let maxAlignment = maxAlignmentOf [alignment; resolvedType.maxAlignment]

let definitionOrRef = resolvedType.typeDefinitionOrReference
let newRef = {ReferenceType.modName = rf.modName; tasName = rf.tasName; tabularized = rf.tabularized; acnArguments = acnArguments; resolvedType=resolvedType; hasConstraints = hasAdditionalConstraints; typeDef=typeDef; uperMaxSizeInBits = uperMaxSizeInBits; uperMinSizeInBits = uperMinSizeInBits; acnMaxSizeInBits = acnMaxSizeInBits; acnMinSizeInBits = acnMinSizeInBits; encodingOptions=encodingOptions; hasExtraConstrainsOrChildrenOrAcnArgs=hasExtraConstrainsOrChildrenOrAcnArgs; refCons = refCons;definitionOrRef=definitionOrRef}
let newRef = {ReferenceType.modName = rf.modName; tasName = rf.tasName; tabularized = rf.tabularized; acnArguments = acnArguments; resolvedType=resolvedType; hasConstraints = hasAdditionalConstraints; typeDef=typeDef; uperMaxSizeInBits = uperMaxSizeInBits; uperMinSizeInBits = uperMinSizeInBits; acnMaxSizeInBits = acnMaxSizeInBits; acnMinSizeInBits = acnMinSizeInBits; encodingOptions=encodingOptions; hasExtraConstrainsOrChildrenOrAcnArgs=hasExtraConstrainsOrChildrenOrAcnArgs; refCons = refCons;definitionOrRef=definitionOrRef; maxAlignment=maxAlignment}
ReferenceType newRef, us2

{
Expand Down
13 changes: 13 additions & 0 deletions FrontEndAst/Asn1AcnAst.fs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,15 @@ type Asn1Type = {
| OctetString os -> os.acnArgs
| BitString bs -> bs.acnArgs
| _ -> []

member this.maxAlignment =
match this.Kind with
| Sequence sq -> sq.maxAlignment
| SequenceOf sqf -> sqf.maxAlignment
| Choice ch -> ch.maxAlignment
| ReferenceType tp -> tp.maxAlignment
| _ -> this.acnAlignment


and Asn1TypeKind =
| Integer of Integer
Expand Down Expand Up @@ -733,6 +742,7 @@ and SequenceOf = {
acnArgs : RelativePath list
typeDef : Map<ProgrammingLanguage, FE_SizeableTypeDefinition>
definitionOrRef : Map<ProgrammingLanguage, TypeDefinitionOrReference>
maxAlignment : AcnAlignment option

}

Expand All @@ -748,6 +758,7 @@ and Sequence = {
acnArgs : RelativePath list
typeDef : Map<ProgrammingLanguage, FE_SequenceTypeDefinition>
definitionOrRef : Map<ProgrammingLanguage, TypeDefinitionOrReference>
maxAlignment : AcnAlignment option
}

and AcnChild = {
Expand Down Expand Up @@ -796,6 +807,7 @@ and Choice = {
acnLoc : SrcLoc option
typeDef : Map<ProgrammingLanguage, FE_ChoiceTypeDefinition>
definitionOrRef : Map<ProgrammingLanguage, TypeDefinitionOrReference>
maxAlignment : AcnAlignment option
}

and ChChildInfo = {
Expand Down Expand Up @@ -837,6 +849,7 @@ and ReferenceType = {
encodingOptions : EncodeWithinOctetOrBitStringProperties option
refCons : AnyConstraint list
definitionOrRef : Map<ProgrammingLanguage, TypeDefinitionOrReference>
maxAlignment : AcnAlignment option
}

type Asn1AcnType =
Expand Down
12 changes: 6 additions & 6 deletions FrontEndAst/DAstTypeDefinition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ let createEnumerated_u (args:CommandLineSettings) (lm:LanguageMacros) (id:Refer
| NonPrimitiveReference2OtherType ->
ReferenceToExistingDefinition {ReferenceToExistingDefinition.programUnit = (if td.programUnit = programUnit then None else Some td.programUnit); typedefName= td.typeName; definedInRtl = false}

let createSequenceOf_u (lm:LanguageMacros) (id:ReferenceToType) (typeDef : Map<ProgrammingLanguage, FE_SizeableTypeDefinition>) (acnMinSizeInBits : BigInteger) (acnMaxSizeInBits : BigInteger) (minSize : SIZE) (maxSize : SIZE) (acnEncodingClass : Asn1AcnAst.SizeableAcnEncodingClass) (acnAlignment : AcnGenericTypes.AcnAlignment option) (child : Asn1AcnAst.Asn1Type) =
let createSequenceOf_u (lm:LanguageMacros) (id:ReferenceToType) (typeDef : Map<ProgrammingLanguage, FE_SizeableTypeDefinition>) (acnMinSizeInBits : BigInteger) (acnMaxSizeInBits : BigInteger) (minSize : SIZE) (maxSize : SIZE) (acnEncodingClass : Asn1AcnAst.SizeableAcnEncodingClass) (acnAlignment : AcnGenericTypes.AcnAlignment option) (maxAlignment: AcnGenericTypes.AcnAlignment option) (child : Asn1AcnAst.Asn1Type) =
let childTypeDefinitionOrReference = lm.lg.definitionOrRef child.typeDefinitionOrReference
let createSequenceOf () =
let define_new_sequence_of = lm.typeDef.Define_new_sequence_of
Expand All @@ -448,7 +448,7 @@ let createSequenceOf_u (lm:LanguageMacros) (id:ReferenceToType) (typeDef : Map<
match td.kind with
| NonPrimitiveNewTypeDefinition ->
let invariants = lm.lg.generateSequenceOfInvariants minSize maxSize
let sizeClsDefinitions, sizeObjDefinitions = lm.lg.generateSequenceOfSizeDefinitions typeDef acnMinSizeInBits acnMaxSizeInBits maxSize acnEncodingClass acnAlignment child
let sizeClsDefinitions, sizeObjDefinitions = lm.lg.generateSequenceOfSizeDefinitions typeDef acnMinSizeInBits acnMaxSizeInBits maxSize acnEncodingClass acnAlignment maxAlignment child
let completeDefinition = define_new_sequence_of td minSize.uper maxSize.uper (minSize.uper = maxSize.uper) (childTypeDefinitionOrReference.longTypedefName2 lm.lg.hasModules) (getChildDefinition childTypeDefinitionOrReference) sizeClsDefinitions sizeObjDefinitions invariants
let privateDefinition =
match childTypeDefinitionOrReference with
Expand Down Expand Up @@ -481,7 +481,7 @@ let createSequenceOf_u (lm:LanguageMacros) (id:ReferenceToType) (typeDef : Map<
ReferenceToExistingDefinition {ReferenceToExistingDefinition.programUnit = (if td.programUnit = programUnit then None else Some td.programUnit); typedefName= td.typeName; definedInRtl = false}


let createSequence_u (args:CommandLineSettings) (lm:LanguageMacros) (typeDef:Map<ProgrammingLanguage, FE_SequenceTypeDefinition>) (id: ReferenceToType) (acnAlignment : AcnGenericTypes.AcnAlignment option) (acnProperties : AcnGenericTypes.SequenceAcnProperties) (acnMinSizeInBits : BigInteger) (acnMaxSizeInBits : BigInteger) (children:Asn1AcnAst.SeqChildInfo list) =
let createSequence_u (args:CommandLineSettings) (lm:LanguageMacros) (typeDef:Map<ProgrammingLanguage, FE_SequenceTypeDefinition>) (id: ReferenceToType) (acnAlignment : AcnGenericTypes.AcnAlignment option) (maxAlignment: AcnGenericTypes.AcnAlignment option) (acnProperties : AcnGenericTypes.SequenceAcnProperties) (acnMinSizeInBits : BigInteger) (acnMaxSizeInBits : BigInteger) (children:Asn1AcnAst.SeqChildInfo list) =
let createSequence (allchildren: Asn1AcnAst.SeqChildInfo list) =
let define_new_sequence = lm.typeDef.Define_new_sequence
let define_new_sequence_child = lm.typeDef.Define_new_sequence_child
Expand Down Expand Up @@ -525,7 +525,7 @@ let createSequence_u (args:CommandLineSettings) (lm:LanguageMacros) (typeDef:Map
match td.kind with
| NonPrimitiveNewTypeDefinition ->
let invariants = lm.lg.generateSequenceInvariants children
let sizeDefinitions = lm.lg.generateSequenceSizeDefinitions acnAlignment acnMinSizeInBits acnMaxSizeInBits allchildren
let sizeDefinitions = lm.lg.generateSequenceSizeDefinitions acnAlignment maxAlignment acnMinSizeInBits acnMaxSizeInBits allchildren
let completeDefinition = define_new_sequence td arrsChildren arrsOptionalChildren childrenCompleteDefinitions arrsNullFieldsSavePos sizeDefinitions invariants
let privateDef =
match childrenPrivatePart with
Expand Down Expand Up @@ -553,7 +553,7 @@ let createSequence_u (args:CommandLineSettings) (lm:LanguageMacros) (typeDef:Map
| NonPrimitiveReference2OtherType ->
ReferenceToExistingDefinition {ReferenceToExistingDefinition.programUnit = (if td.programUnit = programUnit then None else Some td.programUnit); typedefName= td.typeName; definedInRtl = false}

let createChoice_u (args:CommandLineSettings) (typeIdsSet : Map<String,int>) (lm:LanguageMacros) (typeDef:Map<ProgrammingLanguage, FE_ChoiceTypeDefinition>) (id: ReferenceToType) (acnProperties : AcnGenericTypes.ChoiceAcnProperties) (acnAlignment : AcnGenericTypes.AcnAlignment option) (acnMinSizeInBits : BigInteger) (acnMaxSizeInBits : BigInteger) (children:Asn1AcnAst.ChChildInfo list) =
let createChoice_u (args:CommandLineSettings) (typeIdsSet : Map<String,int>) (lm:LanguageMacros) (typeDef:Map<ProgrammingLanguage, FE_ChoiceTypeDefinition>) (id: ReferenceToType) (acnProperties : AcnGenericTypes.ChoiceAcnProperties) (acnAlignment : AcnGenericTypes.AcnAlignment option) (maxAlignment: AcnGenericTypes.AcnAlignment option) (acnMinSizeInBits : BigInteger) (acnMaxSizeInBits : BigInteger) (children:Asn1AcnAst.ChChildInfo list) =
let createChoice (children:Asn1AcnAst.ChChildInfo list) =
let define_new_choice = lm.typeDef.Define_new_choice
let define_new_choice_child = lm.typeDef.Define_new_choice_child
Expand All @@ -580,7 +580,7 @@ let createChoice_u (args:CommandLineSettings) (typeIdsSet : Map<String,int>) (lm

match td.kind with
| NonPrimitiveNewTypeDefinition ->
let sizeDefinitions = lm.lg.generateChoiceSizeDefinitions acnAlignment acnMinSizeInBits acnMaxSizeInBits typeDef children
let sizeDefinitions = lm.lg.generateChoiceSizeDefinitions acnAlignment maxAlignment acnMinSizeInBits acnMaxSizeInBits typeDef children
let completeDefinition = define_new_choice td (lm.lg.choiceIDForNone typeIdsSet id) (lm.lg.presentWhenName0 None children.Head) arrsChildren arrsPresent arrsCombined nIndexMax childrenCompleteDefinitions sizeDefinitions
Some (completeDefinition, privatePart)
| NonPrimitiveNewSubTypeDefinition subDef ->
Expand Down
Loading

0 comments on commit b90cc19

Please sign in to comment.