本文整理汇总了C#中Lens.Compiler.Context类的典型用法代码示例。如果您正苦于以下问题:C# Context类的具体用法?C# Context怎么用?C# Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于Lens.Compiler命名空间,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: compileOperator
protected override void compileOperator(Context ctx)
{
var gen = ctx.CurrentILGenerator;
GetExpressionType(ctx);
loadAndConvertNumerics(ctx);
gen.EmitRemainder();
}
示例2: ProcessClosures
public override void ProcessClosures(Context ctx)
{
if (MustInferArgTypes)
{
var name = Arguments.First(a => a.Type == typeof (UnspecifiedType)).Name;
error(CompilerMessages.LambdaArgTypeUnknown, name);
}
// get evaluated return type
var retType = _InferredReturnType ?? Body.Resolve(ctx);
if (retType == typeof(NullType))
error(CompilerMessages.LambdaReturnTypeUnknown);
if (retType.IsVoid())
retType = typeof (void);
_Method = ctx.Scope.CreateClosureMethod(ctx, Arguments, retType);
_Method.Body = Body;
var outerMethod = ctx.CurrentMethod;
ctx.CurrentMethod = _Method;
_Method.Body.ProcessClosures(ctx);
ctx.CurrentMethod = outerMethod;
}
示例3: compile
protected override void compile(Context ctx, bool mustReturn)
{
var gen = ctx.CurrentILGenerator;
var id = ArgumentId + (ctx.CurrentMethod.IsStatic ? 0 : 1);
gen.EmitLoadArgument(id);
}
示例4: Emit
/// <summary>
/// Generates the IL for this node.
/// </summary>
/// <param name="ctx">Pointer to current context.</param>
/// <param name="mustReturn">Flag indicating the node should return a value.</param>
public void Emit(Context ctx, bool mustReturn)
{
if (IsConstant && !mustReturn)
return;
emitCode(ctx, mustReturn);
}
示例5: expand
protected override NodeBase expand(Context ctx, bool mustReturn)
{
if (RightOperand.IsConstant && RightOperand.ConstantValue == 1)
return LeftOperand;
return base.expand(ctx, mustReturn);
}
示例6: emitCode
protected override void emitCode(Context ctx, bool mustReturn)
{
var gen = ctx.CurrentMethod.Generator;
var loopType = Resolve(ctx);
var saveLast = mustReturn && !loopType.IsVoid();
var beginLabel = gen.DefineLabel();
var endLabel = gen.DefineLabel();
Local tmpVar = null;
if (saveLast)
{
tmpVar = ctx.Scope.DeclareImplicit(ctx, loopType, false);
Expr.Set(tmpVar, Expr.Default(loopType)).Emit(ctx, false);
}
gen.MarkLabel(beginLabel);
Expr.Cast(Condition, typeof(bool)).Emit(ctx, true);
gen.EmitConstant(false);
gen.EmitBranchEquals(endLabel);
Body.Emit(ctx, mustReturn);
if (saveLast)
gen.EmitSaveLocal(tmpVar.LocalBuilder);
gen.EmitJump(beginLabel);
gen.MarkLabel(endLabel);
if (saveLast)
gen.EmitLoadLocal(tmpVar.LocalBuilder);
}
示例7: emitCode
protected override void emitCode(Context ctx, bool mustReturn)
{
if (_Getter == null)
compileArray(ctx);
else
compileCustom(ctx);
}
示例8: compile
protected override void compile(Context ctx, bool mustReturn)
{
GetExpressionType(ctx);
var gen = ctx.CurrentILGenerator;
gen.EmitLoadArgument(0);
}
示例9: ProcessClosures
public override void ProcessClosures(Context ctx)
{
if(Expression is GetIdentifierNode || Expression is GetMemberNode)
Expression.ProcessClosures(ctx);
base.ProcessClosures(ctx);
}
示例10: compileCustom
private void compileCustom(Context ctx)
{
var gen = ctx.CurrentILGenerator;
var exprType = Expression.GetExpressionType(ctx);
var idxType = Index.GetExpressionType(ctx);
try
{
var pty = ctx.ResolveIndexer(exprType, idxType, false);
var idxDest = pty.ArgumentTypes[0];
var valDest = pty.ArgumentTypes[1];
Expression.Compile(ctx, true);
Expr.Cast(Index, idxDest).Compile(ctx, true);
Expr.Cast(Value, valDest).Compile(ctx, true);
gen.EmitCall(pty.MethodInfo);
}
catch (LensCompilerException ex)
{
ex.BindToLocation(this);
throw;
}
}
示例11: compile
protected override void compile(Context ctx, bool mustReturn)
{
resolve(ctx);
var gen = ctx.CurrentILGenerator;
var destType = m_Field != null ? m_Field.FieldType : m_Property.PropertyType;
var valType = Value.GetExpressionType(ctx);
ctx.CheckTypedExpression(Value, valType, true);
if(!destType.IsExtendablyAssignableFrom(valType))
Error(CompilerMessages.ImplicitCastImpossible, valType, destType);
if (!m_IsStatic)
{
var exprType = Expression.GetExpressionType(ctx);
if (Expression is IPointerProvider && exprType.IsStruct())
(Expression as IPointerProvider).PointerRequired = true;
Expression.Compile(ctx, true);
}
Expr.Cast(Value, destType).Compile(ctx, true);
if(m_Field != null)
gen.EmitSaveField(m_Field.FieldInfo);
else
gen.EmitCall(m_Property.Setter, true);
}
示例12: EmitNodeForAccess
/// <summary>
/// Emits the node ready for accessing members or invoking methods on it.
/// </summary>
public static void EmitNodeForAccess(this NodeBase node, Context ctx)
{
var type = node.Resolve(ctx);
if (type.IsValueType)
{
if (node is IPointerProvider)
{
(node as IPointerProvider).PointerRequired = true;
node.Emit(ctx, true);
}
else
{
var gen = ctx.CurrentMethod.Generator;
var tmpVar = ctx.Scope.DeclareImplicit(ctx, type, true);
gen.EmitLoadLocal(tmpVar.LocalBuilder, true);
node.Emit(ctx, true);
gen.EmitSaveObject(type);
gen.EmitLoadLocal(tmpVar.LocalBuilder, true);
}
}
else
{
node.Emit(ctx, true);
}
}
示例13: resolve
protected override Type resolve(Context ctx, bool mustReturn)
{
var exprType = Expression.Resolve(ctx);
var idxType = Index.Resolve(ctx);
if (!exprType.IsArray)
{
try
{
_Indexer = ReflectionHelper.ResolveIndexer(exprType, idxType, false);
}
catch (LensCompilerException ex)
{
ex.BindToLocation(this);
throw;
}
}
var idxDestType = exprType.IsArray ? typeof (int) : _Indexer.ArgumentTypes[0];
var valDestType = exprType.IsArray ? exprType.GetElementType() : _Indexer.ArgumentTypes[1];
if(!idxDestType.IsExtendablyAssignableFrom(idxType))
error(Index, CompilerMessages.ImplicitCastImpossible, idxType, idxDestType);
ensureLambdaInferred(ctx, Value, valDestType);
var valType = Value.Resolve(ctx);
if (!valDestType.IsExtendablyAssignableFrom(valType))
error(Value, CompilerMessages.ImplicitCastImpossible, valType, valDestType);
return base.resolve(ctx, mustReturn);
}
示例14: emitCode
protected override void emitCode(Context ctx, bool mustReturn)
{
var gen = ctx.CurrentMethod.Generator;
var backup = ctx.CurrentTryBlock;
ctx.CurrentTryBlock = this;
EndLabel = gen.BeginExceptionBlock();
Code.Emit(ctx, false);
gen.EmitLeave(EndLabel);
foreach (var curr in CatchClauses)
curr.Emit(ctx, false);
if (Finally != null)
{
gen.BeginFinallyBlock();
Finally.Emit(ctx, false);
}
gen.EndExceptionBlock();
ctx.CurrentTryBlock = backup;
}
示例15: resolve
protected override Type resolve(Context ctx, bool mustReturn)
{
if(ctx.CurrentMethod.IsStatic)
error("Cannot access self-reference in static context!");
return ctx.CurrentType.TypeBuilder;
}