static bool AddScope(Scope provider, Scope scope) { foreach (var sub_scope in provider.Scopes) { if (AddScope (sub_scope, scope)) return true; if (scope.Start.Offset >= sub_scope.Start.Offset && scope.End.Offset <= sub_scope.End.Offset) { sub_scope.Scopes.Add (scope); return true; } } return false; }
private void WriteScope(Scope scope, bool root) { if (scope.Start.Offset == scope.End.Offset) return; writer.OpenScope (scope.Start.Offset); if (scope.HasVariables) { foreach (var el in scope.Variables) { if (!String.IsNullOrEmpty (el.Name)) writer.DefineLocalVariable (el.Index, el.Name); } } if (scope.HasScopes) { foreach (var el in scope.Scopes) WriteScope (el, false); } writer.CloseScope (scope.End.Offset + scope.End.GetSize()); }
static void CreateRootScope(MethodBody body) { if (!body.HasVariables) return; var instructions = body.Instructions; var root = new Scope (); root.Start = instructions [0]; root.End = instructions [instructions.Count - 1]; var variables = body.Variables; for (int i = 0; i < variables.Count; i++) root.Variables.Add (variables [i]); body.Scope = root; }
static void ReadScopeAndLocals(PdbScope scope, Scope parent, MethodBody body, InstructionMapper mapper) { //Scope s = new Scope (); //s.Start = GetInstruction (body, instructions, (int) scope.address); //s.End = GetInstruction (body, instructions, (int) scope.length - 1); //if (parent != null) // parent.Scopes.Add (s); //else // body.Scopes.Add (s); if (scope == null) return; foreach (PdbSlot slot in scope.slots) { int index = (int) slot.slot; if (index < 0 || index >= body.Variables.Count) continue; VariableDefinition variable = body.Variables [index]; variable.Name = slot.name; //s.Variables.Add (variable); } ReadScopeAndLocals (scope.scopes, null /* s */, body, mapper); }
static void ReadScopeAndLocals(PdbScope [] scopes, Scope parent, MethodBody body, InstructionMapper mapper) { foreach (PdbScope scope in scopes) ReadScopeAndLocals (scope, parent, body, mapper); CreateRootScope (body); }
static Scope[] ReadScopes(MethodEntry entry, MethodBody body, InstructionMapper mapper) { var blocks = entry.GetCodeBlocks (); var scopes = new Scope [blocks.Length]; foreach (var block in blocks) { if (block.BlockType != CodeBlockEntry.Type.Lexical) continue; var scope = new Scope (); scope.Start = mapper (block.StartOffset); scope.End = mapper (block.EndOffset); scopes [block.Index] = scope; if (body.Scope == null) body.Scope = scope; if (!AddScope (body.Scope, scope)) body.Scope = scope; } return scopes; }
static void ReadLocalVariables(MethodEntry entry, MethodBody body, Scope [] scopes) { var locals = entry.GetLocals (); foreach (var local in locals) { if (local.Index < 0 || local.Index >= body.Variables.Count) // Mono 2.6 emits wrong local infos for iterators continue; var variable = body.Variables [local.Index]; variable.Name = local.Name; var index = local.BlockIndex; if (index < 0 || index >= scopes.Length) continue; var scope = scopes [index]; if (scope == null) continue; scope.Variables.Add (variable); } }