本文整理汇总了C#中Pchp.CodeAnalysis.CodeGen.CodeGenerator.GenerateScope方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.GenerateScope方法的具体用法?C# CodeGenerator.GenerateScope怎么用?C# CodeGenerator.GenerateScope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.CodeAnalysis.CodeGen.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.GenerateScope方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
internal override void Generate(CodeGenerator cg)
{
Contract.ThrowIfNull(Condition);
if (IsLoop) // perf
{
cg.Builder.EmitBranch(ILOpCode.Br, this.Condition);
// {
cg.GenerateScope(TrueTarget, NextBlock.Ordinal);
// }
// if (Condition)
cg.EmitSequencePoint(this.Condition.PhpSyntax);
cg.Builder.MarkLabel(this.Condition);
cg.EmitConvert(this.Condition, cg.CoreTypes.Boolean);
cg.Builder.EmitBranch(ILOpCode.Brtrue, TrueTarget);
}
else
{
// if (Condition)
cg.EmitSequencePoint(this.Condition.PhpSyntax);
cg.EmitConvert(this.Condition, cg.CoreTypes.Boolean);
cg.Builder.EmitBranch(ILOpCode.Brfalse, FalseTarget);
// {
cg.GenerateScope(TrueTarget, NextBlock.Ordinal);
// }
}
cg.Scope.ContinueWith(FalseTarget);
}
示例2: EmitTryStatement
void EmitTryStatement(CodeGenerator cg, bool emitCatchesOnly = false)
{
// Stack must be empty at beginning of try block.
cg.Builder.AssertStackEmpty();
// IL requires catches and finally block to be distinct try
// blocks so if the source contained both a catch and
// a finally, nested scopes are emitted.
bool emitNestedScopes = (!emitCatchesOnly &&
//(_catchBlocks.Length != 0) &&
(_finallyBlock != null));
cg.Builder.OpenLocalScope(ScopeType.TryCatchFinally);
cg.Builder.OpenLocalScope(ScopeType.Try);
// IL requires catches and finally block to be distinct try
// blocks so if the source contained both a catch and
// a finally, nested scopes are emitted.
//_tryNestingLevel++;
if (emitNestedScopes)
{
EmitTryStatement(cg, emitCatchesOnly: true);
}
else
{
cg.GenerateScope(_body, (_finallyBlock ?? NextBlock).Ordinal);
}
//_tryNestingLevel--;
// Close the Try scope
cg.Builder.CloseLocalScope();
if (!emitNestedScopes)
{
EmitScriptDiedBlock(cg);
//
foreach (var catchBlock in _catchBlocks)
{
EmitCatchBlock(cg, catchBlock);
}
}
if (!emitCatchesOnly && _finallyBlock != null)
{
cg.Builder.OpenLocalScope(ScopeType.Finally);
cg.GenerateScope(_finallyBlock, NextBlock.Ordinal);
// close Finally scope
cg.Builder.CloseLocalScope();
}
// close the whole try statement scope
cg.Builder.CloseLocalScope();
if (!emitCatchesOnly)
{
//
cg.Scope.ContinueWith(NextBlock);
}
}
示例3: EmitBody
void EmitBody(CodeGenerator cg)
{
Debug.Assert(NextBlock.NextEdge is ForeachMoveNextEdge);
cg.GenerateScope(NextBlock, NextBlock.NextEdge.NextBlock.Ordinal);
}
示例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();
}