示例#1
0
        public void ParseDeclaration(DfaState dfa)
        {
            _varibalesTree = new VariableTreeItem("root");

            dfa.ForEachNR((state) =>
            {
                _varibalesTree.AddVariables(state);
            });
        }
示例#2
0
		public void ParseDeclaration(DfaState dfa)
		{
			_varibalesTree = new VariableTreeItem("root");

			dfa.ForEachNR((state) =>
			{
				_varibalesTree.AddVariables(state);
			});
		}
示例#3
0
        private void GenerateGlobalStruct(VariableTreeItem item)
        {
            _main.WriteLine("public partial struct {0}", RemoveBrackets(GetGlobalType(item.Name)));
            _main.WriteLine("{");

            GenerateVariables(item);

            _main.WriteLine("}");
        }
示例#4
0
        //private void GenerateInitializers(VariableTreeItem item, bool isRootClass)
        //{
        //    if (_optimized == OptimizationMode.IndexedArray)
        //    {
        //        GenerateInitializersIndexArrayOptimized_Part1(item, isRootClass);
        //        GenerateInitializersIndexArrayOptimized_Part2(item, isRootClass);
        //    }
        //    else
        //        GenerateInitializersClassic(item, isRootClass);
        //}

        //private void GenerateInitializersClassic(VariableTreeItem item, bool sipMessageReaderClass_Root)
        //{
        //    _main.WriteLine("partial void OnSetDefaultValue();");

        //    _main.WriteLine("public void SetDefaultValue()");
        //    _main.WriteLine("{");

        //    if (sipMessageReaderClass_Root)
        //    {
        //        if (_optimized == OptimizationMode.SingleStatic)
        //        {
        //            _main.WriteLine("Bytes=null;");
        //        }
        //        else if (_optimized == OptimizationMode.IndexedArray)
        //        {
        //            _main.WriteLine("if(bytes[index]!=null)");
        //            _main.WriteLine("lock (sync)");
        //            _main.WriteLine("bytes[index]=null;");
        //        }
        //    }

        //    foreach (var subitem in item.Subitems)
        //    {
        //        if (HasBrackets(subitem.Name))
        //        {
        //            var name = RemoveExtraInfo(RemoveBrackets(subitem.Name));
        //            var counter = GetCounter(subitem.Name);

        //            var structName = IsGlobal(subitem.Name) ?
        //                GetGlobalType(subitem.Name) : RemoveBrackets(subitem.Name) + "Struct";

        //            _main.WriteLine("if({0} == null)", name);
        //            _main.WriteLine("{");
        //            _main.WriteLine("{0} = new {2}[Max.{1}];", name, counter, structName);
        //            _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
        //            _main.WriteLine("{0}[i] = new {1}();", name, structName);
        //            _main.WriteLine("}");

        //            _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
        //            _main.WriteLine("{0}[i].SetDefaultValue();", name);
        //        }
        //        else
        //        {
        //            _main.WriteLine("{0}.SetDefaultValue();", RemoveExtraInfo(subitem.Name));
        //        }
        //    }

        //    if (item == _varibalesTree)
        //    {
        //        _main.WriteLine("Final = false;");
        //        _main.WriteLine("Error = false;");
        //        _main.WriteLine("state = State0;");
        //        _main.WriteLine("boolExPosition = int.MinValue;");
        //    }

        //    foreach (var pair in item.Enums)
        //    {
        //        var name = RemoveBrackets(pair.Key);
        //        GenerateInitializer(pair.Key, name + "s", "", name + "s.None");
        //    }

        //    //foreach(var begin in item.Begins1)
        //    //    _main.WriteLine("{0}.SetDefaultValue();", begin.Value.ShortName);
        //    GenerateInitializers(item.Begins1, _beginEndStructName, "", ".SetDefaultValue()");

        //    GenerateInitializers(item.Counts, "int", "Count.");
        //    GenerateInitializers(item.Decimals1, "int", "", "int.MinValue");
        //    GenerateInitializers(item.Bools, "bool", "", "false");

        //    _main.WriteLine("OnSetDefaultValue();");

        //    _main.WriteLine("}");
        //}

        //private void GenerateInitializersIndexArrayOptimized_Part1(VariableTreeItem item, bool isRootClass)
        //{
        //    _main.WriteLine("internal void Initialize(" + (isRootClass ? "" : "int index") + ")");
        //    _main.WriteLine("{");

        //    foreach (var subitem in item.Subitems)
        //    {
        //        if (HasBrackets(subitem.Name))
        //        {
        //            var name = RemoveExtraInfo(RemoveBrackets(subitem.Name));
        //            var counter = GetCounter(subitem.Name);

        //            var structName = IsGlobal(subitem.Name) ?
        //                GetGlobalType(subitem.Name) : RemoveBrackets(subitem.Name) + "Struct";

        //            _main.WriteLine("{0} = new {2}[Max.{1}];", name, counter, structName);
        //            _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
        //            _main.WriteLine("{0}[i].Initialize(index);", name);
        //        }
        //        else
        //        {
        //            _main.WriteLine("{0}.Initialize(index);", RemoveExtraInfo(subitem.Name));
        //        }
        //    }

        //    if (isRootClass)
        //    {
        //        _main.WriteLine("Final = false;");
        //        _main.WriteLine("Error = false;");
        //        _main.WriteLine("state = State0;");
        //        _main.WriteLine("boolExPosition = int.MinValue;");
        //    }

        //    foreach (var pair in item.Enums)
        //    {
        //        var name = RemoveBrackets(pair.Key);
        //        GenerateInitializer(pair.Key, name + "s", "", name + "s.None");
        //    }

        //    GenerateInitializers(item.Begins1, _beginEndStructName, "", ".SetDefaultValue(index)");

        //    GenerateInitializers(item.Counts, "int", "Count.");
        //    GenerateInitializers(item.Decimals1, "int", "", "int.MinValue");
        //    GenerateInitializers(item.Bools, "bool", "", "false");

        //    _main.WriteLine("}");
        //}

        //private void GenerateInitializersIndexArrayOptimized_Part2(VariableTreeItem item, bool isRootClass)
        //{
        //    _main.WriteLine("partial void OnSetDefaultValue();");

        //    _main.WriteLine("public void SetDefaultValue()");
        //    _main.WriteLine("{");

        //    if (isRootClass)
        //    {
        //        _main.WriteLine("if(isInitialized==false)");
        //        _main.WriteLine("{");
        //        _main.WriteLine("isInitialized=true;");
        //        _main.WriteLine("Initialize();");
        //        _main.WriteLine("}");
        //        _main.WriteLine("else");
        //        _main.WriteLine("{");
        //    }

        //    if (isRootClass)
        //    {
        //        _main.WriteLine("if(bytes[index]!=null)");
        //        _main.WriteLine("lock (sync)");
        //        _main.WriteLine("bytes[index]=null;");
        //    }

        //    foreach (var subitem in item.Subitems)
        //    {
        //        if (HasBrackets(subitem.Name))
        //        {
        //            var name = RemoveExtraInfo(RemoveBrackets(subitem.Name));
        //            var counter = GetCounter(subitem.Name);

        //            var structName = IsGlobal(subitem.Name) ?
        //                GetGlobalType(subitem.Name) : RemoveBrackets(subitem.Name) + "Struct";

        //            _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
        //            _main.WriteLine("{0}[i].SetDefaultValue();", name);
        //        }
        //        else
        //        {
        //            _main.WriteLine("{0}.SetDefaultValue();", RemoveExtraInfo(subitem.Name));
        //        }
        //    }

        //    if (isRootClass)
        //    {
        //        _main.WriteLine("Final = false;");
        //        _main.WriteLine("Error = false;");
        //        _main.WriteLine("state = State0;");
        //        _main.WriteLine("boolExPosition = int.MinValue;");
        //    }

        //    foreach (var pair in item.Enums)
        //    {
        //        var name = RemoveBrackets(pair.Key);
        //        GenerateInitializer(pair.Key, name + "s", "", name + "s.None");
        //    }

        //    GenerateInitializers(item.Begins1, _beginEndStructName, "", ".SetDefaultValue()");

        //    GenerateInitializers(item.Counts, "int", "Count.");
        //    GenerateInitializers(item.Decimals1, "int", "", "int.MinValue");
        //    GenerateInitializers(item.Bools, "bool", "", "false");

        //    if (isRootClass)
        //        _main.WriteLine("}");
        //    _main.WriteLine("OnSetDefaultValue();");
        //    _main.WriteLine("}");
        //}

        #endregion

        private void GenerateEnums(VariableTreeItem item, List <string> enums)
        {
            foreach (var enum1 in item.Enums)
            {
                if (enums.Contains(enum1.Key) == false)
                {
                    GenerateEnum(enum1);
                    enums.Add(enum1.Key);
                }
            }

            foreach (var subitem in item.Subitems)
            {
                GenerateEnums(subitem, enums);
            }
        }
示例#5
0
        private void GenerateVariables(VariableTreeItem item, bool sipMessageReaderClass)
        {
            GenerateConstsMax(item.Counts, "const int");

            GenerateVaribales(item.Counts, "int", "Count");
            GenerateCustomVaribales(item.Customs);
            GenerateVaribales(item.Begins1, _beginEndStructName);
            GenerateVaribales(item.Decimals1, "int");
            GenerateVaribales(item.Bools, "bool");

            foreach (var pair in item.Enums)
            {
                GenerateVaribale(pair.Key, RemoveBrackets(pair.Key) + "s");
            }

            foreach (var subitem in item.Subitems)
            {
                string structName;

                if (IsGlobal(subitem.Name))
                {
                    structName = GetGlobalType(subitem.Name);
                }
                else
                {
                    structName = RemoveBrackets(subitem.Name) + "Struct";

                    _main.WriteLine("public partial struct {0}", structName);
                    _main.WriteLine("{");

                    GenerateVariables(subitem);

                    _main.WriteLine("}");
                }

                GenerateVaribale(RemoveExtraInfo(subitem.Name), structName);
            }

            GenerateInitializers(item, sipMessageReaderClass);

            if (_optimized == OptimizationMode.NoOptimization)
            {
                GenerateSetArrayFunction(item);
            }
        }
示例#6
0
        private void GenerateSetXFunction(VariableTreeItem item, string functionName, string fieldType, string field)
        {
            var argName = field.ToLower();

            _main.WriteLine("public void " + functionName + "(" + fieldType + " " + argName + ")");
            _main.WriteLine("{");

            foreach (var subitem in item.Subitems)
            {
                if (HasBrackets(subitem.Name))
                {
                    var name    = RemoveExtraInfo(RemoveBrackets(subitem.Name));
                    var counter = GetCounter(subitem.Name);

                    _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
                    _main.WriteLine("{0}[i]." + functionName + "(" + argName + ");", name);
                }
                else
                {
                    _main.WriteLine("{0}." + functionName + "(" + argName + ");", RemoveExtraInfo(subitem.Name));
                }
            }

            foreach (var begin in item.Begins1)
            {
                if (HasBrackets(begin.Value.ShortName))
                {
                    var name    = RemoveExtraInfo(RemoveBrackets(begin.Value.ShortName));
                    var counter = GetCounter(begin.Value.ShortName);

                    _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
                    _main.WriteLine("{0}[i]." + field + " = " + argName + ";", name);
                }
                else
                {
                    _main.WriteLine("{0}." + field + " = " + argName + ";", begin.Value.ShortName);
                }
            }

            _main.WriteLine("}");
        }
示例#7
0
        public VariableTreeItem GetItem(string path)
        {
            int splitter = path.IndexOf('.');

            if (splitter < 0)
            {
                return(this);
            }

            var subitemName = path.Substring(0, splitter);

            VariableTreeItem subitem;

            if (_subitems.TryGetValue(subitemName, out subitem) == false)
            {
                subitem = new VariableTreeItem(subitemName);
                _subitems.Add(subitemName, subitem);
            }

            return(subitem.GetItem(path.Substring(splitter + 1)));
        }
示例#8
0
        private void GenerateGlobalStructs(VariableTreeItem item, List <string> structs)
        {
            foreach (var subitem in item.Subitems)
            {
                if (IsGlobal(subitem.Name))
                {
                    var globalType = GetGlobalType(subitem.Name);

                    if (structs.Contains(globalType) == false)
                    {
                        GenerateGlobalStruct(subitem);
                        structs.Add(globalType);
                    }
                }
            }

            foreach (var subitem in item.Subitems)
            {
                GenerateGlobalStructs(subitem, structs);
            }
        }
示例#9
0
        public void ParseDeclaration(Dictionary <string, ActionsDescription> descriptions)
        {
            _varibalesTree = new VariableTreeItem("root");

            foreach (var descr in descriptions)
            {
                if (descr.Value.Actions != null)
                {
                    foreach (var action1 in descr.Value.Actions)
                    {
                        var item = _varibalesTree.GetItem(action1.Args[0]);

                        var mark = new MarkImpl()
                        {
                            Mark = action1.Mark,
                            Name = action1.Args[0],
                        };

                        if (action1.Mark == Marks.Const)
                        {
                            mark.Value = action1.Args[1];
                        }

                        item.AddVariable(mark);

                        if (action1.Mark == Marks.BeginRange)
                        {
                            item.AddVariable(
                                new MarkImpl()
                            {
                                Mark = Marks.EndRange,
                                Name = action1.Args[0],
                            });
                        }
                    }
                }
            }
        }
示例#10
0
		public void ParseDeclaration(Dictionary<string, ActionsDescription> descriptions)
		{
			_varibalesTree = new VariableTreeItem("root");

			foreach (var descr in descriptions)
			{
				if (descr.Value.Actions != null)
				{
					foreach (var action1 in descr.Value.Actions)
					{
						var item = _varibalesTree.GetItem(action1.Args[0]);

						var mark = new MarkImpl()
						{
							Mark = action1.Mark,
							Name = action1.Args[0],
						};

						if (action1.Mark == Marks.Const)
							mark.Value = action1.Args[1];

						item.AddVariable(mark);

						if (action1.Mark == Marks.BeginRange)
						{
							item.AddVariable(
								new MarkImpl()
								{
									Mark = Marks.EndRange,
									Name = action1.Args[0],
								});
						}
					}
				}
			}
		}
示例#11
0
		private void GenerateGlobalStructs(VariableTreeItem item, List<string> structs)
		{
			foreach (var subitem in item.Subitems)
			{
				if (IsGlobal(subitem.Name))
				{
					var globalType = GetGlobalType(subitem.Name);

					if (structs.Contains(globalType) == false)
					{
						GenerateGlobalStruct(subitem);
						structs.Add(globalType);
					}
				}
			}

			foreach (var subitem in item.Subitems)
				GenerateGlobalStructs(subitem, structs);
		}
示例#12
0
		//private void GenerateInitializers(VariableTreeItem item, bool isRootClass)
		//{
		//    if (_optimized == OptimizationMode.IndexedArray)
		//    {
		//        GenerateInitializersIndexArrayOptimized_Part1(item, isRootClass);
		//        GenerateInitializersIndexArrayOptimized_Part2(item, isRootClass);
		//    }
		//    else
		//        GenerateInitializersClassic(item, isRootClass);
		//}

		//private void GenerateInitializersClassic(VariableTreeItem item, bool sipMessageReaderClass_Root)
		//{
		//    _main.WriteLine("partial void OnSetDefaultValue();");

		//    _main.WriteLine("public void SetDefaultValue()");
		//    _main.WriteLine("{");

		//    if (sipMessageReaderClass_Root)
		//    {
		//        if (_optimized == OptimizationMode.SingleStatic)
		//        {
		//            _main.WriteLine("Bytes=null;");
		//        }
		//        else if (_optimized == OptimizationMode.IndexedArray)
		//        {
		//            _main.WriteLine("if(bytes[index]!=null)");
		//            _main.WriteLine("lock (sync)");
		//            _main.WriteLine("bytes[index]=null;");
		//        }
		//    }

		//    foreach (var subitem in item.Subitems)
		//    {
		//        if (HasBrackets(subitem.Name))
		//        {
		//            var name = RemoveExtraInfo(RemoveBrackets(subitem.Name));
		//            var counter = GetCounter(subitem.Name);

		//            var structName = IsGlobal(subitem.Name) ?
		//                GetGlobalType(subitem.Name) : RemoveBrackets(subitem.Name) + "Struct";

		//            _main.WriteLine("if({0} == null)", name);
		//            _main.WriteLine("{");
		//            _main.WriteLine("{0} = new {2}[Max.{1}];", name, counter, structName);
		//            _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
		//            _main.WriteLine("{0}[i] = new {1}();", name, structName);
		//            _main.WriteLine("}");

		//            _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
		//            _main.WriteLine("{0}[i].SetDefaultValue();", name);
		//        }
		//        else
		//        {
		//            _main.WriteLine("{0}.SetDefaultValue();", RemoveExtraInfo(subitem.Name));
		//        }
		//    }

		//    if (item == _varibalesTree)
		//    {
		//        _main.WriteLine("Final = false;");
		//        _main.WriteLine("Error = false;");
		//        _main.WriteLine("state = State0;");
		//        _main.WriteLine("boolExPosition = int.MinValue;");
		//    }

		//    foreach (var pair in item.Enums)
		//    {
		//        var name = RemoveBrackets(pair.Key);
		//        GenerateInitializer(pair.Key, name + "s", "", name + "s.None");
		//    }

		//    //foreach(var begin in item.Begins1)
		//    //    _main.WriteLine("{0}.SetDefaultValue();", begin.Value.ShortName);
		//    GenerateInitializers(item.Begins1, _beginEndStructName, "", ".SetDefaultValue()");

		//    GenerateInitializers(item.Counts, "int", "Count.");
		//    GenerateInitializers(item.Decimals1, "int", "", "int.MinValue");
		//    GenerateInitializers(item.Bools, "bool", "", "false");

		//    _main.WriteLine("OnSetDefaultValue();");

		//    _main.WriteLine("}");
		//}

		//private void GenerateInitializersIndexArrayOptimized_Part1(VariableTreeItem item, bool isRootClass)
		//{
		//    _main.WriteLine("internal void Initialize(" + (isRootClass ? "" : "int index") + ")");
		//    _main.WriteLine("{");

		//    foreach (var subitem in item.Subitems)
		//    {
		//        if (HasBrackets(subitem.Name))
		//        {
		//            var name = RemoveExtraInfo(RemoveBrackets(subitem.Name));
		//            var counter = GetCounter(subitem.Name);

		//            var structName = IsGlobal(subitem.Name) ?
		//                GetGlobalType(subitem.Name) : RemoveBrackets(subitem.Name) + "Struct";

		//            _main.WriteLine("{0} = new {2}[Max.{1}];", name, counter, structName);
		//            _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
		//            _main.WriteLine("{0}[i].Initialize(index);", name);
		//        }
		//        else
		//        {
		//            _main.WriteLine("{0}.Initialize(index);", RemoveExtraInfo(subitem.Name));
		//        }
		//    }

		//    if (isRootClass)
		//    {
		//        _main.WriteLine("Final = false;");
		//        _main.WriteLine("Error = false;");
		//        _main.WriteLine("state = State0;");
		//        _main.WriteLine("boolExPosition = int.MinValue;");
		//    }

		//    foreach (var pair in item.Enums)
		//    {
		//        var name = RemoveBrackets(pair.Key);
		//        GenerateInitializer(pair.Key, name + "s", "", name + "s.None");
		//    }

		//    GenerateInitializers(item.Begins1, _beginEndStructName, "", ".SetDefaultValue(index)");

		//    GenerateInitializers(item.Counts, "int", "Count.");
		//    GenerateInitializers(item.Decimals1, "int", "", "int.MinValue");
		//    GenerateInitializers(item.Bools, "bool", "", "false");

		//    _main.WriteLine("}");
		//}

		//private void GenerateInitializersIndexArrayOptimized_Part2(VariableTreeItem item, bool isRootClass)
		//{
		//    _main.WriteLine("partial void OnSetDefaultValue();");

		//    _main.WriteLine("public void SetDefaultValue()");
		//    _main.WriteLine("{");

		//    if (isRootClass)
		//    {
		//        _main.WriteLine("if(isInitialized==false)");
		//        _main.WriteLine("{");
		//        _main.WriteLine("isInitialized=true;");
		//        _main.WriteLine("Initialize();");
		//        _main.WriteLine("}");
		//        _main.WriteLine("else");
		//        _main.WriteLine("{");
		//    }

		//    if (isRootClass)
		//    {
		//        _main.WriteLine("if(bytes[index]!=null)");
		//        _main.WriteLine("lock (sync)");
		//        _main.WriteLine("bytes[index]=null;");
		//    }

		//    foreach (var subitem in item.Subitems)
		//    {
		//        if (HasBrackets(subitem.Name))
		//        {
		//            var name = RemoveExtraInfo(RemoveBrackets(subitem.Name));
		//            var counter = GetCounter(subitem.Name);

		//            var structName = IsGlobal(subitem.Name) ?
		//                GetGlobalType(subitem.Name) : RemoveBrackets(subitem.Name) + "Struct";

		//            _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
		//            _main.WriteLine("{0}[i].SetDefaultValue();", name);
		//        }
		//        else
		//        {
		//            _main.WriteLine("{0}.SetDefaultValue();", RemoveExtraInfo(subitem.Name));
		//        }
		//    }

		//    if (isRootClass)
		//    {
		//        _main.WriteLine("Final = false;");
		//        _main.WriteLine("Error = false;");
		//        _main.WriteLine("state = State0;");
		//        _main.WriteLine("boolExPosition = int.MinValue;");
		//    }

		//    foreach (var pair in item.Enums)
		//    {
		//        var name = RemoveBrackets(pair.Key);
		//        GenerateInitializer(pair.Key, name + "s", "", name + "s.None");
		//    }

		//    GenerateInitializers(item.Begins1, _beginEndStructName, "", ".SetDefaultValue()");

		//    GenerateInitializers(item.Counts, "int", "Count.");
		//    GenerateInitializers(item.Decimals1, "int", "", "int.MinValue");
		//    GenerateInitializers(item.Bools, "bool", "", "false");

		//    if (isRootClass)
		//        _main.WriteLine("}");
		//    _main.WriteLine("OnSetDefaultValue();");
		//    _main.WriteLine("}");
		//}

		#endregion

		private void GenerateEnums(VariableTreeItem item, List<string> enums)
		{
			foreach (var enum1 in item.Enums)
			{
				if (enums.Contains(enum1.Key) == false)
				{
					GenerateEnum(enum1);
					enums.Add(enum1.Key);
				}
			}

			foreach (var subitem in item.Subitems)
				GenerateEnums(subitem, enums);
		}
示例#13
0
		private void GenerateInitializers(VariableTreeItem item, bool isRootClass)
		{
			_main.WriteLine("partial void OnSetDefaultValue();");

			if (isRootClass || _optimized != OptimizationMode.IndexedArray)
				_main.WriteLine("public void SetDefaultValue()");
			else
				_main.WriteLine("public void SetDefaultValue(int index)");
			_main.WriteLine("{");

			if (isRootClass)
			{
				if (_optimized == OptimizationMode.SingleStatic)
				{
					_main.WriteLine("Bytes=null;");
				}
				else if (_optimized == OptimizationMode.IndexedArray)
				{
					_main.WriteLine("lock (sync)");
					_main.WriteLine("bytes[index]=null;");
				}
			}

			foreach (var subitem in item.Subitems)
			{
				if (HasBrackets(subitem.Name))
				{
					var name = RemoveExtraInfo(RemoveBrackets(subitem.Name));
					var counter = GetCounter(subitem.Name);

					var structName = IsGlobal(subitem.Name) ?
						GetGlobalType(subitem.Name) : RemoveBrackets(subitem.Name) + "Struct";

					_main.WriteLine("if({0} == null)", name);
					_main.WriteLine("{");
					_main.WriteLine("{0} = new {2}[Max.{1}];", name, counter, structName);
					_main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
					_main.WriteLine("{0}[i] = new {1}();", name, structName);
					_main.WriteLine("}");

					_main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
					_main.WriteLine("{0}[i]." + GetSetDefauleValueCall() + ";", name);
				}
				else
				{
					_main.WriteLine("{0}." + GetSetDefauleValueCall() + ";", RemoveExtraInfo(subitem.Name));
				}
			}

			if (isRootClass)
			{
				_main.WriteLine("Final = false;");
				_main.WriteLine("Error = false;");
				_main.WriteLine("state = State0;");
				_main.WriteLine("boolExPosition = int.MinValue;");
			}

			foreach (var pair in item.Enums)
			{
				var name = RemoveBrackets(pair.Key);
				GenerateInitializer(pair.Key, name + "s", "", name + "s.None");
			}

			GenerateInitializers(item.Begins1, _beginEndStructName, "", "." + GetSetDefauleValueCall());

			GenerateInitializers(item.Counts, "int", "Count.");
			GenerateInitializers(item.Decimals1, "int", "", "int.MinValue");
			GenerateInitializers(item.Bools, "bool", "", "false");

			_main.WriteLine("OnSetDefaultValue();");

			_main.WriteLine("}");
		}
示例#14
0
 private void GenerateSetArrayFunction(VariableTreeItem item)
 {
     GenerateSetXFunction(item, "SetArray", "byte[]", "Bytes");
 }
示例#15
0
		private void GenerateSetXFunction(VariableTreeItem item, string functionName, string fieldType, string field)
		{
			var argName = field.ToLower();

			_main.WriteLine("public void " + functionName + "(" + fieldType + " " + argName + ")");
			_main.WriteLine("{");

			foreach (var subitem in item.Subitems)
			{
				if (HasBrackets(subitem.Name))
				{
					var name = RemoveExtraInfo(RemoveBrackets(subitem.Name));
					var counter = GetCounter(subitem.Name);

					_main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
					_main.WriteLine("{0}[i]." + functionName + "(" + argName + ");", name);
				}
				else
				{
					_main.WriteLine("{0}." + functionName + "(" + argName + ");", RemoveExtraInfo(subitem.Name));
				}
			}

			foreach (var begin in item.Begins1)
			{
				if (HasBrackets(begin.Value.ShortName))
				{
					var name = RemoveExtraInfo(RemoveBrackets(begin.Value.ShortName));
					var counter = GetCounter(begin.Value.ShortName);

					_main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
					_main.WriteLine("{0}[i]." + field + " = " + argName + ";", name);
				}
				else
				{
					_main.WriteLine("{0}." + field + " = " + argName + ";", begin.Value.ShortName);
				}
			}

			_main.WriteLine("}");
		}
示例#16
0
		private void GenerateSetArrayFunction(VariableTreeItem item)
		{
			GenerateSetXFunction(item, "SetArray", "byte[]", "Bytes");
		}
示例#17
0
		private void GenerateVariables(VariableTreeItem item, bool sipMessageReaderClass)
		{
			GenerateConstsMax(item.Counts, "const int");

			GenerateVaribales(item.Counts, "int", "Count");
			GenerateCustomVaribales(item.Customs);
			GenerateVaribales(item.Begins1, _beginEndStructName);
			GenerateVaribales(item.Decimals1, "int");
			GenerateVaribales(item.Bools, "bool");

			foreach (var pair in item.Enums)
				GenerateVaribale(pair.Key, RemoveBrackets(pair.Key) + "s");

			foreach (var subitem in item.Subitems)
			{
				string structName;

				if (IsGlobal(subitem.Name))
				{
					structName = GetGlobalType(subitem.Name);
				}
				else
				{
					structName = RemoveBrackets(subitem.Name) + "Struct";

					_main.WriteLine("public partial struct {0}", structName);
					_main.WriteLine("{");

					GenerateVariables(subitem);

					_main.WriteLine("}");
				}

				GenerateVaribale(RemoveExtraInfo(subitem.Name), structName);
			}

			GenerateInitializers(item, sipMessageReaderClass);

			if (_optimized == OptimizationMode.NoOptimization)
				GenerateSetArrayFunction(item);
		}
示例#18
0
 private void GenerateVariables(VariableTreeItem item)
 {
     GenerateVariables(item, false);
 }
示例#19
0
		private void GenerateGlobalStruct(VariableTreeItem item)
		{
			_main.WriteLine("public partial struct {0}", RemoveBrackets(GetGlobalType(item.Name)));
			_main.WriteLine("{");

			GenerateVariables(item);

			_main.WriteLine("}");
		}
示例#20
0
        private void GenerateInitializers(VariableTreeItem item, bool isRootClass)
        {
            _main.WriteLine("partial void OnSetDefaultValue();");

            if (isRootClass || _optimized != OptimizationMode.IndexedArray)
            {
                _main.WriteLine("public void SetDefaultValue()");
            }
            else
            {
                _main.WriteLine("public void SetDefaultValue(int index)");
            }
            _main.WriteLine("{");

            if (isRootClass)
            {
                if (_optimized == OptimizationMode.SingleStatic)
                {
                    _main.WriteLine("Bytes=null;");
                }
                else if (_optimized == OptimizationMode.IndexedArray)
                {
                    _main.WriteLine("lock (sync)");
                    _main.WriteLine("bytes[index]=null;");
                }
            }

            foreach (var subitem in item.Subitems)
            {
                if (HasBrackets(subitem.Name))
                {
                    var name    = RemoveExtraInfo(RemoveBrackets(subitem.Name));
                    var counter = GetCounter(subitem.Name);

                    var structName = IsGlobal(subitem.Name) ?
                                     GetGlobalType(subitem.Name) : RemoveBrackets(subitem.Name) + "Struct";

                    _main.WriteLine("if({0} == null)", name);
                    _main.WriteLine("{");
                    _main.WriteLine("{0} = new {2}[Max.{1}];", name, counter, structName);
                    _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
                    _main.WriteLine("{0}[i] = new {1}();", name, structName);
                    _main.WriteLine("}");

                    _main.WriteLine("for(int i=0; i<Max.{0}; i++)", counter);
                    _main.WriteLine("{0}[i]." + GetSetDefauleValueCall() + ";", name);
                }
                else
                {
                    _main.WriteLine("{0}." + GetSetDefauleValueCall() + ";", RemoveExtraInfo(subitem.Name));
                }
            }

            if (isRootClass)
            {
                _main.WriteLine("Final = false;");
                _main.WriteLine("Error = false;");
                _main.WriteLine("state = State0;");
                _main.WriteLine("boolExPosition = int.MinValue;");
            }

            foreach (var pair in item.Enums)
            {
                var name = RemoveBrackets(pair.Key);
                GenerateInitializer(pair.Key, name + "s", "", name + "s.None");
            }

            GenerateInitializers(item.Begins1, _beginEndStructName, "", "." + GetSetDefauleValueCall());

            GenerateInitializers(item.Counts, "int", "Count.");
            GenerateInitializers(item.Decimals1, "int", "", "int.MinValue");
            GenerateInitializers(item.Bools, "bool", "", "false");

            _main.WriteLine("OnSetDefaultValue();");

            _main.WriteLine("}");
        }
示例#21
0
		public VariableTreeItem GetItem(string path)
		{
			int splitter = path.IndexOf('.');
			if (splitter < 0)
				return this;

			var subitemName = path.Substring(0, splitter);

			VariableTreeItem subitem;
			if (_subitems.TryGetValue(subitemName, out subitem) == false)
			{
				subitem = new VariableTreeItem(subitemName);
				_subitems.Add(subitemName, subitem);
			}

			return subitem.GetItem(path.Substring(splitter + 1));
		}
示例#22
0
		private void GenerateVariables(VariableTreeItem item)
		{
			GenerateVariables(item, false);
		}