public string GetTemplateParameterList() { if (Kind == TypePrinterContextKind.Template) { var template = (Template)Declaration; return(string.Join(", ", template.Parameters.Select(p => p.Name))); } var type = Type.Desugar(); IEnumerable <TemplateArgument> templateArgs; var templateSpecializationType = type as TemplateSpecializationType; if (templateSpecializationType != null) { templateArgs = templateSpecializationType.Arguments; } else { templateArgs = ((ClassTemplateSpecialization)((TagType)type).Declaration).Arguments; } var paramsList = new List <string>(); foreach (var arg in templateArgs.Where(a => a.Kind == TemplateArgument.ArgumentKind.Type)) { var argType = arg.Type.Type.IsPointerToPrimitiveType() ? new CILType(typeof(System.IntPtr)) : arg.Type.Type; paramsList.Add(argType.ToString()); } return(string.Join(", ", paramsList)); }
public static void CheckTypeForSpecialization(Type type, Declaration container, Action <ClassTemplateSpecialization> addSpecialization, ITypeMapDatabase typeMaps, bool internalOnly = false) { type = type.Desugar(); type = (type.GetFinalPointee() ?? type).Desugar(); ClassTemplateSpecialization specialization = GetParentSpecialization(type); if (specialization == null) { return; } if (IsSpecializationNeeded(container, typeMaps, internalOnly, specialization)) { return; } if (!internalOnly) { if (IsSpecializationSelfContained(specialization, container)) { return; } if (IsMappedToPrimitive(typeMaps, type, specialization)) { return; } } addSpecialization(specialization); }
private static bool IsValueDependent(Type type) { var desugared = type.Desugar(); if (desugared is TemplateParameterType) { return(true); } var tagType = desugared as TagType; if (tagType?.IsDependent == true) { return(true); } var templateType = desugared as TemplateSpecializationType; if (templateType?.Arguments.Any( a => a.Type.Type?.Desugar().IsDependent == true) == true) { return(true); } var arrayType = desugared as ArrayType; return(arrayType != null && IsValueDependent(arrayType.Type)); }
public static void CheckTypeForSpecialization(Type type, Declaration container, Action <ClassTemplateSpecialization> addSpecialization, ITypeMapDatabase typeMaps, bool internalOnly = false) { type = type.Desugar(); type = type.GetFinalPointee() ?? type; ClassTemplateSpecialization specialization; type.TryGetDeclaration(out specialization); if (specialization == null || specialization.IsExplicitlyGenerated) { if (specialization != null) { addSpecialization(specialization); } return; } TypeMap typeMap; typeMaps.FindTypeMap(specialization, out typeMap); if ((!internalOnly && (((specialization.Ignore || specialization.TemplatedDecl.TemplatedClass.Ignore) && typeMap == null) || specialization.Arguments.Any(a => UnsupportedTemplateArgument( specialization, a, typeMaps)))) || specialization.IsIncomplete || (!internalOnly && specialization.TemplatedDecl.TemplatedClass.IsIncomplete) || specialization is ClassTemplatePartialSpecialization || container.Namespace == specialization) { return; } while (container.Namespace != null) { if (container.Namespace == specialization) { return; } container = container.Namespace; } if (!internalOnly && typeMaps.FindTypeMap(specialization, out typeMap)) { var typePrinterContext = new TypePrinterContext { Type = type }; var mappedTo = typeMap.CSharpSignatureType(typePrinterContext); mappedTo = mappedTo.Desugar(); mappedTo = (mappedTo.GetFinalPointee() ?? mappedTo); if (mappedTo.IsPrimitiveType() || mappedTo.IsPointerToPrimitiveType() || mappedTo.IsEnum()) { return; } } addSpecialization(specialization); }
public static bool TypeIgnored(CppSharp.AST.Type type) { var desugared = type.Desugar(); var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar(); Class @class; return(finalType.TryGetClass(out @class) && @class.IsIncomplete); }
public bool FindTypeMap(Type type, out TypeMap typeMap) { if (typeMaps.ContainsKey(type)) { typeMap = typeMaps[type]; return(typeMap.IsEnabled); } var template = type as TemplateSpecializationType; if (template != null) { var specialization = template.GetClassTemplateSpecialization(); if (specialization != null && FindTypeMap(specialization, type, out typeMap)) { return(true); } if (template.Template.TemplatedDecl != null) { return(FindTypeMap(template.Template.TemplatedDecl, type, out typeMap)); } } Type desugared = type.Desugar(); bool printExtra = desugared.GetPointee() != null && desugared.GetFinalPointee().Desugar().IsPrimitiveType(); var typePrinter = new CppTypePrinter { PrintTypeQualifiers = printExtra, PrintTypeModifiers = printExtra, PrintLogicalNames = true }; foreach (var resolveTypeDefs in new[] { true, false }) { foreach (var typePrintScopeKind in new[] { TypePrintScopeKind.Local, TypePrintScopeKind.Qualified }) { typePrinter.ResolveTypedefs = resolveTypeDefs; typePrinter.PrintScopeKind = typePrintScopeKind; if (FindTypeMap(type.Visit(typePrinter), out typeMap)) { typeMap.Type = type; typeMaps[type] = typeMap; return(true); } } } typeMap = null; var typedef = type as TypedefType; return(typedef != null && FindTypeMap(typedef.Declaration, type, out typeMap)); }
private static Type GetEnumType(Type mappedType) { var type = mappedType.Desugar(); ClassTemplateSpecialization classTemplateSpecialization; var templateSpecializationType = type as TemplateSpecializationType; if (templateSpecializationType != null) classTemplateSpecialization = templateSpecializationType.GetClassTemplateSpecialization(); else classTemplateSpecialization = (ClassTemplateSpecialization) ((TagType) type).Declaration; return classTemplateSpecialization.Arguments[0].Type.Type; }
public override void CSharpMarshalToManaged(MarshalContext ctx) { var marshal = ctx as CSharpMarshalContext; var fullType = marshal.FullType.Type; var type = Type.Desugar() as TemplateSpecializationType; ctx.Return.Write("new Flood.ResourceHandle<{0}>({1}{2}Id)", type.Arguments[0].Type, ctx.ReturnVarName, (fullType is PointerType) ? "->" : "."); }
public override string CLISignature(CLITypePrinterContext ctx) { var type = Type.Desugar() as TemplateSpecializationType; var arg = type.Arguments[0].Type.ToString(); if (string.IsNullOrEmpty(arg)) { arg = type.Template.Parameters[0].Name; } return(string.Format("Flood::ResourceHandle<{0}>", arg)); }
public static bool IsConstCharString(Type type) { var desugared = type.Desugar(); if (!(desugared is PointerType)) { return(false); } var pointer = desugared as PointerType; return(IsConstCharString(pointer)); }
public override bool VisitType(Type type, TypeQualifiers quals) { type = type.Desugar(); if (AlreadyVisited2(type)) { return(true); } recordStack.Push(type); type.Visit(this); recordStack.Pop(); return(false); }
private static Type GetEnumType(Type mappedType) { var type = mappedType.Desugar(); ClassTemplateSpecialization classTemplateSpecialization; var templateSpecializationType = type as TemplateSpecializationType; if (templateSpecializationType != null) { classTemplateSpecialization = templateSpecializationType.GetClassTemplateSpecialization(); } else { classTemplateSpecialization = (ClassTemplateSpecialization)((TagType)type).Declaration; } return(classTemplateSpecialization.Arguments[0].Type.Type); }
public bool FindTypeMapRecursive(Type type, out TypeMap typeMap) { while (true) { if (FindTypeMap(type, out typeMap)) { return(true); } var desugaredType = type.Desugar(); if (desugaredType == type) { return(false); } type = desugaredType; } }
public override string CSharpSignature(CSharpTypePrinterContext ctx) { if (ctx.CSharpKind == CSharpTypePrinterContextKind.Native) { if (ctx.FullType.Type is PointerType) { return("Flood.ResourceHandle*"); } // Handles only contain a single 32-bit unsigned int handle id. return("Flood.ResourceHandle"); } var type = Type.Desugar() as TemplateSpecializationType; return(string.Format("Flood.ResourceHandle<{0}>", type.Arguments[0].Type)); }
public static bool CheckTypeForSpecialization(Type type, Declaration container, Action <ClassTemplateSpecialization> addSpecialization, ITypeMapDatabase typeMaps, bool internalOnly = false) { type = type.Desugar(); type = (type.GetFinalPointee() ?? type).Desugar(); ClassTemplateSpecialization specialization = GetParentSpecialization(type); if (specialization == null) { return(true); } if (IsSpecializationNeeded(container, typeMaps, internalOnly, type, specialization)) { return(false); } if (!internalOnly) { if (IsSpecializationSelfContained(specialization, container)) { return(true); } if (IsMappedToPrimitive(typeMaps, type)) { return(true); } } if (specialization.Arguments.Select( a => a.Type.Type).Any(t => t != null && !CheckTypeForSpecialization(t, specialization, addSpecialization, typeMaps, internalOnly))) { return(false); } addSpecialization(specialization); return(true); }
private static Type GetEnumType(Type mappedType) { var type = mappedType.Desugar(); ClassTemplateSpecialization classTemplateSpecialization; var templateSpecializationType = type as TemplateSpecializationType; if (templateSpecializationType != null) { return(templateSpecializationType.Arguments[0].Type.Type); } var declaration = ((TagType)type).Declaration; if (declaration.IsDependent) { return(new TagType(((Class)declaration).TemplateParameters[0])); } classTemplateSpecialization = (ClassTemplateSpecialization)declaration; return(classTemplateSpecialization.Arguments[0].Type.Type); }
public bool FindTypeMap(Type type, out TypeMap typeMap) { typeMap = null; while (true) { var typePrinter = new CppTypePrinter(this); var output = type.Visit(typePrinter); if (FindTypeMap(output, out typeMap)) { return(true); } // Try to strip the global scope resolution operator. if (output.StartsWith("::")) { output = output.Substring(2); } if (FindTypeMap(output, out typeMap)) { return(true); } var desugaredType = type.Desugar(); if (desugaredType == type) { return(false); } type = desugaredType; } return(true); }
public bool FindTypeMapRecursive(Type type, out TypeMap typeMap) { while (true) { if (FindTypeMap(type, out typeMap)) return true; var desugaredType = type.Desugar(); if (desugaredType == type) return false; type = desugaredType; } }
public bool FindTypeMap(Type type, out TypeMap typeMap) { // Looks up the type in the cache map. if (typeMaps.ContainsKey(type)) { typeMap = typeMaps[type]; typeMap.Type = type; return(typeMap.IsEnabled); } var template = type as TemplateSpecializationType; if (template != null) { var specialization = template.GetClassTemplateSpecialization(); if (specialization != null && FindTypeMap(specialization, out typeMap)) { return(true); } if (template.Template.TemplatedDecl != null) { if (FindTypeMap(template.Template.TemplatedDecl, out typeMap)) { typeMap.Type = type; return(true); } return(false); } } Type desugared = type.Desugar(); desugared = (desugared.GetFinalPointee() ?? desugared).Desugar(); bool printExtra = desugared.IsPrimitiveType() || (desugared.GetFinalPointee() ?? desugared).Desugar().IsPrimitiveType(); var typePrinter = new CppTypePrinter(Context) { ResolveTypeMaps = false, PrintTypeQualifiers = printExtra, PrintTypeModifiers = printExtra, PrintLogicalNames = true }; typePrinter.PushContext(TypePrinterContextKind.Native); foreach (var resolveTypeDefs in new[] { false, true }) { foreach (var typePrintScopeKind in new[] { TypePrintScopeKind.Local, TypePrintScopeKind.Qualified }) { typePrinter.ResolveTypedefs = resolveTypeDefs; typePrinter.ScopeKind = typePrintScopeKind; var typeName = type.Visit(typePrinter); if (FindTypeMap(typeName, out typeMap)) { typeMap.Type = type; typeMaps[type] = typeMap; return(true); } } } typeMap = null; return(false); }