Skip to content

Commit af4abc6

Browse files
committed
#332 - Duplicate Macro Definitions in Generated Code
1 parent 7ebd007 commit af4abc6

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

BackendAst/DAstACN.fs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ open DAstUtilFunctions
1414
open System.Globalization
1515
open Language
1616

17+
1718
let foldMap = Asn1Fold.foldMap
1819

1920

@@ -328,7 +329,11 @@ let private createAcnFunction (r: Asn1AcnAst.AstRoot)
328329
let prmNames = t.acnParameters |> List.map (fun p -> p.c_name)
329330
let func = Some(EmitTypeAssignment_primitive varName sStar funcName isValidFuncName (typeDefinition.longTypedefName2 lm.lg.hasModules) lvars bodyResult_funcBody soSparkAnnotations sInitialExp prms prmNames (t.acnMaxSizeInBits = 0I) bBsIsUnreferenced bVarNameIsUnreferenced soInitFuncName funcDefAnnots precondAnnots postcondAnnots codec)
330331

331-
let errCodStr = errCodes |> List.map(fun x -> EmitTypeAssignment_def_err_code x.errCodeName (BigInteger x.errCodeValue) x.comment) |> List.distinct
332+
let errCodStr =
333+
errCodes |>
334+
List.groupBy (fun x -> x.errCodeName) |>
335+
List.map (fun (k, v) -> {errCodeName = k; errCodeValue = v.Head.errCodeValue; comment = v.Head.comment}) |>
336+
List.map(fun x -> EmitTypeAssignment_def_err_code x.errCodeName (BigInteger x.errCodeValue) x.comment) |> List.distinct
332337
let funcDef = Some(EmitTypeAssignment_primitive_def varName sStar funcName (typeDefinition.longTypedefName2 lm.lg.hasModules) errCodStr (t.acnMaxSizeInBits = 0I) nMaxBytesInACN ( t.acnMaxSizeInBits) prms soSparkAnnotations codec)
333338
let ns2a =
334339
match t.id.topLevelTas with
@@ -1932,6 +1937,9 @@ let createSequenceFunction (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInsertedFi
19321937

19331938
let handleChild (s: SequenceChildState) (childInfo: SeqChildInfo): SequenceChildResult * SequenceChildState =
19341939
// This binding is suspect, isn't it
1940+
let stateHash = getStateHash s.us
1941+
//printfn "child is %s" childInfo.Name
1942+
//printf "State hash: %s\n" stateHash
19351943
let us = s.us
19361944
let soSaveBitStrmPosStatement = None
19371945
let childNestingScope =
@@ -2099,6 +2107,10 @@ let createSequenceFunction (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInsertedFi
20992107
let res = {stmts=stmts; resultExpr=None; existVar=None; props=props; auxiliaries=auxiliaries; icdResult=icdResult}
21002108
let newAcc = {us=ns2; childIx=s.childIx + 1I; uperAccBits=s.uperAccBits; acnAccBits=s.acnAccBits + acnChild.Type.acnMaxSizeInBits}
21012109
res, newAcc
2110+
2111+
2112+
2113+
21022114
// find acn inserted fields, which are not NULL types and which have no dependency.
21032115
// For those fields we should generated no anc encode/decode function
21042116
// Otherwise, the encoding function is wrong since an uninitialized value is encoded.
@@ -2559,8 +2571,8 @@ let createReferenceFunction (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInsertedF
25592571
let bit_string_containing_ext_field_func = lm.acn.bit_string_containing_ext_field_func
25602572

25612573
let baseTypeAcnFunction = baseType.getAcnFunction codec
2562-
2563-
let funcBody (errCode:ErrorCode) (acnArgs: (AcnGenericTypes.RelativePath*AcnGenericTypes.AcnParameter) list) (nestingScope: NestingScope) (p:CallerScope) =
2574+
//(AcnFuncBodyResult option) * State
2575+
let funcBody (us:State) (errCode:ErrorCode) (acnArgs: (AcnGenericTypes.RelativePath*AcnGenericTypes.AcnParameter) list) (nestingScope: NestingScope) (p:CallerScope) : (AcnFuncBodyResult option)* State =
25642576
TL "ACN_REF_04" (fun () ->
25652577
let pp, resultExpr =
25662578
let str = lm.lg.getParamValue t p.arg codec
@@ -2569,22 +2581,22 @@ let createReferenceFunction (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInsertedF
25692581
let toc = ToC str
25702582
toc, Some toc
25712583
| _ -> str, None
2572-
let funcBodyContent, errCodes, localVariables =
2584+
let funcBodyContent, errCodes, localVariables, ns2 =
25732585
match encOptions.acnEncodingClass, encOptions.octOrBitStr with
25742586
| SZ_EC_ExternalField relPath , ContainedInOctString ->
25752587
let filterDependency (d:AcnDependency) =
25762588
match d.dependencyKind with
25772589
| AcnDepSizeDeterminant_bit_oct_str_contain _ -> true
25782590
| _ -> false
25792591
let extField = getExternalField0 r deps t.id filterDependency
2580-
let soInner, errCodes0, localVariables0 =
2592+
let soInner, errCodes0, localVariables0, ns1 =
25812593
match baseTypeAcnFunction with
2582-
| None -> None, [], []
2594+
| None -> None, [], [], us
25832595
| Some baseTypeAcnFunction ->
25842596
let acnRes, ns = baseTypeAcnFunction.funcBody us acnArgs nestingScope p
25852597
match acnRes with
2586-
| None -> None, [], []
2587-
| Some r -> Some r.funcBody, r.errCodes, r.localVariables
2598+
| None -> None, [], [], ns
2599+
| Some r -> Some r.funcBody, r.errCodes, r.localVariables, ns
25882600

25892601
let fncBody = octet_string_containing_ext_field_func pp baseFncName sReqBytesForUperEncoding extField errCode.errCodeName soInner codec
25902602
// For some reasons, the `soInner` is not inlined in the Ada backend,
@@ -2593,28 +2605,29 @@ let createReferenceFunction (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInsertedF
25932605
match ProgrammingLanguage.ActiveLanguages.Head with
25942606
| Ada -> []
25952607
| _ -> localVariables0
2596-
fncBody, errCode::errCodes0,lvs
2608+
fncBody, errCode::errCodes0,lvs, ns1
25972609
| SZ_EC_ExternalField relPath , ContainedInBitString ->
25982610
let extField = getExternalField r deps t.id
25992611
let fncBody = bit_string_containing_ext_field_func pp baseFncName sReqBytesForUperEncoding sReqBitForUperEncoding extField errCode.errCodeName codec
2600-
fncBody, [errCode],[]
2612+
fncBody, [errCode],[], us
26012613
| SZ_EC_FIXED_SIZE , ContainedInOctString ->
26022614
let fncBody = octet_string_containing_func pp baseFncName sReqBytesForUperEncoding 0I encOptions.minSize.acn encOptions.maxSize.acn true codec
2603-
fncBody, [errCode],[]
2615+
fncBody, [errCode],[], us
26042616
| SZ_EC_LENGTH_EMBEDDED nBits , ContainedInOctString ->
26052617
let fncBody = octet_string_containing_func pp baseFncName sReqBytesForUperEncoding nBits encOptions.minSize.acn encOptions.maxSize.acn false codec
2606-
fncBody, [errCode],[]
2618+
fncBody, [errCode],[], us
26072619
| SZ_EC_FIXED_SIZE , ContainedInBitString ->
26082620
let fncBody = bit_string_containing_func pp baseFncName sReqBytesForUperEncoding sReqBitForUperEncoding 0I encOptions.minSize.acn encOptions.maxSize.acn true codec
2609-
fncBody, [errCode],[]
2621+
fncBody, [errCode],[], us
26102622
| SZ_EC_LENGTH_EMBEDDED nBits , ContainedInBitString ->
26112623
let fncBody = bit_string_containing_func pp baseFncName sReqBytesForUperEncoding sReqBitForUperEncoding nBits encOptions.minSize.acn encOptions.maxSize.acn false codec
2612-
fncBody, [errCode],[]
2624+
fncBody, [errCode],[], us
26132625
| SZ_EC_TerminationPattern nullVal , _ -> raise(SemanticError (loc, "Invalid type for parameter4"))
2614-
Some ({AcnFuncBodyResult.funcBody = funcBodyContent; errCodes = errCodes; localVariables = localVariables; bValIsUnReferenced= false; bBsIsUnReferenced=false; resultExpr=resultExpr; auxiliaries=[]; icdResult = icd}))
2626+
let funcBodyResult = Some ({AcnFuncBodyResult.funcBody = funcBodyContent; errCodes = errCodes; localVariables = localVariables; bValIsUnReferenced= false; bBsIsUnReferenced=false; resultExpr=resultExpr; auxiliaries=[]; icdResult = icd})
2627+
funcBodyResult, ns2)
26152628

26162629
let soSparkAnnotations = Some(sparkAnnotations lm (typeDefinition.longTypedefName2 lm.lg.hasModules) codec)
2617-
let a,b = createAcnFunction r deps lm codec t typeDefinition isValidFunc (fun us e acnArgs nestingScope p -> funcBody e acnArgs nestingScope p, us) (fun atc -> true) soSparkAnnotations [] us
2630+
let a,b = createAcnFunction r deps lm codec t typeDefinition isValidFunc (fun us e acnArgs nestingScope p -> funcBody us e acnArgs nestingScope p) (fun atc -> true) soSparkAnnotations [] us
26182631
Some a, b)
26192632

26202633

FrontEndAst/DAst.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ open AcnGenericTypes
1010
open AbstractMacros
1111
open System.Collections.Generic
1212

13+
open System.Security.Cryptography
14+
open System.Text
15+
1316
//open Constraints
1417

1518

@@ -1121,6 +1124,18 @@ let getNextValidErrorCode (cur:State) (errCodeName:string) (comment:string optio
11211124
let errCode = getErrorCode (errCodeName.ToUpper())
11221125
errCode, {cur with currErrorCode = cur.currErrorCode + 1; curErrCodeNames = cur.curErrCodeNames.Add errCode.errCodeName})
11231126

1127+
1128+
let getStateHash (state:State) =
1129+
let getMd5Hash (input: string) =
1130+
use md5 = MD5.Create()
1131+
let inputBytes = Encoding.UTF8.GetBytes(input)
1132+
let hashBytes = md5.ComputeHash(inputBytes)
1133+
BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant()
1134+
let complete_state = state.curErrCodeNames |> Seq.StrJoin "#"
1135+
let hash = getMd5Hash complete_state
1136+
hash
1137+
1138+
11241139
type TypeAssignment = {
11251140
Name:StringLoc
11261141
c_name:string

asn1scc/Program.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ let printVersion () =
124124
//let fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
125125
//let version = fvi.FileVersion;
126126

127-
let version = "4.6.0.1"
127+
let version = "4.6.0.2"
128128
printfn "asn1scc version %s\n" version
129129
()
130130

0 commit comments

Comments
 (0)