• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CSharp.ExpressionStatement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Mono.CSharp.ExpressionStatement的典型用法代码示例。如果您正苦于以下问题:C# ExpressionStatement类的具体用法?C# ExpressionStatement怎么用?C# ExpressionStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ExpressionStatement类属于Mono.CSharp命名空间,在下文中一共展示了ExpressionStatement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DoResolve

        protected override bool DoResolve(BlockContext ec)
        {
            //
            // When delegate returns void, only expression statements can be used
            //
            if (ec.ReturnType == TypeManager.void_type) {
                Expr = Expr.Resolve (ec);
                if (Expr == null)
                    return false;

                statement = Expr as ExpressionStatement;
                if (statement == null)
                    Expr.Error_InvalidExpressionStatement (ec);

                return true;
            }

            return base.DoResolve (ec);
        }
开发者ID:RainsSoft,项目名称:MonoCompilerAsAService,代码行数:19,代码来源:lambda.cs


示例2: GetActions

		public IEnumerable<CodeAction> GetActions(RefactoringContext context)
		{
			//TODO: implement variable assignment & ctor param
			var varInit = context.GetNode<VariableInitializer>();
			if (varInit != null) {
				AstType type = varInit.GetPrevNode() as AstType;
				if (type == null) yield break;
				if (varInit.Parent is FieldDeclaration) yield break;
				if (CannotExtractField(varInit)) yield break;
				
				yield return new CodeAction("Extract field", s=>{
					var name = varInit.Name;
					FieldDeclaration field = new FieldDeclaration(){
						ReturnType = type.Clone(),
						Variables = { new VariableInitializer(name) }
					};
					AstNode nodeToRemove = RemoveDeclaration(varInit) ? varInit.Parent : type;
					s.Remove(nodeToRemove, true);
					s.InsertWithCursor(context.TranslateString("Extract field"),Script.InsertPosition.Before,field);
					s.FormatText(varInit.Parent);
				});
			}
			
			var idntf = context.GetNode<Identifier>();
			if (idntf == null) yield break;
			var paramDec = idntf.Parent as ParameterDeclaration;
			if (paramDec != null) {
				var ctor = paramDec.Parent as ConstructorDeclaration;
				if (ctor == null) yield break;
				MemberReferenceExpression thisField = new MemberReferenceExpression(new ThisReferenceExpression(), idntf.Name, new AstType[]{});
				var assign = new AssignmentExpression(thisField, AssignmentOperatorType.Assign, new IdentifierExpression(idntf.Name));
				var statement = new ExpressionStatement(assign);
				var type = (idntf.GetPrevNode() as AstType).Clone();
				FieldDeclaration field = new FieldDeclaration(){
					ReturnType = type.Clone(),
					Variables = { new VariableInitializer(idntf.Name) }
				};
				yield return new CodeAction("Extract field", s=>{
					s.InsertWithCursor(context.TranslateString("Extract field"),Script.InsertPosition.Before,field);
					s.AddTo(ctor.Body, statement);
				});
			}
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:43,代码来源:ExtractFieldAction.cs


示例3: ResolveFieldInitializers

		public void ResolveFieldInitializers (BlockContext ec)
		{
			Debug.Assert (!IsPartialPart);

			if (ec.IsStatic) {
				if (initialized_static_fields == null)
					return;

				bool has_complex_initializer = !ec.Module.Compiler.Settings.Optimize;
				int i;
				ExpressionStatement [] init = new ExpressionStatement [initialized_static_fields.Count];
				for (i = 0; i < initialized_static_fields.Count; ++i) {
					FieldInitializer fi = initialized_static_fields [i];
					ExpressionStatement s = fi.ResolveStatement (ec);
					if (s == null) {
						s = EmptyExpressionStatement.Instance;
					} else if (!fi.IsSideEffectFree) {
						has_complex_initializer = true;
					}

					init [i] = s;
				}

				for (i = 0; i < initialized_static_fields.Count; ++i) {
					FieldInitializer fi = initialized_static_fields [i];
					//
					// Need special check to not optimize code like this
					// static int a = b = 5;
					// static int b = 0;
					//
					if (!has_complex_initializer && fi.IsDefaultInitializer)
						continue;

					ec.AssignmentInfoOffset += fi.AssignmentOffset;
					ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
				}

				return;
			}

			if (initialized_fields == null)
				return;

			for (int i = 0; i < initialized_fields.Count; ++i) {
				FieldInitializer fi = initialized_fields [i];

				//
				// Clone before resolving otherwise when field initializer is needed
				// in more than 1 constructor any resolve after the initial one would
				// only took the resolved expression which is problem for expressions
				// that generate extra expressions or code during Resolve phase
				//
				var cloned = fi.Clone (new CloneContext ());

				ExpressionStatement s = fi.ResolveStatement (ec);
				if (s == null) {
					initialized_fields [i] = new FieldInitializer (fi.Field, ErrorExpression.Instance, Location.Null);
					continue;
				}

				//
				// Field is re-initialized to its default value => removed
				//
				if (fi.IsDefaultInitializer && Kind != MemberKind.Struct && ec.Module.Compiler.Settings.Optimize)
					continue;

				ec.AssignmentInfoOffset += fi.AssignmentOffset;
				ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
				initialized_fields [i] = (FieldInitializer) cloned;
			}
		}
开发者ID:razzfazz,项目名称:mono,代码行数:71,代码来源:class.cs


示例4: DynamicEventCompoundAssign

        public DynamicEventCompoundAssign(string name, Arguments args, ExpressionStatement assignment, ExpressionStatement invoke, Location loc)
            : base(null, args, loc)
        {
            this.name = name;
            base.binder = this;

            // Used by += or -= only
            type = TypeManager.bool_type;

            condition = new If (
                new Binary (Binary.Operator.Equality, this, new BoolLiteral (true, loc), loc),
                new StatementExpression (invoke), new StatementExpression (assignment),
                loc);
        }
开发者ID:speier,项目名称:shake,代码行数:14,代码来源:dynamic.cs


示例5: DoResolve

		protected override Expression DoResolve (ResolveContext ec)
		{
			// Field initializer can be resolved (fail) many times
			if (source == null)
				return null;

			if (resolved == null) {
				var ctx = new FieldInitializerContext (mc, ec);
				resolved = base.DoResolve (ctx) as ExpressionStatement;
			}

			return resolved;
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:13,代码来源:assign.cs


示例6: Visit

			public override object Visit (StatementErrorExpression statementErrorExpression)
			{
				var result = new ExpressionStatement ();
				var expr = statementErrorExpression.Expression.Accept (this) as Expression;
				if (expr != null)
					result.AddChild ((Expression)expr, ExpressionStatement.Roles.Expression);
				return result;
			}
开发者ID:N3X15,项目名称:ILSpy,代码行数:8,代码来源:CSharpParser.cs


示例7: DynamicEventCompoundAssign

		public DynamicEventCompoundAssign (string name, Arguments args, ExpressionStatement assignment, ExpressionStatement invoke, Location loc)
			: base (null, args, loc)
		{
			this.name = name;
			this.assignment = assignment;
			this.invoke = invoke;
			base.binder = this;

			// Used by += or -= only
			type = TypeManager.bool_type;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:11,代码来源:dynamic.cs


示例8: Create

 public static ExpressionStatement Create(ExpressionStatement s, Expression orig)
 {
     return new ReducedExpressionStatement (s, orig);
 }
开发者ID:speier,项目名称:shake,代码行数:4,代码来源:ecore.cs


示例9: DoResolve

		protected override bool DoResolve (BlockContext ec)
		{
			//
			// When delegate returns void, only expression statements can be used
			//
			if (ec.ReturnType.Kind == MemberKind.Void) {
				Expr = Expr.Resolve (ec);
				if (Expr == null)
					return false;

				statement = Expr as ExpressionStatement;
				if (statement == null) {
					var reduced = Expr as IReducedExpressionStatement;
					if (reduced != null) {
						statement = EmptyExpressionStatement.Instance;
					} else {
						Expr.Error_InvalidExpressionStatement (ec);
					}
				}

				return true;
			}

			return base.DoResolve (ec);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:25,代码来源:lambda.cs


示例10: GetActions

		public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
		{
			//TODO: implement variable assignment & ctor param
			var varInit = context.GetNode<VariableInitializer>();
			if (varInit != null) {
				var selectedNode = varInit.GetNodeAt(context.Location);
				if (selectedNode != varInit.NameToken)
					yield break;

				AstType type = varInit.GetPrevNode() as AstType;
				if (type == null) yield break;
				if (varInit.Parent is FieldDeclaration) yield break;
				if (CannotExtractField(context, varInit)) yield break;
				
				yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
					var name = varInit.Name;

					AstType extractedType;
					if (type.IsVar()) {
						IType resolvedType = context.Resolve(varInit.Initializer).Type;
						extractedType = context.CreateShortType(resolvedType);
					}
					else {
						extractedType = (AstType) type.Clone();
					}

					AstNode entityDeclarationNode = varInit.Parent;
					while (!(entityDeclarationNode is EntityDeclaration) || (entityDeclarationNode is Accessor)) {
						entityDeclarationNode = entityDeclarationNode.Parent;
					}
					var entity = (EntityDeclaration) entityDeclarationNode;
					bool isStatic = entity.HasModifier(Modifiers.Static);

					FieldDeclaration field = new FieldDeclaration(){
						Modifiers = isStatic ? Modifiers.Static : Modifiers.None,
						ReturnType = extractedType,
						Variables = { new VariableInitializer(name) }
					};
					AstNode nodeToRemove = RemoveDeclaration(varInit) ? varInit.Parent : type;
					s.Remove(nodeToRemove, true);
					s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
					s.FormatText(varInit.Parent);
				}, varInit);
			}
			
			var idntf = context.GetNode<Identifier>();
			if (idntf == null) yield break;
			var paramDec = idntf.Parent as ParameterDeclaration;
			if (paramDec != null) {
				var ctor = paramDec.Parent as ConstructorDeclaration;
				if (ctor == null) yield break;
				MemberReferenceExpression thisField = new MemberReferenceExpression(new ThisReferenceExpression(), idntf.Name, new AstType[]{});
				var assign = new AssignmentExpression(thisField, AssignmentOperatorType.Assign, new IdentifierExpression(idntf.Name));
				var statement = new ExpressionStatement(assign);
				var type = (idntf.GetPrevNode() as AstType).Clone();
				FieldDeclaration field = new FieldDeclaration(){
					ReturnType = type.Clone(),
					Variables = { new VariableInitializer(idntf.Name) }
				};
				yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
					s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
					s.AddTo(ctor.Body, statement);
				}, paramDec);
			}
		}
开发者ID:qhta,项目名称:NRefactory,代码行数:65,代码来源:ExtractFieldAction.cs


示例11: ResolveVariable

		bool ResolveVariable (EmitContext ec)
		{
			ExpressionStatement a = new SimpleAssign (var, init, loc);
			a = a.ResolveStatement (ec);
			if (a == null)
				return false;

			assign = a;

			if (TypeManager.ImplementsInterface (a.Type, TypeManager.idisposable_type)) {
				converted_var = var;
				return true;
			}

			Expression e = Convert.ImplicitConversionStandard (ec, a, TypeManager.idisposable_type, var.Location);
			if (e == null) {
				Error_IsNotConvertibleToIDisposable (var);
				return false;
			}

			converted_var = e;

			return true;
		}
开发者ID:lewurm,项目名称:benchmarker,代码行数:24,代码来源:statement.cs


示例12: StatementExpression

		public StatementExpression (ExpressionStatement expr)
		{
			this.expr = expr;
			loc = expr.Location;
		}
开发者ID:alisci01,项目名称:mono,代码行数:5,代码来源:statement.cs


示例13: ReducedExpressionStatement

 public ReducedExpressionStatement(ExpressionStatement stm, Expression orig)
 {
     this.orig_expr = orig;
     this.stm = stm;
     this.loc = orig.Location;
 }
开发者ID:speier,项目名称:shake,代码行数:6,代码来源:ecore.cs


示例14: DoResolve

		protected override Expression DoResolve (ResolveContext ec)
		{
			// Field initializer can be resolved (fail) many times
			if (source == null)
				return null;

			if (resolved == null) {
				//
				// Field initializers are tricky for partial classes. They have to
				// share same constructor (block) but they have they own resolve scope.
				//

				IMemberContext old = ec.MemberContext;
				ec.MemberContext = rc;

				using (ec.Set (ResolveContext.Options.FieldInitializerScope)) {
					resolved = base.DoResolve (ec) as ExpressionStatement;
				}

				ec.MemberContext = old;
			}

			return resolved;
		}
开发者ID:ikvm,项目名称:mono,代码行数:24,代码来源:assign.cs


示例15: DynamicEventCompoundAssign

		public DynamicEventCompoundAssign (string name, Arguments args, ExpressionStatement assignment, ExpressionStatement invoke, Location loc)
		{
			condition = new IsEvent (name, args, loc);
			this.invoke = invoke;
			this.assign = assignment;
			this.loc = loc;
		}
开发者ID:caomw,项目名称:mono,代码行数:7,代码来源:dynamic.cs


示例16: Visit

			public override object Visit(InvalidStatementExpression invalidStatementExpression)
			{
				var result = new ExpressionStatement();
				if (invalidStatementExpression.Expression == null)
					return result;
				var expr = invalidStatementExpression.Expression.Accept(this) as Expression;
				if (expr != null)
					result.AddChild(expr, Roles.Expression);
				var location = LocationsBag.GetLocations(invalidStatementExpression);
				if (location != null)
					result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.Semicolon), Roles.Semicolon);
				return result;
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:13,代码来源:CSharpParser.cs


示例17: DoResolve

		protected override Expression DoResolve (ResolveContext rc)
		{
			// Field initializer can be resolved (fail) many times
			if (source == null)
				return null;

			var bc = (BlockContext) rc;
			if (resolved == null) {
				var ctx = new FieldInitializerContext (mc, bc);
				resolved = base.DoResolve (ctx) as ExpressionStatement;
				AssignmentOffset = ctx.AssignmentInfoOffset - bc.AssignmentInfoOffset;
			}

			return resolved;
		}
开发者ID:dyxu,项目名称:vimrc,代码行数:15,代码来源:assign.cs


示例18: ResolveFieldInitializers

		public void ResolveFieldInitializers (BlockContext ec)
		{
			Debug.Assert (!IsPartialPart);

			if (ec.IsStatic) {
				if (initialized_static_fields == null)
					return;

				bool has_complex_initializer = !ec.Module.Compiler.Settings.Optimize;
				int i;
				ExpressionStatement [] init = new ExpressionStatement [initialized_static_fields.Count];
				for (i = 0; i < initialized_static_fields.Count; ++i) {
					FieldInitializer fi = initialized_static_fields [i];
					ExpressionStatement s = fi.ResolveStatement (ec);
					if (s == null) {
						s = EmptyExpressionStatement.Instance;
					} else if (!fi.IsSideEffectFree) {
						has_complex_initializer |= true;
					}

					init [i] = s;
				}

				for (i = 0; i < initialized_static_fields.Count; ++i) {
					FieldInitializer fi = initialized_static_fields [i];
					//
					// Need special check to not optimize code like this
					// static int a = b = 5;
					// static int b = 0;
					//
					if (!has_complex_initializer && fi.IsDefaultInitializer)
						continue;

					ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
				}

				return;
			}

			if (initialized_fields == null)
				return;

			for (int i = 0; i < initialized_fields.Count; ++i) {
				FieldInitializer fi = initialized_fields [i];
				ExpressionStatement s = fi.ResolveStatement (ec);
				if (s == null)
					continue;

				//
				// Field is re-initialized to its default value => removed
				//
				if (fi.IsDefaultInitializer && ec.Module.Compiler.Settings.Optimize)
					continue;

				ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
			}
		}
开发者ID:fvalette,项目名称:mono,代码行数:57,代码来源:class.cs


示例19: DoResolveFieldInitializers

		void DoResolveFieldInitializers (BlockContext ec)
		{
			if (ec.IsStatic) {
				if (initialized_static_fields == null)
					return;

				bool has_complex_initializer = !RootContext.Optimize;
				int i;
				ExpressionStatement [] init = new ExpressionStatement [initialized_static_fields.Count];
				for (i = 0; i < initialized_static_fields.Count; ++i) {
					FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
					ExpressionStatement s = fi.ResolveStatement (ec);
					if (s == null) {
						s = EmptyExpressionStatement.Instance;
					} else if (fi.IsComplexInitializer) {
						has_complex_initializer |= true;
					}

					init [i] = s;
				}

				for (i = 0; i < initialized_static_fields.Count; ++i) {
					FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
					//
					// Need special check to not optimize code like this
					// static int a = b = 5;
					// static int b = 0;
					//
					if (!has_complex_initializer && fi.IsDefaultInitializer)
						continue;

					ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
				}

				return;
			}

			if (initialized_fields == null)
				return;

			for (int i = 0; i < initialized_fields.Count; ++i) {
				FieldInitializer fi = (FieldInitializer) initialized_fields [i];
				ExpressionStatement s = fi.ResolveStatement (ec);
				if (s == null)
					continue;

				//
				// Field is re-initialized to its default value => removed
				//
				if (fi.IsDefaultInitializer && RootContext.Optimize)
					continue;

				ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:55,代码来源:class.cs


示例20: Resolve

			public override bool Resolve (BlockContext ec)
			{
				bool is_dynamic = expr.Type == InternalType.Dynamic;

				if (is_dynamic) {
					expr = Convert.ImplicitConversionRequired (ec, expr, TypeManager.ienumerable_type, loc);
				} else if (TypeManager.IsNullableType (expr.Type)) {
					expr = new Nullable.UnwrapCall (expr).Resolve (ec);
				}

				var get_enumerator_mg = ResolveGetEnumerator (ec);
				if (get_enumerator_mg == null) {
					return false;
				}

				var get_enumerator = get_enumerator_mg.BestCandidate;
				enumerator_variable = TemporaryVariableReference.Create (get_enumerator.ReturnType, variable.Block, loc);
				enumerator_variable.Resolve (ec);

				// Prepare bool MoveNext ()
				var move_next_mg = ResolveMoveNext (ec, get_enumerator);
				if (move_next_mg == null) {
					return false;
				}

				move_next_mg.InstanceExpression = enumerator_variable;

				// Prepare ~T~ Current { get; }
				var current_prop = ResolveCurrent (ec, get_enumerator);
				if (current_prop == null) {
					return false;
				}

				var current_pe = new PropertyExpr (current_prop, loc) { InstanceExpression = enumerator_variable }.Resolve (ec);
				if (current_pe == null)
					return false;

				VarExpr ve = var_type as VarExpr;
				if (ve != null) {
					if (is_dynamic) {
						// Source type is dynamic, set element type to dynamic too
						var_type = new TypeExpression (InternalType.Dynamic, var_type.Location);
					} else {
						// Infer implicitly typed local variable from foreach enumerable type
						var_type = new TypeExpression (current_pe.Type, var_type.Location);
					}
				} else if (is_dynamic) {
					// Explicit cast of dynamic collection elements has to be done at runtime
					current_pe = EmptyCast.Create (current_pe, InternalType.Dynamic);
				}

				var_type = var_type.ResolveAsTypeTerminal (ec, false);
				if (var_type == null)
					return false;

				variable.Type = var_type.Type;

				var init = new Invocation (get_enumerator_mg, null);

				statement = new While (new BooleanExpression (new Invocation (move_next_mg, null)),
					new Body (var_type.Type, variable, current_pe, statement, loc), loc);

				var enum_type = enumerator_variable.Type;

				//
				// Add Dispose method call when enumerator can be IDisposable
				//
				if (!enum_type.ImplementsInterface (TypeManager.idisposable_type, false)) {
					if (!enum_type.IsSealed && !TypeManager.IsValueType (enum_type)) {
						//
						// Runtime Dispose check
						//
						var vd = new RuntimeDispose (enumerator_variable.LocalInfo, loc);
						vd.Initializer = init;
						statement = new Using (vd, statement, loc);
					} else {
						//
						// No Dispose call needed
						//
						this.init = new SimpleAssign (enumerator_variable, init);
						this.init.Resolve (ec);
					}
				} else {
					//
					// Static Dispose check
					//
					var vd = new Using.VariableDeclaration (enumerator_variable.LocalInfo, loc);
					vd.Initializer = init;
					statement = new Using (vd, statement, loc);
				}

				return statement.Resolve (ec);
			}
开发者ID:alisci01,项目名称:mono,代码行数:93,代码来源:statement.cs



注:本文中的Mono.CSharp.ExpressionStatement类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CSharp.Field类代码示例发布时间:2022-05-26
下一篇:
C# CSharp.Expression类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap