コード例 #1
0
        public VisitedEventArgs(ILTranslationContext context, T node, IEnumerable <Syntax> results)
        {
            Context = context;
            Node    = node;
            var c = (results as ICollection <Syntax>) ?? results.ToArray();

            Results          = (c as IList <Syntax>) ?? c.ToList();
            _OriginalResults = Results;
        }
コード例 #2
0
        protected virtual D.IModuleDeclaration ResolveModule(ILTranslationContext data, string fullName)
        {
            var ms = Statements;
            var m  = ms.OfType <D.IModuleDeclaration>().FirstOrDefault(e => e.Name == fullName);

            if (m == null)
            {
                m = new D.NamespaceDeclaration()
                {
                    Name = fullName
                };
                ms.Add(m);
            }

            return(m);
        }
コード例 #3
0
        private IEnumerable <D.Parameter> GetParameters(ILTranslationContext data, AstNodeCollection <ParameterDeclaration> parameters)
        {
            foreach (var p in parameters)
            {
                var dp = new D.Parameter()
                {
                    ParameterName = p.Name,
                };
                dp.ParameterType = ResolveType(p, p.Type);

                dp.Decorators = GetDecorators(p.Attributes, data);

                if (p.DefaultExpression?.IsNull == false)
                {
                    dp.Initializer = (Expression)p.DefaultExpression.AcceptVisitor(this, data).LastOrDefault();
                }
                dp.IsOptional = dp.Initializer != null;
                yield return(dp);
            }
        }
コード例 #4
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitTypeDeclaration(TypeDeclaration typeDeclaration, ILTranslationContext data)
 => OnVisiting(data, typeDeclaration, VisitingTypeDeclaration)
 ?? OnVisited(data, typeDeclaration, VisitedTypeDeclaration, TranslateTypeDeclaration(typeDeclaration, data));
コード例 #5
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective, ILTranslationContext data)
 => Enumerable.Empty <Syntax>();
コード例 #6
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, ILTranslationContext data)
 => OnVisiting(data, namespaceDeclaration, VisitingNamespaceDeclaration)
 ?? OnVisited(data, namespaceDeclaration, VisitedNamespaceDeclaration, TranslateNamespaceDeclaration(namespaceDeclaration, data));
コード例 #7
0
        protected virtual IEnumerable <Syntax> TranslateAttribute(Attribute attribute, ILTranslationContext data)
        {
            var d = new D.Decorator();

            d.Name = GetTypeName(attribute.Type);

            foreach (var c in attribute.Children)
            {
                if (c is SimpleType)
                {
                    continue;
                }
                else
                {
                    foreach (var cr in c.AcceptVisitor(this, data))
                    {
                        d.Parameters.Add((Expression)cr);
                    }
                }
            }

            yield return(d);
        }
コード例 #8
0
 protected virtual IEnumerable <Syntax> TranslateAttributeSection(AttributeSection attributeSection, ILTranslationContext data)
 {
     foreach (var c in attributeSection.Children)
     {
         foreach (var cr in c.AcceptVisitor(this, data))
         {
             yield return(cr);
         }
     }
 }
コード例 #9
0
 protected virtual IEnumerable <Syntax> TranslateIndexerExpression(IndexerExpression indexerExpression, ILTranslationContext data)
 {
     yield return(new E.IndexerExpression()
     {
         Object = GetExpression(indexerExpression.Target, data),
         Index = GetExpression(indexerExpression.Arguments.Single(), data),
     });
 }
コード例 #10
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitIndexerExpression(IndexerExpression indexerExpression, ILTranslationContext data)
 => OnVisiting(data, indexerExpression, VisitingIndexerExpression)
 ?? OnVisited(data, indexerExpression, VisitedIndexerExpression, TranslateIndexerExpression(indexerExpression, data));
コード例 #11
0
        protected virtual E.CallExpression TranslateInvocationExpression(InvocationExpression invocationExpression, ILTranslationContext data)
        {
            var inv = new E.CallExpression();

            var mre = invocationExpression.Target as MemberReferenceExpression;

            if (mre != null)
            {
                // TODO: method mapping

                foreach (var t in mre.TypeArguments)
                {
                    inv.TypeArguments.Add(ResolveType(mre, t));
                }

                inv.Target = new E.PropertyExpression()
                {
                    Object   = GetExpression(mre.Target, data),
                    Property = mre.MemberName
                };
            }
            else
            {
                inv.Target = GetExpression(invocationExpression.Target, data);
            }

            foreach (var p in invocationExpression.Arguments)
            {
                inv.Parameters.Add(GetExpression(p, data));
            }

            return(inv);
        }
コード例 #12
0
        protected virtual IEnumerable <Syntax> TranslateUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, ILTranslationContext data)
        {
            if (unaryOperatorExpression.Operator == UnaryOperatorType.Await)
            {
                data.HasAwait = true;

                return(new[]
                {
                    new E.AwaitExpression()
                    {
                        Operand = GetExpression(unaryOperatorExpression.Expression, data)
                    }
                });
            }
            var e = new E.UnaryExpression();

            e.Operand = GetExpression(unaryOperatorExpression.Expression, data);
            switch (unaryOperatorExpression.Operator)
            {
            case UnaryOperatorType.Plus:
                e.Operator = E.UnaryOperator.Plus;
                break;

            case UnaryOperatorType.Minus:
                e.Operator = E.UnaryOperator.Minus;
                break;

            case UnaryOperatorType.Increment:
                e.Operator = E.UnaryOperator.PrefixIncrement;
                break;

            case UnaryOperatorType.PostIncrement:
                e.Operator = E.UnaryOperator.PostfixIncrement;
                break;

            case UnaryOperatorType.Decrement:
                e.Operator = E.UnaryOperator.PrefixDecrement;
                break;

            case UnaryOperatorType.PostDecrement:
                e.Operator = E.UnaryOperator.PostfixDecrement;
                break;

            case UnaryOperatorType.Not:
                e.Operator = E.UnaryOperator.LogicalNot;
                break;

            case UnaryOperatorType.BitNot:
                e.Operator = E.UnaryOperator.BitwiseNot;
                break;

            default:
                throw GetNotImplementedException();
            }

            return(new[] { e });
        }
コード例 #13
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, ILTranslationContext data)
 => OnVisiting(data, unaryOperatorExpression, VisitingUnaryOperatorExpression)
 ?? OnVisited(data, unaryOperatorExpression, VisitedUnaryOperatorExpression, TranslateUnaryOperatorExpression(unaryOperatorExpression, data));
コード例 #14
0
 protected virtual IEnumerable <Syntax> TranslateParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, ILTranslationContext data)
 => parenthesizedExpression.Expression.AcceptVisitor(this, data);
コード例 #15
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, ILTranslationContext data)
 => OnVisiting(data, parenthesizedExpression, VisitingParenthesizedExpression)
 ?? OnVisited(data, parenthesizedExpression, VisitedParenthesizedExpression, TranslateParenthesizedExpression(parenthesizedExpression, data));
コード例 #16
0
        protected virtual IEnumerable <Syntax> TranslateMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, ILTranslationContext data)
        {
            if (memberReferenceExpression.TypeArguments.Any())
            {
                throw GetNotImplementedException();
            }

            yield return(new E.PropertyExpression()
            {
                Object = GetExpression(memberReferenceExpression.Target, data),
                Property = memberReferenceExpression.MemberName
            });
        }
コード例 #17
0
 private Expression GetExpression(ICSharpCode.NRefactory.CSharp.Expression expression, ILTranslationContext data)
 => expression?.IsNull != false ? null : expression.AcceptVisitor(this, data).Cast <Expression>().Single();
コード例 #18
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, ILTranslationContext data)
 => OnVisiting(data, objectCreateExpression, VisitingObjectCreateExpression)
 ?? OnVisited(data, objectCreateExpression, VisitedObjectCreateExpression, TranslateObjectCreateExpression(objectCreateExpression, data));
コード例 #19
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitAttributeSection(AttributeSection attributeSection, ILTranslationContext data)
 => OnVisiting(data, attributeSection, VisitingAttributeSection)
 ?? OnVisited(data, attributeSection, VisitedAttributeSection, TranslateAttributeSection(attributeSection, data));
コード例 #20
0
        protected virtual IEnumerable <Syntax> TranslateObjectCreateExpression(ObjectCreateExpression objectCreateExpression, ILTranslationContext data)
        {
            E.NewExpression ne;

            var clrType = objectCreateExpression.Type.ResolveClrType();

            if (clrType != null)
            {
                if (typeof(MulticastDelegate).IsAssignableFrom(clrType))
                {
                    var p = objectCreateExpression.Arguments.OfType <MemberReferenceExpression>().FirstOrDefault();

                    if (p != null)
                    {
                        var t = p.Target.AcceptVisitor(this, data).ToArray();
                        if (t.Length == 1)
                        {
                            var te = (Expression)t[0];
                            yield return(te.Property(p.MemberName).Property("bind").Call(te));

                            yield break;
                        }
                    }
                }

                ne      = new E.NewExpression();
                ne.Type = ResolveClrType(objectCreateExpression, clrType).ToExpression();
            }
            else
            {
                ne      = new E.NewExpression();
                ne.Type = ResolveType(objectCreateExpression, objectCreateExpression.Type).ToExpression();
            }

            foreach (var p in objectCreateExpression.Arguments)
            {
                ne.Parameters.Add(p.AcceptVisitor(this, data).Cast <Expression>().Single());
            }

            // TODO: initializer

            yield return(ne);
        }
コード例 #21
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitAttribute(Attribute attribute, ILTranslationContext data)
 => OnVisiting(data, attribute, VisitingAttribute)
 ?? OnVisited(data, attribute, VisitedAttribute, TranslateAttribute(attribute, data));
コード例 #22
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, ILTranslationContext data)
 => OnVisiting(data, binaryOperatorExpression, VisitingBinaryOperatorExpression)
 ?? OnVisited(data, binaryOperatorExpression, VisitedBinaryOperatorExpression, TranslateBinaryOperatorExpression(binaryOperatorExpression, data));
コード例 #23
0
        private Collection <D.Decorator> GetDecorators(IEnumerable <AttributeSection> section, ILTranslationContext data)
        {
            Collection <D.Decorator> c = null;

            foreach (var s in section)
            {
                foreach (var a in s.Attributes)
                {
                    foreach (D.Decorator d in a.AcceptVisitor(this, data))
                    {
                        (c ?? (c = new Collection <D.Decorator>())).Add(d);
                    }
                }
            }
            return(c);
        }
コード例 #24
0
 protected virtual IEnumerable <Syntax> TranslateBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, ILTranslationContext data)
 {
     yield return(new E.BinaryExpression()
     {
         Left = GetExpression(binaryOperatorExpression.Left, data),
         Right = GetExpression(binaryOperatorExpression.Right, data),
         Operator = GetOperator(binaryOperatorExpression.Operator)
     });
 }
コード例 #25
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitUsingDeclaration(UsingDeclaration usingDeclaration, ILTranslationContext data)
 => Enumerable.Empty <Syntax>();
コード例 #26
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitAssignmentExpression(AssignmentExpression assignmentExpression, ILTranslationContext data)
 => OnVisiting(data, assignmentExpression, VisitingAssignmentExpression)
 ?? OnVisited(data, assignmentExpression, VisitedAssignmentExpression, TranslateAssignmentExpression(assignmentExpression, data));
コード例 #27
0
        protected virtual IEnumerable <Syntax> TranslateNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, ILTranslationContext data)
        {
            var ns = ResolveModule(data, namespaceDeclaration.FullName);

            foreach (var c in namespaceDeclaration.Children)
            {
                if (c is MemberType)
                {
                    continue;
                }
                if (c is NamespaceDeclaration)
                {
                    foreach (var cr in c.AcceptVisitor(this, data))
                    {
                        yield return(cr);
                    }
                }
                else
                {
                    foreach (var cr in c.AcceptVisitor(this, data))
                    {
                        ns.Members.Add(cr);
                    }
                }
            }

            yield return((Syntax)ns);
        }
コード例 #28
0
 protected virtual IEnumerable <Syntax> TranslateAssignmentExpression(AssignmentExpression assignmentExpression, ILTranslationContext data)
 {
     yield return(new E.AssignmentExpression()
     {
         Target = GetExpression(assignmentExpression.Left, data),
         Value = GetExpression(assignmentExpression.Right, data),
         CompoundOperator = assignmentExpression.Operator == AssignmentOperatorType.Assign ? E.BinaryOperator.Default : GetOperator(assignmentExpression.Operator)
     });
 }
コード例 #29
0
        protected virtual IEnumerable <Syntax> TranslateTypeDeclaration(TypeDeclaration typeDeclaration, ILTranslationContext data)
        {
            D.ITypeDeclaration td;
            switch (typeDeclaration.ClassType)
            {
            case ClassType.Class:
            {
                var cd = new D.ClassDeclaration()
                {
                    IsAbstract = typeDeclaration.HasModifier(Modifiers.Abstract)
                };
                td = cd;

                foreach (var p in GetTypeParameters(typeDeclaration.TypeParameters, typeDeclaration.Constraints))
                {
                    cd.TypeParameters.Add(p);
                }
            }
            break;

            case ClassType.Struct:
            {
                var cd = new D.ClassDeclaration();

                td = cd;

                foreach (var p in GetTypeParameters(typeDeclaration.TypeParameters, typeDeclaration.Constraints))
                {
                    cd.TypeParameters.Add(p);
                }
            }
            break;

            case ClassType.Interface:
                var id = new D.InterfaceDeclaration();
                td = id;

                foreach (var p in GetTypeParameters(typeDeclaration.TypeParameters, typeDeclaration.Constraints))
                {
                    id.TypeParameters.Add(p);
                }

                break;

            case ClassType.Enum:
                td = new D.EnumDeclaration();
                break;

            default:
                throw GetNotImplementedException();
            }

            var decType = typeDeclaration.Parent as TypeDeclaration;

            td.Name     = typeDeclaration.Name;
            td.IsExport = typeDeclaration.HasModifier(Modifiers.Public);

            while (decType != null)
            {
                td.Name      = decType.Name + "$" + td.Name;
                td.IsExport &= decType.HasModifier(Modifiers.Public);
                decType      = decType.Parent as TypeDeclaration;
            }

            foreach (var bt in typeDeclaration.BaseTypes)
            {
                var dt = ResolveType(typeDeclaration, bt);

                var cd = td as D.ClassDeclaration;
                if (cd != null && cd.BaseType == null && dt.IsClass == true)
                {
                    cd.BaseType = dt;
                }
                else if (cd != null)
                {
                    cd.Interfaces.Add(dt);
                }
                else
                {
                    ((D.InterfaceDeclaration)td).BaseTypes.Add(dt);
                }
            }

            foreach (var c in typeDeclaration.Attributes)
            {
                foreach (var cr in c.AcceptVisitor(this, data))
                {
                    td.Decorators.Add((D.Decorator)cr);
                }
            }

            foreach (var c in typeDeclaration.Members)
            {
                var ctd = c as TypeDeclaration;
                if (ctd != null)
                {
                    foreach (var cr in c.AcceptVisitor(this, data))
                    {
                        yield return(cr);
                    }
                    continue;
                }
                foreach (var cr in c.AcceptVisitor(this, data))
                {
                    td.Members.Add(cr);
                }
            }

            yield return((Syntax)td);
        }
コード例 #30
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, ILTranslationContext data)
 => OnVisiting(data, memberReferenceExpression, VisitingMemberReferenceExpression)
 ?? OnVisited(data, memberReferenceExpression, VisitedMemberReferenceExpression, TranslateMemberReferenceExpression(memberReferenceExpression, data));