diff --git a/Antlr/asn1.g b/Antlr/asn1.g index c05a84aed..f26fea21b 100644 --- a/Antlr/asn1.g +++ b/Antlr/asn1.g @@ -343,7 +343,7 @@ bitStringType ; bitStringItem - : identifier a=L_PAREN (INT|valuereference) R_PAREN -> ^(NUMBER_LST_ITEM[$a] identifier INT? valuereference?) + : identifier a=L_PAREN (INT|definedValue) R_PAREN -> ^(NUMBER_LST_ITEM[$a] identifier INT? definedValue?) ; booleanType diff --git a/BackendAst/DAstTypeDefinition.fs b/BackendAst/DAstTypeDefinition.fs index 9896f699f..738bc1290 100644 --- a/BackendAst/DAstTypeDefinition.fs +++ b/BackendAst/DAstTypeDefinition.fs @@ -191,11 +191,24 @@ let createOctetString (r:Asn1AcnAst.AstRoot) (l:ProgrammingLanguage) (t:Asn1Acn let createBitString (r:Asn1AcnAst.AstRoot) (l:ProgrammingLanguage) (t:Asn1AcnAst.Asn1Type) (o:Asn1AcnAst.BitString) (us:State) = let td = o.typeDef.[l] - let define_new_bit_string = match l with C -> header_c.Define_new_bit_string | Ada -> header_a.Define_new_bit_string + let define_new_bit_string = match l with C -> header_c.Define_new_bit_string | Ada -> header_a.Define_new_bit_string + let define_named_bit = match l with C -> header_c.Define_new_bit_string_named_bit | Ada -> header_a.Define_new_bit_string_named_bit + let define_subType_bit_string = match l with C -> header_c.Define_subType_bit_string | Ada -> header_a.Define_subType_bit_string match td.kind with | NonPrimitiveNewTypeDefinition -> - let completeDefintion = define_new_bit_string td (o.minSize.uper) (o.maxSize.uper) (o.minSize.uper = o.maxSize.uper) (BigInteger o.MaxOctets) + let nblist = + o.namedBitList |> + List.filter(fun nb -> nb.resolvedValue < 64I) |> + List.map(fun nb -> + let hexValue = + let aa = int nb.resolvedValue + let hexVal = ((uint64 1) <<< aa) + hexVal.ToString("X") + let sComment = sprintf "(1 << %A)" nb.resolvedValue + define_named_bit td (ToC (nb.Name.Value.ToUpper())) hexValue sComment + ) + let completeDefintion = define_new_bit_string td (o.minSize.uper) (o.maxSize.uper) (o.minSize.uper = o.maxSize.uper) (BigInteger o.MaxOctets) nblist Some completeDefintion | NonPrimitiveNewSubTypeDefinition subDef -> let otherProgramUnit = if td.programUnit = subDef.programUnit then None else (Some subDef.programUnit) diff --git a/BackendAst/PrintAsn1.fs b/BackendAst/PrintAsn1.fs index fa109ecbc..64c01f3d7 100644 --- a/BackendAst/PrintAsn1.fs +++ b/BackendAst/PrintAsn1.fs @@ -76,7 +76,7 @@ let rec PrintType (t:Asn1Type) (m:Asn1Module) (bPrintInSignleModule:bool) = |Integer -> stg_asn1.Print_Integer "" cons |Real -> stg_asn1.Print_Real cons |Boolean -> stg_asn1.Print_Boolean cons - |BitString -> stg_asn1.Print_BitString cons + |BitString _-> stg_asn1.Print_BitString cons |OctetString-> stg_asn1.Print_OctetString cons |NullType -> stg_asn1.Print_NullType cons |IA5String -> stg_asn1.Print_IA5String cons diff --git a/CommonTypes/CommonTypes.fs b/CommonTypes/CommonTypes.fs index 9332dae4e..0da9a82f5 100644 --- a/CommonTypes/CommonTypes.fs +++ b/CommonTypes/CommonTypes.fs @@ -747,3 +747,21 @@ type AntlrParserResult = { type ContainedInOctOrBitString = | ContainedInOctString | ContainedInBitString + + +type IntegerOrDefinedValue = + | IDV_IntegerValue of IntLoc //integer literal i.e. 5 + | IDV_DefinedValue of (StringLoc*StringLoc) // reference to an integer value assignment defined in another module + +type NamedBit0 = { + Name:StringLoc + _value : IntegerOrDefinedValue + Comments: string array +} + +type NamedBit1 = { + Name:StringLoc + resolvedValue : BigInteger + _value : IntegerOrDefinedValue + Comments: string array +} diff --git a/FrontEndAst/AcnCreateFromAntlr.fs b/FrontEndAst/AcnCreateFromAntlr.fs index 477c64491..8529fd539 100644 --- a/FrontEndAst/AcnCreateFromAntlr.fs +++ b/FrontEndAst/AcnCreateFromAntlr.fs @@ -502,7 +502,15 @@ let private mergeOctetStringType (asn1:Asn1Ast.AstRoot) (loc:SrcLoc) (acnErrLoc: let typeDef, us1 = getSizeableTypeDifition tdarg us {OctetString.acnProperties = acnProperties; cons = cons; withcons = withcons; minSize=minSize; maxSize =maxSize; uperMaxSizeInBits = uperMaxSizeInBits; uperMinSizeInBits=uperMinSizeInBits; acnEncodingClass = acnEncodingClass; acnMinSizeInBits=acnMinSizeInBits; acnMaxSizeInBits = acnMaxSizeInBits; typeDef=typeDef}, us1 -let private mergeBitStringType (asn1:Asn1Ast.AstRoot) (loc:SrcLoc) (acnErrLoc: SrcLoc option) (props:GenericAcnProperty list) cons withcons (tdarg:GetTypeDifition_arg) (us:Asn1AcnMergeState) = +let private mergeBitStringType (asn1:Asn1Ast.AstRoot) (namedBitList: NamedBit0 list) (loc:SrcLoc) (acnErrLoc: SrcLoc option) (props:GenericAcnProperty list) cons withcons (tdarg:GetTypeDifition_arg) (us:Asn1AcnMergeState) = + let newNamedBitList = + namedBitList |> List.map(fun nb -> + let resolvedValue = + match nb._value with + | IDV_IntegerValue intVal -> intVal.Value + | IDV_DefinedValue (mdVal, refVal) -> Asn1Ast.GetValueAsInt (Asn1Ast.GetBaseValue mdVal refVal asn1) asn1 + {NamedBit1.Name = nb.Name; _value = nb._value; resolvedValue = resolvedValue; Comments = nb.Comments}) + let sizeUperRange = uPER.getBitStringUperRange cons loc let sizeUperAcnRange = uPER.getBitStringUperRange (cons@withcons) loc //let minSize, maxSize = uPER.getSizeMinAndMaxValue loc sizeUperRange @@ -525,7 +533,7 @@ let private mergeBitStringType (asn1:Asn1Ast.AstRoot) (loc:SrcLoc) (acnErrLoc: S let acnEncodingClass, acnMinSizeInBits, acnMaxSizeInBits= AcnEncodingClasses.GetBitStringEncodingClass aligment loc acnProperties acnUperMinSizeInBits uperMaxSizeInBits minSize.acn maxSize.acn let typeDef, us1 = getSizeableTypeDifition tdarg us - {BitString.acnProperties = acnProperties; cons = cons; withcons = withcons; minSize=minSize; maxSize =maxSize; uperMaxSizeInBits = uperMaxSizeInBits; uperMinSizeInBits=uperMinSizeInBits; acnEncodingClass = acnEncodingClass; acnMinSizeInBits=acnMinSizeInBits; acnMaxSizeInBits = acnMaxSizeInBits; typeDef=typeDef}, us1 + {BitString.acnProperties = acnProperties; cons = cons; withcons = withcons; minSize=minSize; maxSize =maxSize; uperMaxSizeInBits = uperMaxSizeInBits; uperMinSizeInBits=uperMinSizeInBits; acnEncodingClass = acnEncodingClass; acnMinSizeInBits=acnMinSizeInBits; acnMaxSizeInBits = acnMaxSizeInBits; typeDef=typeDef; namedBitList = newNamedBitList}, us1 let private mergeNullType (acnErrLoc: SrcLoc option) (props:GenericAcnProperty list) (tdarg:GetTypeDifition_arg) (us:Asn1AcnMergeState) = let getRtlTypeName l = match l with C -> "", header_c.Declare_NullType (), "NULL" | Ada -> "adaasn1rtl", header_a.Declare_NULLNoRTL (), "NULL" @@ -891,10 +899,10 @@ let rec private mergeType (asn1:Asn1Ast.AstRoot) (acn:AcnAst) (m:Asn1Ast.Asn1Mo let wcons = withCons |> List.collect fixConstraint |> List.map (ConstraintsMapping.getOctetStringConstraint asn1 t) let o, us1 = mergeOctetStringType asn1 t.Location acnErrLoc combinedProperties cons wcons tfdArg us OctetString o, us1 - | Asn1Ast.BitString -> + | Asn1Ast.BitString namedBitList -> let cons = t.Constraints@refTypeCons |> List.collect fixConstraint |> List.map (ConstraintsMapping.getBitStringConstraint asn1 t) let wcons = withCons |> List.collect fixConstraint |> List.map (ConstraintsMapping.getBitStringConstraint asn1 t) - let o, us1 = mergeBitStringType asn1 t.Location acnErrLoc combinedProperties cons wcons tfdArg us + let o, us1 = mergeBitStringType asn1 namedBitList t.Location acnErrLoc combinedProperties cons wcons tfdArg us BitString o, us1 | Asn1Ast.NullType -> let constraints = [] diff --git a/FrontEndAst/Asn1AcnAst.fs b/FrontEndAst/Asn1AcnAst.fs index f97a84043..daafd7bb1 100644 --- a/FrontEndAst/Asn1AcnAst.fs +++ b/FrontEndAst/Asn1AcnAst.fs @@ -355,7 +355,7 @@ type BitString = { acnMinSizeInBits : BigInteger acnEncodingClass : SizeableAcnEncodingClass typeDef : Map - + namedBitList : NamedBit1 list } type TimeType = { diff --git a/FrontEndAst/Asn1Ast.fs b/FrontEndAst/Asn1Ast.fs index 5edfe5e2b..4ba36aab7 100644 --- a/FrontEndAst/Asn1Ast.fs +++ b/FrontEndAst/Asn1Ast.fs @@ -134,7 +134,7 @@ and Asn1TypeKind = | OctetString | NullType | TimeType of TimeTypeClass - | BitString + | BitString of list | Boolean | ObjectIdentifier | RelativeObjectIdentifier @@ -351,7 +351,7 @@ let rec getASN1Name (r:AstRoot) (t:Asn1Type) = | NumericString -> "NumericString" | OctetString -> "OCTET STRING" | NullType -> "NULL" - | BitString -> "BIT STRING" + | BitString _ -> "BIT STRING" | Boolean -> "BOOLEAN" | Enumerated _ -> "ENUMERATED" | SequenceOf _ -> "SEQUENCE OF" diff --git a/FrontEndAst/CheckAsn1.fs b/FrontEndAst/CheckAsn1.fs index adfa13b83..abaa85a29 100644 --- a/FrontEndAst/CheckAsn1.fs +++ b/FrontEndAst/CheckAsn1.fs @@ -285,7 +285,7 @@ let rec CheckIfVariableViolatesTypeConstraints (t:Asn1Type) (v:Asn1Value) ast = let bitOrOctSrt = match (Asn1Ast.GetActualType t ast).Kind with | OctetString -> Some TP_OCT_STR - | BitString -> Some TP_BIT_STR + | BitString _ -> Some TP_BIT_STR | _ -> None let ret = t.Constraints |> Seq.forall(fun c -> IsValueAllowed c v false bitOrOctSrt ast ) match v.Kind, t.Kind with @@ -548,7 +548,7 @@ let rec CheckType(t:Asn1Type) (m:Asn1Module) ast = | Some itm -> () | None -> raise(SemanticError(t.Location, "The constraints defined for this type do not allow any value")) - | BitString -> () + | BitString _ -> () | Integer -> () | TimeType _ -> () (* ++++ diff --git a/FrontEndAst/ConstraintsMapping.fs b/FrontEndAst/ConstraintsMapping.fs index 1f5f4bc53..751bc7dfb 100644 --- a/FrontEndAst/ConstraintsMapping.fs +++ b/FrontEndAst/ConstraintsMapping.fs @@ -334,7 +334,7 @@ let rec getAnyConstraint (r:Asn1Ast.AstRoot) (t:Asn1Ast.Asn1Type) (c:Asn1Ast.Asn |Asn1Ast.OctetString -> OctetStringConstraint (getOctetStringConstraint r t c) |Asn1Ast.NullType -> NullConstraint |Asn1Ast.TimeType _ -> TimeConstraint (getTimeConstraint r t c) - |Asn1Ast.BitString -> BitStringConstraint (getBitStringConstraint r t c) + |Asn1Ast.BitString _ -> BitStringConstraint (getBitStringConstraint r t c) |Asn1Ast.Boolean -> BoolConstraint (getBoolConstraint r t c) |Asn1Ast.ObjectIdentifier -> ObjectIdConstraint(getObjectIdConstraint r t c) |Asn1Ast.RelativeObjectIdentifier -> ObjectIdConstraint(getObjectIdConstraint r t c) diff --git a/FrontEndAst/CreateAsn1AstFromAntlrTree.fs b/FrontEndAst/CreateAsn1AstFromAntlrTree.fs index 571645077..46366e8d1 100644 --- a/FrontEndAst/CreateAsn1AstFromAntlrTree.fs +++ b/FrontEndAst/CreateAsn1AstFromAntlrTree.fs @@ -196,7 +196,7 @@ let rec CreateType (tasParameters : TemplateParameter list) (acnTypeEncodingSpec | asn1Parser.SEQUENCE_TYPE -> Sequence(CreateSequenceChild tasParameters acnTypeEncodingSpec astRoot typeNode fileTokens alreadyTakenComments ) | asn1Parser.SET_TYPE -> Sequence(CreateSequenceChild tasParameters acnTypeEncodingSpec astRoot typeNode fileTokens alreadyTakenComments ) | asn1Parser.ENUMERATED_TYPE -> Enumerated(CreateNamedItems astRoot typeNode fileTokens alreadyTakenComments) - | asn1Parser.BIT_STRING_TYPE -> BitString + | asn1Parser.BIT_STRING_TYPE -> BitString(CreateNamedBitList astRoot typeNode fileTokens alreadyTakenComments) | asn1Parser.OCTECT_STING -> OctetString | asn1Parser.IA5String -> IA5String | asn1Parser.NumericString -> NumericString @@ -276,18 +276,19 @@ and CreateChoiceChild (tasParameters : TemplateParameter list) (chAcnTypeEncodin | _ -> raise (BugErrorException("Bug in CreateChoiceChild")) ) +and singleReference2DoubleReference (tree:ITree) = + let strVal = tree.GetChild(0).TextL + let modl = tree.GetAncestor(asn1Parser.MODULE_DEF) + let modName = modl.GetChild(0).TextL + let imports = modl.GetChildrenByType(asn1Parser.IMPORTS_FROM_MODULE) + let importedFromModule = imports |> List.tryFind(fun imp-> imp.GetChildrenByType(asn1Parser.LID) |> Seq.exists(fun impTypeName -> impTypeName.Text = strVal.Value )) + let valToReturn = + match importedFromModule with + |Some(imp) -> ( imp.GetChild(0).TextL, strVal) + |None -> ( modName, strVal) + valToReturn + and CreateValue (astRoot:list) (tree:ITree ) : Asn1Value= - let singleReference2DoubleReference (tree:ITree) = - let strVal = tree.GetChild(0).TextL - let modl = tree.GetAncestor(asn1Parser.MODULE_DEF) - let modName = modl.GetChild(0).TextL - let imports = modl.GetChildrenByType(asn1Parser.IMPORTS_FROM_MODULE) - let importedFromModule = imports |> List.tryFind(fun imp-> imp.GetChildrenByType(asn1Parser.LID) |> Seq.exists(fun impTypeName -> impTypeName.Text = strVal.Value )) - let valToReturn = - match importedFromModule with - |Some(imp) -> ( imp.GetChild(0).TextL, strVal) - |None -> ( modName, strVal) - valToReturn let GetActualString (str:string) = @@ -463,6 +464,28 @@ and CreateNamedItems (astRoot:list) (tree:ITree) (fileTokens:array List.map CreateItem +and CreateNamedBitList (astRoot:list) (tree:ITree) (fileTokens:array) (alreadyTakenComments:System.Collections.Generic.List)= + let CreateNamedBit(itemItree:ITree) = + let itemChildren = getTreeChildren(itemItree) + match itemChildren with + | name::vlue::_ -> + let value = + match vlue.Type with + | asn1Parser.INT -> + match vlue.BigIntL.Value >= 0I with + | true -> IDV_IntegerValue(vlue.BigIntL) + | false -> raise (SemanticError(vlue.Location, "Negative values are not permitted")) + | asn1Parser.DEFINED_VALUE -> + match vlue.ChildCount with + | 2 -> IDV_DefinedValue(vlue.GetChild(0).TextL, vlue.GetChild(1).TextL) + | 1 -> IDV_DefinedValue(singleReference2DoubleReference vlue) + | _ -> raise (BugErrorException("Bug in CreateValue CreateNamedBit 1")) + | _ -> raise (BugErrorException("Bug in CreateValue CreateNamedBit 2")) + {NamedBit0.Name=name.TextL; _value=value; Comments = Antlr.Comment.GetComments(fileTokens, alreadyTakenComments, fileTokens.[itemItree.TokenStopIndex].Line, itemItree.TokenStartIndex - 1, itemItree.TokenStopIndex + 2)} + | _ -> raise (BugErrorException("Bug in CreateNamedBitList.CreateItem")) + let namedBits = getChildrenByType(tree, asn1Parser.NUMBER_LST_ITEM) + namedBits |> List.map CreateNamedBit + and CreateTimeClass (astRoot:list) (tree:ITree) (fileTokens:array) (alreadyTakenComments:System.Collections.Generic.List)= let rec removeSpaceArountEqual (str:string) = let rs = [" =";"\t=";"\r\n=";"\r=";"\n=";"= ";"=\t";"=\r\n";"=\r";"=\n"] diff --git a/FrontEndAst/FE_TypeDefinition.fs b/FrontEndAst/FE_TypeDefinition.fs index 41abc9ba9..71feaf28e 100644 --- a/FrontEndAst/FE_TypeDefinition.fs +++ b/FrontEndAst/FE_TypeDefinition.fs @@ -491,7 +491,7 @@ let getRefereceTypeDefinition (asn1:Asn1Ast.AstRoot) (t:Asn1Ast.Asn1Type) (arg:G | Asn1Ast.Boolean -> getPrimitiveTypeDifition arg us |> (fun (a,b) -> a |> Map.toList |> List.map (fun (l, d) -> (l, FE_PrimitiveTypeDefinition d)) |> Map.ofList,b) | Asn1Ast.Enumerated _ -> getEnumeratedTypeDifition arg us |> (fun (a,b) -> a |> Map.toList |> List.map (fun (l, d) -> (l, FE_EnumeratedTypeDefinition d)) |> Map.ofList,b) | Asn1Ast.OctetString -> getSizeableTypeDifition arg us |> (fun (a,b) -> a |> Map.toList |> List.map (fun (l, d) -> (l, FE_SizeableTypeDefinition d)) |> Map.ofList,b) - | Asn1Ast.BitString -> getSizeableTypeDifition arg us |> (fun (a,b) -> a |> Map.toList |> List.map (fun (l, d) -> (l, FE_SizeableTypeDefinition d)) |> Map.ofList,b) + | Asn1Ast.BitString _ -> getSizeableTypeDifition arg us |> (fun (a,b) -> a |> Map.toList |> List.map (fun (l, d) -> (l, FE_SizeableTypeDefinition d)) |> Map.ofList,b) | Asn1Ast.SequenceOf _ -> getSizeableTypeDifition arg us |> (fun (a,b) -> a |> Map.toList |> List.map (fun (l, d) -> (l, FE_SizeableTypeDefinition d)) |> Map.ofList,b) | Asn1Ast.NumericString -> getStringTypeDifition arg us |> (fun (a,b) -> a |> Map.toList |> List.map (fun (l, d) -> (l, FE_StringTypeDefinition d)) |> Map.ofList,b) | Asn1Ast.IA5String -> getStringTypeDifition arg us |> (fun (a,b) -> a |> Map.toList |> List.map (fun (l, d) -> (l, FE_StringTypeDefinition d)) |> Map.ofList,b) diff --git a/FrontEndAst/MapParamAstToNonParamAst.fs b/FrontEndAst/MapParamAstToNonParamAst.fs index 3b7ac6305..3a51e7969 100644 --- a/FrontEndAst/MapParamAstToNonParamAst.fs +++ b/FrontEndAst/MapParamAstToNonParamAst.fs @@ -150,6 +150,26 @@ let rec MapAsn1Value (r:ParameterizedAsn1Ast.AstRoot) (kind: ParameterizedAsn1As |ParameterizedAsn1Ast.SeqOfValue(vals) -> match actKind with | ParameterizedAsn1Ast.SequenceOf(ch) -> Asn1Ast.SeqOfValue(vals |> List.mapi (fun idx v -> MapAsn1Value r ch.Kind typeScope (visitSeqOfValue variableScope idx) v)) + | ParameterizedAsn1Ast.BitString namedBits -> + let bitPos = + vals |> + List.map(fun chV -> + match chV.Kind with + | ParameterizedAsn1Ast.RefValue (_,refVal) -> + match namedBits |> Seq.tryFind(fun z -> z.Name.Value = refVal.Value) with + | None -> raise (SemanticError(v.Location, (sprintf "Expecting a BIT STRING value. '%s' is not defined as a named bit" refVal.Value))) + | Some nb -> + match nb._value with + | CommonTypes.IDV_IntegerValue intVal -> intVal.Value + | CommonTypes.IDV_DefinedValue (mdVal, refVal) -> ParameterizedAsn1Ast.GetValueAsInt (ParameterizedAsn1Ast.GetBaseValue mdVal refVal r) r + + | _ -> raise (SemanticError(v.Location, (sprintf "Expecting a BIT STRING value but found a SEQUENCE OF value" ))) + ) |> Set.ofList + let maxValue = bitPos.MaximumElement + + let bitStrVal = + [0I .. maxValue] |> List.map(fun bi -> if bitPos.Contains bi then '1' else '0') |> Seq.StrJoin "" + Asn1Ast.BitStringValue ({StringLoc.Value = bitStrVal; Location = v.Location}) | _ -> raise(SemanticError(v.Location, "Expecting a SEQUENCE OF value")) |ParameterizedAsn1Ast.SeqValue(vals) -> match actKind with @@ -309,7 +329,7 @@ and MapAsn1Type (r:ParameterizedAsn1Ast.AstRoot) typeScope (t:ParameterizedAsn1A | ParameterizedAsn1Ast.OctetString -> aux Asn1Ast.OctetString | ParameterizedAsn1Ast.TimeType cl -> aux (Asn1Ast.TimeType cl) | ParameterizedAsn1Ast.NullType -> aux Asn1Ast.NullType - | ParameterizedAsn1Ast.BitString -> aux Asn1Ast.BitString + | ParameterizedAsn1Ast.BitString nBits -> aux (Asn1Ast.BitString nBits) | ParameterizedAsn1Ast.Boolean -> aux Asn1Ast.Boolean | ParameterizedAsn1Ast.ObjectIdentifier -> aux Asn1Ast.ObjectIdentifier | ParameterizedAsn1Ast.RelativeObjectIdentifier -> aux Asn1Ast.RelativeObjectIdentifier diff --git a/FrontEndAst/ParameterizedAsn1Ast.fs b/FrontEndAst/ParameterizedAsn1Ast.fs index 4f693b61d..0ca178a1a 100644 --- a/FrontEndAst/ParameterizedAsn1Ast.fs +++ b/FrontEndAst/ParameterizedAsn1Ast.fs @@ -100,8 +100,8 @@ and Asn1TypeKind = | ObjectIdentifier | RelativeObjectIdentifier | TimeType of TimeTypeClass - | NullType - | BitString + | NullType + | BitString of list | Boolean | Enumerated of list | SequenceOf of Asn1Type @@ -109,6 +109,10 @@ and Asn1TypeKind = | Choice of list | ReferenceType of StringLoc*StringLoc*(ContainedInOctOrBitString option)*list +and BitStringPosition = { + Name:StringLoc +} + and TemplateArgument = | ArgType of Asn1Type | ArgValue of Asn1Value @@ -231,3 +235,37 @@ let rec GetActualType (t:Asn1Type) (r:AstRoot) = | None -> raise(SemanticError(tasname.Location, sprintf "Reference type: %s.%s can not be resolved" mn.Value tasname.Value )) | _ -> t + + +type Asn1Module with + member m.GetValueAsigByName(name:StringLoc) (r:AstRoot) = + let (n,loc) = name.AsTupple + let value = m.ValueAssignments |> Seq.tryFind(fun x -> x.Name = name) + match value with + | Some(v) -> v + | None -> + let othMods = m.Imports + |> Seq.filter(fun imp -> imp.Values |> Seq.exists(fun vname -> vname = name)) + |> Seq.map(fun imp -> imp.Name) |> Seq.toList + match othMods with + | firstMod::tail -> (getModuleByName r firstMod).GetValueAsigByName name r + | [] -> raise (SemanticError(loc, sprintf "No value assignment with name '%s' exists" n)) + + +let GetBaseValue modName vasName (r:AstRoot) = + let mdl = getModuleByName r modName + let vas = mdl.GetValueAsigByName vasName r + vas.Value + +let rec GetActualValue modName vasName (r:AstRoot) = + let baseVal = GetBaseValue modName vasName r + match baseVal.Kind with + |RefValue(newModName, newVasName) -> GetActualValue newModName newVasName r + | _ -> baseVal + + +let rec GetValueAsInt (v:Asn1Value) r= + match v.Kind with + | IntegerValue(a) -> a.Value + | RefValue(modName,valName) -> GetValueAsInt (GetActualValue modName valName r) r + | _ -> raise(SemanticError (v.Location, sprintf "Expecting Integer value")) diff --git a/FrontEndAst/ValuesMapping.fs b/FrontEndAst/ValuesMapping.fs index ad61ead5f..9cc00a02e 100644 --- a/FrontEndAst/ValuesMapping.fs +++ b/FrontEndAst/ValuesMapping.fs @@ -56,7 +56,7 @@ let rec mapValue | _ -> raise (SemanticError(v.Location, (sprintf "Expecting a %s value but found a BOOLEAN value" (Asn1Ast.getASN1Name r actualType)))) | Asn1Ast.BitStringValue v -> match actualType.Kind with - | Asn1Ast.BitString -> BitStringValue v + | Asn1Ast.BitString _ -> BitStringValue v | Asn1Ast.OctetString -> let arBytes = bitStringValueToByteArray v |> Seq.map(fun curByte -> {ByteLoc.Value = curByte; Location = v.Location}) |> Seq.toList OctetStringValue arBytes @@ -64,7 +64,7 @@ let rec mapValue | Asn1Ast.OctetStringValue bv -> match actualType.Kind with | Asn1Ast.OctetString -> OctetStringValue bv - | Asn1Ast.BitString -> + | Asn1Ast.BitString _ -> let bitStrVal = byteArrayToBitStringValue (bv |> List.map (fun z-> z.Value)) let location = match bv with [] -> emptyLocation | b1::_ -> b1.Location BitStringValue ({StringLoc.Value = bitStrVal; Location = location}) diff --git a/StgAda/spec_a.stg b/StgAda/spec_a.stg index 6fd1f848f..ecae3bb19 100644 --- a/StgAda/spec_a.stg +++ b/StgAda/spec_a.stg @@ -231,7 +231,13 @@ Define_subType_octet_string(td/*:FE_SizeableTypeDefinition*/, prTd/*:FE_Sizeable /*********************************** BIT STRING ************************************************************/ -Define_new_bit_string(td/*:FE_SizeableTypeDefinition*/, nMin, nMax, bFixedSize, nMaxOctets) ::= << +Define_new_bit_string_named_bit(td/*:FE_SizeableTypeDefinition*/, sTargetLangBitName, sHexValue, sComment) ::= << +_ : CONSTANT .Asn1UInt:= 16##; -- +>> + +Define_new_bit_string(td/*:FE_SizeableTypeDefinition*/, nMin, nMax, bFixedSize, nMaxOctets, arrsNamedBits) ::= << +}; separator="\n"> + SUBTYPE is integer range 1..; SUBTYPE IS .BitArray(); SUBTYPE is integer range ..; diff --git a/StgC/header_c.stg b/StgC/header_c.stg index f7a34af2b..fea8f62e4 100644 --- a/StgC/header_c.stg +++ b/StgC/header_c.stg @@ -139,7 +139,14 @@ typedef ; >> /*********************************** BIT STRING ************************************************************/ -Define_new_bit_string(td/*:FE_SizeableTypeDefinition*/, nMin, nMax, bFixedSize, nMaxOctets) ::= << + +Define_new_bit_string_named_bit(td/*:FE_SizeableTypeDefinition*/, sTargetLangBitName, sHexValue, sComment) ::= << +#define _ 0x /**/ +>> + +Define_new_bit_string(td/*:FE_SizeableTypeDefinition*/, nMin, nMax, bFixedSize, nMaxOctets, arrsNamedBits) ::= << +}; separator="\n"> + typedef struct { int nCount; /*Number of bits in the array. Max value is : */ diff --git a/v4Tests/test-cases/acn/08-BIT-STRING/007.asn1 b/v4Tests/test-cases/acn/08-BIT-STRING/007.asn1 new file mode 100644 index 000000000..37b7b77fe --- /dev/null +++ b/v4Tests/test-cases/acn/08-BIT-STRING/007.asn1 @@ -0,0 +1,9 @@ +TEST-CASE DEFINITIONS AUTOMATIC TAGS::= BEGIN + + FruitSaladType ::= BIT STRING { apple(0), avocado(1), banana(2), blackberry(3), blueberry(4), cherry(5), coconut(6), mango(7), melon(8), lemon(9), pear(10) } (SIZE (1..64)) + + mySalad FruitSaladType ::= { avocado, mango} + +END + +--TCLS FruitSaladType[]