System.Xml.Xsl.IlGen.GenerateHelper.MethodBegin C# (CSharp) Method

MethodBegin() public method

Begin generating code within a new method.
public MethodBegin ( MethodBase methInfo, ISourceLineInfo sourceInfo, bool initWriters ) : void
methInfo MethodBase
sourceInfo ISourceLineInfo
initWriters bool
return void
        public void MethodBegin(MethodBase methInfo, ISourceLineInfo sourceInfo, bool initWriters)
        {
            _methInfo = methInfo;
            _ilgen = XmlILModule.DefineMethodBody(methInfo);
            _lastSourceInfo = null;

#if DEBUG
            if (XmlILTrace.IsEnabled) {
                this.numLocals = 0;
                this.symbols = new Hashtable();
                this.lblNum = 0;
                this.sourceFile = null;

                this.writerDump = XmlILTrace.GetTraceWriter("dump.il");
                this.writerDump.WriteLine(".method {0}()", methInfo.Name);
                this.writerDump.WriteLine("{");
            }
#endif

            if (_isDebug)
            {
                DebugStartScope();

                // DebugInfo: Sequence point just before generating code for this function
                if (sourceInfo != null)
                {
                    // Don't call DebugSequencePoint, as it puts Nop *before* the sequence point.  That is
                    // wrong in this case, because we need source line information to be emitted before any
                    // IL instruction so that stepping into this function won't end up in the assembly window.
                    // We still guarantee that:
                    //   1. Two sequence points are never adjacent, since this is the 1st sequence point
                    //   2. Stack depth is 0, since this is the very beginning of the method
                    MarkSequencePoint(sourceInfo);
                    Emit(OpCodes.Nop);
                }
            }
            else if (_module.EmitSymbols)
            {
                // For a retail build, put source information on methods only
                if (sourceInfo != null)
                {
                    MarkSequencePoint(sourceInfo);
                    // Set this.lastSourceInfo back to null to prevent generating additional sequence points
                    // in this method.
                    _lastSourceInfo = null;
                }
            }

            _initWriters = false;
            if (initWriters)
            {
                EnsureWriter();
                LoadQueryRuntime();
                Call(XmlILMethods.GetOutput);
                Emit(OpCodes.Stloc, _locXOut);
            }
        }

Usage Example

Esempio n. 1
0
        //-----------------------------------------------
        // Entry
        //-----------------------------------------------

        /// <summary>
        /// Visits the specified QilExpression graph and generates MSIL code.
        /// </summary>
        public void Visit(QilExpression qil, GenerateHelper helper, MethodInfo methRoot)
        {
            _qil = qil;
            _helper = helper;
            _iterNested = null;
            _indexId = 0;

            // Prepare each global parameter and global variable to be visited
            PrepareGlobalValues(qil.GlobalParameterList);
            PrepareGlobalValues(qil.GlobalVariableList);

            // Visit each global parameter and global variable
            VisitGlobalValues(qil.GlobalParameterList);
            VisitGlobalValues(qil.GlobalVariableList);

            // Build each function
            foreach (QilFunction ndFunc in qil.FunctionList)
            {
                // Visit each parameter and the function body
                Function(ndFunc);
            }

            // Build the root expression
            _helper.MethodBegin(methRoot, null, true);
            StartNestedIterator(qil.Root);
            Visit(qil.Root);
            Debug.Assert(_iterCurr.Storage.Location == ItemLocation.None, "Root expression should have been pushed to the writer.");
            EndNestedIterator(qil.Root);
            _helper.MethodEnd();
        }