private void GenerateInclude(ASTRecord <Declaration> record) { var decl = record.Value; if (decl.Namespace == null) { return; } var typedefType = record.Value as TypedefNameDecl; // Find a type map for the declaration and use it if it exists. TypeMap typeMap; if (TypeMapDatabase.FindTypeMap(record.Value, out typeMap) || (typedefType != null && TypeMapDatabase.FindTypeMap(typedefType.Type.Desugar(), out typeMap))) { typeMap.CLITypeReference(this, record); return; } var typeRef = GetTypeReference(decl); if (typeRef != null) { typeRef.Include.InHeader |= IsIncludeInHeader(record); } }
public CSharpTypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals) { if (tag.Declaration == null) { return(string.Empty); } TypeMap typeMap; if (TypeMapDatabase.FindTypeMap(tag.Declaration, out typeMap)) { typeMap.Type = tag; Context.CSharpKind = ContextKind; Context.Type = tag; string type = typeMap.CSharpSignature(Context); if (!string.IsNullOrEmpty(type)) { return(new CSharpTypePrinterResult { Type = type, TypeMap = typeMap }); } } return(tag.Declaration.Visit(this)); }
public CSharpTypePrinterResult VisitTypedefType(TypedefType typedef, TypeQualifiers quals) { var decl = typedef.Declaration; TypeMap typeMap; if (TypeMapDatabase.FindTypeMap(decl, out typeMap)) { typeMap.Type = typedef; Context.CSharpKind = ContextKind; Context.Type = typedef; return(new CSharpTypePrinterResult() { Type = typeMap.CSharpSignature(Context), TypeMap = typeMap }); } FunctionType func; if (decl.Type.IsPointerTo <FunctionType>(out func)) { if (ContextKind == CSharpTypePrinterContextKind.Native) { return("global::System.IntPtr"); } // TODO: Use SafeIdentifier() return(VisitDeclaration(decl)); } return(decl.Type.Visit(this)); }
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 string VisitTagType(TagType tag, TypeQualifiers quals) { TypeMap typeMap = null; if (TypeMapDatabase.FindTypeMap(tag, out typeMap)) { typeMap.Type = tag; Context.Type = tag; return(typeMap.CLISignature(Context)); } Declaration decl = tag.Declaration; if (decl == null) { return(string.Empty); } return(VisitDeclaration(decl, quals)); }
private void GenerateInclude(ASTRecord <Declaration> record) { var decl = record.Value; if (decl.Namespace == null) { return; } // Find a type map for the declaration and use it if it exists. TypeMap typeMap; if (TypeMapDatabase.FindTypeMap(record.Value, out typeMap)) { typeMap.Declaration = record.Value; typeMap.CLITypeReference(this, record); return; } var translationUnit = decl.Namespace.TranslationUnit; if (translationUnit.IsSystemHeader) { return; } if (!decl.IsGenerated) { return; } if (IsBuiltinTypedef(decl)) { return; } var typeRef = GetTypeReference(decl); if (typeRef.Include.TranslationUnit == null) { typeRef.Include = new Include { File = GetIncludePath(translationUnit), TranslationUnit = translationUnit, Kind = translationUnit.IsGenerated ? Include.IncludeKind.Quoted : Include.IncludeKind.Angled, }; } typeRef.Include.InHeader |= IsIncludeInHeader(record); }
private static bool IsSpecializationNeeded(Declaration container, ITypeMapDatabase typeMaps, bool internalOnly, Type type, ClassTemplateSpecialization specialization) { typeMaps.FindTypeMap(type, out var typeMap); return((!internalOnly && (((specialization.Ignore || specialization.TemplatedDecl.TemplatedClass.Ignore) && typeMap == null) || specialization.Arguments.Any(a => specialization.UnsupportedTemplateArgument(a, typeMaps)) || container.Namespace == specialization)) || (!internalOnly && specialization.TemplatedDecl.TemplatedClass.IsIncomplete) || specialization is ClassTemplatePartialSpecialization); }
public string VisitTypedefType(TypedefType typedef, TypeQualifiers quals) { var decl = typedef.Declaration; TypeMap typeMap = null; if (TypeMapDatabase.FindTypeMap(decl, out typeMap)) { typeMap.Type = typedef; Context.Type = typedef; return(typeMap.CLISignature(Context)); } FunctionType func; if (decl.Type.IsPointerTo <FunctionType>(out func)) { // TODO: Use SafeIdentifier() return(string.Format("{0}^", VisitDeclaration(decl))); } return(decl.Type.Visit(this)); }
private void ProcessTypeMap(ASTRecord <Declaration> record) { TypeMap typeMap; if (!TypeMapDatabase.FindTypeMap(record.Value, out typeMap)) { return; } // Typemap must explicitly set the include file when one is required. GetTypeReference(record.Value).Include.File = ""; typeMap.Declaration = record.Value; typeMap.CLITypeReference(this, record); }
public static bool IsMappedToPrimitive(ITypeMapDatabase typeMaps, Type type) { if (!typeMaps.FindTypeMap(type, out var typeMap)) { return(false); } var typePrinterContext = new TypePrinterContext { Type = type }; var mappedTo = typeMap.CSharpSignatureType(typePrinterContext); mappedTo = mappedTo.Desugar(); mappedTo = (mappedTo.GetFinalPointee() ?? mappedTo).Desugar(); return(mappedTo.IsPrimitiveType() || mappedTo.IsPointerToPrimitiveType() || mappedTo.IsEnum()); }
private static bool IsMappedToPrimitive(ITypeMapDatabase typeMaps, Type type, ClassTemplateSpecialization specialization) { TypeMap typeMap; if (!typeMaps.FindTypeMap(specialization, out typeMap)) { return(false); } var typePrinterContext = new TypePrinterContext { Type = type }; var mappedTo = typeMap.CSharpSignatureType(typePrinterContext); mappedTo = mappedTo.Desugar(); mappedTo = (mappedTo.GetFinalPointee() ?? mappedTo).Desugar(); return(mappedTo.IsPrimitiveType() || mappedTo.IsPointerToPrimitiveType() || mappedTo.IsEnum()); }
private static bool FindTypeMap(ITypeMapDatabase typeMapDatabase, Class @class, out TypeMap typeMap) { return(typeMapDatabase.FindTypeMap(@class, out typeMap) || (@class.HasBase && FindTypeMap(typeMapDatabase, @class.Bases[0].Class, out typeMap))); }
private static bool FindTypeMap(ITypeMapDatabase typeMapDatabase, Class @class, out TypeMap typeMap) { return typeMapDatabase.FindTypeMap(@class, out typeMap) || (@class.HasBase && FindTypeMap(typeMapDatabase, @class.Bases[0].Class, out typeMap)); }
public override bool VisitFieldDecl(Field field) { if (field.Ignore) { return(false); } TypeMap typeMap; if (!typeMapDatabase.FindTypeMap(field.Type, out typeMap)) { return(false); } if (!(typeMap is EventMap)) { return(false); } field.ExplicityIgnored = true; ITypedDecl decl = field; var typedef = field.Type as TypedefType; if (typedef != null) { return(false); } var template = decl.Type as TemplateSpecializationType; var @params = template.Arguments.Select(param => new Parameter() { QualifiedType = param.Type }).ToList(); if (template.Template.TemplatedDecl.Name.StartsWith("Delegate")) { return(false); } // Clean up the event name. var names = StringHelpers.SplitCamelCase(field.Name); if (names.Length > 1 && names[0].Equals("On", StringComparison.InvariantCultureIgnoreCase)) { names = names.Skip(1).ToArray(); } var @event = new Event() { Name = string.Join(string.Empty, names), OriginalName = field.OriginalName, Namespace = field.Namespace, QualifiedType = field.QualifiedType, Parameters = @params }; field.Class.Events.Add(@event); return(true); }