Inheritance: GtkSharp.Generation.ObjectBase
示例#1
0
        public virtual Signal GetSignalRecursively(string name, bool check_self)
        {
            Signal p = null;

            if (check_self)
            {
                p = GetSignal(name);
            }
            if (p == null && Parent != null)
            {
                p = (Parent as ObjectBase).GetSignalRecursively(name, true);
            }

            if (check_self && p == null)
            {
                foreach (string iface in interfaces)
                {
                    InterfaceGen igen = SymbolTable.Table.GetClassGen(iface) as InterfaceGen;
                    if (igen == null)
                    {
                        continue;
                    }
                    p = igen.GetSignalRecursively(name, true);
                    if (p != null)
                    {
                        break;
                    }
                }
            }

            return(p);
        }
示例#2
0
        public override bool Validate()
        {
            LogWriter log = new LogWriter(QualifiedName);

            foreach (string iface in interfaces)
            {
                InterfaceGen igen = SymbolTable.Table[iface] as InterfaceGen;
                if (igen == null)
                {
                    log.Warn("implements unknown GInterface " + iface);
                    return(false);
                }
                if (!igen.ValidateForSubclass())
                {
                    log.Warn("implements invalid GInterface " + iface);
                    return(false);
                }
            }

            ArrayList invalids = new ArrayList();

            foreach (Property prop in props.Values)
            {
                if (!prop.Validate(log))
                {
                    invalids.Add(prop);
                }
            }
            foreach (Property prop in invalids)
            {
                props.Remove(prop.Name);
            }
            invalids.Clear();

            foreach (ObjectField field in fields.Values)
            {
                if (!field.Validate(log))
                {
                    invalids.Add(field);
                }
            }
            foreach (ObjectField field in invalids)
            {
                fields.Remove(field.Name);
            }
            invalids.Clear();

            foreach (Method method in methods.Values)
            {
                if (!method.Validate(log))
                {
                    invalids.Add(method);
                }
            }
            foreach (Method method in invalids)
            {
                methods.Remove(method.Name);
            }
            invalids.Clear();

            foreach (Ctor ctor in ctors)
            {
                if (!ctor.Validate(log))
                {
                    invalids.Add(ctor);
                }
            }
            foreach (Ctor ctor in invalids)
            {
                ctors.Remove(ctor);
            }
            invalids.Clear();

            return(true);
        }
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = QualifiedName;

            string        asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower() + "-sharp" : gen_info.AssemblyName;
            DirectoryInfo di       = GetDirectoryInfo(gen_info.Dir, asm_name);

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name, NS);

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Collections;");
            sw.WriteLine("\tusing System.Collections.Generic;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();

            SymbolTable table = SymbolTable.Table;

            sw.WriteLine("#region Autogenerated code");
            if (IsDeprecated)
            {
                sw.WriteLine("\t[Obsolete]");
            }
            foreach (string attr in customAttrs)
            {
                sw.WriteLine("\t" + attr);
            }
            sw.Write("\t{0} {1}partial class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : "");
            string csParent = table.GetCSType(Elem.GetAttribute("parent"));

            if (!string.IsNullOrEmpty(csParent))
            {
                di.objects.Add(CName, QualifiedName);
                sw.Write(" : " + csParent);
            }
            foreach (string iface in interfaces)
            {
                if (Parent != null && Parent.Implements(iface))
                {
                    continue;
                }
                sw.Write(", " + table.GetCSType(iface));
            }
            foreach (string iface in managed_interfaces)
            {
                if (Parent != null && Parent.Implements(iface))
                {
                    continue;
                }
                sw.Write(", " + iface);
            }
            sw.WriteLine(" {");
            sw.WriteLine();

            GenCtors(gen_info);
            GenProperties(gen_info, null);
            GenFields(gen_info);
            GenChildProperties(gen_info);

            bool has_sigs = (sigs != null && sigs.Count > 0);

            if (!has_sigs)
            {
                foreach (string iface in interfaces)
                {
                    if (table.GetClassGen(iface) is InterfaceGen iGen && iGen.Signals != null)
                    {
                        has_sigs = true;
                        break;
                    }
                }
            }

            if (has_sigs && Elem.HasAttribute("parent"))
            {
                GenSignals(gen_info, null);
            }

            GenConstants(gen_info);
            GenClassMembers(gen_info, csParent);
            GenMethods(gen_info, null, null);

            if (interfaces.Count != 0)
            {
                var all_methods = new Dictionary <string, Method> ();
                foreach (Method m in Methods.Values)
                {
                    all_methods[m.Name] = m;
                }
                var collisions = new Dictionary <string, bool> ();
                foreach (string iface in interfaces)
                {
                    ClassBase igen = table.GetClassGen(iface);
                    foreach (Method m in igen.Methods.Values)
                    {
                        if (m.Name.StartsWith("Get") || m.Name.StartsWith("Set"))
                        {
                            if (GetProperty(m.Name.Substring(3)) != null)
                            {
                                collisions[m.Name] = true;
                                continue;
                            }
                        }

                        all_methods.TryGetValue(m.Name, out Method collision);
                        if (collision != null && collision.Signature.Types == m.Signature.Types)
                        {
                            collisions[m.Name] = true;
                        }
                        else
                        {
                            all_methods[m.Name] = m;
                        }
                    }
                }

                foreach (string iface in interfaces)
                {
                    if (Parent != null && Parent.Implements(iface))
                    {
                        continue;
                    }
                    InterfaceGen igen = table.GetClassGen(iface) as InterfaceGen;
                    igen.GenMethods(gen_info, collisions, this);
                    igen.GenProperties(gen_info, this);
                    igen.GenSignals(gen_info, this);
                    igen.GenVirtualMethods(gen_info, this);
                }
            }

            foreach (XmlElement str in strings)
            {
                sw.Write("\t\tpublic static string " + str.GetAttribute("name"));
                sw.WriteLine(" {\n\t\t\t get { return \"" + str.GetAttribute("value") + "\"; }\n\t\t}");
            }

            if (!string.IsNullOrEmpty(csParent) && GetExpected(CName) != QualifiedName)
            {
                sw.WriteLine();
                sw.WriteLine("\t\tstatic " + Name + " ()");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tGtkSharp." + Studlify(asm_name) + ".ObjectManager.Initialize ();");
                sw.WriteLine("\t\t}");
            }

            GenerateStructureABI(gen_info);
            sw.WriteLine("#endregion");

            sw.WriteLine("\t}");
            sw.WriteLine("}");

            sw.Close();
            gen_info.Writer = null;
            Statistics.ObjectCount++;
        }
示例#4
0
        public override bool Validate()
        {
            if (Parent != null && !Parent.ValidateForSubclass())
            {
                return(false);
            }
            foreach (string iface in interfaces)
            {
                InterfaceGen igen = SymbolTable.Table[iface] as InterfaceGen;
                if (igen == null)
                {
                    Console.WriteLine(QualifiedName + " implements unknown GInterface " + iface);
                    return(false);
                }
                if (!igen.ValidateForSubclass())
                {
                    Console.WriteLine(QualifiedName + " implements invalid GInterface " + iface);
                    return(false);
                }
            }

            ArrayList invalids = new ArrayList();

            foreach (Property prop in props.Values)
            {
                if (!prop.Validate())
                {
                    Console.WriteLine("in type " + QualifiedName);
                    invalids.Add(prop);
                }
            }
            foreach (Property prop in invalids)
            {
                props.Remove(prop.Name);
            }
            invalids.Clear();

            foreach (Signal sig in sigs.Values)
            {
                if (!sig.Validate())
                {
                    Console.WriteLine("in type " + QualifiedName);
                    invalids.Add(sig);
                }
            }
            foreach (Signal sig in invalids)
            {
                sigs.Remove(sig.Name);
            }
            invalids.Clear();

            foreach (ObjectField field in fields.Values)
            {
                if (!field.Validate())
                {
                    Console.WriteLine("in type " + QualifiedName);
                    invalids.Add(field);
                }
            }
            foreach (ObjectField field in invalids)
            {
                fields.Remove(field.Name);
            }
            invalids.Clear();

            foreach (Method method in methods.Values)
            {
                if (!method.Validate())
                {
                    Console.WriteLine("in type " + QualifiedName);
                    invalids.Add(method);
                }
            }
            foreach (Method method in invalids)
            {
                methods.Remove(method.Name);
            }
            invalids.Clear();

            foreach (Ctor ctor in ctors)
            {
                if (!ctor.Validate())
                {
                    Console.WriteLine("in type " + QualifiedName);
                    invalids.Add(ctor);
                }
            }
            foreach (Ctor ctor in invalids)
            {
                ctors.Remove(ctor);
            }
            invalids.Clear();

            return(true);
        }