本文整理汇总了C#中BlockExpression类的典型用法代码示例。如果您正苦于以下问题:C# BlockExpression类的具体用法?C# BlockExpression怎么用?C# BlockExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlockExpression类属于命名空间,在下文中一共展示了BlockExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:28,代码来源:LambdaCompiler.Statements.cs
示例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);
}
开发者ID:mscottford,项目名称:ironruby,代码行数:30,代码来源:LambdaCompiler.Statements.cs
示例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;
}
开发者ID:krixalis,项目名称:Mond,代码行数:7,代码来源:FunctionExpression.cs
示例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);
}
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:60,代码来源:LambdaCompiler.Statements.cs
示例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;
}
开发者ID:krixalis,项目名称:Mond,代码行数:8,代码来源:ForExpression.cs
示例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;
}
开发者ID:hannasm,项目名称:ExpressiveExpressionTreesDotNet,代码行数:10,代码来源:ExpressionVisitor.cs
示例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);
}
开发者ID:hesam,项目名称:SketchSharp,代码行数:14,代码来源:Partitioner.cs
示例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);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:50,代码来源:LambdaCompiler.Statements.cs
示例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);
}
}
开发者ID:joshholmes,项目名称:ironruby,代码行数:24,代码来源:LambdaCompiler.Statements.cs
示例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;
}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:9,代码来源:DoubleVisitor.cs
示例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;
}
开发者ID:dbremner,项目名称:specsharp,代码行数:16,代码来源:Resolver.cs
示例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);
}
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:6,代码来源:BlockFactoryTests.cs
示例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);
}
开发者ID:salloo,项目名称:mono,代码行数:11,代码来源:LambdaCompiler.Logical.cs
示例14: BlockExpressionProxy
public BlockExpressionProxy(BlockExpression node) {
_node = node;
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:3,代码来源:Expression.DebuggerProxy.cs
示例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));
//.........这里部分代码省略.........
开发者ID:hesam,项目名称:SketchSharp,代码行数:101,代码来源:TypeSystem.cs
示例16: VisitBlockExpression
public override Expression VisitBlockExpression(BlockExpression blockExpression)
{
throw new ApplicationException("unimplemented");
}
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:4,代码来源:EmptyVisitor.cs
示例17: VisitBlockExpression
public virtual Expression VisitBlockExpression(BlockExpression blockExpression){
if (blockExpression == null) return null;
blockExpression.Block = this.VisitBlock(blockExpression.Block);
return blockExpression;
}
开发者ID:dbremner,项目名称:specsharp,代码行数:5,代码来源:StandardVisitor.cs
示例18: Branch
public Branch(Expression condition, BlockExpression block)
{
Condition = condition;
Block = block;
}
开发者ID:krixalis,项目名称:Mond,代码行数:5,代码来源:IfExpression.cs
示例19: VisitBlockExpression
public override Expression VisitBlockExpression(BlockExpression blockExpression)
{
if (blockExpression == null) return null;
return base.VisitBlockExpression((BlockExpression)blockExpression.Clone());
}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:5,代码来源:Duplicator.cs
示例20: VisitBlockExpression
public override Expression VisitBlockExpression(BlockExpression blockExpression) {
if (blockExpression == null) return null;
// This is either
// 1) a call of the form {newLocal = e; &newLocal; }.M(...)
// where M.DeclaringType is Struct
// We simply serialize e
// or
// 2) of the form { newLocal = e; AssertNotNull(newLocal); newLocal; }
// or
// 3) of the form { AssertNotNull(e); e; } // where e is a variable
// We simply serialize e
// or
// 4) of the form { Exception e; <boolean expression involving e> }
// This arises from "throws (E e) ensures Q" clauses. Q sits in an ExpressionStatement
// with e as a bound variable of the block scope.
Block block = blockExpression.Block;
if (block == null || block.Statements == null || 3 < block.Statements.Count) return blockExpression;
//Debug.Assert(block.Statements.Count == 2 || block.Statements.Count == 3);
AssignmentStatement a = block.Statements[0] as AssignmentStatement;
if (a != null) { // case (1) or (2)
ExpressionStatement es = (ExpressionStatement)block.Statements[1];
Debug.Assert(es.Expression.NodeType == NodeType.AddressOf || es.Expression.NodeType == NodeType.Call);
this.Visit(a.Source);
} else if (block.Statements.Count == 1) { // case (4) (is a stronger test needed here?
// overload the comprehension serialization and compensate after it has been deserialized as a comprehension
// NB: this code now lives in two places (here and VisitComprehension)!
this._string.Append("{|");
if (0 < block.Scope.Members.Count) {
this._string.Append("{");
Field f = block.Scope.Members[0] as Field; // what if there is more than one?
this.AddType(f.Type);
this._string.Append(",");
this.VisitField(f);
this._string.Append(",null}");
}
this._string.Append(";");
ExpressionStatement es = block.Statements[0] as ExpressionStatement;
this.VisitExpression(es.Expression);
this._string.Append("|}");
}else { // case (3)
ExpressionStatement es = (ExpressionStatement)block.Statements[1];
this.Visit(es.Expression);
}
return blockExpression;
}
开发者ID:hesam,项目名称:SketchSharp,代码行数:46,代码来源:Serializer.cs
注:本文中的BlockExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论