Beispiel #1
0
    public static void Generate(TypeMap typeMap, string fname, string name)
    {
        StreamReader  sr  = new StreamReader(fname);
        XmlSerializer sz  = new XmlSerializer(typeof(xcb));
        xcb           xcb = (xcb)sz.Deserialize(sr);

        string extName = xcb.extensionxname ?? "";

        TypesGenerator tg = new TypesGenerator(typeMap);

        tg.Generate(xcb, name, extName);

        InterfaceGenerator ig = new InterfaceGenerator(typeMap);

        ig.Generate(xcb, name);

        ClassGenerator cg = new ClassGenerator(typeMap);

        cg.Generate(xcb, name, extName);
    }
Beispiel #2
0
        public void Generate(xcb xcb, string name)
        {
            InterfaceDeclarationSyntax ids = InterfaceDeclaration("I" + name);

            foreach (@request req in xcb.Items.Where(r => r is @request).Cast <@request>())
            {
                ids = ids.AddMembers(GenFunction(req, name));
            }

            CompilationUnitSyntax cu = CompilationUnit().
                                       AddUsings(UsingDirective(IdentifierName("System"))).
                                       WithMembers(SingletonList <MemberDeclarationSyntax>(ids)).
                                       NormalizeWhitespace();

            using (FileStream fs = new FileStream(name + "Iface.cs", FileMode.Create))
                using (TextWriter tw = new StreamWriter(fs))
                {
                    cu.WriteTo(tw);
                }
        }
Beispiel #3
0
    public static void Generate(string fname, string name)
    {
        StreamReader  sr  = new StreamReader(fname);
        XmlSerializer sz  = new XmlSerializer(typeof(xcb));
        xcb           xcb = (xcb)sz.Deserialize(sr);

        extName     = xcb.extensionxname == null ? "" : xcb.extensionxname;
        isExtension = extName != "";

        cw  = new CodeWriter(name + ".cs");
        cwt = new CodeWriter(name + "Types.cs");
        cwi = new CodeWriter(name + "Iface.cs");

        cw.WriteLine("using System;", cwt, cwi);
        cw.WriteLine("using System.Collections;", cwt);
        cw.WriteLine("using System.Collections.Generic;", cwt);
        cw.WriteLine("using System.Runtime.InteropServices;", cwt);
        cw.WriteLine("using Mono.Unix;", cwt);
        cw.WriteLine("using Xnb.Protocol." + "Xnb" + ";", cwt);
        cw.WriteLine("using Xnb.Protocol." + "XProto" + ";", cwt);
        cw.WriteLine("", cwt, cwi);
        //cw.WriteLine ("namespace Xnb", cwt);

        cw.WriteLine("namespace Xnb");
        cwt.WriteLine("namespace Xnb.Protocol." + name);

        cw.WriteLine("{", cwt);
        cw.WriteLine("using Protocol." + name + ";");
        cw.WriteLine("public class " + name + " : Extension");
        cwi.WriteLine("public interface I" + name);
        cw.WriteLine("{", cwi);
        cw.WriteLine("public override string XName");
        cw.WriteLine("{");
        cw.WriteLine("get {");
        cw.WriteLine("return \"" + extName + "\";");
        cw.WriteLine("}");
        cw.WriteLine("}");
        cw.WriteLine();

        cwt.WriteLine("#pragma warning disable 0169, 0414");

        foreach (object o in xcb.Items)
        {
            if (o == null)
            {
                continue;
            }
            else if (o is @xidtype)
            {
                GenXidType(o as @xidtype);
            }
            else if (o is @errorcopy)
            {
                GenErrorCopy(o as @errorcopy);
            }
            else if (o is @eventcopy)
            {
                GenEventCopy(o as @eventcopy);
            }
            else if (o is @struct)
            {
                GenStruct(o as @struct);
            }
            else if (o is @union)
            {
                GenUnion(o as @union);
            }
            else if (o is @enum)
            {
                GenEnum(o as @enum);
            }
            else if (o is @event)
            {
                GenEvent(o as @event, name);
            }
            else if (o is @request)
            {
                GenRequest(o as @request, name);
                GenFunction(o as @request, name);
            }
            else if (o is @error)
            {
                GenError(o as @error, name);
            }
        }

        cwt.WriteLine("#pragma warning restore 0169, 0414");

        cwi.WriteLine("}");
        cw.WriteLine("}");
        cw.WriteLine("}", cwt);

        cw.Close();
        cwt.Close();
        cwi.Close();
    }
Beispiel #4
0
        public void Generate(xcb xcb, string name, string extName)
        {
            isExtension = !string.IsNullOrEmpty(extName);

            List <MemberDeclarationSyntax> classMembers = new List <MemberDeclarationSyntax>();

            AccessorDeclarationSyntax xnameGetter =
                AccessorDeclaration(SyntaxKind.GetAccessorDeclaration,
                                    Block(ReturnStatement(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(extName)))));

            PropertyDeclarationSyntax xnameProperty =
                PropertyDeclaration(List <AttributeListSyntax>(),
                                    TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.OverrideKeyword)),
                                    PredefinedType(Token(SyntaxKind.StringKeyword)),
                                    null, Identifier("XName"), AccessorList(SingletonList(xnameGetter)));

            classMembers.Add(xnameProperty);

            foreach (object o in xcb.Items)
            {
                if (o is @xidtype)
                {
                    classMembers.Add(GenXidType(o as @xidtype));
                }
                else if (o is @errorcopy)
                {
                    classMembers.Add(GenErrorCopy(o as @errorcopy));
                }
                else if (o is @eventcopy)
                {
                    classMembers.Add(GenEventCopy(o as @eventcopy));
                }
                else if (o is @struct)
                {
                    classMembers.Add(GenStruct(o as @struct));
                }
                else if (o is @union)
                {
                    classMembers.Add(GenUnion(o as @union));
                }
                else if (o is @enum)
                {
                    classMembers.Add(GenEnum(o as @enum));
                }
                else if (o is @event)
                {
                    classMembers.Add(GenEvent(o as @event));
                }
                else if (o is @request)
                {
                    classMembers.Add(GenRequest(o as @request));
                }
                else if (o is @error)
                {
                    classMembers.Add(GenError(o as @error));
                }
            }

            ClassDeclarationSyntax cd =
                ClassDeclaration(name).
                AddBaseListTypes(SimpleBaseType(IdentifierName("Extension"))).
                WithMembers(List(classMembers));

            List <UsingDirectiveSyntax> usings =
                new[]
            {
                "System", "System.Collections", "System.Collections.Generic", "System.Runtime.InteropServices",
                "Mono.Unix", "XNB.Protocol.XNB", "XNB.Protocol.XProto"
            }.
            Select(IdentifierName).
            Select(UsingDirective).
            ToList();

            NamespaceDeclarationSyntax ns =
                NamespaceDeclaration(IdentifierName("XNB"),
                                     List <ExternAliasDirectiveSyntax>(),
                                     List <UsingDirectiveSyntax>(),
                                     SingletonList <MemberDeclarationSyntax>(cd));

            CompilationUnitSyntax cu = CompilationUnit().
                                       WithUsings(List(usings)).
                                       WithMembers(SingletonList <MemberDeclarationSyntax>(ns)).
                                       NormalizeWhitespace();

            using (FileStream fs = new FileStream(name + ".cs", FileMode.Create))
                using (TextWriter tw = new StreamWriter(fs))
                {
                    cu.WriteTo(tw);
                }
        }