Example #1
0
        public override void CollectDependencies()
        {
            //var isFlags = Type.CustomAttributes.Any(a => a.AttributeType.Name == "FlagsAttribute");
            var underlyingType = Type.Fields.Single(f => f.Name == "value__").FieldType;

            UnderlyingTypeName = TypeHelpers.GetTypeName(Generator, this, underlyingType, TypeUsage.Raw);
        }
Example #2
0
        public string MakeOutType(Generator generator, ITypeRequestSource source, bool isFactoryMethod)
        {
            string outType = String.Join(", ", OutTypes.Select(o => TypeHelpers.GetTypeName(generator, source, o.Item1, (o.Item2 || isFactoryMethod) ? TypeUsage.OutNonNull : TypeUsage.Out)));

            if (OutTypes.Count() != 1)
            {
                outType = "(" + outType + ")"; // also works for count == 0 (empty tuple)
            }
            return(outType);
        }
Example #3
0
        public override void CollectDependencies()
        {
            foreach (var staticType in statics)
            {
                AddDependency(Generator.GetTypeDefinition(staticType));
            }

            factories = GetFactoryTypes().Select(f => TypeHelpers.GetTypeName(Generator, this, f, TypeUsage.Alias)).ToArray();

            if (Type.Interfaces.Count > 0)
            {
                var defaultInterface = TypeHelpers.GetDefaultInterface(Type);
                aliasedType = TypeHelpers.GetTypeName(Generator, this, defaultInterface, TypeUsage.Alias);
            }

            var factoryMethods = GetFactoryTypes().OrderBy(f => f.FullName).SelectMany(f => Generator.GetTypeDefinition(f).Methods).ToArray();
            var staticMethods  = statics.OrderBy(s => s.FullName).SelectMany(s => Generator.GetTypeDefinition(s).Methods).ToArray();

            foreach (var m in factoryMethods)
            {
                methodWrappers.Add(new ClassMethodDef(m, this, true));
            }
            foreach (var m in staticMethods)
            {
                methodWrappers.Add(new ClassMethodDef(m, this, false));
            }

            // fix name clashes in method wrappers (caused by overloads from different interfaces)
            foreach (var nameToFix in methodWrappers.GroupBy(m => m.Name).Where(g => g.Count() > 1))
            {
                // we expect that there is a single base name (modulo suffix numbers) for all clashing interfaces
                string baseName = nameToFix.Select(n => n.WrappedMethod.DeclaringType.Name.TrimEnd('1', '2', '3', '4', '5', '6', '7', '8', '9', '0')).Distinct().Single();
                foreach (var m in nameToFix)
                {
                    // so far this is always "2"
                    var nameSuffix = m.WrappedMethod.DeclaringType.Name.Replace(baseName, "");
                    m.FixupName(nameSuffix);
                }
            }
        }
Example #4
0
        public IEnumerable <string> GetParameterDeclarations()
        {
            yield return("&self");

            foreach (var p in Method.Parameters)
            {
                Assert(!p.IsReturnValue);
                int?lengthIs          = null;
                var lengthIsAttribute = p.CustomAttributes.SingleOrDefault(a => a.AttributeType.Name == "LengthIsAttribute");
                if (lengthIsAttribute != null)
                {
                    lengthIs = (int)lengthIsAttribute.ConstructorArguments[0].Value;
                }

                if (p.ParameterType.IsArray)
                {
                    // need additional input size parameter (even if parameter is marked as [Out])
                    yield return(NameHelpers.FirstToLower(p.Name) + "Size: u32");
                }
                else if (p.ParameterType.IsByReference && (p.ParameterType as ByReferenceType).ElementType.IsArray)
                {
                    Assert(!lengthIs.HasValue);
                    // need additional output size parameter
                    yield return(NameHelpers.FirstToLower(p.Name) + "Size: *mut u32");
                }
                yield return(NameHelpers.PreventKeywords(NameHelpers.FirstToLower(p.Name)) + ": " + TypeHelpers.GetTypeName(DeclaringType.Generator, this, p.ParameterType, TypeUsage.Raw));
            }
            if (Method.ReturnType.FullName != "System.Void")
            {
                if (Method.ReturnType.IsArray)
                {
                    yield return("outSize: *mut u32");
                }
                yield return("out: *mut " + TypeHelpers.GetTypeName(DeclaringType.Generator, this, Method.ReturnType, TypeUsage.Raw));
            }
        }
Example #5
0
 public override void CollectDependencies()
 {
     fields = Type.Fields.Select(f => NameHelpers.PreventKeywords(f.Name) + ": " + TypeHelpers.GetTypeName(Generator, this, f.FieldType, TypeUsage.Raw)).ToList();
 }