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); }
internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals) { if (this.method is JSMethod) { return ((JSMethod) this.method).GetMethodInfo(compilerGlobals); } return this.method; }
internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals) { if (this.method is JSMethod) { return(((JSMethod)this.method).GetMethodInfo(compilerGlobals)); } return(this.method); }
internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals){ if (this.isGetter){ if (this.token == null) this.token = this.classScope.owner.GetExpandoIndexerGetter(); }else{ if (this.token == null) this.token = this.classScope.owner.GetExpandoIndexerSetter(); } return this.token; }
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); }
internal DocumentContext(String name, VsaEngine engine){ this.documentName = name; this.documentWriter = null; this.startLine = 0; this.startCol = 0; this.lastLineInSource = 0; this.sourceItem = null; this.engine = engine; this.debugOn = null == engine ? false : engine.GenerateDebugInfo; this._compilerGlobals = null; this.reportedVariables = null; this.checkForFirst = false; }
internal DocumentContext(String documentName, int startLine, int startCol, int lastLineInSource, VsaItem sourceItem) { this.documentName = documentName; this.documentWriter = null; this.startLine = startLine; this.startCol = startCol; this.lastLineInSource = lastLineInSource; this.sourceItem = sourceItem; this.engine = sourceItem.engine; this.debugOn = null == engine ? false : engine.GenerateDebugInfo; this._compilerGlobals = null; this.checkForFirst = false; }
internal DocumentContext(string documentName, int startLine, int startCol, int lastLineInSource, VsaItem sourceItem) { this.documentName = documentName; this.documentWriter = null; this.startLine = startLine; this.startCol = startCol; this.lastLineInSource = lastLineInSource; this.sourceItem = sourceItem; this.engine = sourceItem.engine; this.debugOn = (this.engine != null) && this.engine.GenerateDebugInfo; this._compilerGlobals = null; this.checkForFirst = false; }
internal DocumentContext(String name, VsaEngine engine) { this.documentName = name; this.documentWriter = null; this.startLine = 0; this.startCol = 0; this.lastLineInSource = 0; this.sourceItem = null; this.engine = engine; this.debugOn = null == engine ? false : engine.GenerateDebugInfo; this._compilerGlobals = null; this.reportedVariables = null; this.checkForFirst = false; }
internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals) { if (this.isGetter) { if (this.token == null) { this.token = this.classScope.owner.GetExpandoIndexerGetter(); } } else if (this.token == null) { this.token = this.classScope.owner.GetExpandoIndexerSetter(); } return(this.token); }
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; }
internal DocumentContext(VsaItem sourceItem){ if (sourceItem.codebase != null) this.documentName = sourceItem.codebase; else{ string rootMoniker = sourceItem.engine.RootMoniker; this.documentName = rootMoniker + (rootMoniker.EndsWith("/", StringComparison.Ordinal) ? "" : "/") + sourceItem.Name; } this.documentWriter = null; this.startLine = 0; this.startCol = 0; this.lastLineInSource = 0; this.sourceItem = sourceItem; this.engine = sourceItem.engine; this.debugOn = null == engine ? false : engine.GenerateDebugInfo; this._compilerGlobals = null; this.checkForFirst = false; }
internal DocumentContext(VsaItem sourceItem) { if (sourceItem.codebase != null) { this.documentName = sourceItem.codebase; } else { string rootMoniker = sourceItem.engine.RootMoniker; this.documentName = rootMoniker + (rootMoniker.EndsWith("/", StringComparison.Ordinal) ? "" : "/") + sourceItem.Name; } this.documentWriter = null; this.startLine = 0; this.startCol = 0; this.lastLineInSource = 0; this.sourceItem = sourceItem; this.engine = sourceItem.engine; this.debugOn = null == engine ? false : engine.GenerateDebugInfo; this._compilerGlobals = null; this.checkForFirst = false; }
internal TypeBuilder TranslateToILClass(CompilerGlobals compilerGlobals) { return(TranslateToILClass(compilerGlobals, true)); }
public VsaEngine(bool fast) : base("JScript", VsaEngine.engineVersion, true){ this.alwaysGenerateIL = false; this.autoRef = false; this.doCRS = false; this.doFast = fast; this.genDebugInfo = false; this.genStartupClass = true; this.doPrint = false; this.doWarnAsError = false; this.nWarningLevel = 4; this.isCLSCompliant = false; this.versionSafe = false; this.PEFileName = null; this.PEFileKind = PEFileKinds.Dll; this.PEKindFlags = PortableExecutableKinds.ILOnly; this.PEMachineArchitecture = ImageFileMachine.I386; this.ReferenceLoaderAPI = LoaderAPI.LoadFrom; this.errorCultureInfo = null; this.libpath = null; this.libpathList = null; this.globalScope = null; this.vsaItems = new VsaItems(this); this.packages = null; this.scopes = null; this.classCounter = 0; this.implicitAssemblies = null; this.implicitAssemblyCache = null; this.cachedTypeLookups = null; this.isEngineRunning = false; this.isEngineCompiled = false; this.isCompilerSet = false; this.isClosed = false; this.runningThread = null; this.compilerGlobals = null; this.globals = null; this.runtimeDirectory = null; Globals.contextEngine = this; this.runtimeAssembly = null; this.typenameTable = null; }
internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals) { return(this.method); }
internal MethodBase GetMethodBase(CompilerGlobals compilerGlobals){ if (this.mb != null) return this.mb; if (this.cb != null) return this.cb; JSFunctionAttributeEnum jsFunctionAttributes = 0; int extras = 3; if (this.isMethod){ if (this.isConstructor && ((ClassScope)this.enclosing_scope).outerClassField != null){ extras = 1; jsFunctionAttributes |= JSFunctionAttributeEnum.IsInstanceNestedClassConstructor; }else extras = 0; }else if (!this.hasArgumentsObject) extras = 2; int np = this.formal_parameters.Length+extras; Type[] ptypes = new Type[np]; Type rtype = Convert.ToType(this.ReturnType(null)); if (extras > 0){ if (this.isConstructor) ptypes[np-1] = ((ClassScope)this.enclosing_scope).outerClassField.FieldType; else ptypes[0] = Typeob.Object; jsFunctionAttributes |= JSFunctionAttributeEnum.HasThisObject; } if (extras > 1){ ptypes[1] = Typeob.VsaEngine; jsFunctionAttributes |= JSFunctionAttributeEnum.HasEngine; } if (extras > 2){ ptypes[2] = Typeob.Object; jsFunctionAttributes |= JSFunctionAttributeEnum.HasArguments; } if (this.must_save_stack_locals) jsFunctionAttributes |= JSFunctionAttributeEnum.HasStackFrame; if (this.isExpandoMethod) jsFunctionAttributes |= JSFunctionAttributeEnum.IsExpandoMethod; if (this.isConstructor){ for (int i = 0; i < np-extras; i++) ptypes[i] = this.parameter_declarations[i].ParameterType; }else{ for (int i = extras; i < np; i++) ptypes[i] = this.parameter_declarations[i-extras].ParameterType; } if (this.enclosing_scope is ClassScope) if (this.isConstructor){ this.cb = ((ClassScope)(this.enclosing_scope)).GetTypeBuilder().DefineConstructor(this.attributes&MethodAttributes.MemberAccessMask, CallingConventions.Standard, ptypes); }else{ String name = this.name; if (this.implementedIfaceMethod != null){ JSMethod jsm = this.implementedIfaceMethod as JSMethod; if (jsm != null) this.implementedIfaceMethod = jsm.GetMethodInfo(compilerGlobals); name = this.implementedIfaceMethod.DeclaringType.FullName + "." + name; } TypeBuilder tb = ((ClassScope)(this.enclosing_scope)).GetTypeBuilder(); if (this.mb != null) return this.mb; //Might have been defined as a result of the above call this.mb = tb.DefineMethod(name, this.attributes, rtype, ptypes); if (this.implementedIfaceMethod != null) ((ClassScope)(this.enclosing_scope)).GetTypeBuilder().DefineMethodOverride(this.mb, this.implementedIfaceMethod); } else{ if (enclosing_scope is FunctionScope){ //dealing with a nested function/function expression. Mangle the name. if (((FunctionScope)enclosing_scope).owner != null){ this.name = ((FunctionScope)enclosing_scope).owner.name+ "." + this.name; jsFunctionAttributes |= JSFunctionAttributeEnum.IsNested; }else{ //dealing with the dummy outer scope of a function expression ScriptObject escope = enclosing_scope; while (escope != null){ if (escope is FunctionScope && ((FunctionScope)escope).owner != null){ this.name = ((FunctionScope)escope).owner.name+ "." + this.name; jsFunctionAttributes |= JSFunctionAttributeEnum.IsNested; break; } escope = escope.GetParent(); } } } //The name could still be a duplicate, so check against a table of names already used. if (compilerGlobals.usedNames[this.name] != null) this.name = this.name + ":" + (compilerGlobals.usedNames.count).ToString(); compilerGlobals.usedNames[this.name] = this; this.mb = (this.classwriter = compilerGlobals.classwriter).DefineMethod(this.name, this.attributes, rtype, ptypes); } // the method is defined, we can now put debug info about the parameters if (extras > 0){ if (this.mb != null) this.mb.DefineParameter(1, (ParameterAttributes)0, "this"); else{ ParameterBuilder pb = this.cb.DefineParameter(np, (ParameterAttributes)0, "this"); pb.SetConstant(null); extras = 0; np--; } } if (extras > 1) this.mb.DefineParameter(2, (ParameterAttributes)0, "vsa Engine"); if (extras > 2) this.mb.DefineParameter(3, (ParameterAttributes)0, "arguments"); for (int i = extras; i < np; i++){ ParameterBuilder pb = this.mb != null ? this.mb.DefineParameter(i + 1, (ParameterAttributes)0, this.parameter_declarations[i-extras].identifier) : this.cb.DefineParameter(i + 1, (ParameterAttributes)0, this.parameter_declarations[i-extras].identifier); CustomAttributeList paramCustAttList = this.parameter_declarations[i-extras].customAttributes; if (paramCustAttList != null){ CustomAttributeBuilder[] paramCustomAttributes = paramCustAttList.GetCustomAttributeBuilders(false); for (int attIndex = 0; attIndex < paramCustomAttributes.Length; attIndex++) pb.SetCustomAttribute(paramCustomAttributes[attIndex]); } } if (jsFunctionAttributes > 0){ CustomAttributeBuilder cab = new CustomAttributeBuilder(CompilerGlobals.jsFunctionAttributeConstructor, new Object[1] {jsFunctionAttributes}); if (this.mb != null) this.mb.SetCustomAttribute(cab); else this.cb.SetCustomAttribute(cab); } // deal with custom attributes if (this.customAttributes != null){ CustomAttributeBuilder[] custAtt = this.customAttributes.GetCustomAttributeBuilders(false); for (int j = 0; j < custAtt.Length; j++){ if (this.mb != null) this.mb.SetCustomAttribute(custAtt[j]); else this.cb.SetCustomAttribute(custAtt[j]); } } if (this.clsCompliance == CLSComplianceSpec.CLSCompliant) if (this.mb != null) this.mb.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.clsCompliantAttributeCtor, new Object[]{true})); else this.cb.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.clsCompliantAttributeCtor, new Object[]{true})); else if (this.clsCompliance == CLSComplianceSpec.NonCLSCompliant) if (this.mb != null) this.mb.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.clsCompliantAttributeCtor, new Object[]{false})); else this.cb.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.clsCompliantAttributeCtor, new Object[]{false})); if (this.mb != null){ this.mb.InitLocals = true; return this.mb; }else{ this.cb.InitLocals = true; return this.cb; } }
internal abstract MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals);
internal abstract MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals);
internal void TranslateBodyToIL(ILGenerator il, CompilerGlobals compilerGlobals){ this.returnLabel = il.DefineLabel(); // Emit all the namespaces used by this function if (this.body.Engine.GenerateDebugInfo){ ScriptObject ns = this.enclosing_scope.GetParent(); while (ns != null){ if (ns is PackageScope) il.UsingNamespace(((PackageScope)ns).name); else if (ns is WrappedNamespace && !((WrappedNamespace)ns).name.Equals("")) il.UsingNamespace(((WrappedNamespace)ns).name); ns = ns.GetParent(); } } int startLine = this.body.context.StartLine; int startCol = this.body.context.StartColumn; this.body.context.document.EmitLineInfo(il, startLine, startCol, startLine, startCol + 1); if (this.body.context.document.debugOn) il.Emit(OpCodes.Nop); //set up the compiler to emit direct accesses to the locals and pars. int n = this.fields.Length; for (int i = 0; i < n; i++){ if (!this.fields[i].IsLiteral || this.fields[i].value is FunctionObject){ Type t = this.fields[i].FieldType; LocalBuilder tok = il.DeclareLocal(t); if (this.fields[i].debugOn) tok.SetLocalSymInfo(this.fields[i].debuggerName); this.fields[i].metaData = tok; } } globals.ScopeStack.Push(this.own_scope); try{ if (this.must_save_stack_locals){ this.TranslateToMethodWithStackFrame(il, compilerGlobals, true); return; } this.body.TranslateToILInitializer(il); this.body.TranslateToIL(il, Typeob.Void); il.MarkLabel(this.returnLabel); }finally{ globals.ScopeStack.Pop(); } }
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; }
public VsaEngine(bool fast) : base("JScript", "7.0.3300.0", true){ this.alwaysGenerateIL = false; this.autoRef = false; this.doCRS = false; this.doFast = fast; this.cachedPEFileName = ""; this.genDebugInfo = false; this.genStartupClass = true; this.doPrint = false; this.doWarnAsError = false; this.nWarningLevel = 4; this.isCLSCompliant = false; this.versionSafe = false; this.PEFileName = null; this.PEFileKind = PEFileKinds.Dll; this.errorCultureInfo = null; this.libpath = null; this.libpathList = null; this.globalScope = null; this.vsaItems = new VsaItems(this); this.packages = null; this.scopes = null; this.classCounter = 0; this.implicitAssemblies = null; this.implicitAssemblyCache = null; this.cachedTypeLookups = null; this.isEngineRunning = false; this.isEngineCompiled = false; this.isCompilerSet = false; this.isClosed = false; this.runningThread = null; this.compilerGlobals = null; this.globals = null; this.runtimeDirectory = null; Globals.contextEngine = this; this.runtimeAssembly = null; this.typenameTable = null; }
internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals){ return this.method; }
internal void TranslateToIL(CompilerGlobals compilerGlobals){ if (this.suppressIL) return; globals.ScopeStack.Push(this.own_scope); try{ if (this.mb == null && this.cb == null) this.GetMethodBase(compilerGlobals); int offset = (this.attributes&MethodAttributes.Static) == MethodAttributes.Static ? 0 : 1; int extras = 3; if (this.isMethod) extras = 0; else if (!this.hasArgumentsObject) extras = 2; ILGenerator il = this.mb != null ? this.mb.GetILGenerator() : this.cb.GetILGenerator(); this.returnLabel = il.DefineLabel(); // Emit all the namespaces used by this function if (this.body.Engine.GenerateDebugInfo){ ScriptObject ns = this.enclosing_scope.GetParent(); while (ns != null){ if (ns is PackageScope) il.UsingNamespace(((PackageScope)ns).name); else if (ns is WrappedNamespace && !((WrappedNamespace)ns).name.Equals("")) il.UsingNamespace(((WrappedNamespace)ns).name); ns = ns.GetParent(); } } if (!this.isImplicitCtor && this.body != null){ int startLine = this.body.context.StartLine; int startCol = this.body.context.StartColumn; this.body.context.document.EmitLineInfo(il, startLine, startCol, startLine, startCol + 1); if (this.body.context.document.debugOn) il.Emit(OpCodes.Nop); } //set up the compiler to emit direct accesses to the locals and pars. int n = this.fields.Length; for (int i = 0; i < n; i++){ int j = System.Array.IndexOf(this.formal_parameters, this.fields[i].Name); if (j >= 0) this.fields[i].metaData = (short)(j+extras+offset); else if (this.hasArgumentsObject && this.fields[i].Name.Equals("arguments")) this.fields[i].metaData = (short)(2+offset); else if (!this.fields[i].IsLiteral || this.fields[i].value is FunctionObject){ Type t = this.fields[i].FieldType; LocalBuilder tok = il.DeclareLocal(t); if (this.fields[i].debugOn) tok.SetLocalSymInfo(this.fields[i].debuggerName); this.fields[i].metaData = tok; }else if (this.own_scope.mustSaveStackLocals){ //Need to emit a field. FunctionDeclaration will initialize it with a closure LocalBuilder tok = il.DeclareLocal(this.fields[i].FieldType); this.fields[i].metaData = tok; } } if (this.isConstructor){ int pn = formal_parameters.Length+1; ClassScope cscope = (ClassScope)this.enclosing_scope; //Call the default super constructor followed by the field initializers if (this.superConstructor == null) cscope.owner.EmitInitialCalls(il, null, null, null, 0); else{ ParameterInfo[] pars = this.superConstructor.GetParameters(); if (this.superConstructorCall != null) cscope.owner.EmitInitialCalls(il, this.superConstructor, pars, this.superConstructorCall.arguments, pn); else cscope.owner.EmitInitialCalls(il, this.superConstructor, pars, null, pn); } } if ((this.isMethod || this.isConstructor) && this.must_save_stack_locals){ this.TranslateToMethodWithStackFrame(il, compilerGlobals, false); return; } this.TranslateToILToCopyOuterScopeLocals(il, true, null); bool savedInsideProtectedRegion = compilerGlobals.InsideProtectedRegion; compilerGlobals.InsideProtectedRegion = false; bool savedInsideFinally = compilerGlobals.InsideFinally; int savedFinallyStackTop = compilerGlobals.FinallyStackTop; compilerGlobals.InsideFinally = false; this.body.TranslateToILInitializer(il); this.body.TranslateToIL(il, Typeob.Void); compilerGlobals.InsideProtectedRegion = savedInsideProtectedRegion; compilerGlobals.InsideFinally = savedInsideFinally; compilerGlobals.FinallyStackTop = savedFinallyStackTop; il.MarkLabel(this.returnLabel); if (this.body.context.document.debugOn){ this.EmitLastLineInfo(il); il.Emit(OpCodes.Nop); } this.TranslateToILToSaveLocals(il); //put locals on heap so that nested functions can get to them if (this.own_scope.returnVar != null) il.Emit(OpCodes.Ldloc, (LocalBuilder)this.own_scope.returnVar.GetMetaData()); il.Emit(OpCodes.Ret); }finally{ globals.ScopeStack.Pop(); } }
internal void TranslateToIL(CompilerGlobals compilerGlobals) { if (!this.suppressIL) { this.globals.ScopeStack.Push(this.own_scope); try { if ((this.mb == null) && (this.cb == null)) { this.GetMethodBase(compilerGlobals); } int num = ((this.attributes & MethodAttributes.Static) == MethodAttributes.Static) ? 0 : 1; int num2 = 3; if (this.isMethod) { num2 = 0; } else if (!this.hasArgumentsObject) { num2 = 2; } ILGenerator ilgen = (this.mb != null) ? this.mb.GetILGenerator() : this.cb.GetILGenerator(); this.returnLabel = ilgen.DefineLabel(); if (this.body.Engine.GenerateDebugInfo) { for (ScriptObject obj2 = this.enclosing_scope.GetParent(); obj2 != null; obj2 = obj2.GetParent()) { if (obj2 is PackageScope) { ilgen.UsingNamespace(((PackageScope) obj2).name); } else if ((obj2 is WrappedNamespace) && !((WrappedNamespace) obj2).name.Equals("")) { ilgen.UsingNamespace(((WrappedNamespace) obj2).name); } } } if (!this.isImplicitCtor && (this.body != null)) { int startLine = this.body.context.StartLine; int startColumn = this.body.context.StartColumn; this.body.context.document.EmitLineInfo(ilgen, startLine, startColumn, startLine, startColumn + 1); if (this.body.context.document.debugOn) { ilgen.Emit(OpCodes.Nop); } } int length = this.fields.Length; for (int i = 0; i < length; i++) { int num7 = this.IsNestedFunctionField(this.fields[i]) ? -1 : Array.IndexOf<string>(this.formal_parameters, this.fields[i].Name); if (num7 >= 0) { this.fields[i].metaData = (short) ((num7 + num2) + num); } else if (this.hasArgumentsObject && this.fields[i].Name.Equals("arguments")) { this.fields[i].metaData = (short) (2 + num); } else if (!this.fields[i].IsLiteral || (this.fields[i].value is FunctionObject)) { Type fieldType = this.fields[i].FieldType; LocalBuilder builder = ilgen.DeclareLocal(fieldType); if (this.fields[i].debugOn) { builder.SetLocalSymInfo(this.fields[i].debuggerName); } this.fields[i].metaData = builder; } else if (this.own_scope.mustSaveStackLocals) { LocalBuilder builder2 = ilgen.DeclareLocal(this.fields[i].FieldType); this.fields[i].metaData = builder2; } } if (this.isConstructor) { int callerParameterCount = this.formal_parameters.Length + 1; ClassScope scope = (ClassScope) this.enclosing_scope; if (this.superConstructor == null) { scope.owner.EmitInitialCalls(ilgen, null, null, null, 0); } else { ParameterInfo[] parameters = this.superConstructor.GetParameters(); if (this.superConstructorCall != null) { scope.owner.EmitInitialCalls(ilgen, this.superConstructor, parameters, this.superConstructorCall.arguments, callerParameterCount); } else { scope.owner.EmitInitialCalls(ilgen, this.superConstructor, parameters, null, callerParameterCount); } } } if ((this.isMethod || this.isConstructor) && this.must_save_stack_locals) { this.TranslateToMethodWithStackFrame(ilgen, compilerGlobals, false); } else { this.TranslateToILToCopyOuterScopeLocals(ilgen, true, null); bool insideProtectedRegion = compilerGlobals.InsideProtectedRegion; compilerGlobals.InsideProtectedRegion = false; bool insideFinally = compilerGlobals.InsideFinally; int finallyStackTop = compilerGlobals.FinallyStackTop; compilerGlobals.InsideFinally = false; this.body.TranslateToILInitializer(ilgen); this.body.TranslateToIL(ilgen, Typeob.Void); compilerGlobals.InsideProtectedRegion = insideProtectedRegion; compilerGlobals.InsideFinally = insideFinally; compilerGlobals.FinallyStackTop = finallyStackTop; ilgen.MarkLabel(this.returnLabel); if (this.body.context.document.debugOn) { this.EmitLastLineInfo(ilgen); ilgen.Emit(OpCodes.Nop); } this.TranslateToILToSaveLocals(ilgen); if (this.own_scope.returnVar != null) { ilgen.Emit(OpCodes.Ldloc, (LocalBuilder) this.own_scope.returnVar.GetMetaData()); } ilgen.Emit(OpCodes.Ret); } } finally { this.globals.ScopeStack.Pop(); } } }
internal ConstructorInfo GetConstructorInfo(CompilerGlobals compilerGlobals) { return(this.cons.GetConstructorInfo(compilerGlobals)); }
protected override void DoClose(){ ((VsaItems)this.vsaItems).Close(); if (null != this.globalScope) this.globalScope.Close(); this.vsaItems = null; this.engineSite = null; this.globalScope = null; this.runningThread = null; this.compilerGlobals = null; this.globals = null; ScriptStream.Out = Console.Out; ScriptStream.Error = Console.Error; this.rawPE = null; this.rawPDB = null; this.isClosed = true; if (this.tempDirectory != null && Directory.Exists(this.tempDirectory)) Directory.Delete(this.tempDirectory); }
internal void TranslateBodyToIL(ILGenerator il, CompilerGlobals compilerGlobals) { this.returnLabel = il.DefineLabel(); if (this.body.Engine.GenerateDebugInfo) { for (ScriptObject obj2 = this.enclosing_scope.GetParent(); obj2 != null; obj2 = obj2.GetParent()) { if (obj2 is PackageScope) { il.UsingNamespace(((PackageScope) obj2).name); } else if ((obj2 is WrappedNamespace) && !((WrappedNamespace) obj2).name.Equals("")) { il.UsingNamespace(((WrappedNamespace) obj2).name); } } } int startLine = this.body.context.StartLine; int startColumn = this.body.context.StartColumn; this.body.context.document.EmitLineInfo(il, startLine, startColumn, startLine, startColumn + 1); if (this.body.context.document.debugOn) { il.Emit(OpCodes.Nop); } int length = this.fields.Length; for (int i = 0; i < length; i++) { if (!this.fields[i].IsLiteral || (this.fields[i].value is FunctionObject)) { Type fieldType = this.fields[i].FieldType; LocalBuilder builder = il.DeclareLocal(fieldType); if (this.fields[i].debugOn) { builder.SetLocalSymInfo(this.fields[i].debuggerName); } this.fields[i].metaData = builder; } } this.globals.ScopeStack.Push(this.own_scope); try { if (this.must_save_stack_locals) { this.TranslateToMethodWithStackFrame(il, compilerGlobals, true); } else { this.body.TranslateToILInitializer(il); this.body.TranslateToIL(il, Typeob.Void); il.MarkLabel(this.returnLabel); } } finally { this.globals.ScopeStack.Pop(); } }
internal TypeBuilder TranslateToILClass(CompilerGlobals compilerGlobals) { return this.TranslateToILClass(compilerGlobals, true); }
internal ConstructorInfo GetConstructorInfo(CompilerGlobals compilerGlobals){ return this.cons.GetConstructorInfo(compilerGlobals); }
internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals){ return this.func.GetMethodInfo(compilerGlobals); }
protected override void ResetCompiledState() { if (this.globalScope != null) { this.globalScope.Reset(); this.globalScope = null; } this.classCounter = 0; base.haveCompiledState = false; base.failedCompilation = true; base.compiledRootNamespace = null; base.startupClass = null; this.compilerGlobals = null; this.globals = null; foreach (object obj2 in base.vsaItems) { ((VsaItem) obj2).Reset(); } this.implicitAssemblies = null; this.implicitAssemblyCache = null; this.cachedTypeLookups = null; base.isEngineCompiled = false; base.isEngineRunning = false; this.isCompilerSet = false; this.packages = null; if (!this.doSaveAfterCompile) { this.PEFileName = null; } this.rawPE = null; this.rawPDB = null; }
private void TranslateToMethodWithStackFrame(ILGenerator il, CompilerGlobals compilerGlobals, bool staticInitializer) { if (this.isStatic) { il.Emit(OpCodes.Ldtoken, ((ClassScope) this.own_scope.GetParent()).GetTypeBuilder()); } else { il.Emit(OpCodes.Ldarg_0); } int length = this.fields.Length; ConstantWrapper.TranslateToILInt(il, length); il.Emit(OpCodes.Newarr, Typeob.JSLocalField); for (int i = 0; i < length; i++) { JSLocalField field = this.fields[i]; il.Emit(OpCodes.Dup); ConstantWrapper.TranslateToILInt(il, i); il.Emit(OpCodes.Ldstr, field.Name); il.Emit(OpCodes.Ldtoken, field.FieldType); ConstantWrapper.TranslateToILInt(il, field.slotNumber); il.Emit(OpCodes.Newobj, CompilerGlobals.jsLocalFieldConstructor); il.Emit(OpCodes.Stelem_Ref); } this.TranslateToILToLoadEngine(il, true); if (this.isStatic) { il.Emit(OpCodes.Call, CompilerGlobals.pushStackFrameForStaticMethod); } else { il.Emit(OpCodes.Call, CompilerGlobals.pushStackFrameForMethod); } bool insideProtectedRegion = compilerGlobals.InsideProtectedRegion; compilerGlobals.InsideProtectedRegion = true; il.BeginExceptionBlock(); this.body.TranslateToILInitializer(il); this.body.TranslateToIL(il, Typeob.Void); il.MarkLabel(this.returnLabel); this.TranslateToILToSaveLocals(il); Label label = il.DefineLabel(); il.Emit(OpCodes.Leave, label); il.BeginFinallyBlock(); this.TranslateToILToLoadEngine(il); il.Emit(OpCodes.Call, CompilerGlobals.popScriptObjectMethod); il.Emit(OpCodes.Pop); il.EndExceptionBlock(); il.MarkLabel(label); if (!staticInitializer) { if (this.body.context.document.debugOn) { this.EmitLastLineInfo(il); il.Emit(OpCodes.Nop); } if (this.own_scope.returnVar != null) { il.Emit(OpCodes.Ldloc, (LocalBuilder) this.own_scope.returnVar.GetMetaData()); } il.Emit(OpCodes.Ret); } compilerGlobals.InsideProtectedRegion = insideProtectedRegion; }
internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals) { return(this.func.GetMethodInfo(compilerGlobals)); }
protected override void DoClose(){ ((VsaItems)this.vsaItems).Close(); if (null != this.globalScope) this.globalScope.Close(); this.vsaItems = null; this.engineSite = null; this.globalScope = null; this.runningThread = null; this.compilerGlobals = null; this.globals = null; ScriptStream.Out = Console.Out; ScriptStream.Error = Console.Error; this.DeleteCachedCompiledState(); this.isClosed = true; // The following calls ensure that all pointers to unmanaged objects get properly released // and avoid memory leaks on shutdown. GC.Collect() should be enough by itself when COM+ // takes care of the second automatically. GC.Collect(); }
internal ConstructorInfo GetConstructorInfo(CompilerGlobals compilerGlobals) { return (ConstructorInfo) this.GetMethodBase(compilerGlobals); }
protected override void ResetCompiledState(){ if (this.globalScope != null){ this.globalScope.Reset(); this.globalScope = null; } this.classCounter = 0; this.haveCompiledState = false; this.failedCompilation = true; this.compiledRootNamespace = null; this.startupClass = null; this.compilerGlobals = null; this.globals = null; foreach (Object item in this.vsaItems) ((VsaItem)item).Reset(); this.implicitAssemblies = null; this.implicitAssemblyCache = null; this.cachedTypeLookups = null; this.isEngineCompiled = false; this.isEngineRunning = false; this.isCompilerSet = false; this.packages = null; this.DeleteCachedCompiledState(); }
internal MethodBase GetMethodBase(CompilerGlobals compilerGlobals) { if (this.mb != null) { return this.mb; } if (this.cb == null) { JSFunctionAttributeEnum none = JSFunctionAttributeEnum.None; int num = 3; if (this.isMethod) { if (this.isConstructor && (((ClassScope) this.enclosing_scope).outerClassField != null)) { num = 1; none |= JSFunctionAttributeEnum.IsInstanceNestedClassConstructor; } else { num = 0; } } else if (!this.hasArgumentsObject) { num = 2; } int iSequence = this.formal_parameters.Length + num; Type[] parameterTypes = new Type[iSequence]; Type returnType = Microsoft.JScript.Convert.ToType(this.ReturnType(null)); if (num > 0) { if (this.isConstructor) { parameterTypes[iSequence - 1] = ((ClassScope) this.enclosing_scope).outerClassField.FieldType; } else { parameterTypes[0] = Typeob.Object; } none |= JSFunctionAttributeEnum.HasThisObject; } if (num > 1) { parameterTypes[1] = Typeob.VsaEngine; none |= JSFunctionAttributeEnum.HasEngine; } if (num > 2) { parameterTypes[2] = Typeob.Object; none |= JSFunctionAttributeEnum.HasArguments; } if (this.must_save_stack_locals) { none |= JSFunctionAttributeEnum.HasStackFrame; } if (this.isExpandoMethod) { none |= JSFunctionAttributeEnum.IsExpandoMethod; } if (this.isConstructor) { for (int j = 0; j < (iSequence - num); j++) { parameterTypes[j] = this.parameter_declarations[j].ParameterType; } } else { for (int k = num; k < iSequence; k++) { parameterTypes[k] = this.parameter_declarations[k - num].ParameterType; } } if (this.enclosing_scope is ClassScope) { if (this.isConstructor) { this.cb = ((ClassScope) this.enclosing_scope).GetTypeBuilder().DefineConstructor(this.attributes & MethodAttributes.MemberAccessMask, CallingConventions.Standard, parameterTypes); } else { string name = base.name; if (this.implementedIfaceMethod != null) { JSMethod implementedIfaceMethod = this.implementedIfaceMethod as JSMethod; if (implementedIfaceMethod != null) { this.implementedIfaceMethod = implementedIfaceMethod.GetMethodInfo(compilerGlobals); } name = this.implementedIfaceMethod.DeclaringType.FullName + "." + name; } TypeBuilder typeBuilder = ((ClassScope) this.enclosing_scope).GetTypeBuilder(); if (this.mb != null) { return this.mb; } this.mb = typeBuilder.DefineMethod(name, this.attributes, returnType, parameterTypes); if (this.implementedIfaceMethod != null) { ((ClassScope) this.enclosing_scope).GetTypeBuilder().DefineMethodOverride(this.mb, this.implementedIfaceMethod); } } } else { if (this.enclosing_scope is FunctionScope) { if (((FunctionScope) this.enclosing_scope).owner != null) { base.name = ((FunctionScope) this.enclosing_scope).owner.name + "." + base.name; none |= JSFunctionAttributeEnum.IsNested; } else { for (ScriptObject obj2 = this.enclosing_scope; obj2 != null; obj2 = obj2.GetParent()) { if ((obj2 is FunctionScope) && (((FunctionScope) obj2).owner != null)) { base.name = ((FunctionScope) obj2).owner.name + "." + base.name; none |= JSFunctionAttributeEnum.IsNested; break; } } } } if (compilerGlobals.usedNames[base.name] != null) { base.name = base.name + ":" + compilerGlobals.usedNames.count.ToString(CultureInfo.InvariantCulture); } compilerGlobals.usedNames[base.name] = this; ScriptObject parent = this.enclosing_scope; while ((parent != null) && !(parent is ClassScope)) { parent = parent.GetParent(); } this.classwriter = (parent == null) ? compilerGlobals.globalScopeClassWriter : compilerGlobals.classwriter; this.mb = this.classwriter.DefineMethod(base.name, this.attributes, returnType, parameterTypes); } if (num > 0) { if (this.mb != null) { this.mb.DefineParameter(1, ParameterAttributes.None, "this"); } else { this.cb.DefineParameter(iSequence, ParameterAttributes.None, "this").SetConstant(null); num = 0; iSequence--; } } if (num > 1) { this.mb.DefineParameter(2, ParameterAttributes.None, "vsa Engine"); } if (num > 2) { this.mb.DefineParameter(3, ParameterAttributes.None, "arguments"); } for (int i = num; i < iSequence; i++) { ParameterBuilder builder3 = (this.mb != null) ? this.mb.DefineParameter(i + 1, ParameterAttributes.None, this.parameter_declarations[i - num].identifier) : this.cb.DefineParameter(i + 1, ParameterAttributes.None, this.parameter_declarations[i - num].identifier); CustomAttributeList customAttributes = this.parameter_declarations[i - num].customAttributes; if (customAttributes != null) { CustomAttributeBuilder[] customAttributeBuilders = customAttributes.GetCustomAttributeBuilders(false); for (int m = 0; m < customAttributeBuilders.Length; m++) { builder3.SetCustomAttribute(customAttributeBuilders[m]); } } } if (none > JSFunctionAttributeEnum.None) { CustomAttributeBuilder customBuilder = new CustomAttributeBuilder(CompilerGlobals.jsFunctionAttributeConstructor, new object[] { none }); if (this.mb != null) { this.mb.SetCustomAttribute(customBuilder); } else { this.cb.SetCustomAttribute(customBuilder); } } if (this.customAttributes != null) { CustomAttributeBuilder[] builderArray2 = this.customAttributes.GetCustomAttributeBuilders(false); for (int n = 0; n < builderArray2.Length; n++) { if (this.mb != null) { this.mb.SetCustomAttribute(builderArray2[n]); } else { this.cb.SetCustomAttribute(builderArray2[n]); } } } if (this.clsCompliance == CLSComplianceSpec.CLSCompliant) { if (this.mb != null) { this.mb.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.clsCompliantAttributeCtor, new object[] { true })); } else { this.cb.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.clsCompliantAttributeCtor, new object[] { true })); } } else if (this.clsCompliance == CLSComplianceSpec.NonCLSCompliant) { if (this.mb != null) { this.mb.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.clsCompliantAttributeCtor, new object[] { false })); } else { this.cb.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.clsCompliantAttributeCtor, new object[] { false })); } } if (this.mb != null) { this.mb.InitLocals = true; return this.mb; } this.cb.InitLocals = true; } return this.cb; }
internal MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals) { return (MethodInfo) this.GetMethodBase(compilerGlobals); }
internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals) { return(null); }