Пример #1
0
 public SingleType Finalize(MsgsFile parent, KeyValuePair <string, string> csharptype)
 {
     string[] PARTS = input.Split(' ');
     rostype = PARTS[0];
     if (!KnownStuff.KnownTypes.ContainsKey(rostype))
     {
         meta = true;
     }
     PARTS[0] = csharptype.Value;
     return(Finalize(parent, PARTS, true));
 }
Пример #2
0
 public static string Sum(MsgsFile m)
 {
     if (!md5memo.ContainsKey(m.Name))
     {
         string hashme = PrepareToHash(m);
         if (hashme == null)
             return null;
         md5memo[m.Name] = Sum(hashme);
     }
     return md5memo[m.Name];
 }
Пример #3
0
 public static SingleType WhatItIs(MsgsFile parent, SingleType t)
 {
     foreach (KeyValuePair <string, string> test in KnownTypes)
     {
         if (t.Test(test))
         {
             t.rostype = t.Type;
             return(t.Finalize(parent, test));
         }
     }
     return(t.Finalize(parent, t.input.Split(spliter, StringSplitOptions.RemoveEmptyEntries), false));
 }
Пример #4
0
        public static SingleType WhatItIs(MsgsFile parent, string s, string extraindent)
        {
            string[] pieces  = s.Split('/');
            string   package = "";

            if (pieces.Length > 1)
            {
                for (int i = 0; i < pieces.Length - 1; i++)
                {
                    if (i > 0 && i < pieces.Length - 2)
                    {
                        package += "/";
                    }
                    package += pieces[i];
                }
                s = pieces[pieces.Length - 1];
            }
            return(WhatItIs(parent, new SingleType(package, s, extraindent)));
        }
Пример #5
0
 public SrvsFile(MsgFileLocation filename)
 {
     //read in srv file
     string[] lines = File.ReadAllLines(filename.Path);
     classname = filename.basename;
     Namespace += "." + filename.package;
     Name = filename.package + "." + filename.basename;
     //def is the list of all lines in the file
     def = new List<string>();
     int mid = 0;
     bool found = false;
     List<string> request = new List<string>(), response = new List<string>();
     //Search through for the "---" separator between request and response
     for (; mid < lines.Length; mid++)
     {
         lines[mid] = lines[mid].Replace("\"", "\\\"");
         if (lines[mid].Contains('#'))
         {
             lines[mid] = lines[mid].Substring(0, lines[mid].IndexOf('#'));
         }
         lines[mid] = lines[mid].Trim();
         if (lines[mid].Length == 0)
         {
             continue;
         }
         def.Add(lines[mid]);
         if (lines[mid].Contains("---"))
         {
             found = true;
             continue;
         }
         if (found)
             response.Add(lines[mid]);
         else
             request.Add(lines[mid]);
     }
     //treat request and response like 2 message files, each with a partial definition and extra stuff tagged on to the classname
     Request = new MsgsFile(new MsgFileLocation(filename.Path.Replace(".srv",".msg"), filename.searchroot), true, request, "\t");
     Response = new MsgsFile(new MsgFileLocation(filename.Path.Replace(".srv", ".msg"), filename.searchroot), false, response, "\t");
 }
Пример #6
0
        public SrvsFile(string filename)
        {
            //read in srv file
            string[] lines = File.ReadAllLines(filename);

            string[] sp = filename.Replace(Program.inputdir, "").Replace(".srv", "").Split('\\');
            //Parse The file name to get the classname;
            classname = sp[sp.Length - 1];
            //Parse for the Namespace
            Namespace += "." + filename.Replace(Program.inputdir, "").Replace(".srv", "");
            Namespace  = Namespace.Replace("\\", ".").Replace("..", ".");

            //split up Namespace and put it back together without the last part, aka. classname
            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!
            //Name set to Namespace + classname
            classname = classname.Replace("/", ".");
            Name      = Namespace.Replace("Messages", "").TrimStart('.') + "." + classname;
            Name      = Name.TrimStart('.');
            classname = Name.Split('.').Length > 1 ? Name.Split('.')[1] : Name;
            Namespace = Namespace.Trim('.');

            //def is the list of all lines in the file
            def = new List <string>();
            int           mid = 0;
            bool          found = false;
            List <string> request = new List <string>(), response = new List <string>();

            //Search through for the "---" separator between request and response
            for (; mid < lines.Length; mid++)
            {
                lines[mid] = lines[mid].Replace("\"", "\\\"");
                if (lines[mid].Contains('#'))
                {
                    lines[mid] = lines[mid].Substring(0, lines[mid].IndexOf('#'));
                }
                lines[mid] = lines[mid].Trim();
                if (lines[mid].Length == 0)
                {
                    continue;
                }
                def.Add(lines[mid]);
                if (lines[mid].Contains("---"))
                {
                    found = true;
                    continue;
                }
                if (found)
                {
                    response.Add(lines[mid]);
                }
                else
                {
                    request.Add(lines[mid]);
                }
            }
            //add lines aproprietly
            Request  = new MsgsFile(filename, true, request, "\t");
            Response = new MsgsFile(filename, false, response, "\t");
        }
Пример #7
0
 public void refinalize(MsgsFile parent, string REALTYPE)
 {
     bool isconst = false;
     string type = REALTYPE;
     string name = backup[1];
     string otherstuff = "";
     if (name.Contains('='))
     {
         string[] parts = name.Split('=');
         isconst = true;
         name = parts[0];
         otherstuff = " = " + parts[1];
     }
     for (int i = 2; i < backup.Length; i++)
         otherstuff += " " + backup[i];
     if (otherstuff.Contains('=')) isconst = true;
     parent.resolve(Package, ref type);
     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.InvariantCultureIgnoreCase))
             {
                 otherstuff = chunks[0] + " = new String(\"" + chunks[1].Trim().Replace("\"", "") + "\")";
             }
         }
         else if (!type.Equals("String"))
         {
             wantsconstructor = true;
         }
         string prefix = "", suffix = "";
         if (isconst)
         {
             if (!type.Equals("string", StringComparison.InvariantCultureIgnoreCase))
             {
                 prefix = "const ";
             }
         }
         if (otherstuff.Contains('='))
             if (wantsconstructor)
                 if (type == "string")
                     suffix = " = \"\"";
                 else
                     suffix = " = new " + type + "()";
             else
                 suffix = KnownStuff.GetConstTypesAffix(type);
         output = lowestindent + "public " + prefix + type + " " + name + otherstuff + suffix + ";";
     }
     else
     {
         if (length.Length != 0)
             IsLiteral = type != "string";
         if (otherstuff.Contains('='))
         {
             string[] split = otherstuff.Split('=');
             otherstuff = split[0] + " = (" + type + ")" + split[1];
         }
         if (length.Length != 0)
             output = lowestindent + "public " + type + "[] " + name + otherstuff + " = new " + type + "[" + length + "];";
         else
             output = lowestindent + "public " + "" + type + "[] " + name + otherstuff + ";";
     }
     Type = type;
     if (!KnownStuff.KnownTypes.ContainsKey(rostype))
         meta = true;
     Name = name.Length == 0 ? otherstuff.Split('=')[0].Trim() : name;
 }
Пример #8
0
 public SingleType Finalize(MsgsFile parent, KeyValuePair<string, string> csharptype)
 {
     string[] PARTS = input.Split(' ');
     rostype = PARTS[0];
     if (!KnownStuff.KnownTypes.ContainsKey(rostype))
         meta = true;
     PARTS[0] = csharptype.Value;
     return Finalize(parent, PARTS, true);
 }
Пример #9
0
 public static SingleType WhatItIs(MsgsFile parent, SingleType t)
 {
     foreach (KeyValuePair<string, string> test in KnownTypes)
     {
         if (t.Test(test))
         {
             t.rostype = t.Type;
             return t.Finalize(parent, test);
         }
     }
     return t.Finalize(parent, t.input.Split(spliter, StringSplitOptions.RemoveEmptyEntries), false);
 }
Пример #10
0
        private static string PrepareToHash(MsgsFile irm)
        {
            string hashme = irm.Definition.Trim('\n', '\t', '\r', ' ');
            while (hashme.Contains("  "))
                hashme = hashme.Replace("  ", " ");
            while (hashme.Contains("\r\n"))
                hashme = hashme.Replace("\r\n", "\n");
            hashme = hashme.Trim();
            string[] lines = hashme.Split('\n');

            Queue<string> haves = new Queue<string>(), havenots = new Queue<string>();
            for (int i = 0; i < lines.Length; i++)
            {
                string l = lines[i];
                if (l.Contains("="))
                {
                    //condense spaces on either side of =
                    string[] ls = l.Split('=');
                    haves.Enqueue(ls[0].Trim()+"="+ls[1].Trim());
                }
                else havenots.Enqueue(l.Trim());
            }
            hashme = "";
            while (haves.Count + havenots.Count > 0)
                hashme += (haves.Count > 0 ? haves.Dequeue() : havenots.Dequeue()) + (haves.Count + havenots.Count >= 1 ? "\n" : "");
            Dictionary<string, MsgFieldInfo> mfis = MessageFieldHelper.Instantiate(irm.Stuff);
            MsgFieldInfo[] fields = mfis.Values.ToArray();
            for(int i=0;i<fields.Length;i++)
            {
                if (fields[i].IsLiteral)
                    continue;
                MsgsFile ms = irm.Stuff[i].Definer;
                if (ms == null)
                {
                    KnownStuff.WhatItIs(irm, irm.Stuff[i]);
                    if (irm.Stuff[i].Type.Contains("/"))
                    {
                        irm.resolve(irm, irm.Stuff[i]);
                    }
                    ms = irm.Stuff[i].Definer;
                }
                if (ms == null)
                {
                    Debug.WriteLine("NEEDS ANOTHER PASS: "******" B/C OF " + irm.Stuff[i].Type);
                    return null;
                }
                string sum = MD5.Sum(ms);
                if (sum == null)
                {
                    Debug.WriteLine("STILL NEEDS ANOTHER PASS: "******" B/C OF " + irm.Stuff[i].Type);
                    return null;
                }
                Regex findCurrentFieldType = new Regex("\\b" + fields[i].Type + "\\b");
                string[] BLADAMN = findCurrentFieldType.Replace(hashme, sum).Split('\n');
                hashme = "";
                for (int x = 0; x < BLADAMN.Length; x++)
                {
                    if (BLADAMN[x].Contains(fields[i].Name.Replace("@", "")))
                    {
                        if (BLADAMN[x].Contains("/"))
                        {
                            BLADAMN[x] = BLADAMN[x].Split('/')[1];
                        }

                        if (BLADAMN[x].Contains("[]") && !fields[i].IsLiteral)
                        {
                            BLADAMN[x] = BLADAMN[x].Replace("[]", "");
                        }
                    }
                    hashme += BLADAMN[x];
                    if (x < BLADAMN.Length - 1)
                        hashme += "\n";
                }
            }
            return hashme;
        }
Пример #11
0
        public SrvsFile(string filename)
        {
            //read in srv file
            string[] lines = File.ReadAllLines(filename);

            string[] sp = filename.Replace(Program.inputdir, "").Replace(".srv", "").Split('\\');
            //Parse The file name to get the classname;
            classname = sp[sp.Length - 1];
            //Parse for the Namespace
            Namespace += "." + filename.Replace(Program.inputdir, "").Replace(".srv", "");
            Namespace = Namespace.Replace("\\", ".").Replace("..", ".");

            //split up Namespace and put it back together without the last part, aka. classname
            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!
            //Name set to Namespace + classname
            classname = classname.Replace("/", ".");
            Name = Namespace.Replace("Messages", "").TrimStart('.') + "." + classname;
            Name = Name.TrimStart('.');
            classname = Name.Split('.').Length > 1 ? Name.Split('.')[1] : Name;
            Namespace = Namespace.Trim('.');

            //def is the list of all lines in the file
            def = new List<string>();
            int mid = 0;
            bool found = false;
            List<string> request = new List<string>(), response = new List<string>();
            //Search through for the "---" separator between request and response
            for (; mid < lines.Length; mid++)
            {
                lines[mid] = lines[mid].Replace("\"", "\\\"");
                if (lines[mid].Contains('#'))
                {
                    lines[mid] = lines[mid].Substring(0, lines[mid].IndexOf('#'));
                }
                lines[mid] = lines[mid].Trim();
                if (lines[mid].Length == 0)
                {
                    continue;
                }
                def.Add(lines[mid]);
                if (lines[mid].Contains("---"))
                {
                    found = true;
                    continue;
                }
                if (found)
                    response.Add(lines[mid]);
                else
                    request.Add(lines[mid]);
            }
            //add lines aproprietly
            Request = new MsgsFile(filename, true, request, "\t");
            Response = new MsgsFile(filename, false, response, "\t");
        }
Пример #12
0
 public void resolve(MsgsFile parent, SingleType st)
 {
     if (st.Type == null)
     {
         KnownStuff.WhatItIs(parent, st);
     }
     List<string> prefixes = new List<string>(new[] { "", "std_msgs", "geometry_msgs", "actionlib_msgs"});
     if (st.Type.Contains("/"))
     {
         string[] pieces = st.Type.Split('/');
         st.Package = pieces[0];
         st.Type = pieces[1];
     }
     if (!string.IsNullOrEmpty(st.Package))
         prefixes[0] = st.Package;
     foreach (string p in prefixes)
     {
         if (resolver.Keys.Contains(p))
         {
             if (resolver[p].ContainsKey(st.Type))
             {
                 if (resolver[p][st.Type].Count == 1)
                 {
                     st.Package = p;
                     st.Definer = resolver[p][st.Type][0].Definer;
                 }
                 else if (resolver[p][st.Type].Count>1)
                     throw new Exception("Could not resolve " + st.Type);
             }
         }
     }
 }
Пример #13
0
        public void Finalize(MsgsFile 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 = false;
                if (otherstuff.Contains("="))
                {
                    string[] chunks = otherstuff.Split('=');
                    ConstValue = chunks[chunks.Length - 1].Trim();
                    if (type.Equals("string", StringComparison.InvariantCultureIgnoreCase))
                    {
                        otherstuff = chunks[0] + " = \"" + chunks[1].Trim() + "\"";
                    }
                }
                string prefix = "", suffix = "";
                if (isconst)
                {
                    if (!type.Equals("string", StringComparison.InvariantCultureIgnoreCase))
                    {
                        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 + "; //woo";
            }
            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(parent, 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();
            }
        }
Пример #14
0
 public static void Finalize(MsgsFile parent, SingleType thing, KeyValuePair<string, string> csharptype)
 {
     string[] PARTS = thing.input.Split(' ');
     thing.rostype = PARTS[0];
     if (!KnownStuff.KnownTypes.ContainsKey(thing.rostype))
         thing.meta = true;
     PARTS[0] = csharptype.Value;
     thing.Finalize(parent, PARTS, true);
 }
Пример #15
0
 public static SingleType WhatItIs(MsgsFile parent, string s, string extraindent)
 {
     string[] pieces = s.Split('/');
     string package = parent.Package;
     if (pieces.Length == 2)
     {
         package = pieces[0];
         s = pieces[1];
     }
     SingleType st = new SingleType(package, s, extraindent);
     parent.resolve(parent, st);
     WhatItIs(parent, st);
     return st;
 }
Пример #16
0
        public void refinalize(MsgsFile parent, string REALTYPE)
        {
            bool   isconst    = false;
            string type       = REALTYPE;
            string name       = backup[1];
            string otherstuff = "";

            if (name.Contains('='))
            {
                string[] parts = name.Split('=');
                isconst    = true;
                name       = parts[0];
                otherstuff = " = " + parts[1];
            }
            for (int i = 2; i < backup.Length; i++)
            {
                otherstuff += " " + backup[i];
            }
            if (otherstuff.Contains('='))
            {
                isconst = true;
            }
            parent.resolve(Package, ref type);
            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.InvariantCultureIgnoreCase))
                    {
                        otherstuff = chunks[0] + " = new String(\"" + chunks[1].Trim().Replace("\"", "") + "\")";
                    }
                }
                else if (!type.Equals("String"))
                {
                    wantsconstructor = true;
                }
                string prefix = "", suffix = "";
                if (isconst)
                {
                    if (!type.Equals("string", StringComparison.InvariantCultureIgnoreCase))
                    {
                        prefix = "const ";
                    }
                }
                if (otherstuff.Contains('='))
                {
                    if (wantsconstructor)
                    {
                        if (type == "string")
                        {
                            suffix = " = \"\"";
                        }
                        else
                        {
                            suffix = " = new " + type + "()";
                        }
                    }
                    else
                    {
                        suffix = KnownStuff.GetConstTypesAffix(type);
                    }
                }
                output = lowestindent + "public " + prefix + type + " " + name + otherstuff + suffix + ";";
            }
            else
            {
                if (length.Length != 0)
                {
                    IsLiteral = type != "string";
                }
                if (otherstuff.Contains('='))
                {
                    string[] split = otherstuff.Split('=');
                    otherstuff = split[0] + " = (" + type + ")" + split[1];
                }
                if (length.Length != 0)
                {
                    output = lowestindent + "public " + type + "[] " + name + otherstuff + " = new " + type + "[" + length + "];";
                }
                else
                {
                    output = lowestindent + "public " + "" + type + "[] " + name + otherstuff + ";";
                }
            }
            Type = type;
            if (!KnownStuff.KnownTypes.ContainsKey(rostype))
            {
                meta = true;
            }
            Name = name.Length == 0 ? otherstuff.Split('=')[0].Trim() : name;
        }
Пример #17
0
 public static SingleType WhatItIs(MsgsFile parent, string s, string extraindent)
 {
     string[] pieces = s.Split('/');
     string package = "";
     if (pieces.Length > 1)
     {
         for (int i = 0; i < pieces.Length - 1; i++)
         {
             if (i > 0 && i < pieces.Length - 2)
                 package += "/";
             package += pieces[i];
         }
         s = pieces[pieces.Length - 1];
     }
     return WhatItIs(parent, new SingleType(package, s, extraindent));
 }