internal ExceptionManager(BodyCodegen _enclosing) { this._enclosing = _enclosing; this.exceptionInfo = new List<BodyCodegen.ExceptionManager.ExceptionInfo>(); }
/// <summary> /// Mark off the end of a bytecode chunk that should be handled by an /// exceptionHandler. /// </summary> /// <remarks> /// Mark off the end of a bytecode chunk that should be handled by an /// exceptionHandler. /// The caller of this method must appropriately mark the start of the /// next bytecode chunk or remove the handler. /// </remarks> private void EndCatch(BodyCodegen.ExceptionManager.ExceptionInfo ei, int exceptionType, int catchEnd) { if (ei.exceptionStarts[exceptionType] == 0) { throw new InvalidOperationException("bad exception start"); } int currentStart = ei.exceptionStarts[exceptionType]; int currentStartPC = this._enclosing.cfw.GetLabelPC(currentStart); int catchEndPC = this._enclosing.cfw.GetLabelPC(catchEnd); if (currentStartPC != catchEndPC) { this._enclosing.cfw.AddExceptionHandler(ei.exceptionStarts[exceptionType], catchEnd, ei.handlerLabels[exceptionType], this._enclosing.ExceptionTypeToName(exceptionType)); } }
private byte[] GenerateCode(string encodedSource) { bool hasScript = (scriptOrFnNodes[0].GetType() == Token.SCRIPT); bool hasFunctions = (scriptOrFnNodes.Length > 1 || !hasScript); string sourceFile = null; if (compilerEnv.IsGenerateDebugInfo()) { sourceFile = scriptOrFnNodes[0].GetSourceName(); } ClassFileWriter cfw = new ClassFileWriter(mainClassName, SUPER_CLASS_NAME, sourceFile); cfw.AddField(ID_FIELD_NAME, "I", ClassFileWriter.ACC_PRIVATE); if (hasFunctions) { GenerateFunctionConstructor(cfw); } if (hasScript) { cfw.AddInterface("org/mozilla/javascript/Script"); GenerateScriptCtor(cfw); GenerateMain(cfw); GenerateExecute(cfw); } GenerateCallMethod(cfw); GenerateResumeGenerator(cfw); GenerateNativeFunctionOverrides(cfw, encodedSource); int count = scriptOrFnNodes.Length; for (int i = 0; i != count; ++i) { ScriptNode n = scriptOrFnNodes[i]; BodyCodegen bodygen = new BodyCodegen(); bodygen.cfw = cfw; bodygen.codegen = this; bodygen.compilerEnv = compilerEnv; bodygen.scriptOrFn = n; bodygen.scriptOrFnIndex = i; try { bodygen.GenerateBodyCode(); } catch (ClassFileWriter.ClassFileFormatException e) { throw ReportClassFileFormatException(n, e.Message); } if (n.GetType() == Token.FUNCTION) { OptFunctionNode ofn = OptFunctionNode.Get(n); GenerateFunctionInit(cfw, ofn); if (ofn.IsTargetOfDirectCall()) { EmitDirectConstructor(cfw, ofn); } } } EmitRegExpInit(cfw); EmitConstantDudeInitializers(cfw); return cfw.ToByteArray(); }