Ejemplo n.º 1
0
        public static string CompareTo(SequenceOrSetType pThis, string varName, Asn1Value constValue)
        {
            string ret = string.Empty;

            string varName2 = varName;
            if (varName.Contains("->"))
                varName2 += ".";
            else
                varName2 += "->";

            ret += "(";

            SequenceOrSetValue val = constValue as SequenceOrSetValue;

            foreach (string id in val.m_children.Keys)
            {
                Asn1Value chVal = val.m_children[id];
                chVal.CName = val.CName + "." + id;
                INonPrimitiveCType chType = chVal.Type as INonPrimitiveCType;
                if (chType != null)
                    ret += chType.CompareTo(varName2 + id, chVal);
                else
                {
                    if (ret.EndsWith(")"))
                        ret += " && ";
                    ret += "(" + varName2+id + " == " + chVal.ToStringC() + ")";
                }
            }

            ret += ")";
            return ret;
        }
Ejemplo n.º 2
0
 public override SequenceOrSetType.Child CreateSequenceOrSetChildType(SequenceOrSetType.Child o)
 {
     return new ICDSequenceOrSetTypeChild(o);
 }
Ejemplo n.º 3
0
        public static void DeclareType(SequenceOrSetType pThis, StreamWriterLevel csFile, string TypeName, int level, string baseClassName)
        {
            csFile.WL(level, "public partial class {0} : {1}", TypeName, baseClassName);
            csFile.WL(level++, "{");

            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                csFile.WriteLine();

                ICSharpType childType = ch.m_type as ICSharpType;
                string propName = C.ID(ch.m_childVarName.Substring(0, 1).ToUpper() + ch.m_childVarName.Substring(1));

                if (childType.RequiresNewTypeDeclaration())
                {
                    childType.DeclareType(csFile, propName, level);
                    csFile.WriteLine();
                }

                

                csFile.WL(level, "public {0} {1}", ((ICSharpType)ch.m_type).DeclaredTypeName, C.ID(ch.m_childVarName));
                csFile.WL(level++, "{");

                csFile.WL(level, "get {{ return m_children[ClassDef.m_children[\"{0}\"].m_index] as {1}; }}", C.ID(ch.m_childVarName), ((ICSharpType)ch.m_type).DeclaredTypeName);
                
                csFile.WL(--level, "}");


                csFile.WL(level, "public {0} Create_{1}()", childType.DeclaredTypeName, C.ID(ch.m_childVarName));
                csFile.WL(level++, "{");

//                csFile.WL(level, "return CreateChild(\"{0}\");", C.ID(ch.m_childVarName));
                csFile.WL(level, "return CreateChild(\"{0}\") as {1};", C.ID(ch.m_childVarName), childType.DeclaredTypeName);
                csFile.WL(--level, "}");

            }

            CSharpType.WriteCustomAttrList(pThis, csFile, level);
            CSharpType.WriteEncodeDecodeMethods(pThis, csFile, level);

            csFile.WL(level, "static Asn1CompositeClass<OptionalNamedChild> _clsDef = new {0}ClassDefinition();",TypeName);
            csFile.WL(level, "public override Asn1CompositeClass<OptionalNamedChild> ClassDef");
            csFile.WL(level++, "{");
            csFile.WL(level, "get");
            csFile.WL(level++, "{");
            csFile.WL(level, "return _clsDef;");
            csFile.WL(--level, "}");
            csFile.WL(--level, "}");


            csFile.WL(level, "public {0}()", TypeName);
            csFile.WL(level++, "{");
            csFile.WL(level, "m_children = new Asn1Object[{0}];",pThis.m_children.Count);
            csFile.WL(--level, "}");

//class definition

            csFile.WL(level, "public class {0}ClassDefinition : Asn1CompositeClass<OptionalNamedChild>", TypeName);
            csFile.WL(level++, "{");

            csFile.WL(level, "public {0}ClassDefinition()", TypeName);
            csFile.WL(level++, "{");


            csFile.WL(level, "OptionalNamedChild ch;");
            int idx = 0;
            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {

                ICSharpType childType = ch.m_type as ICSharpType;

                csFile.WL(level, "ch = new OptionalNamedChild(\"{0}\", {1}, Create{2}, {3}, null);", C.ID(ch.m_childVarName), idx,
//                csFile.WL(level, "ch = new OptionalNamedChild(\"{0}\", {1}, delegate() {{return new {2}();}}, {3}, null);", C.ID(ch.m_childVarName), idx,
                    childType.DeclaredTypeName, (ch.m_optional ? "true" : "false"));
                idx++;

                ChoiceType chChild = ch.m_type.GetFinalType() as ChoiceType;
                if (chChild != null && !ch.m_type.IsTagged())
                {
//                    csFile.WL(level, "ch.UnTaggedChoice = true;");
//                    csFile.WL(level, "ch.m_childrenTags = new List<Tag>();");

                    List<Asn1Type.TagSequence> tags = chChild.getChildrenTags();
                    foreach (Asn1Type.TagSequence tgSq in tags)
                    {
//                        csFile.WL(level, "ch.m_childrenTags.Add(new Tag({0}, TagClass.{1}));", tgSq.m_tags[0].m_tag, tgSq.m_tags[0].m_class);

                        csFile.WL(level, "m_posChildren.Add(0x{0:X}, ch);", CalculateTag(tgSq.m_tags[0]));
                    }
                }
                else
                {
                    Asn1Type.Tag lstTag = ch.m_type.Tags.m_tags[0];
//                    csFile.WL(level, "ch.m_Tag = new Tag({0}, TagClass.{1});", lstTag.m_tag, lstTag.m_class);

                    csFile.WL(level, "m_posChildren.Add(0x{0:X}, ch);", CalculateTag(lstTag));
                }

                
                csFile.WL(level, "m_children.Add(\"{0}\", ch);", C.ID(ch.m_childVarName));
                csFile.WriteLine();


            }
            
            csFile.WL(--level, "}"); //constructor

            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                ICSharpType childType = ch.m_type as ICSharpType;
                csFile.WL(level, "public static {0} Create{0}() {{ return new {0}();}}", childType.DeclaredTypeName);

            }
            
            csFile.WL(--level, "}"); //internal class

           

            csFile.WL(--level, "}"); //class

        }
Ejemplo n.º 4
0
 public ICDSequenceOrSetTypeChild(SequenceOrSetType.Child o)
     : base(o)
 {
 }
Ejemplo n.º 5
0
        public static void Tabularize(SequenceOrSetType s, string tasName)
        {
            foreach (SequenceOrSetType.Child ch in s.m_children.Values)
            {
                ((ICDType)ch.m_type).Tabularize(tasName);
                if (ch.m_type.Constructed)
                {
                    TypeAssigment newTas = ((ICDModule)s.m_module).CreateNewTypeAssigment(ch.m_childVarName, ch.m_type, ch.m_comments);
                    ch.m_type = ReferenceType.CreateByName(newTas);
                }

            }
        }
Ejemplo n.º 6
0
        public static void PrintPreambleHtml(SequenceOrSetType pThis, StreamWriterLevel o, int p)
        {
            string comment = "Special field used by PER to indicate the presence/absence of optional and default fields.";
            if (pThis.IsPERExtensible())
                comment = "Special field used by PER to (a) mark the presence of extension(s) and (b) to indicate the presence/absence of optional and default fields.";
            List<ICDSequenceOrSetTypeChild> tmp = new List<ICDSequenceOrSetTypeChild>();
            foreach (ICDSequenceOrSetTypeChild ch in pThis.m_children.Values)
            {
                if (ch.m_optional || ch.m_defaultValue != null)
                    tmp.Add(ch);
            }
            if (tmp.Count > 0 || pThis.IsPERExtensible())
            {
                comment += "<br/><ul type=\"square\">";
                int bitStart = 0;
                if (pThis.IsPERExtensible())
                {
                    comment += string.Format("<li>bit0 == 1 &#8658 extension(s) is present");
                    bitStart++;
                }
                for (int i = 0; i < tmp.Count; i++)
                    comment += string.Format("<li>bit{0} == 1 &#8658 <font  color=\"#5F9EA0\" >{1}</font> is present</li>", i + bitStart, tmp[i].m_childVarName);
                comment += "</ul>";
            }
            string cssClass = "OddRow";
            o.WriteLine("<tr class=\"" + cssClass + "\">");
            o.WriteLine("<td class=\"no\">1</td>");
            o.WriteLine("<td class=\"field\">Preamble</td>");
            o.WriteLine("<td class=\"comment\">{0}</td>", comment);
            o.WriteLine("<td class=\"optional\">No</td>");
            o.WriteLine("<td class=\"type\">{0}</td>", "Bit mask");

            o.WriteLine("<td class=\"constraint\">{0}</td>", o.Constraint("N.A."));
            o.WriteLine("<td class=\"min\">{0}</td>", pThis.PreambleLength);
            o.WriteLine("<td class=\"max\">{0}</td>", pThis.PreambleLength);
            o.WriteLine("</tr>");
        }
Ejemplo n.º 7
0
        public static void PrintHtml(SequenceOrSetType pThis, PEREffectiveConstraint cns, StreamWriterLevel o, int lev, List<string> comment, TypeAssigment tas, List<IConstraint> additonalConstraints)
        {
            WithComponentsSeqConstraint withCom = null;

            if (additonalConstraints!=null && additonalConstraints.Count > 0)
                withCom = additonalConstraints[0] as WithComponentsSeqConstraint;

            o.WriteLine("<a name=\"{0}\"></a>", "ICD_" + tas.m_name.Replace("-", "_"));
            o.WriteLine("<table border=\"0\" width=\"100%\" >");
            o.WriteLine("<tbody>");
            o.WriteLine("<tr  bgcolor=\"{0}\">", (tas.m_createdThroughTabulization ? "#379CEE" : "#FF8f00"));
            o.WriteLine("<td height=\"35\" colspan=\"4\">");
            o.WriteLine("<font face=\"Verdana\" color=\"#FFFFFF\" size=\"4\">{0}</font><font face=\"Verdana\" color=\"#FFFFFF\" size=\"2\">({1}) </font>", tas.m_name, pThis.Name);
            o.WriteLine("<font face=\"Verdana\" color=\"#FFFFFF\" size=\"2\"><a href=\"#{0}\">ASN.1</a></font>", "ASN1_" + tas.m_name.Replace("-", "_"));
            o.WriteLine("</td>");
            o.WriteLine("<td height=\"35\" colspan=\"2\"  align=\"center\">");

            long minBytesInPER = pThis.MinBytesInPER;
            o.WriteLine("<font face=\"Verdana\" color=\"#FFFFFF\" size=\"2\">min = {0} bytes</font>", (minBytesInPER == -1 ? "&#8734" : minBytesInPER.ToString()));
            o.WriteLine("</td>");
            o.WriteLine("<td height=\"35\" colspan=\"2\" align=\"center\">");
            o.WriteLine("<font face=\"Verdana\" color=\"#FFFFFF\" size=\"2\">max = {0} bytes</font>", (pThis.MaxBytesInPER == -1 ? "&#8734" : pThis.MaxBytesInPER.ToString()));
            o.WriteLine("</td>");
            o.WriteLine("</tr>");

            if (comment.Count > 0)
            {
                o.WriteLine("<tr class=\"CommentRow\">");
                o.WriteLine("<td class=\"comment\" colspan=\"8\">" + o.BR(comment) + "</td>");
                o.WriteLine("</tr>");
            }

            o.WriteLine("<tr class=\"headerRow\">");
            o.WriteLine("<td class=\"hrNo\">No</td>");
            o.WriteLine("<td class=\"hrField\">Field</td>");
            o.WriteLine("<td class=\"hrComment\">Comment</td>");
            o.WriteLine("<td class=\"hrOptional\">Optional</td>");

            o.WriteLine("<td class=\"hrType\">Type</td>");
            o.WriteLine("<td class=\"hrconstraint\">Constraint</td>");
            o.WriteLine("<td class=\"hrMin\">Min Length (bits)</td>");
            o.WriteLine("<td class=\"hrMax\">Max Length (bits)</td>");
            o.WriteLine("</tr>");

            int index = 0;
            if (pThis.PreambleLength > 0)
            {
                PrintPreambleHtml(pThis, o, lev + 1);
                index = 1;
            }
            foreach (ICDSequenceOrSetTypeChild ch in pThis.m_children.Values)
            {
                WithComponentsConstraint.Component component = null;
                if (withCom != null && withCom.m_components.ContainsKey(ch.m_childVarName))
                    component = withCom.m_components[ch.m_childVarName];
                ch.PrintHtml(o, lev + 1, ++index, component);
            }
            o.WriteLine("</tbody>");
            o.WriteLine("</table>");
        }
Ejemplo n.º 8
0
        public static void PrintCDecode(SequenceOrSetType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string varName, int lev)
        {
            string varName2 = varName;
            if (!varName.Contains("->"))
                varName2 += "->";
            else
                varName2 += ".";

            int nBitMaskLength = (int)Math.Ceiling(pThis.GetNumberOfOptionalOrDefaultFields() / 8.0);
            //c.P(lev); c.WriteLine("{"); lev++;
            c.P(lev);
            if (nBitMaskLength > 0)
            {
                //c.WriteLine("byte bitMask[{0}];", nBitMaskLength);
                //c.P(lev);
                c.WriteLine("if (!BitStream_ReadBits(pBitStrm, bitMask, {0})) {{", pThis.GetNumberOfOptionalOrDefaultFields());
                c.P(lev + 1);
                c.WriteLine("*pErrCode = ERR_INSUFFICIENT_DATA;");
                c.P(lev + 1);
                c.WriteLine("return FALSE;");
                c.P(lev);
                c.WriteLine("}");
            }

            int currentByte = 0;
            int currentBit = 0;
            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                c.P(lev); c.WriteLine("/*Decode {0} ({1})*/", ch.m_childVarName, ch.m_type.Name);
                if (ch.m_optional || ch.m_default)
                {
                    byte cb = 0x80;
                    c.P(lev);
                    c.WriteLine("{0}exist.{1} = 0;", varName2, C.ID(ch.m_childVarName));

                    c.P(lev);
                    c.WriteLine("if ((bitMask[{0}] & 0x{1:X2}) != 0 ) {{", currentByte, (cb >> currentBit));

                    c.P(lev + 1);
                    c.WriteLine("{0}exist.{1} = 1;", varName2, C.ID(ch.m_childVarName));

                    ((ISCCType)ch.m_type).PrintCDecode(ch.m_type.PEREffectiveConstraint, c, varName2 + C.ID(ch.m_childVarName), lev + 1);
                    c.P(lev); c.WriteLine("}");
                    if (ch.m_defaultValue != null)
                    {
                        c.P(lev); c.WriteLine("else");
                        c.P(lev); c.WriteLine("{");

                        c.P(lev + 1);
                        c.WriteLine("{0}exist.{1} = 1;", varName2, C.ID(ch.m_childVarName));

                        ((ISCCType)ch.m_type).PrintCInitialize(ch.m_type.PEREffectiveConstraint, ch.m_defaultValue, c, "", varName2 + C.ID(ch.m_childVarName), lev + 1, CLocalVariable.GetArrayIndex(varName) + 1);
                        c.P(lev); c.WriteLine("}");
                    }

                    currentBit++;
                    if (currentBit == 8)
                    {
                        currentBit = 0;
                        currentByte++;
                    }
                }
                else
                {
                    ((ISCCType)ch.m_type).PrintCDecode(ch.m_type.PEREffectiveConstraint, c, varName2 + C.ID(ch.m_childVarName), lev);
                }
            }
            //lev--; c.P(lev); c.WriteLine("}");
        }
Ejemplo n.º 9
0
 public static void VarsNeededForPrintCInitialize(SequenceOrSetType pThis, int lev, OrderedDictionary<string, CLocalVariable> existingVars)
 {
     foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
     {
         ((ISCCType)ch.m_type).VarsNeededForPrintCInitialize(lev, existingVars);
     }
 }
Ejemplo n.º 10
0
        public static void VarsNeededForDecode(SequenceOrSetType pThis, PEREffectiveConstraint cns, int arrayDepth, OrderedDictionary<string, CLocalVariable> existingVars)
        {
            int nBitMaskLength = (int)Math.Ceiling(pThis.GetNumberOfOptionalOrDefaultFields() / 8.0);
            if (nBitMaskLength > 0)
            {
                if (!existingVars.ContainsKey("bitMask"))
                    existingVars.Add("bitMask", new CLocalVariable("bitMask", "byte", nBitMaskLength, ""));
                else
                {
                    CLocalVariable lv = existingVars["bitMask"];
                    if (lv.arrayLen < nBitMaskLength)
                        lv.arrayLen = nBitMaskLength;
                }
            }

            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                ((ISCCType)ch.m_type).VarsNeededForDecode(ch.m_type.PEREffectiveConstraint, arrayDepth, existingVars);
            }
        }
Ejemplo n.º 11
0
 public static void VarsNeededForEncode(SequenceOrSetType pThis, PEREffectiveConstraint cns, int arrayDepth, OrderedDictionary<string, CLocalVariable> existingVars)
 {
     foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
     {
         ((ISCCType)ch.m_type).VarsNeededForEncode(ch.m_type.PEREffectiveConstraint, arrayDepth, existingVars);
     }
 }
Ejemplo n.º 12
0
        public static void PrintHTypeDeclaration(SequenceOrSetType pThis, PEREffectiveConstraint cns, StreamWriterLevel h, string typeName, string varName, int lev)
        {
            h.WriteLine("struct {");
            //            h.WriteLine("struct {0} {{", typeName);
            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                h.WriteComment(ch.m_comments, lev + 1);
                h.P(lev + 1);
                ((ISCCType)ch.m_type).PrintHTypeDeclaration(ch.m_type.PEREffectiveConstraint, h,
                    typeName + "_" + C.ID(ch.m_childVarName), C.ID(ch.m_childVarName), lev + 1);
                if (!(ch.m_type is IA5StringType))
                    h.WriteLine(" {0};", C.ID(ch.m_childVarName));
            }
            if (pThis.GetNumberOfOptionalOrDefaultFields() != 0)
            {
                h.P(lev + 1);
                h.WriteLine("struct {");
                foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
                {
                    if (ch.m_optional || ch.m_defaultValue != null)
                    {
                        h.P(lev + 2);
                        h.WriteLine("unsigned int {0}:1;", C.ID(ch.m_childVarName));
                    }
                }
                h.P(lev + 1);
                h.WriteLine("} exist;");

            }
            h.P(lev);
            h.Write("}");
        }
Ejemplo n.º 13
0
 public static void PrintHConstraintConstant(SequenceOrSetType pThis, StreamWriterLevel h, string name)
 {
     CSSType.PrintHConstraintConstant(pThis, h, C.ID(name));
     foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
     {
         ((ISCCType)ch.m_type).PrintHConstraintConstant(h, C.ID(name) + "_" + C.ID(ch.m_childVarName));
     }
 }
Ejemplo n.º 14
0
        public static void PrintCIsConstraintValid(SequenceOrSetType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string typeName, string varName, int lev, int arrayDepth)
        {
            string varName2 = varName;
            if (!varName.Contains("->"))
                varName2 += "->";
            else
                varName2 += ".";

            CSSType.PrintCIsConstraintValid(pThis, cns, c, errorCode, typeName, varName, lev, arrayDepth);

            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                if (ch.m_optional || ch.m_default)
                {
                    c.P(lev);
                    c.WriteLine("if ( {0}exist.{1} ) {{", varName2, C.ID(ch.m_childVarName));

                    ((ISCCType)ch.m_type).PrintCIsConstraintValid(ch.m_type.PEREffectiveConstraint, c, errorCode + "_" + C.ID(ch.m_childVarName),
                        typeName + "_" + C.ID(ch.m_childVarName), varName2 + C.ID(ch.m_childVarName), lev + 1, arrayDepth);

                    c.P(lev); c.WriteLine("}");

                }
                else
                {
                    ((ISCCType)ch.m_type).PrintCIsConstraintValid(ch.m_type.PEREffectiveConstraint, c, errorCode + "_" + C.ID(ch.m_childVarName),
                        typeName + "_" + C.ID(ch.m_childVarName), varName2 + C.ID(ch.m_childVarName), lev, arrayDepth);
                }
                c.WriteLine();
            }
        }
Ejemplo n.º 15
0
        public static void PrintCInitialize(SequenceOrSetType pThis, PEREffectiveConstraint cns, Asn1Value defaultValue, StreamWriterLevel c, string typeName, string varName, int lev, int arrayDepth)
        {
            bool topLevel = !varName.Contains("->");
            string prefix = "";
            if (topLevel)
                prefix = varName + "->";
            else
                prefix = varName + ".";

            SCCSequenceOrSetValue defVal = defaultValue as SCCSequenceOrSetValue;
            if (defVal == null)
            {
                foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
                {
                    ((ISCCType)ch.m_type).PrintCInitialize(ch.m_type.PEREffectiveConstraint,
                        (ch.m_defaultValue!=null?ch.m_defaultValue:ch.m_type.GetOneValidValue()),
                        c, typeName + "_" + C.ID(ch.m_childVarName), prefix + C.ID(ch.m_childVarName), lev, arrayDepth);
                }
            }
            else
            {
                foreach (string chName in defVal.m_children.Keys)
                {
                    Asn1Value chVal = defVal.m_children[chName];
                    chVal.CName = defVal.CName + "." + C.ID(chName);
                    Asn1Type chType = pThis.m_children[chName].m_type;
                    ((ISCCType)chType).PrintCInitialize(chType.PEREffectiveConstraint, chVal, c,
                        typeName + "_" + C.ID(chName), prefix + C.ID(chName), lev, arrayDepth);

                }
            }
        }
Ejemplo n.º 16
0
        public static void PrintCEncode(SequenceOrSetType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string varName, int lev)
        {
            string varName2 = varName;
            if (!varName.Contains("->"))
                varName2 += "->";
            else
                varName2 += ".";
            if (pThis.GetNumberOfOptionalOrDefaultFields() > 0)
            {
                c.P(lev);
                c.WriteLine("/* Encode Bit Mask for optional and default fields*/");
            }

            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                if (ch.m_optional || ch.m_default)
                {
                    c.P(lev);
                    c.WriteLine("BitStream_AppendBit(pBitStrm, {0});", varName2 + "exist." + C.ID(ch.m_childVarName));
                }
            }
            c.WriteLine();
            foreach (SequenceOrSetType.Child ch in pThis.m_children.Values)
            {
                c.P(lev); c.WriteLine("/*Encode {0} ({1})*/", ch.m_childVarName, ch.m_type.Name);
                if (ch.m_optional || ch.m_default)
                {
                    c.P(lev);
                    c.WriteLine("if ( {0}exist.{1} ) {{", varName2, C.ID(ch.m_childVarName));
                    ((ISCCType)ch.m_type).PrintCEncode(ch.m_type.PEREffectiveConstraint, c, errorCode + "_" + C.ID(ch.m_childVarName), varName2 + C.ID(ch.m_childVarName), lev + 1);
                    c.P(lev); c.WriteLine("}");

                }
                else
                    ((ISCCType)ch.m_type).PrintCEncode(ch.m_type.PEREffectiveConstraint, c, errorCode + "_" + C.ID(ch.m_childVarName), varName2 + C.ID(ch.m_childVarName), lev);
                c.WriteLine();
            }
        }