Esempio n. 1
0
        public bool FindTypeMap(Declaration decl, Type type, out TypeMap typeMap)
        {
            // We try to find type maps from the most qualified to less qualified
            // types. Example: '::std::vector', 'std::vector' and 'vector'

            var typePrinter = new CppTypePrinter {
                PrintLogicalNames = true
            };

            if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
            {
                typeMap.Declaration = decl;
                typeMap.Type        = type;
                return(true);
            }

            typePrinter.PrintScopeKind = TypePrintScopeKind.Qualified;
            if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
            {
                typeMap.Declaration = decl;
                typeMap.Type        = type;
                return(true);
            }

            typePrinter.ResolveTypedefs = true;
            if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
            {
                typeMap.Declaration = decl;
                typeMap.Type        = type;
                return(true);
            }
            typePrinter.ResolveTypedefs = false;

            typePrinter.PrintScopeKind = TypePrintScopeKind.Local;
            if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
            {
                typeMap.Declaration = decl;
                typeMap.Type        = type;
                return(true);
            }

            var specialization = decl as ClassTemplateSpecialization;

            if (specialization != null &&
                FindTypeMap(specialization.TemplatedDecl.Visit(typePrinter), out typeMap))
            {
                typeMap.Declaration = decl;
                typeMap.Type        = type;
                return(true);
            }

            var typedef = decl as TypedefDecl;

            return(typedef != null && FindTypeMap(typedef.Type, out typeMap));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
 private bool FindTypeMap(Declaration decl, Type type, out TypeMap typeMap, CppTypePrinter typePrinter)
 {
     if (FindTypeMap(decl.Visit(typePrinter), out typeMap))
     {
         if (type != null && typeMap.Type == null)
         {
             typeMap.Type   = type;
             typeMaps[type] = typeMap;
         }
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
        public bool FindTypeMap(Type type, out TypeMap typeMap)
        {
            if (typeMaps.ContainsKey(type))
            {
                typeMap = typeMaps[type];
                return(typeMap.IsEnabled);
            }

            var typePrinter = new CppTypePrinter
            {
                PrintTypeQualifiers = false,
                PrintTypeModifiers  = false,
                PrintLogicalNames   = true
            };

            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));
                }
            }

            typePrinter.PrintScopeKind = TypePrintScopeKind.Local;
            if (FindTypeMap(type.Visit(typePrinter), out typeMap))
            {
                typeMap.Type   = type;
                typeMaps[type] = typeMap;
                return(true);
            }

            typePrinter.PrintScopeKind = TypePrintScopeKind.Qualified;
            if (FindTypeMap(type.Visit(typePrinter), out typeMap))
            {
                typeMap.Type   = type;
                typeMaps[type] = typeMap;
                return(true);
            }

            var typedef = type as TypedefType;

            return(typedef != null && FindTypeMap(typedef.Declaration, type, out typeMap));
        }
Esempio n. 5
0
        public bool FindTypeMap(Type type, out TypeMap typeMap)
        {
            var typePrinter = new CppTypePrinter(false, false)
            {
                PrintLogicalNames = true
            };

            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));
                }
            }

            if (FindTypeMap(type.Visit(typePrinter), out typeMap))
            {
                typeMap.Type = type;
                return(true);
            }

            if (FindTypeMap(type.Visit(typePrinter), out typeMap))
            {
                typeMap.Type = type;
                return(true);
            }

            typePrinter.PrintScopeKind = CppTypePrintScopeKind.Qualified;
            if (FindTypeMap(type.Visit(typePrinter), out typeMap))
            {
                typeMap.Type = type;
                return(true);
            }

            var typedef = type as TypedefType;

            return(typedef != null && FindTypeMap(typedef.Declaration, type, out typeMap));
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }