コード例 #1
0
        public override void Generate(GenerationInfo gen_info, string indent)
        {
            if (Hidden)
            {
                return;
            }

            StreamWriter sw    = gen_info.Writer;
            SymbolTable  table = SymbolTable.Table;

            string       wrapped      = table.GetCSType(CType);
            string       wrapped_name = SymbolTable.Table.MangleName(CName);
            IGeneratable gen          = table [CType];

            if (IsArray)
            {
                sw.WriteLine(indent + "[MarshalAs (UnmanagedType.ByValArray, SizeConst=" + ArrayLength + ")]");
                sw.WriteLine(indent + "{0} {1} {2};", Access, CSType, StudlyName);
            }
            else if (IsBitfield)
            {
                base.Generate(gen_info, indent);
            }
            else if (gen is IAccessor)
            {
                sw.WriteLine(indent + "private {0} {1};", gen.MarshalType, Name);

                if (Access != "private")
                {
                    IAccessor acc = table [CType] as IAccessor;
                    sw.WriteLine(indent + Access + " " + wrapped + " " + StudlyName + " {");
                    acc.WriteAccessors(sw, indent + "\t", Name);
                    sw.WriteLine(indent + "}");
                }
            }
            else if (IsPointer && (gen is StructGen || gen is BoxedGen))
            {
                sw.WriteLine(indent + "private {0} {1};", CSType, Name);
                sw.WriteLine();
                if (Access != "private")
                {
                    sw.WriteLine(indent + Access + " " + wrapped + " " + wrapped_name + " {");
                    sw.WriteLine(indent + "\tget { return " + table.FromNativeReturn(CType, Name) + "; }");
                    sw.WriteLine(indent + "}");
                }
            }
            else if (IsPointer && CSType != "string")
            {
                // FIXME: probably some fields here which should be visible.
                sw.WriteLine(indent + "private {0} {1};", CSType, Name);
            }
            else
            {
                sw.WriteLine(indent + "{0} {1} {2};", Access, CSType, Access == "public" ? StudlyName : Name);
            }
        }
コード例 #2
0
ファイル: FieldBase.cs プロジェクト: Dynalon/clutter-sharp
        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);
            }
        }