コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: CSharpTypePrinter.cs プロジェクト: UIKit0/CppSharp
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: CLITypePrinter.cs プロジェクト: gpetrou/CppSharp
        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));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: Utils.cs プロジェクト: tornado12345/CppSharp
        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);
        }
コード例 #8
0
ファイル: CLITypePrinter.cs プロジェクト: cDoru/CppSharp
        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));
        }
コード例 #9
0
ファイル: CLITypeReferences.cs プロジェクト: cDoru/CppSharp
        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);
        }
コード例 #10
0
        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());
        }
コード例 #11
0
ファイル: Utils.cs プロジェクト: sbertout/CppSharp
        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());
        }
コード例 #12
0
 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)));
 }
コード例 #13
0
ファイル: CSharpMarshal.cs プロジェクト: vovkasm/CppSharp
 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));
 }
コード例 #14
0
ファイル: Flood.cs プロジェクト: aldyjepara/flood
        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);
        }