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("}"); }
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(); }
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("}"); } }
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")); } } } }
public void PrintCDecode(PEREffectiveConstraint cns, StreamWriterLevel c, string varName, int lev) { long min = minItems(cns); long max = maxItems(cns); string i = "i" + (CLocalVariable.GetArrayIndex(varName) + 1); string length = "length" + (CLocalVariable.GetArrayIndex(varName) + 1); string curBlockSize = "curBlockSize" + (CLocalVariable.GetArrayIndex(varName) + 1); string nCount = "nCount" + (CLocalVariable.GetArrayIndex(varName) + 1); string prefix = ""; bool topLevel = !varName.Contains("->"); if (topLevel) prefix = varName + "->"; else prefix = varName + "."; if (max < 0x10000) { if (min != max) { c.P(lev); c.WriteLine("if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &nCount, {0}, {1})) {{", min, max); 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}nCount = (long)nCount;", prefix); } else { c.P(lev); c.WriteLine("{0}nCount = {1};", prefix, max); } c.P(lev); c.WriteLine("if (!BitStream_ReadBits(pBitStrm, {0}arr, {0}nCount)) {{", prefix); c.P(lev + 1); c.WriteLine("*pErrCode = ERR_INSUFFICIENT_DATA;"); c.P(lev + 1); c.WriteLine("return FALSE;"); c.P(lev); c.WriteLine("}"); } else { PrintCDecodeFragmentation(cns, c, varName, lev, "arr", max, prefix, length, curBlockSize, nCount); } }
//Default implementation of PrintHtml for all types public static void PrintHtml(Asn1Type pThis, PEREffectiveConstraint cns, StreamWriterLevel o, int lev, List<string> comment, TypeAssigment tas, List<IConstraint> additonalConstraints) { 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=\"2\" >"); 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\" align=\"center\">"); o.WriteLine(" <font face=\"Verdana\" color=\"#FFFFFF\" size=\"2\">min = {0} bytes</font>", (pThis.MinBytesInPER == -1 ? "∞" : pThis.MinBytesInPER.ToString())); o.WriteLine("</td>"); o.WriteLine("<td height=\"35\" align=\"center\">"); o.WriteLine(" <font face=\"Verdana\" color=\"#FFFFFF\" size=\"2\">max = {0} bytes{1}</font>", (pThis.MaxBytesInPER == -1 ? "∞" : pThis.MaxBytesInPER.ToString()), pThis.MaxBitsInPER_Explained); o.WriteLine("</td>"); o.WriteLine("</tr>"); IInternalContentsInHtml pICIH = pThis as IInternalContentsInHtml; string tmp = string.Empty; if (pICIH != null) tmp = pICIH.InternalContentsInHtml(additonalConstraints); if (comment.Count > 0 || tmp.Length > 0) { o.WriteLine("<tr class=\"CommentRow\">"); o.WriteLine("<td class=\"comment2\" colspan=\"4\">" + o.BR(comment) + tmp + "</td>"); o.WriteLine("</tr>"); } o.WriteLine("<tr class=\"headerRow\">"); o.WriteLine("<td class=\"hrconstraint2\" colspan=\"2\">Constraints</td>"); o.WriteLine("<td class=\"hrMin2\">Min Length (bits)</td>"); o.WriteLine("<td class=\"hrMax2\">Max Length (bits)</td>"); o.WriteLine("</tr>"); o.WriteLine("<tr class=\"OddRow\">"); o.WriteLine(" <td class=\"constraint\" colspan=\"2\">{0}</td>", o.Constraint(pThis.Constraints + BaseConstraint.AsString(additonalConstraints))); o.WriteLine(" <td class=\"min\" >{0}</td>", pThis.MinBitsInPER); o.WriteLine(" <td class=\"max\" >{0}{1}</td>", pThis.MaxBitsInPER, pThis.MaxBitsInPER_Explained); o.WriteLine("</tr>"); o.WriteLine("</tbody>"); o.WriteLine("</table>"); }
public void printCode(StreamWriterLevel csFile) { csFile.WriteLine(); foreach (ImportedModule im in m_imports) csFile.WriteLine("using {0};",C.ID(im.m_moduleID)); csFile.WriteLine("namespace {0}", NameSpace); csFile.WriteLine("{"); csFile.WriteLine(); foreach (TypeAssigment tas in m_typeAssigments.Values) { ICSharpType csType = tas.m_type as ICSharpType; csType.DeclareType(csFile, C.ID(tas.m_name), 1); csFile.WriteLine(); } csFile.WriteLine("}"); }
public void printCode() { string path = DefaultBackend.m_outDirectory; string fileName = Path.GetFileNameWithoutExtension(m_fileName); if (path != "" && !path.EndsWith(Path.DirectorySeparatorChar.ToString())) path += Path.DirectorySeparatorChar; using (StreamWriterLevel csFile = new StreamWriterLevel(path + fileName + ".cs")) { csFile.WriteLine("using System;"); csFile.WriteLine("using System.Collections.Generic;"); csFile.WriteLine("using System.Text;"); csFile.WriteLine("using System.IO;"); csFile.WriteLine("using CSharpAsn1CRT;"); foreach (CSharpModule m in m_modules) m.printCode(csFile); } }
public void PrintCDecode(PEREffectiveConstraint cns, StreamWriterLevel c, string varName, int lev) { string varName2 = varName; if (!varName.Contains("->")) varName2 += "->"; else varName2 += "."; int largestIndex = -1; foreach (string v in m_children.Keys) { if (m_children[v].m_extended) continue; largestIndex++; } c.P(lev); c.WriteLine("if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, &nChoiceIndex, {0}, {1})) {{", 0, largestIndex); 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("switch(nChoiceIndex)"); c.P(lev); c.WriteLine("{"); int choiceIndex = 0; foreach (ChoiceChild ch in m_children.Values) { c.P(lev); c.WriteLine("case {0}:", choiceIndex); ((ISCCType)ch.m_type).PrintCDecode(ch.m_type.PEREffectiveConstraint, c, varName2 + "u." + C.ID(ch.m_childVarName), lev + 1); c.P(lev + 1); c.WriteLine("{0}kind = {1};", varName2, ch.CID); c.P(lev + 1); c.WriteLine("break;"); choiceIndex++; } c.P(lev); c.WriteLine("}"); }
public static void PrintCInitialize(ArrayType pThis, PEREffectiveConstraint cns, Asn1Value defauleVal, StreamWriterLevel c, string typeName, string varName, int lev, int arrayDepth) { long min = pThis.minItems(cns); long max = pThis.maxItems(cns); string i = "i" + arrayDepth.ToString(); string prefix = ""; bool topLevel = !varName.Contains("->"); if (topLevel) prefix = varName + "->"; else { prefix = varName + "."; } ArrayValue arVal = defauleVal as ArrayValue; if (arVal == null) { c.P(lev); c.WriteLine("{0}nCount = 0;", prefix); c.P(lev); c.WriteLine("for({0}=0;{0}<{1};{0}++)", i, pThis.maxItems(cns)); c.P(lev); c.WriteLine("{"); ((ISCCType)pThis.m_type).PrintCInitialize(pThis.m_type.PEREffectiveConstraint, pThis.m_type.GetOneValidValue(), c, typeName + "_arr", prefix + "arr[" + i + "]", lev + 1, arrayDepth + 1); c.P(lev); c.WriteLine("}"); } else { c.P(lev); c.WriteLine("{0}nCount = {1};", prefix, arVal.m_children.Count); for (int k = 0; k < arVal.m_children.Count; k++) { c.P(lev); c.WriteLine("{"); ((ISCCType)pThis.m_type).PrintCInitialize(pThis.m_type.PEREffectiveConstraint, arVal.m_children[k], c, typeName + "_arr", prefix + "arr[" + k.ToString() + "]", lev + 1, arrayDepth + 1); c.P(lev); c.WriteLine("}"); } } }
public void PrintHtml(StreamWriterLevel wr, int p) { wr.WriteLine("<div style=\"width: 100%\">"); wr.WriteLine(string.Format("<h2 >Module : {0}</h2>", m_moduleID)); wr.WriteLine("<font face=\"Courier\" color=\"DimGray\"><pre>"); wr.WriteLine(wr.BR(m_comments)); wr.WriteLine("</pre></font>"); List<TypeAssigment> topLevelPDUs = GetTopLevelTypes(); if (!DefaultBackend.displayTypesAsAppearInAsn1Grammar) { foreach (ICDTypeAssigment tas in topLevelPDUs) tas.PrintHtml(wr, p + 1); } foreach (ICDTypeAssigment tas in m_typeAssigments.Values) if (!topLevelPDUs.Contains(tas)) { tas.PrintHtml(wr, p + 1); } wr.WriteLine("</div>"); }
public void PrintHtml(StreamWriterLevel wr, int p) { ((ICDType)m_type).PrintHtml(m_type.PEREffectiveConstraint, wr, p, m_comments, this, null); wr.WriteLine(" <br/>"); }
public void PrintHtml(PEREffectiveConstraint cns, StreamWriterLevel o, int lev, List<string> comment, TypeAssigment tas, List<IConstraint> additonalConstraints) { ICDBType.PrintHtml(this, cns, o, lev, comment, tas, additonalConstraints); }
public void PrintHtml(PEREffectiveConstraint cns, StreamWriterLevel o, int lev, List<string> comment, TypeAssigment tas, List<IConstraint> additonalConstraints) { ((ICDType)Type).PrintHtml(cns, o, lev, comment, tas, m_constraints); }
public void PrintCEncode(PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string varName, int lev) { SCCStringBase.PrintCEncode(this, cns, c, errorCode, varName, lev); }
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); } }
public void PrintHTypeDeclaration(PEREffectiveConstraint cns, StreamWriterLevel h, string typeName, string varName, int lev) { SCCStringBase.PrintHTypeDeclaration(this, cns, h, typeName, varName, lev); }
private void PrintUtilityDefines(StreamWriterLevel h) { foreach (Module m in m_modules) foreach (SCCTypeAssigment t in m.m_typeAssigments.Values) { string uniqueID = DefaultBackend.Instance.TypePrefix + DefaultBackend.Instance.GetUniqueID(C.ID(t.m_name)); foreach (EnumeratedType en in t.m_type.GetMySelfAndAnyChildren<EnumeratedType>()) { foreach (EnumeratedType.Item item in en.m_enumValues.Values) { if (t.m_type != en) h.WriteLine("#define\tENUM_{0}\t{1}::{0}", item.CID, uniqueID); else h.WriteLine("#define\tENUM_{0}\t{0}", item.CID); } } foreach (ChoiceType ch in t.m_type.GetMySelfAndAnyChildren<ChoiceType>()) { foreach (ChoiceChild item in ch.m_children.Values) { h.WriteLine("#define\tCHOICE_{0}\t{1}::{0}", item.CID, uniqueID); } } } }
public void PrintCIsConstraintValid(PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string typeName, string varName, int lev, int arrayDepth) { CSSType.PrintCIsConstraintValid(this, cns, c, errorCode, typeName, varName, lev, arrayDepth); }
public void PrintCEncode(PEREffectiveConstraint cns, StreamWriterLevel c, string errorCode, string varName, int lev) { c.P(lev); c.WriteLine("/* NULL type */"); }
private void EncodeNormal(PERIntegerEffectiveConstraint cn, StreamWriterLevel c, string var, int lev) { if (!cn.m_rootRange.m_minIsInfinite && !cn.m_rootRange.m_maxIsInfinite) { c.P(lev); if (cn.m_rootRange.m_min == cn.m_rootRange.m_max) c.WriteLine("/* No need to encode value since it will always be {0}*/", cn.m_rootRange.m_min); else c.WriteLine("BitStream_EncodeConstraintWholeNumber(pBitStrm, {0}, {1}, {2});", var, C.L(cn.m_rootRange.m_min), C.L(cn.m_rootRange.m_max)); } else if (!cn.m_rootRange.m_minIsInfinite && cn.m_rootRange.m_maxIsInfinite) { c.P(lev); c.WriteLine("BitStream_EncodeSemiConstraintWholeNumber(pBitStrm, {0}, {1});", var, C.L(cn.m_rootRange.m_min)); } else { c.P(lev); c.WriteLine("BitStream_EncodeUnConstraintWholeNumber(pBitStrm, {0});", var); } }
private void DecodeNormal(PERIntegerEffectiveConstraint cn, StreamWriterLevel c, string var, int lev) { if (!cn.m_rootRange.m_minIsInfinite && !cn.m_rootRange.m_maxIsInfinite && (cn.m_rootRange.m_max == cn.m_rootRange.m_min)) { c.P(lev); c.WriteLine("{0} = {1};", var.Replace("&", ""), C.L(cn.m_rootRange.m_min)); } else { if (!cn.m_rootRange.m_minIsInfinite && !cn.m_rootRange.m_maxIsInfinite) { c.P(lev); c.WriteLine("if (!BitStream_DecodeConstraintWholeNumber(pBitStrm, {0}, {1}, {2})) {{", var, C.L(cn.m_rootRange.m_min), C.L(cn.m_rootRange.m_max)); } else if (!cn.m_rootRange.m_minIsInfinite && cn.m_rootRange.m_maxIsInfinite) { c.P(lev); c.WriteLine("if (!BitStream_DecodeSemiConstraintWholeNumber(pBitStrm, {0}, {1})) {{", var, C.L(cn.m_rootRange.m_min)); } else { c.P(lev); c.WriteLine("if (!BitStream_DecodeUnConstraintWholeNumber(pBitStrm, {0})) {{", var); } c.P(lev + 1); c.WriteLine("*pErrCode = ERR_INSUFFICIENT_DATA;"); c.P(lev + 1); c.WriteLine("return FALSE;"); c.P(lev); c.WriteLine("}"); } }
public void PrintCInitialize(PEREffectiveConstraint cns, Asn1Value defaultVal, StreamWriterLevel h, string typeName, string varName, int lev, int arrayDepth) { bool topLevel = !varName.Contains("->"); long defValue = 0; PERIntegerEffectiveConstraint intCns = cns as PERIntegerEffectiveConstraint; if (defaultVal != null) defValue = ((IntegerValue)defaultVal).Value; h.P(lev); if (topLevel) h.WriteLine("*{0} = {1};", varName, C.L(defValue)); else h.WriteLine("{0} = {1};", varName, C.L(defValue)); }
public void PrintHConstraintConstant(StreamWriterLevel h, string name) { CSSType.PrintHConstraintConstant(this, h, name); }
static int Main2(string[] args) { List<string> inputFiles = new List<string>(); SCCBackend compInv = new SCCBackend(); bool debug = false; string astXml = string.Empty; for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("-")) { if (args[i] == "-debug") debug = true; else if (args[i] == "-typePrefix") { try { i++; compInv.TypePrefix = args[i]; } catch (Exception ex) { Console.Error.WriteLine("-typePrefix argument specified, but not prefix was given."); Console.Error.WriteLine(ex.Message); return Usage(); } } else if (args[i] == "-useSpecialComments") DefaultBackend.UseSpecialComments = true; else if (args[i] == "-o") { try { i++; string outFileDir = args[i]; if (!System.IO.Directory.Exists(outFileDir)) { Console.Error.WriteLine("{0} is not a valid directory.", outFileDir); return Usage(); } DefaultBackend.m_outDirectory = outFileDir; } catch (Exception ) { Console.Error.WriteLine("-o argument specified, but no directory was given."); return Usage(); } } else if (args[i] == "-wordSize") { try { i++; Config.IntegerSize = int.Parse(args[i]); } catch (FormatException) { Console.Error.WriteLine("Error in argument -wordSize: {0} is not a number", args[i]); return Usage(); } catch (Exception) { Console.Error.WriteLine("Error in argument -wordSize: No value specified"); return Usage(); } } else if (args[i] == "-ast") { try { i++; astXml = args[i]; FileStream dummy = System.IO.File.Create(astXml); dummy.Close(); System.IO.File.Delete(astXml); } catch (Exception) { Console.Error.WriteLine("Can not create file {0}", astXml); return Usage(); } } else { Console.Error.WriteLine("Unrecognized option: " + args[i]); return Usage(); } } else { inputFiles.Add(args[i]); } } if (inputFiles.Count == 0) { Console.Error.WriteLine("No input files."); return Usage(); } foreach (string inFileName in inputFiles) { if (!System.IO.File.Exists(inFileName)) { Console.Error.WriteLine("File: " + inFileName + " doesn't exist"); return Usage(); } } //Create Syntax Tree try { compInv.CreateASTs(inputFiles); } catch (RecognitionException) { return 1; } catch (SemanticErrorException ex) { Console.Error.WriteLine(ex.Message); return 2; } // Modify Syntax Tree and make Semantic checks try { compInv.SemanticParse(); } catch (SemanticErrorException ex) { Console.Error.WriteLine(ex.Message); return 2; } if (astXml != string.Empty) { using (StreamWriterLevel xmlstream = new StreamWriterLevel(astXml)) { compInv.ToXml(xmlstream, 0); } return 0; } if (debug) { compInv.debug(); } else { try { compInv.printC(); string asn1crth = Properties.Resources.asn1crt; if (Config.IntegerSize != 8) asn1crth = asn1crth.Replace("#define WORD_SIZE 8", "#define WORD_SIZE 4"); File.WriteAllText(DefaultBackend.m_outDirectory + "asn1crt.h", asn1crth); File.WriteAllText(DefaultBackend.m_outDirectory + "asn1crt.c", Properties.Resources.asn1crt1); File.WriteAllText(DefaultBackend.m_outDirectory + "real.c", Properties.Resources.real); } catch (SemanticErrorException ex) { Console.Error.WriteLine(ex.Message); return 2; } } DefaultBackend.CheckRecursiveFuncSetIsEmpty(); return 0; }
public void PrintHTypeDeclaration(PEREffectiveConstraint cns, StreamWriterLevel h, string typeName, string varName, int lev) { h.Write("NullType "); }
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); } } }
public void PrintCDecodeItem(PEREffectiveConstraint cns, StreamWriterLevel c, string varName, int lev) { SCCStringBase.PrintCDecodeItem(this, cns, c, varName, lev); }
public void PrintCInitialize(PEREffectiveConstraint cns, Asn1Value defaultVal, StreamWriterLevel h, string typeName, string varName, int lev, int arrayDepth) { bool topLevel = !varName.Contains("->"); h.P(lev); if (topLevel) h.WriteLine("*{0} = 0;", varName); else h.WriteLine("{0} = 0;", varName); }
public void PrintCDecode(PEREffectiveConstraint cns, StreamWriterLevel c, 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("if (!BitStream_DecodeUnConstraintWholeNumber(pBitStrm, {0})) {{", var); c.P(lev + 1); c.WriteLine("*pErrCode = ERR_INSUFFICIENT_DATA;"); c.P(lev + 1); c.WriteLine("return FALSE;"); c.P(lev); c.WriteLine("}"); } else { if (cn.Extensible) { c.P(lev); c.WriteLine("if (!BitStream_ReadBit(pBitStrm, &extBit)) { /* read extension bit*/ "); 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("if (extBit==0) { /* ext bit is zero ==> value is expecteted with root range*/"); DecodeNormal(cn, c, var, lev + 1); c.P(lev); c.WriteLine("} else {"); c.P(lev + 1); c.WriteLine("if (!BitStream_DecodeUnConstraintWholeNumber(pBitStrm, {0})) {{", var); c.P(lev + 2); c.WriteLine("*pErrCode = ERR_INSUFFICIENT_DATA;"); c.P(lev + 2); c.WriteLine("return FALSE;"); c.P(lev + 1); c.WriteLine("}"); c.P(lev); c.WriteLine("}"); } else DecodeNormal(cn, c, var, lev); } }