/// <inheritdoc/>
        public TypeOrValue Analyze(ILocalScope Scope)
        {
            string name = Identifier.Contents;

            // TODO: handle types, functions and globals
            return(new TypeOrValue(Scope.GetLocal(name)));
        }
Пример #2
0
        private void AddLocalsAndConstants(DecompiledBlock block, ILocalScope scope)
        {
            Contract.Requires(block != null);
            Contract.Requires(scope != null);
            Contract.Requires(this.localScopeProvider != null);

            bool isLexicalScope = false;
            int  counter        = 0;

            foreach (var local in this.localScopeProvider.GetConstantsInScope(scope))
            {
                Contract.Assume(local != null);
                var localVariable = this.GetLocalWithSourceName(local);
                Contract.Assume(counter <= block.Statements.Count);
                block.Statements.Insert(counter++, new LocalDeclarationStatement()
                {
                    LocalVariable = localVariable
                });
            }
            foreach (var local in this.localScopeProvider.GetVariablesInScope(scope))
            {
                Contract.Assume(local != null);
                var localVariable = this.GetLocalWithSourceName(local);
                Contract.Assume(counter <= block.Statements.Count);
                block.Statements.Insert(counter++, new LocalDeclarationStatement()
                {
                    LocalVariable = localVariable
                });
            }
            if (isLexicalScope)
            {
                block.IsLexicalScope = true;
            }
        }
 private void PrintScopes(ILocalScope scope) {
   this.writer.Write(string.Format("IL_{0} ... IL_{1} ", scope.Offset.ToString("x4"), (scope.Offset+scope.Length).ToString("x4")), true);
   this.writer.WriteLine("{");
   this.PrintConstants(this.pdbReader.GetConstantsInScope(scope));
   this.PrintLocals(this.pdbReader.GetVariablesInScope(scope));
   this.writer.WriteLine("}");
 }
Пример #4
0
        /// <summary>
        /// Returns zero or more local variable definitions that are local to the given scope.
        /// </summary>
        public IEnumerable <ILocalDefinition> GetVariablesInScope(ILocalScope scope)
        {
            PdbLocalScope /*?*/ pdbLocalScope = scope as PdbLocalScope;

            if (pdbLocalScope == null)
            {
                yield break;
            }
            uint index = 0;

            foreach (ILocalDefinition localDefinition in pdbLocalScope.methodBody.LocalVariables)
            {
                if (localDefinition.IsConstant)
                {
                    continue;
                }
                foreach (PdbSlot slot in pdbLocalScope.pdbScope.slots)
                {
                    if ((slot.flags & 1) != 0)
                    {
                        continue;
                    }
                    if (slot.slot == index)
                    {
                        yield return(localDefinition);

                        break;
                    }
                }
                index++;
            }
        }
Пример #5
0
 internal CopiedLocalScope(ILocalScope originalScope, IMethodBody copiedMethodBody)
 {
     Contract.Requires(originalScope != null);
     Contract.Requires(copiedMethodBody != null);
     this.originalScope    = originalScope;
     this.copiedMethodBody = copiedMethodBody;
 }
Пример #6
0
        protected override void Run(ITreeNode element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
        {
            IFunction   thisElement = null;
            ILocalScope topScope    = null;
            var         function    = element as ICSharpFunctionDeclaration;

            if (function != null)
            {
                thisElement = function.DeclaredElement;
                topScope    = function.Body as ILocalScope;
            }

            var inspector = new ClosureInspector(element, thisElement);

            element.ProcessDescendants(inspector);

            // report closures allocations
            if (inspector.Closures.Count > 0)
            {
                ReportClosureAllocations(
                    element, thisElement, topScope, inspector, consumer);
            }

            // report non-cached generic lambda expressions
            if (function != null && inspector.ClosurelessLambdas.Count > 0)
            {
                ReportClosurelessAllocations(function, inspector, consumer);
            }

            // report anonymous types in query expressions
            if (inspector.AnonymousTypes.Count > 0)
            {
                ReportAnonymousTypes(inspector, consumer);
            }
        }
 private void PrintScopes(ILocalScope scope)
 {
     this.writer.Write(string.Format("IL_{0} ... IL_{1} ", scope.Offset.ToString("x4"), (scope.Offset + scope.Length).ToString("x4")), true);
     this.writer.WriteLine("{");
     this.PrintConstants(this.pdbReader.GetConstantsInScope(scope));
     this.PrintLocals(this.pdbReader.GetVariablesInScope(scope));
     this.writer.WriteLine("}");
 }
Пример #8
0
 public LocalDeclarationScope(
     ILocalScope Parent,
     string VariableName, IValue Variable)
 {
     this.parentScope  = Parent;
     this.variableName = VariableName;
     this.variable     = Variable;
 }
Пример #9
0
        protected override void Run(ITreeNode element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
        {
            IParametersOwner function = null;
            ILocalScope      topScope = null;

            if (element is ICSharpFunctionDeclaration functionDeclaration)
            {
                function = functionDeclaration.DeclaredElement;
                topScope = functionDeclaration.Body as ILocalScope;
            }

            if (element is IExpressionBodyOwnerDeclaration expressionBodyOwner)
            {
#if RESHARPER2017_1
                var arrowExpression = expressionBodyOwner.ArrowClause;
#else
                var arrowExpression = expressionBodyOwner.ArrowExpression;
#endif
                if (arrowExpression != null)
                {
#if RESHARPER2016_3
                    function = expressionBodyOwner.GetParametersOwner();
                    topScope = arrowExpression as ILocalScope;
#else
                    function = expressionBodyOwner.GetFunction();
                    topScope = arrowExpression;
#endif
                }
                else
                {
                    if (element is IAccessorOwnerDeclaration)
                    {
                        return;
                    }
                }
            }

            var inspector = new ClosureInspector(element, function);
            element.ProcessDescendants(inspector);

            // report closures allocations
            if (inspector.Closures.Count > 0)
            {
                ReportClosureAllocations(element, function, topScope, inspector, consumer);
            }

            // report non-cached generic lambda expressions
            if (function != null && inspector.ClosurelessLambdas.Count > 0)
            {
                ReportClosurelessAllocations(element, function, inspector, consumer);
            }

            // report anonymous types in query expressions
            if (inspector.AnonymousTypes.Count > 0)
            {
                ReportAnonymousTypes(inspector, consumer);
            }
        }
Пример #10
0
        /// <summary>
        /// Checks that the type is non-null, and returns it.
        /// </summary>
        public IType CheckType(ILocalScope Scope)
        {
            if (Type == null)
            {
                throw new Exception("Type was null");
            }

            return(Type);
        }
Пример #11
0
        /// <summary>
        /// Checks that the type-or-value's value is non-null,
        /// and then creates a set-statement.
        /// </summary>
        public IStatement CreateSetStatement(IExpression NewValue, ILocalScope Scope)
        {
            if (Value == null)
            {
                throw new Exception("Value was null");
            }

            return(Value.CreateSetStatement(NewValue, Scope));
        }
Пример #12
0
        /// <summary>
        /// Checks that the value is non-null, and then creates
        /// a get-expression.
        /// </summary>
        public IExpression CreateGetExpression(ILocalScope Scope)
        {
            if (Value == null)
            {
                throw new Exception("Value was null");
            }

            return(Value.CreateGetExpression(Scope));
        }
Пример #13
0
 /// <summary>
 /// Returns zero or more local constant definitions that are local to the given scope.
 /// </summary>
 public IEnumerable<ILocalDefinition> GetConstantsInScope(ILocalScope scope)
 {
     ILocalScopeProvider/*?*/ provider = this.GetProvider(scope.MethodDefinition);
       if (provider == null) {
     return IteratorHelper.GetEmptyEnumerable<ILocalDefinition>();
       } else {
     return provider.GetConstantsInScope(scope);
       }
 }
Пример #14
0
        /// <summary>
        /// Returns zero or more local constant definitions that are local to the given scope.
        /// </summary>
        public virtual IEnumerable <ILocalDefinition> GetConstantsInScope(ILocalScope scope)
        {
            var ilGeneratorScope = scope as ILGeneratorScope;

            if (ilGeneratorScope == null)
            {
                return(Enumerable <ILocalDefinition> .Empty);
            }
            return(ilGeneratorScope.Constants);
        }
Пример #15
0
 private void PrintScopes(ILocalScope scope)
 {
     sourceEmitterOutput.Write(string.Format("IL_{0} ... IL_{1} ", scope.Offset.ToString("x4"), (scope.Offset + scope.Length).ToString("x4")), true);
     sourceEmitterOutput.WriteLine("{");
     sourceEmitterOutput.IncreaseIndent();
     PrintConstants(this.pdbReader.GetConstantsInScope(scope));
     PrintLocals(this.pdbReader.GetVariablesInScope(scope));
     sourceEmitterOutput.DecreaseIndent();
     sourceEmitterOutput.WriteLine("}", true);
 }
Пример #16
0
            /// <summary>
            /// Returns zero or more local constant definitions that are local to the given scope.
            /// </summary>
            /// <param name="scope"></param>
            /// <returns></returns>
            public IEnumerable <ILocalDefinition> GetConstantsInScope(ILocalScope scope)
            {
                var generatorScope = scope as ILGeneratorScope;

                if (generatorScope == null)
                {
                    return(this.originalLocalScopeProvider.GetConstantsInScope(scope));
                }
                return(generatorScope.Constants);
            }
Пример #17
0
            /// <summary>
            /// Returns zero or more local variable definitions that are local to the given scope.
            /// </summary>
            /// <param name="scope"></param>
            /// <returns></returns>
            public IEnumerable <ILocalDefinition> GetVariablesInScope(ILocalScope scope)
            {
                var generatorScope = scope as ILGeneratorScope;

                if (generatorScope == null)
                {
                    return(this.originalLocalScopeProvider.GetVariablesInScope(scope));
                }
                return(generatorScope.Locals ?? Enumerable <ILocalDefinition> .Empty);
            }
Пример #18
0
        /// <summary>
        /// Returns zero or more local variable definitions that are local to the given scope.
        /// </summary>
        public virtual IEnumerable <ILocalDefinition> GetVariablesInScope(ILocalScope scope)
        {
            var ilGeneratorScope = scope as ILGeneratorScope;

            if (ilGeneratorScope == null)
            {
                return(IteratorHelper.GetEmptyEnumerable <ILocalDefinition>());
            }
            return(ilGeneratorScope.Locals);
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="instruction"></param>
        protected virtual void EmitScopeInformationFor(Instruction instruction)
        {
            Contract.Requires(instruction != null);

            IOperation operation = instruction.Operation;

            if (this.scopeEnumerator == null)
            {
                return;
            }
            ILocalScope /*?*/ currentScope = null;

            while (this.scopeStack.Count > 0)
            {
                currentScope = this.scopeStack.Peek();
                Contract.Assume(currentScope != null);
                if (operation.Offset < currentScope.Offset + currentScope.Length)
                {
                    break;
                }
                this.scopeStack.Pop();
                this.ilGenerator.EndScope();
                currentScope = null;
            }
            while (this.scopeEnumeratorIsValid)
            {
                currentScope = this.scopeEnumerator.Current;
                Contract.Assume(currentScope != null);
                if (currentScope.Offset <= operation.Offset && operation.Offset < currentScope.Offset + currentScope.Length)
                {
                    this.scopeStack.Push(currentScope);
                    this.ilGenerator.BeginScope();
                    Contract.Assume(this.localScopeProvider != null);
                    foreach (var local in this.localScopeProvider.GetVariablesInScope(currentScope))
                    {
                        Contract.Assume(local != null);
                        if (this.localIndex.ContainsKey(local))
                        {
                            this.ilGenerator.AddVariableToCurrentScope(local);
                        }
                    }
                    foreach (var constant in this.localScopeProvider.GetConstantsInScope(currentScope))
                    {
                        Contract.Assume(constant != null);
                        this.ilGenerator.AddConstantToCurrentScope(constant);
                    }
                    this.scopeEnumeratorIsValid = this.scopeEnumerator.MoveNext();
                }
                else
                {
                    break;
                }
            }
        }
Пример #20
0
        /// <summary>
        /// Returns zero or more local constant definitions that are local to the given scope.
        /// </summary>
        public IEnumerable <ILocalDefinition> GetConstantsInScope(ILocalScope scope)
        {
            PdbLocalScope /*?*/ pdbLocalScope = scope as PdbLocalScope;

            if (pdbLocalScope == null)
            {
                yield break;
            }
            foreach (PdbConstant constant in pdbLocalScope.pdbScope.constants)
            {
                yield return(new PdbLocalConstant(constant, this.host, pdbLocalScope.methodBody.MethodDefinition));
            }
        }
Пример #21
0
        /// <summary>
        /// Returns zero or more local constant definitions that are local to the given scope.
        /// </summary>
        public IEnumerable <ILocalDefinition> GetConstantsInScope(ILocalScope scope)
        {
            ILocalScopeProvider /*?*/ provider = this.GetProvider(scope.MethodDefinition);

            if (provider == null)
            {
                return(IteratorHelper.GetEmptyEnumerable <ILocalDefinition>());
            }
            else
            {
                return(provider.GetConstantsInScope(scope));
            }
        }
Пример #22
0
        /// <summary>
        /// Returns zero or more local variable definitions that are local to the given scope.
        /// </summary>
        public IEnumerable <ILocalDefinition> GetVariablesInScope(ILocalScope scope)
        {
            ILocalScopeProvider /*?*/ provider = this.GetProvider(scope.MethodDefinition);

            if (provider == null)
            {
                return(Enumerable <ILocalDefinition> .Empty);
            }
            else
            {
                return(provider.GetVariablesInScope(scope));
            }
        }
Пример #23
0
        /// <inheritdoc/>
        public TypeOrValue Analyze(ILocalScope Scope)
        {
            int result;

            if (!int.TryParse(Value.Contents, out result))
            {
                throw new Exception("invalid integer literal '" + Value.Contents + "'.");
            }

            // Wrap the integer in an expression, and create a
            // TypeOrValue instance from that.
            return(new TypeOrValue(new IntegerExpression(result)));
        }
Пример #24
0
        /// <inheritdoc/>
        public TypeOrValue Analyze(ILocalScope Scope)
        {
            double result;

            if (!double.TryParse(Value.Contents, out result))
            {
                throw new Exception(
                          "invalid double-precision floating point literal '" +
                          Value.Contents + "'.");
            }

            // Wrap the double in an expression, and create a
            // TypeOrValue instance from that.
            return(new TypeOrValue(new Float64Expression(result)));
        }
Пример #25
0
        IEnumerable <ILocalDefinition> ILocalScopeProvider.GetVariablesInScope(ILocalScope scope)
        {
            Contract.Assume(!scope.MethodDefinition.IsAbstract && !scope.MethodDefinition.IsExternal);
            IMethodBody body        = scope.MethodDefinition.Body;
            var         copiedScope = scope as CopiedLocalScope;

            if (copiedScope != null)
            {
                scope = copiedScope.OriginalScope;
            }
            foreach (var localDef in this.providerForOriginal.GetVariablesInScope(scope))
            {
                Contract.Assume(localDef != null);
                yield return(this.GetCorrespondingLocal(localDef));
            }
        }
        private void EmitDebugInformationFor(IOperation operation)
        {
            this.ilGenerator.MarkSequencePoint(operation.Location);
            if (this.scopeEnumerator == null)
            {
                return;
            }
            ILocalScope /*?*/ currentScope = null;

            while (this.scopeStack.Count > 0)
            {
                currentScope = this.scopeStack.Peek();
                if (operation.Offset < currentScope.Offset + currentScope.Length)
                {
                    break;
                }
                this.scopeStack.Pop();
                this.ilGenerator.EndScope();
                currentScope = null;
            }
            while (this.scopeEnumeratorIsValid)
            {
                currentScope = this.scopeEnumerator.Current;
                if (currentScope.Offset <= operation.Offset && operation.Offset < currentScope.Offset + currentScope.Length)
                {
                    this.scopeStack.Push(currentScope);
                    this.ilGenerator.BeginScope();
                    foreach (var local in this.pdbReader.GetVariablesInScope(currentScope))
                    {
                        this.ilGenerator.AddVariableToCurrentScope(local);
                    }
                    foreach (var constant in this.pdbReader.GetConstantsInScope(currentScope))
                    {
                        this.ilGenerator.AddConstantToCurrentScope(constant);
                    }
                    this.scopeEnumeratorIsValid = this.scopeEnumerator.MoveNext();
                }
                else
                {
                    break;
                }
            }
        }
Пример #27
0
 internal CopiedLocalScope(ILocalScope originalScope, IMethodBody copiedMethodBody) {
   Contract.Requires(originalScope != null);
   Contract.Requires(copiedMethodBody != null);
   this.originalScope = originalScope;
   this.copiedMethodBody = copiedMethodBody;
 }
Пример #28
0
 IEnumerable<ILocalDefinition> ILocalScopeProvider.GetVariablesInScope(ILocalScope scope) {
   Contract.Assume(!scope.MethodDefinition.IsAbstract && !scope.MethodDefinition.IsExternal);
   IMethodBody body = scope.MethodDefinition.Body;
   var copiedScope = scope as CopiedLocalScope;
   if (copiedScope != null) scope = copiedScope.OriginalScope;
   foreach (var localDef in this.providerForOriginal.GetVariablesInScope(scope)) {
     Contract.Assume(localDef != null);
     yield return this.GetCorrespondingLocal(localDef);
   }
 }
Пример #29
0
 /// <summary>
 /// Returns zero or more local variable definitions that are local to the given scope.
 /// </summary>
 public IEnumerable<ILocalDefinition> GetVariablesInScope(ILocalScope scope) {
   ILocalScopeProvider/*?*/ provider = this.GetProvider(scope.MethodDefinition);
   if (provider == null) {
     return Enumerable<ILocalDefinition>.Empty;
   } else {
     return provider.GetVariablesInScope(scope);
   }
 }
Пример #30
0
        private static void ReportClosureAllocations(
            [NotNull] ITreeNode topDeclaration, [CanBeNull] IFunction thisElement, [CanBeNull] ILocalScope topScope,
            [NotNull] ClosureInspector inspector, [NotNull] IHighlightingConsumer consumer)
        {
            var scopesMap     = new Dictionary <IDeclaredElement, ILocalScope>();
            var captureScopes = new Dictionary <ILocalScope, JetHashSet <IDeclaredElement> >();

            // group captures by their scope, report non-cached delegates
            foreach (var closure in inspector.Closures)
            {
                foreach (var capture in closure.Value)
                {
                    ILocalScope scope = null;
                    if (capture is IFunction)
                    {
                        scope = topScope;             // 'this' capture
                    }
                    else
                    {
                        var declarations = capture.GetDeclarations();
                        if (declarations.Count == 0) // accessors 'value' parameter
                        {
                            var accessor = thisElement as IAccessor;
                            if (accessor != null && Equals(accessor.ValueVariable, capture))
                            {
                                scope = topScope;
                            }
                        }
                        else
                        {
                            foreach (var declaration in declarations)
                            {
                                if (declaration is IRegularParameterDeclaration)
                                {
                                    scope = topScope;
                                }
                                else
                                {
                                    scope = declaration.GetContainingNode <ILocalScope>();
                                }
                                break;
                            }
                        }
                    }

                    if (scope == null)
                    {
                        continue;
                    }

                    JetHashSet <IDeclaredElement> captures;
                    if (!captureScopes.TryGetValue(scope, out captures))
                    {
                        captureScopes[scope] = captures = new JetHashSet <IDeclaredElement>();
                    }

                    captures.Add(capture);
                    scopesMap[capture] = scope;
                }


                {
                    var highlightingRange = GetClosureRange(closure.Key);
                    if (highlightingRange.IsValid())
                    {
                        if (IsExpressionLambda(closure.Key))
                        {
                            consumer.AddHighlighting(
                                new ObjectAllocationHighlighting(closure.Key, "expression tree construction"),
                                highlightingRange);
                        }
                        else
                        {
                            consumer.AddHighlighting(
                                new DelegateAllocationHighlighting(closure.Key, "capture of " + FormatClosureDescription(closure.Value)),
                                highlightingRange);
                        }
                    }
                }
            }

            // highlight first captured entity per every scope
            foreach (var scopeToCaptures in captureScopes)
            {
                var firstOffset = TreeOffset.MaxValue;
                IDeclaredElement firstCapture = null;

                foreach (var capture in scopeToCaptures.Value)
                {
                    if (capture is IFunction)
                    {
                        continue;
                    }

                    var offset = GetCaptureStartOffset(capture);
                    if (offset < firstOffset)
                    {
                        firstOffset  = offset;
                        firstCapture = capture;
                    }
                }

                var scopeClosure = FormatClosureDescription(scopeToCaptures.Value);

                // collect outer captures
                JetHashSet <IDeclaredElement> outerCaptures = null;
                foreach (var closureToCaptures in inspector.Closures)
                {
                    if (!scopeToCaptures.Key.Contains(closureToCaptures.Key))
                    {
                        continue;
                    }
                    foreach (var capture in closureToCaptures.Value)
                    {
                        ILocalScope scope;
                        if (!scopesMap.TryGetValue(capture, out scope))
                        {
                            continue;
                        }
                        if (scopeToCaptures.Key.Contains(scope))
                        {
                            continue;
                        }

                        outerCaptures = outerCaptures ?? new JetHashSet <IDeclaredElement>();
                        outerCaptures.Add(capture);
                    }
                }

                if (outerCaptures != null)
                {
                    scopeClosure += string.Format(" + (outer closure of {0})", FormatClosureDescription(outerCaptures));
                }

                if (firstCapture != null)
                {
                    DocumentRange highlightingRange;
                    var           anchor = GetCaptureHighlightingRange(
                        topDeclaration, thisElement, firstCapture, out highlightingRange);
                    if (anchor != null && highlightingRange.IsValid())
                    {
                        consumer.AddHighlighting(
                            new ClosureAllocationHighlighting(anchor, scopeClosure),
                            highlightingRange);
                    }
                }
            }
        }
Пример #31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="operation"></param>
        protected virtual void EmitDebugInformationFor(IOperation operation)
        {
            Contract.Requires(operation != null);

            this.Generator.MarkSequencePoint(operation.Location);
            if (this.scopeEnumerator == null)
            {
                return;
            }
            ILocalScope /*?*/ currentScope = null;

            while (this.scopeStack.Count > 0)
            {
                currentScope = this.scopeStack.Peek();
                Contract.Assume(currentScope != null);
                if (operation.Offset < currentScope.Offset + currentScope.Length)
                {
                    break;
                }
                this.scopeStack.Pop();
                this.Generator.EndScope();
                currentScope = null;
            }
            while (this.scopeEnumeratorIsValid)
            {
                currentScope = this.scopeEnumerator.Current;
                Contract.Assume(currentScope != null);
                if (currentScope.Offset <= operation.Offset && operation.Offset < currentScope.Offset + currentScope.Length)
                {
                    this.scopeStack.Push(currentScope);
                    uint iteratorLocalsInScope = 0;
                    if (this.iteratorScopeEnumerator != null)
                    {
                        while (this.iteratorScopeEnumeratorIsValid)
                        {
                            var iteratorScope = this.iteratorScopeEnumerator.Current;
                            Contract.Assume(iteratorScope != null);
                            if (iteratorScope.Offset >= currentScope.Offset && iteratorScope.Offset + iteratorScope.Length <= currentScope.Offset + currentScope.Length)
                            {
                                iteratorLocalsInScope++;
                                this.iteratorScopeEnumeratorIsValid = this.iteratorScopeEnumerator.MoveNext();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    this.Generator.BeginScope(iteratorLocalsInScope);
                    Contract.Assume(this.localScopeProvider != null);
                    foreach (var local in this.localScopeProvider.GetVariablesInScope(currentScope))
                    {
                        Contract.Assume(local != null);
                        Contract.Assume(local.MethodDefinition == this.generator.Method);
                        if (!this.localIndex.ContainsKey(local))
                        {
                            this.localIndex.Add(local, (uint)this.localVariables.Count);
                            this.localVariables.Add(local);
                        }
                        this.Generator.AddVariableToCurrentScope(local);
                    }
                    foreach (var constant in this.localScopeProvider.GetConstantsInScope(currentScope))
                    {
                        Contract.Assume(constant != null);
                        Contract.Assume(constant.MethodDefinition == this.generator.Method);
                        this.Generator.AddConstantToCurrentScope(constant);
                    }
                    this.scopeEnumeratorIsValid = this.scopeEnumerator.MoveNext();
                }
                else
                {
                    break;
                }
            }
            if (this.syncPointEnumeratorIsValid)
            {
                Contract.Assume(this.syncPointEnumerator != null);
                var syncPoint = this.syncPointEnumerator.Current;
                Contract.Assume(syncPoint != null);
                if (syncPoint.SynchronizeOffset == operation.Offset)
                {
                    if (syncPoint.ContinuationMethod == null)
                    {
                        this.generator.MarkSynchronizationPoint(this.generator.Method, this.GetLabelFor(syncPoint.ContinuationOffset));
                    }
                    else
                    {
                        this.generator.MarkSynchronizationPoint(syncPoint.ContinuationMethod, new ILGeneratorLabel()
                        {
                            Offset = syncPoint.ContinuationOffset
                        });
                    }
                    Contract.Assume(this.syncPointEnumerator != null);
                    this.syncPointEnumeratorIsValid = this.syncPointEnumerator.MoveNext();
                }
            }
        }
 public IEnumerable<ILocalDefinition> GetVariablesInScope(ILocalScope scope) {
   Contract.Requires(scope != null);
   Contract.Ensures(Contract.Result<IEnumerable<ILocalDefinition>>() != null);
   throw new NotImplementedException();
 }
Пример #33
0
 /// <summary>
 /// Returns zero or more local constant definitions that are local to the given scope.
 /// </summary>
 /// <param name="scope"></param>
 /// <returns></returns>
 public IEnumerable<ILocalDefinition> GetConstantsInScope(ILocalScope scope) {
   var generatorScope = scope as ILGeneratorScope;
   if (generatorScope == null) return this.originalLocalScopeProvider.GetConstantsInScope(scope);
   return generatorScope.Constants??Enumerable<ILocalDefinition>.Empty;
 }
Пример #34
0
    private void AddLocalsAndConstants(DecompiledBlock block, ILocalScope scope) {
      Contract.Requires(block != null);
      Contract.Requires(scope != null);
      Contract.Requires(this.localScopeProvider != null);

      bool isLexicalScope = false;
      int counter = 0;
      foreach (var local in this.localScopeProvider.GetConstantsInScope(scope)) {
        Contract.Assume(local != null);
        var localVariable = this.GetLocalWithSourceName(local);
        Contract.Assume(counter <= block.Statements.Count);
        block.Statements.Insert(counter++, new LocalDeclarationStatement() { LocalVariable = localVariable });
      }
      foreach (var local in this.localScopeProvider.GetVariablesInScope(scope)) {
        Contract.Assume(local != null);
        var localVariable = this.GetLocalWithSourceName(local);
        Contract.Assume(counter <= block.Statements.Count);
        block.Statements.Insert(counter++, new LocalDeclarationStatement() { LocalVariable = localVariable });
      }
      if (isLexicalScope) block.IsLexicalScope = true;
    }
Пример #35
0
 /// <summary>
 /// Returns zero or more local constant definitions that are local to the given scope.
 /// </summary>
 public virtual IEnumerable <ILocalDefinition> GetConstantsInScope(ILocalScope scope)
 {
     return(IteratorHelper.GetEmptyEnumerable <ILocalDefinition>());
 }
Пример #36
0
 /// <summary>
 /// Returns zero or more local variable definitions that are local to the given scope.
 /// </summary>
 public virtual IEnumerable<ILocalDefinition> GetVariablesInScope(ILocalScope scope) {
   var ilGeneratorScope = scope as ILGeneratorScope;
   if (ilGeneratorScope == null) return Enumerable<ILocalDefinition>.Empty;
   return ilGeneratorScope.Locals;
 }
Пример #37
0
 /// <inheritdoc/>
 public IStatement CreateSetStatement(IExpression Value, ILocalScope Scope)
 {
     throw new Exception("cannot store a value here");
 }
Пример #38
0
 /// <inheritdoc/>
 public IExpression CreateGetExpression(ILocalScope Scope)
 {
     return(GetExpression);
 }
Пример #39
0
 /// <summary>
 /// Returns zero or more local variable definitions that are local to the given scope.
 /// </summary>
 /// <param name="scope"></param>
 /// <returns></returns>
 public IEnumerable<ILocalDefinition> GetVariablesInScope(ILocalScope scope)
 {
     var generatorScope = scope as ILGeneratorScope;
     if (generatorScope == null) return this.originalLocalScopeProvider.GetVariablesInScope(scope);
     return generatorScope.Locals;
 }
Пример #40
0
 private void PrintScopes(ILocalScope scope)
 {
     sourceEmitterOutput.Write(string.Format("IL_{0} ... IL_{1} ", scope.Offset.ToString("x4"), (scope.Offset + scope.Length).ToString("x4")), true);
     sourceEmitterOutput.WriteLine("{");
     sourceEmitterOutput.IncreaseIndent();
     PrintConstants(pdbReader.GetConstantsInScope(scope));
     PrintLocals(pdbReader.GetVariablesInScope(scope));
     sourceEmitterOutput.DecreaseIndent();
     sourceEmitterOutput.WriteLine("}", true);
 }
Пример #41
0
 /// <summary>
 /// Returns zero or more local constant definitions that are local to the given scope.
 /// </summary>
 public virtual IEnumerable<ILocalDefinition> GetConstantsInScope(ILocalScope scope)
 {
     return IteratorHelper.GetEmptyEnumerable<ILocalDefinition>();
 }
Пример #42
0
 public IEnumerable <ILocalDefinition> GetVariablesInScope(ILocalScope scope)
 {
     Contract.Requires(scope != null);
     Contract.Ensures(Contract.Result <IEnumerable <ILocalDefinition> >() != null);
     throw new NotImplementedException();
 }
Пример #43
0
 /// <summary>
 /// Returns zero or more local constant definitions that are local to the given scope.
 /// </summary>
 public IEnumerable<ILocalDefinition> GetConstantsInScope(ILocalScope scope)
 {
     PdbLocalScope/*?*/ pdbLocalScope = scope as PdbLocalScope;
       if (pdbLocalScope == null) yield break;
       foreach (PdbConstant constant in pdbLocalScope.pdbScope.constants) {
     yield return new PdbLocalConstant(constant, this.host, pdbLocalScope.methodBody.MethodDefinition);
       }
 }
 /// <summary>
 /// Returns zero or more local variable definitions that are local to the given scope.
 /// </summary>
 public IEnumerable<ILocalDefinition> GetVariablesInScope(ILocalScope scope) {
   PdbLocalScope/*?*/ pdbLocalScope = scope as PdbLocalScope;
   if (pdbLocalScope == null) yield break;
   foreach (PdbSlot slot in pdbLocalScope.pdbScope.slots) {
     if ((slot.flags & 1) != 0) continue;
     if (slot.slot == 0 && slot.name.StartsWith("$VB")) 
       yield return new PdbLocalVariable(slot, this.host, pdbLocalScope.methodBody.MethodDefinition);
     uint index = 0;
     foreach (ILocalDefinition localDefinition in pdbLocalScope.methodBody.LocalVariables) {
       if (localDefinition.IsConstant) continue;
       if (slot.slot == index) {
         yield return localDefinition;
         break;
       }
       index++;
     }
   }
 }
Пример #45
0
 /// <summary>
 /// Returns zero or more local variable definitions that are local to the given scope.
 /// </summary>
 public IEnumerable<ILocalDefinition> GetVariablesInScope(ILocalScope scope)
 {
     PdbLocalScope/*?*/ pdbLocalScope = scope as PdbLocalScope;
       if (pdbLocalScope == null) yield break;
       uint index = 0;
       foreach (ILocalDefinition localDefinition in pdbLocalScope.methodBody.LocalVariables) {
     if (localDefinition.IsConstant) continue;
     foreach (PdbSlot slot in pdbLocalScope.pdbScope.slots) {
       if ((slot.flags & 1) != 0) continue;
       if (slot.slot == index) {
     yield return localDefinition;
     break;
       }
     }
     index++;
       }
 }