Пример #1
0
        /// <summary>
        /// Checks if a given type is invalid, which can happen for a number of
        /// reasons: incomplete definitions, being explicitly ignored, or also
        /// by being a type we do not know how to handle.
        /// </summary>
        private bool HasInvalidType(Type type, Module module, out string msg)
        {
            if (type == null)
            {
                msg = "null";
                return(true);
            }

            if (!IsTypeComplete(type))
            {
                msg = "incomplete";
                return(true);
            }

            if (IsTypeIgnored(type))
            {
                msg = "ignored";
                return(true);
            }

            if (Options.DoAllModulesHaveLibraries() &&
                module != Options.SystemModule && ASTUtils.IsTypeExternal(module, type))
            {
                msg = "external";
                return(true);
            }

            msg = null;
            return(false);
        }
Пример #2
0
 /// <summary>
 /// Moves specializations which use in their arguments types located outside
 /// the library their template is located in, to the module of said external types.
 /// </summary>
 /// <param name="template">The template to check for external specializations.</param>
 private static void MoveExternalSpecializations(Class template)
 {
     for (int i = template.Specializations.Count - 1; i >= 0; i--)
     {
         var specialization = template.Specializations[i];
         var modules        = (from arg in specialization.Arguments
                               where arg.Type.Type != null &&
                               ASTUtils.IsTypeExternal(
                                   template.TranslationUnit.Module, arg.Type.Type)
                               let module = arg.Type.Type.GetModule()
                                            where module != null
                                            select module).ToList().TopologicalSort(m => m.Dependencies);
         if (modules.Any())
         {
             var module = modules.Last();
             module.ExternalClassTemplateSpecializations.Add(specialization);
             template.Specializations.RemoveAt(i);
         }
     }
 }
Пример #3
0
        private bool HasInvalidType(Type type, Declaration decl, out string msg)
        {
            if (type == null)
            {
                msg = "null";
                return(true);
            }

            if (!IsTypeComplete(type))
            {
                msg = "incomplete";
                return(true);
            }

            if (IsTypeIgnored(type))
            {
                msg = "ignored";
                return(true);
            }

            var module = decl.TranslationUnit.Module;

            if (Options.DoAllModulesHaveLibraries() &&
                module != Options.SystemModule && ASTUtils.IsTypeExternal(module, type))
            {
                msg = "external";
                return(true);
            }

            var arrayType = type as ArrayType;

            if (arrayType != null && arrayType.SizeType == ArrayType.ArraySize.Constant &&
                arrayType.Size == 0)
            {
                msg = "zero-sized array";
                return(true);
            }

            msg = null;
            return(false);
        }
Пример #4
0
        private void CleanSpecializations(Class template)
        {
            template.Specializations.RemoveAll(s =>
                                               !specializations.Contains(s) && !internalSpecializations.Contains(s));

            foreach (var specialization in template.Specializations.Where(
                         s => !s.IsExplicitlyGenerated &&
                         (s.Arguments.Any(a =>
            {
                if (a.Kind != TemplateArgument.ArgumentKind.Declaration &&
                    a.Kind != TemplateArgument.ArgumentKind.Template &&
                    a.Kind != TemplateArgument.ArgumentKind.Type)
                {
                    return(true);
                }

                var type = a.Type.Type.Desugar();
                if (ASTUtils.IsTypeExternal(template.TranslationUnit.Module, type) ||
                    type.IsPrimitiveType(PrimitiveType.Void))
                {
                    return(true);
                }

                var typeIgnoreChecker = new TypeIgnoreChecker(TypeMaps);
                type.Visit(typeIgnoreChecker);
                return(typeIgnoreChecker.IsIgnored);
            }) ||
                          s.SpecializationKind == TemplateSpecializationKind.ExplicitSpecialization ||
                          s is ClassTemplatePartialSpecialization ||
                          internalSpecializations.Contains(s))))
            {
                specialization.ExplicitlyIgnore();
            }

            Func <TemplateArgument, bool> allPointers =
                a => a.Type.Type != null && a.Type.Type.IsAddress();
            var groups = (from specialization in template.Specializations
                          group specialization by specialization.Arguments.All(allPointers)
                          into @group
                          select @group).ToList();

            foreach (var group in groups.Where(g => g.Key))
            {
                foreach (var specialization in group.Skip(1))
                {
                    template.Specializations.Remove(specialization);
                }
            }

            for (int i = template.Specializations.Count - 1; i >= 0; i--)
            {
                var specialization = template.Specializations[i];
                if (specialization is ClassTemplatePartialSpecialization &&
                    !specialization.Arguments.All(allPointers))
                {
                    template.Specializations.RemoveAt(i);
                }
            }

            if (!template.IsExplicitlyGenerated &&
                template.Specializations.All(s => s.Ignore))
            {
                template.ExplicitlyIgnore();
            }
        }