internal SubstitutedPropertySymbol(SubstitutedNamedTypeSymbol containingType, PropertySymbol originalDefinition) { _containingType = containingType; _originalDefinition = originalDefinition; }
internal override void Generate(CodeGenerator cg) { Debug.Assert(this.Enumeree != null); // get the enumerator, // bind actual MoveNext() and CurrentValue and CurrentKey // Template: using( // a) enumerator = enumeree.GetEnumerator() // b) enumerator = Operators.GetEnumerator(enumeree) // ) ... cg.EmitSequencePoint(this.Enumeree.PhpSyntax); var enumereeType = cg.Emit(this.Enumeree); Debug.Assert(enumereeType.SpecialType != SpecialType.System_Void); var getEnumeratorMethod = enumereeType.LookupMember<MethodSymbol>(WellKnownMemberNames.GetEnumeratorMethodName); TypeSymbol enumeratorType; if (enumereeType.IsOfType(cg.CoreTypes.PhpArray)) { cg.Builder.EmitBoolConstant(_aliasedValues); // PhpArray.GetForeachtEnumerator(bool) enumeratorType = cg.EmitCall(ILOpCode.Callvirt, cg.CoreMethods.PhpArray.GetForeachEnumerator_Boolean); // TODO: IPhpArray } // TODO: IPhpEnumerable // TODO: IPhpArray // TODO: Iterator else if (getEnumeratorMethod != null && getEnumeratorMethod.ParameterCount == 0 && enumereeType.IsReferenceType) { // enumeree.GetEnumerator() enumeratorType = cg.EmitCall(getEnumeratorMethod.IsVirtual ? ILOpCode.Callvirt : ILOpCode.Call, getEnumeratorMethod); } else { cg.EmitConvertToPhpValue(enumereeType, 0); cg.Builder.EmitBoolConstant(_aliasedValues); cg.EmitCallerRuntimeTypeHandle(); // Operators.GetForeachEnumerator(PhpValue, bool, RuntimeTypeHandle) enumeratorType = cg.EmitCall(ILOpCode.Call, cg.CoreMethods.Operators.GetForeachEnumerator_PhpValue_Bool_RuntimeTypeHandle); } // _current = enumeratorType.LookupMember<PropertySymbol>(WellKnownMemberNames.CurrentPropertyName); // TODO: Err if no Current _currentValue = enumeratorType.LookupMember<PropertySymbol>(_aliasedValues ? "CurrentValueAliased" : "CurrentValue"); _currentKey = enumeratorType.LookupMember<PropertySymbol>("CurrentKey"); _disposeMethod = enumeratorType.LookupMember<MethodSymbol>("Dispose", m => m.ParameterCount == 0 && !m.IsStatic); // _enumeratorLoc = cg.GetTemporaryLocal(enumeratorType); cg.Builder.EmitLocalStore(_enumeratorLoc); // bind methods _moveNextMethod = enumeratorType.LookupMember<MethodSymbol>(WellKnownMemberNames.MoveNextMethodName); // TODO: Err if there is no MoveNext() Debug.Assert(_moveNextMethod.ReturnType.SpecialType == SpecialType.System_Boolean); Debug.Assert(_moveNextMethod.IsStatic == false); if (_disposeMethod != null) { /* Template: try { body } finally { enumerator.Dispose } */ // try { cg.Builder.AssertStackEmpty(); cg.Builder.OpenLocalScope(ScopeType.TryCatchFinally); cg.Builder.OpenLocalScope(ScopeType.Try); // EmitBody(cg); // } cg.Builder.CloseLocalScope(); // /Try // finally { cg.Builder.OpenLocalScope(ScopeType.Finally); // enumerator.Dispose() & cleanup EmitDisposeAndClean(cg); // } cg.Builder.CloseLocalScope(); // /Finally cg.Builder.CloseLocalScope(); // /TryCatchFinally } else { EmitBody(cg); EmitDisposeAndClean(cg); } }
internal SubstitutedParameterSymbol(PropertySymbol containingSymbol, TypeMap map, ParameterSymbol originalParameter) : this((Symbol)containingSymbol, map, originalParameter) { }
void EmitDisposeAndClean(CodeGenerator cg) { // enumerator.Dispose() if (_disposeMethod != null) { // TODO: if (enumerator != null) if (_enumeratorLoc.Type.IsValueType) cg.Builder.EmitLocalAddress(_enumeratorLoc); else cg.Builder.EmitLocalLoad(_enumeratorLoc); cg.EmitCall(_disposeMethod.IsVirtual ? ILOpCode.Callvirt : ILOpCode.Call, _disposeMethod) .Expect(SpecialType.System_Void); } //// enumerator = null; //if (!_enumeratorLoc.Type.IsValueType) //{ // cg.Builder.EmitNullConstant(); // cg.Builder.EmitLocalStore(_enumeratorLoc); //} // cg.ReturnTemporaryLocal(_enumeratorLoc); _enumeratorLoc = null; // unbind _moveNextMethod = null; _disposeMethod = null; _currentValue = null; _currentKey = null; _current = null; }
public PropertyPlace(IPlace holder, Cci.IPropertyDefinition property) { Contract.ThrowIfNull(property); _holder = holder; _property = (PropertySymbol)property; }
public BoundPropertyPlace(BoundExpression instance, Cci.IPropertyDefinition property) { Contract.ThrowIfNull(property); _instance = instance; _property = (PropertySymbol)property; }
void GenerateFieldAccessorProperty(Emit.PEModuleBuilder module, DiagnosticBag diagnostics, SourceFieldSymbol srcf, PropertySymbol paccessor) { // module.SynthesizedManager.AddProperty(this, paccessor); // var get_body = MethodGenerator.GenerateMethodBody(module, paccessor.GetMethod, (il) => { // Template: return field; var place = new FieldPlace(new ArgPlace(this, 0), srcf.OverridenDefinition, module); place.EmitLoad(il); il.EmitRet(false); }, null, diagnostics, false); module.SetMethodBody(paccessor.GetMethod, get_body); module.SynthesizedManager.AddMethod(this, paccessor.GetMethod); // var set_body = MethodGenerator.GenerateMethodBody(module, paccessor.SetMethod, (il) => { // Template: field = value; var place = new FieldPlace(new ArgPlace(this, 0), srcf.OverridenDefinition, module); place.EmitStorePrepare(il); new ArgPlace(this, 1).EmitLoad(il); place.EmitStore(il); il.EmitRet(true); }, null, diagnostics, false); module.SetMethodBody(paccessor.SetMethod, set_body); module.SynthesizedManager.AddMethod(this, paccessor.SetMethod); }
internal TypeSymbol EmitGetProperty(IPlace holder, PropertySymbol prop) { Debug.Assert(prop.IsStatic || holder != null); Debug.Assert(prop.GetMethod != null); Debug.Assert(prop.GetMethod.ParameterCount == 0); var getter = prop.GetMethod; if (holder != null && !getter.IsStatic) { Debug.Assert(holder.TypeOpt != null); if (holder.TypeOpt.IsValueType) { holder.EmitLoadAddress(_il); } else { holder.EmitLoad(_il); } } return EmitCall(getter.IsVirtual ? ILOpCode.Callvirt : ILOpCode.Call, getter); }