Пример #1
0
        /// <summary>
        /// Close the current scope at the given offset.
        /// </summary>
        /// <param name="offset">The offset of where to close the scope.</param>
        public void CloseScope(int offset)
        {

            // Make sure a scope is open
            if (currentScope == null)
                throw new Exception("You can not close a scope now, none are open.");

            // Set the end offset for this scope and close it.
            currentScope.OffsetEnd = offset;
            currentScope = currentScope.ParentScope;

        }
Пример #2
0
        /// <summary>
        /// Write out the scopes and the locals to the PDB file.
        /// </summary>
        /// <param name="symWriter">The symbol writer for this file.</param>
        /// <param name="scope">The scope to write out.</param>
        private static void WriteScopeAndLocals(QSy.SymbolWriter symWriter, Scope scope)
        {
            // Open the scope
            symWriter.OpenScope(scope.OffsetStart);

            // Add each local variable
            foreach (LocalBinding lb in scope.Locals)
            {
                symWriter.DefineLocalVariable2(
                    lb.Name,
                    0,
#if SIMPLEWRITER
                    lb.Token.GetToken(),
#else
                    lb.Token,              
#endif
                    1,
                    lb.Index,
                    0,
                    0,
                    lb.OffsetStart,
                    lb.OffsetEnd
                );
            }

            // Add each constants
            /* For now don't add constants.  Doesn't work. AKB 09-01-2007
            foreach (ConstantBinding cb in scope.Constants) {
                symWriter.DefineConstant(
                    cb.Name,
                    cb.Value,
                    cb.GetSig()
                );
            }
            */

            // Add any child scopes
            foreach (Scope childScope in scope.ChildScopes)
                WriteScopeAndLocals(symWriter, childScope);

            // Close the scope
            symWriter.CloseScope(scope.OffsetEnd);

        }
Пример #3
0
 /// <summary>
 /// Close the current scope.
 /// </summary>
 public void CloseScope()
 {
     //Console.WriteLine("Close scope on " + currentScope._thisMeth.Name());
       AddToBuffer(new CloseScope(currentScope));
       currentScope = currentScope._parent;
 }
Пример #4
0
        /// <summary>
        /// Open a new scope.
        /// </summary>
        /// <param name="offset">Offset as to where the scope should start.</param>
        public void OpenScope(int offset)
        {

            // Make sure we are in a method
            if (currentMethod == null)
                throw new Exception("You can not open a scope before opening a method.");

            // Create and add the new scope
            Scope scope = new Scope();
            scope.OffsetStart = offset;
            scope.ParentScope = currentScope;

            // Check if this is the first/root scope or a child scope.
            if (currentScope == null)
            {

                // Check to make sure we don't try to create two root scopes.
                if (currentMethod.Scope != null)
                    throw new Exception("Only one top-most scope is permitted.");

                currentMethod.Scope = scope;
            }
            else
            {
                currentScope.ChildScopes.Add(scope);
            }

            // Set the current scope
            currentScope = scope;

        }
Пример #5
0
 internal Scope(Scope parent, MethodDef thisMeth)
 {
     _thisMeth = thisMeth;
       _parent = parent;
 }
Пример #6
0
 /// <summary>
 /// Create a new OpenScope instruction.
 /// </summary>
 /// <param name="scope">The scope that is being opened.</param>
 public OpenScope(Scope scope)
 {
     size = 0;
       _scope = scope;
 }
Пример #7
0
 /// <summary>
 /// The constructor to build a new CloseScope instruction.
 /// </summary>
 /// <param name="scope">The scope to close.</param>
 public CloseScope(Scope scope)
 {
     size = 0;
       _scope = scope;
 }
Пример #8
0
 /// <summary>
 /// Open a new scope.
 /// </summary>
 public void OpenScope()
 {
     currentScope = new Scope(currentScope, thisMeth);
       AddToBuffer(new OpenScope(currentScope));
       //Console.WriteLine("Open scope on " + currentScope._thisMeth.Name());
 }
Пример #9
0
        private static Scope ReadPDBScope(PDBScope scope, MergeBuffer mergeBuffer, [CanBeNull] Scope parent, MethodDef thisMeth)
        {
            Contract.Requires(scope != null);
            Contract.Requires(thisMeth != null);
            Scope thisScope = new Scope(parent, thisMeth);

            if (parent != null) mergeBuffer.Add(new OpenScope(thisScope), (uint)scope.StartOffset);

            foreach (PDBVariable var in scope.Variables)
                thisScope.AddLocalBinding(var.Name, var.Address);

            foreach (PDBScope child in scope.Children)
                ReadPDBScope(child, mergeBuffer, thisScope, thisMeth);

            if (parent != null) mergeBuffer.Add(new CloseScope(thisScope), (uint)scope.EndOffset);

            return thisScope;
        }