本文整理汇总了C#中Pchp.CodeAnalysis.CodeGen.CodeGenerator.ReturnTemporaryLocal方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.ReturnTemporaryLocal方法的具体用法?C# CodeGenerator.ReturnTemporaryLocal怎么用?C# CodeGenerator.ReturnTemporaryLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.CodeAnalysis.CodeGen.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.ReturnTemporaryLocal方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
internal override TypeSymbol Emit(CodeGenerator cg)
{
Debug.Assert(this.Access.IsNone || Access.IsRead);
Debug.Assert(!this.Access.IsReadRef);
Debug.Assert(!this.Access.IsWrite);
Debug.Assert(this.Target.Access.IsRead && this.Target.Access.IsWrite);
Debug.Assert(this.Value.Access.IsRead);
Debug.Assert(this.Value is BoundLiteral);
if (this.UsesOperatorMethod)
{
throw new NotImplementedException();
}
TypeSymbol result_type = cg.CoreTypes.Void;
LocalDefinition postfix_temp = null;
var read = this.Access.IsRead;
var target_place = this.Target.BindPlace(cg);
Debug.Assert(target_place != null);
using (var instance_holder = new InstanceCacheHolder())
{
// prepare target for store operation
target_place.EmitStorePrepare(cg, instance_holder);
// load target value
target_place.EmitLoadPrepare(cg, instance_holder);
}
var target_load_type = target_place.EmitLoad(cg);
TypeSymbol op_type;
if (read && IsPostfix)
{
// store original value of target
// <temp> = TARGET
postfix_temp = cg.GetTemporaryLocal(target_load_type);
cg.EmitOpCode(ILOpCode.Dup);
cg.Builder.EmitLocalStore(postfix_temp);
}
if (IsIncrement)
{
op_type = BoundBinaryEx.EmitAdd(cg, target_load_type, this.Value, target_place.TypeOpt);
}
else
{
Debug.Assert(IsDecrement);
op_type = BoundBinaryEx.EmitSub(cg, target_load_type, this.Value, target_place.TypeOpt);
}
if (read)
{
if (IsPostfix)
{
// READ <temp>
cg.Builder.EmitLocalLoad(postfix_temp);
result_type = target_load_type;
//
cg.ReturnTemporaryLocal(postfix_temp);
postfix_temp = null;
}
else
{
// dup resulting value
// READ (++TARGET OR --TARGET)
cg.Builder.EmitOpCode(ILOpCode.Dup);
result_type = op_type;
}
}
//
target_place.EmitStore(cg, op_type);
Debug.Assert(postfix_temp == null);
Debug.Assert(!read || result_type.SpecialType != SpecialType.System_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)
{
// four cases:
// 1. just single or none case label that can be replaced with single IF
// 2. switch over integers, using native CIL switch
// 3. switch over strings, using C# static Dictionary and CIL switch
// 4. PHP style switch which is just a bunch of IFs
if (this.CaseBlocks.Length == 0 || this.CaseBlocks[0].IsDefault)
{
Debug.Assert(this.CaseBlocks.Length <= 1);
// no SWITCH or IF needed
cg.EmitPop(this.SwitchValue.WithAccess(BoundAccess.None).Emit(cg)); // None Access, also using BoundExpression.Emit directly to avoid CodeGenerator type specialization which is not needed
if (this.CaseBlocks.Length == 1)
{
cg.GenerateScope(this.CaseBlocks[0], NextBlock.Ordinal);
}
}
else
{
// CIL Switch:
bool allconsts = this.CaseBlocks.All(c => c.IsDefault || c.CaseValue.ConstantValue.HasValue);
bool allconstints = allconsts && this.CaseBlocks.All(c => c.IsDefault || IsInt32(c.CaseValue.ConstantValue.Value));
//bool allconststrings = allconsts && this.CaseBlocks.All(c => c.IsDefault || IsString(c.CaseValue.ConstantValue.Value));
var default_block = this.DefaultBlock;
// <switch_loc> = <SwitchValue>;
TypeSymbol switch_type;
LocalDefinition switch_loc;
// Switch Header
if (allconstints)
{
switch_type = cg.CoreTypes.Int32;
cg.EmitSequencePoint(this.SwitchValue.PhpSyntax);
cg.EmitConvert(this.SwitchValue, switch_type);
switch_loc = cg.GetTemporaryLocal(switch_type);
cg.Builder.EmitLocalStore(switch_loc);
// switch (labels)
cg.Builder.EmitIntegerSwitchJumpTable(GetSwitchCaseLabels(CaseBlocks), default_block ?? NextBlock, switch_loc, switch_type.PrimitiveTypeCode);
}
//else if (allconststrings)
//{
//}
else
{
// legacy jump table
// IF (case_i) GOTO label_i;
cg.EmitSequencePoint(this.SwitchValue.PhpSyntax);
switch_type = cg.Emit(this.SwitchValue);
switch_loc = cg.GetTemporaryLocal(switch_type);
cg.Builder.EmitLocalStore(switch_loc);
//
for (int i = 0; i < this.CaseBlocks.Length; i++)
{
var this_block = this.CaseBlocks[i];
if (this_block.CaseValue != null)
{
// <CaseValue>:
cg.EmitSequencePoint(this_block.CaseValue.PhpSyntax);
// if (<switch_loc> == c.CaseValue) goto this_block;
cg.Builder.EmitLocalLoad(switch_loc);
BoundBinaryEx.EmitEquality(cg, switch_type, this_block.CaseValue);
cg.Builder.EmitBranch(ILOpCode.Brtrue, this_block);
}
}
// default:
cg.Builder.EmitBranch(ILOpCode.Br, default_block ?? NextBlock);
}
// FREE <switch_loc>
cg.ReturnTemporaryLocal(switch_loc);
// Switch Body
this.CaseBlocks.ForEach((i, this_block) =>
{
var next_case = (i + 1 < this.CaseBlocks.Length) ? this.CaseBlocks[i + 1] : null;
// {
cg.GenerateScope(this_block, (next_case ?? NextBlock).Ordinal);
// }
});
}
//
cg.Scope.ContinueWith(NextBlock);
}
示例4: EmitDisposeAndClean
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;
}
示例5: 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();
}
示例6: WriteBackAndFree
/// <summary>
/// Writes the value back to <see cref="Target"/> and free resources.
/// </summary>
public void WriteBackAndFree(CodeGenerator cg)
{
// Template: <Target> = <TmpLocal>;
var place = Target.BindPlace(cg);
place.EmitStorePrepare(cg, null);
cg.Builder.EmitLocalLoad(TmpLocal);
place.EmitStore(cg, (TypeSymbol)TmpLocal.Type);
// free <TmpLocal>
cg.ReturnTemporaryLocal(TmpLocal);
TmpLocal = null;
}