示例#1
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));
        }