Beispiel #1
0
        public IEnumerable <ILLocalVariable> GetLocalVariables(IMethod method)
        {
            string id   = IdStringProvider.GetIdString(method.MemberDefinition);
            var    file = GetSymbols(method);

            if (file == null || !file.DebugSymbols.ContainsKey(id))
            {
                return(Enumerable.Empty <ILLocalVariable>());
            }

            var symbols = file.DebugSymbols[id];

            var context = new SimpleTypeResolveContext(method);
            var loader  = new CecilLoader();

            return(symbols.LocalVariables.Where(v => v.OriginalVariable != null).Select(
                       v => new Debugger.ILLocalVariable()
            {
                Index = v.OriginalVariable.Index,
                Type = loader.ReadTypeReference(v.Type).Resolve(context),
                Name = v.Name,
                IsCompilerGenerated = false,
                ILRanges = new [] { new ILRange(0, int.MaxValue) }
            }));
        }
            public void AddMember(IUnresolvedEntity entity, Mono.Cecil.MemberReference cecilObject)
            {
                rwLock.EnterWriteLock();
                try {
                    uint token = cecilObject.MetadataToken.ToUInt32();
                    metadataTokens[entity] = token;

                    var cecilMethod = cecilObject as Mono.Cecil.MethodDefinition;
                    if (cecilMethod != null)
                    {
                        IUnresolvedMethod method = (IUnresolvedMethod)entity;
                        tokenToMethod[token] = method;
                        if (cecilMethod.HasBody)
                        {
                            var locals = cecilMethod.Body.Variables;
                            if (locals.Count > 0)
                            {
                                localVariableTypes[method] = locals.Select(v => typeRefLoader.ReadTypeReference(v.VariableType)).ToArray();
                            }
                            if (cecilMethod.RVA != 0)
                            {
                                // The method was loaded from image - we can free the memory for the body
                                // because Cecil will re-initialize it on demand
                                cecilMethod.Body = null;
                            }
                        }
                    }
                } finally {
                    rwLock.ExitWriteLock();
                }
            }
Beispiel #3
0
        public IType Resolve(TypeReference typeReference)
        {
            if (typeReference == null)
            {
                return(SpecialType.UnknownType);
            }
            if (typeReference is SentinelType || typeReference is PinnedType)
            {
                typeReference = ((TypeSpecification)typeReference).ElementType;
            }
            ITypeReference typeRef;

            lock (typeReferenceCecilLoader)
                typeRef = typeReferenceCecilLoader.ReadTypeReference(typeReference);
            return(typeRef.Resolve(context));
        }
        public IType ResolveType(NRefactory.VB.Ast.AstType type, NRefactory.VB.Ast.TypeDeclaration entity = null)
        {
            var annotation = type.Annotation <TypeReference>();

            if (annotation == null)
            {
                return(null);
            }

            IEntity current = null;

            if (entity != null)
            {
                var typeInfo = entity.Annotation <TypeReference>();
                current = loader.ReadTypeReference(typeInfo).Resolve(context).GetDefinition();
            }

            return(loader.ReadTypeReference(annotation, entity: current).Resolve(context));
        }
Beispiel #5
0
        public IType Resolve(TypeReference typeReference)
        {
            if (typeReference == null)
            {
                return(SpecialType.UnknownType);
            }
            // We need to skip SentinelType and PinnedType.
            // But PinnedType can be nested within modopt, so we'll also skip those.
            while (typeReference is OptionalModifierType || typeReference is RequiredModifierType)
            {
                typeReference = ((TypeSpecification)typeReference).ElementType;
            }
            if (typeReference is SentinelType || typeReference is PinnedType)
            {
                typeReference = ((TypeSpecification)typeReference).ElementType;
            }
            ITypeReference typeRef;

            lock (typeReferenceCecilLoader)
                typeRef = typeReferenceCecilLoader.ReadTypeReference(typeReference);
            return(typeRef.Resolve(context));
        }