Beispiel #1
0
 public DefaultGenerators(
     GlobalNamespaceProvider globalNamespace,
     IDocumentationLinker documentation,
     ExternalDocCommentsReader docReader,
     GeneratorConfig config,
     Logger logger)
 {
     Constant              = new ConstantCodeGenerator();
     Property              = new PropertyCodeGenerator(this, documentation, docReader);
     Enum                  = new EnumCodeGenerator(documentation, docReader);
     ExplicitOffsetField   = new FieldCodeGenerator(documentation, docReader, true);
     AutoLayoutField       = new FieldCodeGenerator(documentation, docReader, false);
     Struct                = new StructCodeGenerator(this, documentation, docReader);
     NativeStruct          = new NativeStructCodeGenerator(this, globalNamespace);
     NativeInvocation      = new NativeInvocationCodeGenerator(this, globalNamespace);
     Callable              = new CallableCodeGenerator(this, documentation, docReader, globalNamespace, logger);
     Method                = new MethodCodeGenerator(this);
     Function              = new FunctionCodeGenerator(this);
     Interface             = new InterfaceCodeGenerator(this, documentation, docReader, globalNamespace);
     Group                 = new GroupCodeGenerator(this, documentation, docReader);
     LocalInterop          = new LocalInteropCodeGenerator(this);
     InteropMethod         = new InteropMethodCodeGenerator();
     ShadowCallable        = new ShadowCallbackGenerator(this, globalNamespace);
     ReverseCallableProlog = new ReverseCallablePrologCodeGenerator(this, globalNamespace);
     Vtbl                  = new VtblGenerator(this, globalNamespace);
     Shadow                = new ShadowGenerator(this, globalNamespace);
     Marshalling           = new MarshallingRegistry(globalNamespace, logger);
     Config                = config;
 }
        public override IEnumerable <MemberDeclarationSyntax> GenerateCode(CsStruct csElement)
        {
            var innerStructs = csElement.InnerStructs.SelectMany(GenerateCode);

            var constants = csElement.Variables.SelectMany(var => Generators.Constant.GenerateCode(var));

            var fields = csElement.PublicFields.SelectMany(field =>
            {
                var explicitLayout = !csElement.HasMarshalType && csElement.ExplicitLayout;
                var generator      = explicitLayout ? Generators.ExplicitOffsetField : Generators.AutoLayoutField;
                return(generator.GenerateCode(field));
            });

            var marshallingStructAndConversions = csElement.HasMarshalType && !csElement.HasCustomMarshal
                                                      ? Generators.NativeStruct.GenerateCode(csElement)
                                                      : Enumerable.Empty <MemberDeclarationSyntax>();

            var attributeList = !csElement.HasMarshalType
                                    ? SingletonList(NativeStructCodeGenerator.GenerateStructLayoutAttribute(csElement))
                                    : default;

            var modifierTokenList = csElement.VisibilityTokenList.Add(Token(SyntaxKind.PartialKeyword));
            var identifier        = Identifier(csElement.Name);
            var memberList        = List(
                innerStructs.Concat(constants).Concat(fields).Concat(marshallingStructAndConversions)
                );

            MemberDeclarationSyntax declaration = csElement.GenerateAsClass
                                                      ? ClassDeclaration(
                attributeList,
                modifierTokenList,
                identifier,
                default,
 public DefaultGenerators(GeneratorConfig config, Ioc ioc)
 {
     Constant              = new ConstantCodeGenerator(ioc);
     Property              = new PropertyCodeGenerator(ioc);
     Enum                  = new EnumCodeGenerator(ioc);
     ExplicitOffsetField   = new FieldCodeGenerator(ioc, true);
     AutoLayoutField       = new FieldCodeGenerator(ioc, false);
     Struct                = new StructCodeGenerator(ioc);
     NativeStruct          = new NativeStructCodeGenerator(ioc);
     NativeInvocation      = new NativeInvocationCodeGenerator(ioc);
     Callable              = new CallableCodeGenerator(ioc);
     Method                = new MethodCodeGenerator(ioc);
     Function              = new FunctionCodeGenerator(ioc);
     Interface             = new InterfaceCodeGenerator(ioc);
     Group                 = new GroupCodeGenerator(ioc);
     ShadowCallable        = new ShadowCallbackGenerator(ioc);
     ReverseCallableProlog = new ReverseCallablePrologCodeGenerator(ioc);
     Vtbl                  = new VtblGenerator(ioc);
     Shadow                = new ShadowGenerator(ioc);
     Marshalling           = new MarshallingRegistry(ioc);
     Config                = config;
 }