Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into catchup
Browse files Browse the repository at this point in the history
Conflicts:
	FrontEndAst/AcnCreateFromAntlr.fs
  • Loading branch information
mario-bucev committed Sep 9, 2024
2 parents 4158bcc + 21ebae7 commit 40137f6
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 42 deletions.
32 changes: 23 additions & 9 deletions BackendAst/DAstACN.fs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ let private createAcnFunction (r: Asn1AcnAst.AstRoot)
| _ -> None
let errCodeName = ToC ("ERR_ACN" + (codec.suffix.ToUpper()) + "_" + ((t.id.AcnAbsPath |> Seq.skip 1 |> Seq.StrJoin("-")).Replace("#","elm")))
let errCode, ns = getNextValidErrorCode us errCodeName None
//if t.id.AsString.EndsWith "ALPHA-DELETE-DIAGNOSTIC-PARAMETER-REPORT-STRUCTURES-GENERIC" then
// printfn "debug"
let nMaxBytesInACN = BigInteger (ceil ((double t.acnMaxSizeInBits)/8.0))
let nMinBytesInACN = BigInteger (ceil ((double t.acnMinSizeInBits)/8.0))
let soInitFuncName = getFuncNameGeneric typeDefinition (lm.init.methodNameSuffix())
Expand Down Expand Up @@ -1256,9 +1258,9 @@ let createSequenceOfFunction (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInserted
lengthRow@chRows@[THREE_DOTS]@lastChRows@terminationPattern, []
| false ->
let sType = TypeHash childIcdTas.hash
let a1 = {IcdRow.fieldName = fieldName; comments = comments; sPresent=sPresent;sType=sType; sConstraint=None; minLengthInBits = t.acnMinSizeInBits; maxLengthInBits=t.acnMaxSizeInBits;sUnits=None; rowType = IcdRowType.LengthDeterminantRow; idxOffset = Some (lengthRow.Length + 1)}
let a2 = {a1 with idxOffset = Some ((int o.maxSize.acn)+lengthRow.Length)}
[a1;THREE_DOTS;a2], [childIcdTas]
let a1 = {IcdRow.fieldName = "Item #1"; comments = comments; sPresent=sPresent;sType=sType; sConstraint=None; minLengthInBits = child.acnMinSizeInBits; maxLengthInBits=child.acnMaxSizeInBits;sUnits=None; rowType = IcdRowType.LengthDeterminantRow; idxOffset = Some (lengthRow.Length + 1)}
let a2 = {a1 with fieldName = $"Item #{o.maxSize.acn}"; idxOffset = Some ((int o.maxSize.acn)+lengthRow.Length)}
lengthRow@[a1;THREE_DOTS;a2], [childIcdTas]
| None -> lengthRow@terminationPattern, []
let sExtraComment =
match o.acnEncodingClass with
Expand Down Expand Up @@ -1412,7 +1414,9 @@ let rec handleSingleUpdateDependency (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.Acn
| Some prmUpdateStatement ->
let updateFunc (child: AcnChild) (nestingScope: NestingScope) (vTarget : CallerScope) (pSrcRoot : CallerScope) =
prmUpdateStatement.updateAcnChildFnc child nestingScope vTarget pSrcRoot
let icdComments = []
let icdComments =
let aaa = sprintf "reference determinant for %s " (acnPrm.id.AsString)
[aaa]
Some ({AcnChildUpdateResult.updateAcnChildFnc = updateFunc; icdComments=icdComments; errCodes=prmUpdateStatement.errCodes; testCaseFnc = prmUpdateStatement.testCaseFnc; localVariables=[]}), ns1
| AcnDepSizeDeterminant (minSize, maxSize, szAcnProp) ->
let updateFunc (child: AcnChild) (nestingScope: NestingScope) (vTarget : CallerScope) (pSrcRoot : CallerScope) =
Expand All @@ -1433,7 +1437,9 @@ let rec handleSingleUpdateDependency (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.Acn
let testCaseFnc (atc:AutomaticTestCase) : TestCaseValue option =
atc.testCaseTypeIDsMap.TryFind d.asn1Type

let icdComments = []
let icdComments =
let aaa = sprintf "size determinant for %s " (d.asn1Type.AsString)
[aaa]
Some ({AcnChildUpdateResult.updateAcnChildFnc = updateFunc; icdComments=icdComments; errCodes=[]; testCaseFnc=testCaseFnc; localVariables=[]}), us
| AcnDepSizeDeterminant_bit_oct_str_contain o ->
let baseTypeDefinitionName =
Expand Down Expand Up @@ -1475,7 +1481,9 @@ let rec handleSingleUpdateDependency (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.Acn
let testCaseFnc (atc:AutomaticTestCase) : TestCaseValue option =
atc.testCaseTypeIDsMap.TryFind d.asn1Type
let localVars = lm.lg.acn.getAcnDepSizeDeterminantLocVars sReqBytesForUperEncoding
let icdComments = []
let icdComments =
let aaa = sprintf "size determinant for %s " (d.asn1Type.AsString)
[aaa]
Some ({AcnChildUpdateResult.updateAcnChildFnc = updateFunc; icdComments=icdComments; errCodes=errCodes0; testCaseFnc=testCaseFnc; localVariables= localVariables0@localVars}), ns
| AcnDepIA5StringSizeDeterminant (minSize, maxSize, szAcnProp) ->

Expand All @@ -1488,7 +1496,9 @@ let rec handleSingleUpdateDependency (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.Acn
| _ -> checkAccessPath checkPath updateStatement v (initExpr r lm m child.Type)
let testCaseFnc (atc:AutomaticTestCase) : TestCaseValue option =
atc.testCaseTypeIDsMap.TryFind d.asn1Type
let icdComments = []
let icdComments =
let aaa = sprintf "size determinant for %s " (d.asn1Type.AsString)
[aaa]
Some ({AcnChildUpdateResult.updateAcnChildFnc = updateFunc; icdComments=icdComments; errCodes=[]; testCaseFnc=testCaseFnc; localVariables=[]}), us
| AcnDepPresenceBool ->
let updateFunc (child: AcnChild) (nestingScope: NestingScope) (vTarget : CallerScope) (pSrcRoot : CallerScope) =
Expand All @@ -1505,7 +1515,9 @@ let rec handleSingleUpdateDependency (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.Acn
match atc.testCaseTypeIDsMap.TryFind(d.asn1Type) with
| Some _ -> Some TcvComponentPresent
| None -> Some TcvComponentAbsent
let icdComments = []
let icdComments =
let aaa = sprintf "Used as a presence determinant for %s " (d.asn1Type.AsString)
[aaa]
Some ({AcnChildUpdateResult.updateAcnChildFnc = updateFunc; icdComments=icdComments; errCodes=[]; testCaseFnc=testCaseFnc; localVariables=[]}), us
| AcnDepPresence (relPath, chc) ->
let icdComments =
Expand Down Expand Up @@ -1603,7 +1615,9 @@ let rec handleSingleUpdateDependency (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.Acn
| _ -> checkAccessPath checkPath updateStatement2 v (initExpr r lm m child.Type)
let testCaseFnc (atc:AutomaticTestCase) : TestCaseValue option =
atc.testCaseTypeIDsMap.TryFind d.asn1Type
let icdComments = []
let icdComments =
let aaa = sprintf "Used as a presence determinant for %s " (chc.typeDef[C].asn1Name)
[aaa]
Some ({AcnChildUpdateResult.updateAcnChildFnc = updateFunc; icdComments=icdComments; errCodes=[] ; testCaseFnc=testCaseFnc; localVariables=[]}), us

and getUpdateFunctionUsedInEncoding (r: Asn1AcnAst.AstRoot) (deps: Asn1AcnAst.AcnInsertedFieldDependencies) (lm: LanguageMacros) (m: Asn1AcnAst.Asn1Module) (acnChildOrAcnParameterId) (us:State) : (AcnChildUpdateResult option*State)=
Expand Down
73 changes: 73 additions & 0 deletions BackendAst/DAstUtilFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ open Asn1AcnAst
open Asn1AcnAstUtilFunctions
open DAst
open Language
open System.Xml.Serialization
open System.IO
//open Newtonsoft.Json

let getAccessFromScopeNodeList (ReferenceToType nodes) (childTypeIsString: bool) (lm:LanguageMacros) (pVal : CallerScope) =
let handleNode zeroBasedSequenceOfLevel (pVal : CallerScope) (n:ScopeNode) (childTypeIsString: bool) =
Expand Down Expand Up @@ -1061,3 +1064,73 @@ let getBaseFuncName (lm:LanguageMacros) (typeDefinition:TypeDefinitionOrReferenc
| true -> typeDefinitionName0
| false -> moduleName + "." + typeDefinitionName0
baseTypeDefinitionName, baseTypeDefinitionName + methodSuffix + codec.suffix


let serializeIcdTasToXml (icdTypeAss: IcdTypeAss) =
let serializer = XmlSerializer(typeof<IcdTypeAss>)
use stringWriter = new StringWriter()
serializer.Serialize(stringWriter, icdTypeAss)
stringWriter.ToString()

//let serializeIcdTasToJson (icdTypeAss: IcdTypeAss) =
// JsonConvert.SerializeObject(icdTypeAss)

(*
and IcdTypeAss = {
linkId : ReferenceToType
tasInfo : TypeAssignmentInfo option
asn1Link : string option
acnLink : string option
name : string
kind : string
comments : string list
rows : IcdRow list
compositeChildren : IcdTypeAss list
minLengthInBytes : BigInteger
maxLengthInBytes : BigInteger
hash : string
canBeEmbedded : bool
hasAcnDefinition : bool
*)

let md5 = System.Security.Cryptography.MD5.Create()
let calcIcdTypeAssHash (t1:IcdTypeAss) =
let rec calcIcdTypeAssHash_aux (t1:IcdTypeAss) =
let rws =
t1.rows |>
Seq.map(fun r -> sprintf "%A%A%A%A%A%A%A%A%A%A" r.idxOffset r.fieldName r.comments r.sPresent r.sType r.sConstraint r.minLengthInBits r.maxLengthInBits r.sUnits r.rowType) |>
Seq.StrJoin ""
let aa = sprintf"%A%A%A%A%A%A%A%A%A" t1.acnLink t1.asn1Link t1.name t1.kind t1.comments t1.minLengthInBytes t1.maxLengthInBytes (rws) ("")
let bytes = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes aa)
Convert.ToHexString bytes
calcIcdTypeAssHash_aux t1

let serializeIcdTasToText (icdTypeAss: IcdTypeAss) =
let printRow (r:IcdRow) =
sprintf """
idxOffset = %A
fieldName = %A
comments = %A
sPresent = %A
sType = %A
sConstraint = %A
minLengthInBits = %A
maxLengthInBits = %A
sUnits = %A
rowType = %A
""" r.idxOffset r.fieldName r.comments r.sPresent r.sType r.sConstraint r.minLengthInBits r.maxLengthInBits r.sUnits r.rowType

//let aa = sprintf"%A%A%A%A%A%A%A%A%A" t1.acnLink t1.asn1Link t1.name t1.kind t1.comments t1.minLengthInBytes t1.maxLengthInBytes (rws) ("")
let rws = icdTypeAss.rows |> Seq.map printRow |> Seq.StrJoin "\n"
sprintf """
acnLink = %A
asn1Link = %A
name = %A
kind = %A
comments = %A
minLengthInBytes = %A
maxLengthInBytes = %A
rows =
%A
""" icdTypeAss.acnLink icdTypeAss.asn1Link icdTypeAss.name icdTypeAss.kind icdTypeAss.comments icdTypeAss.minLengthInBytes icdTypeAss.maxLengthInBytes rws
89 changes: 58 additions & 31 deletions BackendAst/GenerateAcnIcd.fs
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,12 @@ let emitIcdRow stgFileName (r:AstRoot) _i (rw:IcdRow) =
| _ -> icd_acn.EmitSeqOrChoiceRow stgFileName sClass (BigInteger i) rw.fieldName sComment rw.sPresent (emitTypeCol stgFileName r rw.sType) sConstraint (rw.minLengthInBits.ToString()) (rw.maxLengthInBits.ToString()) None rw.sUnits

let emitTas2 stgFileName (r:AstRoot) myParams (icdTas:IcdTypeAss) =
let sCommentLine = icdTas.hash::icdTas.comments |> Seq.StrJoin (icd_uper.NewLine stgFileName ())
let sCommentLine = icdTas.comments |> Seq.StrJoin (icd_uper.NewLine stgFileName ())
let arRows =
icdTas.rows |> List.mapi (fun i rw -> emitIcdRow stgFileName r (i+1) rw)
let bHasAcnDef = icdTas.hasAcnDefinition
icd_acn.EmitSequenceOrChoice stgFileName false icdTas.name icdTas.hash bHasAcnDef (icdTas.kind) (icdTas.minLengthInBytes.ToString()) (icdTas.maxLengthInBytes.ToString()) "sMaxBitsExplained" sCommentLine arRows (myParams 4I) (sCommentLine.Split [|'\n'|])
let sMaxBitsExplained = ""
icd_acn.EmitSequenceOrChoice stgFileName false icdTas.name icdTas.hash bHasAcnDef (icdTas.kind) (icdTas.minLengthInBytes.ToString()) (icdTas.maxLengthInBytes.ToString()) sMaxBitsExplained sCommentLine arRows (myParams 4I) (sCommentLine.Split [|'\n'|])

(*
let rec PrintType2 stgFileName (r:AstRoot) acnParams (icdTas:IcdTypeAss): string list =
Expand Down Expand Up @@ -717,17 +718,31 @@ let printTasses3 stgFileName (r:DAst.AstRoot) : (string list)*(string list) =
(files, icdHashesToPrint)

let PrintAsn1FileInColorizedHtml (stgFileName:string) (r:AstRoot) (icdHashesToPrint:string list) (f:Asn1File) =
let debug (tsName:string) =
r.icdHashes.Values |>
Seq.collect id |>
Seq.filter(fun ts -> ts.name = tsName) |>
Seq.iter(fun ts ->
let content = DAstUtilFunctions.serializeIcdTasToText ts
let fileName = sprintf "%s_%s.txt" tsName ts.hash
File.WriteAllText(fileName, content))
//debug("ALPHA-TC-SECONDARY-HEADER")
//let tryCreateRefType = CreateAsn1AstFromAntlrTree.CreateRefTypeContent
let icdHashesToPrintSet = icdHashesToPrint |> Set.ofList
let fileModules = f.Modules |> List.map(fun m -> m.Name.Value) |> Set.ofList
let fileTypeAssignments =
r.icdHashes.Values |>
Seq.collect id |>
Seq.choose(fun z ->
match z.tasInfo with
| None -> None
| Some ts when icdHashesToPrintSet.Contains z.hash && fileModules.Contains ts.modName -> Some (ts.tasName, z.hash)
| Some _ -> None ) |> Seq.toList
//match z.tasInfo with
//| None -> None
//| Some ts when icdHashesToPrintSet.Contains z.hash && fileModules.Contains ts.modName -> Some (ts.tasName, z.hash)
//| Some _ -> None ) |>
match icdHashesToPrintSet.Contains z.hash with
| true -> Some (z.name, z.hash)
| false -> None ) |>
Seq.distinct |>
Seq.toList


//let blueTasses = f.Modules |> Seq.collect(fun m -> getModuleBlueTasses m)
Expand All @@ -749,45 +764,57 @@ let PrintAsn1FileInColorizedHtml (stgFileName:string) (r:AstRoot) (icdHashesToPr
let isAsn1Token = GenerateUperIcd.asn1Tokens.Contains t.Text
//let isType = containedIn tasses
let safeText = t.Text.Replace("<",lt).Replace(">",gt)
let checkWsCmt (tok: IToken) =
match tok.Type with
|asn1Lexer.WS
|asn1Lexer.COMMENT
|asn1Lexer.COMMENT2 -> false
|_ -> true
let findToken = Array.tryFind(fun tok -> checkWsCmt tok)
let findNextToken = f.Tokens.[idx+1..] |> findToken
let findPrevToken = Array.rev f.Tokens.[0..idx-1] |> findToken
let nextToken =
let size = Seq.length(f.Tokens) - 1
match findNextToken with
|Some(tok) -> tok
|None -> if idx = size then t else f.Tokens.[idx+1]
let prevToken =
match findPrevToken with
|Some(tok) -> tok
|None -> if idx = 0 then t else f.Tokens.[idx-1]
let uid =
//match fileTypeAssignments.TryFind t.Text with
match fileTypeAssignments |> List.filter(fun (tasName,_) -> tasName = t.Text) with
let uid () =
let checkWsCmt (tok: IToken) =
match tok.Type with
|asn1Lexer.WS
|asn1Lexer.COMMENT
|asn1Lexer.COMMENT2 -> false
|_ -> true
let findToken = Array.tryFind(fun tok -> checkWsCmt tok)
let findNextToken = f.Tokens.[idx+1..] |> findToken
let findPrevToken = Array.rev f.Tokens.[0..idx-1] |> findToken
let nextToken =
let size = Seq.length(f.Tokens) - 1
match findNextToken with
|Some(tok) -> tok
|None -> if idx = size then t else f.Tokens.[idx+1]
let prevToken =
match findPrevToken with
|Some(tok) -> tok
|None -> if idx = 0 then t else f.Tokens.[idx-1]
let tasfileTypeAssignments = fileTypeAssignments |> List.filter(fun (tasName,_) -> tasName = t.Text)
match tasfileTypeAssignments with
| [] -> safeText
//|Some tasHash ->
| (_,tasHash)::[] ->
if nextToken.Type = asn1Lexer.ASSIG_OP && prevToken.Type <> asn1Lexer.LID then
icd_uper.TasName stgFileName safeText tasHash
else
icd_uper.TasName2 stgFileName safeText tasHash
| _ ->
//printfn "Warning: %s is not unique" t.Text
//printfn "Warning: %A" (fileTypeAssignments |> List.filter(fun (tasName,_) -> tasName = t.Text))
let debug () =
printfn "Warning: %s is not unique. %d" t.Text tasfileTypeAssignments.Length

printfn "Warning: %A" tasfileTypeAssignments
//print to jso the type assignments that are not unique
tasfileTypeAssignments |>
Seq.iter (fun (tasName, tasHash) ->
let icdTas = r.icdHashes.[tasHash]
icdTas |>
Seq.iter(fun icdTas ->
let content = DAstUtilFunctions.serializeIcdTasToText icdTas
let fileName = sprintf "%s_%s.txt" tasName icdTas.hash
File.WriteAllText(fileName, content)))

//debug ()
safeText
//|None -> safeText
let colored =
match t.Type with
|asn1Lexer.StringLiteral
|asn1Lexer.OctectStringLiteral
|asn1Lexer.BitStringLiteral -> icd_uper.StringLiteral stgFileName safeText
|asn1Lexer.UID -> uid
|asn1Lexer.UID -> uid ()
|asn1Lexer.COMMENT
|asn1Lexer.COMMENT2 -> icd_uper.Comment stgFileName safeText
|_ -> safeText
Expand Down
6 changes: 6 additions & 0 deletions FrontEndAst/AcnCreateFromAntlr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,12 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (m:Asn1Ast.Asn1Mo
let acnErrLoc = acnType |> Option.map(fun x -> x.loc)
let combinedProperties = acnProps
let allCons = t.Constraints@refTypeCons@withCons
let debug = ReferenceToType curPath
//if debug.AsString.EndsWith "ALPHA-DELETE-DIAGNOSTIC-PARAMETER-REPORT-STRUCTURES-GENERIC" then
// printfn "%s" debug.AsString
//if debug.AsString = "RW90-DATAVIEW.UART-Config.timeout" then
// printfn "%s" debug.AsString

let tfdArg = {GetTypeDefinition_arg.asn1TypeKind = t.Kind; loc = t.Location; curPath = curPath; typeDefPath = typeDefPath; enmItemTypeDefPath = enmItemTypeDefPath; inheritInfo = inheritInfo; typeAssignmentInfo = typeAssignmentInfo; rtlFnc = None; blm=asn1.args.blm}
let fixConstraint = fixConstraint asn1

Expand Down
2 changes: 1 addition & 1 deletion StgVarious/icdtemplate_acn.stg
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ RelativeOid() ::= "RELATIVE-OID"

EmitRowWith3Dots() ::= <<
<tr class="CommentRow">
<td class="threeDots" colspan="8"> <p>. . .</p> </td>
<td class="threeDots" colspan="9"> <p>. . .</p> </td>
</tr>
>>

Expand Down
2 changes: 1 addition & 1 deletion asn1scc/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ let printVersion () =
//let fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
//let version = fvi.FileVersion;

let version = "4.5.2.1"
let version = "4.5.2.2"
printfn "asn1scc version %s\n" version
()

Expand Down

0 comments on commit 40137f6

Please sign in to comment.