Exemple #1
0
        public virtual void Generate(GenerationInfo gen_info, string indent)
        {
            if (Ignored || Hidden)
            {
                return;
            }

            CheckGlue();
            if ((getterName != null || setterName != null || getOffsetName != null) &&
                gen_info.GlueWriter == null)
            {
                Console.WriteLine("No glue-filename specified, can't create glue for {0}.{1}",
                                  container_type.Name, Name);
                return;
            }

            GenerateImports(gen_info, indent);

            SymbolTable  table     = SymbolTable.Table;
            StreamWriter sw        = gen_info.Writer;
            string       modifiers = elem.HasAttribute("new_flag") ? "new " : "";
            bool         is_struct = table.IsStruct(CType) || table.IsBoxed(CType);

            sw.WriteLine(indent + "public " + modifiers + CSType + " " + Name + " {");

            if (Getter != null)
            {
                sw.Write(indent + "\tget ");
                Getter.GenerateBody(gen_info, container_type, "\t");
                sw.WriteLine("");
            }
            else if (getterName != null)
            {
                sw.WriteLine(indent + "\tget {");
                container_type.Prepare(sw, indent + "\t\t");
                sw.WriteLine(indent + "\t\t" + CSType + " result = " + table.FromNativeReturn(ctype, getterName + " (" + container_type.CallByName() + ")") + ";");
                container_type.Finish(sw, indent + "\t\t");
                sw.WriteLine(indent + "\t\treturn result;");
                sw.WriteLine(indent + "\t}");
            }
            else if (Readable && offsetName != null)
            {
                sw.WriteLine(indent + "\tget {");
                sw.WriteLine(indent + "\t\tunsafe {");
                if (is_struct)
                {
                    sw.WriteLine(indent + "\t\t\t" + CSType + "* raw_ptr = (" + CSType + "*)(((byte*)" + container_type.CallByName() + ") + " + offsetName + ");");
                    sw.WriteLine(indent + "\t\t\treturn *raw_ptr;");
                }
                else
                {
                    sw.WriteLine(indent + "\t\t\t" + table.GetMarshalReturnType(CType) + "* raw_ptr = (" + table.GetMarshalReturnType(CType) + "*)(((byte*)" + container_type.CallByName() + ") + " + offsetName + ");");
                    sw.WriteLine(indent + "\t\t\treturn " + table.FromNativeReturn(ctype, "(*raw_ptr)") + ";");
                }
                sw.WriteLine(indent + "\t\t}");
                sw.WriteLine(indent + "\t}");
            }

            if (Setter != null)
            {
                sw.Write(indent + "\tset ");
                Setter.GenerateBody(gen_info, container_type, "\t");
                sw.WriteLine("");
            }
            else if (setterName != null)
            {
                sw.WriteLine(indent + "\tset {");
                container_type.Prepare(sw, indent + "\t\t");
                sw.WriteLine(indent + "\t\t" + setterName + " (" + container_type.CallByName() + ", " + table.CallByName(ctype, "value") + ");");
                container_type.Finish(sw, indent + "\t\t");
                sw.WriteLine(indent + "\t}");
            }
            else if (Writable && offsetName != null)
            {
                sw.WriteLine(indent + "\tset {");
                sw.WriteLine(indent + "\t\tunsafe {");
                if (is_struct)
                {
                    sw.WriteLine(indent + "\t\t\t" + CSType + "* raw_ptr = (" + CSType + "*)(((byte*)" + container_type.CallByName() + ") + " + offsetName + ");");
                    sw.WriteLine(indent + "\t\t\t*raw_ptr = value;");
                }
                else
                {
                    sw.WriteLine(indent + "\t\t\t" + table.GetMarshalReturnType(CType) + "* raw_ptr = (" + table.GetMarshalReturnType(CType) + "*)(((byte*)" + container_type.CallByName() + ") + " + offsetName + ");");
                    sw.WriteLine(indent + "\t\t\t*raw_ptr = " + table.ToNativeReturn(ctype, "value") + ";");
                }
                sw.WriteLine(indent + "\t\t}");
                sw.WriteLine(indent + "\t}");
            }

            sw.WriteLine(indent + "}");
            sw.WriteLine("");

            if (getterName != null || setterName != null || getOffsetName != null)
            {
                GenerateGlue(gen_info);
            }
        }
Exemple #2
0
        public void Generate(GenerationInfo gen_info, string indent, ClassBase implementor)
        {
            SymbolTable  table = SymbolTable.Table;
            StreamWriter sw    = gen_info.Writer;

            if (Hidden || (!Readable && !Writable))
            {
                return;
            }

            string modifiers = "";

            if (IsNew || (container_type.Parent != null && container_type.Parent.GetPropertyRecursively(Name) != null))
            {
                modifiers = "new ";
            }
            else if (implementor != null && implementor.Parent != null && implementor.Parent.GetPropertyRecursively(Name) != null)
            {
                modifiers = "new ";
            }

            string name = Name;

            if (name == container_type.Name)
            {
                name += "Prop";
            }
            string qpname = "\"" + CName + "\"";

            string v_type = "";

            if (table.IsInterface(CType))
            {
                v_type = "(GLib.Object)";
            }
            else if (table.IsOpaque(CType))
            {
                v_type = "(GLib.Opaque)";
            }
            else if (table.IsEnum(CType))
            {
                v_type = "(Enum)";
            }

            GenerateImports(gen_info, indent);

            if (IsDeprecated ||
                (Getter != null && Getter.IsDeprecated) ||
                (Setter != null && Setter.IsDeprecated))
            {
                sw.WriteLine(indent + "[Obsolete]");
            }
            sw.WriteLine(indent + PropertyAttribute(qpname));
            sw.WriteLine(indent + "public " + modifiers + CSType + " " + name + " {");
            indent += "\t";

            if (Getter != null)
            {
                sw.Write(indent + "get ");
                Getter.GenerateBody(gen_info, implementor, "\t");
                sw.WriteLine();
            }
            else if (Readable)
            {
                sw.WriteLine(indent + "get {");
                sw.WriteLine(indent + "\tGLib.Value val = " + RawGetter(qpname) + ";");
                if (table.IsOpaque(CType) || table.IsBoxed(CType))
                {
                    sw.WriteLine(indent + "\t" + CSType + " ret = (" + CSType + ") val;");
                }
                else if (table.IsInterface(CType))
                {
                    // Do we have to dispose the GLib.Object from the GLib.Value?
                    sw.WriteLine(indent + "\t{0} ret = {0}Adapter.GetObject ((GLib.Object) val);", CSType);
                }
                else
                {
                    sw.Write(indent + "\t" + CSType + " ret = ");
                    sw.Write("(" + CSType + ") ");
                    if (v_type != "")
                    {
                        sw.Write(v_type + " ");
                    }
                    sw.WriteLine("val;");
                }

                sw.WriteLine(indent + "\tval.Dispose ();");
                sw.WriteLine(indent + "\treturn ret;");
                sw.WriteLine(indent + "}");
            }

            if (Setter != null)
            {
                sw.Write(indent + "set ");
                Setter.GenerateBody(gen_info, implementor, "\t");
                sw.WriteLine();
            }
            else if (Writable)
            {
                sw.WriteLine(indent + "set {");
                sw.Write(indent + "\tGLib.Value val = ");
                if (table.IsBoxed(CType))
                {
                    sw.WriteLine("(GLib.Value) value;");
                }
                else if (table.IsOpaque(CType))
                {
                    sw.WriteLine("new GLib.Value(value, \"{0}\");", CType);
                }
                else
                {
                    sw.Write("new GLib.Value(");
                    if (v_type != "" && !(table.IsObject(CType) || table.IsInterface(CType) || table.IsOpaque(CType)))
                    {
                        sw.Write(v_type + " ");
                    }
                    sw.WriteLine("value);");
                }
                sw.WriteLine(indent + "\t" + RawSetter(qpname) + ";");
                sw.WriteLine(indent + "\tval.Dispose ();");
                sw.WriteLine(indent + "}");
            }

            sw.WriteLine(indent.Substring(1) + "}");
            sw.WriteLine();

            Statistics.PropCount++;
        }
Exemple #3
0
        public virtual void Generate(GenerationInfo gen_info, string indent)
        {
            if (Ignored || Hidden)
            {
                return;
            }

            CheckGlue();
            if ((getterName != null || setterName != null || getOffsetName != null) && gen_info.GlueWriter == null)
            {
                LogWriter log = new LogWriter(container_type.QualifiedName);
                log.Member = Name;
                log.Warn("needs glue for field access.  Specify --glue-filename");
                return;
            }

            GenerateImports(gen_info, indent);

            SymbolTable  table     = SymbolTable.Table;
            StreamWriter sw        = gen_info.Writer;
            string       modifiers = elem.HasAttribute("new_flag") ? "new " : "";
            bool         is_struct = table.IsStruct(CType) || table.IsBoxed(CType);

            sw.WriteLine(indent + "public " + modifiers + CSType + " " + Name + " {");

            if (Getter != null)
            {
                sw.Write(indent + "\tget ");
                Getter.GenerateBody(gen_info, container_type, "\t");
                sw.WriteLine("");
            }
            else if (getterName != null)
            {
                sw.WriteLine(indent + "\tget {");
                container_type.Prepare(sw, indent + "\t\t");
                sw.WriteLine(indent + "\t\t" + CSType + " result = " + table.FromNative(ctype, getterName + " (" + container_type.CallByName() + ")") + ";");
                container_type.Finish(sw, indent + "\t\t");
                sw.WriteLine(indent + "\t\treturn result;");
                sw.WriteLine(indent + "\t}");
            }
            else if (Readable && offsetName != null)
            {
                sw.WriteLine(indent + "\tget {");
                sw.WriteLine(indent + "\t\tunsafe {");
                if (is_struct)
                {
                    sw.WriteLine(indent + "\t\t\t" + CSType + "* raw_ptr = (" + CSType + "*)(((byte*)" + container_type.CallByName() + ") + " + offsetName + ");");
                    sw.WriteLine(indent + "\t\t\treturn *raw_ptr;");
                }
                else
                {
                    sw.WriteLine(indent + "\t\t\t" + table.GetMarshalType(CType) + "* raw_ptr = (" + table.GetMarshalType(CType) + "*)(((byte*)" + container_type.CallByName() + ") + " + offsetName + ");");
                    sw.WriteLine(indent + "\t\t\treturn " + table.FromNative(ctype, "(*raw_ptr)") + ";");
                }
                sw.WriteLine(indent + "\t\t}");
                sw.WriteLine(indent + "\t}");
            }

            IGeneratable gen       = table [CType];
            string       to_native = (gen is IManualMarshaler) ? (gen as IManualMarshaler).AllocNative("value") : gen.CallByName("value");

            if (Setter != null)
            {
                sw.Write(indent + "\tset ");
                Setter.GenerateBody(gen_info, container_type, "\t");
                sw.WriteLine("");
            }
            else if (setterName != null)
            {
                sw.WriteLine(indent + "\tset {");
                container_type.Prepare(sw, indent + "\t\t");
                sw.WriteLine(indent + "\t\t" + setterName + " (" + container_type.CallByName() + ", " + to_native + ");");
                container_type.Finish(sw, indent + "\t\t");
                sw.WriteLine(indent + "\t}");
            }
            else if (Writable && offsetName != null)
            {
                sw.WriteLine(indent + "\tset {");
                sw.WriteLine(indent + "\t\tunsafe {");
                if (is_struct)
                {
                    sw.WriteLine(indent + "\t\t\t" + CSType + "* raw_ptr = (" + CSType + "*)(((byte*)" + container_type.CallByName() + ") + " + offsetName + ");");
                    sw.WriteLine(indent + "\t\t\t*raw_ptr = value;");
                }
                else
                {
                    sw.WriteLine(indent + "\t\t\t" + table.GetMarshalType(CType) + "* raw_ptr = (" + table.GetMarshalType(CType) + "*)(((byte*)" + container_type.CallByName() + ") + " + offsetName + ");");
                    sw.WriteLine(indent + "\t\t\t*raw_ptr = " + to_native + ";");
                }
                sw.WriteLine(indent + "\t\t}");
                sw.WriteLine(indent + "\t}");
            }

            sw.WriteLine(indent + "}");
            sw.WriteLine("");

            if (getterName != null || setterName != null || getOffsetName != null)
            {
                GenerateGlue(gen_info);
            }
        }