Esempio n. 1
0
        public static void HideLineFromDebugger(this Instruction i, SequencePoint seqPoint)
        {
            if (seqPoint == null)
                return;

            HideLineFromDebugger(i, seqPoint.Document);
        }
 private bool IsSignificantSequencePoint(Instruction ins, SequencePoint sp)
 {
     if (ins.OpCode == OpCodes.Nop)
         return false;
     if (ins.OpCode == OpCodes.Ret && ins.Next == null)
         return false;
     return sp.StartLine != HiddenLine;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="SequencePoint" />, copying
 /// data from the provided <see cref="Cil.SequencePoint" />.
 /// </summary>
 /// <param name="sequencePoint">
 /// An instance of <see cref="Cil.SequencePoint" /> from which to copy
 /// property values.
 /// </param>
 public SequencePoint(Cil.SequencePoint sequencePoint)
     : this()
 {
     StartLine   = sequencePoint.StartLine;
     StartColumn = sequencePoint.StartColumn;
     EndLine     = sequencePoint.EndLine;
     EndColumn   = sequencePoint.EndColumn;
 }
 string CreateLeftLink(SequencePoint rightSP, FormattingInfo info, int offset = 0)
 {
     if (rightSP != null)
     {
         var rightSPUrl = CreateSequencePointUrl(info.LeftUrl, rightSP, offset);
         return String.Format("[ {0} ]", CreateMarkdownUrl("link", rightSPUrl));
     }
     return "";
 }
		static void WriteSequencePoint (TextWriter writer, SequencePoint sequence_point)
		{
			writer.Write (".line {0},{1}:{2},{3} '{4}'",
				sequence_point.StartLine,
				sequence_point.EndLine,
				sequence_point.StartColumn,
				sequence_point.EndColumn,
				sequence_point.Document.Url);
		}
 private SequencePoint CreateSequencePoint(Loc location)
 {
     var result = new SequencePoint(this.document);
     result.StartLine = 0;
     result.StartColumn = location.Position;
     // TODO: End location
     result.EndLine = 0;
     result.EndColumn = location.End;
     return result;
 }
Esempio n. 7
0
 public void LogError(string message, SequencePoint point = null)
 {
     if (point == null)
     {
         _weaver.LogError(message);
     }
     else
     {
         _weaver.LogErrorPoint(message, point);
     }
 }
Esempio n. 8
0
 void LogWarningPoint(string message, SequencePoint point)
 {
     if (point == null)
     {
         Logger.LogWarning(message);
     }
     else
     {
         Logger.LogWarning(message, point.Document.Url, point.StartLine, point.StartColumn, point.EndLine, point.EndColumn);
     }
 }
Esempio n. 9
0
        public void CreateMethodFromScratch()
        {
            IgnoreOnMono ();

            var module = ModuleDefinition.CreateModule ("Pan", ModuleKind.Dll);
            var type = new TypeDefinition ("Pin", "Pon", TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Sealed, module.ImportReference (typeof (object)));
            module.Types.Add (type);

            var method = new MethodDefinition ("Pang", MethodAttributes.Public | MethodAttributes.Static, module.ImportReference (typeof (string)));
            type.Methods.Add (method);

            var body = method.Body;

            body.InitLocals = true;

            var il = body.GetILProcessor ();
            var temp = new VariableDefinition (module.ImportReference (typeof (string)));
            body.Variables.Add (temp);

            il.Emit (OpCodes.Nop);
            il.Emit (OpCodes.Ldstr, "hello");
            il.Emit (OpCodes.Stloc, temp);
            il.Emit (OpCodes.Ldloc, temp);
            il.Emit (OpCodes.Ret);

            var sequence_point = new SequencePoint (body.Instructions [0], new Document (@"C:\test.cs")) {
                StartLine = 0,
                StartColumn = 0,
                EndLine = 0,
                EndColumn = 4,
            };

            method.DebugInformation.SequencePoints.Add (sequence_point);

            method.DebugInformation.Scope = new ScopeDebugInformation  (body.Instructions [0], null) {
                Variables = { new VariableDebugInformation (temp, "temp") }
            };

            var file = Path.Combine (Path.GetTempPath (), "Pan.dll");
            module.Write (file, new WriterParameters {
                SymbolWriterProvider = new PdbWriterProvider (),
            });

            module = ModuleDefinition.ReadModule (file, new ReaderParameters {
                SymbolReaderProvider = new PdbReaderProvider (),
            });

            method = module.GetType ("Pin.Pon").GetMethod ("Pang");

            Assert.AreEqual ("temp", method.DebugInformation.Scope.Variables [0].Name);
        }
 private ICirFunction processMemberReference(ICirData cirData, IMemberReference memberDefinition, SequencePoint sequencePoint)
 {
     switch (memberDefinition.GetType().Name)
     {
         case "MethodReference":
             return processMethodReference(cirData, (MethodReference)memberDefinition, sequencePoint);
         case "MethodDefinition":
             return processMethodDefinition(cirData, (MethodDefinition)memberDefinition, sequencePoint);
         default:
             DI.log.error("in CirFactory.processMethodMember, unsupported MethodMember: {0}", memberDefinition.GetType().Name);
             break;
     }
     return null;
 }
Esempio n. 11
0
 public CirFunctionCall(ICirFunction _cirFunction, SequencePoint sequencePoint)
     : this(_cirFunction)
 {            
     if (sequencePoint!=null)
     {
         fileName = sequencePoint.Document.Url;
         lineNumber = sequencePoint.StartLine;
         endLine = sequencePoint.EndLine;
         startColumn = sequencePoint.StartColumn;
         endColumn = sequencePoint.EndColumn;                
     }
     else
     {
         
     }
 }
Esempio n. 12
0
        private static string ReadSourceLineFor(SequencePoint sp)
        {
            var lineContent = string.Empty;

            using (var fileStream = new FileStream(sp.Document.Url, FileMode.Open))
            using (TextReader reader = new StreamReader(fileStream))
            {
                //For some reason, sometimes StartLine holds an invalid line number.
                //in this case we are going to handle as if the source file is not available.                
                for (var i = 0; i < sp.StartLine && lineContent != null; i++)
                {
                    lineContent = reader.ReadLine();
                }
            }

            return lineContent;
        }
Esempio n. 13
0
		private static string FormatSourceInformation(SequencePoint sp, Instruction instruction)
		{
			Func<SequencePoint, string> sequencePointFormater = delegate(SequencePoint s)
			                                                    	{
																		return string.Format("{0} ({1}, {2}) (IL instruction: {3} {4})", s.Document.Url, s.StartLine, s.StartColumn, instruction.OpCode, instruction.Operand);
																	};

			if (sp == null) return string.Format("{0} {1}", instruction.OpCode, instruction.Operand);

			if (!File.Exists(sp.Document.Url))
			{
				return sequencePointFormater(sp);
			}

			string lineContent = ReadSourceLineFor(sp);
			return lineContent != null
					? string.Format("{0} ({1}, {2}) : {3}", sp.Document.Url, sp.StartLine, sp.StartColumn, lineContent.Substring(sp.StartColumn - 1, sp.EndColumn - sp.StartColumn - 1))
					: sequencePointFormater(sp);
		}
Esempio n. 14
0
    void InjectPropertyGetterGuard(MethodBody getBody, SequencePoint seqPoint, PropertyReference property)
    {
        var guardInstructions = new List<Instruction>();

        var returnPoints = getBody.Instructions
            .Select((o, i) => new { o, i })
            .Where(a => a.o.OpCode == OpCodes.Ret)
            .Select(a => a.i)
            .OrderByDescending(i => i);

        foreach (var ret in returnPoints)
        {
            var returnInstruction = getBody.Instructions[ret];
            var errorMessage = string.Format(CultureInfo.InvariantCulture, ReturnValueOfPropertyIsNull, property.FullName);

            guardInstructions.Clear();

            if (isDebug)
            {
                InstructionPatterns.DuplicateReturnValue(guardInstructions, property.PropertyType);

                InstructionPatterns.CallDebugAssertInstructions(guardInstructions, errorMessage);
            }

            InstructionPatterns.DuplicateReturnValue(guardInstructions, property.PropertyType);

            InstructionPatterns.IfNull(guardInstructions, returnInstruction, i =>
            {
                // Clean up the stack since we're about to throw up.
                i.Add(Instruction.Create(OpCodes.Pop));

                InstructionPatterns.LoadInvalidOperationException(i, errorMessage);

                // Throw the top item off the stack
                i.Add(Instruction.Create(OpCodes.Throw));
            });

            guardInstructions[0].HideLineFromDebugger(seqPoint);

            getBody.Instructions.Insert(ret, guardInstructions);
        }
    }
        public string GetSourceCode(SequencePoint sequencePoint)
        {
            var lines = sourceCodeProvider.GetSourceCode(sequencePoint.Document.Url);
            if (lines == null)
            {
                return null;
            }

            if (sequencePoint.StartLine == sequencePoint.EndLine)
            {
                return lines[sequencePoint.StartLine - 1].Substring(sequencePoint.StartColumn - 1, sequencePoint.EndColumn - sequencePoint.StartColumn);
            }

            var list = new List<string>();

            var startLine = sequencePoint.StartLine - 1;
            var endLine = sequencePoint.EndLine - 1;

            list.Add(lines[startLine].Substring(sequencePoint.StartColumn - 1));
            for (var i = startLine + 1; i < endLine; i++)
            {
                list.Add(lines[i]);
            }

            var endColumn = sequencePoint.EndColumn - 1;
            var lastLine = lines[endLine];
            if (endColumn < lastLine.Length)
            {
                list.Add(lastLine.Remove(endColumn));
            }
            else
            {
                list.Add(lastLine);
            }
            return string.Join(" ", list.Select(x => x.Trim()));
        }
Esempio n. 16
0
 public MethodCalled(IMemberReference _memberReference, SequencePoint _sequencePoint)
 {
     memberReference = _memberReference;
     sequencePoint = _sequencePoint;
 }
Esempio n. 17
0
		private static string FormatSequencePoint (SequencePoint sp, bool exact)
		{
			return FormatSequencePoint (sp.Document.Url, sp.StartLine, sp.StartColumn, exact);
		}
Esempio n. 18
0
    SequencePoint TranslateSequencePoint(SequencePoint sequencePoint)
    {
        if (sequencePoint == null)
            return null;

        var document = new Document(Path.Combine(Path.GetDirectoryName(AssemblyFilePath), Path.GetFileName(sequencePoint.Document.Url)))
        {
            Language = sequencePoint.Document.Language,
            LanguageVendor = sequencePoint.Document.LanguageVendor,
            Type = sequencePoint.Document.Type,
        };

        return new SequencePoint(document)
        {
            StartLine = sequencePoint.StartLine,
            StartColumn = sequencePoint.StartColumn,
            EndLine = sequencePoint.EndLine,
            EndColumn = sequencePoint.EndColumn,
        };
    }
Esempio n. 19
0
    private void InjectPropertySetterGuard(MethodBody setBody, SequencePoint seqPoint, ParameterDefinition valueParameter, string errorMessage)
    {
        if (!valueParameter.MayNotBeNull())
            return;

        var guardInstructions = new List<Instruction>();

        var entry = setBody.Instructions.First();

        if (isDebug)
        {
            InstructionPatterns.LoadArgumentOntoStack(guardInstructions, valueParameter);

            InstructionPatterns.CallDebugAssertInstructions(guardInstructions, errorMessage);
        }

        InstructionPatterns.LoadArgumentOntoStack(guardInstructions, valueParameter);

        InstructionPatterns.IfNull(guardInstructions, entry, i =>
        {
            InstructionPatterns.LoadArgumentNullException(i, valueParameter.Name, errorMessage);

            // Throw the top item off the stack
            i.Add(Instruction.Create(OpCodes.Throw));
        });

        guardInstructions[0].HideLineFromDebugger(seqPoint);

        setBody.Instructions.Prepend(guardInstructions);
    }
Esempio n. 20
0
        private static Tuple <bool, TestId> IsSequencePointAtStartOfAUnitTest(RunStartParams rsp, Mono.Cecil.Cil.SequencePoint sp, FilePath assemblyPath, Func <DocumentLocation, IEnumerable <DTestCase> > findTest)
        {
            if (sp == null)
            {
                return(new Tuple <bool, TestId>(false, null));
            }

            var dl = new DocumentLocation {
                document = PathBuilder.rebaseCodeFilePath(rsp.Solution.Path, rsp.Solution.SnapshotPath, FilePath.NewFilePath(sp.Document.Url)), line = DocumentCoordinate.NewDocumentCoordinate(sp.StartLine)
            };
            var test = findTest(dl).FirstOrDefault(t => t.Source.Equals(assemblyPath));

            if (test == null)
            {
                return(new Tuple <bool, TestId>(false, null));
            }
            else
            {
                return(new Tuple <bool, TestId>(
                           true,
                           new TestId(assemblyPath, dl)));
            }
        }
Esempio n. 21
0
    void InjectMethodArgumentGuards(MethodDefinition method, MethodBody body, SequencePoint seqPoint)
    {
        var guardInstructions = new List<Instruction>();

        foreach (var parameter in method.Parameters.Reverse())
        {
            if (!parameter.MayNotBeNull())
                continue;

            if (method.IsSetter && parameter.Equals(method.GetPropertySetterValueParameter()))
                continue;

            if (CheckForExistingGuard(body.Instructions, parameter))
                continue;

            var entry = body.Instructions.First();
            var errorMessage = string.Format(CultureInfo.InvariantCulture, IsNull, parameter.Name);

            guardInstructions.Clear();

            if (isDebug)
            {
                InstructionPatterns.LoadArgumentOntoStack(guardInstructions, parameter);

                InstructionPatterns.CallDebugAssertInstructions(guardInstructions, errorMessage);
            }

            InstructionPatterns.LoadArgumentOntoStack(guardInstructions, parameter);

            InstructionPatterns.IfNull(guardInstructions, entry, i =>
            {
                InstructionPatterns.LoadArgumentNullException(i, parameter.Name, errorMessage);

                // Throw the top item off the stack
                i.Add(Instruction.Create(OpCodes.Throw));
            });

            guardInstructions[0].HideLineFromDebugger(seqPoint);

            body.Instructions.Prepend(guardInstructions);
        }
    }
Esempio n. 22
0
    void InjectMethodReturnGuard(ValidationFlags localValidationFlags, MethodDefinition method, MethodBody body, SequencePoint seqPoint)
    {
        var guardInstructions = new List<Instruction>();

        var returnPoints = body.Instructions
                .Select((o, ix) => new { o, ix })
                .Where(a => a.o.OpCode == OpCodes.Ret)
                .Select(a => a.ix)
                .OrderByDescending(ix => ix);

        foreach (var ret in returnPoints)
        {
            if (localValidationFlags.HasFlag(ValidationFlags.ReturnValues) &&
                !method.AllowsNullReturnValue() &&
                method.ReturnType.IsRefType() &&
                method.ReturnType.FullName != typeof(void).FullName &&
                !method.IsGetter)
            {
                var errorMessage = string.Format(CultureInfo.InvariantCulture, ReturnValueOfMethodIsNull, method.FullName);
                AddReturnNullGuard(body.Instructions, seqPoint, ret, method.ReturnType, errorMessage, Instruction.Create(OpCodes.Throw));
            }

            if (localValidationFlags.HasFlag(ValidationFlags.Arguments))
            {
                foreach (var parameter in method.Parameters.Reverse())
                {
                    // This is no longer the return instruction location, but it is where we want to jump to.
                    var returnInstruction = body.Instructions[ret];

                    if (localValidationFlags.HasFlag(ValidationFlags.OutValues) &&
                        parameter.IsOut &&
                        parameter.ParameterType.IsRefType() &&
                        !parameter.AllowsNull())
                    {
                        var errorMessage = string.Format(CultureInfo.InvariantCulture, OutParameterIsNull, parameter.Name);

                        guardInstructions.Clear();

                        if (isDebug)
                        {
                            InstructionPatterns.LoadArgumentOntoStack(guardInstructions, parameter);

                            InstructionPatterns.CallDebugAssertInstructions(guardInstructions, errorMessage);
                        }

                        InstructionPatterns.LoadArgumentOntoStack(guardInstructions, parameter);

                        InstructionPatterns.IfNull(guardInstructions, returnInstruction, i =>
                        {
                            InstructionPatterns.LoadInvalidOperationException(i, errorMessage);

                            // Throw the top item off the stack
                            i.Add(Instruction.Create(OpCodes.Throw));
                        });

                        guardInstructions[0].HideLineFromDebugger(seqPoint);

                        body.Instructions.Insert(ret, guardInstructions);
                    }
                }
            }
        }
    }
Esempio n. 23
0
        private LocalizedString CreateLocalizedString (LanguageGender gender, SequencePoint sequencePoint)
        {
            var localized_string = new LocalizedString { Gender = gender };

            if (sequencePoint != null) {
                localized_string.AddReference (RelativeDocumentUrl (sequencePoint.Document.Url), sequencePoint.StartLine);
            }

            if (StringAnalyzer.CheckFormatArguments (localized_string.UntranslatedSingularValue) ||
                StringAnalyzer.CheckFormatArguments (localized_string.UntranslatedPluralValue)) {
                localized_string.StringFormatHint = "csharp-format";
            }

            return localized_string;
        }
Esempio n. 24
0
        static void ReadLine(PdbLine line, Document document, MethodDebugInformation info)
        {
            var sequence_point = new SequencePoint ((int) line.offset, document);
            sequence_point.StartLine = (int) line.lineBegin;
            sequence_point.StartColumn = (int) line.colBegin;
            sequence_point.EndLine = (int) line.lineEnd;
            sequence_point.EndColumn = (int) line.colEnd;

            info.sequence_points.Add (sequence_point);
        }
Esempio n. 25
0
 /// <summary>
 /// Wrap the given sequence point which cn be null.
 /// </summary>
 public static ISourceLocation Wrap(SequencePoint sequencePoint)
 {
     return (sequencePoint != null) ? new SequencePointWrapper(sequencePoint) : null;
 }
Esempio n. 26
0
 /// <summary>
 /// Default ctor
 /// </summary>
 private SequencePointWrapper(SequencePoint sequencePoint)
 {
     this.sequencePoint = sequencePoint;
 }
Esempio n. 27
0
        private IEnumerable<LocalizedString> GenerateLocalizedStrings (SequencePoint sequencePoint,
            Stack<KeyValuePair<string, string>> parameters, bool gendered)
        {
            var neutral = CreateLocalizedString (LanguageGender.Neutral, sequencePoint);
            var masculine = CreateLocalizedString (LanguageGender.Masculine, sequencePoint);
            var feminine = CreateLocalizedString (LanguageGender.Feminine, sequencePoint);

            while (parameters.Count > 0) {
                var param = parameters.Pop ();
                switch (param.Key) {
                    case "comment":
                        neutral.DeveloperComments = param.Value;
                        masculine.DeveloperComments = param.Value;
                        feminine.DeveloperComments = param.Value;
                        break;
                    case "message":
                    case "singularMessage":
                        if (gendered) {
                            masculine.UntranslatedSingularValue = param.Value;
                            feminine.UntranslatedSingularValue = param.Value;
                        }

                        neutral.UntranslatedSingularValue = param.Value;
                        break;
                    case "pluralMessage":
                        if (gendered) {
                            masculine.UntranslatedPluralValue = param.Value;
                            feminine.UntranslatedPluralValue = param.Value;
                        }

                        neutral.UntranslatedPluralValue = param.Value;
                        break;
                    case "masculineMessage":
                    case "singularMasculineMessage":
                        masculine.UntranslatedSingularValue = param.Value;
                        break;
                    case "pluralMasculineMessage":
                        masculine.UntranslatedPluralValue = param.Value;
                        break;
                    case "feminineMessage":
                    case "singularFeminineMessage":
                        feminine.UntranslatedSingularValue = param.Value;
                        break;
                    case "pluralFeminineMessage":
                        feminine.UntranslatedPluralValue = param.Value;
                        break;
                }
            }

            if (neutral.IsDefined) {
                yield return neutral;
            }

            if (masculine.IsDefined) {
                yield return masculine;
            }

            if (feminine.IsDefined) {
                yield return feminine;
            }
        }
Esempio n. 28
0
        static void ReadLine(PdbLine line, Document document, InstructionMapper mapper)
        {
            var instruction = mapper ((int) line.offset);
            if (instruction == null)
                return;

            var sequence_point = new SequencePoint (document);
            sequence_point.StartLine = (int) line.lineBegin;
            sequence_point.StartColumn = (int) line.colBegin;
            sequence_point.EndLine = (int) line.lineEnd;
            sequence_point.EndColumn = (int) line.colEnd;

            instruction.SequencePoint = sequence_point;
        }
        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;
            }            
        }        
Esempio n. 30
0
 private string Sequence(SequencePoint point)
 {
     return point == null ? "NULL" : string.Format("{0}[{1}]-{2}[{3}] <{4}>", point.StartLine, point.StartColumn, point.EndLine, point.EndColumn, point.Document.Url);
 }
        public ICirFunction processMethodReference(ICirData cirData, MethodReference methodReference, SequencePoint sequencePoint)
        {
            try
            {                
                var functionSignature = CirFactoryUtils.getFunctionUniqueSignatureFromMethodReference(methodReference);
                var functionType = CirFactoryUtils.getTypeUniqueSignatureFromTypeReference(methodReference.DeclaringType);
                var cirFunction = getCirFunction(cirData, functionSignature, functionType);

                cirFunction.CecilSignature = methodReference.ToString();
                cirFunction.ReturnType = methodReference.ReturnType.ReturnType.FullName;
                cirFunction.ParentClass = getCirClass(cirData, CirFactoryUtils.getTypeUniqueSignatureFromTypeReference(methodReference.DeclaringType));
                cirFunction.ParentClassFullName = methodReference.DeclaringType.FullName;
                cirFunction.ParentClassName = methodReference.DeclaringType.Name;
                //
                cirFunction.Module = (methodReference.DeclaringType.Module != null) ? methodReference.DeclaringType.Module.Assembly.ToString() : "[NullModule]";
                //cirFunction.Module = (methodReference.DeclaringType.Module != null) ? methodReference.DeclaringType.Module.Name : "[NullModule]";
                cirFunction.FunctionName = methodReference.Name;
                cirFunction.FunctionNameAndParameters = CecilUtils.getMethodNameAndParameters(methodReference);                

                cirFunction.ClassNameFunctionNameAndParameters = string.Format("{0}.{1}",
                                                                               cirFunction.ParentClassFullName,
                                                                               cirFunction.FunctionNameAndParameters);
                cirFunction.SymbolDef = Guid.NewGuid().ToString();
                /*if (sequencePoint != null)
                {
                    if (string.IsNullOrEmpty(cirFunction.File) == false)
                    { 
                    }
                    cirFunction.File = sequencePoint.Document.Url;
                    cirFunction.FileLine = sequencePoint.StartColumn.ToString();
                }*/
                
               
                //methodReference.ReturnType  // to implement since we need to add reference to a CirClass
                return cirFunction;
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in CirFactory.processMethodReference", true);
                return null;
            }

        }
Esempio n. 32
0
 public InstructionSymbol(int offset, SequencePoint sequencePoint)
 {
     this.Offset        = offset;
     this.SequencePoint = sequencePoint;
 }
Esempio n. 33
0
 public InstructionSymbol(int offset, SequencePoint sequencePoint)
 {
     this.Offset = offset;
     this.SequencePoint = sequencePoint;
 }
 static internal string GetIdentifier(Cil.SequencePoint sequencePoint)
 {
     return(GetIdentifier(sequencePoint.StartLine, sequencePoint.StartColumn, sequencePoint.EndLine,
                          sequencePoint.EndColumn));
 }