示例#1
0
		public Ctor (XmlElement elem, ClassBase implementor) : base (elem, implementor)
		{
			preferred = elem.GetAttributeAsBoolean ("preferred");
			if (implementor is ObjectGen)
				needs_chaining = true;
			name = implementor.Name;
		}
示例#2
0
		public VirtualMethod (XmlElement elem, ClassBase container_type) : base (elem, container_type)
		{
			this.elem = elem;
			retval = new ReturnValue (elem ["return-type"]);
			parms = new Parameters (elem["parameters"]);
			parms.HideData = true;
		}
示例#3
0
		public Ctor (XmlElement elem, ClassBase implementor) : base (elem, implementor) 
		{
			if (elem.HasAttribute ("preferred"))
				preferred = true;
			if (implementor is ObjectGen)
				needs_chaining = true;
			name = implementor.Name;
		}
示例#4
0
		/* Creates a callback method which invokes the corresponding virtual method
		* @implementor is the class that implements the virtual method(e.g. the class that derives from an interface) or NULL if containing and declaring type are equal
		*/
		public void GenerateCallback (StreamWriter sw, ClassBase implementor)
		{
			if (!Validate ())
				return;

			string native_signature = "";
			if (!IsStatic) {
				native_signature += "IntPtr inst";
				if (parms.Count > 0)
					native_signature += ", ";
			}
			if (parms.Count > 0)
				native_signature += parms.ImportSignature;

			sw.WriteLine ("\t\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
			sw.WriteLine ("\t\tdelegate {0} {1}NativeDelegate ({2});", retval.ToNativeType, this.Name, native_signature);
			sw.WriteLine ();
			sw.WriteLine ("\t\tstatic {0} {1}_cb ({2})", retval.ToNativeType, this.Name, native_signature);
			sw.WriteLine ("\t\t{");
			string unconditional = call.Unconditional ("\t\t\t");
			if (unconditional.Length > 0)
				sw.WriteLine (unconditional);
			sw.WriteLine ("\t\t\ttry {");

			if (!this.IsStatic) {
				string type;
				if (implementor != null)
					type = implementor.QualifiedName;
				else if (this.container_type is InterfaceGen)
					type = this.container_type.Name + "Implementor"; // We are in an interface/adaptor, invoke the method in the implementor class
				else
					type = this.container_type.Name;

				sw.WriteLine ("\t\t\t\t{0} __obj = Gst.GLib.Object.GetObject (inst, false) as {0};", type);
			}

			sw.Write (call.Setup ("\t\t\t\t"));
			sw.Write ("\t\t\t\t");
			if (!retval.IsVoid)
				sw.Write (retval.CSType + " __result = ");
			if (!this.IsStatic)
				sw.Write ("__obj.");
			sw.WriteLine (this.CallString + ";");
			sw.Write (call.Finish ("\t\t\t\t"));
			if (!retval.IsVoid)
				sw.WriteLine ("\t\t\t\treturn " + retval.ToNative ("__result") + ";");

			bool fatal = parms.HasOutParam || !retval.IsVoid;
			sw.WriteLine ("\t\t\t} catch (Exception e) {");
			sw.WriteLine ("\t\t\t\tGst.GLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");
			if (fatal) {
				sw.WriteLine ("\t\t\t\t// NOTREACHED: above call does not return.");
				sw.WriteLine ("\t\t\t\tthrow e;");
			}
			sw.WriteLine ("\t\t\t}");
			sw.WriteLine ("\t\t}");
			sw.WriteLine ();
		}
示例#5
0
文件: Signal.cs 项目: rubenv/tripod
		public Signal (XmlElement elem, ClassBase container_type)
		{
			this.elem = elem;
			name = elem.GetAttribute ("name");
			marshaled = elem.GetAttribute ("manual") == "true";
			retval = new ReturnValue (elem ["return-type"]);
			parms = new Parameters (elem["parameters"]);
			this.container_type = container_type;
		}
示例#6
0
		public Method (XmlElement elem, ClassBase container_type) : base (elem, container_type)
		{
			this.retval = new ReturnValue (elem["return-type"]);
			
			if (!container_type.IsDeprecated) {
				deprecated = elem.GetAttributeAsBoolean ("deprecated");
			}
			
			if (Name == "GetType")
				Name = "GetGType";
		}
示例#7
0
文件: Method.cs 项目: rubenv/tripod
		public Method (XmlElement elem, ClassBase container_type) : base (elem, container_type)
		{
			this.retval = new ReturnValue (elem["return-type"]);
			
			if (!container_type.IsDeprecated && elem.HasAttribute ("deprecated")) {
				string attr = elem.GetAttribute ("deprecated");
				deprecated = attr == "1" || attr == "true";
			}
			
			if (Name == "GetType")
				Name = "GetGType";
		}
示例#8
0
文件: Method.cs 项目: shana/gtk-sharp
        public Method(XmlElement elem, ClassBase container_type) : base(elem, container_type)
        {
            this.retval = new ReturnValue(elem["return-type"]);

            if (!container_type.IsDeprecated && elem.HasAttribute("deprecated"))
            {
                string attr = elem.GetAttribute("deprecated");
                deprecated = attr == "1" || attr == "true";
            }

            if (elem.HasAttribute("win32_utf8_variant"))
            {
                string attr = elem.GetAttribute("win32_utf8_variant");
                win32_utf8_variant = attr == "1" || attr.ToLower() == "true";
            }

            if (Name == "GetType")
            {
                Name = "GetGType";
            }
        }
示例#9
0
 protected MethodBase(XmlElement elem, ClassBase container_type)
 {
     this.elem = elem;
     this.container_type = container_type;
     this.name = elem.GetAttribute ("name");
     parms = new Parameters (elem ["parameters"]);
     IsStatic = elem.GetAttribute ("shared") == "true";
     if (elem.HasAttribute ("new_flag"))
         mods = "new ";
     if (elem.HasAttribute ("accessibility")) {
         string attr = elem.GetAttribute ("accessibility");
         switch (attr) {
             case "public":
             case "protected":
             case "internal":
             case "private":
             case "protected internal":
                 protection = attr;
                 break;
         }
     }
 }
        public void Generate(GenerationInfo gen_info, ClassBase implementor)
        {
            StreamWriter sw = gen_info.Writer;

            if (implementor == null)
            {
                GenEventHandler(gen_info);
            }

            GenDefaultHandlerDelegate(gen_info, implementor);
            if (gen_info.GlueEnabled && implementor == null && ClassFieldName.Length > 0)
            {
                GenGlueVirtualMethod(gen_info);
            }
            else
            {
                GenChainVirtualMethod(sw, implementor);
            }
            GenEvent(sw, implementor, "this");

            Statistics.SignalCount++;
        }
示例#11
0
		protected MethodBase (XmlElement elem, ClassBase container_type) 
		{
			this.elem = elem;
			this.container_type = container_type;
			this.name = elem.GetAttribute ("name");
			parms = new Parameters (elem ["parameters"]);
			IsStatic = elem.GetAttribute ("shared") == "true";
			if (elem.HasAttribute ("new_flag"))
				mods = "new ";
			if (elem.HasAttribute ("accessibility")) {
				string attr = elem.GetAttribute ("accessibility");
				switch (attr) {
					case "public":
					case "protected":
					case "internal":
					case "private":
					case "protected internal":
						protection = attr;
						break;
				}
			}
		}
示例#12
0
文件: Signal.cs 项目: rubenv/tripod
		public void GenEvent (StreamWriter sw, ClassBase implementor, string target)
		{
			string args_type = IsEventHandler ? "" : ", typeof (" + EventArgsQualifiedName + ")";
			
			if (Marshaled) {
				GenCallback (sw);
				args_type = ", new " + DelegateName + "(" + CallbackName + ")";
			}

			sw.WriteLine("\t\t[GLib.Signal("+ CName + ")]");
			sw.Write("\t\tpublic ");
			if (NeedNew (implementor))
				sw.Write("new ");
			sw.WriteLine("event " + EventHandlerQualifiedName + " " + Name + " {");
			sw.WriteLine("\t\t\tadd {");
			sw.WriteLine("\t\t\t\tGLib.Signal sig = GLib.Signal.Lookup (" + target + ", " + CName + args_type + ");");
			sw.WriteLine("\t\t\t\tsig.AddDelegate (value);");
			sw.WriteLine("\t\t\t}");
			sw.WriteLine("\t\t\tremove {");
			sw.WriteLine("\t\t\t\tGLib.Signal sig = GLib.Signal.Lookup (" + target + ", " + CName + args_type + ");");
			sw.WriteLine("\t\t\t\tsig.RemoveDelegate (value);");
			sw.WriteLine("\t\t\t}");
			sw.WriteLine("\t\t}");
			sw.WriteLine();
		}
示例#13
0
		/* Creates a callback method which invokes the corresponding virtual method
		* @implementor is the class that implements the virtual method(e.g. the class that derives from an interface) or NULL if containing and declaring type are equal
		*/
		public void GenerateCallback (StreamWriter sw, ClassBase implementor)
		{
			LogWriter log = new LogWriter ();
			log.Type = container_type.QualifiedName;
			if (!Validate (log))
				return;

			string native_signature = "";
			if (!IsStatic) {
				native_signature += "IntPtr inst";
				if (parms.Count > 0)
					native_signature += ", ";
			}
			if (parms.Count > 0)
				native_signature += parms.ImportSignature;

			sw.WriteLine ("\t\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
			sw.WriteLine ("\t\tdelegate {0} {1}NativeDelegate ({2});", retval.ToNativeType, this.Name, native_signature);
			sw.WriteLine ();
			sw.WriteLine ("\t\tstatic {0} {1}_cb ({2})", retval.ToNativeType, this.Name, native_signature);
			sw.WriteLine ("\t\t{");
			string unconditional = call.Unconditional ("\t\t\t");
			if (unconditional.Length > 0)
				sw.WriteLine (unconditional);
			sw.WriteLine ("\t\t\ttry {");

			if (!this.IsStatic) {
				string type;
				if (implementor != null)
					type = implementor.QualifiedName;
				else if (this.container_type is InterfaceGen)
					// We are in an interface/adaptor, invoke the method in the implementor class
					type = (this.container_type as InterfaceGen).ImplementorName;
				else
					type = this.container_type.Name;

				sw.WriteLine ("\t\t\t\t{0} __obj = GLib.Object.GetObject (inst, false) as {0};", type);
			}

			string indent = "\t\t\t\t";
			if (!retval.IsVoid)
				sw.WriteLine (indent + retval.CSType + " __result;");
			sw.Write (call.Setup (indent));
			sw.Write (indent);
			if (!retval.IsVoid)
				sw.Write ("__result = ");
			if (!this.IsStatic)
				sw.Write ("__obj.");
			sw.WriteLine (this.CallString + ";");
			sw.Write (call.Finish (indent));
			if (!retval.IsVoid)
				sw.WriteLine ("\t\t\t\treturn " + retval.ToNative ("__result") + ";");

			bool fatal = parms.HasOutParam || !retval.IsVoid;
			sw.WriteLine ("\t\t\t} catch (Exception e) {");
			sw.WriteLine ("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");
			if (fatal) {
				sw.WriteLine ("\t\t\t\t// NOTREACHED: above call does not return.");
				sw.WriteLine ("\t\t\t\tthrow e;");
			}

			if (call.HasDisposeParam) {
				sw.WriteLine ("\t\t\t} finally {");
				sw.Write (call.DisposeParams (indent));
			}
			sw.WriteLine ("\t\t\t}");
			sw.WriteLine ("\t\t}");
			sw.WriteLine ();
		}
示例#14
0
		public FieldBase (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
示例#15
0
文件: Signal.cs 项目: rubenv/tripod
		private bool NeedNew (ClassBase implementor)
		{
			return elem.HasAttribute ("new_flag") ||
				(container_type != null && container_type.GetSignalRecursively (Name) != null) ||
				(implementor != null && implementor.GetSignalRecursively (Name) != null);
		}
示例#16
0
文件: Method.cs 项目: mono/gio-sharp
 private void GenerateDeclCommon(StreamWriter sw, ClassBase implementor)
 {
     GenerateDeclCommon (sw, implementor, false);
 }
示例#17
0
		protected bool IgnoreMethod (Method method, ClassBase implementor)
		{	
			if (implementor != null && implementor.QualifiedName != this.QualifiedName && method.IsStatic)
				return true;

			string mname = method.Name;
			return ((method.IsSetter || (method.IsGetter && mname.StartsWith("Get"))) &&
				((props != null) && props.ContainsKey(mname.Substring(3)) ||
				 (fields != null) && fields.ContainsKey(mname.Substring(3))));
		}
示例#18
0
 public PropertyBase(XmlElement elem, ClassBase container_type)
 {
     this.elem           = elem;
     this.container_type = container_type;
 }
示例#19
0
文件: Signal.cs 项目: rubenv/tripod
		private void GenChainVirtualMethod (StreamWriter sw, ClassBase implementor)
		{
			GenVMDeclaration (sw, implementor);
			sw.WriteLine ("\t\t{");
			if (IsVoid)
				sw.WriteLine ("\t\t\tGLib.Value ret = GLib.Value.Empty;");
			else
				sw.WriteLine ("\t\t\tGLib.Value ret = new GLib.Value (" + ReturnGType + ");");

			sw.WriteLine ("\t\t\tGLib.ValueArray inst_and_params = new GLib.ValueArray (" + parms.Count + ");");
			sw.WriteLine ("\t\t\tGLib.Value[] vals = new GLib.Value [" + parms.Count + "];");
			sw.WriteLine ("\t\t\tvals [0] = new GLib.Value (this);");
			sw.WriteLine ("\t\t\tinst_and_params.Append (vals [0]);");
			string cleanup = "";
			for (int i = 1; i < parms.Count; i++) {
				Parameter p = parms [i];
				if (p.PassAs != "") {
					if (SymbolTable.Table.IsBoxed (p.CType)) {
						if (p.PassAs == "ref")
							sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + p.Name + ");");
						else
							sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value ((GLib.GType)typeof (" + p.CSType + "));");
						cleanup += "\t\t\t" + p.Name + " = (" + p.CSType + ") vals [" + i + "];\n";
					} else {
						if (p.PassAs == "ref")
							sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = GLib.Marshaller.StructureToPtrAlloc (" + p.Generatable.CallByName (p.Name) + ");");
						else
							sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + p.MarshalType + ")));");

						sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + p.Name + "_ptr);");
						cleanup += "\t\t\t" + p.Name + " = " + p.FromNative ("(" + p.MarshalType + ") Marshal.PtrToStructure (" + p.Name + "_ptr, typeof (" + p.MarshalType + "))") + ";\n";
						cleanup += "\t\t\tMarshal.FreeHGlobal (" + p.Name + "_ptr);\n";
					}
				} else if (p.IsLength && parms [i - 1].IsString)
					sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (System.Text.Encoding.UTF8.GetByteCount (" + parms [i-1].Name + "));");
				else
					sw.WriteLine ("\t\t\tvals [" + i + "] = new GLib.Value (" + p.Name + ");");

				sw.WriteLine ("\t\t\tinst_and_params.Append (vals [" + i + "]);");
			}

			sw.WriteLine ("\t\t\tg_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);");
			if (cleanup != "")
				sw.WriteLine (cleanup);
			sw.WriteLine ("\t\t\tforeach (GLib.Value v in vals)");
			sw.WriteLine ("\t\t\t\tv.Dispose ();");
			if (!IsVoid) {
				IGeneratable igen = SymbolTable.Table [retval.CType];
				sw.WriteLine ("\t\t\t" + retval.CSType + " result = (" + (igen is EnumGen ? retval.CSType + ") (Enum" : retval.CSType) + ") ret;");
				sw.WriteLine ("\t\t\tret.Dispose ();");
				sw.WriteLine ("\t\t\treturn result;");
			}
			sw.WriteLine ("\t\t}\n");
		}
示例#20
0
		public void GenProperties (GenerationInfo gen_info, ClassBase implementor)
		{		
			if (props.Count == 0)
				return;

			foreach (Property prop in props.Values)
				prop.Generate (gen_info, "\t\t", implementor);
		}
示例#21
0
		public ObjectField (XmlElement elem, ClassBase container_type) : base (elem, container_type)
		{
			if (CType == "char*" || CType == "gchar*")
				ctype = "const-" + CType;
		}
        public void GenSignals(GenerationInfo gen_info, ClassBase implementor)
        {
            if (sigs == null)
                return;

            foreach (Signal sig in sigs.Values)
                sig.Generate (gen_info, implementor);
        }
示例#23
0
文件: Signal.cs 项目: rubenv/tripod
		public void Generate (GenerationInfo gen_info, ClassBase implementor)
		{
			StreamWriter sw = gen_info.Writer;

			if (implementor == null)
				GenEventHandler (gen_info);

			GenDefaultHandlerDelegate (gen_info, implementor);
			if (gen_info.GlueEnabled && implementor == null && ClassFieldName.Length > 0)
				GenGlueVirtualMethod (gen_info);
			else
				GenChainVirtualMethod (sw, implementor);
			GenEvent (sw, implementor, "this");
			
			Statistics.SignalCount++;
		}
示例#24
0
 private void GenerateDeclCommon(StreamWriter sw, ClassBase implementor)
 {
     GenerateDeclCommon(sw, implementor, false);
 }
示例#25
0
		public void GenMethods (GenerationInfo gen_info, IDictionary<string, bool> collisions, ClassBase implementor)
		{
			if (methods == null)
				return;

			foreach (Method method in methods.Values) {
				if (IgnoreMethod (method, implementor))
				    	continue;

				string oname = null, oprotection = null;
				if (collisions != null && collisions.ContainsKey (method.Name)) {
					oname = method.Name;
					oprotection = method.Protection;
					method.Name = QualifiedName + "." + method.Name;
					method.Protection = "";
				}
				method.Generate (gen_info, implementor);
				if (oname != null) {
					method.Name = oname;
					method.Protection = oprotection;
				}
			}
		}
示例#26
0
文件: Signal.cs 项目: rubenv/tripod
		private void GenVMDeclaration (StreamWriter sw, ClassBase implementor)
		{
			VMSignature vmsig = new VMSignature (parms);
			sw.WriteLine ("\t\t[GLib.DefaultSignalHandler(Type=typeof(" + (implementor != null ? implementor.QualifiedName : container_type.QualifiedName) + "), ConnectionMethod=\"Override" + Name +"\")]");
			sw.Write ("\t\tprotected ");
			if (NeedNew (implementor))
				sw.Write ("new ");
			sw.WriteLine ("virtual {0} {1} ({2})", retval.CSType, "On" + Name, vmsig.ToString ());
		}
示例#27
0
		public void GenerateBody (GenerationInfo gen_info, ClassBase implementor, string indent)
		{
			StreamWriter sw = gen_info.Writer;
			sw.WriteLine(" {");
			if (!IsStatic && implementor != null)
				implementor.Prepare (sw, indent + "\t\t\t");
			if (IsAccessor)
				Body.InitAccessor (sw, Signature, indent);
			Body.Initialize(gen_info, is_get, is_set, indent);

			if (HasWin32Utf8Variant) {
				if (!retval.IsVoid)
					sw.WriteLine(indent + "\t\t\t" + retval.MarshalType + " raw_ret;");
				sw.WriteLine(indent + "\t\t\t" + "if (Environment.OSVersion.Platform == PlatformID.Win32NT ||");
				sw.WriteLine(indent + "\t\t\t" + "    Environment.OSVersion.Platform == PlatformID.Win32S ||");
				sw.WriteLine(indent + "\t\t\t" + "    Environment.OSVersion.Platform == PlatformID.Win32Windows ||");
				sw.WriteLine(indent + "\t\t\t" + "    Environment.OSVersion.Platform == PlatformID.WinCE)");
				if (retval.IsVoid) {
					sw.WriteLine(indent + "\t\t\t\t" + CName + "_utf8" + call + ";");
					sw.WriteLine(indent + "\t\t\t" + "else");
					sw.WriteLine(indent + "\t\t\t\t" + CName + call + ";");
				} else {
					sw.WriteLine(indent + "\t\t\t\traw_ret = " + CName + "_utf8" + call + ";");
					sw.WriteLine(indent + "\t\t\t" + "else");
					sw.WriteLine(indent + "\t\t\t\traw_ret = " + CName + call + ";");
					sw.WriteLine(indent + "\t\t\t" + retval.CSType + " ret = " + retval.FromNative ("raw_ret") + ";");
				}
			} else {
				sw.Write(indent + "\t\t\t");
				if (retval.IsVoid)
					sw.WriteLine(CName + call + ";");
				else {
					sw.WriteLine(retval.MarshalType + " raw_ret = " + CName + call + ";");
					sw.WriteLine(indent + "\t\t\t" + retval.CSType + " ret = " + retval.FromNative ("raw_ret") + ";");
				}
			}

			if (!IsStatic && implementor != null)
				implementor.Finish (sw, indent + "\t\t\t");
			Body.Finish (sw, indent);
			Body.HandleException (sw, indent);

			if (is_get && Parameters.Count > 0) 
				sw.WriteLine (indent + "\t\t\treturn " + Parameters.AccessorName + ";");
			else if (!retval.IsVoid)
				sw.WriteLine (indent + "\t\t\treturn ret;");
			else if (IsAccessor)
				Body.FinishAccessor (sw, Signature, indent);

			sw.Write(indent + "\t\t}");
		}
示例#28
0
文件: Method.cs 项目: shana/gtk-sharp
        public void GenerateBody(GenerationInfo gen_info, ClassBase implementor, string indent)
        {
            StreamWriter sw = gen_info.Writer;

            sw.WriteLine(" {");
            if (!IsStatic && implementor != null)
            {
                implementor.Prepare(sw, indent + "\t\t\t");
            }
            if (IsAccessor)
            {
                Body.InitAccessor(sw, Signature, indent);
            }
            Body.Initialize(gen_info, is_get, is_set, indent);

            if (HasWin32Utf8Variant)
            {
                if (!retval.IsVoid)
                {
                    sw.WriteLine(indent + "\t\t\t" + retval.MarshalType + " raw_ret;");
                }
                sw.WriteLine(indent + "\t\t\t" + "if (Environment.OSVersion.Platform == PlatformID.Win32NT ||");
                sw.WriteLine(indent + "\t\t\t" + "    Environment.OSVersion.Platform == PlatformID.Win32S ||");
                sw.WriteLine(indent + "\t\t\t" + "    Environment.OSVersion.Platform == PlatformID.Win32Windows ||");
                sw.WriteLine(indent + "\t\t\t" + "    Environment.OSVersion.Platform == PlatformID.WinCE)");
                if (retval.IsVoid)
                {
                    sw.WriteLine(indent + "\t\t\t\t" + CName + "_utf8" + call + ";");
                    sw.WriteLine(indent + "\t\t\t" + "else");
                    sw.WriteLine(indent + "\t\t\t\t" + CName + call + ";");
                }
                else
                {
                    sw.WriteLine(indent + "\t\t\t\traw_ret = " + CName + "_utf8" + call + ";");
                    sw.WriteLine(indent + "\t\t\t" + "else");
                    sw.WriteLine(indent + "\t\t\t\traw_ret = " + CName + call + ";");
                    sw.WriteLine(indent + "\t\t\t" + retval.CSType + " ret = " + retval.FromNative("raw_ret") + ";");
                }
            }
            else
            {
                sw.Write(indent + "\t\t\t");
                if (retval.IsVoid)
                {
                    sw.WriteLine(CName + call + ";");
                }
                else
                {
                    sw.WriteLine(retval.MarshalType + " raw_ret = " + CName + call + ";");
                    sw.WriteLine(indent + "\t\t\t" + retval.CSType + " ret = " + retval.FromNative("raw_ret") + ";");
                }
            }

            if (!IsStatic && implementor != null)
            {
                implementor.Finish(sw, indent + "\t\t\t");
            }
            Body.Finish(sw, indent);
            Body.HandleException(sw, indent);

            if (is_get && Parameters.Count > 0)
            {
                sw.WriteLine(indent + "\t\t\treturn " + Parameters.AccessorName + ";");
            }
            else if (!retval.IsVoid)
            {
                sw.WriteLine(indent + "\t\t\treturn ret;");
            }
            else if (IsAccessor)
            {
                Body.FinishAccessor(sw, Signature, indent);
            }

            sw.Write(indent + "\t\t}");
        }
示例#29
0
        public void Generate(GenerationInfo gen_info, ClassBase implementor)
        {
            if (!Validate ())
                return;

            Method comp = null;

            gen_info.CurrentMember = Name;

            /* we are generated by the get Method, if there is one */
            if (is_set || is_get)
            {
                if (Modifiers != "new " && container_type.GetPropertyRecursively (Name.Substring (3)) != null)
                    return;
                comp = GetComplement ();
                if (comp != null && is_set) {
                    if (Parameters.AccessorReturnType == comp.ReturnType)
                        return;
                    else {
                        is_set = false;
                        call = "(Handle, " + Body.GetCallString (false) + ")";
                        comp = null;
                    }
                }
                /* some setters take more than one arg */
                if (comp != null && !comp.is_set)
                    comp = null;
            }

            GenerateImport (gen_info.Writer);
            if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType)
                comp.GenerateImport (gen_info.Writer);

            if (IsDeprecated)
                gen_info.Writer.WriteLine("\t\t[Obsolete]");
            gen_info.Writer.Write("\t\t");
            if (Protection != "")
                gen_info.Writer.Write("{0} ", Protection);
            GenerateDeclCommon (gen_info.Writer, implementor);

            if (is_get || is_set)
            {
                gen_info.Writer.Write ("\t\t\t");
                gen_info.Writer.Write ((is_get) ? "get" : "set");
                GenerateBody (gen_info, implementor, "\t");
            }
            else
                GenerateBody (gen_info, implementor, "");

            if (is_get || is_set)
            {
                if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType)
                {
                    gen_info.Writer.WriteLine ();
                    gen_info.Writer.Write ("\t\t\tset");
                    comp.GenerateBody (gen_info, implementor, "\t");
                }
                gen_info.Writer.WriteLine ();
                gen_info.Writer.WriteLine ("\t\t}");
            }
            else
                gen_info.Writer.WriteLine();

            gen_info.Writer.WriteLine();

            Statistics.MethodCount++;
        }
示例#30
0
        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++;
        }
示例#31
0
        private void GenerateDeclCommon(StreamWriter sw, ClassBase implementor)
        {
            if (IsStatic)
                sw.Write("static ");
            sw.Write (Safety);
            Method dup = null;
            if (container_type != null)
                dup = container_type.GetMethodRecursively (Name);
            if (implementor != null)
                dup = implementor.GetMethodRecursively (Name);

            if (Name == "ToString" && Parameters.Count == 0)
                sw.Write("override ");
            else if (Name == "GetGType" && container_type is ObjectGen)
                sw.Write("new ");
            else if (Modifiers == "new " || (dup != null && ((dup.Signature != null && Signature != null && dup.Signature.ToString() == Signature.ToString()) || (dup.Signature == null && Signature == null))))
                sw.Write("new ");

            if (is_get || is_set) {
                if (retval.IsVoid)
                    sw.Write (Parameters.AccessorReturnType);
                else
                    sw.Write(retval.CSType);
                sw.Write(" ");
                if (Name.StartsWith ("Get") || Name.StartsWith ("Set"))
                    sw.Write (Name.Substring (3));
                else {
                    int dot = Name.LastIndexOf ('.');
                    if (dot != -1 && (Name.Substring (dot + 1, 3) == "Get" || Name.Substring (dot + 1, 3) == "Set"))
                        sw.Write (Name.Substring (0, dot + 1) + Name.Substring (dot + 4));
                    else
                        sw.Write (Name);
                }
                sw.WriteLine(" { ");
            } else if (IsAccessor) {
                sw.Write (Signature.AccessorType + " " + Name + "(" + Signature.AsAccessor + ")");
            } else {
                sw.Write(retval.CSType + " " + Name + "(" + (Signature != null ? Signature.ToString() : "") + ")");
            }
        }
示例#32
0
		public ChildProperty (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
示例#33
0
 protected void GenerateMethodBody(StreamWriter sw, ClassBase implementor)
 {
     sw.WriteLine ("\t\t[GLib.DefaultSignalHandler(Type=typeof(" + (implementor != null ? implementor.QualifiedName : container_type.QualifiedName) + "), ConnectionMethod=\"Override" + this.Name +"\")]");
     sw.Write ("\t\t{0} ", this.Protection);
     if (this.modifiers != "")
         sw.Write ("{0} ", this.modifiers);
     sw.WriteLine ("virtual {0} On{1} ({2})", retval.CSType, this.Name, Signature.ToString ());
     sw.WriteLine ("\t\t{");
     sw.WriteLine ("\t\t\t{0}Internal{1} ({2});", retval.IsVoid ? "" : "return ", this.Name, Signature.GetCallString (false));
     sw.WriteLine ("\t\t}");
     sw.WriteLine ();
     // This method is to be invoked from existing VM implementations in the custom code
     sw.WriteLine ("\t\tprivate {0} Internal{1} ({2})", retval.CSType, this.Name, Signature.ToString ());
     sw.WriteLine ("\t\t{");
 }
示例#34
0
 public MethodABIField(XmlElement elem, ClassBase container_type, string info_name) :
     base(elem, container_type, info_name)
 {
     Elem     = elem;
     is_valid = true;
 }
示例#35
0
 public Property(XmlElement elem, ClassBase container_type) : base(elem, container_type)
 {
 }
示例#36
0
 public PropertyBase(XmlElement elem, ClassBase container_type)
 {
     this.elem = elem;
     this.container_type = container_type;
 }
示例#37
0
        public void Generate(GenerationInfo gen_info, ClassBase implementor)
        {
            Method comp = null;

            gen_info.CurrentMember = Name;

            /* we are generated by the get Method, if there is one */
            if (is_set || is_get)
            {
                if (Modifiers != "new " && container_type.GetPropertyRecursively(Name.Substring(3)) != null)
                {
                    return;
                }
                comp = GetComplement();
                if (comp != null && is_set)
                {
                    if (Parameters.AccessorReturnType == comp.ReturnType)
                    {
                        return;
                    }
                    else
                    {
                        is_set = false;
                        call   = "(" + (IsStatic ? "" : container_type.CallByName() + (parms.Count > 0 ? ", " : "")) + Body.GetCallString(false) + ")";
                        comp   = null;
                    }
                }
                /* some setters take more than one arg */
                if (comp != null && !comp.is_set)
                {
                    comp = null;
                }
            }

            GenerateImport(gen_info.Writer);
            if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType)
            {
                comp.GenerateImport(gen_info.Writer);
            }

            if (IsDeprecated)
            {
                gen_info.Writer.WriteLine("\t\t[Obsolete]");
            }
            gen_info.Writer.Write("\t\t");
            if (Protection != "")
            {
                gen_info.Writer.Write("{0} ", Protection);
            }
            GenerateDeclCommon(gen_info.Writer, implementor);

            if (is_get || is_set)
            {
                gen_info.Writer.Write("\t\t\t");
                gen_info.Writer.Write((is_get) ? "get" : "set");
                GenerateBody(gen_info, implementor, "\t");
            }
            else
            {
                GenerateBody(gen_info, implementor, "");
            }

            if (is_get || is_set)
            {
                if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType)
                {
                    gen_info.Writer.WriteLine();
                    gen_info.Writer.Write("\t\t\tset");
                    comp.GenerateBody(gen_info, implementor, "\t");
                }
                gen_info.Writer.WriteLine();
                gen_info.Writer.WriteLine("\t\t}");
            }
            else
            {
                gen_info.Writer.WriteLine();
            }

            if (Parameters.HasOptional && !(is_get || is_set))
            {
                GenerateOverloads(gen_info.Writer);
            }

            gen_info.Writer.WriteLine();

            Statistics.MethodCount++;
        }
示例#38
0
        /* Creates a callback method which invokes the corresponding virtual method
         * @implementor is the class that implements the virtual method(e.g. the class that derives from an interface) or NULL if containing and declaring type are equal
         */
        public void GenerateCallback(StreamWriter sw, ClassBase implementor)
        {
            if (!Validate())
            {
                return;
            }

            string native_signature = "";

            if (!IsStatic)
            {
                native_signature += "IntPtr inst";
                if (parms.Count > 0)
                {
                    native_signature += ", ";
                }
            }
            if (parms.Count > 0)
            {
                native_signature += parms.ImportSignature;
            }

            sw.WriteLine("\t\t[GLib.CDeclCallback]");
            sw.WriteLine("\t\tdelegate {0} {1}NativeDelegate ({2});", retval.ToNativeType, this.Name, native_signature);
            sw.WriteLine();
            sw.WriteLine("\t\tstatic {0} {1}_cb ({2})", retval.ToNativeType, this.Name, native_signature);
            sw.WriteLine("\t\t{");
            string unconditional = call.Unconditional("\t\t\t");

            if (unconditional.Length > 0)
            {
                sw.WriteLine(unconditional);
            }
            sw.WriteLine("\t\t\ttry {");

            if (!this.IsStatic)
            {
                string type;
                if (implementor != null)
                {
                    type = implementor.QualifiedName;
                }
                else if (this.container_type is InterfaceGen)
                {
                    type = this.container_type.Name + "Implementor";                     // We are in an interface/adaptor, invoke the method in the implementor class
                }
                else
                {
                    type = this.container_type.Name;
                }

                sw.WriteLine("\t\t\t\t{0} __obj = GLib.Object.GetObject (inst, false) as {0};", type);
            }

            sw.Write(call.Setup("\t\t\t\t"));
            sw.Write("\t\t\t\t");
            if (!retval.IsVoid)
            {
                sw.Write(retval.CSType + " __result = ");
            }
            if (!this.IsStatic)
            {
                sw.Write("__obj.");
            }
            sw.WriteLine(this.CallString + ";");
            sw.Write(call.Finish("\t\t\t\t"));
            if (!retval.IsVoid)
            {
                sw.WriteLine("\t\t\t\treturn " + retval.ToNative("__result") + ";");
            }

            bool fatal = parms.HasOutParam || !retval.IsVoid;

            sw.WriteLine("\t\t\t} catch (Exception e) {");
            sw.WriteLine("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");
            if (fatal)
            {
                sw.WriteLine("\t\t\t\t// NOTREACHED: above call does not return.");
                sw.WriteLine("\t\t\t\tthrow e;");
            }
            sw.WriteLine("\t\t\t}");
            sw.WriteLine("\t\t}");
            sw.WriteLine();
        }
示例#39
0
文件: Signal.cs 项目: rubenv/tripod
		private void GenDefaultHandlerDelegate (GenerationInfo gen_info, ClassBase implementor)
		{
			StreamWriter sw = gen_info.Writer;
			StreamWriter glue;
			bool use_glue = gen_info.GlueEnabled && implementor == null && ClassFieldName.Length > 0;
			string glue_name = String.Empty;
			ManagedCallString call = new ManagedCallString (parms, true);
			sw.WriteLine ("\t\t[GLib.CDeclCallback]");
			sw.WriteLine ("\t\tdelegate " + retval.ToNativeType + " " + Name + "VMDelegate (" + parms.ImportSignature + ");\n");

			if (use_glue) {
				glue = gen_info.GlueWriter;
				glue_name = String.Format ("{0}sharp_{1}_override_{2}", container_type.NS.ToLower ().Replace (".", "_"), container_type.Name.ToLower (), ClassFieldName);
				sw.WriteLine ("\t\t[DllImport (\"{0}\")]", gen_info.GluelibName);
				sw.WriteLine ("\t\tstatic extern void {0} (IntPtr gtype, {1}VMDelegate cb);\n", glue_name, Name);
				glue.WriteLine ("void {0} (GType gtype, gpointer cb);\n", glue_name);
				glue.WriteLine ("void\n{0} (GType gtype, gpointer cb)", glue_name);
				glue.WriteLine ("{");
				glue.WriteLine ("\tGObjectClass *klass = g_type_class_peek (gtype);");
				glue.WriteLine ("\tif (klass == NULL)");
				glue.WriteLine ("\t\tklass = g_type_class_ref (gtype);");
				glue.WriteLine ("\t(({0} *)klass)->{1} = cb;", container_type.CName + "Class", ClassFieldName);
				glue.WriteLine ("}\n");
			}

			sw.WriteLine ("\t\tstatic {0} {1};\n", Name + "VMDelegate", Name + "VMCallback");
			sw.WriteLine ("\t\tstatic " + retval.ToNativeType + " " + Name.ToLower() + "_cb (" + parms.ImportSignature + ")");
			sw.WriteLine ("\t\t{");
			string unconditional = call.Unconditional ("\t\t\t");
			if (unconditional.Length > 0)
				sw.WriteLine (unconditional);
			sw.WriteLine ("\t\t\ttry {");
			sw.WriteLine ("\t\t\t\t{0} {1}_managed = GLib.Object.GetObject ({1}, false) as {0};", implementor != null ? implementor.Name : container_type.Name, parms[0].Name);
			sw.Write (call.Setup ("\t\t\t\t"));
			sw.Write ("\t\t\t\t{0}", IsVoid ? "" : retval.CSType == retval.ToNativeType ? "return " : retval.CSType + " raw_ret = ");
			sw.WriteLine ("{2}_managed.{0} ({1});", "On" + Name, call.ToString (), parms[0].Name);
			sw.Write (call.Finish ("\t\t\t\t"));
			if (!IsVoid && retval.CSType != retval.ToNativeType)
				sw.WriteLine ("\t\t\t\treturn {0};", SymbolTable.Table.ToNativeReturn (retval.CType, "raw_ret"));
			sw.WriteLine ("\t\t\t} catch (Exception e) {");
			bool fatal = HasOutParams || !IsVoid;
			sw.WriteLine ("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");
			if (fatal) {
				sw.WriteLine ("\t\t\t\t// NOTREACHED: above call doesn't return");
				sw.WriteLine ("\t\t\t\tthrow e;");
			}
			sw.WriteLine ("\t\t\t}");
			sw.WriteLine ("\t\t}\n");
			sw.WriteLine ("\t\tprivate static void Override" + Name + " (GLib.GType gtype)");
			sw.WriteLine ("\t\t{");
			sw.WriteLine ("\t\t\tif (" + Name + "VMCallback == null)");
			sw.WriteLine ("\t\t\t\t" + Name + "VMCallback = new " + Name + "VMDelegate (" + Name.ToLower() + "_cb);");
			if (use_glue)
				sw.WriteLine ("\t\t\t{0} (gtype.Val, {1}VMCallback);", glue_name, Name);
			else
				sw.WriteLine ("\t\t\tOverrideVirtualMethod (gtype, " + CName + ", " + Name + "VMCallback);");
			sw.WriteLine ("\t\t}\n");
		}
示例#40
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            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);

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Collections;");
            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 custom_attrs)
            {
                sw.WriteLine("\t" + attr);
            }
            sw.Write("\t{0} {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : "");
            string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));

            if (cs_parent != "")
            {
                di.objects.Add(CName, QualifiedName);
                sw.Write(" : " + cs_parent);
            }
            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)
                {
                    ClassBase igen = table.GetClassGen(iface);
                    if (igen != null && igen.Signals != null)
                    {
                        has_sigs = true;
                        break;
                    }
                }
            }

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

            if (vm_nodes.Count > 0)
            {
                if (gen_info.GlueEnabled)
                {
                    GenVirtualMethods(gen_info);
                }
                else
                {
                    Statistics.VMIgnored       = true;
                    Statistics.ThrottledCount += vm_nodes.Count;
                }
            }

            GenMethods(gen_info, null, null);

            if (interfaces.Count != 0)
            {
                Hashtable all_methods = new Hashtable();
                foreach (Method m in Methods.Values)
                {
                    all_methods[m.Name] = m;
                }
                Hashtable collisions = new Hashtable();
                foreach (string iface in interfaces)
                {
                    ClassBase igen = table.GetClassGen(iface);
                    foreach (Method m in igen.Methods.Values)
                    {
                        Method collision = all_methods[m.Name] as Method;
                        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;
                    }
                    ClassBase igen = table.GetClassGen(iface);
                    igen.GenMethods(gen_info, collisions, this);
                    igen.GenProperties(gen_info, this);
                    igen.GenSignals(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 (cs_parent != String.Empty && 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}");
            }

            sw.WriteLine("#endregion");
            AppendCustom(sw, gen_info.CustomDir);

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

            sw.Close();
            gen_info.Writer = null;
            Statistics.ObjectCount++;
        }
示例#41
0
文件: Property.cs 项目: jwzl/ossbuild
		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 = "(Gst.GLib.Object)";
			} else if (table.IsOpaque (CType)) {
				v_type = "(Gst.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 + "\tGst.GLib.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 Gst.GLib.Object from the Gst.GLib.Value?
					sw.WriteLine (indent + "\t{0} ret = {0}Adapter.GetObject ((Gst.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 + "\tGst.GLib.Value val = ");
				if (table.IsBoxed (CType)) {
					sw.WriteLine("(Gst.GLib.Value) value;");
				} else if (table.IsOpaque (CType)) {
					sw.WriteLine("new Gst.GLib.Value(value, \"{0}\");", CType);
				} else {
					sw.Write("new Gst.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++;
		}
示例#42
0
        public void GenerateBody(GenerationInfo gen_info, ClassBase implementor, string indent)
        {
            StreamWriter sw = gen_info.Writer;
            sw.WriteLine(" {");
            if (!IsStatic && implementor != null)
                implementor.Prepare (sw, indent + "\t\t\t");
            if (IsAccessor)
                Body.InitAccessor (sw, Signature, indent);
            Body.Initialize(gen_info, is_get, is_set, indent);

            sw.Write(indent + "\t\t\t");
            if (retval.IsVoid)
                sw.WriteLine(CName + call + ";");
            else {
                sw.WriteLine(retval.MarshalType + " raw_ret = " + CName + call + ";");
                sw.WriteLine(indent + "\t\t\t" + retval.CSType + " ret = " + retval.FromNative ("raw_ret") + ";");
            }

            if (!IsStatic && implementor != null)
                implementor.Finish (sw, indent + "\t\t\t");
            Body.Finish (sw, indent);
            Body.HandleException (sw, indent);

            if (is_get && Parameters.Count > 0)
                sw.WriteLine (indent + "\t\t\treturn " + Parameters.AccessorName + ";");
            else if (!retval.IsVoid)
                sw.WriteLine (indent + "\t\t\treturn ret;");
            else if (IsAccessor)
                Body.FinishAccessor (sw, Signature, indent);

            sw.Write(indent + "\t\t}");
        }
 private bool NeedNew(ClassBase implementor)
 {
     return(elem.HasAttribute("new_flag") ||
            (container_type != null && container_type.GetSignalRecursively(Name) != null) ||
            (implementor != null && implementor.GetSignalRecursively(Name) != null));
 }
示例#44
0
        public void GenMethods(GenerationInfo gen_info, IDictionary <string, bool> collisions, ClassBase implementor)
        {
            if (methods == null)
            {
                return;
            }

            foreach (Method method in methods.Values)
            {
                if (IgnoreMethod(method, implementor))
                {
                    continue;
                }

                string oname = null, oprotection = null;
                if (collisions != null && collisions.ContainsKey(method.Name))
                {
                    oname             = method.Name;
                    oprotection       = method.Protection;
                    method.Name       = QualifiedName + "." + method.Name;
                    method.Protection = "";
                }
                method.Generate(gen_info, implementor);
                if (oname != null)
                {
                    method.Name       = oname;
                    method.Protection = oprotection;
                }
            }
        }
        private void GenChainVirtualMethod(StreamWriter sw, ClassBase implementor)
        {
            GenVMDeclaration(sw, implementor);
            sw.WriteLine("\t\t{");
            if (IsVoid)
            {
                sw.WriteLine("\t\t\tGLib.Value ret = GLib.Value.Empty;");
            }
            else
            {
                sw.WriteLine("\t\t\tGLib.Value ret = new GLib.Value (" + ReturnGType + ");");
            }

            sw.WriteLine("\t\t\tGLib.ValueArray inst_and_params = new GLib.ValueArray (" + parms.Count + ");");
            sw.WriteLine("\t\t\tusing (var val0 = new GLib.Value (this)) {");
            sw.WriteLine("\t\t\t\tinst_and_params.Append (val0);");
            string cleanup = "";
            string indent  = new string ('\t', 4);

            for (int i = 1; i < parms.Count; i++)
            {
                Parameter p = parms [i];
                indent = new string ('\t', 3 + i);
                if (p.PassAs != "")
                {
                    if (SymbolTable.Table.IsBoxed(p.CType))
                    {
                        if (p.PassAs == "ref")
                        {
                            sw.WriteLine(indent + "using (var val" + i + " = new GLib.Value (" + p.Name + ")) {");
                        }
                        else
                        {
                            sw.WriteLine(indent + "using (var val" + i + " = new GLib.Value ((GLib.GType)typeof (" + p.CSType + "))) {");
                        }
                        cleanup += indent + p.Name + " = (" + p.CSType + ") vals [" + i + "];\n";
                    }
                    else
                    {
                        if (p.PassAs == "ref")
                        {
                            sw.WriteLine(indent + "IntPtr " + p.Name + "_ptr = GLib.Marshaller.StructureToPtrAlloc<" + p.MarshalType + "> (" + p.Generatable.CallByName(p.Name) + ");");
                        }
                        else
                        {
                            sw.WriteLine(indent + "IntPtr " + p.Name + "_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + p.MarshalType + ")));");
                        }

                        sw.WriteLine(indent + "using (var val" + i + " = new GLib.Value (" + p.Name + "_ptr)) {");
                        cleanup += indent + p.Name + " = " + p.FromNative("Marshal.PtrToStructure<" + p.MarshalType + "> (" + p.Name + "_ptr)") + ";\n";
                        cleanup += indent + "Marshal.FreeHGlobal (" + p.Name + "_ptr);\n";
                    }
                }
                else if (p.IsLength && parms [i - 1].IsString)
                {
                    sw.WriteLine(indent + "using (var val" + i + " = new GLib.Value (System.Text.Encoding.UTF8.GetByteCount (" + parms [i - 1].Name + "))) {");
                }
                else
                {
                    sw.WriteLine(indent + "using (var val" + i + " = new GLib.Value (" + p.Name + ")) {");
                }

                sw.WriteLine(indent + "inst_and_params.Append (val" + i + ");");
            }

            sw.WriteLine(indent + "g_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);");
            if (cleanup != "")
            {
                sw.WriteLine(cleanup);
            }
            for (int i = 1; i < parms.Count; ++i)
            {
                indent = new string ('\t', parms.Count - i + 3);
                sw.WriteLine(indent + "}");
            }
            sw.WriteLine("\t\t\t}");
            if (!IsVoid)
            {
                IGeneratable igen = SymbolTable.Table [retval.CType];
                sw.WriteLine("\t\t\t" + retval.CSType + " result = (" + (igen is EnumGen ? retval.CSType + ") (Enum" : retval.CSType) + ") ret;");
                sw.WriteLine("\t\t\tret.Dispose ();");
                sw.WriteLine("\t\t\treturn result;");
            }
            sw.WriteLine("\t\t}\n");
        }
示例#46
0
        public void Generate(GenerationInfo gen_info, string indent, ClassBase implementor)
        {
            var table = SymbolTable.Table;
            var 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++;
        }
        private void GenDefaultHandlerDelegate(GenerationInfo gen_info, ClassBase implementor)
        {
            StreamWriter      sw = gen_info.Writer;
            StreamWriter      glue;
            bool              use_glue  = gen_info.GlueEnabled && implementor == null && ClassFieldName.Length > 0;
            string            glue_name = String.Empty;
            ManagedCallString call      = new ManagedCallString(parms, true);

            sw.WriteLine("\t\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
            sw.WriteLine("\t\tdelegate " + retval.ToNativeType + " " + Name + "VMDelegate (" + parms.CallbackImportSignature + ");\n");

            if (use_glue)
            {
                glue      = gen_info.GlueWriter;
                glue_name = String.Format("{0}sharp_{1}_override_{2}", container_type.NS.ToLower().Replace(".", "_"), container_type.Name.ToLower(), ClassFieldName);
                sw.WriteLine("\t\t[DllImport (\"{0}\", CallingConvention = CallingConvention.Cdecl)]", gen_info.GluelibName);
                sw.WriteLine("\t\tstatic extern void {0} (IntPtr gtype, {1}VMDelegate cb);\n", glue_name, Name);
                glue.WriteLine("void {0} (GType gtype, gpointer cb);\n", glue_name);
                glue.WriteLine("void\n{0} (GType gtype, gpointer cb)", glue_name);
                glue.WriteLine("{");
                glue.WriteLine("\tGObjectClass *klass = g_type_class_peek (gtype);");
                glue.WriteLine("\tif (klass == NULL)");
                glue.WriteLine("\t\tklass = g_type_class_ref (gtype);");
                glue.WriteLine("\t(({0} *)klass)->{1} = cb;", container_type.CName + "Class", ClassFieldName);
                glue.WriteLine("}\n");
            }

            sw.WriteLine("\t\tstatic {0} {1};\n", Name + "VMDelegate", Name + "VMCallback");
            sw.WriteLine("\t\tstatic " + retval.ToNativeType + " " + Name.ToLower() + "_cb (" + parms.CallbackImportSignature + ")");
            sw.WriteLine("\t\t{");
            string unconditional = call.Unconditional("\t\t\t");

            if (unconditional.Length > 0)
            {
                sw.WriteLine(unconditional);
            }
            sw.WriteLine("\t\t\ttry {");
            sw.WriteLine("\t\t\t\t{0} {1}_managed = GLib.Object.GetObject ({1}, false) as {0};", implementor != null ? implementor.Name : container_type.Name, parms[0].Name);
            sw.Write(call.Setup("\t\t\t\t"));
            sw.Write("\t\t\t\t{0}", IsVoid ? "" : retval.CSType == retval.ToNativeType ? "return " : retval.CSType + " raw_ret = ");
            sw.WriteLine("{2}_managed.{0} ({1});", "On" + Name, call.ToString(), parms[0].Name);
            sw.Write(call.Finish("\t\t\t\t"));
            if (!IsVoid && retval.CSType != retval.ToNativeType)
            {
                sw.WriteLine("\t\t\t\treturn {0};", SymbolTable.Table.ToNativeReturn(retval.CType, "raw_ret"));
            }
            sw.WriteLine("\t\t\t} catch (Exception e) {");
            bool fatal = HasOutParams || !IsVoid;

            sw.WriteLine("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");
            if (fatal)
            {
                sw.WriteLine("\t\t\t\t// NOTREACHED: above call doesn't return");
                sw.WriteLine("\t\t\t\tthrow e;");
            }
            sw.WriteLine("\t\t\t}");
            sw.WriteLine("\t\t}\n");
            sw.WriteLine("\t\tprivate static void Override" + Name + " (GLib.GType gtype)");
            sw.WriteLine("\t\t{");
            sw.WriteLine("\t\t\tif (" + Name + "VMCallback == null)");
            sw.WriteLine("\t\t\t\t" + Name + "VMCallback = new " + Name + "VMDelegate (" + Name.ToLower() + "_cb);");
            if (use_glue)
            {
                sw.WriteLine("\t\t\t{0} (gtype.Val, {1}VMCallback);", glue_name, Name);
            }
            else
            {
                sw.WriteLine("\t\t\tOverrideVirtualMethod (gtype, " + CName + ", " + Name + "VMCallback);");
            }
            sw.WriteLine("\t\t}\n");
        }
示例#48
0
        private void GenerateDeclCommon(StreamWriter sw, ClassBase implementor)
        {
            if (IsStatic)
            {
                sw.Write("static ");
            }
            sw.Write(Safety);
            Method dup = null;

            if (container_type != null)
            {
                dup = container_type.GetMethodRecursively(Name);
            }
            if (implementor != null)
            {
                dup = implementor.GetMethodRecursively(Name);
            }

            if (Name == "ToString" && Parameters.Count == 0 && (!(container_type is InterfaceGen) || implementor != null))
            {
                sw.Write("override ");
            }
            else if (Name == "GetGType" && (container_type is ObjectGen || (container_type.Parent != null && container_type.Parent.Methods.ContainsKey("GetType"))))
            {
                sw.Write("new ");
            }
            else if (Modifiers == "new " || (dup != null && ((dup.Signature != null && Signature != null && dup.Signature.ToString() == Signature.ToString()) || (dup.Signature == null && Signature == null))))
            {
                sw.Write("new ");
            }

            if (Name.StartsWith(container_type.Name))
            {
                Name = Name.Substring(container_type.Name.Length);
            }

            if (is_get || is_set)
            {
                if (retval.IsVoid)
                {
                    sw.Write(Parameters.AccessorReturnType);
                }
                else
                {
                    sw.Write(retval.CSType);
                }
                sw.Write(" ");
                if (Name.StartsWith("Get") || Name.StartsWith("Set"))
                {
                    sw.Write(Name.Substring(3));
                }
                else
                {
                    int dot = Name.LastIndexOf('.');
                    if (dot != -1 && (Name.Substring(dot + 1, 3) == "Get" || Name.Substring(dot + 1, 3) == "Set"))
                    {
                        sw.Write(Name.Substring(0, dot + 1) + Name.Substring(dot + 4));
                    }
                    else
                    {
                        sw.Write(Name);
                    }
                }
                sw.WriteLine(" { ");
            }
            else if (IsAccessor)
            {
                sw.Write(Signature.AccessorType + " " + Name + "(" + Signature.AsAccessor + ")");
            }
            else
            {
                sw.Write(retval.CSType + " " + Name + "(" + (Signature != null ? Signature.ToString() : "") + ")");
            }
        }
示例#49
0
 public FieldBase(XmlElement elem, ClassBase container_type) : base(elem, container_type)
 {
 }
示例#50
0
		public StructField (XmlElement elem, ClassBase container_type) : base (elem, container_type) {}
示例#51
0
 public FieldBase(XmlElement elem, ClassBase container_type, FieldBase abi_field) : base(elem, container_type)
 {
     abi_field = abi_field;
 }