@@ -225,6 +225,54 @@ let adaptArgumentValue = DAstUPer.adaptArgumentValue
225225
226226let joinedOrAsIdentifier = DAstUPer.joinedOrAsIdentifier
227227
228+ (*
229+ If the type assignment has acnParameters, then no function is generated. This function can only be inlined by the calling function
230+ (i.e. by the parent type encoding function).
231+ Now, we have to make this rule recursive:
232+ A composite type (e.g SEQUENCE, choice etc ) may have references (i.e. reference types) to a type assignment that has acnParameters.
233+ In this case, the reference must have arguments in the acn in the form <arg1,arg2, ...>
234+ These argument can either ACN inserted fields or acnParameters.
235+ If the reference type is written explicitly in the acn, by the user, then the arguments must be checked to be inline with the acnParameters.
236+ If they are not, the user gets an error.
237+
238+ However, there are cases where the reference type is not written explicitly by the user in the acn grammar,
239+ but is infered by the compiler. For example,
240+
241+ The following asn1 grammar define two types:
242+ CfdpPDU ::= SEQUENCE {
243+ pdu-header PDUHeader,
244+ payload OCTET STRING (CONTAINING PayloadData)
245+ }
246+ PayloadData ::= CHOICE {
247+ file-directive FileDirectiveType,
248+ file-data FileDataType
249+ }
250+ FileDataType ::= SEQUENCE {
251+ file-data-pdu FileDataPDU
252+ }
253+
254+ However the acn grammar provides defintions only for CfdpPDU and FileDataType, not PayloadData. In fact, the PayloadData acn spec
255+ is provided inline in the CfdpPDU acn spec, not at the PayloadData Type Assignment Level.
256+ CfdpPDU [] {
257+ pdu-header [] {
258+ pdu-type PDUType [encoding pos-int, size 1],
259+ pdu-data-field-length PDUDataFieldLength [encoding pos-int, size 16]
260+ },
261+ payload [size pdu-header.pdu-data-field-length] {
262+ file-directive [present-when pdu-header.pdu-type==0],
263+ file-data <pdu-header.pdu-data-field-length> [present-when pdu-header.pdu-type==1]
264+ }
265+ }
266+ FileDataType <PDUDataFieldLength:pdu-data-field-length> [] {
267+ file-data-pdu <pdu-data-field-length> []
268+ }
269+
270+ Therefore, the compiler uses a defult acn specs for the PayloadData type assignment, which is not provided by the user.
271+ In this case the file-data reference type has no acnArgs. This means that no acn function must be generated for the FileDataType type assignment.
272+
273+ *)
274+
275+
228276let private createAcnFunction ( r : Asn1AcnAst.AstRoot )
229277 ( deps : Asn1AcnAst.AcnInsertedFieldDependencies )
230278 ( lm : LanguageMacros )
@@ -257,7 +305,11 @@ let private createAcnFunction (r: Asn1AcnAst.AstRoot)
257305 let EmitTypeAssignment_primitive = lm.acn.EmitTypeAssignment_ primitive
258306 let EmitTypeAssignment_primitive_def = lm.acn.EmitTypeAssignment_ primitive_ def
259307 let EmitTypeAssignment_def_err_code = lm.acn.EmitTypeAssignment_ def_ err_ code
308+ let EmitEncodingSizeConstants = lm.acn.EmitEncodingSizeConstants
260309
310+ let typeDefinitionName = typeDefinition.longTypedefName2 lm.lg.hasModules
311+ let sEncodingSizeConstant = EmitEncodingSizeConstants typeDefinitionName nMaxBytesInACN t.acnMaxSizeInBits
312+
261313 let funcBodyAsSeqComp ( st : State )
262314 ( prms : ( RelativePath * AcnParameter ) list )
263315 ( nestingScope : NestingScope )
@@ -327,14 +379,14 @@ let private createAcnFunction (r: Asn1AcnAst.AstRoot)
327379 let lvars = bodyResult_ localVariables |> List.map( fun ( lv : LocalVariable ) -> lm.lg.getLocalVariableDeclaration lv) |> Seq.distinct
328380 let prms = t.acnParameters |> List.map handleAcnParameter
329381 let prmNames = t.acnParameters |> List.map ( fun p -> p.c_ name)
330- let func = Some( EmitTypeAssignment_ primitive varName sStar funcName isValidFuncName ( typeDefinition.longTypedefName2 lm.lg.hasModules ) lvars bodyResult_ funcBody soSparkAnnotations sInitialExp prms prmNames ( t.acnMaxSizeInBits = 0 I) bBsIsUnreferenced bVarNameIsUnreferenced soInitFuncName funcDefAnnots precondAnnots postcondAnnots codec)
382+ let func = Some( EmitTypeAssignment_ primitive varName sStar funcName isValidFuncName typeDefinitionName lvars bodyResult_ funcBody soSparkAnnotations sInitialExp prms prmNames ( t.acnMaxSizeInBits = 0 I) bBsIsUnreferenced bVarNameIsUnreferenced soInitFuncName funcDefAnnots precondAnnots postcondAnnots codec)
331383
332384 let errCodStr =
333385 errCodes |>
334386 List.groupBy ( fun x -> x.errCodeName) |>
335387 List.map ( fun ( k , v ) -> { errCodeName = k; errCodeValue = v.Head.errCodeValue; comment = v.Head.comment}) |>
336388 List.map( fun x -> EmitTypeAssignment_ def_ err_ code x.errCodeName ( BigInteger x.errCodeValue) x.comment) |> List.distinct
337- let funcDef = Some( EmitTypeAssignment_ primitive_ def varName sStar funcName ( typeDefinition.longTypedefName2 lm.lg.hasModules ) errCodStr ( t.acnMaxSizeInBits = 0 I) nMaxBytesInACN ( t.acnMaxSizeInBits) prms soSparkAnnotations codec)
389+ let funcDef = Some( EmitTypeAssignment_ primitive_ def varName sStar funcName typeDefinitionName errCodStr ( t.acnMaxSizeInBits = 0 I) nMaxBytesInACN ( t.acnMaxSizeInBits) prms soSparkAnnotations codec)
338390 let ns2a =
339391 match t.id.topLevelTas with
340392 | None -> ns1a
@@ -367,6 +419,7 @@ let private createAcnFunction (r: Asn1AcnAst.AstRoot)
367419 funcBodyAsSeqComp = funcBodyAsSeqComp
368420 isTestVaseValid = isTestVaseValid
369421 icdTas = icdAux
422+ encodingSizeConstant = sEncodingSizeConstant
370423 }
371424 ret, ns3
372425
@@ -866,7 +919,12 @@ let createNullTypeFunction (r:Asn1AcnAst.AstRoot) (deps: Asn1AcnAst.AcnInsertedF
866919
867920
868921let getExternalField0 ( r : Asn1AcnAst.AstRoot ) ( deps : Asn1AcnAst.AcnInsertedFieldDependencies ) asn1TypeIdWithDependency func1 =
869- let dependency = deps.acnDependencies |> List.find( fun d -> d.asn1Type = asn1TypeIdWithDependency && func1 d )
922+ let dependency =
923+ match deps.acnDependencies |> List.tryFind ( fun d -> d.asn1Type = asn1TypeIdWithDependency && func1 d ) with
924+ | Some d -> d
925+ | None ->
926+ failwithf " getExternalField0: No dependency found for %A " asn1TypeIdWithDependency
927+
870928 let rec resolveParam ( prmId : ReferenceToType ) =
871929 let nodes = match prmId with ReferenceToType nodes -> nodes
872930 let lastNode = nodes |> List.rev |> List.head
@@ -1448,7 +1506,7 @@ let rec handleSingleUpdateDependency (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.Acn
14481506 | Some f ->
14491507 let fncBdRes , ns = f.funcBody us [] ( NestingScope.init asn1TypeD.acnMaxSizeInBits asn1TypeD.uperMaxSizeInBits []) { CallerScope.modName = " " ; arg = Selection.valueEmptyPath " dummy" }
14501508 match fncBdRes with
1451- | Some x -> x.errCodes, x.localVariables , ns
1509+ | Some x -> x.errCodes, [] , ns
14521510 | None -> [], [], us
14531511 | None -> [], [], us
14541512
0 commit comments