Exemplo n.º 1
0
            internal protected override void Visit(StringBuilder builder, YMethod method)
            {
                base.Visit(builder, method);

                if (method.IsPure)
                {
                    return;
                }

                if (method is YDestructor)
                {
                    builder.Append($"{ Class.Name }::~{ Class.Name }()");
                }
                else
                {
                    builder.Append(_typeMapper.ValueOf(method.Signature.ReturnType));
                    builder.Append(" ");
                    builder.Append($"{ Class.Name }::{ method.Name }");

                    builder.Append("(");
                    builder.Append(_typeMapper.ValueOf(method.Signature.Parameters));
                    builder.Append(")");
                }

                builder.AppendEx(method.Body);
            }
Exemplo n.º 2
0
 protected override void Visit(YMethod @method)
 {
     if (_w.Class.ParentOf(method))
     {
         _w.Visit(_w._builder, @method);
     }
 }
Exemplo n.º 3
0
            internal protected override void Visit(StringBuilder builder, YMethod method)
            {
                StringBuilder b;

                if (method.Visibility == Private)
                {
                    b = GetBuilder(Private, Method);
                }
                else if (method.Visibility == Public)
                {
                    b = GetBuilder(Public, Method);
                }
                else
                {
                    throw new TException("Unsupported visibility");
                }

                if (method.IsVirtual)
                {
                    b.Append("virtual ");
                }

                if (method is YDestructor)
                {
                    // todo move this declaration to the bottom of the generated file

                    b.Append("~" + Class.Name + "()");
                }
                else
                {
                    b.Append(_typeMapper.ValueOf(method.Signature.ReturnType));
                    b.Append(" ");
                    b.Append(method.Signature.Name);

                    b.Append("(");
                    b.Append(_typeMapper.ValueOf(method.Signature.Parameters));
                    b.Append(")");
                }

                if (method.IsPure)
                {
                    b.Append("=0");
                }

                b.Append(";");
            }
Exemplo n.º 4
0
 protected virtual void Visit(YMethod @method)
 {
 }
Exemplo n.º 5
0
 internal protected virtual void Visit(StringBuilder builder, YMethod @method)
 {
 }
Exemplo n.º 6
0
        void ProcessInterfaces(YNamespace @namespace, NamespaceDeclarationSyntax inputNamespace)
        {
            // Interfaces:

            foreach (var inputInterace in inputNamespace.ChildNodes().OfType <InterfaceDeclarationSyntax>())
            {
                var interfaceName = inputInterace.GetName();
                if (interfaceName == "")
                {
                    continue;
                }

                var @interface = new YClass(interfaceName);
                @namespace.AddChild(@interface);

                _generationUnits.Add(new GenerationUnit(@interface));

                // Methods:

                foreach (var inputMethod in inputInterace.ChildNodes().OfType <MethodDeclarationSyntax>())
                {
                    var     name             = inputMethod.Identifier.ToString();
                    var     methodReturnType = inputMethod.ReturnType;
                    var     parameterList    = inputMethod.ParameterList;
                    YMethod method;

                    // Signature:

                    if (parameterList.Parameters.Count() <= 0)
                    {
                        method = new YMethod(name, inputMethod.ReturnType.GetYType());
                    }
                    else
                    {
                        var @params = new List <YParameter>();

                        foreach (var p in parameterList.Parameters)
                        {
                            @params.Add(new YParameter(p.GetName(), p.Type.GetYType()));
                        }

                        method = new YMethod(name, inputMethod.ReturnType.GetYType(), @params.ToArray());
                    }

                    // Body:

                    // all methods of an interface are public and pure by default
                    method.IsPure     = true;
                    method.Visibility = YVisibility.Public;
                    @interface.AddChild(method);
                }

                // Misc:

                var destructor = new YDestructor();

                destructor.IsVirtual  = true;
                destructor.Visibility = YVisibility.Public;
                destructor.Body       = new YBlock();

                @interface.AddChild(destructor);
            }
        }
Exemplo n.º 7
0
        void ProcessClasses(YNamespace @namespace, NamespaceDeclarationSyntax inputNamespace)
        {
            // Classes:

            foreach (var inputClass in inputNamespace.ChildNodes().OfType <ClassDeclarationSyntax>())
            {
                var className = inputClass.GetName();
                if (className == "")
                {
                    continue;
                }

                var @class = new YClass(className);
                @namespace.AddChild(@class);

                _generationUnits.Add(new GenerationUnit(@class));

                // Fields:

                foreach (var inputField in inputClass.ChildNodes().OfType <FieldDeclarationSyntax>())
                {
                    var declaration     = inputField.Declaration;
                    var declarationType = declaration.Type;
                    var variables       = declaration.Variables;

                    if (variables.Count == 1)
                    {
                        var variable = variables[0];

                        var field = new YField()
                        {
                            Type = declarationType.GetYType(),
                            Name = variable.GetName()
                        };

                        field.Visibility = inputField.Modifiers.GetYVisibility();

                        // expresions: literal

                        // todo process negative numbers

                        if (variable.Initializer?.Value is LiteralExpressionSyntax)
                        {
                            var literalExperssion = (LiteralExpressionSyntax)variable.Initializer.Value;

                            if (literalExperssion.Token.Value is int)
                            {
                                field.Value = new YConstExpr((int)literalExperssion.Token.Value);
                            }
                        }

                        @class.AddChild(field);
                    }
                    else
                    {
                        throw new TException("Unsupported");
                    }
                }

                // Methods:

                foreach (var inputMethod in inputClass.ChildNodes().OfType <MethodDeclarationSyntax>())
                {
                    var     name             = inputMethod.Identifier.ToString();
                    var     methodReturnType = inputMethod.ReturnType;
                    var     parameterList    = inputMethod.ParameterList;
                    YMethod method;

                    // Signature:

                    if (parameterList.Parameters.Count() <= 0)
                    {
                        method = new YMethod(name, inputMethod.ReturnType.GetYType());
                    }
                    else
                    {
                        var @params = new List <YParameter>();

                        foreach (var p in parameterList.Parameters)
                        {
                            @params.Add(new YParameter(p.GetName(), p.Type.GetYType()));
                        }

                        method = new YMethod(name, inputMethod.ReturnType.GetYType(), @params.ToArray());
                    }

                    // Body:

                    method.Visibility = inputMethod.Modifiers.GetYVisibility();
                    method.Body       = ProcessStatement(inputMethod.Body);
                    @class.AddChild(method);
                }
            }
        }