resolve() public method

public resolve ( MsgsFile parent, SingleType st ) : void
parent MsgsFile
st SingleType
return void
Exemplo n.º 1
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;
        }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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;
        }