public void refinalize(MsgFile parent, string REALTYPE) { bool isconst = false; Type = REALTYPE; string name = backup[1]; string otherstuff = ""; if (name.Contains('=')) { string[] parts = name.Split('='); isconst = true; name = parts[0]; otherstuff = " = " + parts[1]; } if (IsCSharpKeyword(name)) { name = "@" + name; } for (int i = 2; i < backup.Length; i++) { otherstuff += " " + backup[i]; } if (otherstuff.Contains('=')) { isconst = true; } parent.resolve(this); if (!IsArray) { if (otherstuff.Contains('=') && Type.Equals("string", StringComparison.CurrentCultureIgnoreCase)) { otherstuff = otherstuff.Replace("\\", "\\\\"); otherstuff = otherstuff.Replace("\"", "\\\""); string[] split = otherstuff.Split('='); otherstuff = split[0] + " = \"" + split[1].Trim() + "\""; } if (otherstuff.Contains('=') && Type == "bool") { otherstuff = otherstuff.Replace("0", "false").Replace("1", "true"); } if (otherstuff.Contains('=') && Type == "byte") { otherstuff = otherstuff.Replace("-1", "255"); } Const = isconst; bool wantsconstructor = false; if (otherstuff.Contains("=")) { string[] chunks = otherstuff.Split('='); ConstValue = chunks[chunks.Length - 1].Trim(); if (Type.Equals("string", StringComparison.OrdinalIgnoreCase)) { otherstuff = chunks[0] + " = \"" + chunks[1].Trim().Replace("\"", "") + "\""; } } else if (!Type.Equals("String")) { wantsconstructor = true; } string prefix = "", suffix = ""; if (isconst) { if (!Type.Equals("string", StringComparison.OrdinalIgnoreCase)) { prefix = "const "; } } if (otherstuff.Contains('=')) { if (wantsconstructor) { if (Type == "string") { suffix = " = \"\""; } else { suffix = " = new " + Type + "()"; } } else { suffix = KnownStuff.GetConstTypesAffix(Type); } } string t = KnownStuff.GetNamespacedType(this, Type); output = lowestindent + "public " + prefix + t + " " + name + otherstuff + suffix + ";"; } else { if (length.Length != 0) { IsLiteral = true; //type != "string"; } if (otherstuff.Contains('=')) { string[] split = otherstuff.Split('='); otherstuff = split[0] + " = (" + Type + ")" + split[1]; } string t = KnownStuff.GetNamespacedType(this, Type); if (length.Length != 0) { output = lowestindent + "public " + t + "[] " + name + otherstuff + " = new " + t + "[" + length + "];"; } else { output = lowestindent + "public " + "" + t + "[] " + name + otherstuff + ";"; } } if (!KnownStuff.KnownTypes.ContainsKey(rostype)) { meta = true; } Name = name.Length == 0 ? otherstuff.Split('=')[0].Trim() : name; }
public void Finalize(MsgFile parent, string[] s, bool isliteral) { backup = new string[s.Length]; Array.Copy(s, backup, s.Length); bool isconst = false; IsLiteral = isliteral; string type = s[0]; string name = s[1]; string otherstuff = ""; if (name.Contains('=')) { string[] parts = name.Split('='); isconst = true; name = parts[0]; otherstuff = " = " + parts[1]; } if (IsCSharpKeyword(name)) { name = "@" + name; } for (int i = 2; i < s.Length; i++) { otherstuff += " " + s[i]; } if (otherstuff.Contains('=')) { isconst = true; } if (!IsArray) { if (otherstuff.Contains('=') && type.Equals("string", StringComparison.CurrentCultureIgnoreCase)) { otherstuff = otherstuff.Replace("\\", "\\\\"); otherstuff = otherstuff.Replace("\"", "\\\""); string[] split = otherstuff.Split('='); otherstuff = split[0] + " = " + split[1].Trim() + ""; } if (otherstuff.Contains('=') && type == "bool") { otherstuff = otherstuff.Replace("0", "false").Replace("1", "true"); } if (otherstuff.Contains('=') && type == "byte") { otherstuff = otherstuff.Replace("-1", "255"); } Const = isconst; bool wantsconstructor = true; if (otherstuff.Contains("=")) { string[] chunks = otherstuff.Split('='); ConstValue = chunks[chunks.Length - 1].Trim(); if (type.Equals("string", StringComparison.OrdinalIgnoreCase)) { otherstuff = chunks[0] + " = \"" + chunks[1].Trim() + "\""; wantsconstructor = false; } } string prefix = "", suffix = ""; if (isconst) { if (!type.Equals("string", StringComparison.OrdinalIgnoreCase)) { prefix = "const "; wantsconstructor = false; } } string t = KnownStuff.GetNamespacedType(this, type); if (otherstuff.Contains('=')) { if (wantsconstructor) { if (type == "string") { suffix = " = \"\""; } else { suffix = " = new " + type + "()"; } } else { suffix = KnownStuff.GetConstTypesAffix(type); } } else { if (type == "string") { suffix = " = \"\""; } else { suffix = " = new " + prefix + t + "()"; } } output = lowestindent + "public " + prefix + t + " " + name + otherstuff + suffix + ";"; } else { if (length.Length > 0) { IsLiteral = true; } if (otherstuff.Contains('=')) { string[] split = otherstuff.Split('='); otherstuff = split[0] + " = (" + type + ")" + split[1]; } string t = KnownStuff.GetNamespacedType(this, type); if (length.Length > 0) { output = lowestindent + "public " + t + "[] " + name + otherstuff + " = new " + type + "[" + length + "];"; } else { output = lowestindent + "public " + "" + t + "[] " + name + otherstuff + ";"; } } Type = type; parent.resolve(this); if (!KnownStuff.KnownTypes.ContainsKey(rostype)) { meta = true; } Name = name.Length == 0 ? otherstuff.Trim() : name; if (Name.Contains('=')) { Name = Name.Substring(0, Name.IndexOf("=")).Trim(); } }
public MsgsFile(string filename, string extraindent) { if (resolver == null) { resolver = new Dictionary <string, List <string> >(); } if (!filename.Contains(".msg")) { throw new Exception("" + filename + " IS NOT A VALID MSG FILE!"); } string[] sp = filename.Replace(Program.inputdir, "").Replace(".msg", "").Split('\\'); classname = sp[sp.Length - 1]; Namespace += "." + filename.Replace(Program.inputdir, "").Replace(".msg", ""); Namespace = Namespace.Replace("\\", ".").Replace("..", "."); string[] sp2 = Namespace.Split('.'); Namespace = ""; for (int i = 0; i < sp2.Length - 2; i++) { Namespace += sp2[i] + "."; } Namespace += sp2[sp2.Length - 2]; //THIS IS BAD! classname = classname.Replace("/", "."); Name = Namespace.Replace("Messages", "").TrimStart('.') + "." + classname; Name = Name.TrimStart('.'); classname = Name.Split('.').Length > 1 ? Name.Split('.')[1] : Name; Namespace = Namespace.Trim('.'); if (!resolver.Keys.Contains(classname) && Namespace != "Messages.std_msgs") { resolver.Add(classname, new List <string>() { Namespace + "." + classname }); } else if (Namespace != "Messages.std_msgs") { resolver[classname].Add(Namespace + "." + classname); } List <string> lines = new List <string>(File.ReadAllLines(filename)); lines = lines.Where(st => (!st.Contains('#') || st.Split('#')[0].Length != 0)).ToList(); for (int i = 0; i < lines.Count; i++) { lines[i] = lines[i].Split('#')[0].Trim(); } //lines = lines.Where((st) => (st.Length > 0)).ToList(); lines.ForEach(s => { if (s.Contains('#') && s.Split('#')[0].Length != 0) { s = s.Split('#')[0]; } if (s.Contains('#')) { s = ""; } }); lines = lines.Where(st => (st.Length > 0)).ToList(); def = new List <string>(); for (int i = 0; i < lines.Count; i++) { def.Add(lines[i]); if (Name.ToLower() == "string") { lines[i].Replace("String", "string"); } SingleType test = KnownStuff.WhatItIs(this, lines[i], extraindent); if (test != null) { Stuff.Add(test); } } }