public bool Validate (LogWriter log) { if (CSType == "" && !Hidden) { log.Member = Name; log.Warn ("property has unknown type '{0}' ", CType); Statistics.ThrottledCount++; return false; } return true; }
public virtual bool Validate (LogWriter log) { if (ConstType == String.Empty) { log.Warn ("{0} type is missing or wrong", Name); return false; } if (SymbolTable.Table.GetMarshalType (ctype) == "int" && value.Length >= 20) { return false; } return true; }
public override bool Validate (LogWriter log) { if (!base.Validate (log)) return false; if (IsBitfield) { log.Warn ("bitfields are not supported"); return false; } return true; }
public virtual bool Validate (LogWriter log) { log.Member = Name; if (!Ignored && !Hidden && CSType == "") { if (Name == "Priv") return false; log.Warn ("field has unknown type: " + CType); Statistics.ThrottledCount++; return false; } return true; }
public bool Validate (LogWriter log) { log.Member = Name; if (Name == "") { log.Warn ("Nameless signal found. Add name attribute with fixup."); Statistics.ThrottledCount++; return false; } else if (!parms.Validate (log) || !retval.Validate (log)) { Statistics.ThrottledCount++; return false; } return true; }
public override bool Validate () { LogWriter log = new LogWriter (QualifiedName); var invalids = new List<string> (); foreach (string prop_name in childprops.Keys) { if (!childprops [prop_name].Validate (log)) invalids.Add (prop_name); } foreach (string prop_name in invalids) childprops.Remove (prop_name); return base.Validate (); }
public override bool Validate () { valid = true; LogWriter log = new LogWriter (); log.Type = QualifiedName; if (!retval.Validate (log) || !parms.Validate (log)) { Statistics.ThrottledCount++; valid = false; } if (!String.IsNullOrEmpty (retval.CountParameterName)) retval.CountParameter = parms.GetCountParameter (retval.CountParameterName); if (retval.CountParameterIndex >= 0) retval.CountParameter = parms[retval.CountParameterIndex]; return valid; }
public override bool Validate (LogWriter log) { log.Member = Name; if (!retval.Validate (log) || !base.Validate (log)) return false; if (Name == String.Empty || CName == String.Empty) { log.Warn ("Method has no name or cname."); return false; } Parameters parms = Parameters; is_get = ((parms.IsAccessor && retval.IsVoid) || (parms.Count == 0 && !retval.IsVoid)) && HasGetterName; is_set = ((parms.IsAccessor || (parms.VisibleCount == 1 && retval.IsVoid)) && HasSetterName); call = "(" + (IsStatic ? "" : container_type.CallByName () + (parms.Count > 0 ? ", " : "")) + Body.GetCallString (is_set) + ")"; return true; }
public bool Validate(LogWriter log) { if (MarshalType == "" || CSType == "") { log.Warn ("Unknown return type: {0}", CType); return false; } else if ((CSType == "GLib.List" || CSType == "GLib.SList") && String.IsNullOrEmpty (ElementType)) log.Warn ("Returns {0} with unknown element type. Add element_type attribute with gapi-fixup.", CType); return true; }
public virtual bool ValidateForSubclass() { LogWriter log = new LogWriter (QualifiedName); ArrayList invalids = new ArrayList (); foreach (Signal sig in sigs.Values) { if (!sig.Validate (log)) { invalids.Add (sig); } } foreach (Signal sig in invalids) sigs.Remove (sig.Name); invalids.Clear (); return true; }
public override bool Validate(LogWriter log) { if (!base.Validate (log)) return false; bool is_valid = true; if (this.IsStatic) { switch (OverrideType) { case VMOverrideType.Unspecified: log.Warn ("Static virtual methods can only be generated if you provide info on how to override this method via the metadata "); is_valid = false; break; case VMOverrideType.ImplementingClass: log.Warn ("Overriding static virtual methods in the implementing class is not supported yet "); is_valid = false; break; } } return is_valid; }
public override bool Validate(LogWriter log) { if (vstate != ValidState.Unvalidated) return vstate == ValidState.Valid; vstate = ValidState.Valid; log.Member = Name; if (!parms.Validate (log) || !retval.Validate (log)) { vstate = ValidState.Invalid; return false; } call = new ManagedCallString (parms); return true; }
public virtual bool Validate (LogWriter log) { log.Member = Name; if (!parms.Validate (log)) { Statistics.ThrottledCount++; return false; } return true; }
public override bool ValidateForSubclass() { if (!base.ValidateForSubclass ()) return false; LogWriter log = new LogWriter (QualifiedName); ArrayList invalids = new ArrayList (); foreach (Method method in methods.Values) { if (!method.Validate (log)) invalids.Add (method); } foreach (Method method in invalids) methods.Remove (method.Name); invalids.Clear (); return true; }
public override bool Validate() { LogWriter log = new LogWriter (QualifiedName); ArrayList invalids = new ArrayList (); foreach (ChildProperty prop in childprops.Values) { if (!prop.Validate (log)) invalids.Add (prop); } foreach (ChildProperty prop in invalids) childprops.Remove (prop); return base.Validate (); }
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; IGeneratable gen = table [CType]; StreamWriter sw = gen_info.Writer; string modifiers = elem.GetAttributeAsBoolean ("new_flag") ? "new " : ""; 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 (gen is CallbackGen) { sw.WriteLine (indent + "\t\t\tIntPtr* raw_ptr = (IntPtr*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");"); sw.WriteLine (indent + "\t\t\t {0} del = ({0})Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof({0}));", table.GetMarshalType (CType)); sw.WriteLine (indent + "\t\t\treturn " + table.FromNative (ctype, "(del)") + ";"); } 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}"); } 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 (gen is CallbackGen) { sw.WriteLine (indent + "\t\t\t{0} wrapper = new {0} (value);", ((CallbackGen)gen).WrapperName); sw.WriteLine (indent + "\t\t\tIntPtr* raw_ptr = (IntPtr*)(((byte*)" + container_type.CallByName () + ") + " + offsetName + ");"); sw.WriteLine (indent + "\t\t\t*raw_ptr = Marshal.GetFunctionPointerForDelegate (wrapper.NativeDelegate);"); } 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); }
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); string access = elem.HasAttribute ("access") ? elem.GetAttribute ("access") : "public"; sw.WriteLine (indent + access + " " + 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); }
public bool Validate(LogWriter log) { 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) { log.Warn ("Ellipsis parameter: hide and bind manually if no alternative exists. "); Clear (); return false; } if ((p.CSType == "") || (p.Name == "") || (p.MarshalType == "") || (SymbolTable.Table.CallByName(p.CType, p.Name) == "")) { log.Warn ("Unknown type {1} on parameter {0}", 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) { p.IsCount = false; if (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; }
public bool Validate (LogWriter log) { if (MarshalType == "" || CSType == "") { log.Warn ("Unknown return type: {0}", CType); return false; } else if ((CSType == "GLib.List" || CSType == "GLib.SList") && String.IsNullOrEmpty (ElementType)) log.Warn ("Returns {0} with unknown element type. Add element_type attribute with gapi-fixup.", CType); if (is_array && !is_null_term && String.IsNullOrEmpty (array_length_param)) { log.Warn ("Returns an array with undeterminable length. Add null_term_array or array_length_param attribute with gapi-fixup."); return false; } return true; }
/* 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) 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 (); }
public override bool Validate () { LogWriter log = new LogWriter (QualifiedName); foreach (string iface in interfaces) { InterfaceGen igen = SymbolTable.Table[iface] as InterfaceGen; if (igen == null) { log.Warn ("implements unknown GInterface " + iface); return false; } if (!igen.ValidateForSubclass ()) { log.Warn ("implements invalid GInterface " + iface); return false; } } ArrayList invalids = new ArrayList (); foreach (Property prop in props.Values) { if (!prop.Validate (log)) invalids.Add (prop); } foreach (Property prop in invalids) props.Remove (prop.Name); invalids.Clear (); foreach (ObjectField field in fields.Values) { if (!field.Validate (log)) invalids.Add (field); } foreach (ObjectField field in invalids) fields.Remove (field.Name); invalids.Clear (); foreach (Method method in methods.Values) { if (!method.Validate (log)) invalids.Add (method); } foreach (Method method in invalids) methods.Remove (method.Name); invalids.Clear (); foreach (Constant con in constants.Values) { if (!con.Validate (log)) invalids.Add (con); } foreach (Constant con in invalids) constants.Remove (con.Name); invalids.Clear (); foreach (Ctor ctor in ctors) { if (!ctor.Validate (log)) invalids.Add (ctor); } foreach (Ctor ctor in invalids) ctors.Remove (ctor); invalids.Clear (); return true; }
public override bool Validate() { if (Parent != null && !(Parent as ObjectBase).ValidateForSubclass ()) return false; LogWriter log = new LogWriter (QualifiedName); ArrayList invalids = new ArrayList (); foreach (GObjectVM vm in virtual_methods) if (!vm.Validate (log)) invalids.Add (vm); foreach (VirtualMethod invalid_vm in invalids) { virtual_methods.Remove (invalid_vm); hidden_vms.Add (invalid_vm); } invalids.Clear (); class_fields_valid = true; foreach (ClassField field in class_fields) if (!field.Validate (log)) class_fields_valid = false; foreach (InterfaceVM vm in interface_vms) if (!vm.Validate (log)) invalids.Add (vm); foreach (InterfaceVM invalid_vm in invalids) { interface_vms.Remove (invalid_vm); hidden_vms.Add (invalid_vm); } invalids.Clear (); foreach (Signal sig in sigs.Values) { if (!sig.Validate (log)) invalids.Add (sig); } foreach (Signal sig in invalids) sigs.Remove (sig.Name); return base.Validate (); }
public override bool Validate() { valid = true; LogWriter log = new LogWriter (); log.Type = QualifiedName; if (!retval.Validate (log) || !parms.Validate (log)) { Statistics.ThrottledCount++; valid = false; } return valid; }
public override bool Validate () { LogWriter log = new LogWriter (QualifiedName); foreach (StructField field in fields) { if (!field.Validate (log)) { if (!field.IsPointer) return false; } } return base.Validate (); }
public override bool Validate (LogWriter log) { if (!base.Validate (log)) return false; if (target == null && !(container_type as InterfaceGen).IsConsumeOnly) { log.Warn ("No matching target method to invoke. Add target_method attribute with fixup."); return false; } return true; }