public EmitDebugAssertNotNull ( IPlace place, string messageOpt = null ) : void | ||
place | IPlace | The variable to emit assertion for. |
messageOpt | string | Optional second argument for assert. |
return | void |
void EmitPhpNew(SynthesizedPhpNewMethodSymbol phpnew, Emit.PEModuleBuilder module) { if (phpnew == null) return; // static class module.SetMethodBody(phpnew, MethodGenerator.GenerateMethodBody(module, phpnew, (Action<Microsoft.CodeAnalysis.CodeGen.ILBuilder>)(il => { Debug.Assert(SpecialParameterSymbol.IsContextParameter(phpnew.Parameters[0])); var cg = new CodeGenerator(il, module, DiagnosticBag.GetInstance(), OptimizationLevel.Release, false, this, new ParamPlace(phpnew.Parameters[0]), new ArgPlace(this, 0)); // initialize <ctx> field, // if field is declared within this type var ctxField = this.ContextStore; if (ctxField != null && object.ReferenceEquals((object)ctxField.ContainingType, this)) { var ctxFieldPlace = new FieldPlace(cg.ThisPlaceOpt, (IFieldSymbol)ctxField); // Debug.Assert(<ctx> != null) cg.EmitDebugAssertNotNull(cg.ContextPlaceOpt, "Context cannot be null."); // <this>.<ctx> = <ctx> ctxFieldPlace.EmitStorePrepare(il); cg.EmitLoadContext(); ctxFieldPlace.EmitStore(il); } // initialize class fields foreach (var fld in this.GetFieldsToEmit().OfType<SourceFieldSymbol>().Where(fld => !fld.RequiresHolder && !fld.IsStatic && !fld.IsConst)) { fld.EmitInit(cg); } // base..phpnew ?? base..ctor var basenew = phpnew.BasePhpNew; Debug.Assert(basenew != null); cg.EmitPop(cg.EmitThisCall(basenew, phpnew)); Debug.Assert(phpnew.ReturnsVoid); cg.EmitRet(phpnew.ReturnType); }), null, DiagnosticBag.GetInstance(), false)); }
internal override void Emit(CodeGenerator cg) { // first brace sequence point var body = cg.Routine.Syntax.BodySpanOrInvalid(); if (body.IsValid && cg.IsDebug) { cg.EmitSequencePoint(new Span(body.Start, 1)); cg.EmitOpCode(ILOpCode.Nop); } else { cg.Builder.DefineInitialHiddenSequencePoint(); } // if (cg.IsDebug) { if (cg.Routine.IsStatic) { // Debug.Assert(<context> != null); cg.EmitDebugAssertNotNull(cg.ContextPlaceOpt, "Context cannot be null."); } // TODO: emit parameters checks } // var locals = cg.Routine.LocalsTable; // in case of script, declare the script, functions and types if (cg.Routine is Symbols.SourceGlobalMethodSymbol) { // <ctx>.OnInclude<TScript>() cg.EmitLoadContext(); cg.EmitCall(ILOpCode.Callvirt, cg.CoreMethods.Context.OnInclude_TScript.Symbol.Construct(cg.Routine.ContainingType)); // <ctx>.DeclareFunction() cg.Routine.ContainingFile.Functions .Where(f => !f.IsConditional) .ForEach(cg.EmitDeclareFunction); // <ctx>.DeclareType() cg.DeclaringCompilation.SourceSymbolTables.GetTypes() .OfType<Symbols.SourceTypeSymbol>() .Where(t => !t.Syntax.IsConditional && t.ContainingFile == cg.Routine.ContainingFile) // non conditional declaration within this file .ForEach(cg.EmitDeclareType); } else { if (cg.HasUnoptimizedLocals) { // <locals> = new PhpArray(HINTCOUNT) cg.LocalsPlaceOpt.EmitStorePrepare(cg.Builder); cg.Builder.EmitIntConstant(locals.Count); // HINTCOUNT cg.EmitCall(ILOpCode.Newobj, cg.CoreMethods.Ctors.PhpArray_int); cg.LocalsPlaceOpt.EmitStore(cg.Builder); } } // variables/parameters initialization foreach (var loc in locals.Variables) { loc.EmitInit(cg); } // base.Emit(cg); }