public void Save(CGenerator cGenerator) { CFile cFile = new CFile(); cFile.AddElement(new Comment("Generated by LwipMibCompiler")); cFile.AddElement(EmptyLine.SingleLine); string headerDefine = cGenerator.FileName; headerDefine = new Regex("[^a-zA-Z0-9]").Replace(headerDefine, "_"); headerDefine = headerDefine.ToUpperInvariant(); CodeContainerBase e = cFile.AddElement(new PP_Ifdef(headerDefine, inverted: true)) as CodeContainerBase; e.AddElement(new PP_Macro(headerDefine, headerDefine)); e.AddElement(EmptyLine.SingleLine); e.AddElement(new PP_Include(LwipDefs.Incl_SnmpOpts)); e = e.AddElement(new PP_If(LwipDefs.Opt_SnmpEnabled)) as CodeContainerBase; e.AddElement(EmptyLine.SingleLine); CodeContainerBase cplusplusopen = e.AddElement(new PP_Ifdef("__cplusplus")) as CodeContainerBase; cplusplusopen.AddElement(new Code("extern \"C\" {")); e.AddElement(EmptyLine.SingleLine); if (this.includes.Count > 0) { e.AddElements(this.includes); e.AddElement(EmptyLine.SingleLine); } if (this.defines.Count > 0) { e.AddElements(this.defines); e.AddElement(EmptyLine.SingleLine); } e.AddElements(this.functionDeclarations, EmptyLine.SingleLine); e.AddElements(this.variableDeclarations, EmptyLine.SingleLine); e.AddElement(EmptyLine.SingleLine); CodeContainerBase cplusplusclose = e.AddElement(new PP_Ifdef("__cplusplus")) as CodeContainerBase; cplusplusclose.AddElement(new Code("}")); e.AddElement(EmptyLine.SingleLine); cFile.Save(cGenerator); }
public void Save(CGenerator cGenerator) { CFile cFile = new CFile(); cFile.AddElement(new Comment("Generated by LwipMibCompiler")); cFile.AddElement(EmptyLine.SingleLine); cFile.AddElement(new PP_Include(LwipDefs.Incl_SnmpOpts)); CodeContainerBase e = cFile.AddElement(new PP_If(LwipDefs.Opt_SnmpEnabled)) as CodeContainerBase; e.AddElement(EmptyLine.SingleLine); // include header file string file = cGenerator.FileName; if (!String.IsNullOrWhiteSpace(file)) { string ext = System.IO.Path.GetExtension(file); string headerFile = !String.IsNullOrEmpty(ext) ? file.Substring(0, file.Length - ext.Length) : file; headerFile += ".h"; e.AddElement(new PP_Include(headerFile)); } // include common snmp files e.AddElement(new PP_Include("lwip/apps/snmp.h")); e.AddElement(new PP_Include("lwip/apps/snmp_core.h")); e.AddElement(new PP_Include("lwip/apps/snmp_scalar.h")); e.AddElement(new PP_Include("lwip/apps/snmp_table.h")); if (this.includes.Count > 0) { e.AddElement(EmptyLine.SingleLine); e.AddElements(this.includes); } if (this.defines.Count > 0) { e.AddElement(EmptyLine.SingleLine); e.AddElements(this.defines); } if (this.declarations.Count > 0) { e.AddElement(EmptyLine.TwoLines); e.AddElements(this.declarations); } if (this.implementation.Count > 0) { e.AddElement(EmptyLine.TwoLines); e.AddElements(this.implementation); } if (this.preservedCode.Count > 0) { e.AddElement(EmptyLine.TwoLines); e.AddElement(new Comment(PreservedSectionHeader)); e.AddElement(EmptyLine.SingleLine); e.AddElements(this.preservedCode); } cFile.Save(cGenerator); }