本文整理汇总了C#中Lens.Compiler.Context类的典型用法代码示例。如果您正苦于以下问题:C# Context类的具体用法?C# Context怎么用?C# Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于Lens.Compiler命名空间,在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: compileOperator
protected override void compileOperator(Context ctx)
{
var gen = ctx.CurrentILGenerator;
GetExpressionType(ctx);
loadAndConvertNumerics(ctx);
gen.EmitRemainder();
}
开发者ID:TrickyCat,项目名称:lens,代码行数:7,代码来源:RemainderOperatorNode.cs
示例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;
}
开发者ID:menozz,项目名称:lens,代码行数:25,代码来源:LambdaNode.cs
示例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);
}
开发者ID:TrickyCat,项目名称:lens,代码行数:7,代码来源:GetArgumentNode.cs
示例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);
}
开发者ID:menozz,项目名称:lens,代码行数:12,代码来源:NodeBase.cs
示例5: expand
protected override NodeBase expand(Context ctx, bool mustReturn)
{
if (RightOperand.IsConstant && RightOperand.ConstantValue == 1)
return LeftOperand;
return base.expand(ctx, mustReturn);
}
开发者ID:menozz,项目名称:lens,代码行数:7,代码来源:DivideOperatorNode.cs
示例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);
}
开发者ID:menozz,项目名称:lens,代码行数:33,代码来源:WhileNode.cs
示例7: emitCode
protected override void emitCode(Context ctx, bool mustReturn)
{
if (_Getter == null)
compileArray(ctx);
else
compileCustom(ctx);
}
开发者ID:menozz,项目名称:lens,代码行数:7,代码来源:GetIndexNode.cs
示例8: compile
protected override void compile(Context ctx, bool mustReturn)
{
GetExpressionType(ctx);
var gen = ctx.CurrentILGenerator;
gen.EmitLoadArgument(0);
}
开发者ID:TrickyCat,项目名称:lens,代码行数:7,代码来源:ThisNode.cs
示例9: ProcessClosures
public override void ProcessClosures(Context ctx)
{
if(Expression is GetIdentifierNode || Expression is GetMemberNode)
Expression.ProcessClosures(ctx);
base.ProcessClosures(ctx);
}
开发者ID:menozz,项目名称:lens,代码行数:7,代码来源:InvocationNode.cs
示例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;
}
}
开发者ID:TrickyCat,项目名称:lens,代码行数:26,代码来源:SetIndexNode.cs
示例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);
}
开发者ID:TrickyCat,项目名称:lens,代码行数:30,代码来源:SetMemberNode.cs
示例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);
}
}
开发者ID:menozz,项目名称:lens,代码行数:32,代码来源:NodeExtensions.cs
示例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);
}
开发者ID:menozz,项目名称:lens,代码行数:31,代码来源:SetIndexNode.cs
示例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;
}
开发者ID:menozz,项目名称:lens,代码行数:25,代码来源:TryNode.cs
示例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;
}
开发者ID:menozz,项目名称:lens,代码行数:7,代码来源:ThisNode.cs
示例16: emitCode
protected override void emitCode(Context ctx, bool mustReturn)
{
if (_Indexer == null)
emitSetArray(ctx);
else
emitSetCustomIndexer(ctx);
}
开发者ID:menozz,项目名称:lens,代码行数:7,代码来源:SetIndexNode.cs
示例17: expand
protected override NodeBase expand(Context ctx, bool mustReturn)
{
var leftType = LeftOperand.Resolve(ctx, mustReturn);
// create a lambda expression that passes the result of left function to the right one
if (leftType.IsCallableType())
{
var leftVar = ctx.Unique.TempVariableName();
var rightVar = ctx.Unique.TempVariableName();
var delegateType = ReflectionHelper.WrapDelegate(leftType);
var argDefs = delegateType.ArgumentTypes.Select(x => Expr.Arg(ctx.Unique.AnonymousArgName(), x.FullName)).ToArray();
return Expr.Lambda(
argDefs,
Expr.Block(
Expr.Let(leftVar, LeftOperand),
Expr.Let(rightVar, RightOperand),
Expr.Invoke(
Expr.Get(rightVar),
Expr.Invoke(
Expr.Get(leftVar),
argDefs.Select(x => Expr.Get(x.Name)).ToArray()
)
)
)
);
}
return base.expand(ctx, mustReturn);
}
开发者ID:menozz,项目名称:lens,代码行数:30,代码来源:ShiftOperatorNode.cs
示例18: compileOperator
protected override void compileOperator(Context ctx)
{
var gen = ctx.CurrentILGenerator;
Operand.Compile(ctx, true);
gen.EmitNegate();
}
开发者ID:TrickyCat,项目名称:lens,代码行数:7,代码来源:NegationOperatorNode.cs
示例19: resolveExpressionType
protected override System.Type resolveExpressionType(Context ctx, bool mustReturn = true)
{
if(ctx.CurrentMethod.IsStatic)
Error("Cannot access self-reference in static context!");
return ctx.CurrentType.TypeBuilder;
}
开发者ID:TrickyCat,项目名称:lens,代码行数:7,代码来源:ThisNode.cs
示例20: emitCode
protected override void emitCode(Context ctx, bool mustReturn)
{
var gen = ctx.CurrentMethod.Generator;
Expr.Cast<int>(Size).Emit(ctx, true);
gen.EmitCreateArray(Type);
}
开发者ID:menozz,项目名称:lens,代码行数:7,代码来源:NewObjectArrayNode.cs
注:本文中的Lens.Compiler.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论