public override void AcceptVisitor(StatementVisitor visitor)
 {
     visitor.VisitParameterExpression(this);
 }
Beispiel #2
0
 public override R Accept <R>(StatementVisitor <R> vis)
 {
     return(vis.Visit(this));
 }
Beispiel #3
0
 void CheckUpdatedCompilation(Compilation originalCompilation, Compilation updatedCompilation){
   this.WriteOutAnyErrors();
   if (originalCompilation != updatedCompilation){
     Console.WriteLine("update of {0} resulted in a new compilation instance", originalCompilation.TargetModule.Name);
     return;
   }
   CompilationUnit updatedCompilationUnit = null;
   for (int i = 0, n = updatedCompilation.CompilationUnits == null ? 0 : updatedCompilation.CompilationUnits.Count; i < n; i++){
     if (updatedCompilation.CompilationUnits[i] == null)
       Console.WriteLine("updated compilation unit {0} is null", i);
     else if (updatedCompilation.CompilationUnits[i].Name.UniqueIdKey == this.compilationUnit.Name.UniqueIdKey){
       updatedCompilationUnit = updatedCompilation.CompilationUnits[i];
       break;
     }
   }
   StatementVisitor statVis = new StatementVisitor();
   statVis.Visit(updatedCompilationUnit);
 }
Beispiel #4
0
        public override MemberDeclarationSyntax VisitForClass(ConversionContext context, ClassDeclarationSyntax classSyntax, ConstructorDeclaration ctorDecl)
        {
            var ctorSyntax = SyntaxFactory.ConstructorDeclaration(classSyntax.Identifier.Value.ToString())
                             .WithLeadingTrivia(SyntaxFactory.CarriageReturnLineFeed);

            var mods = ctorDecl.getModifiers();

            if (mods.HasFlag(Modifier.PUBLIC))
            {
                ctorSyntax = ctorSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
            }
            if (mods.HasFlag(Modifier.PROTECTED))
            {
                ctorSyntax = ctorSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword));
            }
            if (mods.HasFlag(Modifier.PRIVATE))
            {
                ctorSyntax = ctorSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword));
            }

            var parameters = ctorDecl.getParameters().ToList <Parameter>();

            if (parameters != null && parameters.Count > 0)
            {
                var paramSyntaxes = new List <ParameterSyntax>();

                foreach (var param in parameters)
                {
                    var name        = param.getId().toString();
                    var paramSyntax = SyntaxFactory.Parameter(SyntaxFactory.ParseToken(TypeHelper.ConvertIdentifierName(name)));

                    if (param.isVarArgs())
                    {
                        paramSyntax = paramSyntax.WithType(SyntaxFactory.ParseTypeName(TypeHelper.ConvertType(param.getType().toString()) + "[]"))
                                      .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ParamsKeyword)));
                    }
                    else
                    {
                        paramSyntax = paramSyntax.WithType(SyntaxFactory.ParseTypeName(TypeHelper.ConvertType(param.getType().toString())));
                    }

                    paramSyntaxes.Add(paramSyntax);
                }

                ctorSyntax = ctorSyntax.AddParameterListParameters(paramSyntaxes.ToArray());
            }

            //chaws: var block = ctorDecl.getBlock();
            var block      = ctorDecl.getBody();
            var statements = block.getStmts().ToList <Statement>();

            // handle special case for constructor invocation
            if (statements != null && statements.Count > 0 && statements[0] is ExplicitConstructorInvocationStmt)
            {
                var ctorInvStmt = (ExplicitConstructorInvocationStmt)statements[0];
                statements.RemoveAt(0);

                ArgumentListSyntax argsSyntax = null;

                var initargs = ctorInvStmt.getArgs().ToList <Expression>();

                if (initargs != null && initargs.Count > 0)
                {
                    var initargslist = new List <ArgumentSyntax>();

                    foreach (var arg in initargs)
                    {
                        var argsyn = ExpressionVisitor.VisitExpression(context, arg);
                        initargslist.Add(SyntaxFactory.Argument(argsyn));
                    }

                    argsSyntax = SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(initargslist, Enumerable.Repeat(SyntaxFactory.Token(SyntaxKind.CommaToken), initargslist.Count - 1)));
                }

                ConstructorInitializerSyntax ctorinitsyn;

                if (ctorInvStmt.isThis())
                {
                    ctorinitsyn = SyntaxFactory.ConstructorInitializer(SyntaxKind.ThisConstructorInitializer, argsSyntax);
                }
                else
                {
                    ctorinitsyn = SyntaxFactory.ConstructorInitializer(SyntaxKind.BaseConstructorInitializer, argsSyntax);
                }

                ctorSyntax = ctorSyntax.WithInitializer(ctorinitsyn);
            }

            var statementSyntax = StatementVisitor.VisitStatements(context, statements);

            ctorSyntax = ctorSyntax.AddBodyStatements(statementSyntax.ToArray());

            return(ctorSyntax);
        }
Beispiel #5
0
        public override void VisitConstructorDeclaration(IConstructorDeclaration decl, SST context)
        {
            _cancellationToken.ThrowIfCancellationRequested();

            var nameGen   = new UniqueVariableNameGenerator();
            var exprVisit = new ExpressionVisitor(nameGen, _marker);

            if (decl.DeclaredElement != null)
            {
                var methodName = decl.DeclaredElement.GetName <IMethodName>();

                var sstDecl = new MethodDeclaration
                {
                    Name         = methodName,
                    IsEntryPoint = _entryPoints.Contains(methodName)
                };
                context.Methods.Add(sstDecl);

                if (decl == _marker.HandlingNode && _marker.Case == CompletionCase.InBody)
                {
                    sstDecl.Body.Add(new ExpressionStatement {
                        Expression = new CompletionExpression()
                    });
                }

                if (decl.Initializer != null)
                {
                    var name = Names.UnknownMethod;

                    var substitution = decl.DeclaredElement.IdSubstitution;
                    var resolvedRef  = decl.Initializer.Reference.Resolve();
                    if (resolvedRef.DeclaredElement != null)
                    {
                        name = resolvedRef.DeclaredElement.GetName <IMethodName>(substitution);
                    }

                    var args = Lists.NewList <ISimpleExpression>();
                    foreach (var p in decl.Initializer.Arguments)
                    {
                        var expr = exprVisit.ToSimpleExpression(p.Value, sstDecl.Body);
                        args.Add(expr);
                    }

                    var varId = new VariableReference().Identifier; // default value
                    if (decl.Initializer.Instance != null)
                    {
                        var tokenType = decl.Initializer.Instance.GetTokenType();
                        var isThis    = CSharpTokenType.THIS_KEYWORD == tokenType;
                        var isBase    = CSharpTokenType.BASE_KEYWORD == tokenType;

                        varId = isThis ? "this" : isBase ? "base" : varId;
                    }

                    sstDecl.Body.Add(
                        new ExpressionStatement
                    {
                        Expression = new InvocationExpression
                        {
                            Reference = new VariableReference {
                                Identifier = varId
                            },
                            MethodName = name,
                            Parameters = args
                        }
                    });
                }

                if (!decl.IsAbstract)
                {
                    var bodyVisitor = new StatementVisitor(nameGen, _marker);

                    Execute.AndSupressExceptions(
                        delegate { decl.Accept(bodyVisitor, sstDecl.Body); });
                }
            }
        }
Beispiel #6
0
 public abstract void AcceptVisitor(StatementVisitor visitor);
 public override void visit(StatementVisitor visitor)
 {
     visitor.visit_import(this);
 }
Beispiel #8
0
 public override void AcceptVisitor(StatementVisitor visitor)
 {
     this.Delegate?.AcceptVisitor(visitor);
 }
 public override void visit(StatementVisitor visitor)
 {
     visitor.visit_expression(this);
 }
 public override void visit(StatementVisitor visitor)
 {
     visitor.visit_using(this);
 }
 public override void visit(StatementVisitor visitor)
 {
     visitor.visit_block(this);
 }
 public abstract void visit(StatementVisitor visitor);
 public override void visit(StatementVisitor visitor)
 {
     visitor.visit_while(this);
 }
Beispiel #14
0
 public abstract void Visit(StatementVisitor visitor);
 public override void visit(StatementVisitor visitor)
 {
     visitor.visit_return(this);
 }
 public override void visit(StatementVisitor visitor)
 {
     visitor.visit_interrupt(this);
 }
 public override void visit(StatementVisitor visitor)
 {
     visitor.visit_continue(this);
 }
 public abstract Statement visit(StatementVisitor v);
Beispiel #19
0
 public void AcceptVisitor(StatementVisitor visitor)
 {
     visitor.VisitReferenceToMethodParameter(this);
 }
Beispiel #20
0
 public override T AcceptVisitor <T, C>(StatementVisitor <T, C> visitor, C context)
 {
     return(visitor.VisitVariableDeclarationStatement(this, context));
 }
Beispiel #21
0
 public override void AcceptVisitor(StatementVisitor visitor)
 {
     Condition.AcceptVisitor(visitor);
     WhenTrue.AcceptVisitor(visitor);
     WhenFalse.AcceptVisitor(visitor);
 }
Beispiel #22
0
 public override void AcceptVisitor(StatementVisitor visitor)
 {
     visitor.VisitReferenceToTypeMember(TypeOperand);
 }
        public override MemberDeclarationSyntax VisitForClass(ConversionContext context, ClassDeclarationSyntax classSyntax, MethodDeclaration methodDecl)
        {
            var returnType     = methodDecl.getType();
            var returnTypeName = TypeHelper.ConvertType(returnType.toString());

            var methodName = TypeHelper.Capitalize(methodDecl.getName());

            methodName = TypeHelper.ReplaceCommonMethodNames(methodName);

            var methodSyntax = SyntaxFactory.MethodDeclaration(SyntaxFactory.ParseTypeName(returnTypeName), methodName);

            // TODO: Call methodDecl.getTypeParameters() to see if the method is generic

            var mods = methodDecl.getModifiers();

            if (mods.HasFlag(Modifier.PUBLIC))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
            }
            if (mods.HasFlag(Modifier.PROTECTED))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword));
            }
            if (mods.HasFlag(Modifier.PRIVATE))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword));
            }
            if (mods.HasFlag(Modifier.STATIC))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword));
            }
            if (mods.HasFlag(Modifier.ABSTRACT))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.AbstractKeyword));
            }

            var  annotations = methodDecl.getAnnotations().ToList <AnnotationExpr>();
            bool isOverride  = false;

            // TODO: figure out how to check for a non-interface base type
            if (annotations != null &&
                annotations.Count > 0)
            {
                foreach (var annotation in annotations)
                {
                    string name = annotation.getName().getName();
                    if (name == "Override")
                    {
                        methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.OverrideKeyword));
                        isOverride   = true;
                    }
                }
            }

            if (!mods.HasFlag(Modifier.FINAL) &&
                !mods.HasFlag(Modifier.ABSTRACT) &&
                !mods.HasFlag(Modifier.STATIC) &&
                !mods.HasFlag(Modifier.PRIVATE) &&
                !isOverride &&
                !classSyntax.Modifiers.Any(i => i.Kind() == SyntaxKind.SealedKeyword))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.VirtualKeyword));
            }

            var parameters = methodDecl.getParameters().ToList <Parameter>();

            if (parameters != null && parameters.Count > 0)
            {
                var paramSyntaxes = new List <ParameterSyntax>();

                foreach (var param in parameters)
                {
                    string typeName   = TypeHelper.ConvertType(param.getType().toString());
                    string identifier = TypeHelper.ConvertIdentifierName(param.getId().getName());

                    if ((param.getId().getArrayCount() > 0 && !typeName.EndsWith("[]")) || param.isVarArgs())
                    {
                        typeName += "[]";
                    }

                    SyntaxTokenList modifiers = SyntaxFactory.TokenList();

                    if (param.isVarArgs())
                    {
                        modifiers = SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ParamsKeyword));
                    }

                    var paramSyntax = SyntaxFactory.Parameter(attributeLists: SyntaxFactory.List <AttributeListSyntax>(),
                                                              modifiers: modifiers,
                                                              type: SyntaxFactory.ParseTypeName(typeName),
                                                              identifier: SyntaxFactory.ParseToken(identifier),
                                                              @default: null);

                    paramSyntaxes.Add(paramSyntax);
                }

                methodSyntax = methodSyntax.AddParameterListParameters(paramSyntaxes.ToArray());
            }

            var block = methodDecl.getBody();

            if (block == null)
            {
                // i.e. abstract method
                methodSyntax = methodSyntax.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken));

                return(methodSyntax.AddComment(context, methodDecl));
            }

            var statements      = block.getStmts().ToList <Statement>();
            var statementSyntax = StatementVisitor.VisitStatements(context, statements);

            // Look for comments at the end of the method body
            var trailingComments = block
                                   .getChildrenNodes().AsEnumerable <Node>()
                                   .OrderByDescending(n => n.getBeginLine()).ThenByDescending(n => n.getBeginColumn())
                                   .TakeWhile(n => n is Comment)
                                   .Cast <Comment>()
                                   .Reverse()
                                   .Select(cmt => SyntaxFactory.Comment(cmt.toString().TrimEnd('\r', '\n')));

            if (mods.HasFlag(Modifier.SYNCHRONIZED))
            {
                LockStatementSyntax lockSyntax;
                BlockSyntax         lockBlock = SyntaxFactory.Block(statementSyntax);

                if (mods.HasFlag(Modifier.STATIC))
                {
                    lockSyntax = SyntaxFactory.LockStatement(SyntaxFactory.TypeOfExpression(SyntaxFactory.ParseTypeName(classSyntax.Identifier.Value.ToString())), lockBlock);
                }
                else
                {
                    lockSyntax = SyntaxFactory.LockStatement(SyntaxFactory.ThisExpression(), lockBlock);
                }

                methodSyntax = methodSyntax.AddBodyStatements(lockSyntax);
            }
            else
            {
                methodSyntax = methodSyntax.AddBodyStatements(statementSyntax.ToArray());
            }

            // Add any trailing comments before the closing bracket
            var closeBraceToken = methodSyntax.Body.CloseBraceToken
                                  .WithLeadingTrivia(trailingComments);

            methodSyntax = methodSyntax.ReplaceNode(methodSyntax.Body,
                                                    methodSyntax.Body.WithCloseBraceToken(closeBraceToken));

            return(methodSyntax.AddComment(context, methodDecl));
            // Trailing
        }
Beispiel #24
0
 public override void AcceptVisitor(StatementVisitor visitor)
 {
 }
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public override void AcceptVisitor(StatementVisitor visitor)
        {
            visitor.VisitAnonymousDelegateExpression(this);
            Body.AcceptVisitor(visitor);
        }
Beispiel #26
0
 public override T AcceptVisitor <T, C>(StatementVisitor <T, C> visitor, C context)
 {
     return(visitor.VisitIfStatement(this, context));
 }
        public override MemberDeclarationSyntax VisitForClass(ConversionContext context, ClassDeclarationSyntax classSyntax, MethodDeclaration methodDecl)
        {
            var returnType     = methodDecl.getType();
            var returnTypeName = TypeHelper.ConvertType(returnType.toString());

            var methodName = TypeHelper.Capitalize(methodDecl.getName());

            methodName = TypeHelper.ReplaceCommonMethodNames(methodName);

            var methodSyntax = SyntaxFactory.MethodDeclaration(SyntaxFactory.ParseTypeName(returnTypeName), methodName);

            var mods = methodDecl.getModifiers();

            if (mods.HasFlag(Modifier.PUBLIC))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
            }
            if (mods.HasFlag(Modifier.PROTECTED))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword));
            }
            if (mods.HasFlag(Modifier.PRIVATE))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.PrivateKeyword));
            }
            if (mods.HasFlag(Modifier.STATIC))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword));
            }
            if (mods.HasFlag(Modifier.ABSTRACT))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.AbstractKeyword));
            }

            var  annotations = methodDecl.getAnnotations().ToList <AnnotationExpr>();
            bool isOverride  = false;

            // TODO: figure out how to check for a non-interface base type
            if (annotations != null &&
                annotations.Count > 0)
            {
                foreach (var annotation in annotations)
                {
                    string name = annotation.getName().getName();
                    if (name == "Override")
                    {
                        methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.OverrideKeyword));
                        isOverride   = true;
                    }
                }
            }

            if (!mods.HasFlag(Modifier.FINAL) &&
                !mods.HasFlag(Modifier.ABSTRACT) &&
                !mods.HasFlag(Modifier.STATIC) &&
                !mods.HasFlag(Modifier.PRIVATE) &&
                !isOverride &&
                !classSyntax.Modifiers.Any(i => i.Kind() == SyntaxKind.SealedKeyword))
            {
                methodSyntax = methodSyntax.AddModifiers(SyntaxFactory.Token(SyntaxKind.VirtualKeyword));
            }

            var parameters = methodDecl.getParameters().ToList <Parameter>();

            if (parameters != null && parameters.Count > 0)
            {
                var paramSyntaxes = new List <ParameterSyntax>();

                foreach (var param in parameters)
                {
                    string typeName   = TypeHelper.ConvertType(param.getType().toString());
                    string identifier = TypeHelper.ConvertIdentifierName(param.getId().getName());

                    if ((param.getId().getArrayCount() > 0 && !typeName.EndsWith("[]")) || param.isVarArgs())
                    {
                        typeName += "[]";
                    }

                    SyntaxTokenList modifiers = SyntaxFactory.TokenList();

                    if (param.isVarArgs())
                    {
                        modifiers = SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.ParamsKeyword));
                    }

                    var paramSyntax = SyntaxFactory.Parameter(
                        attributeLists: new SyntaxList <AttributeListSyntax>(),
                        modifiers: modifiers,
                        type: SyntaxFactory.ParseTypeName(typeName),
                        identifier: SyntaxFactory.ParseToken(identifier),
                        @default: null);

                    paramSyntaxes.Add(paramSyntax);
                }

                methodSyntax = methodSyntax.AddParameterListParameters(paramSyntaxes.ToArray());
            }

            var block = methodDecl.getBody();

            if (block == null)
            {
                // i.e. abstract method
                methodSyntax = methodSyntax.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken));

                return(methodSyntax);
            }

            var statements = block.getStmts().ToList <Statement>();

            var statementSyntax = StatementVisitor.VisitStatements(context, statements);

            if (mods.HasFlag(Modifier.SYNCHRONIZED))
            {
                LockStatementSyntax lockSyntax;
                BlockSyntax         lockBlock = SyntaxFactory.Block(statementSyntax);

                if (mods.HasFlag(Modifier.STATIC))
                {
                    lockSyntax = SyntaxFactory.LockStatement(SyntaxFactory.TypeOfExpression(SyntaxFactory.ParseTypeName(classSyntax.Identifier.Value.ToString())), lockBlock);
                }
                else
                {
                    lockSyntax = SyntaxFactory.LockStatement(SyntaxFactory.ThisExpression(), lockBlock);
                }

                methodSyntax = methodSyntax.AddBodyStatements(lockSyntax);
            }
            else
            {
                methodSyntax = methodSyntax.AddBodyStatements(statementSyntax.ToArray());
            }

            return(methodSyntax);
        }
 ///////////////////////////////////////////////////////////////////
 public override Statement visit(StatementVisitor v)
 {
     return(v.visit(this));
 }
Beispiel #29
0
 public override void AcceptVisitor(StatementVisitor visitor)
 {
     visitor.VisitReThrowStatement(this);
 }
Beispiel #30
0
 public override void Accept(StatementVisitor vis)
 {
     vis.Visit(this);
 }
Beispiel #31
0
 public abstract R Accept <R>(StatementVisitor <R> vis);
Beispiel #32
0
 public override void Visit(StatementVisitor visitor)
 {
     visitor.Visit(this);
 }
 public override void visit(StatementVisitor visitor)
 {
     visitor.visit_trycatch(this);
 }