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

C# ArrayInitializer类代码示例

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

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



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

示例1: case_525

void case_525()
#line 3796 "cs-parser.jay"
{
		var ai = new ArrayInitializer (0, GetLocation (yyVals[-1+yyTop]));
		ai.VariableDeclaration = current_variable;
		lbag.AddLocation (ai, GetLocation (yyVals[0+yyTop]));
		yyVal = ai;
	  }
开发者ID:segaman,项目名称:NRefactory,代码行数:8,代码来源:cs-parser.cs


示例2: Visit

		public virtual object Visit (ArrayInitializer arrayInitializer)
		{
			return null;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:4,代码来源:visit.cs


示例3: CreateDynamicBinderArguments

		public ArrayInitializer CreateDynamicBinderArguments (ResolveContext rc)
		{
			Location loc = Location.Null;
			var all = new ArrayInitializer (args.Count, loc);

			MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace (rc, loc);

			foreach (Argument a in args) {
				Arguments dargs = new Arguments (2);

				// CSharpArgumentInfoFlags.None = 0
				const string info_flags_enum = "CSharpArgumentInfoFlags";
				Expression info_flags = new IntLiteral (rc.BuiltinTypes, 0, loc);

				if (a.Expr is Constant) {
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc));
				} else if (a.ArgType == Argument.AType.Ref) {
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc));
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
				} else if (a.ArgType == Argument.AType.Out) {
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc));
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
				} else if (a.ArgType == Argument.AType.DynamicTypeName) {
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc));
				}

				TypeSpec arg_type;

				if (rc.FileType == SourceFileType.PlayScript &&
				    a.Expr is ArrayInitializer || a.Expr is AsObjectInitializer) {
					if (a.Expr is ArrayInitializer) {
						arg_type = rc.Module.PredefinedTypes.AsArray.Resolve();
					} else {
						arg_type = rc.Module.PredefinedTypes.AsObject.Resolve();
					}
				} else {
					arg_type = a.Expr.Type;
				}

				if (arg_type.BuiltinType != BuiltinTypeSpec.Type.Dynamic && arg_type != InternalType.NullLiteral) {
					MethodGroupExpr mg = a.Expr as MethodGroupExpr;

					bool wasConverted = false;

					// In PlayScript, we try to implicity convert to dynamic, which handles conversions of method groups to delegates, and
					// anon methods to delegates.
					if (rc.FileType == SourceFileType.PlayScript && (mg != null || arg_type == InternalType.AnonymousMethod)) {
						var expr = Convert.ImplicitConversion (rc, a.Expr, rc.BuiltinTypes.Dynamic, loc);
						if (expr != null) {
							a.Expr = expr;
							arg_type = rc.BuiltinTypes.Dynamic;
							wasConverted = true;
						}
					}

					// Failed.. check the C# error
					if (!wasConverted) {
						if (mg != null) {
							rc.Report.Error (1976, a.Expr.Location,
								"The method group `{0}' cannot be used as an argument of dynamic operation. Consider using parentheses to invoke the method",
								mg.Name);
						} else if (arg_type == InternalType.AnonymousMethod) {
							rc.Report.Error (1977, a.Expr.Location,
								"An anonymous method or lambda expression cannot be used as an argument of dynamic operation. Consider using a cast");
						} else if (arg_type.Kind == MemberKind.Void || arg_type == InternalType.Arglist || arg_type.IsPointer) {
							rc.Report.Error (1978, a.Expr.Location,
								"An expression of type `{0}' cannot be used as an argument of dynamic operation",
								arg_type.GetSignatureForError ());
						}
					}

					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
				}

				string named_value;
				NamedArgument na = a as NamedArgument;
				if (na != null) {
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc));

					named_value = na.Name;
				} else {
					named_value = null;
				}

				dargs.Add (new Argument (info_flags));
				dargs.Add (new Argument (new StringLiteral (rc.BuiltinTypes, named_value, loc)));
				all.Add (new Invocation (new MemberAccess (new MemberAccess (binder, "CSharpArgumentInfo", loc), "Create", loc), dargs));
			}

			return all;
		}
开发者ID:johnv315,项目名称:playscript-mono,代码行数:99,代码来源:argument.cs


示例4: case_524

void case_524()
#line 3574 "C:\Projects\Junk\mono\mcs\class\Mono.CSharp\..\..\mcs\cs-parser.jay"
{
		var ai = new ArrayInitializer ((List<Expression>) yyVals[-2+yyTop], GetLocation (yyVals[-3+yyTop]));
		ai.VariableDeclaration = current_variable;
		if (yyVals[-1+yyTop] != null) {
			lbag.AddLocation (ai, GetLocation (yyVals[-1+yyTop]), GetLocation (yyVals[0+yyTop]));
		} else {
			lbag.AddLocation (ai, GetLocation (yyVals[0+yyTop]));
		}
		yyVal = ai;
	  }
开发者ID:RainsSoft,项目名称:MonoCompilerAsAService,代码行数:12,代码来源:cs-parser.cs


示例5: Visit

		public void Visit(ArrayInitializer x)
		{
			
		}
开发者ID:DinrusGroup,项目名称:D_Parser,代码行数:4,代码来源:ParameterInsightResolution.cs


示例6: CreateDynamicBinderArguments

		public ArrayInitializer CreateDynamicBinderArguments (ResolveContext rc)
		{
			Location loc = Location.Null;
			var all = new ArrayInitializer (args.Count, loc);

			MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace (loc);

			foreach (Argument a in args) {
				Arguments dargs = new Arguments (2);

				// CSharpArgumentInfoFlags.None = 0
				const string info_flags_enum = "CSharpArgumentInfoFlags";
				Expression info_flags = new IntLiteral (0, loc);

				var constant = a.Expr as Constant;
				if (constant != null && constant.IsLiteral) {
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc), loc);
				} else if (a.ArgType == Argument.AType.Ref) {
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc), loc);
				} else if (a.ArgType == Argument.AType.Out) {
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc), loc);
				} else if (a.ArgType == Argument.AType.DynamicTypeName) {
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc), loc);
				}

				var arg_type = a.Expr.Type;

				if (arg_type != InternalType.Dynamic) {
					MethodGroupExpr mg = a.Expr as MethodGroupExpr;
					if (mg != null) {
						rc.Report.Error (1976, a.Expr.Location,
							"The method group `{0}' cannot be used as an argument of dynamic operation. Consider using parentheses to invoke the method",
							mg.Name);
					} else if (arg_type == InternalType.AnonymousMethod) {
						rc.Report.Error (1977, a.Expr.Location,
							"An anonymous method or lambda expression cannot be used as an argument of dynamic operation. Consider using a cast");
					} else if (arg_type == TypeManager.void_type || arg_type == InternalType.Arglist || arg_type.IsPointer) {
						rc.Report.Error (1978, a.Expr.Location,
							"An expression of type `{0}' cannot be used as an argument of dynamic operation",
							TypeManager.CSharpName (arg_type));
					}

					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc), loc);
				}

				string named_value;
				NamedArgument na = a as NamedArgument;
				if (na != null) {
					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc), loc);

					named_value = na.Name;
				} else {
					named_value = null;
				}

				dargs.Add (new Argument (info_flags));
				dargs.Add (new Argument (new StringLiteral (named_value, loc)));
				all.Add (new Invocation (new MemberAccess (new MemberAccess (binder, "CSharpArgumentInfo", loc), "Create", loc), dargs));
			}

			return all;
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:68,代码来源:argument.cs


示例7: CreateCallSiteBinder

        public Expression CreateCallSiteBinder(ResolveContext ec, Arguments args)
        {
            Arguments binder_args = new Arguments (member != null ? 5 : 3);
            bool is_member_access = member is MemberAccess;

            CSharpBinderFlags call_flags;
            if (!is_member_access && member is SimpleName) {
                call_flags = CSharpBinderFlags.InvokeSimpleName;
                is_member_access = true;
            } else {
                call_flags = 0;
            }

            binder_args.Add (new Argument (new BinderFlags (call_flags, this)));

            if (is_member_access)
                binder_args.Add (new Argument (new StringLiteral (member.Name, member.Location)));

            if (member != null && member.HasTypeArguments) {
                TypeArguments ta = member.TypeArguments;
                if (ta.Resolve (ec)) {
                    var targs = new ArrayInitializer (ta.Count, loc);
                    foreach (TypeSpec t in ta.Arguments)
                        targs.Add (new TypeOf (new TypeExpression (t, loc), loc));

                    binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", targs, loc)));
                }
            } else if (is_member_access) {
                binder_args.Add (new Argument (new NullLiteral (loc)));
            }

            binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));

            Expression real_args;
            if (args == null) {
                // Cannot be null because .NET trips over
                real_args = new ArrayCreation (
                    new MemberAccess (GetBinderNamespace (loc), "CSharpArgumentInfo", loc), "[]",
                    new ArrayInitializer (0, loc), loc);
            } else {
                real_args = new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc);
            }

            binder_args.Add (new Argument (real_args));

            return new Invocation (GetBinder (is_member_access ? "InvokeMember" : "Invoke", loc), binder_args);
        }
开发者ID:speier,项目名称:shake,代码行数:47,代码来源:dynamic.cs


示例8: Visit

			public override object Visit (ArrayInitializer arrayInitializer)
			{
				var result = new ArrayInitializerExpression ();
				var location = LocationsBag.GetLocations (arrayInitializer);
				var commaLocations = LocationsBag.GetLocations (arrayInitializer.Elements);
				for (int i = 0; i < arrayInitializer.Count; i++) {
					result.AddChild((Expression)arrayInitializer[i].Accept(this), ArrayInitializerExpression.Roles.Expression);
				}
				
				return result;
			}
开发者ID:madkat,项目名称:NRefactory,代码行数:11,代码来源:CSharpParser.cs


示例9: VisitArrayInitializer

        public void VisitArrayInitializer(ArrayInitializer initializer)
        {
            Formatter.StartNode(initializer);

            Formatter.OpenBrace(Parameters.ArrayInitializerBraceStyle);
            WriteCommaSeparatedNodes(initializer.Elements, true);
            Formatter.CloseBrace(Parameters.ArrayInitializerBraceStyle);

            Formatter.EndNode();
        }
开发者ID:JerreS,项目名称:AbstractCode,代码行数:10,代码来源:CSharpAstWriter.cs


示例10: NonVoidInitializer

        IExpression NonVoidInitializer(IBlockNode Scope = null)
        {
            TrackerVariables.IsParsingInitializer = true;

            #region ArrayInitializer
            if (laKind == OpenSquareBracket)
            {
                Step();

                // ArrayMemberInitializations
                var ae = new ArrayInitializer() { Location=t.Location};
                LastParsedObject = ae;
                var inits=new List<ArrayMemberInitializer>();

                bool IsInit = true;
                while (IsInit || laKind == (Comma))
                {
                    if (!IsInit) Step();
                    IsInit = false;

                    // Allow empty post-comma expression IF the following token finishes the initializer expression
                    // int[] a=[1,2,3,4,];
                    if (laKind == CloseSquareBracket)
                        break;

                    // ArrayMemberInitialization
                    var ami = new ArrayMemberInitializer()
                    {
                        Left = NonVoidInitializer(Scope)
                    };
                    LastParsedObject = ami;
                    bool HasBeenAssExpr = !(t.Kind == (CloseSquareBracket) || t.Kind == (CloseCurlyBrace));

                    // AssignExpression : NonVoidInitializer
                    if (HasBeenAssExpr && laKind == (Colon))
                    {
                        Step();
                        ami.Specialization = NonVoidInitializer(Scope);
                    }
                    inits.Add(ami);
                }

                ae.ArrayMemberInitializations = inits.ToArray();

                Expect(CloseSquareBracket);
                ae.EndLocation = t.EndLocation;

                // auto i=[1,2,3].idup; // in this case, this entire thing is meant to be an AssignExpression but not a dedicated initializer..
                if (laKind == Dot)
                {
                    Step();

                    var ae2 = new PostfixExpression_Access();
                    LastParsedObject = ae2;
                    ae2.PostfixForeExpression = ae;
                    ae2.TemplateOrIdentifier = Type(); //TODO: Is it really a type!?
                    ae2.EndLocation = t.EndLocation;

                    if (!IsEOF)
                        TrackerVariables.IsParsingInitializer = false;

                    return ae2;
                }

                if (!IsEOF)
                    TrackerVariables.IsParsingInitializer = false;

                return ae;
            }
            #endregion

            // StructInitializer
            if (laKind == OpenCurlyBrace)
            {
                // StructMemberInitializations
                var ae = new StructInitializer() { Location = la.Location };
                LastParsedObject = ae;
                var inits = new List<StructMemberInitializer>();

                bool IsInit = true;
                while (IsInit || laKind == (Comma))
                {
                    Step();
                    IsInit = false;

                    // Allow empty post-comma expression IF the following token finishes the initializer expression
                    // int[] a=[1,2,3,4,];
                    if (laKind == CloseCurlyBrace)
                        break;

                    // Identifier : NonVoidInitializer
                    var sinit = new StructMemberInitializer();
                    LastParsedObject = sinit;
                    if (laKind == Identifier && Lexer.CurrentPeekToken.Kind == Colon)
                    {
                        Step();
                        sinit.MemberName = t.Value;
                        Step();
                    }

//.........这里部分代码省略.........
开发者ID:nazriel,项目名称:Mono-D,代码行数:101,代码来源:Parser_Impl.cs


示例11: Visit

		public ISymbolValue Visit(ArrayInitializer x)
		{
			return Visit((AssocArrayExpression)x);
		}
开发者ID:DinrusGroup,项目名称:D_Parser,代码行数:4,代码来源:Evaluation.PrimaryExpression.cs


示例12: case_517

void case_517()
{
		var ai = new ArrayInitializer (0, GetLocation (yyVals[-1+yyTop]));
		ai.VariableDeclaration = current_variable;
		lbag.AddLocation (ai, GetLocation (yyVals[0+yyTop]));
		yyVal = ai;
	  }
开发者ID:animaonline,项目名称:Portable-Mono.CSharp,代码行数:7,代码来源:cs-parser.cs


示例13: ParseExpr

        EXPR ParseExpr(bool isArithExpr)
        {
            EXPR e = null;
            if (tokens[i].type == TokenType.byte_lit)
            {
                e = new bytelit() { value = (byte)tokens[i].val };
                i++;
            }
            else if (tokens[i].type == TokenType.int_lit)
            {
                e = new intlit() { value = (int)tokens[i].val };
                i++;
            }
            else if (tokens[i].type == TokenType.string_lit)
            {
                e = new stringlit() { value = tokens[i].val as string };
                i++;
            }
            else if (tokens[i].type == TokenType.symbol && (char)tokens[i].val == '<')
            {
                i++;
                List<string> fargs = new List<string>();
                while (i < tokens.Length && !(tokens[i].type == TokenType.symbol && (char)tokens[i].val == '>'))
                {
                    if (tokens[i].type == TokenType.word)
                    {
                        fargs.Add(tokens[i].val as string);
                    }
                    i++;
                }
                i++;
                bool lnfc = infnc;
                infnc = true;
                STMT[] body = ParseBody();
                infnc = lnfc;

                e = new LambdaExpr() { args = fargs.ToArray(), body = body };
            }
            else if (tokens[i].type == TokenType.word && tokens[i].val as string == "array" && tokens[i + 1].type == TokenType.symbol && (char)tokens[i + 1].val == '[')
            {
                i += 2;
                EXPR count = ParseExpr(isArithExpr);
                i++;
                e = new ArrayInitializer() { count = count };
            }
            else if (tokens[i].type == TokenType.word && tokens[i + 1].type == TokenType.symbol && (char)tokens[i + 1].val == '[')
            {
                string varname = tokens[i].val as string;
                i += 2;
                EXPR index = ParseExpr(isArithExpr);
                i++;
                if (tokens[i].type == TokenType.symbol && (char)tokens[i].val == '=')
                {
                    i++;
                    EXPR val = ParseExpr(isArithExpr);
                    e = new ArrayStrElem() { varname = varname, index = index, value = val };
                }
                else
                {
                    e = new ArrayGetElem() { varname = varname, index = index };
                }
            }
            else if (i + 1 < tokens.Length && tokens[i + 1].type == TokenType.symbol && (char)tokens[i + 1].val == '(')
            {
                string fname = tokens[i].val as string;
                i += 2;
                List<EXPR> args = new List<EXPR>();
                while (!(tokens[i].type == TokenType.symbol && (char)tokens[i].val == ')'))
                {
                    EXPR ex = ParseExpr(isArithExpr);
                    if (ex != null)
                    {
                        args.Add(ex);
                    }
                    else
                    {
                        i++;
                    }
                }
                i++;
                e = new fcall() { fname = fname, args = args.ToArray() };
            }
            else if (tokens[i].type == TokenType.word && tokens[i].val as string == "asm")
            {
                i++;
                string asm = tokens[i].val as string;
                i++;
                return new asm() { asmtxt = asm };
            }
            else if (tokens[i].type == TokenType.word)
            {
                string vname = tokens[i].val as string;
                if (vname.StartsWith("@"))
                {
                    e = new getvarptr() { varname = vname.Substring(1) };
                }
                else
                {
                    e = new getvar() { varname = vname };
                }
//.........这里部分代码省略.........
开发者ID:Northcode,项目名称:nvm,代码行数:101,代码来源:Parser.cs


示例14: yyparse


//.........这里部分代码省略.........
				     name, current_local_parameters, (Attributes) yyVals[-9+yyTop], yyVals[0+yyTop] != null);
		if(current_container.Kind == MemberKind.Interface && current_extensionContainer != null){
		    var parameters = new List<Parameter>();
            var typeExpression = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation (yyVals[-9+yyTop]));
            var parameter = new Parameter(typeExpression, "self", Parameter.Modifier.This, null, GetLocation(yyVals[-9+yyTop]));
            parameters.Add(parameter);
            parameters.Add(new Parameter(typeExpression, "ctx", Parameter.Modifier.NONE, null, GetLocation(yyVals[-9+yyTop])));
		    var clone = current_local_parameters.Clone();
		    for(var i = 0; i < clone.Count; i++){
		       parameters.Add(clone[i]);
		    }
		    
			var parameterTypeExpressions = parameters.Select(p=>p.TypeExpression).ToList();
			var key = current_namespace.NS.Name + "," + name.Name + "," + string.Join(",",parameterTypeExpressions.Select(p => p.ToString()));
			if(roleExtensionMethodDummies.Add(key)){
               var returnType = (FullNamedExpression) yyVals[-7+yyTop];
			   var parametersCompiled = new ParametersCompiled(parameters.ToArray(),false);
		       var dummy = Method.Create (current_extensionContainer, generic, (FullNamedExpression) yyVals[-7+yyTop], Modifiers.PUBLIC | Modifiers.STATIC,
				       name, parametersCompiled, (Attributes) yyVals[-9+yyTop], yyVals[0+yyTop] != null);
                var location = GetLocation(yyVals[-9+yyTop]);
				var parameterName = new SimpleName("self", null, location);
				var getTypeAccess = new MemberAccess(parameterName, "GetType", null, location);
                var getTypeExpression =  new Invocation(getTypeAccess, new Arguments(0));
                var argCount = parameterTypeExpressions.Count-1;
                var argumentsForGetMethod = new Arguments(2);
				var stringLiteral =  new StringLiteral(compiler.BuiltinTypes,name.Name,location);
                argumentsForGetMethod.Add(new Argument(stringLiteral));
				var typeName = new SimpleName("Type", null, location);
				var types = parameterTypeExpressions.Skip(2)
				                          .Select(t =>(Expression)(t.Type != null 
										                             ? new TypeOf(t.Type,location) 
																	 : new TypeOf(t,location))
									  ).ToList();
				var initializer = new ArrayInitializer(types,location);
                var parameterTypes = new ImplicitlyTypedArrayCreation (
				                           new ComposedTypeSpecifier (1, location), 
										   initializer, 
										   location);
		        lbag.AddLocation (parameterTypes, location, location);
				
                argumentsForGetMethod.Add(new Argument(parameterTypes));
                var getMethodExpression = new Invocation(new MemberAccess(getTypeExpression,"GetMethod"),argumentsForGetMethod);
                var argumentsForMethod = new Arguments(2);

                var delegatedArguments = parameters.Skip(2).Select(p =>
                         (Expression)new Cast(
                                  new TypeExpression(compiler.BuiltinTypes.Object,location),
                                  new SimpleName(p.Name,location),
                                  location)).ToList();
		        argumentsForMethod.Add(new Argument(new SimpleName("self", null, location)));
                if(delegatedArguments.Any()){
				      initializer = new ArrayInitializer(delegatedArguments,location);
				
				      argumentsForMethod.Add(new Argument(new ImplicitlyTypedArrayCreation(
				                           new ComposedTypeSpecifier (1, location), 
										   initializer, 
										   location)));
                } else {
				   argumentsForMethod.Add(new Argument(new ArrayCreation(new TypeExpression(compiler.BuiltinTypes.Object,location),new ArrayInitializer(0,location)))); 
				}    

                var invocation = new Invocation(new MemberAccess(getMethodExpression,"Invoke"),argumentsForMethod);
				Statement statement = new StatementExpression(invocation);
				var retType = (returnType as TypeExpression);
                if(retType != null && retType.Type.Name != "Void"){
				    var cast = new Cast(returnType,invocation,location);
开发者ID:runefs,项目名称:Marvin,代码行数:67,代码来源:cs-parser.cs


示例15: case_526

void case_526()
#line 3803 "cs-parser.jay"
{
		var ai = new ArrayInitializer ((List<Expression>) yyVals[-2+yyTop], GetLocation (yyVals[-3+yyTop]));
		ai.VariableDeclaration = current_variable;
		if (yyVals[-1+yyTop] != null) {
			lbag.AddLocation (ai, GetLocation (yyVals[-1+yyTop]), GetLocation (yyVals[0+yyTop]));
		} else {
			lbag.AddLocation (ai, GetLocation (yyVals[0+yyTop]));
		}
		yyVal = ai;
	  }
开发者ID:segaman,项目名称:NRefactory,代码行数:12,代码来源:cs-parser.cs


示例16: Visit

			public override object Visit (ArrayInitializer arrayInitializer)
			{
				var result = new ArrayInitializerExpression ();
				var location = LocationsBag.GetLocations (arrayInitializer);
				result.AddChild (new CSharpTokenNode (Convert (arrayInitializer.Location), "[".Length), ArrayInitializerExpression.Roles.LBracket);
				var commaLocations = LocationsBag.GetLocations (arrayInitializer.Elements);
				for (int i = 0; i < arrayInitializer.Count; i++) {
					result.AddChild ((AstNode)arrayInitializer[i].Accept (this), ArrayInitializerExpression.Roles.Initializer);
					if (commaLocations != null && i < commaLocations.Count)
						result.AddChild (new CSharpTokenNode (Convert (commaLocations[i]), ",".Length), ArrayInitializerExpression.Roles.Comma);
				}
				
				if (location != null) {
					if (location.Count == 2) // optional comma
						result.AddChild (new CSharpTokenNode (Convert (location[1]), ",".Length), ArrayInitializerExpression.Roles.Comma);
					result.AddChild (new CSharpTokenNode (Convert (location[location.Count - 1]), "]".Length), ArrayInitializerExpression.Roles.RBracket);
				}
				return result;
			}
开发者ID:tech-uday-mca,项目名称:monodevelop,代码行数:19,代码来源:CSharpParser.cs


示例17: CSharpGrammar

        // IMPORTANT NOTE:
        // The grammar consists of a few LALR(1) conflicts. These issues are, however, correctly handled, due to the fact that the grammar 
        // is defined in a specific order making the already added parser actions have precedence over the other.
        //
        // Known conflicts that are correctly handled:
        //
        // - ELSE:          Shift/Reduce conflict Dangling ELSE problem.  Lots of articles are around on the internet. 
        //                  The shift action is taken here.
        //
        // - CLOSE_PARENS:  Shift/Reduce conflict. This is due to the fact that the explicit cast expression is like the parenthesized 
        //                  expression. The shift action is taken here.
        //
        // - STAR:          Reduce/Reduce conflict, between VariableType -> TypeNameExpression and PrimaryExpression -> TypeNameExpression, 
        //                  due to the fact variable types can have '*', and look therefore like a binary operator expression. 
        //                  The first reduce action is taken here.

        public CSharpGrammar()
        {
            // Please let me know if there is a better way of tidying this :s

            TokenMapping.Add((int)ERROR, Error);

            #region Definitions to use later

            var statementList = new GrammarDefinition("StatementList");
            var statementListOptional = new GrammarDefinition("StatementListOptional",
                rule: null
                      | statementList);

            var blockStatement = new GrammarDefinition("BlockStatement");

            var variableDeclarator = new GrammarDefinition("VariableDeclarator");
            var variableDeclaratorList = new GrammarDefinition("VariableDeclaratorList");
            variableDeclaratorList.Rule = variableDeclarator
                                          | variableDeclaratorList
                                          + ToElement(COMMA)
                                          + variableDeclarator;
            var variableDeclaration = new GrammarDefinition("VariableDeclaration");
            var variableInitializer = new GrammarDefinition("VariableInitializer");
            var arrayInitializer = new GrammarDefinition("ArrayInitializer");
            var arrayInitializerOptional = new GrammarDefinition("ArrayInitializerOptional",
                rule: null | arrayInitializer);
            var identifierInsideBody = new GrammarDefinition("IdentifierInsideBody",
                rule: ToElement(IDENTIFIER),
                createNode: node => ToIdentifier(node.Children[0].Result));
            var identifierInsideBodyOptional = new GrammarDefinition("IdentifierInsideBodyOptional",
                rule: null | identifierInsideBody);

            variableDeclarator.Rule = identifierInsideBody
                                      | identifierInsideBody
                                      + ToElement(EQUALS)
                                      + variableInitializer;
            variableDeclarator.ComputeResult = node =>
            {
                var result = new VariableDeclarator((Identifier) node.Children[0].Result);
                if (node.Children.Count > 1)
                {
                    result.OperatorToken = (AstToken) node.Children[1].Result;
                    result.Value = (Expression) node.Children[2].Result;
                }
                return result;
            };

            var typeReference = new GrammarDefinition("TypeReference");

            var identifierExpression = new GrammarDefinition("IdentifierExpression",
                rule: identifierInsideBody,
                createNode: node => new IdentifierExpression((Identifier) node.Children[0].Result));

            var usingDirectiveListOptional = new GrammarDefinition("UsingDirectiveListOptional");

            #endregion

            #region Type References

            var namespaceOrTypeExpression = new GrammarDefinition("NamespaceOrTypeExpression");

            namespaceOrTypeExpression.Rule = identifierExpression |
                                             namespaceOrTypeExpression
                                             + ToElement(DOT)
                                             + ToElement(IDENTIFIER);

            namespaceOrTypeExpression.ComputeResult = node =>
            {
                if (node.Children.Count == 1)
                    return ToTypeReference((IConvertibleToType) node.Children[0].Result);
                var result = new MemberTypeReference();
                result.Target = (TypeReference) node.Children[0].Result;
                result.AddChild(AstNodeTitles.Accessor, node.Children[1].Result);
                result.Identifier = ToIdentifier(node.Children[2].Result);
                return result;
            };

            ComputeResultDelegate createPrimitiveTypeExpression = node =>
            {
                if (node.Children[0].Result is PrimitiveTypeReference)
                    return node.Children[0].Result;
                return new PrimitiveTypeReference
                {
                    Identifier = ToIdentifier(node.Children[0].Result),
//.........这里部分代码省略.........
开发者ID:JerreS,项目名称:AbstractCode,代码行数:101,代码来源:CSharpGrammar.cs


示例18: VerifyArgumentsCompat

        public bool VerifyArgumentsCompat(ResolveContext ec, ref Arguments arguments,
            int arg_count, MethodSpec method,
            bool chose_params_expanded,
            bool may_fail, Location loc)
        {
            AParametersCollection pd = method.Parameters;
            int param_count = GetApplicableParametersCount (method, pd);

            int errors = ec.Report.Errors;
            Parameter.Modifier p_mod = 0;
            TypeSpec pt = null;
            int a_idx = 0, a_pos = 0;
            Argument a = null;
            ArrayInitializer params_initializers = null;
            bool has_unsafe_arg = method.ReturnType.IsPointer;

            for (; a_idx < arg_count; a_idx++, ++a_pos) {
                a = arguments [a_idx];
                if (p_mod != Parameter.Modifier.PARAMS) {
                    p_mod = pd.FixedParameters [a_idx].ModFlags;
                    pt = pd.Types [a_idx];
                    has_unsafe_arg |= pt.IsPointer;

                    if (p_mod == Parameter.Modifier.PARAMS) {
                        if (chose_params_expanded) {
                            params_initializers = new ArrayInitializer (arg_count - a_idx, a.Expr.Location);
                            pt = TypeManager.GetElementType (pt);
                        }
                    }
                }

                //
                // Types have to be identical when ref or out modifer is used
                //
                if (a.Modifier != 0 || (p_mod & ~Parameter.Modifier.PARAMS) != 0) {
                    if ((p_mod & ~Parameter.Modifier.PARAMS) != a.Modifier)
                        break;

                    if (!TypeManager.IsEqual (a.Expr.Type, pt))
                        break;

                    continue;
                } else {
                    NamedArgument na = a as NamedArgument;
                    if (na != null) {
                        int name_index = pd.GetParameterIndexByName (na.Name);
                        if (name_index < 0 || name_index >= param_count) {
                            if (DeclaringType != null && TypeManager.IsDelegateType (DeclaringType)) {
                                ec.Report.SymbolRelatedToPreviousError (DeclaringType);
                                ec.Report.Error (1746, na.Location,
                                    "The delegate `{0}' does not contain a parameter named `{1}'",
                                    TypeManager.CSharpName (DeclaringType), na.Name);
                            } else {
                                ec.Report.SymbolRelatedToPreviousError (best_candidate);
                                ec.Report.Error (1739, na.Location,
                                    "The best overloaded method match for `{0}' does not contain a parameter named `{1}'",
                                    TypeManager.CSharpSignature (method), na.Name);
                            }
                        } else if (arguments[name_index] != a) {
                            if (DeclaringType != null && TypeManager.IsDelegateType (DeclaringType))
                                ec.Report.SymbolRelatedToPreviousError (DeclaringType);
                            else
                                ec.Report.SymbolRelatedToPreviousError (best_candidate);

                            ec.Report.Error (1744, na.Location,
                                "Named argument `{0}' cannot be used for a parameter which has positional argument specified",
                                na.Name);
                        }
                    }
                }

                if (a.Expr.Type == InternalType.Dynamic)
                    continue;

                if (delegate_type != null && !Delegate.IsTypeCovariant (a.Expr, pt))
                    break;

                Expression conv = Convert.ImplicitConversion (ec, a.Expr, pt, loc);
                if (conv == null)
                    break;

                //
                // Convert params arguments to an array initializer
                //
                if (params_initializers != null) {
                    // we choose to use 'a.Expr' rather than 'conv' so that
                    // we don't hide the kind of expression we have (esp. CompoundAssign.Helper)
                    params_initializers.Add (a.Expr);
                    arguments.RemoveAt (a_idx--);
                    --arg_count;
                    continue;
                }

                // Update the argument with the implicit conversion
                a.Expr = conv;
            }

            if (a_idx != arg_count) {
                if (!may_fail && ec.Report.Errors == errors) {
                    if (CustomErrorHandler != null)
//.........这里部分代码省略.........
开发者ID:speier,项目名称:shake,代码行数:101,代码来源:ecore.cs


示例19: Visit

			public override object Visit(ArrayInitializer arrayInitializer)
			{
				var result = new ArrayInitializerExpression();
				var location = LocationsBag.GetLocations(arrayInitializer);
				result.AddChild(new CSharpTokenNode(Convert(arrayInitializer.Location), Roles.LBrace), Roles.LBrace);
				var commaLocations = LocationsBag.GetLocations(arrayInitializer.Elements);
				for (int i = 0; i < arrayInitializer.Count; i++) {
					var init = arrayInitializer [i];
					if (init == null)
						continue;
					result.AddChild((Expression)init.Accept(this), Roles.Expression);
					if (commaLocations != null && i < commaLocations.Count)
						result.AddChild(new CSharpTokenNode(Convert(commaLocations [i]), Roles.Comma), Roles.Comma);
				}
				
				if (location != null) {
					if (location.Count == 2) // optional comma
						result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.Comma), Roles.Comma);
					result.AddChild(new CSharpTokenNode(Convert(location [location.Count - 1]), Roles.RBrace), Roles.RBrace);
				}
				return result;
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:22,代码来源:CSharpParser.cs


示例20: yyparse

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ArrayInitializerExpression类代码示例发布时间:2022-05-24
下一篇:
C# ArrayCreateExpression类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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