本文整理汇总了C#中BlockExpression类的典型用法代码示例。如果您正苦于以下问题:C# BlockExpression类的具体用法?C# BlockExpression怎么用?C# BlockExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlockExpression类属于命名空间,在下文中一共展示了BlockExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Emit
private void Emit(BlockExpression node, EmitAs emitAs) {
EnterScope(node);
int count = node.ExpressionCount;
for (int index = 0; index < count - 1; index++) {
var e = node.GetExpression(index);
if (_emitDebugSymbols) {
//No need to emit a clearance if the next expression in the block is also a
//DebugInfoExprssion.
var debugInfo = e as DebugInfoExpression;
if (debugInfo != null && debugInfo.IsClear && node.GetExpression(index + 1) is DebugInfoExpression) {
continue;
}
}
EmitExpressionAsVoid(e);
}
// if the type of Block it means this is not a Comma
// so we will force the last expression to emit as void.
if (emitAs == EmitAs.Void || node.Type == typeof(void)) {
EmitExpressionAsVoid(node.GetExpression(count - 1));
} else {
EmitExpressionAsType(node.GetExpression(count - 1), node.Type);
}
ExitScope(node);
}
示例2: Emit
private void Emit(BlockExpression node, EmitAs emitAs) {
int count = node.ExpressionCount;
// Labels defined immediately in the block are valid for the whole block
for(int i = 0; i < count; i++) {
Expression e = node.GetExpression(i);
var label = e as LabelExpression;
if (label != null) {
DefineLabel(label.Label);
}
}
EnterScope(node);
for (int index = 0; index < count - 1; index++) {
EmitExpressionAsVoid(node.GetExpression(index));
}
// if the type of Block it means this is not a Comma
// so we will force the last expression to emit as void.
if (emitAs == EmitAs.Void || node.Type == typeof(void)) {
EmitExpressionAsVoid(node.GetExpression(count - 1));
} else {
EmitExpression(node.GetExpression(count - 1));
}
ExitScope(node);
}
示例3: FunctionExpression
public FunctionExpression(Token token, string name, List<string> arguments, BlockExpression block)
: base(token.FileName, token.Line)
{
Name = name;
Arguments = arguments.AsReadOnly();
Block = block;
}
示例4: Emit
private void Emit(BlockExpression node, CompilationFlags flags)
{
int count = node.ExpressionCount;
if (count == 0)
{
return;
}
EnterScope(node);
CompilationFlags emitAs = flags & CompilationFlags.EmitAsTypeMask;
CompilationFlags tailCall = flags & CompilationFlags.EmitAsTailCallMask;
for (int index = 0; index < count - 1; index++)
{
var e = node.GetExpression(index);
var next = node.GetExpression(index + 1);
CompilationFlags tailCallFlag;
if (tailCall != CompilationFlags.EmitAsNoTail)
{
var g = next as GotoExpression;
if (g != null && (g.Value == null || !Significant(g.Value)) && ReferenceLabel(g.Target).CanReturn)
{
// Since tail call flags are not passed into EmitTryExpression, CanReturn means the goto will be emitted
// as Ret. Therefore we can emit the current expression with tail call.
tailCallFlag = CompilationFlags.EmitAsTail;
}
else
{
// In the middle of the block.
// We may do better here by marking it as Tail if the following expressions are not going to emit any IL.
tailCallFlag = CompilationFlags.EmitAsMiddle;
}
}
else
{
tailCallFlag = CompilationFlags.EmitAsNoTail;
}
flags = UpdateEmitAsTailCallFlag(flags, tailCallFlag);
EmitExpressionAsVoid(e, flags);
}
// if the type of Block it means this is not a Comma
// so we will force the last expression to emit as void.
// We don't need EmitAsType flag anymore, should only pass
// the EmitTailCall field in flags to emitting the last expression.
if (emitAs == CompilationFlags.EmitAsVoidType || node.Type == typeof(void))
{
EmitExpressionAsVoid(node.GetExpression(count - 1), tailCall);
}
else
{
EmitExpressionAsType(node.GetExpression(count - 1), node.Type, tailCall);
}
ExitScope(node);
}
示例5: ForExpression
public ForExpression(Token token, Expression initializer, Expression condition, BlockExpression increment, BlockExpression block)
: base(token.FileName, token.Line)
{
Initializer = initializer;
Condition = condition;
Increment = increment;
Block = block;
}
示例6: UpdateBlockExpression
protected virtual BlockExpression UpdateBlockExpression(BlockExpression exp, IEnumerable<Expression> expressions, IEnumerable<ParameterExpression> variables)
{
if (exp.Expressions != expressions ||
exp.Variables != variables) {
return Expression.Block(
variables, expressions
);
}
return exp;
}
示例7: VisitBlockExpression
public override Expression VisitBlockExpression(BlockExpression blockExpression){
if (blockExpression == null) return null;
Block block = blockExpression.Block;
if (block != null && block.Statements != null && block.Statements.Count == 1) {
ExpressionStatement es = block.Statements[0] as ExpressionStatement;
if (es != null) {
es.Expression = this.VisitExpression(es.Expression);
this.composers.Clear();
this.composers.Add(this.GetComposer(es.Expression));
return (Expression) this.Compose(blockExpression, this.composers);
}
}
return base.VisitBlockExpression(blockExpression);
}
示例8: Emit
private void Emit(BlockExpression node, CompilationFlags flags) {
EnterScope(node);
CompilationFlags emitAs = flags & CompilationFlags.EmitAsTypeMask;
int count = node.ExpressionCount;
CompilationFlags tailCall = flags & CompilationFlags.EmitAsTailCallMask;
CompilationFlags middleTailCall = tailCall == CompilationFlags.EmitAsNoTail ? CompilationFlags.EmitAsNoTail : CompilationFlags.EmitAsMiddle;
for (int index = 0; index < count - 1; index++) {
var e = node.GetExpression(index);
var next = node.GetExpression(index + 1);
if (EmitDebugSymbols) {
// No need to emit a clearance if the next expression in the block is also a
// DebugInfoExprssion.
var debugInfo = e as DebugInfoExpression;
if (debugInfo != null && debugInfo.IsClear && next is DebugInfoExpression) {
continue;
}
}
// In the middle of the block.
// We may do better here by marking it as Tail if the following expressions are not going to emit any IL.
var tailCallFlag = middleTailCall;
var g = next as GotoExpression;
if (g != null && (g.Value == null || !Significant(g.Value))) {
var labelInfo = ReferenceLabel(g.Target);
if (labelInfo.CanReturn) {
// Since tail call flags are not passed into EmitTryExpression, CanReturn means the goto will be emitted
// as Ret. Therefore we can emit the current expression with tail call.
tailCallFlag = CompilationFlags.EmitAsTail;
}
}
flags = UpdateEmitAsTailCallFlag(flags, tailCallFlag);
EmitExpressionAsVoid(e, flags);
}
// if the type of Block it means this is not a Comma
// so we will force the last expression to emit as void.
// We don't need EmitAsType flag anymore, should only pass
// the EmitTailCall field in flags to emitting the last expression.
if (emitAs == CompilationFlags.EmitAsVoidType || node.Type == typeof(void)) {
EmitExpressionAsVoid(node.GetExpression(count - 1), tailCall);
} else {
EmitExpressionAsType(node.GetExpression(count - 1), node.Type, tailCall);
}
ExitScope(node);
}
示例9: EnterScope
private void EnterScope(BlockExpression node) {
if (node.Variables.Count > 0 &&
(_scope.MergedScopes == null || !_scope.MergedScopes.Contains(node))) {
CompilerScope scope;
if (!_tree.Scopes.TryGetValue(node, out scope)) {
//
// Very often, we want to compile nodes as reductions
// rather than as IL, but usually they need to allocate
// some IL locals. To support this, we allow emitting a
// BlockExpression that was not bound by VariableBinder.
// This works as long as the variables are only used
// locally -- i.e. not closed over.
//
// User-created blocks will never hit this case; only our
// internally reduced nodes will.
//
scope = new CompilerScope(node) { NeedsClosure = _scope.NeedsClosure };
}
_scope = scope.Enter(this, _scope);
Debug.Assert(_scope.Node == node);
}
}
示例10: VisitBlockExpression
public virtual Expression VisitBlockExpression(BlockExpression blockExpression1, BlockExpression blockExpression2)
{
if (blockExpression1 == null) return null;
if (blockExpression2 == null)
blockExpression1.Block = this.VisitBlock(blockExpression1.Block, null);
else
blockExpression1.Block = this.VisitBlock(blockExpression1.Block, blockExpression2.Block);
return blockExpression1;
}
示例11: VisitBlockExpression
public override Expression VisitBlockExpression(BlockExpression blockExpression){
if (blockExpression == null) return null;
Block b = blockExpression.Block = this.VisitBlock(blockExpression.Block);
blockExpression.Type = SystemTypes.Void;
StatementList statements = b == null ? null : b.Statements;
if (statements != null && statements.Count > 0){
ExpressionStatement es = statements[statements.Count-1] as ExpressionStatement;
if (es != null && es.Expression != null && es.Expression.Type != null) {
blockExpression.Type = es.Expression.Type;
if (es.Expression is Literal && statements.Count == 1){
return es.Expression;
}
}
}
return blockExpression;
}
示例12: Visit
private static BlockExpression Visit(BlockExpression node)
{
// Tests dispatch of ExpressionVisitor into Rewrite method which calls Expression.Block factories.
return (BlockExpression)new Visitor().Visit(node);
}
示例13: EmitBranchBlock
private void EmitBranchBlock(bool branch, BlockExpression node, Label label) {
EnterScope(node);
int count = node.ExpressionCount;
for (int i = 0; i < count - 1; i++) {
EmitExpressionAsVoid(node.GetExpression(i));
}
EmitExpressionAndBranch(branch, node.GetExpression(count - 1), label);
ExitScope(node);
}
示例14: BlockExpressionProxy
public BlockExpressionProxy(BlockExpression node) {
_node = node;
}
示例15: ImplicitCoercion
public virtual Expression ImplicitCoercion(Expression source, TypeNode targetType, TypeViewer typeViewer){
TypeNode originalTargetType = targetType;
if (targetType == null || targetType.Name == Looker.NotFound) return source;
if (source == null) return null;
//HS D
if (source is Hole)
{
source.Type = targetType;
return source;
}
//HS D
if (source is LambdaHole)
{
if (targetType == SystemTypes.Boolean)
source = new LambdaHole(source, new Literal(0), NodeType.Ge, source.SourceContext);
source.Type = targetType;
return source;
}
Literal sourceLit = source as Literal;
if (sourceLit != null && sourceLit.Value is TypeNode){
this.HandleError(source, Error.TypeInVariableContext, this.GetTypeName((TypeNode)sourceLit.Value), "class", "variable");
return null;
}
//Ignore parentheses
if (source.NodeType == NodeType.Parentheses){
UnaryExpression uex = (UnaryExpression)source;
uex.Operand = this.ImplicitCoercion(uex.Operand, targetType, typeViewer);
if (uex.Operand == null) return null;
uex.Type = uex.Operand.Type;
return uex;
}
bool targetIsNonNullType = this.IsNonNullType(targetType);
targetType = TypeNode.StripModifier(targetType, SystemTypes.NonNullType);
targetType = TypeNode.StripModifier(targetType, SystemTypes.NullableType);
//TODO: handle SkipCheck and EnforceCheck
//Special case for closure expressions
if (source.NodeType == NodeType.AnonymousNestedFunction)
return this.CoerceAnonymousNestedFunction((AnonymousNestedFunction)source, targetType, false, typeViewer);
TypeNode sourceType = source.Type;
if (sourceType == null) sourceType = SystemTypes.Object;
bool sourceIsNonNullType = this.IsNonNullType(source.Type);
sourceType = TypeNode.StripModifier(sourceType, SystemTypes.NonNullType);
sourceType = TypeNode.StripModifier(sourceType, SystemTypes.NullableType);
if (sourceType == SystemTypes.String && !sourceIsNonNullType && source is Literal)
sourceIsNonNullType = ((Literal)source).Value != null;
if (this.currentParameter != null && targetType is Reference){
UnaryExpression uex = source as UnaryExpression;
if (uex != null){
if (sourceIsNonNullType && !targetIsNonNullType){
string ttypeName = this.GetTypeName(targetType);
string stypeName = this.GetTypeName(source.Type);
this.HandleError(source, Error.NoImplicitCoercion, stypeName, ttypeName);
return null;
}
if (!sourceIsNonNullType && targetIsNonNullType){
string ttypeName = this.GetTypeName(targetType);
string stypeName = this.GetTypeName(source.Type);
this.HandleError(source, Error.NoImplicitCoercion, stypeName, ttypeName);
return null;
}
if (uex.NodeType == NodeType.OutAddress){
if ((this.currentParameter.Flags & ParameterFlags.Out) == 0){
this.currentParameter.Flags |= ParameterFlags.Out;
string stypeName = this.GetTypeName(sourceType);
this.currentParameter.Flags &= ~ParameterFlags.Out;
this.HandleError(source, Error.NoImplicitCoercion, stypeName, this.GetTypeName(targetType));
return null;
}
}else if (uex.NodeType == NodeType.RefAddress){
if ((this.currentParameter.Flags & ParameterFlags.Out) != 0){
this.currentParameter.Flags &= ~ParameterFlags.Out;
string stypeName = this.GetTypeName(sourceType);
this.currentParameter.Flags |= ParameterFlags.Out;
this.HandleError(source, Error.NoImplicitCoercion, stypeName, this.GetTypeName(targetType));
return null;
}
}
}
}
Expression result = this.StandardImplicitCoercion(source, sourceIsNonNullType, sourceType, targetIsNonNullType, targetType, originalTargetType, typeViewer);
if (result != null) return result;
Method coercion = this.UserDefinedImplicitCoercionMethod(source, sourceType, targetType, true, typeViewer);
if (coercion != null){
if (this.IsNullableType(targetType) && this.IsNullableType(sourceType) && !this.IsNullableType(coercion.Parameters[0].Type))
return this.CoerceWithLiftedCoercion(source, sourceType, targetType, coercion, false, typeViewer);
ExpressionList args = new ExpressionList(1);
args.Add(this.ImplicitCoercion(source, coercion.Parameters[0].Type, typeViewer));
return this.ImplicitCoercion(new MethodCall(new MemberBinding(null, coercion), args, NodeType.Call, coercion.ReturnType, source.SourceContext), targetType, typeViewer);
}
if (sourceType == SystemTypes.Type && source is Literal)
this.HandleError(source, Error.TypeInVariableContext, this.GetTypeName((TypeNode)((Literal)source).Value), "class", "variable");
else if (this.IsNullableType(sourceType) && this.IsNullableType(targetType) && this.ImplicitCoercionFromTo(this.RemoveNullableWrapper(sourceType), this.RemoveNullableWrapper(targetType))) {
TypeNode usType = this.RemoveNullableWrapper(sourceType);
TypeNode utType = this.RemoveNullableWrapper(targetType);
Local tempSrc = new Local(sourceType);
Local tempTar = new Local(targetType);
StatementList statements = new StatementList();
BlockExpression result1 = new BlockExpression(new Block(statements));
statements.Add(new AssignmentStatement(tempSrc, source));
//.........这里部分代码省略.........