public static RoslynVisitor GetInstance(Dictionary <CSharpSyntaxNode, uint> csmap, CrossEdgeFiller crossEdgeFiller)
 {
     if (Instance == null)
     {
         Instance = new RoslynVisitor();
     }
     _map             = csmap;
     _crossEdgeFiller = crossEdgeFiller;
     return(Instance);
 }
예제 #2
0
 /// <summary>
 /// </summary>
 /// <param name="node"></param>
 /// <param name="crossEdgeFiller"></param>
 public static void CreateMethodCallEdgeFromIdentifier(IdentifierNameSyntax node,
                                                       CrossEdgeFiller crossEdgeFiller)
 {
     CreateMethodCallFromExpression(node.GetParent <BinaryExpressionSyntax>( ), ExpressionKind.BinaryExpression,
                                    crossEdgeFiller);
     CreateMethodCallFromExpression(node.GetParent <PostfixUnaryExpressionSyntax>( ),
                                    ExpressionKind.PostfixUnaryExpression, crossEdgeFiller);
     CreateMethodCallFromExpression(node.GetParent <PrefixUnaryExpressionSyntax>( ),
                                    ExpressionKind.PrefixUnaryExpression, crossEdgeFiller);
     CreateMethodCallFromExpression(node.GetParent <AssignmentExpressionSyntax>( ),
                                    ExpressionKind.AssigmentExpression, crossEdgeFiller);
 }
예제 #3
0
        /// <summary>
        ///     Create crose edge for the Class through the Using edge
        /// </summary>
        /// <param name="node"></param>
        /// <param name="symbol"></param>
        /// <param name="crossEdgeFiller"></param>
        public static void CreateUsesEdge(TypeSyntax node, ISymbol symbol, CrossEdgeFiller crossEdgeFiller)
        {
            SyntaxNode tmpNode;
            var        reference = symbol.GetDefinition(out tmpNode);

            if (reference != null && reference.Kind == symbol.Kind)
            {
                MainDeclaration.Instance.UsesStack.Peek( ).Add(reference.GetLimType( ).Id);
            }
            else if (symbol.IsInMetadata( ))
            {
                var type = symbol.GetLimType( );
                MainDeclaration.Instance.LimFactory.setFiltered(type.Id);
                MainDeclaration.Instance.UsesStack.Peek( ).Add(type.Id);
            }
            var baseType = tmpNode as BaseTypeDeclarationSyntax;

            if (baseType != null)
            {
                crossEdgeFiller.OriginalDefinitionFiller(baseType, node);
            }
        }
예제 #4
0
 public static void Visit(SyntaxNode node, Dictionary <Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode, uint> map, CrossEdgeFiller crossEdgeFiller)
 {
     RoslynVisitor.GetInstance(map, crossEdgeFiller).Visit(node);
 }
예제 #5
0
        /// <summary>
        ///     TODO separte
        /// </summary>
        /// <param name="expressionSyntax"></param>
        /// <param name="expressionKind"></param>
        /// <param name="crossEdgeFiller"></param>
        private static void CreateMethodCallFromExpression(ExpressionSyntax expressionSyntax,
                                                           ExpressionKind expressionKind, CrossEdgeFiller crossEdgeFiller)
        {
            if (expressionSyntax != null)
            {
                MainDeclaration.Instance.RoslynWatch.Start( );
                var symbol = MainDeclaration.Instance.Model.GetSymbolInfo(expressionSyntax).Symbol;
                MainDeclaration.Instance.RoslynWatch.Stop( );
                if (symbol != null)
                {
                    if (symbol.IsInMetadata( ))
                    {
                        CreateMethodCallEdge(symbol, symbol, MainDeclaration.Instance.LimFactory.setFiltered);
                    }
                    else
                    {
                        SyntaxNode method;
                        var        calledSymbol = symbol.GetDefinition(out method);
                        if (method != null && calledSymbol == null)
                        {
                            calledSymbol =
                                MainDeclaration.Instance.Solution.GetDocument(method.SyntaxTree)
                                .GetSemanticModelAsync( )
                                .Result.GetDeclaredSymbol(method.Parent);
                            method = method.Parent;
                            // conversation operator overloading has been handled another places
                            if (method.Kind( ) == SyntaxKind.ConversionOperatorDeclaration)
                            {
                                return;
                            }
                        }
                        CreateMethodCallEdge(symbol, calledSymbol);
                        switch (expressionKind)
                        {
                        case ExpressionKind.BinaryExpression:
                            crossEdgeFiller.OverloadedOperatorCallFiller(( OperatorDeclarationSyntax )method,
                                                                         ( BinaryExpressionSyntax )expressionSyntax);
                            break;

                        case ExpressionKind.PrefixUnaryExpression:
                            crossEdgeFiller.OverloadedOperatorCallFiller(( OperatorDeclarationSyntax )method,
                                                                         ( PrefixUnaryExpressionSyntax )expressionSyntax);
                            break;

                        case ExpressionKind.PostfixUnaryExpression:
                            crossEdgeFiller.OverloadedOperatorCallFiller(( OperatorDeclarationSyntax )method,
                                                                         ( PostfixUnaryExpressionSyntax )expressionSyntax);
                            break;

                        case ExpressionKind.AssigmentExpression:
                            if (method != null && method.Parent.Kind( ) == SyntaxKind.AccessorList)
                            {
                                crossEdgeFiller.EventAccessorCallFiller(( AccessorDeclarationSyntax )method,
                                                                        ( AssignmentExpressionSyntax )expressionSyntax);
                            }
                            else
                            {
                                crossEdgeFiller.OverloadedOperatorCallFiller(( OperatorDeclarationSyntax )method,
                                                                             ( AssignmentExpressionSyntax )expressionSyntax);
                            }
                            break;
                        }
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        ///     Create cross edge for Method through the MethodCall edge
        /// </summary>
        /// <param name="node"></param>
        /// <param name="symbol"></param>
        /// <param name="crossEdgeFiller"></param>
        public static void CreateMethodCallFromProperty(CSharpSyntaxNode node, ISymbol symbol,
                                                        CrossEdgeFiller crossEdgeFiller)
        {
            SyntaxNode accessor;
            SyntaxNode property;
            var        propertySymbol = symbol.GetDefinition(out property) as IPropertySymbol;
            bool       needAllAccessor;
            var        method = GetCalledAccessor(node, symbol, out needAllAccessor);

            if (needAllAccessor)
            {
                if (propertySymbol != null && propertySymbol.Kind == symbol.Kind)
                {
                    var calledGetAccessor = propertySymbol.GetMethod;
                    if (calledGetAccessor != null)
                    {
                        calledGetAccessor = ( IMethodSymbol )calledGetAccessor.GetDefinition(out accessor);
                        var methodCall =
                            MainDeclaration.Instance.LimFactory.createMethodCall(
                                calledGetAccessor.ConvertToLimNode( ).Id);
                        MainDeclaration.Instance.MethodStack.Peek( )
                        .Calls.Add(new KeyValuePair <uint, bool>(methodCall.Id, false));
                        if (node.Kind( ) == SyntaxKind.IdentifierName)
                        {
                            crossEdgeFiller.AccessorCallFiller(( AccessorDeclarationSyntax )accessor,
                                                               ( IdentifierNameSyntax )node);
                        }
                        else
                        {
                            crossEdgeFiller.AccessorCallFiller(( AccessorDeclarationSyntax )accessor,
                                                               ( ElementAccessExpressionSyntax )node);
                        }
                    }
                    var calledSetAccessor = propertySymbol.SetMethod;
                    if (calledSetAccessor != null)
                    {
                        calledSetAccessor = ( IMethodSymbol )calledSetAccessor.GetDefinition(out accessor);
                        var methodCall =
                            MainDeclaration.Instance.LimFactory.createMethodCall(
                                calledSetAccessor.ConvertToLimNode( ).Id);
                        MainDeclaration.Instance.MethodStack.Peek( )
                        .Calls.Add(new KeyValuePair <uint, bool>(methodCall.Id, false));
                        if (node.Kind( ) == SyntaxKind.IdentifierName)
                        {
                            crossEdgeFiller.AccessorCallFiller(( AccessorDeclarationSyntax )accessor,
                                                               ( IdentifierNameSyntax )node);
                        }
                        else
                        {
                            crossEdgeFiller.AccessorCallFiller(( AccessorDeclarationSyntax )accessor,
                                                               ( ElementAccessExpressionSyntax )node);
                        }
                    }
                }
                else if (symbol.IsInMetadata( ) && MainDeclaration.Instance.MethodStack.Count > 0)
                {
                    var    prop      = symbol as IPropertySymbol;
                    Method getMethod = null;
                    if (prop != null && prop.GetMethod != null)
                    {
                        getMethod = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(prop.GetMethod);
                    }

                    if (getMethod != null)
                    {
                        MainDeclaration.Instance.LimFactory.setFiltered(getMethod.Id);
                        Commons.Common.FillFromMethodStack(MainDeclaration.Instance.MethodStack.Pop( ));
                        var methodCall = MainDeclaration.Instance.LimFactory.createMethodCall(getMethod.Id);
                        MainDeclaration.Instance.LimFactory.setFiltered(methodCall.Id);
                        MainDeclaration.Instance.MethodStack.Peek( )
                        .Calls.Add(new KeyValuePair <uint, bool>(methodCall.Id, true));

                        Method setMethod = null;
                        if (prop.SetMethod != null)
                        {
                            setMethod = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(prop.SetMethod);
                        }

                        if (setMethod != null)
                        {
                            MainDeclaration.Instance.LimFactory.setFiltered(setMethod.Id);
                            Commons.Common.FillFromMethodStack(MainDeclaration.Instance.MethodStack.Pop( ));
                            methodCall = MainDeclaration.Instance.LimFactory.createMethodCall(setMethod.Id);
                        }
                        MainDeclaration.Instance.LimFactory.setFiltered(methodCall.Id);
                        MainDeclaration.Instance.MethodStack.Peek( )
                        .Calls.Add(new KeyValuePair <uint, bool>(methodCall.Id, true));
                    }
                }
            }
            else if (method != null)
            {
                var calledPropertyAccessor = method.GetDefinition(out accessor);
                if (calledPropertyAccessor != null && calledPropertyAccessor.Kind == method.Kind)
                {
                    var methodCall =
                        MainDeclaration.Instance.LimFactory.createMethodCall(
                            calledPropertyAccessor.ConvertToLimNode( ).Id);
                    MainDeclaration.Instance.MethodStack.Peek( )
                    .Calls.Add(new KeyValuePair <uint, bool>(methodCall.Id, false));
                    if (node.Kind( ) == SyntaxKind.IdentifierName)
                    {
                        crossEdgeFiller.AccessorCallFiller(( AccessorDeclarationSyntax )accessor,
                                                           ( IdentifierNameSyntax )node);
                    }
                    else
                    {
                        crossEdgeFiller.AccessorCallFiller(( AccessorDeclarationSyntax )accessor,
                                                           ( ElementAccessExpressionSyntax )node);
                    }
                }
                else if (method.IsInMetadata( ) && MainDeclaration.Instance.MethodStack.Count > 0)
                {
                    var mth = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(method);
                    Commons.Common.FillFromMethodStack(MainDeclaration.Instance.MethodStack.Pop( ));
                    mth.IsCompilerGenerated = true;
                    MainDeclaration.Instance.LimFactory.setFiltered(mth.Id);
                    var methodCall = MainDeclaration.Instance.LimFactory.createMethodCall(mth.Id);
                    MainDeclaration.Instance.LimFactory.setFiltered(methodCall.Id);
                    MainDeclaration.Instance.MethodStack.Peek( )
                    .Calls.Add(new KeyValuePair <uint, bool>(methodCall.Id, true));
                }
            }
        }