コード例 #1
0
 public void GenerateCode(CGenerator generator)
 {
     if (!String.IsNullOrWhiteSpace(this.Type))
     {
         generator.OutputStream.Write(this.ToString().Trim());
     }
 }
コード例 #2
0
ファイル: VariableDeclaration.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(int level, CGenerator generator)
		{
			if (this.Type != null)
			{
				generator.IndentLine(level);

				if (this.IsStatic)
				{
					generator.OutputStream.Write("static ");
				}

				// declare the variable
				this.Type.GenerateCode(generator);

				if (!String.IsNullOrWhiteSpace(this.InitialValue))
				{
					// add initialization value
					generator.OutputStream.Write(" = ");
					generator.WriteMultilineString(this.InitialValue, level);
				}

				generator.OutputStream.Write(";");
				generator.WriteNewLine();
			}
		}
コード例 #3
0
ファイル: Switch.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(int level, CGenerator generator)
		{
			if (!String.IsNullOrWhiteSpace(this.Value))
			{
				generator.IndentLine(level);
				if (this.IsDefault)
				{
					generator.OutputStream.Write("default:");
				}
				else
				{
					generator.OutputStream.Write(String.Format("case {0}:", this.Value));
				}
				generator.WriteNewLine();
				generator.IndentLine(level + 1);
				generator.OutputStream.Write("{");
				generator.WriteNewLine();

				base.GenerateCode(level + 1, generator);

				generator.IndentLine(level + 1);
				generator.OutputStream.Write("}");
				generator.WriteNewLine();

				generator.IndentLine(level + 1);
				generator.OutputStream.Write("break;");
				generator.WriteNewLine();
			}
		}
コード例 #4
0
        public override void GenerateCode(int level, CGenerator generator)
        {
            if (this.Type != null)
            {
                generator.IndentLine(level);

                if (this.IsStatic)
                {
                    generator.OutputStream.Write("static ");
                }

                // declare the variable
                this.Type.GenerateCode(generator);

                if (!String.IsNullOrWhiteSpace(this.InitialValue))
                {
                    // add initialization value
                    generator.OutputStream.Write(" = ");
                    generator.WriteMultilineString(this.InitialValue, level);
                }

                generator.OutputStream.Write(";");
                generator.WriteNewLine();
            }
        }
コード例 #5
0
        public override void GenerateCode(int level, CGenerator generator)
        {
            if (!String.IsNullOrWhiteSpace(this.Value))
            {
                generator.IndentLine(level);
                if (this.IsDefault)
                {
                    generator.OutputStream.Write("default:");
                }
                else
                {
                    generator.OutputStream.Write(String.Format("case {0}:", this.Value));
                }
                generator.WriteNewLine();
                generator.IndentLine(level + 1);
                generator.OutputStream.Write("{");
                generator.WriteNewLine();

                base.GenerateCode(level + 1, generator);

                generator.IndentLine(level + 1);
                generator.OutputStream.Write("}");
                generator.WriteNewLine();

                generator.IndentLine(level + 1);
                generator.OutputStream.Write("break;");
                generator.WriteNewLine();
            }
        }
コード例 #6
0
        public override void GenerateCode(int level, CGenerator generator)
        {
            if (!String.IsNullOrWhiteSpace(this.SwitchVar))
            {
                generator.IndentLine(level);
                generator.OutputStream.Write(String.Format("switch ({0})", this.SwitchVar));
                generator.WriteNewLine();
                generator.IndentLine(level);
                generator.OutputStream.Write("{");
                generator.WriteNewLine();

                SwitchCase defaultCase = null;                 // generate 'default' always as last case
                foreach (SwitchCase switchCase in this.switches)
                {
                    if (switchCase.IsDefault)
                    {
                        defaultCase = switchCase;
                    }
                    else
                    {
                        switchCase.GenerateCode(level + 1, generator);
                    }
                }
                if (defaultCase != null)
                {
                    defaultCase.GenerateCode(level + 1, generator);
                }

                generator.IndentLine(level);
                generator.OutputStream.Write("}");
                generator.WriteNewLine();
            }
        }
コード例 #7
0
ファイル: VariableType.cs プロジェクト: plocklsh/lwip
		public void GenerateCode(CGenerator generator)
		{
			if (!String.IsNullOrWhiteSpace(this.Type))
			{
				generator.OutputStream.Write(this.ToString().Trim());
			}
		}
コード例 #8
0
ファイル: CFile.cs プロジェクト: plocklsh/lwip
		public void Save(CGenerator generator)
		{
			if (generator == null)
			{
				throw new ArgumentNullException("generator");
			}

			this.GenerateCode(0, generator);
		}
コード例 #9
0
        public void Save(CGenerator generator)
        {
            if (generator == null)
            {
                throw new ArgumentNullException("generator");
            }

            this.GenerateCode(0, generator);
        }
コード例 #10
0
ファイル: PP_If.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(int level, CGenerator generator)
		{
			if (!String.IsNullOrWhiteSpace(this.Condition))
			{
				generator.OutputStream.Write("#if " + this.Condition);
				generator.WriteNewLine();

				base.GenerateCode(level, generator);

				generator.OutputStream.Write("#endif /* " + this.Condition + " */");
				generator.WriteNewLine();
			}
		}
コード例 #11
0
ファイル: PP_If.cs プロジェクト: hnkr/lwip_contrib
        public override void GenerateCode(int level, CGenerator generator)
        {
            if (!String.IsNullOrWhiteSpace(this.Condition))
            {
                generator.OutputStream.Write("#if " + this.Condition);
                generator.WriteNewLine();

                base.GenerateCode(level, generator);

                generator.OutputStream.Write("#endif /* " + this.Condition + " */");
                generator.WriteNewLine();
            }
        }
コード例 #12
0
ファイル: PP_Include.cs プロジェクト: hnkr/lwip_contrib
        public override void GenerateCode(int level, CGenerator generator)
        {
            if (!String.IsNullOrWhiteSpace(this.File))
            {
                // includes are never indented
                if (this.IsLocal)
                {
                    generator.OutputStream.Write("#include \"" + this.File + "\"");
                }
                else
                {
                    generator.OutputStream.Write("#include <" + this.File + ">");
                }

                generator.WriteNewLine();
            }
        }
コード例 #13
0
ファイル: PP_Include.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(int level, CGenerator generator)
		{
			if (!String.IsNullOrWhiteSpace(this.File))
			{
				// includes are never indented
				if (this.IsLocal)
				{
					generator.OutputStream.Write("#include \"" + this.File + "\"");
				}
				else
				{
					generator.OutputStream.Write("#include <" + this.File + ">");
				}

				generator.WriteNewLine();			
			}
		}
コード例 #14
0
ファイル: MibHeaderFile.cs プロジェクト: plocklsh/lwip
		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);
		}
コード例 #15
0
        public override void GenerateCode(int level, CGenerator generator)
        {
            if (!String.IsNullOrWhiteSpace(this.Condition))
            {
                generator.IndentLine(level);
                generator.OutputStream.Write(String.Format("else if ({0})", this.Condition));
                generator.WriteNewLine();
                generator.IndentLine(level);
                generator.OutputStream.Write("{");
                generator.WriteNewLine();

                base.GenerateCode(level, generator);

                generator.IndentLine(level);
                generator.OutputStream.Write("}");
                generator.WriteNewLine();
            }
        }
コード例 #16
0
ファイル: IfThenElse.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(int level, CGenerator generator)
		{
			if (!String.IsNullOrWhiteSpace(this.Condition))
			{
				generator.IndentLine(level);
				generator.OutputStream.Write(String.Format("else if ({0})", this.Condition));
				generator.WriteNewLine();
				generator.IndentLine(level);
				generator.OutputStream.Write("{");
				generator.WriteNewLine();

				base.GenerateCode(level, generator);

				generator.IndentLine(level);
				generator.OutputStream.Write("}");
				generator.WriteNewLine();
			}
		}
コード例 #17
0
ファイル: PP_Ifdef.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(int level, CGenerator generator)
		{
			if (!String.IsNullOrWhiteSpace(this.Macro))
			{
				if (this.Inverted)
				{
					generator.OutputStream.Write("#ifndef " + this.Macro);
				}
				else
				{
					generator.OutputStream.Write("#ifdef " + this.Macro);
				}
				generator.WriteNewLine();

				base.GenerateCode(level, generator);

				generator.OutputStream.Write("#endif /* " + this.Macro + " */");
				generator.WriteNewLine();
			}
		}
コード例 #18
0
        public override void GenerateCode(int level, CGenerator generator)
        {
            if (!String.IsNullOrWhiteSpace(this.Macro))
            {
                if (this.Inverted)
                {
                    generator.OutputStream.Write("#ifndef " + this.Macro);
                }
                else
                {
                    generator.OutputStream.Write("#ifdef " + this.Macro);
                }
                generator.WriteNewLine();

                base.GenerateCode(level, generator);

                generator.OutputStream.Write("#endif /* " + this.Macro + " */");
                generator.WriteNewLine();
            }
        }
コード例 #19
0
        public override void GenerateCode(int level, CGenerator generator)
        {
            generator.IndentLine(level);

            if (this.IsStatic)
            {
                generator.OutputStream.Write("static ");
            }

            this.returnType.GenerateCode(generator);
            generator.OutputStream.Write(" " + this.Name + "(");

            if (this.Parameter.Count > 0)
            {
                for (int i = 0; i < this.parameter.Count; i++)
                {
                    this.parameter[i].GenerateCode(generator);

                    if (i < (this.parameter.Count - 1))
                    {
                        generator.OutputStream.Write(", ");
                    }
                }
            }
            else
            {
                generator.OutputStream.Write("void");
            }

            generator.OutputStream.Write(")");
            generator.WriteNewLine();
            generator.IndentLine(level);
            generator.OutputStream.Write("{");
            generator.WriteNewLine();

            base.GenerateCode(level, generator);

            generator.IndentLine(level);
            generator.OutputStream.Write("}");
            generator.WriteNewLine();
        }
コード例 #20
0
        public override void GenerateCode(int level, CGenerator generator)
        {
            if (this.increaseLevel)
            {
                level++;
            }

            if (this.declarations.Count > 0)
            {
                foreach (CodeElement element in this.declarations)
                {
                    element.GenerateCode(level, generator);
                }

                EmptyLine.SingleLine.GenerateCode(level, generator);
            }

            foreach (CodeElement element in this.innerElements)
            {
                element.GenerateCode(level, generator);
            }
        }
コード例 #21
0
        public override void GenerateCode(int level, CGenerator generator)
        {
            if (!String.IsNullOrWhiteSpace(this.Condition))
            {
                generator.IndentLine(level);
                generator.OutputStream.Write(String.Format("if ({0})", this.Condition));
                generator.WriteNewLine();
                generator.IndentLine(level);
                generator.OutputStream.Write("{");
                generator.WriteNewLine();

                base.GenerateCode(level, generator);

                generator.IndentLine(level);
                generator.OutputStream.Write("}");
                generator.WriteNewLine();

                foreach (ElseIf elif in this.elseIf)
                {
                    elif.GenerateCode(level, generator);
                }

                if (this.else_.InnerElements.Count > 0)
                {
                    generator.IndentLine(level);
                    generator.OutputStream.Write("else");
                    generator.WriteNewLine();
                    generator.IndentLine(level);
                    generator.OutputStream.Write("{");
                    generator.WriteNewLine();

                    this.else_.GenerateCode(level, generator);

                    generator.IndentLine(level);
                    generator.OutputStream.Write("}");
                    generator.WriteNewLine();
                }
            }
        }
コード例 #22
0
ファイル: FunctionDeclaration.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(int level, CGenerator generator)
		{
			generator.IndentLine(level);

			if (this.IsExtern)
			{
				generator.OutputStream.Write("extern ");
			}

			if (this.IsStatic)
			{
				generator.OutputStream.Write("static ");
			}

			this.returnType.GenerateCode(generator);
			generator.OutputStream.Write(" " + this.Name + "(");

			if (this.Parameter.Count > 0)
			{
				for (int i = 0; i < this.parameter.Count; i++)
				{
					this.parameter[i].GenerateCode(generator);

					if (i < (this.parameter.Count - 1))
					{
						generator.OutputStream.Write(", ");
					}
				}
			}
			else
			{
				generator.OutputStream.Write("void");
			}

			generator.OutputStream.Write(");");
			generator.WriteNewLine();
		}
コード例 #23
0
ファイル: IfThenElse.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(int level, CGenerator generator)
		{
			if (!String.IsNullOrWhiteSpace(this.Condition))
			{
				generator.IndentLine(level);
				generator.OutputStream.Write(String.Format("if ({0})", this.Condition));
				generator.WriteNewLine();
				generator.IndentLine(level);
				generator.OutputStream.Write("{");
				generator.WriteNewLine();

				base.GenerateCode(level, generator);

				generator.IndentLine(level);
				generator.OutputStream.Write("}");
				generator.WriteNewLine();

				foreach (ElseIf elif in this.elseIf)
				{
					elif.GenerateCode(level, generator);
				}

				if (this.else_.InnerElements.Count > 0)
				{
					generator.IndentLine(level);
					generator.OutputStream.Write("else");
					generator.WriteNewLine();
					generator.IndentLine(level);
					generator.OutputStream.Write("{");
					generator.WriteNewLine();

					this.else_.GenerateCode(level, generator);

					generator.IndentLine(level);
					generator.OutputStream.Write("}");
					generator.WriteNewLine();
				}
			}
		}
コード例 #24
0
ファイル: CodeContainerBase.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(int level, CGenerator generator)
		{
			if (this.increaseLevel)
				level++;

			if (this.declarations.Count > 0)
			{
				foreach (CodeElement element in this.declarations)
				{
					element.GenerateCode(level, generator);
				}

				EmptyLine.SingleLine.GenerateCode(level, generator);
			}

			foreach (CodeElement element in this.innerElements)
			{
				element.GenerateCode(level, generator);
			}
		}
コード例 #25
0
ファイル: Program.cs プロジェクト: plocklsh/lwip
		static void Main(string[] args)
		{
			Console.WriteLine("lwIP MIB Compiler");
			Console.WriteLine("");

			// check args
			if ((args.Length < 2) || String.IsNullOrWhiteSpace(args[0]) || String.IsNullOrWhiteSpace(args[1]))
			{
				PrintUsage();
				return;
			}

			string mibFile = args[0];
			if (!File.Exists(mibFile))
			{
				Console.WriteLine(String.Format("Unable to find file '{0}'!", mibFile));
			}

			string destFile = args[1];
			string destHeaderFile;

			if (Directory.Exists(destFile))
			{
				// only directory passed -> create dest filename from mib filename
				string mibFileName = Path.GetFileNameWithoutExtension(mibFile).ToLowerInvariant();
				destFile = Path.Combine(destFile, mibFileName + ".c");
			}
			
			string destFileExt = Path.GetExtension(destFile);
			if (!String.IsNullOrEmpty(destFileExt))
			{
				destHeaderFile = destFile.Substring(0, destFile.Length - destFileExt.Length);
			}
			else
			{
				destHeaderFile = destFile;
			}
			destHeaderFile += ".h";

			for (int i=2; i<args.Length; i++)
			{
				if (!String.IsNullOrWhiteSpace(args[i]) && Directory.Exists(args[i]))
				{
					MibTypesResolver.RegisterResolver(new FileSystemMibResolver(args[i], true));
				}
			}

			
			// read and resolve MIB
			Console.WriteLine(" Reading MIB file...");
			
			MibDocument md = new MibDocument(mibFile);
			MibTypesResolver.ResolveTypes(md.Modules[0]);
			MibTree mt = new MibTree(md.Modules[0] as MibModule);

			if (mt.Root.Count == 0)
			{
				Console.WriteLine("No root element found inside MIB!");
				return;
			}

			MibCFile generatedFile = new MibCFile();
			MibHeaderFile generatedHeaderFile = new MibHeaderFile();

			foreach (MibTreeNode mibTreeNode in mt.Root)
			{
				// create LWIP object tree from MIB structure
				Console.WriteLine(" Creating lwIP object tree " + mibTreeNode.Entity.Name);

				SnmpMib snmpMib = new SnmpMib();
				snmpMib.Oid = mibTreeNode.Entity.Value;
				snmpMib.BaseOid = MibTypesResolver.ResolveOid(mibTreeNode.Entity).GetOidValues();
				snmpMib.Name = mibTreeNode.Entity.Name;

				ProcessMibTreeNode(mibTreeNode, snmpMib);

				// let the tree transform itself depending on node structure
				snmpMib.Analyze();

				// generate code from LWIP object tree
				Console.WriteLine(" Generating code " + snmpMib.Name);
				snmpMib.Generate(generatedFile, generatedHeaderFile);
			}

			string preservedCode = MibCFile.GetPreservedCode(destFile);
			if (!string.IsNullOrEmpty(preservedCode))
			{
				generatedFile.PreservedCode.Add(new PlainText(preservedCode));
			}
			else
			{
				generatedFile.PreservedCode.AddRange(generatedFile.Implementation);
			}
			generatedFile.Implementation.Clear();


			using (StreamWriter fileWriter = new StreamWriter(destHeaderFile))
			{
				CGenerator cGenerator = new CGenerator(fileWriter, destHeaderFile, 3, " ", Environment.NewLine);
				generatedHeaderFile.Save(cGenerator);
			}
			using (StreamWriter fileWriter = new StreamWriter(destFile))
			{
				CGenerator cGenerator = new CGenerator(fileWriter, destFile, 3, " ", Environment.NewLine);
				generatedFile.Save(cGenerator);
			}

			Console.WriteLine(" Done");
		}
コード例 #26
0
ファイル: Switch.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(int level, CGenerator generator)
		{
			if (!String.IsNullOrWhiteSpace(this.SwitchVar))
			{
				generator.IndentLine(level);
				generator.OutputStream.Write(String.Format("switch ({0})", this.SwitchVar));
				generator.WriteNewLine();
				generator.IndentLine(level);
				generator.OutputStream.Write("{");
				generator.WriteNewLine();

				SwitchCase defaultCase = null; // generate 'default' always as last case
				foreach (SwitchCase switchCase in this.switches)
				{
					if (switchCase.IsDefault)
					{
						defaultCase = switchCase;
					}
					else
					{
						switchCase.GenerateCode(level + 1, generator);
					}
				}
				if (defaultCase != null)
				{
					defaultCase.GenerateCode(level + 1, generator);
				}

				generator.IndentLine(level);
				generator.OutputStream.Write("}");
				generator.WriteNewLine();
			}
		}
コード例 #27
0
ファイル: MibCFile.cs プロジェクト: plocklsh/lwip
		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);
		}