CloseScope() public method

public CloseScope ( int endOffset ) : void
endOffset int
return void
Beispiel #1
0
        public void Write(MethodBody body, /*Telerik Authorship*/ MetadataToken methodToken, /*Telerik Authorship*/ MetadataToken localVarToken)
        {
            /*Telerik Authorship*/
            //var method_token = body.Method.MetadataToken;
            var sym_token = new SymbolToken(methodToken.ToInt32());
            //var sym_token = new SymbolToken(body.Method.MetadataToken.ToInt32());

            var instructions = CollectInstructions(body);

            if (instructions.Count == 0)
            {
                return;
            }

            var start_offset = 0;
            var end_offset   = body.CodeSize;

            writer.OpenMethod(sym_token);
            writer.OpenScope(start_offset);

            DefineSequencePoints(instructions);

            /*Telerik Authorship*/
            Dictionary <VariableDefinition, string> methodVariableDefinitionToNameMap =
                GetMethodVariableDefinitionToNameMap(body.Method);

            DefineVariables(body, /*Telerik Authorship*/ localVarToken, /*Telerik Authorship*/ methodVariableDefinitionToNameMap, start_offset, end_offset);

            writer.CloseScope(end_offset);
            writer.CloseMethod();
        }
Beispiel #2
0
        public void Write(MethodBody body)
        {
            var method_token = body.Method.MetadataToken;
            var sym_token    = new SymbolToken(method_token.ToInt32());

            var instructions = CollectInstructions(body);

            if (instructions.Count == 0)
            {
                return;
            }

            var start_offset = 0;
            var end_offset   = body.CodeSize;

            writer.OpenMethod(sym_token);
            writer.OpenScope(start_offset);

            DefineSequencePoints(instructions);
            DefineVariables(body, start_offset, end_offset);

            writer.CloseScope(end_offset);

            if (body.IteratorType != null)
            {
                DefineIteratorType(sym_token, body.IteratorType.Name);
            }

            if (body.iterator_scopes != null)
            {
                DefineIteratorScopes(sym_token, body.IteratorScopes, body.CodeSize);
            }

            writer.CloseMethod();
        }
Beispiel #3
0
        void DefineScope(ScopeDebugInformation scope, MethodDebugInformation info)
        {
            var start_offset = scope.Start.Offset;
            var end_offset   = scope.End.IsEndOfMethod
                                ? info.code_size
                                : scope.End.Offset;

            writer.OpenScope(start_offset);

            var sym_token = new SymbolToken(info.local_var_token.ToInt32());

            if (!scope.variables.IsNullOrEmpty())
            {
                for (int i = 0; i < scope.variables.Count; i++)
                {
                    var variable = scope.variables [i];
                    CreateLocalVariable(variable, sym_token, start_offset, end_offset);
                }
            }

            if (!scope.scopes.IsNullOrEmpty())
            {
                for (int i = 0; i < scope.scopes.Count; i++)
                {
                    DefineScope(scope.scopes [i], info);
                }
            }

            writer.CloseScope(end_offset);
        }
Beispiel #4
0
        void CreateScopes(MethodBody body, ScopeCollection scopes, SymbolToken localVarToken)
        {
            foreach (Scope s in scopes)
            {
                int startOffset = s.Start.Offset;
                int endOffset   = s.End == body.Instructions.Outside ?
                                  body.Instructions[body.Instructions.Count - 1].Offset + 1 :
                                  s.End.Offset;

                m_writer.OpenScope(startOffset);
                m_writer.UsingNamespace(body.Method.DeclaringType.Namespace);
                m_writer.OpenNamespace(body.Method.DeclaringType.Namespace);

                int start = body.Instructions.IndexOf(s.Start);
                int end   = s.End == body.Instructions.Outside ?
                            body.Instructions.Count - 1 :
                            body.Instructions.IndexOf(s.End);

                ArrayList instructions = CollectSequencePoints(body, start, end);
                DefineSequencePoints(instructions);

                CreateLocalVariable(s, startOffset, endOffset, localVarToken);

                CreateScopes(body, s.Scopes, localVarToken);
                m_writer.CloseNamespace();

                m_writer.CloseScope(endOffset);
            }
        }
Beispiel #5
0
        public void Write(MethodBody body)
        {
            var method_token = body.Method.MetadataToken;
            var sym_token    = new SymbolToken(method_token.ToInt32());

            var instructions = CollectInstructions(body);

            if (instructions.Count == 0 && !body.HasVariables)
            {
                return;
            }

            var pdbSymbols = body.Symbols as PdbMethodSymbols;

            writer.OpenMethod(sym_token);

            DefineSequencePoints(instructions);

            if (body.Scope != null)
            {
                WriteScope(body, body.Scope, true);
            }
            else
            {
                writer.OpenScope(0);
                DefineUsedNamespaces(pdbSymbols);
                if (body.HasVariables)
                {
                    DefineVariables(body, body.Variables, 0, body.CodeSize);
                }
                writer.CloseScope(body.CodeSize);
            }

            DefineCustomMetadata(pdbSymbols);

            writer.CloseMethod();
        }
Beispiel #6
0
        void DefineScope(ScopeDebugInformation scope, MethodDebugInformation info, out MetadataToken import_parent)
        {
            var start_offset = scope.Start.Offset;
            var end_offset   = scope.End.IsEndOfMethod
                                ? info.code_size
                                : scope.End.Offset;

            import_parent = new MetadataToken(0u);

            writer.OpenScope(start_offset);

            if (scope.Import != null && scope.Import.HasTargets && !import_info_to_parent.TryGetValue(info.scope.Import, out import_parent))
            {
                foreach (var target in scope.Import.Targets)
                {
                    switch (target.Kind)
                    {
                    case ImportTargetKind.ImportNamespace:
                        writer.UsingNamespace("U" + target.@namespace);
                        break;

                    case ImportTargetKind.ImportType:
                        writer.UsingNamespace("T" + TypeParser.ToParseable(target.type));
                        break;

                    case ImportTargetKind.DefineNamespaceAlias:
                        writer.UsingNamespace("A" + target.Alias + " U" + target.@namespace);
                        break;

                    case ImportTargetKind.DefineTypeAlias:
                        writer.UsingNamespace("A" + target.Alias + " T" + TypeParser.ToParseable(target.type));
                        break;
                    }
                }

                import_info_to_parent.Add(info.scope.Import, info.method.MetadataToken);
            }

            var sym_token = info.local_var_token.ToInt32();

            if (!scope.variables.IsNullOrEmpty())
            {
                for (int i = 0; i < scope.variables.Count; i++)
                {
                    var variable = scope.variables [i];
                    DefineLocalVariable(variable, sym_token, start_offset, end_offset);
                }
            }

            if (!scope.constants.IsNullOrEmpty())
            {
                for (int i = 0; i < scope.constants.Count; i++)
                {
                    var constant = scope.constants [i];
                    DefineConstant(constant);
                }
            }

            if (!scope.scopes.IsNullOrEmpty())
            {
                for (int i = 0; i < scope.scopes.Count; i++)
                {
                    MetadataToken _;
                    DefineScope(scope.scopes [i], info, out _);
                }
            }

            writer.CloseScope(end_offset);
        }