本文整理汇总了C#中Pchp.CodeAnalysis.CodeGen.CodeGenerator.GetTemporaryLocal方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.GetTemporaryLocal方法的具体用法?C# CodeGenerator.GetTemporaryLocal怎么用?C# CodeGenerator.GetTemporaryLocal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.CodeAnalysis.CodeGen.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.GetTemporaryLocal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
internal override TypeSymbol Emit(CodeGenerator cg)
{
var result_type = cg.DeclaringCompilation.GetTypeFromTypeRef(cg.Routine, this.TypeRefMask);
if (this.IfTrue != null)
{
object trueLbl = new object();
object endLbl = new object();
// Cond ? True : False
cg.EmitConvert(this.Condition, cg.CoreTypes.Boolean); // i4
cg.Builder.EmitBranch(ILOpCode.Brtrue, trueLbl);
// false:
cg.EmitConvert(this.IfFalse, result_type);
cg.Builder.EmitBranch(ILOpCode.Br, endLbl);
cg.Builder.AdjustStack(-1); // workarounds assert in ILBuilder.MarkLabel, we're doing something wrong with ILBuilder
// trueLbl:
cg.Builder.MarkLabel(trueLbl);
cg.EmitConvert(this.IfTrue, result_type);
// endLbl:
cg.Builder.MarkLabel(endLbl);
}
else
{
object trueLbl = new object();
object endLbl = new object();
// Cond ?: False
// <stack> = <cond_var> = Cond
var cond_type = cg.Emit(this.Condition);
var cond_var = cg.GetTemporaryLocal(cond_type);
cg.Builder.EmitOpCode(ILOpCode.Dup);
cg.Builder.EmitLocalStore(cond_var);
cg.EmitConvertToBool(cond_type, this.Condition.TypeRefMask);
cg.Builder.EmitBranch(ILOpCode.Brtrue, trueLbl);
// false:
cg.EmitConvert(this.IfFalse, result_type);
cg.Builder.EmitBranch(ILOpCode.Br, endLbl);
cg.Builder.AdjustStack(-1); // workarounds assert in ILBuilder.MarkLabel, we're doing something wrong with ILBuilder
// trueLbl:
cg.Builder.MarkLabel(trueLbl);
cg.Builder.EmitLocalLoad(cond_var);
cg.EmitConvert(cond_type, this.Condition.TypeRefMask, result_type);
// endLbl:
cg.Builder.MarkLabel(endLbl);
//
cg.ReturnTemporaryLocal(cond_var);
}
//
if (Access.IsNone)
{
cg.EmitPop(result_type);
result_type = cg.CoreTypes.Void;
}
//
return result_type;
}
示例2:
void IBoundReference.EmitStore(CodeGenerator cg, TypeSymbol valueType)
{
var rtype = cg.CoreTypes.IPhpArray;
cg.EmitConvert(valueType, 0, rtype);
var tmp = cg.GetTemporaryLocal(rtype);
cg.Builder.EmitLocalStore(tmp);
// NOTE: since PHP7, variables are assigned from left to right
var vars = this.Variables;
for (int i = 0; i < vars.Length; i++)
{
var target = vars[i];
if (target == null)
continue;
var boundtarget = target.BindPlace(cg);
boundtarget.EmitStorePrepare(cg);
// LOAD IPhpArray.GetItemValue(IntStringKey{i})
cg.Builder.EmitLocalLoad(tmp);
cg.EmitIntStringKey(i);
var itemtype = cg.EmitCall(ILOpCode.Callvirt, cg.CoreMethods.IPhpArray.GetItemValue_IntStringKey);
// STORE vars[i]
boundtarget.EmitStore(cg, itemtype);
}
//
cg.ReturnTemporaryLocal(tmp);
}
示例3: 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);
}
}
示例4: EmitCatchBlock
void EmitCatchBlock(CodeGenerator cg, CatchBlock catchBlock)
{
Debug.Assert(catchBlock.Variable.Variable != null);
if (catchBlock.TypeRef.ResolvedType == null)
{
throw new NotImplementedException("handle exception type dynamically"); // TODO: if (ex is ctx.ResolveType(ExceptionTypeName)) { ... }
}
var extype = catchBlock.TypeRef.ResolvedType;
cg.Builder.AdjustStack(1); // Account for exception on the stack.
cg.Builder.OpenLocalScope(ScopeType.Catch, (Microsoft.Cci.ITypeReference)extype);
// <tmp> = <ex>
var tmploc = cg.GetTemporaryLocal(extype);
cg.Builder.EmitLocalStore(tmploc);
var varplace = catchBlock.Variable.BindPlace(cg);
Debug.Assert(varplace != null);
// $x = <tmp>
varplace.EmitStorePrepare(cg);
cg.Builder.EmitLocalLoad(tmploc);
varplace.EmitStore(cg, (TypeSymbol)tmploc.Type);
//
cg.ReturnTemporaryLocal(tmploc);
tmploc = null;
//
cg.GenerateScope(catchBlock, NextBlock.Ordinal);
//
cg.Builder.CloseLocalScope();
}
示例5: EmitName
/// <summary>
/// Emits name as string, uses cached variable.
/// </summary>
void EmitName(CodeGenerator cg, BoundExpression name)
{
Contract.ThrowIfNull(cg);
Contract.ThrowIfNull(name);
if (_name_loc != null)
{
cg.Builder.EmitLocalLoad(_name_loc);
}
else
{
_cg = cg;
// return (<loc> = <name>)
_name_loc = cg.GetTemporaryLocal(cg.CoreTypes.String);
cg.EmitConvert(name, cg.CoreTypes.String);
cg.Builder.EmitOpCode(ILOpCode.Dup);
cg.Builder.EmitLocalStore(_name_loc);
}
}
示例6: EmitInstance
/// <summary>
/// Emits <see name="_instance"/>, uses cached value if initialized already.
/// </summary>
TypeSymbol EmitInstance(CodeGenerator cg, Func<TypeSymbol> emitter)
{
Debug.Assert(cg != null);
if (_instance_loc != null)
{
cg.Builder.EmitLocalLoad(_instance_loc);
}
else
{
_cg = cg;
// return (<loc> = <instance>);
_instance_loc = cg.GetTemporaryLocal(emitter());
cg.EmitOpCode(ILOpCode.Dup);
cg.Builder.EmitLocalStore(_instance_loc);
}
return (TypeSymbol)_instance_loc.Type;
}
示例7: EmitTmpRet
/// <summary>
/// Stores value from top of the evaluation stack to a temporary variable which will be returned from the exit block.
/// </summary>
internal void EmitTmpRet(CodeGenerator cg, Symbols.TypeSymbol stack)
{
// lazy initialize
if (_retlbl == null)
{
_retlbl = new object();
}
if (_rettmp == null)
{
var rtype = cg.Routine.ReturnType;
if (rtype.SpecialType != SpecialType.System_Void)
{
_rettmp = cg.GetTemporaryLocal(rtype);
}
}
// <rettmp> = <stack>;
if (_rettmp != null)
{
cg.EmitConvert(stack, 0, (Symbols.TypeSymbol)_rettmp.Type);
cg.Builder.EmitLocalStore(_rettmp);
cg.Builder.EmitBranch(ILOpCode.Br, _retlbl);
}
else
{
cg.EmitPop(stack);
}
}
示例8: CreateAndLoad
/// <summary>
/// Loads temporary local variable as an argument to <paramref name="targetp"/>.
/// </summary>
/// <param name="cg"></param>
/// <param name="targetp">Target parameter.</param>
/// <param name="expr">Value to be passed as its argument.</param>
/// <returns><see cref="WriteBackInfo"/> which has to be finalized with <see cref="WriteBackAndFree(CodeGenerator)"/> once the routine call ends.</returns>
public static WriteBackInfo CreateAndLoad(CodeGenerator cg, ParameterSymbol targetp, BoundReferenceExpression expr)
{
var writeback = new WriteBackInfo()
{
TmpLocal = cg.GetTemporaryLocal(targetp.Type),
Target = expr,
};
//
writeback.EmitLoadArgument(cg, targetp);
//
return writeback;
}