Skip to content

Commit a768f5b

Browse files
committed
declare user defined functions at the begining of the source generated file.
1 parent 45f3f53 commit a768f5b

File tree

13 files changed

+151
-86
lines changed

13 files changed

+151
-86
lines changed

BackendAst/DAstACN.fs

Lines changed: 80 additions & 71 deletions
Large diffs are not rendered by default.

BackendAst/DAstConstruction.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let private createAcnChild (r:Asn1AcnAst.AstRoot) (icdStgFileName:string) (deps:
5555

5656
let funcBodyDecode, ns2 =
5757
match ch.Type with
58-
| Asn1AcnAst.AcnInteger a -> DAstACN.createAcnIntegerFunction r deps lm Codec.Decode ch.id a ns1
58+
| Asn1AcnAst.AcnInteger a -> DAstACN.createAcnIntegerFunction r deps lm Codec.Decode ch.id a tdBodyWithinSeq ns1
5959
| Asn1AcnAst.AcnBoolean a -> DAstACN.createAcnBooleanFunction r deps lm Codec.Decode ch.id a ns1
6060
| Asn1AcnAst.AcnNullType a -> DAstACN.createAcnNullTypeFunction r deps lm Codec.Decode ch.id a ns1
6161
| Asn1AcnAst.AcnReferenceToEnumerated a -> DAstACN.createAcnEnumeratedFunction r deps icdStgFileName lm Codec.Decode ch.id a (defOrRef r m a) ns1

BackendAst/EncodeDecodeTestCase.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ let _createAcnEncDecFunction (r:Asn1AcnAst.AstRoot) (lm:LanguageMacros) (t:Asn1A
152152
let sStar = lm.lg.getStar p.accessPath
153153
let sAmberDecode = getAmberDecode t
154154
let sAmberIsValid = getAmberDecode t
155-
156-
match hasAcnEncodeFunction encFunc t.acnParameters t.id.tasInfo with
155+
let bHasAcnEncodeFunction = hasAcnEncodeFunction encFunc t.acnParameters t.id.tasInfo
156+
match bHasAcnEncodeFunction with
157157
| false -> None, us
158158
| true ->
159159
match funcName with
@@ -189,7 +189,7 @@ let _createAcnEncDecFunction (r:Asn1AcnAst.AstRoot) (lm:LanguageMacros) (t:Asn1A
189189
}
190190
joinItems (content.orElse "") sNestedContent
191191

192-
match hasAcnEncodeFunction encFunc t.acnParameters t.id.tasInfo with
192+
match bHasAcnEncodeFunction with
193193
| true ->
194194
let sNestedStatements =
195195
let rec printStatements statements : string option =

BackendAst/GenerateFiles.fs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ let private printUnit (r:DAst.AstRoot) (lm:LanguageMacros) (encodings: CommonTy
267267
(t.Type.acnEncFunction |> Option.toList |> List.collect (fun x -> (x.func |> Option.toList) @ x.auxiliaries)) @
268268
(t.Type.acnDecFunction |> Option.toList |> List.collect (fun x -> (x.func |> Option.toList) @ x.auxiliaries))
269269
else []
270+
270271
let allProcs =
271272
(privateDefinition |> Option.toList) @
272273
eqFuncs @ isValidFuncs @ special_init_funcs @
@@ -286,11 +287,18 @@ let private printUnit (r:DAst.AstRoot) (lm:LanguageMacros) (encodings: CommonTy
286287
[], []
287288
let rtlFiles = lm.lg.getRtlFiles r.args.encodings arrsTypeAssignments
288289
let arrsImportedFiles = rtlFiles@pu.importedUserModules@pu.importedProgramUnits |> List.distinct
290+
let arrsUserDefinedFunctions =
291+
tases |> List.collect(fun t ->
292+
(t.Type.acnEncFunction |> Option.toList |> List.collect (fun x -> x.userDefinedFunctions )) @
293+
(t.Type.acnDecFunction |> Option.toList |> List.collect (fun x -> x.userDefinedFunctions )) ) |>
294+
List.map(fun f -> f.functionProtype.Trim()) |>
295+
List.filter (fun s -> s <> "") |>
296+
List.distinct
289297
let puCorrName =
290298
match r.lang with
291299
| CommonTypes.ProgrammingLanguage.Scala -> ToC (pu.name)
292300
| _ -> pu.name
293-
let srcBody = lm.src.printSourceFile puCorrName arrsImportedFiles pu.importedTypes (arrsValueAssignments@arrsSourceAnonymousValues@arrsTypeAssignments)
301+
let srcBody = lm.src.printSourceFile puCorrName arrsImportedFiles pu.importedTypes arrsUserDefinedFunctions (arrsValueAssignments@arrsSourceAnonymousValues@arrsTypeAssignments)
294302

295303
let eqContntent =
296304
match lm.lg.allowsSrcFilesWithNoFunctions with

CommonTypes/AbstractMacros.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Generated by the C stg macros with the following command
8585
[<AbstractClass>]
8686
type ISrcBody () =
8787
abstract member rtlModuleName : unit -> string;
88-
abstract member printSourceFile : sFileNameWithoutExtension:string -> arrsIncludedFiles:seq<string> -> arrsAdaUseTypes:seq<string> -> arrsValueAndTypeAssignments:seq<string> -> string;
88+
abstract member printSourceFile : sFileNameWithoutExtension:string -> arrsIncludedFiles:seq<string> -> arrsAdaUseTypes:seq<string> -> arrsUserDefinedFunctions:seq<string> -> arrsValueAndTypeAssignments:seq<string> -> string;
8989
abstract member printTass : arrsAllProcs:seq<string> -> string;
9090

9191

@@ -369,7 +369,7 @@ Generated by the C stg macros with the following command
369369
abstract member EmitEncodingSizeConstants : sTypeDefName:string -> nMaxBytesInACN:BigInteger -> nMaxBitsInACN:BigInteger -> string;
370370
abstract member EmitTypeAssignment_primitive_def : sVarName:string -> sStar:string -> sFuncName:string -> sTypeDefName:string -> arrsErrcodes:seq<string> -> bEmptyEncodingSpace:bool -> nMaxBytesInACN:BigInteger -> nMaxBitsInACN:BigInteger -> arrsAcnPrms:seq<string> -> soSparkAnnotations:string option -> codec:Codec -> string;
371371
abstract member EmitTypeAssignment_primitive : sVarName:string -> sStar:string -> sFuncName:string -> soIValidFuncName:string option -> sTypeDefName:string -> arrsLocalVariables:seq<string> -> sContent:string -> soSparkAnnotations:string option -> sInitialExp:string -> arrsAcnPrms:seq<string> -> arrsAcnParamNames:seq<string> -> bEmptyEncodingSpace:bool -> bBsIsUnreferenced:bool -> bVarNameIsUnreferenced:bool -> soInitFuncName:string option -> arrsAnnots:seq<string> -> arrsPrecond:seq<string> -> soPostcond:string option -> codec:Codec -> string;
372-
abstract member MappingFunctionDeclaration : sTypeName:string -> sMF:string -> string;
372+
abstract member MappingFunctionDeclaration : sTypeName:string -> sMF:string -> codec:Codec -> string;
373373
abstract member alignToNext : sMainBody:string -> sAlignmentValue:string -> nAlignmentValue:BigInteger -> nAbsOffset:BigInteger -> nRemainingMinBits:BigInteger -> nLevel:BigInteger -> nIx:BigInteger -> nOffset:BigInteger -> codec:Codec -> string;
374374
abstract member PositiveInteger_ConstSize : p:string -> sSsuffix:string -> sErrCode:string -> nFixedSize:BigInteger -> soMF:string option -> soMFM:string option -> nUperMin:BigInteger -> nUperMax:BigInteger -> codec:Codec -> string;
375375
abstract member PositiveInteger_ConstSize_8 : p:string -> sSsuffix:string -> sErrCode:string -> soMF:string option -> soMFM:string option -> nUperMin:BigInteger -> nUperMax:BigInteger -> codec:Codec -> string;
@@ -443,6 +443,8 @@ Generated by the C stg macros with the following command
443443
abstract member sequence_default_child : p:string -> sAcc:string -> sChName:string -> sChildContent:string -> sInitWithDefaultValue:string -> soExistVar:string option -> soChildExpr:string option -> sChildTypedef:string -> soSaveBitStrmPosStatement:string option -> codec:Codec -> string;
444444
abstract member sequence_call_post_encoding_function : p:string -> sFncName:string -> sBitStreamStartPos:string -> sBitStreamPositionsNullPos:string -> string;
445445
abstract member sequence_call_post_decoding_validator : p:string -> sFncName:string -> sBitStreamStartPos:string -> sBitStreamPositionsNullPos:string -> string;
446+
abstract member sequence_call_post_encoding_function_prototype : sTypedefName:string -> sFncName:string -> sExtFuncsPositionsTypeName:string -> string;
447+
abstract member sequence_call_post_decoding_validator_prototype : sTypedefName:string -> sFncName:string -> sExtFuncsPositionsTypeName:string -> string;
446448
abstract member ChoiceChildAlwaysAbsent : p:string -> sAcc:string -> sChildID:string -> nChildIndex:BigInteger -> sErrorCodeName:string -> codec:Codec -> string;
447449
abstract member ChoiceChild : p:string -> sAcc:string -> sChildID:string -> nChildIndex:BigInteger -> nIndexSizeInBits:BigInteger -> nLastItemIndex:BigInteger -> sChildContent:string -> sChildName:string -> sChildTypeDef:string -> sChoiceTypeName:string -> sChildInitExpr:string -> codec:Codec -> string;
448450
abstract member Choice : p:string -> sAcc:string -> arrsChildren:seq<string> -> nLastItemIndex:BigInteger -> sChoiceIndexName:string -> td:FE_ChoiceTypeDefinition -> nIndexSizeInBits:BigInteger -> sErrCode:string -> codec:Codec -> string;

CommonTypes/AcnGenericTypes.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ type UserDefinedFunction =
315315
| UserMappingFunction of string
316316
| UserPostEncodingFunction of string
317317
| UserPreDecodingFunction of string
318+
with
319+
member this.functionProtype =
320+
match this with
321+
| UserMappingFunction fn
322+
| UserPostEncodingFunction fn
323+
| UserPreDecodingFunction fn -> fn
318324

319325
type IntegerAcnProperties = {
320326
encodingProp : AcnIntEncoding option

FrontEndAst/DAst.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ type AcnFuncBodyResult = {
485485
resultExpr : string option
486486
auxiliaries : string list
487487
icdResult : IcdArgAux option
488-
userDefinedFunctions : UserDefinedFunction list
488+
userDefinedFunctions : UserDefinedFunction list //a list of user defined functions prototypes used in this function body. Emitted at the begining of the source file
489489
}
490490

491491
type XERFuncBodyResult = {
@@ -530,6 +530,7 @@ type AcnFunction = {
530530
funcBody : AcnFuncBody
531531
funcBodyAsSeqComp : AcnFuncBodySeqComp
532532
isTestVaseValid : AutomaticTestCase -> bool
533+
userDefinedFunctions : UserDefinedFunction list //a list of user defined functions prototypes used in this function body. Emitted at the begining of the source file
533534
icdTas : IcdTypeAss option (* always present in Encode, always None in Decode *)
534535
}
535536

@@ -999,6 +1000,7 @@ and AcnChildUpdateResult = {
9991000
testCaseFnc : AutomaticTestCase -> TestCaseValue option
10001001
errCodes : ErrorCode list
10011002
localVariables : LocalVariable list
1003+
//userDefinedFunctions : UserDefinedFunction list //a list of user defined functions prototypes used in this function body. Emitted at the begining of the source file
10021004
}
10031005

10041006
and DastAcnParameter = {

StgAda/acn_a.stg

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ end if;
157157
MFen(soMF, soMFM, p) /*nogen*/ ::= "<if(soMF)><soMFM>.<soMF>_encode(<p>)<else><p><endif>"
158158

159159

160-
MappingFunctionDeclaration(sTypeName, sMF) ::= <<
160+
MappingFunctionDeclaration_encode(sTypeName, sMF) ::= <<
161+
>>
162+
163+
MappingFunctionDeclaration_decode(sTypeName, sMF) ::= <<
161164
>>
162165

163166

@@ -1076,6 +1079,12 @@ sequence_call_post_decoding_validator(p, sFncName, sBitStreamStartPos, sBitStrea
10761079
result := <sFncName>(<p>, <sBitStreamStartPos>, <sBitStreamPositionsNullPos>, bs);
10771080
>>
10781081

1082+
sequence_call_post_encoding_function_prototype(sTypedefName, sFncName, sExtFuncsPositionsTypeName) ::= <<
1083+
>>
1084+
1085+
sequence_call_post_decoding_validator_prototype(sTypedefName, sFncName, sExtFuncsPositionsTypeName) ::= <<
1086+
>>
1087+
10791088

10801089

10811090

StgAda/body_a.stg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ group a_body;
33
rtlModuleName() ::= "adaasn1rtl"
44

55

6-
printSourceFile(sPackageName, arrsIncludedModules, arrsAdaUseTypes, arrsValueAndTypeAssignments) ::= <<
6+
printSourceFile(sPackageName, arrsIncludedModules, arrsAdaUseTypes, arrsUserDefinedFunctions, arrsValueAndTypeAssignments) ::= <<
77
pragma Style_Checks (Off);
88
-- Code automatically generated by asn1scc tool
99

StgC/acn_c.stg

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ if (ret) {
112112
<endif>
113113
>>
114114

115-
MappingFunctionDeclaration(sTypeName, sMF) ::= <<
116-
extern <sTypeName> <sMF>_decode(<sTypeName>);
115+
MappingFunctionDeclaration_encode(sTypeName, sMF) ::= <<
116+
extern <sTypeName> <sMF>_encode(<sTypeName>);
117117
>>
118118

119+
MappingFunctionDeclaration_decode(sTypeName, sMF) ::= <<
120+
extern <sTypeName> <sMF>_decode(<sTypeName>);
121+
>>
119122

120123

121124

@@ -886,6 +889,15 @@ sequence_call_post_decoding_validator(p, sFncName, sBitStreamStartPos, sBitStrea
886889
ret = <sFncName>(<p>, &<sBitStreamStartPos>, &<sBitStreamPositionsNullPos>, pBitStrm, pErrCode);
887890
>>
888891

892+
sequence_call_post_encoding_function_prototype(sTypedefName, sFncName, sExtFuncsPositionsTypeName) ::= <<
893+
extern void <sFncName>(const <sTypedefName>* pPDU, BitStream* pStartBitStrm, <sExtFuncsPositionsTypeName>*, BitStream* pEndBitStrm);
894+
>>
895+
896+
sequence_call_post_decoding_validator_prototype(sTypedefName, sFncName, sExtFuncsPositionsTypeName) ::= <<
897+
extern flag <sFncName>(const <sTypedefName>* pPDU, BitStream* pStartBitStrm, <sExtFuncsPositionsTypeName>*, BitStream* pEndBitStrm, int* pErrorCode);
898+
>>
899+
900+
889901
/* SEQUENCE END */
890902

891903

0 commit comments

Comments
 (0)