Exemple #1
0
        /// <summary>
        ///     In this sectio, it'll be create:
        ///     - MethodCall edge from cast expression (e.x.: (float)intTypeVariable)
        ///     These edges add to the acutal method from the MethodStack
        /// </summary>
        /// <param name="node"></param>
        public override void VisitCastExpression(CastExpressionSyntax node)
        {
            MainDeclaration.Instance.RoslynWatch.Start( );
            var castedExpressionType            = MainDeclaration.Instance.Model.GetTypeInfo(node.Type).Type;
            var foundConversionOperatorOverload = MainDeclaration.Instance.Model.ClassifyConversion(node.Expression,
                                                                                                    castedExpressionType);

            MainDeclaration.Instance.RoslynWatch.Stop( );
            if (foundConversionOperatorOverload.MethodSymbol != null)
            {
                SyntaxNode calledSyntax = null;
                if (foundConversionOperatorOverload.MethodSymbol.IsInMetadata( ))
                {
                    EdgeBuilder.CreateMethodCallEdge(foundConversionOperatorOverload.MethodSymbol,
                                                     foundConversionOperatorOverload.MethodSymbol, MainDeclaration.Instance.LimFactory.setFiltered);
                }
                else
                {
                    var calledSymbol = foundConversionOperatorOverload.MethodSymbol.GetDefinition(out calledSyntax,
                                                                                                  true);
                    // e.x. (Func<int,int>)MethodIdentifier will be skipp
                    if (calledSymbol.Kind != SymbolKind.NamedType &&
                        calledSyntax.Kind( ) != SyntaxKind.MethodDeclaration)
                    {
                        _crossEdgeFiller.ConversionOperatorCallFiller(
                            ( ConversionOperatorDeclarationSyntax )calledSyntax.Parent, node);
                        EdgeBuilder.CreateMethodCallEdge(calledSymbol, calledSymbol);
                    }
                }
            }
            base.VisitCastExpression(node);
        }
Exemple #2
0
        /// <summary>
        ///     In this sectio, it'll be create:
        ///     - MethodCall edge from element access expression (e.x.: a[i])
        ///     These edges add to the acutal method from the MethodStack
        /// </summary>
        /// <param name="node"></param>
        public override void VisitElementAccessExpression(ElementAccessExpressionSyntax node)
        {
            MainDeclaration.Instance.RoslynWatch.Start( );
            var namedType = MainDeclaration.Instance.Model.GetTypeInfo(node.Expression).Type;

            MainDeclaration.Instance.RoslynWatch.Stop( );
            if (namedType != null)
            {
                var             members = namedType.GetMembers( );
                IPropertySymbol indexer = null;
                foreach (var member in members)
                {
                    if (member.Kind != SymbolKind.Property)
                    {
                        continue;
                    }
                    var propertySymbol = ( IPropertySymbol )member;
                    if (propertySymbol.IsIndexer)
                    {
                        if (propertySymbol.Parameters.Length == node.ArgumentList.Arguments.Count)
                        {
                            var assignmentExpressionArgumentTypes = node.ArgumentList.Arguments.Select(t =>
                            {
                                MainDeclaration.Instance.RoslynWatch.Start( );
                                var res = MainDeclaration.Instance.Model.GetTypeInfo(t.Expression).Type;
                                MainDeclaration.Instance.RoslynWatch.Stop( );
                                return(res);
                            }).ToArray( );
                            var  propertySymbolParameterType = propertySymbol.Parameters.Select(t => t.Type).ToArray( );
                            byte sameTypeCounter             = 0;
                            for (var i = 0; i < propertySymbolParameterType.Length; i++)
                            {
                                if (assignmentExpressionArgumentTypes[i] != null &&
                                    assignmentExpressionArgumentTypes[i].Equals(propertySymbolParameterType[i]))
                                {
                                    sameTypeCounter++;
                                }
                            }
                            if (sameTypeCounter == propertySymbolParameterType.Length)
                            {
                                indexer = propertySymbol;
                                break;
                            }
                        }
                    }
                }
                if (indexer != null)
                {
                    EdgeBuilder.CreateMethodCallFromProperty(node, indexer, _crossEdgeFiller);
                }
            }

            base.VisitElementAccessExpression(node);
        }
Exemple #3
0
    private static void AddTileToLevel(LevelEnvironmentData data, TileData tile, Vector3 worldPosition, byte bitmask)
    {
        int verticeCount = data.Vertices.Count;

        TileMeshData meshData = tile.Brush.GetMeshData(bitmask);

        // Vertices.
        foreach (Vector3 vertex in meshData.Vertices)
        {
            data.Vertices.Add(Utility.ScaleToHexagonalSize(vertex) + worldPosition);
        }

        // Triangles.
        int[][] rawTriangles = meshData.Triangles;
        for (int i = 0; i < rawTriangles.Length; i++)
        {
            int[] trianglesToSet = new int[rawTriangles[i].Length];

            // Offset the triangles
            for (int w = 0; w < rawTriangles[i].Length; w++)
            {
                trianglesToSet[w] = rawTriangles[i][w] + verticeCount;
            }

            data.SetTriangles(tile.BrushMaterials[i], trianglesToSet);
        }

        // UVs.
        foreach (Vector2 uv in meshData.UVs)
        {
            data.UVs.Add(uv);
        }

        // Edges.
        if (!AxialDirection.ContainsDirection(bitmask, AxialDirection.DownLeft) || !AxialDirection.ContainsDirection(bitmask, AxialDirection.DownRight))
        {
            EdgeBuilder.Build(data, tile, worldPosition, bitmask);
        }
    }
Exemple #4
0
        /// <summary>
        ///     In this sectio, it'll be create:
        ///     - MethodCall edge from invocation expression
        ///     These edges add to the acutal method from the MethodStack
        /// </summary>
        /// <param name="node"></param>
        public override void VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            base.VisitInvocationExpression(node);

            //if (node.IsParent<AnonymousObjectMemberDeclaratorSyntax>()) return;
            MainDeclaration.Instance.RoslynWatch.Start( );
            var symbol = MainDeclaration.Instance.Model.GetSymbolInfo(node).Symbol;

            MainDeclaration.Instance.RoslynWatch.Stop( );
            if (symbol != null && MainDeclaration.Instance.MethodStack.Count > 0)
            {
                SyntaxNode method;
                var        calledSymbol = symbol.GetDefinition(out method);
                if (calledSymbol != null && calledSymbol.Kind == symbol.Kind)
                {
                    EdgeBuilder.CreateMethodCallEdge(symbol, calledSymbol);
                    _crossEdgeFiller.MethodCallFiller(method as MethodDeclarationSyntax, node);
                }
                else if (calledSymbol != null && calledSymbol.Kind == SymbolKind.NamedType)
                {
                    var possibleDelegateSymbol = ( INamedTypeSymbol )calledSymbol;
                    if (possibleDelegateSymbol.TypeKind == TypeKind.Delegate)
                    {
                        EdgeBuilder.CreateMethodCallEdgeFromDelegatePointer(node, possibleDelegateSymbol, _map);
                    }
                }
                else if (symbol.IsInMetadata( ) && MainDeclaration.Instance.MethodStack.Count > 0)
                {
                    var methodSymbol = symbol as IMethodSymbol;
                    if (methodSymbol != null)
                    {
                        EdgeBuilder.CreateMethodCallEdge(methodSymbol, symbol,
                                                         MainDeclaration.Instance.LimFactory.setFiltered);
                    }
                }
            }
        }
Exemple #5
0
        private void visitMethod <T>(BaseMethodDeclarationSyntax node, VisitNode <T> visitor)
            where T : CSharpSyntaxNode
        {
            MainDeclaration.Instance.RoslynWatch.Start( );
            var symbol = MainDeclaration.Instance.Model.GetDeclaredSymbol(node);

            MainDeclaration.Instance.RoslynWatch.Stop( );

            HalsteadAnalyzer halsteadAnalyzer = new HalsteadAnalyzer();
            var halstedMetrics = halsteadAnalyzer.Calculate(node);

            var limNode = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(symbol);

            limNode.TotalOperands     = halstedMetrics.TotalOperands;
            limNode.TotalOperators    = halstedMetrics.TotalOperators;
            limNode.DistinctOperands  = halstedMetrics.DistinctOperands;
            limNode.DistinctOperators = halstedMetrics.DistinctOperators;
            if (symbol.OverriddenMethod != null)
            {
                if (symbol.OverriddenMethod.IsInMetadata( ))
                {
                    MainDeclaration.Instance
                    .OverrideRelations.AddOverride(
                        ( Method )symbol.OverriddenMethod.ConvertToLimNode( ),
                        limNode
                        );
                }
                else
                {
                    SyntaxNode dummyNode;
                    var        asd = symbol.OverriddenMethod.GetDefinition(out dummyNode);
                    if (asd != null && asd.Kind == symbol.OverriddenMethod.Kind)
                    {
                        var overriddenMethodSymbol = ( Method )asd.ConvertToLimNode( );
                        MainDeclaration.Instance
                        .OverrideRelations.AddOverride(
                            overriddenMethodSymbol,
                            limNode
                            );
                    }
                }
            }
            if (symbol.ContainingType.TypeKind == TypeKind.Interface)
            {
                Commons.Common.ChangeRealizationLevel(limNode);
            }
            if (symbol.PartialImplementationPart != null)
            {
                Commons.Common.ChangeRealizationLevel(limNode);
                var method = symbol.PartialImplementationPart.IsGenericMethod
                    ? SymbolBuilder.BuildDispatch <MethodGeneric, IMethodSymbol>(symbol.PartialImplementationPart)
                    : SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(symbol.PartialImplementationPart);
                method.NumberOfBranches = 0;
                limNode.setDeclares(method.Id);
                Commons.Common.FillFromMethodStack(MainDeclaration.Instance.MethodStack.Pop( ));
            }

            if (node.Kind( ) == SyntaxKind.ConstructorDeclaration)
            {
                var init = (( ConstructorDeclarationSyntax )node).Initializer;
                if (init != null)
                {
                    MainDeclaration.Instance.RoslynWatch.Start( );
                    var calleeSymbol = MainDeclaration.Instance.Model.GetSymbolInfo(init).Symbol;
                    MainDeclaration.Instance.RoslynWatch.Stop( );
                    if (calleeSymbol != null)
                    {
                        SyntaxNode calledCtor;
                        calleeSymbol.GetDefinition(out calledCtor);
                        EdgeBuilder.CreateMethodCallEdge(symbol, calleeSymbol);
                        if (calledCtor != null && calledCtor.Kind( ) == SyntaxKind.ConstructorDeclaration)
                        {
                            // if the called constructor doesn't exist in the code e.x.: default constructor
                            _crossEdgeFiller.ConstructorCallFiller(( ConstructorDeclarationSyntax )calledCtor, init);
                        }
                    }
                }
            }

            MainDeclaration.Instance.LimOrigin.addCompIdCsharpIdLimIdToMap(MainDeclaration.Instance.Component.Id,
                                                                           _map[node], limNode.Id);
            node.CreateCommentNode(symbol);

            visitor(node as T);

            if (MainDeclaration.Instance.MethodStack.Count > 0)
            {
                Commons.Common.SetMetrics(node);
            }

            limNode.SetCLOC(node);
        }
Exemple #6
0
        /// <summary>
        ///     In this section it'll be create:
        ///     - MethodCall edge from identifier
        ///     - AttributeAccess edge from identifier
        ///     - Uses edge from identifier
        ///     These edges add to the acutal method from the MethodStack
        /// </summary>
        /// <param name="node"></param>
        public override void VisitIdentifierName(IdentifierNameSyntax node)
        {
            if (MainDeclaration.Instance.MethodStack.Count <= 0)
            {
                return;
            }
            if (node.IsParent <ParameterSyntax>( ))
            {
                return;
            }
            if (node.Identifier.Text != Constants.VAR && node.Identifier.Text != Constants.DYNAMIC)
            {
                MainDeclaration.Instance.RoslynWatch.Start( );
                var symbol = MainDeclaration.Instance.Model.GetSymbolInfo(node).Symbol;
                MainDeclaration.Instance.RoslynWatch.Stop( );
                if (symbol != null)
                {
                    switch (symbol.Kind)
                    {
                    case SymbolKind.Method:
                        if (!symbol.IsInMetadata( ) &&
                            (node.IsParent <InvocationExpressionSyntax, AssignmentExpressionSyntax>( ) ||
                             node.IsParent <InvocationExpressionSyntax, ArgumentSyntax>( )))
                        {
                            SyntaxNode dec;
                            var        methodDef = symbol.GetDefinition(out dec);
                            _crossEdgeFiller.DeclarationFiller(( CSharpSyntaxNode )dec, node);
                            if (methodDef != null && methodDef.Kind == symbol.Kind)
                            {
                                MainDeclaration.Instance.UsesStack.Peek( )
                                .Add(methodDef.ContainingType.GetLimType( ).Id);
                            }
                        }
                        break;

                    case SymbolKind.Field:
                        EdgeBuilder.CreateAttributeAccessEdge(node, symbol);
                        break;

                    case SymbolKind.Local:
                    case SymbolKind.Parameter:
                        if (node.IsParent <ParameterListSyntax>( ))
                        {
                            return;
                        }
                        if (node.Identifier.Text == Constants.VALUE)
                        {
                            return;
                        }
                        if (!symbol.IsInMetadata( ))
                        {
                            MainDeclaration.Instance.RoslynWatch.Start( );
                            var iConversaitonOpOverLoad = MainDeclaration.Instance.Model.GetConversion(node);
                            MainDeclaration.Instance.RoslynWatch.Stop( );
                            if (iConversaitonOpOverLoad.MethodSymbol != null)
                            {
                                if (iConversaitonOpOverLoad.MethodSymbol.IsInMetadata( ))
                                {
                                    EdgeBuilder.CreateMethodCallEdge(symbol.ContainingSymbol,
                                                                     iConversaitonOpOverLoad.MethodSymbol,
                                                                     MainDeclaration.Instance.LimFactory.setFiltered);
                                }
                                else
                                {
                                    SyntaxNode _tmp;
                                    var        calledSymbol = iConversaitonOpOverLoad.MethodSymbol.GetDefinition(
                                        out _tmp, true);
                                    EdgeBuilder.CreateMethodCallEdge(symbol.ContainingSymbol, calledSymbol);
                                }
                            }
                            var declaration = symbol.DeclaringSyntaxReferences[0].GetSyntax( );
                            _crossEdgeFiller.DeclarationFiller(( CSharpSyntaxNode )declaration, node);
                        }
                        break;

                    case SymbolKind.NamedType:
                        EdgeBuilder.CreateUsesEdge(node, symbol, _crossEdgeFiller);
                        break;

                    case SymbolKind.Property:
                        var parent    = node.GetParent <AnonymousObjectMemberDeclaratorSyntax>( );
                        var needToRun = true;
                        if (parent != null)
                        {
                            needToRun =
                                parent.Expression.IsEquivalentTo(node.GetParent <ExpressionStatementSyntax>( ));
                        }

                        if (needToRun)
                        {
                            EdgeBuilder.CreateMethodCallFromProperty(node, symbol, _crossEdgeFiller);
                        }
                        break;

                    default:
                        break;
                    }
                }
                EdgeBuilder.CreateMethodCallEdgeFromIdentifier(node, _crossEdgeFiller);
            }

            base.VisitIdentifierName(node);
        }
 // Use this for initialization
 void Start()
 {
     Debug.Log (transform.GetChild (0));
     buildObject = transform.GetChild (0).gameObject;
     edgeBuilder = transform.parent.GetComponent<EdgeBuilder> ();
 }