コード例 #1
0
ファイル: CSharpParser.cs プロジェクト: 0xb1dd1e/NRefactory
			IEnumerable<Attribute> GetAttributes(IEnumerable<Mono.CSharp.Attribute> optAttributes)
			{
				if (optAttributes == null)
					yield break;
				foreach (var attr in optAttributes) {
					var result = new Attribute();
					result.Type = ConvertToType(attr.TypeNameExpression);
					var loc = LocationsBag.GetLocations(attr);
					result.HasArgumentList = loc != null;
					int pos = 0;
					if (loc != null)
						result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.LPar), Roles.LPar);
					
					if (attr.PositionalArguments != null) {
						foreach (var arg in attr.PositionalArguments) {
							if (arg == null)
								continue;
							var na = arg as NamedArgument;
							if (na != null) {
								var newArg = new NamedArgumentExpression();
								newArg.AddChild(Identifier.Create(na.Name, Convert(na.Location)), Roles.Identifier);
								
								var argLoc = LocationsBag.GetLocations(na);
								if (argLoc != null)
									newArg.AddChild(new CSharpTokenNode(Convert(argLoc [0]), Roles.Colon), Roles.Colon);
								if (na.Expr != null)
									newArg.AddChild((Expression)na.Expr.Accept(this), Roles.Expression);
								result.AddChild(newArg, Roles.Argument);
							} else {
								if (arg.Expr != null)
									result.AddChild((Expression)arg.Expr.Accept(this), Roles.Argument);
							}
							if (loc != null && pos + 1 < loc.Count)
								result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.Comma), Roles.Comma);
						}
					}
					if (attr.NamedArguments != null) {
						foreach (var arg in attr.NamedArguments) {
							var na = (NamedArgument)arg;
							var newArg = new NamedExpression();
							newArg.AddChild(Identifier.Create(na.Name, Convert(na.Location)), Roles.Identifier);
							
							var argLoc = LocationsBag.GetLocations(na);
							if (argLoc != null)
								newArg.AddChild(new CSharpTokenNode(Convert(argLoc [0]), Roles.Assign), Roles.Assign);
							if (na.Expr != null)
								newArg.AddChild((Expression)na.Expr.Accept(this), Roles.Expression);
							result.AddChild(newArg, Roles.Argument);
							if (loc != null && pos + 1 < loc.Count)
								result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.Comma), Roles.Comma);
						}
					}
					if (loc != null && pos < loc.Count)
						result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.RPar), Roles.RPar);
					
					yield return result;
				}
			}
コード例 #2
0
ファイル: CSharpParser.cs プロジェクト: 0xb1dd1e/NRefactory
			Expression ConvertArgument(Argument arg)
			{
				var na = arg as NamedArgument;
				if (na != null) {
					var newArg = new NamedArgumentExpression();
					newArg.AddChild(Identifier.Create(na.Name, Convert(na.Location)), Roles.Identifier);
					
					var loc = LocationsBag.GetLocations(na);
					if (loc != null)
						newArg.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.Colon), Roles.Colon);
					
					if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) {
						var direction = new DirectionExpression();
						direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
						var argLocation = LocationsBag.GetLocations(arg);
						if (argLocation != null) {
							var r = arg.ArgType == Argument.AType.Out ? DirectionExpression.OutKeywordRole : DirectionExpression.RefKeywordRole;
							direction.AddChild(new CSharpTokenNode(Convert(argLocation [0]), r), r);
						}
						direction.AddChild((Expression)arg.Expr.Accept(this), Roles.Expression);
						newArg.AddChild(direction, Roles.Expression);
					} else {
						newArg.AddChild(na.Expr != null ? (Expression)na.Expr.Accept(this) : new ErrorExpression("Named argument expression parse error"), Roles.Expression);
					}
					return newArg;
				}
				
				if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) {
					var direction = new DirectionExpression();
					direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
					var argLocation = LocationsBag.GetLocations(arg);
					if (argLocation != null) {
						var r = arg.ArgType == Argument.AType.Out ? DirectionExpression.OutKeywordRole : DirectionExpression.RefKeywordRole;
						direction.AddChild(new CSharpTokenNode(Convert(argLocation [0]), r), r);
					}
					direction.AddChild((Expression)arg.Expr.Accept(this), Roles.Expression);
					return direction;
				}
				
				return (Expression)arg.Expr.Accept(this);
			}
コード例 #3
0
ファイル: CSharpParser.cs プロジェクト: rmattuschka/ILSpy
			public override object Visit (NewAnonymousType newAnonymousType)
			{
				var result = new AnonymousTypeCreateExpression ();
				foreach (var par in newAnonymousType.Parameters) {
					var location = LocationsBag.GetLocations (par);

					if (location == null) {
						result.AddChild ((Expression)par.Expr.Accept (this), AnonymousTypeCreateExpression.Roles.Expression);
					} else {
						var namedArgument = new NamedArgumentExpression ();
						namedArgument.AddChild (new Identifier (par.Name, Convert (par.Location)), AnonymousTypeCreateExpression.Roles.Identifier);
						namedArgument.AddChild (new CSharpTokenNode (Convert (location [0]), 1), AnonymousTypeCreateExpression.Roles.Assign);
						namedArgument.AddChild ((Expression)par.Expr.Accept (this), AnonymousTypeCreateExpression.Roles.Expression);
						result.AddChild (namedArgument, AnonymousTypeCreateExpression.Roles.Expression);
					}
				}
				return result;
			}
コード例 #4
0
ファイル: CSharpParser.cs プロジェクト: N3X15/ILSpy
			Expression ConvertArgument (Argument arg)
			{
				if (arg is NamedArgument) {
					var na = (NamedArgument)arg;
					NamedArgumentExpression newArg = new NamedArgumentExpression();
					newArg.AddChild (Identifier.Create (na.Name, Convert (na.Location)), NamedArgumentExpression.Roles.Identifier);
					
					var loc = LocationsBag.GetLocations (na);
					if (loc != null)
						newArg.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), NamedArgumentExpression.Roles.Colon);
					
					if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) {
						DirectionExpression direction = new DirectionExpression ();
						direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
						var argLocation = LocationsBag.GetLocations (arg);
						if (argLocation != null)
							direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword);
						direction.AddChild ((Expression)arg.Expr.Accept (this), InvocationExpression.Roles.Expression);
						newArg.AddChild (direction, NamedArgumentExpression.Roles.Expression);
					} else {
						newArg.AddChild ((Expression)na.Expr.Accept (this), NamedArgumentExpression.Roles.Expression);
					}
					return newArg;
				}
				
				if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) {
					DirectionExpression direction = new DirectionExpression ();
					direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
					var argLocation = LocationsBag.GetLocations (arg);
					if (argLocation != null)
						direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword);
					direction.AddChild ((Expression)arg.Expr.Accept (this), InvocationExpression.Roles.Expression);
					return direction;
				}
				
				return (Expression)arg.Expr.Accept (this);
			}
コード例 #5
0
ファイル: CSharpParser.cs プロジェクト: rmattuschka/ILSpy
			IEnumerable<Attribute> GetAttributes (Attributes optAttributes)
			{
				if (optAttributes == null || optAttributes.Attrs == null)
					yield break;
				
				foreach (var attr in optAttributes.Attrs) {
					Attribute result = new Attribute ();
					result.Type = ConvertToType (attr.TypeNameExpression);
					
					if (attr.PosArguments != null) {
						foreach (var arg in attr.PosArguments) {
							result.AddChild ((Expression)arg.Expr.Accept (this), Attribute.Roles.Argument);
						}
					}
					if (attr.NamedArguments != null) { 
						foreach (NamedArgument na in attr.NamedArguments) {
							NamedArgumentExpression newArg = new NamedArgumentExpression ();
							newArg.AddChild (new Identifier (na.Name, Convert (na.Location)), NamedArgumentExpression.Roles.Identifier);
							
							var loc = LocationsBag.GetLocations (na);
							if (loc != null)
								newArg.AddChild (new CSharpTokenNode (Convert (loc [0]), 1), NamedArgumentExpression.Roles.Assign);
							newArg.AddChild ((Expression)na.Expr.Accept (this), NamedArgumentExpression.Roles.Expression);
							result.AddChild (newArg, Attribute.Roles.Argument);
						}
					}
					yield return result;
				}
			}