本文整理汇总了C#中Expression.Generate方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Generate方法的具体用法?C# Expression.Generate怎么用?C# Expression.Generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression.Generate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnGenerate
protected override void OnGenerate()
{
var cond = T.Children[0];
var message = T.Children[1];
var end = Ctx.Sink.DefineLabel();
var messageLabel = Ctx.Sink.DefineLabel();
var condExp = new Expression(cond);
Errors.AddRange(condExp.Generate(Ctx));
Ctx.EmitUnwrapBool();
Ctx.Sink.Emit(OpCodes.Brtrue, messageLabel);
Ctx.EmitEmptyString();
Ctx.Sink.Emit(OpCodes.Br, end);
Ctx.Sink.MarkLabel(messageLabel);
var messageExp = new Expression(message);
Errors.AddRange(messageExp.Generate(Ctx));
Ctx.Sink.MarkLabel(end);
}
示例2: EmitFlatArgList
public ErrorList EmitFlatArgList(CommonTree fnArgs)
{
var errors = new ErrorList();
var args = fnArgs.Children;
for (var i = 0; i < args.Count; i++)
{
var exp = new Expression(args[i]);
errors.AddRange(exp.Generate(this));
}
return errors;
}
示例3: EmitArgList
public ErrorList EmitArgList(CommonTree fnArgs, Action<Context> last)
{
var errors = new ErrorList();
if (fnArgs.Type == 0)
{
EmitNullRef();
errors.ErrorParse((CommonErrorNode) fnArgs);
return errors;
}
var args = fnArgs.Children;
var size = args.Count + 1;
var local = Sink.DeclareLocal(typeof (ITemplateType[]));
Sink.FastEmitConstInt(size);
Sink.Emit(OpCodes.Newarr, typeof (ITemplateType));
Sink.FastEmitStoreLocal(local.LocalIndex);
for (var i = 0; i < args.Count; i++)
{
Sink.FastEmitLoadLocal(local.LocalIndex);
Sink.FastEmitConstInt(i);
var exp = new Expression(args[i]);
errors.AddRange(exp.Generate(this));
Sink.Emit(OpCodes.Stelem_Ref);
}
Sink.FastEmitLoadLocal(local.LocalIndex);
Sink.FastEmitConstInt(fnArgs.Children.Count);
last(this);
Sink.Emit(OpCodes.Stelem_Ref);
Sink.FastEmitLoadLocal(local.LocalIndex);
return errors;
}
示例4: OnGenerate
protected override void OnGenerate()
{
var var = (CommonTree) T.Children[0];
if (var.Type == 0)
{
Errors.ErrorParse((CommonErrorNode) var);
return;
}
var exp = (CommonTree) T.Children[1];
if (exp.Type == 0)
{
Errors.ErrorParse((CommonErrorNode) exp);
return;
}
var defaultBlock = (CommonTree) T.Children[2];
var blocks = new Dictionary<LoopDirective, CommonTree>();
for (var i = 3; i < T.Children.Count; i++)
{
var targeted = (CommonTree) T.Children[i];
var ins = targeted.Children[0];
var tBlock = (CommonTree) targeted.Children[1];
LoopDirective d;
if (!Enum.TryParse(ins.Text, true, out d))
{
Errors.ErrorUnknownLoopDirective(ins.Text);
continue;
}
blocks[d] = tBlock;
}
if (Errors.ContainsError())
return;
var endOfLoop = Ctx.Sink.DefineLabel();
var continuePoint = Ctx.Sink.DefineLabel();
var top = Ctx.Sink.DefineLabel();
var endOfBlock = Ctx.Sink.DefineLabel();
var oddEvenVar = Ctx.Sink.DeclareLocal(typeof (int));
var iter = Ctx.Sink.DeclareLocal(typeof (IEnumerator));
var current = Ctx.Sink.DeclareLocal(typeof (ITemplateType));
Ctx.PushNewJumpScope(continuePoint, endOfLoop);
try
{
//init part here
var enumerableExp = new Expression(exp);
Errors.AddRange(enumerableExp.Generate(Ctx));
Ctx.Sink.FastEmitStoreLocal(current.LocalIndex);
Ctx.Sink.Emit(OpCodes.Ldarg_0);
Ctx.Sink.FastEmitLoadLocal(current.LocalIndex);
Ctx.EmitVTFunctionCall("CheckIsEnumerable");
Ctx.Sink.Emit(OpCodes.Brfalse, endOfBlock);
Ctx.Sink.Emit(OpCodes.Ldarg_0);
Ctx.Sink.FastEmitLoadLocal(current.LocalIndex);
Ctx.EmitVTFunctionCall("PrimeIter");
Ctx.Sink.FastEmitStoreLocal(iter.LocalIndex);
Ctx.Sink.FastEmitConstInt(0);
Ctx.Sink.FastEmitStoreLocal(oddEvenVar.LocalIndex);
var noDataSkip = Ctx.Sink.DefineLabel();
Ctx.Sink.FastEmitLoadLocal(iter.LocalIndex);
Ctx.EmitIterMoveNext();
Ctx.Sink.Emit(OpCodes.Brfalse, noDataSkip);
var skipStart = Ctx.Sink.DefineLabel();
Ctx.Sink.Emit(OpCodes.Ldarg_0);
Ctx.Sink.FastEmitLoadLocal(iter.LocalIndex);
Ctx.EmitVTFunctionCall("CurrentToTType");
Ctx.Sink.FastEmitStoreLocal(current.LocalIndex);
var s = new Statement(var);
Errors.AddRange(s.GenerateSet(Ctx, current.LocalIndex));
TryEmitBlock(LoopDirective.BeforeAll, blocks);
Ctx.Sink.Emit(OpCodes.Br, skipStart);
Ctx.Sink.MarkLabel(top);
Ctx.Sink.Emit(OpCodes.Nop);
Ctx.Sink.Emit(OpCodes.Ldarg_0);
Ctx.Sink.FastEmitLoadLocal(iter.LocalIndex);
Ctx.EmitVTFunctionCall("CurrentToTType");
Ctx.Sink.FastEmitStoreLocal(current.LocalIndex);
s = new Statement(var);
s.GenerateSet(Ctx, current.LocalIndex);
Ctx.Sink.MarkLabel(skipStart);
Ctx.Sink.Emit(OpCodes.Nop);
if (blocks.ContainsKey(LoopDirective.Between))
{
var skipFirstBetween = Ctx.Sink.DefineLabel();
Ctx.Sink.FastEmitLoadLocal(oddEvenVar.LocalIndex);
Ctx.Sink.FastEmitConstInt(0);
Ctx.Sink.Emit(OpCodes.Ceq);
Ctx.Sink.Emit(OpCodes.Brtrue, skipFirstBetween);
//.........这里部分代码省略.........
示例5: GenerateSet
public ErrorList GenerateSet(Context ctx, Expression exp)
{
return GenerateSet(ctx, c => Errors.AddRange(exp.Generate(c)));
}