[457] | 1 | /*
|
---|
| 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
| 6 | * are permitted provided that the following conditions are met:
|
---|
| 7 | *
|
---|
| 8 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
| 9 | * this list of conditions and the following disclaimer.
|
---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
| 11 | * this list of conditions and the following disclaimer in the documentation
|
---|
| 12 | * and/or other materials provided with the distribution.
|
---|
| 13 | * 3. The name of the author may not be used to endorse or promote products
|
---|
| 14 | * derived from this software without specific prior written permission.
|
---|
| 15 | *
|
---|
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
---|
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
---|
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
---|
| 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
| 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
---|
| 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
| 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
| 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
---|
| 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
---|
| 25 | * OF SUCH DAMAGE.
|
---|
| 26 | *
|
---|
| 27 | * This file is part of the lwIP TCP/IP stack.
|
---|
| 28 | *
|
---|
| 29 | * Author: Martin Hentschel <info@cl-soft.de>
|
---|
| 30 | *
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | using System.Collections.Generic;
|
---|
| 34 | using System.Text.RegularExpressions;
|
---|
| 35 | using CCodeGeneration;
|
---|
| 36 |
|
---|
| 37 | namespace LwipSnmpCodeGeneration
|
---|
| 38 | {
|
---|
| 39 | public class MibHeaderFile
|
---|
| 40 | {
|
---|
| 41 |
|
---|
| 42 | #region Fields
|
---|
| 43 |
|
---|
| 44 | private readonly List<CodeElement> defines = new List<CodeElement>();
|
---|
| 45 | private readonly List<CodeElement> includes = new List<CodeElement>();
|
---|
| 46 | private readonly List<CodeElement> functionDeclarations = new List<CodeElement>();
|
---|
| 47 | private readonly List<CodeElement> variableDeclarations = new List<CodeElement>();
|
---|
| 48 |
|
---|
| 49 | #endregion
|
---|
| 50 |
|
---|
| 51 | public MibHeaderFile()
|
---|
| 52 | {
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | #region Accessors
|
---|
| 56 |
|
---|
| 57 | public List<CodeElement> Defines
|
---|
| 58 | {
|
---|
| 59 | get { return this.defines; }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public List<CodeElement> Includes
|
---|
| 63 | {
|
---|
| 64 | get { return this.includes; }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | public List<CodeElement> FunctionDeclarations
|
---|
| 68 | {
|
---|
| 69 | get { return this.functionDeclarations; }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | public List<CodeElement> VariableDeclarations
|
---|
| 73 | {
|
---|
| 74 | get { return this.variableDeclarations; }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | #endregion
|
---|
| 78 |
|
---|
| 79 | #region Methods
|
---|
| 80 |
|
---|
| 81 | public void Save(CGenerator cGenerator)
|
---|
| 82 | {
|
---|
| 83 | CFile cFile = new CFile();
|
---|
| 84 |
|
---|
| 85 | cFile.AddElement(new Comment("Generated by LwipMibCompiler"));
|
---|
| 86 | cFile.AddElement(EmptyLine.SingleLine);
|
---|
| 87 |
|
---|
| 88 | string headerDefine = cGenerator.FileName;
|
---|
| 89 | headerDefine = new Regex("[^a-zA-Z0-9]").Replace(headerDefine, "_");
|
---|
| 90 | headerDefine = headerDefine.ToUpperInvariant();
|
---|
| 91 |
|
---|
| 92 | CodeContainerBase e = cFile.AddElement(new PP_Ifdef(headerDefine, inverted: true)) as CodeContainerBase;
|
---|
| 93 | e.AddElement(new PP_Macro(headerDefine, headerDefine));
|
---|
| 94 | e.AddElement(EmptyLine.SingleLine);
|
---|
| 95 |
|
---|
| 96 | e.AddElement(new PP_Include(LwipDefs.Incl_SnmpOpts));
|
---|
| 97 | e = e.AddElement(new PP_If(LwipDefs.Opt_SnmpEnabled)) as CodeContainerBase;
|
---|
| 98 | e.AddElement(EmptyLine.SingleLine);
|
---|
| 99 |
|
---|
| 100 | CodeContainerBase cplusplusopen = e.AddElement(new PP_Ifdef("__cplusplus")) as CodeContainerBase;
|
---|
| 101 | cplusplusopen.AddElement(new Code("extern \"C\" {"));
|
---|
| 102 | e.AddElement(EmptyLine.SingleLine);
|
---|
| 103 |
|
---|
| 104 | if (this.includes.Count > 0)
|
---|
| 105 | {
|
---|
| 106 | e.AddElements(this.includes);
|
---|
| 107 | e.AddElement(EmptyLine.SingleLine);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | if (this.defines.Count > 0)
|
---|
| 111 | {
|
---|
| 112 | e.AddElements(this.defines);
|
---|
| 113 | e.AddElement(EmptyLine.SingleLine);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | e.AddElements(this.functionDeclarations, EmptyLine.SingleLine);
|
---|
| 117 | e.AddElements(this.variableDeclarations, EmptyLine.SingleLine);
|
---|
| 118 |
|
---|
| 119 | e.AddElement(EmptyLine.SingleLine);
|
---|
| 120 | CodeContainerBase cplusplusclose = e.AddElement(new PP_Ifdef("__cplusplus")) as CodeContainerBase;
|
---|
| 121 | cplusplusclose.AddElement(new Code("}"));
|
---|
| 122 |
|
---|
| 123 | e.AddElement(EmptyLine.SingleLine);
|
---|
| 124 | cFile.Save(cGenerator);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | #endregion
|
---|
| 128 | }
|
---|
| 129 | }
|
---|