public CodeTypeReference CppToCSharp(Smoke.Type *type, out bool isRef) { string typeString = ByteArrayManager.GetString(type->name); isRef = false; if ((IntPtr)type->name == IntPtr.Zero) { return(new CodeTypeReference(typeof(void))); } Smoke.TypeId typeId = (Smoke.TypeId)(type->flags & (ushort)Smoke.TypeFlags.tf_elem); if (typeId == Smoke.TypeId.t_bool) { return(new CodeTypeReference(typeof(bool))); } if (typeId == Smoke.TypeId.t_char) { return(new CodeTypeReference(typeof(sbyte))); } if (typeId == Smoke.TypeId.t_uchar) { return(new CodeTypeReference(typeof(byte))); } if (typeId == Smoke.TypeId.t_short) { return(new CodeTypeReference(typeof(short))); } if (typeId == Smoke.TypeId.t_ushort) { return(new CodeTypeReference(typeof(ushort))); } if (typeId == Smoke.TypeId.t_int) { return(new CodeTypeReference(typeof(int))); } if (typeId == Smoke.TypeId.t_uint) { // HACK: qdrawutil.h says, DrawingHint is for internal use; nonetheless, SMOKE generates an overload using it; ignoring if (typeString == "unsigned int" || typeString == "QFlags<QDrawBorderPixmap::DrawingHint>") { return(new CodeTypeReference(typeof(uint))); } } if (typeId == Smoke.TypeId.t_long) { return(new CodeTypeReference("NativeLong")); } if (typeId == Smoke.TypeId.t_ulong) { return(new CodeTypeReference("NativeULong")); } if (typeId == Smoke.TypeId.t_float) { return(new CodeTypeReference(typeof(float))); } if (typeId == Smoke.TypeId.t_double) { return(new CodeTypeReference(typeof(double))); } return(this.CppToCSharp(typeString, out isRef)); }
private string GetArgName(Smoke *smoke, short *typeIndex, IList <string> methodArgs, ref int count, bool isRef, CodeTypeReference argType) { if (methodArgs == null) { return("arg" + count++); } string arg = methodArgs[count++ - 1]; int nameEnd = arg.IndexOf(' '); if (nameEnd > 0) { string defaultValue = arg.Substring(nameEnd + 3); arg = arg.Substring(0, nameEnd); if (isRef) { return(arg); } // HACK if (argType.BaseType.EndsWith("NativeLong") || argType.BaseType.EndsWith("NativeULong")) { return(arg); } arg = Provider.CreateEscapedIdentifier(arg); Smoke.TypeId typeId = (Smoke.TypeId)((smoke->types + *typeIndex)->flags & (ushort)Smoke.TypeFlags.tf_elem); switch (typeId) { case Smoke.TypeId.t_voidp: case Smoke.TypeId.t_class: switch (argType.BaseType) { case "System.Int64": return(arg + " = 0"); case "System.IntPtr": return(arg + " = new IntPtr()"); } if (argType.BaseType.Contains("QObjectWrapOption")) { return(arg + " = 0"); } switch (defaultValue) { case "0": return(arg + " = null"); case "QString()": return(arg + " = \"\""); } break; case Smoke.TypeId.t_int: if (char.IsLetter(defaultValue[0])) { int indexOfColon = defaultValue.IndexOf("::", StringComparison.Ordinal); string containingType; string enumMember; string additional; if (indexOfColon > 0) { containingType = defaultValue.Substring(0, indexOfColon); Match match = Regex.Match(defaultValue, @"::(\w+)(.*)"); enumMember = match.Groups[1].Value; additional = match.Groups[2].Value; } else { containingType = this.type.Name; enumMember = defaultValue; additional = string.Empty; } string enumType = (from keyValue in this.data.EnumTypeMap where keyValue.Value.IsEnum && keyValue.Key.StartsWith(containingType + "::") from CodeTypeMember member in keyValue.Value.Members where member.Name == enumMember select keyValue.Value.Name).FirstOrDefault() ?? (from referencedType in this.data.ReferencedTypeMap.Values where referencedType.IsEnum && referencedType.FullName.Contains("." + containingType + "+") from FieldInfo member in referencedType.GetFields(BindingFlags.Public | BindingFlags.Static) where member.Name == enumMember select referencedType.Name).FirstOrDefault(); if (string.IsNullOrEmpty(enumType)) { var result = (from CodeTypeReference baseType in this.type.BaseTypes where this.data.CSharpTypeMap.ContainsKey(baseType.BaseType) let baseTypeDeclaration = this.data.CSharpTypeMap[baseType.BaseType] from CodeTypeDeclaration member in baseTypeDeclaration.Members.OfType <CodeTypeDeclaration>() where member.IsEnum from CodeTypeMember enumValue in member.Members where enumValue.Name == enumMember select new KeyValuePair <string, string>(baseType.BaseType, member.Name)).FirstOrDefault(); containingType = result.Key; enumType = result.Value; } return(arg + " = (int) " + GetEnumMembers(string.Format("{0}.{1}", containingType, enumType), enumMember) + additional); } goto default; case Smoke.TypeId.t_uint: case Smoke.TypeId.t_enum: if (defaultValue == "0" || defaultValue.EndsWith("()")) { return(arg + " = 0"); } if (char.IsLetter(defaultValue[0])) { return(arg + " = " + GetEnumMembers(argType.BaseType, defaultValue)); } goto default; case Smoke.TypeId.t_char: break; default: return(arg + " = " + defaultValue); } } return(arg); }