コード例 #1
0
ファイル: UnitCompiler.cs プロジェクト: m039/SharpCpp
 protected override void Visit(YClass @class)
 {
     if (_w.Class == @class)
     {
         _w.Visit(_w._builder, @class);
     }
 }
コード例 #2
0
        public GenerationUnit(YClass @class)
        {
            Class = @class;

            _header = new GeneratedFile {
                Name = Class.Name,
                Type = GeneratedFile.GeneratedFileType.HEADER
            };

            _source = new GeneratedFile {
                Name = Class.Name,
                Type = GeneratedFile.GeneratedFileType.SOURCE
            };
        }
コード例 #3
0
            internal protected override void Visit(StringBuilder builder, YClass @class)
            {
                if ([email protected])
                {
                    var nestedLevelsCount = _nestedLevels.Count - 1;
                    if (nestedLevelsCount >= 0 && _nestedLevels[nestedLevelsCount] is YClass)
                    {
                        CloseClass(builder);
                        _nestedLevels.RemoveAt(nestedLevelsCount);
                    }
                }

                builder.Append("class " + @class.Name + "{");

                ClearBuilders();

                GetBuilder(Public, Constructor)
                .Append(@class.Name + "();");

                builder.Append(PrivateMark);
                builder.Append(PublicMark);

                _nestedLevels.Add(@class);
            }
コード例 #4
0
ファイル: YSyntaxWalker.cs プロジェクト: m039/SharpCpp
 protected virtual void Visit(YClass @class)
 {
 }
コード例 #5
0
ファイル: SourceCompiler.cs プロジェクト: m039/SharpCpp
 public SourceWalker(YClass @class, TypeMapper.IncludeFinder finder) : base(@class, finder)
 {
     _typeMapper = new TypeMapper(finder, new HashSet <string>()); // ignore includes for now
 }
コード例 #6
0
ファイル: SourceCompiler.cs プロジェクト: m039/SharpCpp
 public override UnitWalker CreateUnitWalker(YClass @class, TypeMapper.IncludeFinder finder)
 {
     return(new SourceWalker(@class, finder));
 }
コード例 #7
0
 public HeaderWalker(YClass @class, TypeMapper.IncludeFinder finder) : base(@class, finder)
 {
     _typeMapper = new TypeMapper(finder, _includes);
 }
コード例 #8
0
ファイル: UnitCompiler.cs プロジェクト: m039/SharpCpp
 public abstract UnitWalker CreateUnitWalker(YClass @class, TypeMapper.IncludeFinder finder);
コード例 #9
0
ファイル: UnitCompiler.cs プロジェクト: m039/SharpCpp
 internal protected virtual void Visit(StringBuilder builder, YClass @class)
 {
 }
コード例 #10
0
ファイル: UnitCompiler.cs プロジェクト: m039/SharpCpp
 protected UnitWalker(YClass @class, TypeMapper.IncludeFinder finder)
 {
     Class         = @class;
     IncludeFinder = finder;
 }
コード例 #11
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);
            }
        }
コード例 #12
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);
                }
            }
        }