public override bool VisitTemplateSpecializationType(TemplateSpecializationType template, TypeQualifiers quals) { if (AlreadyVisited(template) || template.Template.Access == AccessSpecifier.Private) return false; if (template.Arguments.Select(a => a.Type.Type.Desugar()).All(t => t.IsAddress() && !t.GetFinalPointee().IsDependent)) { var cppTypePrinter = new CppTypePrinter { PrintScopeKind = CppTypePrintScopeKind.Qualified }; templateInstantiations.Add(string.Format("{0}<{1}>", template.Template.Name, string.Join(", ", template.Arguments.Select(a => a.Type.Type.Visit(cppTypePrinter))))); } return true; }
public override TypePrinterResult VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { var decl = template.GetClassTemplateSpecialization() ?? template.Template.TemplatedDecl; TypeMap typeMap; if (!TypeMapDatabase.FindTypeMap(template, out typeMap)) { if (ContextKind == TypePrinterContextKind.Managed && decl == template.Template.TemplatedDecl && template.Arguments.All(IsValid)) { List <TemplateArgument> args = template.Arguments; var @class = (Class)template.Template.TemplatedDecl; TemplateArgument lastArg = args.Last(); return($@"{VisitDeclaration(decl)}<{string.Join(", ", args.Concat(Enumerable.Range(0, @class.TemplateParameters.Count - args.Count).Select( i => lastArg)).Select(this.VisitTemplateArgument))}>"); } if (ContextKind == TypePrinterContextKind.Native) { return(template.Desugared.Visit(this)); } return(decl.Visit(this)); } typeMap.Type = template; var typePrinterContext = new TypePrinterContext { Type = template, Kind = ContextKind, MarshalKind = MarshalKind }; return(typeMap.CSharpSignatureType(typePrinterContext).ToString()); }
public override TypePrinterResult VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { var decl = template.Template.TemplatedDecl; if (decl == null) { return(string.Empty); } TypeMap typeMap = null; if (TypeMapDatabase.FindTypeMap(template, out typeMap) && !typeMap.IsIgnored) { var typePrinterContext = new TypePrinterContext { Type = template }; return(typeMap.CLISignatureType(typePrinterContext).ToString()); } return(decl.Name); }
public string VisitTemplateSpecializationType(TemplateSpecializationType template, TypeQualifiers quals) { var decl = template.Template.TemplatedDecl; if (decl == null) { return(string.Empty); } TypeMap typeMap = null; if (TypeMapDatabase.FindTypeMap(template, out typeMap) && !typeMap.IsIgnored) { typeMap.Declaration = decl; typeMap.Type = template; TypePrinterContext.Type = template; return(typeMap.CLISignature(TypePrinterContext)); } return(decl.Name); }
public override void CSharpMarshalToManaged(MarshalContext ctx) { TemplateSpecializationType templateType = (TemplateSpecializationType)this.Type; QualifiedType type = templateType.Arguments[0].Type; TextGenerator supportBefore = ctx.SupportBefore; string returnVarName = ctx.ReturnVarName; if (ctx.ReturnType.Type.Desugar().IsAddress()) { returnVarName = string.Format("(*(QList.Internal*) {0})", returnVarName); } supportBefore.WriteLine("var __qlistData = QListData.{0}({1}._0.p);", Helpers.CreateInstanceIdentifier, returnVarName); supportBefore.WriteLine("var __size = __qlistData.Size;"); supportBefore.WriteLine("var __list = new System.Collections.Generic.List<{0}>(__size);", type); supportBefore.WriteLine("for (int i = 0; i < __size; i++)"); supportBefore.WriteStartBraceIndent(); // TODO: handle pointers to primitives, they cannot be used as a placeholder type and use IntPtr instead if (type.Type.IsPrimitiveType() || type.Type.IsEnumType()) { supportBefore.WriteLine("__list.Add(*({0}*) __qlistData.At(i));", type); } else { Class @class; Type pointee; if ((type.Type.TryGetClass(out @class) || (type.Type.IsPointerTo(out pointee) && pointee.TryGetClass(out @class))) && @class.IsAbstract) { supportBefore.WriteLine("__list.Add({0}Internal.{1}(new global::System.IntPtr(__qlistData.At(i))));", type, Helpers.CreateInstanceIdentifier); } else { supportBefore.WriteLine("__list.Add({0}.{1}(new global::System.IntPtr(__qlistData.At(i))));", type, Helpers.CreateInstanceIdentifier); } } supportBefore.WriteCloseBraceIndent(); ctx.Return.Write("__list"); }
public override bool VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { TypeMap typeMap; if (TypeMapDatabase.FindTypeMap(template, out typeMap)) { if (typeMap.IsIgnored) { Ignore(); } return(false); } var specialization = template.GetClassTemplateSpecialization(); if (specialization == null || specialization.Ignore) { Ignore(); } return(base.VisitTemplateSpecializationType(template, quals)); }
public override bool VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { TypeMap typeMap; if (TypeMapDatabase.FindTypeMap(template, out typeMap)) { if (typeMap.IsIgnored) { Ignore(); } return(false); } var result = base.VisitTemplateSpecializationType(template, quals); if (!result) { Ignore(); } return(result); }
public CSharpTypePrinterResult VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { var decl = template.Template.TemplatedDecl; TypeMap typeMap = null; if (TypeMapDatabase.FindTypeMap(template, out typeMap)) { typeMap.Declaration = decl; typeMap.Type = template; Context.Type = template; Context.CSharpKind = ContextKind; return(new CSharpTypePrinterResult() { Type = GetCSharpSignature(typeMap), TypeMap = typeMap }); } return(decl.Name); }
public CSharpTypePrinterResult VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { var decl = template.Template.TemplatedDecl; TypeMap typeMap; if (!driver.TypeDatabase.FindTypeMap(template, out typeMap)) { if (ContextKind != CSharpTypePrinterContextKind.Native) { return(GetNestedQualifiedName(decl)); } return(GetTemplateSpecializationInternal(template)); } typeMap.Declaration = decl; typeMap.Type = template; Context.Type = template; Context.CSharpKind = ContextKind; Context.MarshalKind = MarshalKind; var type = GetCSharpSignature(typeMap); if (!string.IsNullOrEmpty(type)) { return(new CSharpTypePrinterResult { Type = type, TypeMap = typeMap }); } return(GetNestedQualifiedName(decl) + (ContextKind == CSharpTypePrinterContextKind.Native ? ".Internal" : string.Empty)); }
public override TypePrinterResult VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { var decl = template.GetClassTemplateSpecialization() ?? template.Template.TemplatedDecl; TypeMap typeMap; if (!TypeMapDatabase.FindTypeMap(template, out typeMap)) { return(decl.Visit(this)); } typeMap.Declaration = decl; typeMap.Type = template; var typePrinterContext = new TypePrinterContext { Type = template, Kind = ContextKind, MarshalKind = MarshalKind }; var type = typeMap.CSharpSignature(typePrinterContext); if (!string.IsNullOrEmpty(type)) { return(new TypePrinterResult { Type = type, TypeMap = typeMap }); } return(decl.Visit(this)); }
private TemplateSpecializationType(TemplateSpecializationType.Internal native, bool skipVTables = false) : this(__CopyValue(native), skipVTables) { __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; }
private static void* __CopyValue(TemplateSpecializationType.__Internal native) { var ret = Marshal.AllocHGlobal(32); global::CppSharp.Parser.AST.TemplateSpecializationType.__Internal.cctor_1(ret, new global::System.IntPtr(&native)); return ret.ToPointer(); }
public static TemplateSpecializationType __CreateInstance(TemplateSpecializationType.Internal native, bool skipVTables = false) { return new TemplateSpecializationType(native, skipVTables); }
public abstract TRet VisitTemplateSpecialization(TemplateSpecializationType type);
public TRet Visit(Parser.AST.Type type) { if (type.__Instance == IntPtr.Zero) { return(default(TRet)); } switch (type.Kind) { case TypeKind.Tag: { var _type = new TagType(type.__Instance); return(VisitTag(_type)); } case TypeKind.Array: { var _type = new ArrayType(type.__Instance); return(VisitArray(_type)); } case TypeKind.Function: { var _type = new FunctionType(type.__Instance); return(VisitFunction(_type)); } case TypeKind.Pointer: { var _type = new PointerType(type.__Instance); return(VisitPointer(_type)); } case TypeKind.MemberPointer: { var _type = new MemberPointerType(type.__Instance); return(VisitMemberPointer(_type)); } case TypeKind.Typedef: { var _type = new TypedefType(type.__Instance); return(VisitTypedef(_type)); } case TypeKind.Attributed: { var _type = new AttributedType(type.__Instance); return(VisitAttributed(_type)); } case TypeKind.Decayed: { var _type = new DecayedType(type.__Instance); return(VisitDecayed(_type)); } case TypeKind.TemplateSpecialization: { var _type = new TemplateSpecializationType(type.__Instance); return(VisitTemplateSpecialization(_type)); } case TypeKind.TemplateParameter: { var _type = new TemplateParameterType(type.__Instance); return(VisitTemplateParameter(_type)); } case TypeKind.TemplateParameterSubstitution: { var _type = new TemplateParameterSubstitutionType(type.__Instance); return(VisitTemplateParameterSubstitution(_type)); } case TypeKind.InjectedClassName: { var _type = new InjectedClassNameType(type.__Instance); return(VisitInjectedClassName(_type)); } case TypeKind.DependentName: { var _type = new DependentNameType(type.__Instance); return(VisitDependentName(_type)); } case TypeKind.Builtin: { var _type = new BuiltinType(type.__Instance); return(VisitBuiltin(_type)); } } throw new ArgumentOutOfRangeException(); }
internal TemplateSpecializationType(TemplateSpecializationType.Internal* native) : this(new global::System.IntPtr(native)) { }
internal TemplateSpecializationType(TemplateSpecializationType.Internal native) : this(&native) { }
private TemplateSpecializationType(TemplateSpecializationType.Internal native) : this(__CopyValue(native)) { __ownsNativeInstance = true; NativeToManagedMap[__Instance] = this; }
public string VisitTemplateSpecializationType(TemplateSpecializationType template, TypeQualifiers quals) { var decl = template.Template.TemplatedDecl; return(decl.Visit(this)); }
public override bool VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { TypeMap typeMap; if (TypeMapDatabase.FindTypeMap(template, out typeMap)) { if (typeMap.IsIgnored) Ignore(); return false; } var specialization = template.GetClassTemplateSpecialization(); if (specialization == null || specialization.Ignore) Ignore(); return base.VisitTemplateSpecializationType(template, quals); }
protected TemplateSpecializationType(TemplateSpecializationType.Internal* native, bool skipVTables = false) : base((CppSharp.Parser.AST.Type.Internal*) null) { __PointerAdjustment = 0; if (native == null) return; __Instance = new global::System.IntPtr(native); }
public override bool VisitTemplateSpecializationType(TemplateSpecializationType template, TypeQualifiers quals) { TypeMap typeMap; if (Context.Driver.TypeDatabase.FindTypeMap(template, out typeMap) && typeMap.DoesMarshalling) { typeMap.Type = template; typeMap.CLIMarshalToManaged(Context); return true; } return template.Template.Visit(this); }
public override void CSharpMarshalToNative(MarshalContext ctx) { TextGenerator supportBefore = ctx.SupportBefore; string suffix = ctx.ParameterIndex > 0 ? ctx.ParameterIndex.ToString(CultureInfo.InvariantCulture) : string.Empty; string qList = string.Format("__qList{0}", suffix); supportBefore.WriteLine(string.Format("var {0} = new QtCore.QList.Internal();", qList)); string qListDataData = string.Format("__qlistDataData{0}", suffix); supportBefore.WriteLine("var {0} = (QListData.Data.Internal*) {1}._0.d;", qListDataData, qList); // TODO: tests with Qt shows that while alloc is not smaller than end, it's not equal, it reserves more space actually supportBefore.WriteLine("{0}->alloc = {1}.Count;", qListDataData, ctx.Parameter.Name); supportBefore.WriteLine("{0}->begin = 0;", qListDataData, ctx.Parameter.Name); supportBefore.WriteLine("{0}->end = {1}.Count;", qListDataData, ctx.Parameter.Name); supportBefore.WriteLine("fixed (void** __v = new void*[{0}.Count])", ctx.Parameter.Name); supportBefore.WriteStartBraceIndent(); supportBefore.WriteLine("{0}->array = __v;", qListDataData); supportBefore.WriteCloseBraceIndent(); supportBefore.WriteLine("", qListDataData, ctx.Parameter.Name); var parameterType = ctx.Parameter.Type.Desugar(); TemplateSpecializationType type = parameterType as TemplateSpecializationType; if (type == null) { TypedefType typedef; if (parameterType.IsPointerTo(out typedef)) { type = (TemplateSpecializationType)typedef.Desugar(); } else { parameterType.IsPointerTo(out type); } } Type elementType = type.Arguments[0].Type.Type.Desugar(); string instance = string.Empty; if (!elementType.IsPointerToPrimitiveType()) { instance = string.Format(".{0}", Helpers.InstanceIdentifier); } supportBefore.WriteLine("for (int i = 0; i < {0}.Count; i++)", ctx.Parameter.Name); supportBefore.WriteStartBraceIndent(); Type desugared = ctx.Parameter.Type.Desugar(); TemplateSpecializationType templateSpecializationType = desugared as TemplateSpecializationType; if (templateSpecializationType == null) { Type paramType; desugared.IsPointerTo(out paramType); templateSpecializationType = (TemplateSpecializationType)paramType.Desugar(); } TemplateArgument templateArgument = templateSpecializationType.Arguments[0]; if (templateArgument.Type.ToString() == "string") { supportBefore.WriteLine("{0}->array[i] = Marshal.StringToHGlobalUni({1}[i]).ToPointer();", qListDataData, ctx.Parameter.Name, instance); } else { Class @class; if (templateArgument.Type.Type.TryGetClass(out @class) && @class.IsValueType) { supportBefore.WriteLine("{0}.Internal __value = {1}[i]{2};", @class.Name, ctx.Parameter.Name, instance, Helpers.InstanceIdentifier); supportBefore.WriteLine("{0}->array[i] = &__value;", qListDataData, ctx.Parameter.Name, instance); } else { supportBefore.WriteLine("{0}->array[i] = (void*) {1}[i]{2};", qListDataData, ctx.Parameter.Name, instance); } } supportBefore.WriteCloseBraceIndent(); if (parameterType.IsAddress()) { ctx.Return.Write("new global::System.IntPtr(&{0})", qList); } else { ctx.Return.Write(qList); } }
public override bool VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { TypeMap typeMap; if (TypeMapDatabase.FindTypeMap(template, out typeMap)) { if (typeMap.IsIgnored) Ignore(); return false; } Ignore(); return base.VisitTemplateSpecializationType(template, quals); }
public bool VisitTemplateSpecializationType(TemplateSpecializationType template, TypeQualifiers quals) { return(false); }
public static TemplateSpecializationType __CreateInstance(TemplateSpecializationType.Internal native) { return new TemplateSpecializationType(native); }
public bool VisitTemplateSpecializationType(TemplateSpecializationType template, TypeQualifiers quals) { throw new NotImplementedException(); }
public virtual TypePrinterResult VisitTemplateSpecializationType( TemplateSpecializationType template, TypeQualifiers quals) { throw new NotImplementedException(); }
private static TemplateSpecializationType.Internal* __CopyValue(TemplateSpecializationType.Internal native) { var ret = Marshal.AllocHGlobal(48); CppSharp.Parser.AST.TemplateSpecializationType.Internal.cctor_1(ret, new global::System.IntPtr(&native)); return (TemplateSpecializationType.Internal*) ret; }
internal TemplateSpecializationType(TemplateSpecializationType.Internal native) : this(__CopyValue(native)) { }
protected TemplateSpecializationType(TemplateSpecializationType.Internal* native, bool isInternalImpl = false) : base((CppSharp.Parser.AST.Type.Internal*) native) { }
private TemplateSpecializationType(TemplateSpecializationType.Internal native) : this(__CopyValue(native)) { __ownsNativeInstance = true; }