public static void onBeforeExpand(TreeNode selectedTreeNode, Action <ICirFunctionCall, TreeNode, bool,bool> addToNodeFunction, bool dontAddRecursiveCalls)
        {
            if (selectedTreeNode != null)
            {
                ICirFunctionCall functionCall = null;
                if (selectedTreeNode.Tag is ICirFunctionCall)
                {
                    functionCall = (ICirFunctionCall)selectedTreeNode.Tag;
                    //addToNode_MakesCallsTo(functionCall, selectedTreeNode, false);
                }
                else if (selectedTreeNode.Tag is ICirFunction)
                {
                    selectedTreeNode.Nodes.Clear();
                    functionCall = new CirFunctionCall((ICirFunction)selectedTreeNode.Tag);

                }
                if (functionCall != null)
                {
                    selectedTreeNode.Nodes.Clear();
                    addToNodeFunction(functionCall, selectedTreeNode, false, dontAddRecursiveCalls);
                }
            }
        }
        public ICirFunction processMethodDefinition(ICirData cirData, MethodDefinition methodDefinition, SequencePoint sequencePoint)
        {
            try
            {
                //var functionSignature = methodDefinition.ToString();
                var functionSignature = CirFactoryUtils.getFunctionUniqueSignatureFromMethodReference(methodDefinition);
                var functionClass = CirFactoryUtils.getTypeUniqueSignatureFromTypeReference(methodDefinition.DeclaringType);
                var cirFunction = getCirFunction(cirData, functionSignature, functionClass);
                if (false == cirFunction.HasBeenProcessedByCirFactory)
                {
                    if (methodDefinition.CustomAttributes != null && methodDefinition.CustomAttributes.Count > 0)
                    {
                        foreach (CustomAttribute customAttribute in methodDefinition.CustomAttributes)
                        {
                            var constructorSignature = CirFactoryUtils.getFunctionUniqueSignatureFromMethodReference(customAttribute.Constructor);
                            var cirAttribute = new CirAttribute(constructorSignature);
                            foreach (var constructorParameter in customAttribute.ConstructorParameters)
                            {
                                var type = constructorParameter.GetType().FullName;
                            }
                            if (customAttribute.Fields.Count > 0 || customAttribute.Properties.Count > 0)
                            {
                            }
                           // PublicDI.log.debug("Added attribute {0} to {1}", customAttribute.Constructor.Name, cirFunction.FunctionName);
                            cirFunction.FunctionAttributes.Add(cirAttribute);
                        }
                    }
                    

                    // map the common values with MethodReference
                    processMethodReference(cirData, methodDefinition, sequencePoint);

                    cirFunction.HasBeenProcessedByCirFactory = true;  // we need to put this in here or we will have an infinite loop on recursive functions
                    cirFunction.HasControlFlowGraph = true;           // ControlFlowGraph is use by the Viewers to determine if we have more than just a reference to this method
                    cirFunction.ParentClass.bClassHasMethodsWithControlFlowGraphs = true;  // also mark the parent class

                    cirFunction.IsStatic = methodDefinition.IsStatic;
                    cirFunction.IsUnmanaged = methodDefinition.IsUnmanaged;
                    cirFunction.IsUnmanagedExport = methodDefinition.IsUnmanagedExport;
                    cirFunction.IsVirtual = methodDefinition.IsVirtual;
                    cirFunction.IsSetter = methodDefinition.IsSetter;
                    cirFunction.IsGetter = methodDefinition.IsGetter;
                    cirFunction.IsRuntime = methodDefinition.IsRuntime;
                    cirFunction.IsPublic = methodDefinition.IsPublic;
                    cirFunction.IsPrivate = methodDefinition.IsPrivate;
                    cirFunction.IsPInvokeImpl = methodDefinition.IsPInvokeImpl;
                    cirFunction.IsNative = methodDefinition.IsNative;
                    cirFunction.IsManaged = methodDefinition.IsManaged;
                    cirFunction.IsInternalCall = methodDefinition.IsInternalCall;
                    cirFunction.IsIL = methodDefinition.IsIL;
                    cirFunction.IsConstructor = methodDefinition.IsConstructor;
                    cirFunction.IsAbstract = methodDefinition.IsAbstract;
                    cirFunction.HasSecurity = methodDefinition.HasSecurity;
                    cirFunction.HasBody = methodDefinition.HasBody;

                    // try to find the location of the current method by going for the first line of the first method
                    if (methodDefinition.HasBody)
                        foreach (Instruction instruction in methodDefinition.Body.Instructions)
                            if (instruction.SequencePoint != null )
                            {
                                cirFunction.File = instruction.SequencePoint.Document.Url;
                                if (instruction.SequencePoint.StartLine == 16707566) // means there is no source code ref                                
                                    cirFunction.FileLine = "0";
                                else
                                    cirFunction.FileLine = instruction.SequencePoint.StartLine.ToString();
                                break;
                            }
                    
                    // map method parameters (this could be on the MethodReference but if so we would have to check for doing it more than once:
                    foreach (ParameterDefinition parameter in methodDefinition.Parameters)
                    {
                        ICirFunctionParameter functionParameter = new CirFunctionParameter
                        {
                            ParameterName = parameter.ToString(),
                            ParameterType = parameter.ParameterType.FullName,
                            Constant = (parameter.Constant != null) ? parameter.Constant.ToString() : "",
                            HasConstant = parameter.HasConstant,
                            HasDefault = parameter.HasDefault,
                            Method = parameter.Method.ToString()
                        };

                        cirFunction.FunctionParameters.Add(functionParameter);
                    }

                    // map the calls made and the IsCalledBy                   
                    foreach (var methodCalled in CecilUtils.getMethodsCalledInsideMethod(methodDefinition))
                    {
                        ICirFunction cirCalledFunction = processMemberReference(cirData, methodCalled.memberReference, methodCalled.sequencePoint);

                        if (cirCalledFunction != null)
                        {
                            // store the fucntion called sequence
                            cirFunction.FunctionsCalled.Add(new CirFunctionCall(cirCalledFunction,methodCalled.sequencePoint)); 
                            // store the unique list of funcions called
                            if (false == cirFunction.FunctionsCalledUniqueList.Contains(cirCalledFunction))
                                cirFunction.FunctionsCalledUniqueList.Add(cirCalledFunction);

                            // map the FunctionCalled and FunctionIsCalledBy

                            var cirFunctionCall = new CirFunctionCall(cirCalledFunction, sequencePoint);
                            //cirFunction.FunctionsCalled.Add(cirFunctionCall);                            
                            cirCalledFunction.FunctionIsCalledBy.Add(cirFunctionCall);

                            
                            //if (false == cirCalledFunction.FunctionIsCalledBy.Contains(cirFunction))
                            //    cirCalledFunction.FunctionIsCalledBy.Add(cirFunction);
                        }
                    }                                       
                }
                // to implement if needed
              /*  foreach (var methodOverride in methodDefinition.Overrides)
                {
                    var name = methodOverride.GetType();
                }*/

                return cirFunction;
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in CirFactory.processMethodDefinition", true);
                return null;
            }            
        }        
Пример #3
0
        public static void mapFunctionCall(ICirData cirData, ICirFunction cfCirFunction, String sSymbolRef, String sSignature)
        {            
            ICirFunction cfCalledCirFunction = getFunction_bySignature(cirData, sSymbolRef, sSignature);

            // add 'functions called' mapping
            if (false == cfCirFunction.FunctionsCalledUniqueList.Contains(cfCalledCirFunction))
                cfCirFunction.FunctionsCalledUniqueList.Add(cfCalledCirFunction);
            
            // map the FunctionCalled and FunctionIsCalledBy
            var cirFunctionCall = new CirFunctionCall(cfCalledCirFunction);
            cfCirFunction.FunctionsCalled.Add(cirFunctionCall);
            //if (false == cfCalledCirFunction.FunctionIsCalledBy.Contains(cfCirFunction))
            cfCalledCirFunction.FunctionIsCalledBy.Add(cirFunctionCall);
            /*
            if (false == cfCalledCirFunction.FunctionIsCalledBy.Contains(FunctionSignature))
            {

                cfCalledCirFunction.FunctionIsCalledBy.Add(FunctionSignature);
            }*/
        }