Beispiel #1
0
        public static void PrintCIsConstraintValid(Asn1Type pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string typeName, string varName, int lev, int arrayDepth)
        {
            string varName2 = varName;
            if (!varName.Contains("->"))
                varName2 = "*" + varName;

            if (pThis.m_constraints.Count > 0)
            {
                c.P(lev); c.Write("if ( !(");
                for (int i = 0; i < pThis.m_constraints.Count; i++)
                {
                    string ret = ((ISCConstraint)pThis.m_constraints[i]).PrintCIsConstraintValid(varName2, lev);
                    c.Write(ret);
                    if (i != pThis.m_constraints.Count - 1)
                        c.Write(" && ");
                }
                c.WriteLine(") ) {");
                c.P(lev + 1);
                c.WriteLine("*pErrCode = ERR_{0};", C.ID(errorCode));
                c.P(lev + 1);
                c.WriteLine("return FALSE;");
                c.P(lev);
                c.WriteLine("}");
            }
        }
Beispiel #2
0
        public static void Print(StreamWriterLevel c, OrderedDictionary<string, CLocalVariable> vars)
        {
            foreach (CLocalVariable v in vars.Values)
            {
                c.P(1);
                if (v.staticDeclaration)
                    c.Write("static ");

                c.Write("{0} {1}", v.type, v.varName);

                if (v.arrayLen > 0)
                    c.Write("[{0}]",v.arrayLen);

                if (v.initVal != "")
                    c.Write(" = {0}", v.initVal);
                c.WriteLine(";");

                //if (v.arrayLen == 0)
                //{
                //    c.WriteLine("{0} {1} = {2};", v.type, v.varName, v.initVal);
                //}
                //else
                //{
                //    c.WriteLine("{0} {1}[{2}];", v.type, v.varName, v.arrayLen);
                //}

            }
            if (vars.Count > 0)
                c.WriteLine();
        }
Beispiel #3
0
        public static void dump(string fileName, string outFileName, bool ignoreExtraBytes, bool handleExtraBytesAsDNA)
        {
            using (MemoryStream f = new MemoryStream(File.ReadAllBytes(fileName), false))
            using (StreamWriterLevel w = new StreamWriterLevel(outFileName))
            {

                do
                {
                    BERNode root = BERNode.Create(f);
                    root.dump(w, 0);
                } while (!ignoreExtraBytes && handleExtraBytesAsDNA && f.Length>f.Position);

                if (!ignoreExtraBytes && !handleExtraBytesAsDNA && f.Position < f.Length)
                {
                    w.WriteLine("File contains {0} extra bytes at the end", f.Length-f.Position);
                    int rdVal = 0;

                    int col = 0;
                    while ((rdVal = f.ReadByte()) != -1)
                    {
                        col++;
                        if (col % 80 == 0)
                            w.WriteLine();
                        byte b = (byte)rdVal;
                        w.Write(b.ToString("X2"));
                    }

                }
            }
        }
Beispiel #4
0
        public static void PrintC(ArrayValue pThis, StreamWriterLevel c, int lev)
        {
            c.WriteLine("{");
            lev++;

            int cnt = pThis.m_children.Count;

            c.P(lev); c.WriteLine("{0},", cnt);

            c.P(lev); c.WriteLine("{");
            for (int i = 0; i < cnt; i++)
            {
                c.P(lev + 1);
                ((ISCCVariable)pThis.m_children[i]).PrintC(c, lev + 1);
                if (i != cnt - 1)
                    c.WriteLine(",");
                else
                    c.WriteLine();
            }
            c.P(lev); c.WriteLine("}");

            lev--;
            c.P(lev);
            c.Write("}");
        }
Beispiel #5
0
        public override void PrintAsn1(StreamWriterLevel o)
        {
            if (m_size != null)
            {

                o.Write("SIZE [");
                m_size.m_rootRange.PrintAsn1(o);
                if (m_size.Extensible)
                    o.Write(",...");
                if (m_size.m_extRange != null)
                {
                    o.Write(",");
                    m_size.m_extRange.PrintAsn1(o);
                }
                o.Write("]");
            }
            if (m_from != null)
            {
                o.Write("FROM [\"");
                o.Write(m_from.ToString());
                o.Write("\"]");
            }
        }
Beispiel #6
0
 public void PrintExternDeclaration(StreamWriterLevel h)
 {
     //            h.WriteLine("extern {0} {1};", C.ID(m_type.Name), C.ID(m_name));
     h.Write("extern ");
     ((ISCCType)m_type).PrintHTypeDeclaration(m_type.PEREffectiveConstraint, h, "", "", 0);
     h.WriteLine(" {0};", C.ID(m_name));
 }
Beispiel #7
0
 public void PrintHTypeDeclaration(PEREffectiveConstraint cns, StreamWriterLevel h, string typeName, string varName, int lev)
 {
     h.Write("NullType ");
 }
Beispiel #8
0
        public void PrintHTypeDeclaration(PEREffectiveConstraint cns, StreamWriterLevel h, string typeName, string varName, int lev)
        {
            h.WriteLine("enum {");
            //            h.WriteLine("enum {0} {{", typeName);
            int i = 0;
            foreach (Item it in m_enumValues.Values)
            {
                h.P(lev + 1);
                h.Write("{0} = {1}", it.CID, it.m_value);
                if (i < m_enumValues.Values.Count - 1)
                    h.WriteLine(",");
                else
                    h.WriteLine();
                i++;
            }

            h.P(lev);
            h.Write("}");
        }
Beispiel #9
0
 public static void PrintCEncodeItem(IA5StringType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string varName, int lev)
 {
     PERAlphabetAndSizeEffectiveConstraint cn = (PERAlphabetAndSizeEffectiveConstraint)cns;
     CharSet perAlphaCon = cn.m_from;
     int min = 0;
     int max;
     List<char> tmp = null;
     if (perAlphaCon != null)
         tmp = perAlphaCon.m_set;
     else
         tmp = new List<char>(pThis.AllowedCharSet);
     max = tmp.Count - 1;
     if (min == max)
         return;
     c.P(lev);
     c.Write("static byte allowedCharSet[] = {");
     for (int i = 0; i < tmp.Count; i++)
     {
         c.Write("0x{0:X2}", Convert.ToByte(tmp[i]));
         if (i == tmp.Count - 1)
             c.WriteLine("};");
         else
             c.Write(",");
         if ((i + 1) % 15 == 0)
         {
             c.WriteLine();
             c.P(lev + 7);
         }
     }
     c.P(lev);
     c.WriteLine("int charIndex = GetCharIndex({0}, allowedCharSet,{1});", varName, tmp.Count);
     c.P(lev);
     c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, charIndex, {0}, {1});", 0, tmp.Count - 1);
 }
Beispiel #10
0
 public void PrintHTypeDeclaration(PEREffectiveConstraint cns, StreamWriterLevel h, string typeName, string varName, int lev)
 {
     h.Write(DefaultBackend.Instance.TypePrefix + C.ID(m_referencedTypeName));
 }
Beispiel #11
0
 public void PrintHTypeDeclaration(PEREffectiveConstraint cns, StreamWriterLevel h, string typeName, string varName, int lev)
 {
     lev++;
     long max = maxItems(cns);
     h.WriteLine("struct {");
     h.P(lev + 1);
     h.WriteLine("long nCount;");
     h.P(lev + 1); h.WriteLine("byte arr[{0}];", max);
     h.P(lev);
     h.Write("}");
 }
Beispiel #12
0
 public static void PrintC(Asn1Value pThis, StreamWriterLevel c, int lev)
 {
     c.Write(pThis.ToStringC());
 }
Beispiel #13
0
        public void PrintC(StreamWriterLevel c, int lev)
        {
            //calculate optional fields which are present
            SequenceOrSetType myType = Type.GetFinalType() as SequenceOrSetType;
            List<string> existedFields = new List<string>();
            if (myType.GetNumberOfOptionalOrDefaultFields() > 0)
            {
                foreach (string varName in myType.m_children.Keys)
                {
                    SequenceOrSetType.Child ch = myType.m_children[varName];
                    if (ch.m_optional || ch.m_defaultValue != null)
                    {
                        if (m_children.ContainsKey(varName))
                        {
                            existedFields.Add(varName);
                        }
                    }
                }
            }

            c.WriteLine("{");
            int cnt = m_children.Count;
            for (int i = 0; i < cnt; i++)
            {
                c.P(lev + 1);
                c.Write(".{0} = ", m_children.Keys[i]);
                ((ISCCVariable)m_children.Values[i]).PrintC(c, lev + 1);
                if (i != cnt - 1 || existedFields.Count > 0)
                    c.WriteLine(",");
                else
                    c.WriteLine();
            }

            if (existedFields.Count > 0)
            {
                lev++;
                c.P(lev);
                c.WriteLine(".exist = {");
                lev++;

                cnt = existedFields.Count;
                for (int i = 0; i < cnt; i++)
                {
                    c.P(lev);
                    c.Write(".{0} = 1", existedFields[i]);
                    if (i != cnt - 1)
                        c.WriteLine(",");
                    else
                        c.WriteLine();
                }
                lev--;
                c.P(lev);
                c.WriteLine("}");
                lev--;
            }

            c.P(lev);
            c.Write("}");
        }
Beispiel #14
0
        public void PrintC(StreamWriterLevel c, int lev)
        {
            c.WriteLine("{");
            lev++;

            int cnt = Value.Count;

            c.P(lev); c.WriteLine("{0},", cnt);

            c.P(lev); c.WriteLine("{");
            for (int i = 0; i < cnt; i++)
            {
                c.P(lev + 1);
                c.Write("0x{0:X2}", Value[i]);
                if (i != cnt - 1)
                    c.WriteLine(",");
                else
                    c.WriteLine();
            }
            c.P(lev); c.WriteLine("}");

            lev--;
            c.P(lev);
            c.Write("}");
        }
Beispiel #15
0
        public void PrintC(StreamWriterLevel c, int lev)
        {
            c.WriteLine("{");
            c.P(lev + 1);
            c.WriteLine(".kind = {0},", ChoiceType.m_children[AlternativeName].CID);
            c.P(lev + 1);
            c.Write(".u = {{ .{0}=", ChoiceType.m_children[AlternativeName].CID.Replace("_PRESENT", ""));
            ((ISCCVariable)Value).PrintC(c, lev + 1);

            c.WriteLine();
            c.P(lev);
            c.Write("} }");
        }
Beispiel #16
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("}");
        }
Beispiel #17
0
 public override void PrintAsn1(StreamWriterLevel o)
 {
     o.Write("SIZE [");
     m_size.m_rootRange.PrintAsn1(o);
     if (m_size.Extensible)
         o.Write(",...");
     if (m_size.m_extRange != null)
     {
         o.Write(",");
         m_size.m_extRange.PrintAsn1(o);
     }
     o.Write("]");
 }
Beispiel #18
0
        public void PrintC(StreamWriterLevel c, int lev)
        {
            c.WriteLine("{");
            lev++;

            List<byte> val = OctetStringValue.ConvertToOctetArray(this,false);

            int cnt = val.Count;

            c.P(lev); c.WriteLine("{0},", this.Value.Length);

            c.P(lev); c.WriteLine("{");
            for (int i = 0; i < cnt; i++)
            {
                c.P(lev + 1);
                c.Write("0x{0:X2}", val[i]);
                if (i != cnt - 1)
                    c.WriteLine(",");
                else
                    c.WriteLine();
            }
            c.P(lev); c.WriteLine("}");

            lev--;
            c.P(lev);
            c.Write("}");
        }
Beispiel #19
0
        public void PrintAsn1InHtml(StreamWriterLevel wr, int lev)
        {
            //string fname = m_fileName.Substring(m_fileName.LastIndexOf(

            wr.WriteLine("    <div style=\"width: 100%\">");
            wr.WriteLine("    <h1 >File : {0}</h1>", System.IO.Path.GetFileName(m_fileName));
            wr.WriteLine("<div style=\"width: 100%; white-space:pre; font-family:Courier New; font-size:small\">");
            wr.Write(getAsn1InHtml());
            wr.WriteLine("</div>");
            wr.WriteLine("    </div>");
        }
Beispiel #20
0
        public void PrintCIsConstraintValidAuxBody(StreamWriterLevel c)
        {
            AuxFunctionID = nCount;

            c.WriteLine("flag CheckString{0}(const char* str)", AuxFunctionID);
            c.WriteLine("{");
            c.P(1); c.WriteLine("size_t i;");
            c.P(1); c.WriteLine("size_t n = strlen(str);");
            c.P(1);
            c.WriteLine("for(i=0;i<n;i++)");
            c.P(1); c.WriteLine("{");

            c.P(2);
            c.Write("if (!");
            for (int i = 0; i < allowed_char_set.m_constraints.Count; i++)
            {
                c.Write(((ISCConstraint)allowed_char_set.m_constraints[i]).PrintCIsConstraintValid("str[i]", 0));
                if (i != allowed_char_set.m_constraints.Count - 1)
                    c.Write(" && ");
            }
            c.WriteLine(")");
            c.P(3);
            c.WriteLine("return FALSE;");
            c.P(1); c.WriteLine("}");

            c.P(1); c.WriteLine("return TRUE;");
            c.WriteLine("}");
        }
Beispiel #21
0
        public void PrintCIsConstraintValid(PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string typeName, string varName, int lev, int arrayDepth)
        {
            c.P(lev); c.Write("if ( !");
            if ((Type is IA5StringType) || !varName.Contains("->"))
                c.WriteLine("{0}_IsConstraintValid({1}, pErrCode) )", DefaultBackend.Instance.TypePrefix + C.ID(m_referencedTypeName), varName);
            else
                c.WriteLine("{0}_IsConstraintValid(&{1}, pErrCode) )", DefaultBackend.Instance.TypePrefix + C.ID(m_referencedTypeName), varName);

            c.P(lev);
            c.WriteLine("{");
            //c.P(lev + 1);
            //c.WriteLine("*pErrCode = ERR_{0};", C.ID(errorCode));
            c.P(lev + 1);
            c.WriteLine("return FALSE;");
            c.P(lev);
            c.WriteLine("}");

            CSSType.PrintCIsConstraintValid(this, cns, c, errorCode, typeName, varName, lev, arrayDepth);
        }
Beispiel #22
0
        public void PrintCIsConstraintValidAuxBody(StreamWriterLevel c)
        {
            c.WriteLine("flag WithComponentAux{0}({1})", AuxFunctionID, m_args);
            c.WriteLine("{");
            c.P(1); c.WriteLine("size_t i;");
            c.P(1); c.WriteLine("size_t n = {0}nCount;", variableName);
            c.P(1);
            c.WriteLine("for(i=0;i<n;i++)");
            c.P(1); c.WriteLine("{");

            c.P(2);

            string varName = variableName + "arr[i]";

            c.Write("if (!");

            c.Write(((ISCConstraint)m_innerTypeConstraint).PrintCIsConstraintValid(varName, 0));

            c.WriteLine(")");
            c.P(3);
            c.WriteLine("return FALSE;");
            c.P(1); c.WriteLine("}");

            c.P(1); c.WriteLine("return TRUE;");
            c.WriteLine("}");
        }
Beispiel #23
0
        public static void PrintCDecodeItem(IA5StringType pThis, PEREffectiveConstraint cns, StreamWriterLevel c, string varName, int lev)
        {
            PERAlphabetAndSizeEffectiveConstraint cn = (PERAlphabetAndSizeEffectiveConstraint)cns;
            CharSet perAlphaCon = cn.m_from;
            int min = 0;
            int max;
            List<char> tmp = null;
            if (perAlphaCon != null)
                tmp = perAlphaCon.m_set;
            else
                tmp = new List<char>(pThis.AllowedCharSet);
            max = tmp.Count - 1;
            if (min == max)
                return;
            c.P(lev);
            c.Write("static byte allowedCharSet[] = {");
            for (int i = 0; i < tmp.Count; i++)
            {
                c.Write("0x{0:X2}", Convert.ToByte(tmp[i]));
                if (i == tmp.Count - 1)
                    c.WriteLine("};");
                else
                    c.Write(",");
                if ((i + 1) % 15 == 0)
                {
                    c.WriteLine();
                    c.P(lev + 7);
                }
            }
            c.P(lev);
            c.WriteLine("asn1SccSint charIndex = 0;");
            c.P(lev);
            c.WriteLine("if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &charIndex, {0}, {1})) {{", 0, tmp.Count - 1);
            c.P(lev + 1);
            c.WriteLine("*pErrCode = ERR_INSUFFICIENT_DATA;");
            c.P(lev + 1);
            c.WriteLine("return FALSE;");
            c.P(lev);
            c.WriteLine("}");

            c.P(lev);
            c.WriteLine("{0} = allowedCharSet[charIndex];", varName);
        }
Beispiel #24
0
 public override void PrintAsn1(StreamWriterLevel o, int lev)
 {
     if (m_tag != null)
         m_tag.PrintAsn1(o, lev);
     o.Write("SEQUENCE");
     PrintAsn1Constraints(o);
     o.Write(" OF ");
     m_type.PrintAsn1(o, lev);
 }
Beispiel #25
0
 public void PrintHTypeDeclaration(PEREffectiveConstraint cns, StreamWriterLevel h, string typeName, string varName, int lev)
 {
     lev++;
     long max = (long)Math.Ceiling((double)maxItems(cns) / 8.0);
     h.WriteLine("struct {");
     h.P(lev + 1);
     h.WriteLine("long nCount; /*Number of bits in the array. Max value is : {0} */", maxItems(cns));
     h.P(lev + 1); h.WriteLine("byte arr[{0}];", max);
     h.P(lev);
     h.Write("}");
 }
Beispiel #26
0
        internal void PrintH(StreamWriterLevel h, string uniqueID)
        {
            ////print type declaration
            //h.WriteLine("/*");
            //h.WriteLine("Definition of :{0}", m_name);
            //foreach(string line in m_comments)
            //    h.WriteLine("{0}", line);
            //h.WriteLine("*/");

            h.WriteComment(m_comments, 0);

            h.Write("typedef ");
            ((ISCCType)m_type).PrintHTypeDeclaration(m_type.PEREffectiveConstraint, h, uniqueID, "", 0);
            if (!(m_type is IA5StringType))
                h.WriteLine(" {0};", uniqueID);
            h.WriteLine();

            //print
            h.WriteLine("#define {0}_REQUIRED_BYTES_FOR_ENCODING		{1}", uniqueID, m_type.MaxBytesInPER);
            h.WriteLine();
            ((ISCCType)m_type).PrintHConstraintConstant(h, uniqueID);
            h.WriteLine();
            string star = "";
            if (!(m_type is IA5StringType))
                star = "*";
            h.WriteLine("void {0}_Initialize({0}{1} pVal);", uniqueID, star);
            h.WriteLine("flag {0}_IsConstraintValid(const {0}{1} val, int* pErrCode);", uniqueID, star);
            h.WriteLine("flag {0}_Encode(const {0}{1} val, BitStream* pBitStrm, int* pErrCode, flag bCheckConstraints);", uniqueID, star);
            h.WriteLine("flag {0}_Decode({0}{1} pVal, BitStream* pBitStrm, int* pErrCode);", uniqueID, star);
            h.WriteLine();
            h.WriteLine();
        }
Beispiel #27
0
        public void PrintCEncode(PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string varName, int lev)
        {
            string var = varName;
            if (!varName.Contains("->"))
                var = "*" + var;

            PERIntegerEffectiveConstraint cn = cns as PERIntegerEffectiveConstraint;
            if (cn == null) //unconstraint integer
            {
                c.P(lev);
                c.WriteLine("BitStream_EncodeUnConstraintWholeNumber(pBitStrm, {0});", var);
            }
            else
            {
                if (cn.Extensible)
                {
                    if ((cn.m_extRange == null))
                    {
                        c.P(lev);
                        c.WriteLine("BitStream_AppendBitZero(pBitStrm); /* write extension bit*/");
                        EncodeNormal(cn, c, var, lev);
                    }
                    else
                    {
                        c.P(lev);
                        c.Write("if ");
                        for (int i = 0; i < m_constraints.Count; i++)
                        {
                            string ret = ((ISCConstraint)m_constraints[i]).PrintCIsRootConstraintValid(var, lev);
                            c.Write(ret);
                            if (i != m_constraints.Count - 1)
                                c.Write(" && ");
                        }
                        c.WriteLine(" {");
                        c.P(lev + 1);
                        c.WriteLine("BitStream_AppendBitZero(pBitStrm); /* value within root range, so ext bit is zero*/");
                        EncodeNormal(cn, c, var, lev + 1);
                        c.P(lev);
                        c.WriteLine("} else {");
                        lev++;
                        c.P(lev);
                        c.WriteLine("/* value is not within root range, so ext bit is one and value is encoded as uncostraint*/");
                        c.P(lev);
                        c.WriteLine("BitStream_AppendBitOne(pBitStrm);");
                        c.P(lev);
                        c.WriteLine("BitStream_EncodeUnConstraintWholeNumber(pBitStrm, {0});", var);
                        lev--;
                        c.P(lev);
                        c.WriteLine("}");
                    }

                }
                else
                    EncodeNormal(cn, c, var, lev);

            }
        }
Beispiel #28
0
 public void PrintAsn1(StreamWriterLevel o)
 {
     if (m_minIsInfinite)
         o.Write("MIN");
     else
     {
         if (m_minIsIncluded)
             o.Write(m_min);
         else
             o.Write(m_min + 1);
     }
     o.Write("..");
     if (m_maxIsInfinite)
         o.Write("MAX");
     else
     {
         if (m_maxIsIncluded)
             o.Write(m_max);
         else
             o.Write(m_max - 1);
     }
 }
Beispiel #29
0
        public void printC()
        {
            string path = DefaultBackend.m_outDirectory;
            string fileName = Path.GetFileNameWithoutExtension(m_fileName);
            if (path != "" && !path.EndsWith(Path.DirectorySeparatorChar.ToString()))
                path += Path.DirectorySeparatorChar;

            using (StreamWriterLevel c = new StreamWriterLevel(path + fileName + ".c"))
            using (StreamWriterLevel h = new StreamWriterLevel(path + fileName + ".h"))
            {
                h.WriteLine("#ifndef _INC_{0}_H", C.ID(fileName).ToUpper());
                h.WriteLine("#define _INC_{0}_H", C.ID(fileName).ToUpper());
                h.WriteLine("/*");
                h.WriteLine("Code automatically generated by asn1cc tool");
                h.WriteLine("*/");
                h.WriteLine();

                foreach (Module m in m_modules)
                {
                    foreach (ImportedModule imp in m.m_imports)
                    {
                        Asn1File incf = null;
                        foreach (Asn1File f in DefaultBackend.Instance.m_files)
                            foreach (Module exp in f.m_modules)
                                if (exp.m_moduleID == imp.m_moduleID)
                                    incf = f;
                        h.WriteLine("#include \"{0}.h\"", Path.GetFileNameWithoutExtension(incf.m_fileName));
                    }
                }

                h.WriteLine("#include \"asn1crt.h\"");
                h.WriteLine();
                h.WriteLine("#ifdef  __cplusplus");
                h.WriteLine("extern \"C\" {");
                h.WriteLine("#endif");
                h.WriteLine();
                List<TypeAssigment> tmp = GetTypesWithNoDepends();

                foreach (SCCTypeAssigment t in tmp)
                {
                    string uniqueID = DefaultBackend.Instance.TypePrefix + DefaultBackend.Instance.GetUniqueID(C.ID(t.m_name));
                    t.PrintH(h, uniqueID);
                }

                c.WriteLine();
                foreach (Module m in m_modules)
                    foreach (SCCValueAssigment v in m.m_valuesAssigments.Values)
                        v.PrintExternDeclaration(h);

                h.WriteLine("#ifdef  __cplusplus");
                h.WriteLine("}");
                PrintUtilityDefines(h);

                h.WriteLine("#endif");
                h.WriteLine();

                h.WriteLine("#endif");

            // C file

                c.WriteLine("/*");
                c.WriteLine("Code automatically generated by asn1scc tool");
                c.WriteLine("*/");

                c.WriteLine("#include <string.h>");
                //                c.WriteLine("#include <assert.h>");

                c.WriteLine("#include \"{0}\"", fileName + ".h");

                //print unnamed variables

                int indx = 0;
                foreach (SCCTypeAssigment t in tmp)
                    foreach (Asn1Value vtop in t.m_type.GetAllVariables())
                        foreach (Asn1Value v in vtop.GetMySelfAndAnyChildren<Asn1Value>())
                        {
                            if ( (v.Type is OctetStringType) || (v.Type is BitStringType))
                            {
                                indx++;
                                ((ISCCType)v.Type).PrintHTypeDeclaration(v.Type.PEREffectiveConstraint, c, "", "", 0);
                                v.CName = "var" + indx.ToString();
                                c.Write(" {0} = ", v.CName);
                                ((ISCCVariable)v).PrintC(c, 0);
                                c.WriteLine(";");
                            }

                        }

                // print variable assigments
                c.WriteLine();
                foreach (Module m in m_modules)
                    foreach (SCCValueAssigment v in m.m_valuesAssigments.Values)
                    {
                        v.m_value.CName = C.ID(v.m_name);
                        v.PrintC(c);
                    }

                //print various methods
                c.WriteLine();
                foreach (SCCTypeAssigment t in tmp)
                {
                    string uniqueID = DefaultBackend.Instance.TypePrefix + DefaultBackend.Instance.GetUniqueID(C.ID(t.m_name));
                    t.PrintC(c, uniqueID);
                }

            }
        }
Beispiel #30
0
        internal void PrintC(StreamWriterLevel c)
        {
            ((ISCCType)m_type).PrintHTypeDeclaration(m_type.PEREffectiveConstraint, c, "", "", 0);

            c.Write(" {0} = ", C.ID(m_name));
            //            c.Write("{0} {1} = ", C.ID(m_type.Name), C.ID(m_name));
            ((ISCCVariable)m_value).PrintC(c, 0);
            c.WriteLine(";");
        }