本文整理汇总了C#中Pchp.CodeAnalysis.CodeGen.CodeGenerator.EmitCallerRuntimeTypeHandle方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.EmitCallerRuntimeTypeHandle方法的具体用法?C# CodeGenerator.EmitCallerRuntimeTypeHandle怎么用?C# CodeGenerator.EmitCallerRuntimeTypeHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.CodeAnalysis.CodeGen.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.EmitCallerRuntimeTypeHandle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
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);
}
}