Exemplo n.º 1
0
			void AddConstraints(AstNode parent, TypeParameters d)
			{
				if (d == null)
					return;
				for (int i = 0; i < d.Count; i++) {
					var typeParameter = d [i];
					if (typeParameter == null)
						continue;
					var c = typeParameter.Constraints;
					if (c == null)
						continue;
					var location = LocationsBag.GetLocations(c);
					var constraint = new Constraint();
					constraint.AddChild(new CSharpTokenNode(Convert(c.Location), Roles.WhereKeyword), Roles.WhereKeyword);
					constraint.AddChild(new SimpleType(Identifier.Create(c.TypeParameter.Value, Convert(c.TypeParameter.Location))), Roles.ConstraintTypeParameter);
					if (location != null)
						constraint.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.Colon), Roles.Colon);
					var commaLocs = LocationsBag.GetLocations(c.ConstraintExpressions);
					int curComma = 0;
					if (c.ConstraintExpressions != null) {
						foreach (var expr in c.ConstraintExpressions) {
							constraint.AddChild(ConvertToType(expr), Roles.BaseType);
							var sce = expr as SpecialContraintExpr;
							if (sce != null) {
								switch (sce.Constraint) {
									case SpecialConstraint.Class:
										break;
									case SpecialConstraint.Struct:
										break;
									case SpecialConstraint.Constructor:
										var bl = LocationsBag.GetLocations(expr);
										if (bl != null) {
											constraint.AddChild(new CSharpTokenNode(Convert(bl [0]), Roles.LPar), Roles.LPar);
											constraint.AddChild(new CSharpTokenNode(Convert(bl [1]), Roles.RPar), Roles.RPar);
										}
										break;
								}
							}

							if (commaLocs != null && curComma < commaLocs.Count)
								constraint.AddChild(new CSharpTokenNode(Convert(commaLocs [curComma++]), Roles.Comma), Roles.Comma);
						}
					}
					
					// We need to sort the constraints by position; as they might be in a different order than the type parameters
					AstNode prevSibling = parent.LastChild;
					while (prevSibling.StartLocation > constraint.StartLocation && prevSibling.PrevSibling != null)
						prevSibling = prevSibling.PrevSibling;
					parent.InsertChildAfter(prevSibling, constraint, Roles.Constraint);
				}
			}
Exemplo n.º 2
0
			void AddConstraints (AstNode parent, DeclSpace d)
			{
				if (d == null || d.Constraints == null)
					return;
				for (int i = 0; i < d.PlainConstraints.Count; i++) {
					Constraints c = d.PlainConstraints [i];
					var location = LocationsBag.GetLocations (c);
					var constraint = new Constraint ();
					constraint.AddChild (new CSharpTokenNode (Convert (c.Location), "where".Length), InvocationExpression.Roles.Keyword);
					constraint.AddChild (new SimpleType (Identifier.Create (c.TypeParameter.Value, Convert (c.TypeParameter.Location))), Constraint.TypeParameterRole);
					if (location != null)
						constraint.AddChild (new CSharpTokenNode (Convert (location [0]), 1), Constraint.ColonRole);
					var commaLocs = LocationsBag.GetLocations (c.ConstraintExpressions);
					int curComma = 0;
					foreach (var expr in c.ConstraintExpressions) {
						constraint.AddChild (ConvertToType (expr), Constraint.BaseTypeRole);
						if (commaLocs != null && curComma < commaLocs.Count)
							constraint.AddChild (new CSharpTokenNode (Convert (commaLocs[curComma++]), 1), InvocationExpression.Roles.Comma);
					}
					parent.AddChild (constraint, AstNode.Roles.Constraint);
				}
			}
Exemplo n.º 3
0
            void AddConstraints(AstNode parent, TypeParameters d)
            {
                if (d == null)
                    return;
                for (int i = d.Count - 1; i >= 0; i--) {
                    var typeParameter = d [i];
                    if (typeParameter == null)
                        continue;
                    var c = typeParameter.Constraints;
                    if (c == null)
                        continue;
                    var location = LocationsBag.GetLocations (c);
                    var constraint = new Constraint ();
                    constraint.AddChild (new CSharpTokenNode (Convert (c.Location), Roles.WhereKeyword), Roles.WhereKeyword);
                    constraint.AddChild (new SimpleType (Identifier.Create (c.TypeParameter.Value, Convert (c.TypeParameter.Location))), Roles.ConstraintTypeParameter);
                    if (location != null)
                        constraint.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.Colon), Roles.Colon);
                    var commaLocs = LocationsBag.GetLocations (c.ConstraintExpressions);
                    int curComma = 0;
                    if (c.ConstraintExpressions != null) {
                        foreach (var expr in c.ConstraintExpressions) {
                            constraint.AddChild (ConvertToType (expr), Roles.BaseType);
                            if (commaLocs != null && curComma < commaLocs.Count)
                                constraint.AddChild (new CSharpTokenNode (Convert (commaLocs [curComma++]), Roles.Comma), Roles.Comma);
                        }
                    }

                    parent.AddChild (constraint, Roles.Constraint);
                }
            }
Exemplo n.º 4
0
			void AddConstraints (AstNode parent, DeclSpace d)
			{
				if (d == null || d.Constraints == null)
					return;
				for (int i = 0; i < d.Constraints.Count; i++) {
					Constraints c = d.Constraints[i];
					var location = LocationsBag.GetLocations (c);
					var constraint = new Constraint ();
					constraint.AddChild (new CSharpTokenNode (Convert (location[0]), "where".Length), InvocationExpression.Roles.Keyword);
					constraint.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
					constraint.AddChild (new CSharpTokenNode (Convert (location[1]), 1), Constraint.ColonRole);
					foreach (var expr in c.ConstraintExpressions)
						constraint.AddChild (ConvertToType (expr), Constraint.BaseTypeRole);
					parent.AddChild (constraint, AstNode.Roles.Constraint);
				}
			}