Ejemplo n.º 1
0
 public DefaultGenerators(Ioc ioc)
 {
     ExpressionConstant = new ExpressionConstantCodeGenerator(ioc);
     GuidConstant       = new GuidConstantCodeGenerator(ioc);
     ResultConstant     = new ResultConstantCodeGenerator(ioc);
     ResultRegistration = new ResultRegistrationCodeGenerator(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);
     FunctionImport        = new FunctionImportCodeGenerator(ioc);
     Interface             = new InterfaceCodeGenerator(ioc);
     Group                 = new GroupCodeGenerator(ioc);
     ShadowCallable        = new ShadowCallbackGenerator(ioc);
     ReverseCallableProlog = new ReverseCallablePrologCodeGenerator(ioc);
     Vtbl        = new VtblGenerator(ioc);
     Marshalling = new MarshallingRegistry(ioc);
     Config      = ioc.GeneratorConfig;
 }
Ejemplo n.º 2
0
    public override MemberDeclarationSyntax GenerateCode(CsStruct csElement)
    {
        var list = NewMemberList;

        list.AddRange(csElement.InnerStructs, Generators.Struct);
        list.AddRange(csElement.ExpressionConstants, Generators.ExpressionConstant);
        list.AddRange(csElement.GuidConstants, Generators.GuidConstant);
        list.AddRange(csElement.ResultConstants, Generators.ResultConstant);

        var explicitLayout = !csElement.HasMarshalType && csElement.ExplicitLayout;
        var generator      = explicitLayout ? Generators.ExplicitOffsetField : Generators.AutoLayoutField;

        list.AddRange(csElement.PublicFields, generator);

        if (csElement.HasMarshalType && !csElement.HasCustomMarshal)
        {
            list.Add(csElement, Generators.NativeStruct);
        }

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

        var modifierTokenList = csElement.VisibilityTokenList.Add(Token(SyntaxKind.PartialKeyword));
        var identifier        = Identifier(csElement.Name);

        MemberDeclarationSyntax declaration = csElement.GenerateAsClass
                                                  ? ClassDeclaration(
            attributeList,
            modifierTokenList,
            identifier,
            default,