Skip to content

Commit

Permalink
Merge pull request #19 from mario-bucev/runtime-safety
Browse files Browse the repository at this point in the history
Runtime safety
  • Loading branch information
fschramka authored Apr 15, 2024
2 parents 1e7cd57 + 8cc5cb6 commit c9becef
Show file tree
Hide file tree
Showing 42 changed files with 5,727 additions and 1,615 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
shared_workdir/
.metals
.vscode
.idea
Expand Down
658 changes: 420 additions & 238 deletions BackendAst/DAstACN.fs

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions BackendAst/DAstConstruction.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ let private createAcnChild (r:Asn1AcnAst.AstRoot) (deps:Asn1AcnAst.AcnInsertedFi
let funcUpdateStatement, ns3 = DAstACN.getUpdateFunctionUsedInEncoding r deps lm m ch.id ns2
let c_name = DAstACN.getAcnDeterminantName ch.id

let newFuncBody (codec:Codec) (prms:((AcnGenericTypes.RelativePath*AcnGenericTypes.AcnParameter) list)) (p:CallerScope) : (AcnFuncBodyResult option)=
let funBodyWithState st errCode prms p =
let newFuncBody (codec:Codec) (prms:((AcnGenericTypes.RelativePath*AcnGenericTypes.AcnParameter) list)) (nestingScope: NestingScope) (p:CallerScope): AcnFuncBodyResult option=
let funBodyWithState st errCode prms nestingScope p =
let funcBody codec = match codec with Codec.Encode -> funcBodyEncode | Codec.Decode -> funcBodyDecode
funcBody codec prms p, st
let retFunc = DAstACN.handleSavePosition funBodyWithState ch.Type.savePosition c_name ch.id lm codec prms p
retFunc emptyState {ErrorCode.errCodeName = ""; ErrorCode.errCodeValue=0; comment=None} prms p |> fst
funcBody codec prms nestingScope p, st
let retFunc = DAstACN.handleSavePosition funBodyWithState ch.Type.savePosition c_name ch.id lm codec
retFunc emptyState {ErrorCode.errCodeName = ""; ErrorCode.errCodeValue=0; comment=None} prms nestingScope p |> fst

let tdBodyWithinSeq = DAstACN.getDeterminantTypeDefinitionBodyWithinSeq r lm (Asn1AcnAst.AcnChildDeterminant ch)
let initExpression =
Expand Down Expand Up @@ -962,4 +962,3 @@ let DoWork (r:Asn1AcnAst.AstRoot) (icdStgFileName:string) (deps:Asn1AcnAst.AcnIn
deps = deps
icdHashes = ns.icdHashes
}

328 changes: 222 additions & 106 deletions BackendAst/DAstUPer.fs

Large diffs are not rendered by default.

54 changes: 45 additions & 9 deletions BackendAst/DAstUtilFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ let getAccessFromScopeNodeList (ReferenceToType nodes) (childTypeIsString: bool
| TA _
| PRM _
| VA _ -> raise(BugErrorException "getAccessFromScopeNodeList")
| SEQ_CHILD (chName, chOpt) ->
let isPresent =
| SEQ_CHILD (chName, chOpt) ->
let isPresent =
match chOpt with
| true -> [lm.lg.getSeqChildIsPresent pVal.arg chName] //[sprintf "%s%sexist.%s" pVal.arg.p (lm.lg.getAccess pVal.arg) chName]
| false -> []
isPresent, {pVal with arg = lm.lg.getSeqChild pVal.arg (ToC chName) childTypeIsString chOpt}
| CH_CHILD (chName, pre_name, chParent) ->
| CH_CHILD (chName, pre_name, chParent) ->
let chChildIsPresent =
match ST.lang with
| Scala -> sprintf "%s.isInstanceOf[%s.%s_PRESENT]" (pVal.arg.joined lm.lg) chParent pre_name
Expand Down Expand Up @@ -735,10 +735,37 @@ with
| Some tasInfo -> Some tasInfo.AsTasInfo
| None -> None

type Asn1Child with
member this.getBackendName l =
match l with
| C -> this._c_name
| Scala -> this._scala_name
| Ada -> this._ada_name
member this.acnMinSizeInBits =
match this.Optionality with
| Some(AlwaysAbsent) -> 0I
| _ -> this.Type.acnMinSizeInBits

member this.acnMaxSizeInBits =
match this.Optionality with
| Some(AlwaysAbsent) -> 0I
| _ -> this.Type.acnMaxSizeInBits

//let getValueType (r:AstRoot) (v:Asn1GenericValue) =
// r.typesMap.[v.refToType]
member this.uperMinSizeInBits =
match this.Optionality with
| Some(AlwaysAbsent) -> 0I
| _ -> this.Type.uperMinSizeInBits

member this.uperMaxSizeInBits =
match this.Optionality with
| Some(AlwaysAbsent) -> 0I
| _ -> this.Type.uperMaxSizeInBits

member this.maxSizeInBits (enc: Asn1Encoding): BigInteger =
match enc with
| UPER -> this.uperMaxSizeInBits
| ACN -> this.acnMaxSizeInBits
| _ -> raise (BugErrorException $"Unexpected encoding: {enc}")

type Asn1Module with
member this.ExportedTypes =
Expand Down Expand Up @@ -872,25 +899,34 @@ type SeqChildInfo with
| AcnChild x -> None
member this.acnMaxSizeInBits =
match this with
| Asn1Child x -> x.Type.acnMaxSizeInBits
| Asn1Child x -> x.acnMaxSizeInBits // Takes into account ALWAYS ABSENT
| AcnChild x -> x.Type.acnMaxSizeInBits
member this.acnMinSizeInBits =
match this with
| Asn1Child x -> x.Type.acnMinSizeInBits
| Asn1Child x -> x.acnMinSizeInBits
| AcnChild x -> x.Type.acnMinSizeInBits
member this.Comments =
match this with
| Asn1Child x -> x.Comments
| AcnChild x -> [||]

member this.maxSizeInBits (enc: Asn1Encoding): BigInteger =
match enc with
| UPER ->
match this with
| Asn1Child x -> x.uperMaxSizeInBits
| AcnChild x -> raise (BugErrorException $"Unexpected UPER encoding for ACN child {x.Name}")
| ACN -> this.acnMaxSizeInBits
| _ -> raise (BugErrorException $"Unexpected encoding: {enc}")

let hasAcnEncodeFunction (encFunc : AcnFunction option) acnParameters =
match encFunc with
| None -> false
| Some fnc ->
match acnParameters with
| [] ->
let p = {CallerScope.modName = ""; arg = Selection.valueEmptyPath "dummy"}
let ret,_ = fnc.funcBody emptyState [] p
let ret,_ = fnc.funcBody emptyState [] (NestingScope.init 0I 0I) p
match ret with
| None -> false
| Some _ -> true
Expand All @@ -901,7 +937,7 @@ let hasUperEncodeFunction (encFunc : UPerFunction option) =
| None -> false
| Some fnc ->
let p = {CallerScope.modName = ""; arg = Selection.valueEmptyPath "dummy"}
match fnc.funcBody p with
match fnc.funcBody (NestingScope.init 0I 0I) p with
| None -> false
| Some _ -> true

Expand Down
16 changes: 8 additions & 8 deletions CommonTypes/AbstractMacros.fs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ Generated by the C stg macros with the following command
abstract member InternalItem_string_with_alpha : p:string -> sErrCode:string -> td:FE_StringTypeDefinition -> i:string -> nLastItemIndex:BigInteger -> arrnAlphabetAsciiCodes:seq<BigInteger> -> nAlphabetLength:BigInteger -> nCharIndexSize:BigInteger -> codec:Codec -> string;
abstract member InternalItem_string_no_alpha : p:string -> sErrCode:string -> i:string -> codec:Codec -> string;
abstract member IntFullyConstraint : p:string -> nMin:BigInteger -> nMax:BigInteger -> nBits:BigInteger -> sSsuffix:string -> sErrCode:string -> codec:Codec -> string;
abstract member IntFullyConstraintPos : p:string -> nMin:BigInteger -> nMax:BigInteger -> nBits:BigInteger -> sSsuffix:string -> sErrCode:string -> codec:Codec -> string;
abstract member IntFullyConstraintPos : p:string -> nMin:BigInteger -> nMax:BigInteger -> nBits:BigInteger -> sSsuffix:string -> sErrCode:string -> soRangeAssert:string option -> codec:Codec -> string;
abstract member IntUnconstrained : p:string -> sErrCode:string -> bCoverageIgnore:bool -> codec:Codec -> string;
abstract member IntUnconstrainedMax : p:string -> nMax:BigInteger -> soCheckExp:string option -> sErrCode:string -> codec:Codec -> string;
abstract member IntSemiConstraint : p:string -> nMin:BigInteger -> sErrCode:string -> codec:Codec -> string;
Expand All @@ -325,17 +325,17 @@ Generated by the C stg macros with the following command
abstract member Enumerated_item : p:string -> sName:string -> nIndex:BigInteger -> nLastItemIndex:BigInteger -> codec:Codec -> string;
abstract member Enumerated : p:string -> td:FE_EnumeratedTypeDefinition -> arrsItem:seq<string> -> nMin:BigInteger -> nMax:BigInteger -> nBits:BigInteger -> sErrCode:string -> nLastItemIndex:BigInteger -> sFirstItemName:string -> codec:Codec -> string;
abstract member choice_child : p:string -> sAcc:string -> sChildID:string -> nChildIndex:BigInteger -> nIndexSizeInBits:BigInteger -> nLastItemIndex:BigInteger -> sChildContent:string -> sChildName:string -> sChildTypeDef:string -> sChoiceTypeName:string -> sChildInitExpr:string -> bIsSequence:bool -> bIsEnum:bool -> codec:Codec -> string;
abstract member choice : p:string -> sAcc:string -> arrsChildren:seq<string> -> nLastItemIndex:BigInteger -> sChoiceIndexName:string -> sErrCode:string -> td:FE_ChoiceTypeDefinition -> nIndexSizeInBits:BigInteger -> codec:Codec -> string;
abstract member choice : p:string -> sAcc:string -> arrsChildren:seq<string> -> nLastItemIndex:BigInteger -> sChoiceIndexName:string -> sErrCode:string -> td:FE_ChoiceTypeDefinition -> nIndexSizeInBits:BigInteger -> bIntroSnap:bool -> codec:Codec -> string;
abstract member sequence_presence_bit : p:string -> sAcc:string -> sChName:string -> soExistVar:string option -> sErrCode:string -> codec:Codec -> string;
abstract member sequence_presence_bit_fix : p:string -> sAcc:string -> sChName:string -> soExistVar:string option -> sErrCode:string -> sVal:string -> codec:Codec -> string;
abstract member sequence_mandatory_child : sChName:string -> sChildContent:string -> codec:Codec -> string;
abstract member sequence_optional_child : p:string -> sAcc:string -> sChName:string -> sChildContent:string -> soExistVar:string option -> soChildExpr:string option -> sChildTypedef:string -> codec:Codec -> string;
abstract member sequence_default_child : p:string -> sAcc:string -> sChName:string -> sChildContent:string -> soExistVar:string option -> soChildExpr:string option -> sChildTypedef:string -> sInitWithDefaultValue:string -> codec:Codec -> string;
abstract member sequence_build : p:string -> sTypeDefName:string -> arrsChildren:seq<string> -> string;
abstract member str_FixedSize : p:string -> sTasName:string -> i:string -> sInternalItem:string -> nFixedSize:BigInteger -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> nAlignSize:BigInteger -> soInitExpr:string option -> codec:Codec -> string;
abstract member str_FixedSize : p:string -> sTasName:string -> i:string -> sInternalItem:string -> nFixedSize:BigInteger -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> nAlignSize:BigInteger -> soInitExpr:string option -> bIntroSnap:bool -> soPreSerde:string option -> soPostSerde:string option -> soPostInc:string option -> soInvariant:string option -> codec:Codec -> string;
abstract member str_VarSize : p:string -> sTasName:string -> i:string -> sInternalItem:string -> nSizeMin:BigInteger -> nSizeMax:BigInteger -> nSizeInBits:BigInteger -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> nAlignSize:BigInteger -> soInitExpr:string option -> codec:Codec -> string;
abstract member seqOf_FixedSize : p:string -> sTasName:string -> i:string -> sInternalItem:string -> nFixedSize:BigInteger -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> nAlignSize:BigInteger -> sChildInitExpr:string -> codec:Codec -> string;
abstract member seqOf_VarSize : p:string -> sAcc:string -> sTasName:string -> i:string -> sInternalItem:string -> nSizeMin:BigInteger -> nSizeMax:BigInteger -> nSizeInBits:BigInteger -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> nAlignSize:BigInteger -> sChildInitExpr:string -> sErrCode:string -> codec:Codec -> string;
abstract member seqOf_VarSize : p:string -> sAcc:string -> sTasName:string -> i:string -> sInternalItem:string -> nSizeMin:BigInteger -> nSizeMax:BigInteger -> nSizeInBits:BigInteger -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> nAlignSize:BigInteger -> sChildInitExpr:string -> sErrCode:string -> nAbsOffset:BigInteger -> nRemainingMinBits:BigInteger -> nLevel:BigInteger -> nIx:BigInteger -> nOffset:BigInteger -> bIntroSnap:bool -> soPreSerde:string option -> soPostSerde:string option -> soPostInc:string option -> soInvariant:string option -> codec:Codec -> string;
abstract member octet_FixedSize : sTypeDefName:string -> p:string -> sAcc:string -> nFixedSize:BigInteger -> codec:Codec -> string;
abstract member octet_VarSize : sTypeDefName:string -> p:string -> sAcc:string -> nSizeMin:BigInteger -> nSizeMax:BigInteger -> nSizeInBits:BigInteger -> sErrCode:string -> codec:Codec -> string;
abstract member bitString_FixSize : sTypeDefName:string -> p:string -> sAcc:string -> nFixedSize:BigInteger -> sErrCode:string -> codec:Codec -> string;
Expand Down Expand Up @@ -364,7 +364,7 @@ Generated by the C stg macros with the following command
abstract member EmitAcnParameter : sName:string -> sType:string -> string;
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;
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;
abstract member alignToNext : sMainBody:string -> sAlignmentValue:string -> nAlignmentValue:BigInteger -> codec:Codec -> string;
abstract member alignToNext : sMainBody:string -> sAlignmentValue:string -> nAlignmentValue:BigInteger -> nAbsOffset:BigInteger -> nRemainingMinBits:BigInteger -> nLevel:BigInteger -> nIx:BigInteger -> nOffset:BigInteger -> codec:Codec -> string;
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;
abstract member PositiveInteger_ConstSize_8 : p:string -> sSsuffix:string -> sErrCode:string -> soMF:string option -> soMFM:string option -> nUperMin:BigInteger -> nUperMax:BigInteger -> codec:Codec -> string;
abstract member PositiveInteger_ConstSize_big_endian_16 : p:string -> sSsuffix:string -> sErrCode:string -> soMF:string option -> soMFM:string option -> nUperMin:BigInteger -> nUperMax:BigInteger -> codec:Codec -> string;
Expand Down Expand Up @@ -408,11 +408,11 @@ Generated by the C stg macros with the following command
abstract member Acn_String_Ascii_Internal_Field_Determinant : p:string -> sErrCode:string -> nAsn1Max:BigInteger -> nAsn1Min:BigInteger -> nInternalLengthDeterminantSizeInBits:BigInteger -> codec:Codec -> string;
abstract member Acn_String_CharIndex_FixSize : p:string -> sErrCode:string -> nAsn1Max:BigInteger -> arrnAlphabetAsciiCodes:seq<BigInteger> -> nCharSetSize:BigInteger -> td:FE_StringTypeDefinition -> nCharSize:BigInteger -> codec:Codec -> string;
abstract member Acn_String_CharIndex_External_Field_Determinant : p:string -> sErrCode:string -> nAsn1Max:BigInteger -> arrnAlphabetAsciiCodes:seq<BigInteger> -> nCharSetSize:BigInteger -> sExtFld:string -> td:FE_StringTypeDefinition -> nCharSize:BigInteger -> codec:Codec -> string;
abstract member Acn_IA5String_CharIndex_External_Field_Determinant : p:string -> sErrCode:string -> nAsn1Max:BigInteger -> sExtFld:string -> td:FE_StringTypeDefinition -> nCharSize:BigInteger -> codec:Codec -> string;
abstract member Acn_IA5String_CharIndex_External_Field_Determinant : p:string -> sErrCode:string -> nAsn1Max:BigInteger -> sExtFld:string -> td:FE_StringTypeDefinition -> nCharSize:BigInteger -> nRemainingBits:BigInteger -> codec:Codec -> string;
abstract member oct_external_field : sTypedefName:string -> p:string -> sAcc:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> bIsUnsigned:bool -> nAlignSize:BigInteger -> sErrCode:string -> codec:Codec -> string;
abstract member oct_external_field_fix_size : sTypedefName:string -> p:string -> sAcc:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> bIsUnsigned:bool -> nAlignSize:BigInteger -> sErrCode:string -> codec:Codec -> string;
abstract member sqf_external_field : sTypeDefName:string -> p:string -> sAcc:string -> i:string -> sInternalItem:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> bIsUnsigned:bool -> nAlignSize:BigInteger -> sErrCode:string -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> sChildInitExpr:string -> codec:Codec -> string;
abstract member sqf_external_field_fix_size : sTypeDefName:string -> p:string -> sAcc:string -> i:string -> sInternalItem:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> bIsUnsigned:bool -> nAlignSize:BigInteger -> sErrCode:string -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> sChildInitExpr:string -> codec:Codec -> string;
abstract member sqf_external_field : sTypeDefName:string -> p:string -> sAcc:string -> i:string -> sInternalItem:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> bIsUnsigned:bool -> nAlignSize:BigInteger -> sErrCode:string -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> sChildInitExpr:string -> bIntroSnap:bool -> soPreSerde:string option -> soPostSerde:string option -> soPostInc:string option -> soInvariant:string option -> codec:Codec -> string;
abstract member sqf_external_field_fix_size : sTypeDefName:string -> p:string -> sAcc:string -> i:string -> sInternalItem:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> bIsUnsigned:bool -> nAlignSize:BigInteger -> sErrCode:string -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> sChildInitExpr:string -> bIntroSnap:bool -> soPreSerde:string option -> soPostSerde:string option -> soPostInc:string option -> soInvariant:string option -> codec:Codec -> string;
abstract member oct_sqf_null_terminated : p:string -> sAcc:string -> i:string -> sInternalItem:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> arruNullBytes:seq<byte> -> nBitPatternLength:BigInteger -> sErrCode:string -> nIntItemMinSize:BigInteger -> nIntItemMaxSize:BigInteger -> codec:Codec -> string;
abstract member bit_string_external_field : sTypeDefName:string -> p:string -> sErrCode:string -> sAcc:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> codec:Codec -> string;
abstract member bit_string_external_field_fixed_size : sTypeDefName:string -> p:string -> sErrCode:string -> sAcc:string -> noSizeMin:BigInteger option -> nSizeMax:BigInteger -> sExtFld:string -> codec:Codec -> string;
Expand Down
Loading

0 comments on commit c9becef

Please sign in to comment.