Exemple #1
0
        public bool IsHidden(Parameter p)
        {
            int idx = param_list.IndexOf (p);

            if (idx > 0 && p.IsLength && p.PassAs == String.Empty && this [idx - 1].IsString)
                return true;

            if (p.IsCount && ((idx > 0 && this [idx - 1].IsArray) ||
                      (idx < Count - 1 && this [idx + 1].IsArray)))
                return true;

            if (p.CType == "GError**")
                return true;

            if (HasCB || HideData) {
                if (p.IsUserData && (idx == Count - 1))
                                        return true;
                if (p.IsUserData && (idx == Count - 2) && this [Count - 1] is ErrorParameter)
                                        return true;
                if (p.IsUserData && idx > 0 &&
                    this [idx - 1].Generatable is CallbackGen)
                    return true;
                if (p.IsDestroyNotify && (idx == Count - 1) &&
                    this [idx - 1].IsUserData)
                    return true;
            }

            return false;
        }
Exemple #2
0
        public bool Validate()
        {
            if (valid)
                return true;

            if (elem == null)
                return false;

            for (int i = first_is_instance ? 1 : 0; i < elem.ChildNodes.Count; i++) {
                XmlElement parm = elem.ChildNodes [i] as XmlElement;
                if (parm == null || parm.Name != "parameter")
                    continue;
                Parameter p = new Parameter (parm);

                if (p.IsEllipsis) {
                    Console.Write("Ellipsis parameter ");
                    Clear ();
                    return false;
                }

                if ((p.CSType == "") || (p.Name == "") ||
                    (p.MarshalType == "") || (SymbolTable.Table.CallByName(p.CType, p.Name) == "")) {
                    Console.Write ("Invalid parameter {0} of type {1}", p.Name, p.CType);
                    Clear ();
                    return false;
                }

                IGeneratable gen = p.Generatable;

                if (p.IsArray) {
                    p = new ArrayParameter (parm);
                    if (i < elem.ChildNodes.Count - 1) {
                        XmlElement next = elem.ChildNodes [i + 1] as XmlElement;
                        if (next != null || next.Name == "parameter") {
                            Parameter c = new Parameter (next);
                            if (c.IsCount) {
                                p = new ArrayCountPair (parm, next, false);
                                i++;
                            }
                        }
                    }
                } else if (p.IsCount && i < elem.ChildNodes.Count - 1) {
                    XmlElement next = elem.ChildNodes [i + 1] as XmlElement;
                    if (next != null || next.Name == "parameter") {
                        Parameter a = new Parameter (next);
                        if (a.IsArray) {
                            p = new ArrayCountPair (next, parm, true);
                            i++;
                        }
                    }
                } else if (p.CType == "GError**")
                    p = new ErrorParameter (parm);
                else if (gen is StructBase || gen is ByRefGen) {
                    p = new StructParameter (parm);
                } else if (gen is CallbackGen) {
                    has_cb = true;
                }
                param_list.Add (p);
            }

            if (has_cb && Count > 2 && this [Count - 3].Generatable is CallbackGen && this [Count - 2].IsUserData && this [Count - 1].IsDestroyNotify)
                this [Count - 3].Scope = "notified";

            valid = true;
            return true;
        }
Exemple #3
0
        public void Generate(GenerationInfo gen_info)
        {
            if (!Validate())
            {
                return;
            }

            StreamWriter sw = gen_info.Writer;

            gen_info.CurrentMember = CName;

            GenerateImport(sw);

            if (IsStatic)
            {
                GenerateStatic(gen_info);
            }
            else
            {
                sw.WriteLine("\t\t{0} {1}{2} ({3}) {4}", Protection, Safety, name, Signature.ToString(), needs_chaining ? ": base (IntPtr.Zero)" : "");
                sw.WriteLine("\t\t{");

                if (needs_chaining)
                {
                    sw.WriteLine("\t\t\tif (GetType () != typeof (" + name + ")) {");

                    if (Parameters.Count == 0)
                    {
                        sw.WriteLine("\t\t\t\tCreateNativeObject (new string [0], new GLib.Value[0]);");
                        sw.WriteLine("\t\t\t\treturn;");
                    }
                    else
                    {
                        ArrayList names  = new ArrayList();
                        ArrayList values = new ArrayList();
                        for (int i = 0; i < Parameters.Count; i++)
                        {
                            Parameter p = Parameters[i];
                            if (container_type.GetPropertyRecursively(p.StudlyName) != null)
                            {
                                names.Add(p.Name);
                                values.Add(p.Name);
                            }
                            else if (p.PropertyName != String.Empty)
                            {
                                names.Add(p.PropertyName);
                                values.Add(p.Name);
                            }
                        }

                        if (names.Count == Parameters.Count)
                        {
                            sw.WriteLine("\t\t\t\tArrayList vals = new ArrayList();");
                            sw.WriteLine("\t\t\t\tArrayList names = new ArrayList();");
                            for (int i = 0; i < names.Count; i++)
                            {
                                Parameter p      = Parameters [i];
                                string    indent = "\t\t\t\t";
                                if (p.Generatable is ClassBase && !(p.Generatable is StructBase))
                                {
                                    sw.WriteLine(indent + "if (" + p.Name + " != null) {");
                                    indent += "\t";
                                }
                                sw.WriteLine(indent + "names.Add (\"" + names [i] + "\");");
                                sw.WriteLine(indent + "vals.Add (new GLib.Value (" + values[i] + "));");

                                if (p.Generatable is ClassBase && !(p.Generatable is StructBase))
                                {
                                    sw.WriteLine("\t\t\t\t}");
                                }
                            }

                            sw.WriteLine("\t\t\t\tCreateNativeObject ((string[])names.ToArray (typeof (string)), (GLib.Value[])vals.ToArray (typeof (GLib.Value)));");
                            sw.WriteLine("\t\t\t\treturn;");
                        }
                        else
                        {
                            sw.WriteLine("\t\t\t\tthrow new InvalidOperationException (\"Can't override this constructor.\");");
                        }
                    }

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

                Body.Initialize(gen_info, false, false, "");
                sw.WriteLine("\t\t\t{0} = {1}({2});", container_type.AssignToName, CName, Body.GetCallString(false));
                Body.Finish(sw, "");
                Body.HandleException(sw, "");
            }

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

            Statistics.CtorCount++;
        }