EmitFirstLineInfo() private method

private EmitFirstLineInfo ( ILGenerator ilgen ) : void
ilgen System.Reflection.Emit.ILGenerator
return void
Example #1
0
        internal TypeBuilder TranslateToILClass(CompilerGlobals compilerGlobals)
        {
            TypeBuilder classwriter = compilerGlobals.classwriter =
                compilerGlobals.module.DefineType("JScript " + (this.Engine.classCounter++).ToString(), TypeAttributes.Public, typeof(GlobalScope), null);

            compilerGlobals.classwriter.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.compilerGlobalScopeAttributeCtor, new Object[0]));

            //Define a constructor that calls the appropriate constructor on GlobalScope
            ConstructorBuilder cons = compilerGlobals.classwriter.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { typeof(GlobalScope) });
            ILGenerator        il   = cons.GetILGenerator();

            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldarg_1);
            il.Emit(OpCodes.Dup);
            il.Emit(OpCodes.Ldfld, CompilerGlobals.engineField);
            il.Emit(OpCodes.Call, CompilerGlobals.GlobalScopeConstructor);
            il.Emit(OpCodes.Ret);

            //Define a method to contain the global code
            MethodBuilder mw = classwriter.DefineMethod("Global Code", MethodAttributes.Public, Typeob.Object, null);

            il = mw.GetILGenerator();

            if (this.Engine.GenerateDebugInfo)
            {
                ScriptObject ns = this.own_scope.GetParent();
                while (ns != null)
                {
                    if (ns is WrappedNamespace && !((WrappedNamespace)ns).name.Equals(""))
                    {
                        il.UsingNamespace(((WrappedNamespace)ns).name);
                    }
                    ns = ns.GetParent();
                }
            }

            int startLine = this.context.StartLine;
            int startCol  = this.context.StartColumn;
            //this.context.document.EmitLineInfo(il, startLine, startCol, startLine, startCol + 1); // NOTE: make the debugger stop at line 1 in the jscript source instead of in prolog code
            Context firstContext = this.GetFirstExecutableContext();

            if (firstContext != null)
            {
                firstContext.EmitFirstLineInfo(il);
            }

            //Emit code to push the scope onto the stack for use by eval
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Call, CompilerGlobals.pushScriptObjectMethod);
            this.TranslateToILInitializer(il);
            this.TranslateToIL(il, Typeob.Object);
            this.EmitILToLoadEngine(il);
            il.Emit(OpCodes.Call, CompilerGlobals.popScriptObjectMethod);
            il.Emit(OpCodes.Pop);
            il.Emit(OpCodes.Ret);

            return(classwriter);
        }
Example #2
0
        internal TypeBuilder TranslateToILClass(CompilerGlobals compilerGlobals, bool pushScope)
        {
            VsaEngine   engine  = base.Engine;
            int         num2    = engine.classCounter++;
            TypeBuilder builder = compilerGlobals.classwriter = compilerGlobals.module.DefineType("JScript " + num2.ToString(CultureInfo.InvariantCulture), TypeAttributes.Public, Typeob.GlobalScope, (Type[])null);

            compilerGlobals.classwriter.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.compilerGlobalScopeAttributeCtor, new object[0]));
            if (null == compilerGlobals.globalScopeClassWriter)
            {
                compilerGlobals.globalScopeClassWriter = builder;
            }
            ILGenerator iLGenerator = compilerGlobals.classwriter.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { Typeob.GlobalScope }).GetILGenerator();

            iLGenerator.Emit(OpCodes.Ldarg_0);
            iLGenerator.Emit(OpCodes.Ldarg_1);
            iLGenerator.Emit(OpCodes.Dup);
            iLGenerator.Emit(OpCodes.Ldfld, CompilerGlobals.engineField);
            iLGenerator.Emit(OpCodes.Call, CompilerGlobals.globalScopeConstructor);
            iLGenerator.Emit(OpCodes.Ret);
            iLGenerator = builder.DefineMethod("Global Code", MethodAttributes.Public, Typeob.Object, null).GetILGenerator();
            if (base.Engine.GenerateDebugInfo)
            {
                for (ScriptObject obj2 = this.own_scope.GetParent(); obj2 != null; obj2 = obj2.GetParent())
                {
                    if ((obj2 is WrappedNamespace) && !((WrappedNamespace)obj2).name.Equals(""))
                    {
                        iLGenerator.UsingNamespace(((WrappedNamespace)obj2).name);
                    }
                }
            }
            int     startLine              = base.context.StartLine;
            int     startColumn            = base.context.StartColumn;
            Context firstExecutableContext = this.GetFirstExecutableContext();

            if (firstExecutableContext != null)
            {
                firstExecutableContext.EmitFirstLineInfo(iLGenerator);
            }
            if (pushScope)
            {
                base.EmitILToLoadEngine(iLGenerator);
                iLGenerator.Emit(OpCodes.Ldarg_0);
                iLGenerator.Emit(OpCodes.Call, CompilerGlobals.pushScriptObjectMethod);
            }
            this.TranslateToILInitializer(iLGenerator);
            this.TranslateToIL(iLGenerator, Typeob.Object);
            if (pushScope)
            {
                base.EmitILToLoadEngine(iLGenerator);
                iLGenerator.Emit(OpCodes.Call, CompilerGlobals.popScriptObjectMethod);
                iLGenerator.Emit(OpCodes.Pop);
            }
            iLGenerator.Emit(OpCodes.Ret);
            return(builder);
        }