void TestParameters(DelegateDeclaration dd)
        {
            Assert.AreEqual(3, dd.Parameters.Count());

            Assert.AreEqual("a", ((ParameterDeclaration)dd.Parameters.ElementAt(0)).Name);
            //Assert.AreEqual("System.Int32", ((ParameterDeclaration)dd.Parameters.ElementAt(0)).TypeReference.Type);
            Assert.Ignore("check types"); // TODO
            Assert.AreEqual("secondParam", ((ParameterDeclaration)dd.Parameters.ElementAt(1)).Name);
            //Assert.AreEqual("System.Int32", ((ParameterDeclaration)dd.Parameters.ElementAt(1)).TypeReference.Type);

            Assert.AreEqual("lastParam", ((ParameterDeclaration)dd.Parameters.ElementAt(2)).Name);
            //Assert.AreEqual("MyObj", ((ParameterDeclaration)dd.Parameters.ElementAt(2)).TypeReference.Type);
        }
Beispiel #2
0
        void TestParameters(DelegateDeclaration dd)
        {
            Assert.AreEqual(3, dd.Parameters.Count);

            Assert.AreEqual("a", ((ParameterDeclarationExpression)dd.Parameters[0]).ParameterName);
            Assert.AreEqual("System.Int32", ((ParameterDeclarationExpression)dd.Parameters[0]).TypeReference.Type);

            Assert.AreEqual("secondParam", ((ParameterDeclarationExpression)dd.Parameters[1]).ParameterName);
            Assert.AreEqual("System.Int32", ((ParameterDeclarationExpression)dd.Parameters[1]).TypeReference.Type);

            Assert.AreEqual("lastParam", ((ParameterDeclarationExpression)dd.Parameters[2]).ParameterName);
            Assert.AreEqual("MyObj", ((ParameterDeclarationExpression)dd.Parameters[2]).TypeReference.Type);
        }
Beispiel #3
0
        /// <summary>
        ///     Adds the submitted delegates to the diagram.
        /// </summary>
        private void AddDelegate(DelegateDeclaration dd)
        {
            var delegateType = diagram.AddDelegate();

            delegateType.Name           = dd.Name;
            delegateType.AccessModifier = dd.Modifiers.ToNClass();
            delegateType.ReturnType     = dd.ReturnType.ToString();

            foreach (var ichParameter in dd.Parameters)
            {
                delegateType.AddParameter(ichParameter.ToString()); // To Check
            }
        }
		static DelegateDeclaration CreateType(RefactoringContext context, SimpleType simpleType)
		{
			var result = new DelegateDeclaration() {
				Name = simpleType.Identifier,
				Modifiers = ((EntityDeclaration)simpleType.Parent).Modifiers,
				ReturnType = new PrimitiveType("void"),
				Parameters = {
					new ParameterDeclaration(new PrimitiveType("object"), "sender"),
					new ParameterDeclaration(context.CreateShortType("System", "EventArgs"), "e")
				}
			};
			return result;
		}
Beispiel #5
0
        public void CSharpGenericDelegateDeclarationTest()
        {
            string program         = "public delegate T CreateObject<T>(int a, int secondParam, MyObj lastParam) where T : ICloneable;\n";
            DelegateDeclaration dd = ParseUtilCSharp.ParseGlobal <DelegateDeclaration>(program);

            Assert.AreEqual("CreateObject", dd.Name);
            Assert.AreEqual("T", dd.ReturnType.Type);
            TestParameters(dd);
            Assert.AreEqual(1, dd.Templates.Count);
            Assert.AreEqual("T", dd.Templates[0].Name);
            Assert.AreEqual(1, dd.Templates[0].Bases.Count);
            Assert.AreEqual("ICloneable", dd.Templates[0].Bases[0].Type);
        }
Beispiel #6
0
        public DelegateType(AbstractType ReturnType, DelegateDeclaration Declaration, IEnumerable <AbstractType> Parameters = null) : base(ReturnType, Declaration)
        {
            this.IsFunction = Declaration.IsFunction;

            if (Parameters is AbstractType[])
            {
                this.Parameters = (AbstractType[])Parameters;
            }
            else if (Parameters != null)
            {
                this.Parameters = Parameters.ToArray();
            }
        }
Beispiel #7
0
        // Build the arguments of the delegate declaration.
        public static void BuildArgument(IronyParser parser, DelegateDeclaration method, ParseTreeNode node)
        {
            if (node.Term.ToString() == "out_parameter")
            {
                var a = new DirectionedParameter(null, node.FindToken().Convert());
                switch (node.ChildNodes[0].ChildNodes[0].Term.ToString())
                {
                case "ref":
                    a.Direction = ParameterDirection.Ref;
                    break;

                case "out":
                    a.Direction = ParameterDirection.Out;
                    break;
                }
                a.TypeName = parser.CheckAlias(node.ChildNodes[1].FindTokenAndGetText());
                a.Name     = node.ChildNodes[2].FindTokenAndGetText();
                method.Parameters.Add(a);
            }
            else if (node.Term.ToString() == "array_parameter")
            {
                var a = new SimpleParameter(null, node.FindToken().Convert());
                a.TypeName = parser.CheckAlias(node.ChildNodes[0].FindTokenAndGetText()) + "[]";
                a.Name     = node.ChildNodes[3].FindTokenAndGetText();
                method.Parameters.Add(a);
            }
            else if (node.Term.ToString() == "generic_parameter")
            {
                var    a        = new SimpleParameter(null, node.FindToken().Convert());
                string typeName = node.ChildNodes[0].ChildNodes[0].FindTokenAndGetText() + "<";
                for (int i = 0; i < node.ChildNodes[0].ChildNodes[2].ChildNodes.Count; i++)
                {
                    typeName += parser.CheckAlias(node.ChildNodes[0].ChildNodes[2].ChildNodes[i].FindTokenAndGetText());
                    if (i < node.ChildNodes[0].ChildNodes[2].ChildNodes.Count - 1)
                    {
                        typeName += ",";
                    }
                }
                typeName  += ">";
                a.TypeName = typeName;
                a.Name     = node.ChildNodes[1].FindTokenAndGetText();
                method.Parameters.Add(a);
            }
            else
            {
                var a = new SimpleParameter(null, node.FindToken().Convert());
                a.TypeName = parser.CheckAlias(node.ChildNodes[0].FindTokenAndGetText());
                a.Name     = node.ChildNodes[1].FindTokenAndGetText();
                method.Parameters.Add(a);
            }
        }
Beispiel #8
0
            internal override bool CanMatch(AstNode node)
            {
                IdentifierExpression ident = node as IdentifierExpression;

                if (ident != null)
                {
                    return(searchTerm == null || ident.Identifier == searchTerm);
                }

                MemberReferenceExpression mre = node as MemberReferenceExpression;

                if (mre != null)
                {
                    return(searchTerm == null || mre.MemberName == searchTerm);
                }

                SimpleType st = node as SimpleType;

                if (st != null)
                {
                    return(searchTerm == null || st.Identifier == searchTerm);
                }

                MemberType mt = node as MemberType;

                if (mt != null)
                {
                    return(searchTerm == null || mt.MemberName == searchTerm);
                }

                if (searchTerm == null && node is PrimitiveType)
                {
                    return(true);
                }

                TypeDeclaration typeDecl = node as TypeDeclaration;

                if (typeDecl != null)
                {
                    return(searchTerm == null || typeDecl.Name == searchTerm);
                }

                DelegateDeclaration delegateDecl = node as DelegateDeclaration;

                if (delegateDecl != null)
                {
                    return(searchTerm == null || delegateDecl.Name == searchTerm);
                }

                return(false);
            }
        public override void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
        {
            ForceSpacesBefore(delegateDeclaration.LParToken, policy.SpaceBeforeDelegateDeclarationParentheses);
            if (delegateDeclaration.Parameters.Any()) {
                ForceSpacesAfter(delegateDeclaration.LParToken, policy.SpaceWithinDelegateDeclarationParentheses);
                ForceSpacesBefore(delegateDeclaration.RParToken, policy.SpaceWithinDelegateDeclarationParentheses);
            } else {
                ForceSpacesAfter(delegateDeclaration.LParToken, policy.SpaceBetweenEmptyDelegateDeclarationParentheses);
                ForceSpacesBefore(delegateDeclaration.RParToken, policy.SpaceBetweenEmptyDelegateDeclarationParentheses);
            }
            FormatCommas(delegateDeclaration, policy.SpaceBeforeDelegateDeclarationParameterComma, policy.SpaceAfterDelegateDeclarationParameterComma);

            base.VisitDelegateDeclaration(delegateDeclaration);
        }
        public void CSharpCodeGenerator_DelegateDeclaration()
        {
            var d = new DelegateDeclaration("Sample");

            d.ReturnType = typeof(void);
            d.Arguments.Add(new MethodArgumentDeclaration(typeof(string), "a"));
            d.Modifiers = Modifiers.Public;

            var generator = new CSharpCodeGenerator();
            var result    = generator.Write(d);

            Assert.That.StringEquals(@"public delegate void Sample(string a);
", result);
        }
Beispiel #11
0
        static DelegateDeclaration CreateType(RefactoringContext context, SimpleType simpleType)
        {
            var result = new DelegateDeclaration()
            {
                Name       = simpleType.Identifier,
                Modifiers  = ((EntityDeclaration)simpleType.Parent).Modifiers,
                ReturnType = new PrimitiveType("void"),
                Parameters =
                {
                    new ParameterDeclaration(new PrimitiveType("object"),      "sender"),
                    new ParameterDeclaration(context.CreateShortType("System", "EventArgs"), "e")
                }
            };

            return(result);
        }
		public override object VisitEventDeclaration(EventDeclaration eventDeclaration, object data)
		{
			if (!eventDeclaration.HasAddRegion && !eventDeclaration.HasRaiseRegion && !eventDeclaration.HasRemoveRegion) {
				if (eventDeclaration.TypeReference.IsNull) {
					DelegateDeclaration dd = new DelegateDeclaration(eventDeclaration.Modifier, null);
					dd.Name = eventDeclaration.Name + "EventHandler";
					dd.Parameters = eventDeclaration.Parameters;
					dd.ReturnType = new TypeReference("System.Void", true);
					dd.Parent = eventDeclaration.Parent;
					eventDeclaration.Parameters = null;
					InsertAfterSibling(eventDeclaration, dd);
					eventDeclaration.TypeReference = new TypeReference(dd.Name);
				}
			}
			return base.VisitEventDeclaration(eventDeclaration, data);
		}
Beispiel #13
0
        public override object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
        {
            ForceSpacesBefore(delegateDeclaration.LParToken, policy.BeforeDelegateDeclarationParentheses);
            if (delegateDeclaration.Parameters.Any())
            {
                ForceSpacesAfter(delegateDeclaration.LParToken, policy.WithinDelegateDeclarationParentheses);
                ForceSpacesBefore(delegateDeclaration.RParToken, policy.WithinDelegateDeclarationParentheses);
            }
            else
            {
                ForceSpacesAfter(delegateDeclaration.LParToken, policy.BetweenEmptyDelegateDeclarationParentheses);
                ForceSpacesBefore(delegateDeclaration.RParToken, policy.BetweenEmptyDelegateDeclarationParentheses);
            }
            FormatCommas(delegateDeclaration, policy.BeforeDelegateDeclarationParameterComma, policy.AfterDelegateDeclarationParameterComma);

            return(base.VisitDelegateDeclaration(delegateDeclaration, data));
        }
Beispiel #14
0
        public static TooltipInformation Generate(DelegateDeclaration dd, int currentParam = -1)
        {
            var sb = new StringBuilder("<i>(Delegate)</i> ");

            if (dd.ReturnType != null)
            {
                sb.Append(dd.ReturnType.ToString(true)).Append(' ');
            }

            if (dd.IsFunction)
            {
                sb.Append("function");
            }
            else
            {
                sb.Append("delegate");
            }

            sb.Append('(');
            if (dd.Parameters != null && dd.Parameters.Count != 0)
            {
                for (int i = 0; i < dd.Parameters.Count; i++)
                {
                    var p = dd.Parameters[i] as DNode;
                    if (i == currentParam)
                    {
                        sb.Append("<u>");
                        sb.Append(p.ToString(false));
                        sb.Append("</u>,");
                    }
                    else
                    {
                        sb.Append(p.ToString(false)).Append(',');
                    }
                }

                sb.Remove(sb.Length - 1, 1);
            }
            sb.Append(')');

            var tti = new TooltipInformation();

            tti.SignatureMarkup = sb.ToString();

            return(tti);
        }
Beispiel #15
0
        // Build a delegate declaration expression.
        public static void BuildDelegate(IronyParser parser, Root root, Expression parentExpression, ParseTreeNode currentNode)
        {
            var d = new DelegateDeclaration(parentExpression, currentNode.Token.Convert());

            parentExpression.ChildExpressions.Add(d);

            // Interpret the declaration modifiers.
            InterpretModifiers(root, d, currentNode.ChildNodes[0]);

            // Find the return type of the declaration: check for array and generic types differently.
            if (currentNode.ChildNodes[2].ChildNodes[0].ChildNodes[0].Term.ToString() == "array")
            {
                d.ReturnTypeName = parser.CheckAlias(currentNode.ChildNodes[2].ChildNodes[0].ChildNodes[0].FindTokenAndGetText()) + "[]";
            }
            else if (currentNode.ChildNodes[2].ChildNodes[0].ChildNodes[0].Term.ToString() == "generic_identifier")
            {
                string returnType = currentNode.ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[0].FindTokenAndGetText() + "<";
                for (int i = 0; i < currentNode.ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[2].ChildNodes.Count; i++)
                {
                    var genericNode = currentNode.ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[2].ChildNodes[i];
                    returnType += parser.CheckAlias(genericNode.FindTokenAndGetText());
                    if (i < currentNode.ChildNodes[2].ChildNodes[0].ChildNodes[0].ChildNodes[2].ChildNodes.Count - 1)
                    {
                        returnType += ",";
                    }
                }
                returnType      += ">";
                d.ReturnTypeName = returnType;
            }
            else
            {
                d.ReturnTypeName = parser.CheckAlias(currentNode.ChildNodes[2].ChildNodes[0].FindTokenAndGetText());
            }

            d.Name = currentNode.ChildNodes[2].ChildNodes[1].FindTokenAndGetText();

            // Build the arguments of the delegate declaration.
            if (currentNode.ChildNodes[3].ChildNodes.Count > 0)
            {
                foreach (var n in currentNode.ChildNodes[3].ChildNodes)
                {
                    BuildArgument(parser, d, n.ChildNodes[0]);
                }
            }
        }
Beispiel #16
0
        public UnifiedElement VisitDelegateDeclaration(
            DelegateDeclaration delegateDeclaration, object data)
        {
            var generics = delegateDeclaration.TypeParameters.AcceptVisitorAsTypeParams(this, data);

            if (generics.IsEmptyOrNull())
            {
                generics = null;
            }

            return(UnifiedDelegateDefinition.Create(
                       annotations: null,
                       modifiers: LookupModifiers(delegateDeclaration.Modifiers),
                       type: LookupType(delegateDeclaration.ReturnType),
                       genericParameters: generics,
                       name: delegateDeclaration.Name.ToVariableIdentifier(),
                       parameters: delegateDeclaration.Parameters.AcceptVisitorAsParams(this, data)));
        }
Beispiel #17
0
 public override object VisitEventDeclaration(EventDeclaration eventDeclaration, object data)
 {
     if (!eventDeclaration.HasAddRegion && !eventDeclaration.HasRaiseRegion && !eventDeclaration.HasRemoveRegion)
     {
         if (eventDeclaration.TypeReference.IsNull)
         {
             DelegateDeclaration dd = new DelegateDeclaration(eventDeclaration.Modifier, null);
             dd.Name       = eventDeclaration.Name + "EventHandler";
             dd.Parameters = eventDeclaration.Parameters;
             dd.ReturnType = new TypeReference("System.Void", true);
             dd.Parent     = eventDeclaration.Parent;
             eventDeclaration.Parameters = null;
             InsertAfterSibling(eventDeclaration, dd);
             eventDeclaration.TypeReference = new TypeReference(dd.Name);
         }
     }
     return(base.VisitEventDeclaration(eventDeclaration, data));
 }
Beispiel #18
0
 public object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
 {
     B.CallableDefinition cd = new B.CallableDefinition(GetLexicalInfo(delegateDeclaration));
     cd.Name = delegateDeclaration.Name;
     ConvertAttributes(delegateDeclaration.Attributes, cd.Attributes);
     cd.Modifiers = ConvertModifier(delegateDeclaration, B.TypeMemberModifiers.Private);
     ConvertParameters(delegateDeclaration.Parameters, cd.Parameters);
     cd.ReturnType = ConvertTypeReference(delegateDeclaration.ReturnType);
     if (currentType != null)
     {
         currentType.Members.Add(cd);
     }
     else
     {
         module.Members.Add(cd);
     }
     return(cd);
 }
Beispiel #19
0
    // ALL FUNCTIONS
    // Start is called before the first frame update
    void Start()
    {
        // get kernel id
        kernel        = compute.FindKernel("CreateSprite");
        normalKernel  = compute.FindKernel("CalcNormals");
        normalKernel5 = compute.FindKernel("CalcNormals5");
        blurKernel    = compute.FindKernel("GaussianBlur");

        // create textures
        result = new RenderTexture(pixHeight, pixWidth, 24);
        result.enableRandomWrite = true;
        result.Create();
        bumpMap = new RenderTexture(pixHeight, pixWidth, 24);
        bumpMap.enableRandomWrite = true;
        bumpMap.Create();
        smoothMap = new RenderTexture(pixHeight, pixWidth, 24);
        smoothMap.enableRandomWrite = true;
        smoothMap.Create();

        // create delegates (this is for passing functions through the gentex Function)
        DelegateDeclaration noiseCol = PerlinNoiseColour;
        DelegateDeclaration shapeCol = ShapeColour;

        // THIS SHIT CHOKES THE COMPUTER THE F**K OUT, NEED TO FIX
        // generate noise texture
        //noiseTex = new Texture2D(pixWidth * 2, pixHeight * 2);
        //noiseTex = GenTex(noiseTex, noiseCol);

        // generate basic shape
        //shapeTex = new Texture2D(pixWidth, pixHeight);
        //shapeTex = GenTex(shapeTex, shapeCol);

        // set textures in compute shader
        compute.SetTexture(kernel, "Result", result);
        compute.SetTexture(kernel, "Noise", noiseTex);
        compute.SetTexture(kernel, "Shape", shapeTex);

        // run compute shader
        compute.Dispatch(kernel, pixWidth / 8, pixHeight / 8, 1);

        // get renderer
        m_Renderer = GetComponent <Renderer>();
    }
        // The following conversions are implemented:
        //   Public Event EventName(param As String) -> automatic delegate declaration
        //   static variables inside methods become fields

        public override object VisitEventDeclaration(EventDeclaration eventDeclaration, object data)
        {
            if (!eventDeclaration.HasAddRegion && !eventDeclaration.HasRaiseRegion && !eventDeclaration.HasRemoveRegion)
            {
                if (eventDeclaration.TypeReference.IsNull)
                {
                    DelegateDeclaration dd = new DelegateDeclaration(eventDeclaration.Modifier, null);
                    dd.Name       = eventDeclaration.Name + "EventHandler";
                    dd.Parameters = eventDeclaration.Parameters;
                    dd.ReturnType = new TypeReference("System.Void");
                    dd.Parent     = eventDeclaration.Parent;
                    eventDeclaration.Parameters = null;
                    int index = eventDeclaration.Parent.Children.IndexOf(eventDeclaration);
                    // inserting before current position is not allowed in a Transformer
                    eventDeclaration.Parent.Children.Insert(index + 1, dd);
                    eventDeclaration.TypeReference = new TypeReference(dd.Name);
                }
            }
            return(base.VisitEventDeclaration(eventDeclaration, data));
        }
Beispiel #21
0
        public ITypeDeclaration VisitDelegateType(DelegateType t)
        {
            var dd = new DelegateDeclaration
            {
                ReturnType = AcceptType(t.ReturnType),
                IsFunction = t.IsFunction
            };

            if (t.Parameters != null)
            {
                foreach (var p in t.Parameters)
                {
                    dd.Parameters.Add(new DVariable {
                        Type = AcceptType(p)
                    });
                }
            }

            return(dd);
        }
        public virtual object Visit(DelegateDeclaration delegateDeclaration, object data)
        {
            Debug.Assert(delegateDeclaration != null);
            Debug.Assert(delegateDeclaration.Attributes != null);
            Debug.Assert(delegateDeclaration.Parameters != null);
            Debug.Assert(delegateDeclaration.ReturnType != null);

            foreach (AttributeSection section in delegateDeclaration.Attributes)
            {
                Debug.Assert(section != null);
                section.AcceptVisitor(this, data);
            }

            foreach (ParameterDeclarationExpression p in delegateDeclaration.Parameters)
            {
                Debug.Assert(p != null);
                p.AcceptVisitor(this, data);
            }
            return(delegateDeclaration.ReturnType.AcceptVisitor(this, data));
        }
Beispiel #23
0
        public static string GeneratePrototype(DelegateDeclaration dd, int currentParam = -1)
        {
            var sb = new StringBuilder("Delegate: ");

            if (dd.ReturnType != null)
            {
                sb.Append(dd.ReturnType.ToString(true)).Append(' ');
            }

            if (dd.IsFunction)
            {
                sb.Append("function");
            }
            else
            {
                sb.Append("delegate");
            }

            sb.Append('(');
            if (dd.Parameters != null && dd.Parameters.Count != 0)
            {
                for (int i = 0; i < dd.Parameters.Count; i++)
                {
                    var p = dd.Parameters[i] as DNode;
                    if (i == currentParam)
                    {
                        sb.Append(p.ToString(false)).Append(',');
                    }
                    else
                    {
                        sb.Append(p.ToString(false)).Append(',');
                    }
                }

                sb.Remove(sb.Length - 1, 1);
            }
            sb.Append(')');

            return(sb.ToString());
        }
Beispiel #24
0
    Texture2D GenTex(Texture2D tex, DelegateDeclaration handler)
    {
        Color[] colourMem  = new Color[tex.height * tex.width];
        int     noiseScale = 10;
        int     y          = 0;

        while (y < tex.height)
        {
            int x = 0;
            while (x < tex.width)
            {
                colourMem[FindIndex(x, y, tex.width)] = handler(x, y, tex.width, tex.height, noiseScale);
                x++;
            }
            y++;
        }

        // Copy the pixel data to the texture and load it into the GPU.
        tex.SetPixels(colourMem);
        tex.Apply();
        return(tex);
    }
Beispiel #25
0
        public static DelegateType Resolve(DelegateDeclaration dg, ResolutionContext ctxt)
        {
            var returnTypes = Resolve(dg.ReturnType, ctxt);

            ctxt.CheckForSingleResult(returnTypes, dg.ReturnType);

            if (returnTypes != null && returnTypes.Length != 0)
            {
                List <AbstractType> paramTypes = null;
                if (dg.Parameters != null &&
                    dg.Parameters.Count != 0)
                {
                    paramTypes = new List <AbstractType>();
                    foreach (var par in dg.Parameters)
                    {
                        paramTypes.Add(ResolveSingle(par.Type, ctxt));
                    }
                }
                return(new DelegateType(returnTypes[0], dg, paramTypes));
            }
            return(null);
        }
Beispiel #26
0
		public override IUnresolvedEntity VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
		{
			var td = currentTypeDefinition = CreateTypeDefinition(delegateDeclaration.Name);
			td.Kind = TypeKind.Delegate;
			td.Region = MakeRegion(delegateDeclaration);
			td.BaseTypes.Add(KnownTypeReference.MulticastDelegate);
			
			ApplyModifiers(td, delegateDeclaration.Modifiers);
			td.IsSealed = true; // delegates are implicitly sealed
			
			ConvertTypeParameters(td.TypeParameters, delegateDeclaration.TypeParameters, delegateDeclaration.Constraints, EntityType.TypeDefinition);
			
			ITypeReference returnType = delegateDeclaration.ReturnType.ToTypeReference();
			List<IUnresolvedParameter> parameters = new List<IUnresolvedParameter>();
			ConvertParameters(parameters, delegateDeclaration.Parameters);
			AddDefaultMethodsToDelegate(td, returnType, parameters);
			
			foreach (AttributeSection section in delegateDeclaration.Attributes) {
				if (section.AttributeTarget == "return") {
					List<IUnresolvedAttribute> returnTypeAttributes = new List<IUnresolvedAttribute>();
					ConvertAttributes(returnTypeAttributes, section);
					IUnresolvedMethod invokeMethod = (IUnresolvedMethod)td.Members.Single(m => m.Name == "Invoke");
					IUnresolvedMethod endInvokeMethod = (IUnresolvedMethod)td.Members.Single(m => m.Name == "EndInvoke");
					foreach (IUnresolvedAttribute attr in returnTypeAttributes) {
						invokeMethod.ReturnTypeAttributes.Add(attr);
						endInvokeMethod.ReturnTypeAttributes.Add(attr);
					}
				} else {
					ConvertAttributes(td.Attributes, section);
				}
			}
			
			currentTypeDefinition = (CSharpUnresolvedTypeDefinition)currentTypeDefinition.DeclaringTypeDefinition;
			if (interningProvider != null) {
				td.ApplyInterningProvider(interningProvider);
			}
			return td;
		}
        DelegateDeclaration ConvertDelegate(IMethod invokeMethod, Modifiers modifiers)
        {
            ITypeDefinition d = invokeMethod.DeclaringTypeDefinition;

            DelegateDeclaration decl = new DelegateDeclaration();

            decl.Modifiers  = modifiers & ~Modifiers.Sealed;
            decl.ReturnType = ConvertType(invokeMethod.ReturnType);
            decl.Name       = d.Name;

            if (this.ShowTypeParameters)
            {
                foreach (ITypeParameter tp in d.TypeParameters)
                {
                    decl.TypeParameters.Add(ConvertTypeParameter(tp));
                }
            }

            foreach (IParameter p in invokeMethod.Parameters)
            {
                decl.Parameters.Add(ConvertParameter(p));
            }

            if (this.ShowTypeParameters && this.ShowTypeParameterConstraints)
            {
                foreach (ITypeParameter tp in d.TypeParameters)
                {
                    var constraint = ConvertTypeParameterConstraint(tp);
                    if (constraint != null)
                    {
                        decl.Constraints.Add(constraint);
                    }
                }
            }
            return(decl);
        }
Beispiel #28
0
			public override void Visit(Mono.CSharp.Delegate d)
			{
				var newDelegate = new DelegateDeclaration();
				var location = LocationsBag.GetMemberLocation(d);
				AddAttributeSection(newDelegate, d);
				AddModifiers(newDelegate, location);
				if (location != null && location.Count > 0) {
					newDelegate.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.DelegateKeyword), Roles.DelegateKeyword);
				}
				if (d.ReturnType != null)
					newDelegate.AddChild(ConvertToType(d.ReturnType), Roles.Type);
				newDelegate.AddChild(Identifier.Create(d.MemberName.Name, Convert(d.MemberName.Location)), Roles.Identifier);
				AddTypeParameters(newDelegate, d.MemberName);
				
				if (location != null && location.Count > 1)
					newDelegate.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.LPar), Roles.LPar);
				AddParameter(newDelegate, d.Parameters);
				
				if (location != null && location.Count > 2) {
					newDelegate.AddChild(new CSharpTokenNode(Convert(location [2]), Roles.RPar), Roles.RPar);
				}
				AddConstraints(newDelegate, d.CurrentTypeParameters);
				if (location != null && location.Count > 3) {
					newDelegate.AddChild(new CSharpTokenNode(Convert(location [3]), Roles.Semicolon), Roles.Semicolon);
				}
				AddType(newDelegate);
			}
Beispiel #29
0
			public override void Visit (Mono.CSharp.Delegate d)
			{
				DelegateDeclaration newDelegate = new DelegateDeclaration ();
				var location = LocationsBag.GetMemberLocation (d);
				
				AddModifiers (newDelegate, location);
				if (location != null)
					newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.TypeKeyword);
				newDelegate.AddChild ((INode)d.ReturnType.Accept (this), AbstractNode.Roles.ReturnType);
				newDelegate.AddChild (new Identifier (d.Name, Convert (d.MemberName.Location)), AbstractNode.Roles.Identifier);
				if (d.MemberName.TypeArguments != null)  {
					var typeArgLocation = LocationsBag.GetLocations (d.MemberName);
					if (typeArgLocation != null)
						newDelegate.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
//					AddTypeArguments (newDelegate, typeArgLocation, d.MemberName.TypeArguments);
					if (typeArgLocation != null)
						newDelegate.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
					AddConstraints (newDelegate, d);
				}
				if (location != null) {
					newDelegate.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DelegateDeclaration.Roles.LPar);
					newDelegate.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DelegateDeclaration.Roles.RPar);
					newDelegate.AddChild (new CSharpTokenNode (Convert (location[3]), 1), DelegateDeclaration.Roles.Semicolon);
				}
				AddType (newDelegate);
			}
Beispiel #30
0
			public override void Visit (Mono.CSharp.Delegate d)
			{
				DelegateDeclaration newDelegate = new DelegateDeclaration ();
				var location = LocationsBag.GetMemberLocation (d);
				AddAttributeSection (newDelegate, d);
				AddModifiers (newDelegate, location);
				if (location != null)
					newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.Roles.Keyword);
				newDelegate.AddChild (ConvertToType (d.ReturnType), AstNode.Roles.Type);
				newDelegate.AddChild (Identifier.Create (d.MemberName.Name, Convert (d.MemberName.Location)), AstNode.Roles.Identifier);
				if (d.MemberName.TypeArguments != null)  {
					AddTypeParameters (newDelegate, d.MemberName.TypeArguments);
				}
				if (location != null)
					newDelegate.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DelegateDeclaration.Roles.LPar);
				AddParameter (newDelegate, d.Parameters);
				
				if (location != null) {
					newDelegate.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DelegateDeclaration.Roles.RPar);
				}
				AddConstraints (newDelegate, d);
				if (location != null) {
					newDelegate.AddChild (new CSharpTokenNode (Convert (location[3]), 1), DelegateDeclaration.Roles.Semicolon);
				}
				AddType (newDelegate);
			}
		void HandleVisitorDelegateDeclarationVisited (DelegateDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckDelegate (node, data))
					return;
			}
		}
Beispiel #32
0
		public DelegateType(AbstractType ReturnType,DelegateDeclaration Declaration, IEnumerable<AbstractType> Parameters = null) : base(ReturnType, Declaration)
		{
			this.IsFunction = Declaration.IsFunction;

			if (Parameters is AbstractType[])
				this.Parameters = (AbstractType[])Parameters;
			else if(Parameters!=null)
				this.Parameters = Parameters.ToArray();
		}
Beispiel #33
0
        private void Process_Delegate_Declaration(DelegateDeclaration node)
        {
            if (node == null) throw new ArgumentNullException("node");

            var dele = new Delegate(controller);
            dele.Name = node.Name.Text;
            dele.Modifiers.AddRange(FormatterUtility.GetModifiersFromEnum(node.Modifiers));
            dele.ReturnType = FormatterUtility.GetDataTypeFromTypeReference(node.ReturnType, document, controller);

            foreach (ParameterDeclaration paramNode in node.Parameters)
            {
                Parameter param = GetParameterFromParameterDeclaration(document, controller, paramNode);
                param.ParentObject = dele;
                dele.Parameters.Add(param);
            }

            SetupBaseConstruct(node, dele);
        }
Beispiel #34
0
		public virtual void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
		{
			StartNode(delegateDeclaration);
			WriteAttributes(delegateDeclaration.Attributes);
			WriteModifiers(delegateDeclaration.ModifierTokens);
			WriteKeyword(Roles.DelegateKeyword);
			delegateDeclaration.ReturnType.AcceptVisitor(this);
			Space();
			WriteIdentifier(delegateDeclaration.NameToken);
			WriteTypeParameters(delegateDeclaration.TypeParameters, CodeBracesRangeFlags.AngleBrackets);
			Space(policy.SpaceBeforeDelegateDeclarationParentheses);
			WriteCommaSeparatedListInParenthesis(delegateDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses, CodeBracesRangeFlags.Parentheses);
			int count = 0;
			foreach (Constraint constraint in delegateDeclaration.Constraints) {
				if (count-- <= 0) {
					cancellationToken.ThrowIfCancellationRequested();
					count = CANCEL_CHECK_LOOP_COUNT;
				}
				constraint.AcceptVisitor(this);
			}
			SaveDeclarationOffset();
			Semicolon();
			EndNode(delegateDeclaration);
		}
 public virtual void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(delegateDeclaration);
     }
 }
Beispiel #36
0
	void NonModuleDeclaration(
#line  424 "VBNET.ATG" 
ModifierList m, List<AttributeSection> attributes) {

#line  426 "VBNET.ATG" 
		TypeReference typeRef = null;
		List<TypeReference> baseInterfaces = null;
		
		switch (la.kind) {
		case 71: {

#line  429 "VBNET.ATG" 
			m.Check(Modifiers.Classes); 
			lexer.NextToken();

#line  432 "VBNET.ATG" 
			TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
			newType.StartLocation = t.Location;
			compilationUnit.AddChild(newType);
			compilationUnit.BlockStart(newType);
			
			newType.Type       = ClassType.Class;
			
			Identifier();

#line  439 "VBNET.ATG" 
			newType.Name = t.val; 
			TypeParameterList(
#line  440 "VBNET.ATG" 
newType.Templates);
			EndOfStmt();

#line  442 "VBNET.ATG" 
			newType.BodyStartLocation = t.Location; 
			if (la.kind == 127) {
				ClassBaseType(
#line  443 "VBNET.ATG" 
out typeRef);

#line  443 "VBNET.ATG" 
				SafeAdd(newType, newType.BaseTypes, typeRef); 
			}
			while (la.kind == 123) {
				TypeImplementsClause(
#line  444 "VBNET.ATG" 
out baseInterfaces);

#line  444 "VBNET.ATG" 
				newType.BaseTypes.AddRange(baseInterfaces); 
			}
			ClassBody(
#line  445 "VBNET.ATG" 
newType);
			Expect(100);
			Expect(71);

#line  446 "VBNET.ATG" 
			newType.EndLocation = t.EndLocation; 
			EndOfStmt();

#line  449 "VBNET.ATG" 
			compilationUnit.BlockEnd();
			
			break;
		}
		case 141: {
			lexer.NextToken();

#line  453 "VBNET.ATG" 
			m.Check(Modifiers.VBModules);
			TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
			compilationUnit.AddChild(newType);
			compilationUnit.BlockStart(newType);
			newType.StartLocation = m.GetDeclarationLocation(t.Location);
			newType.Type = ClassType.Module;
			
			Identifier();

#line  460 "VBNET.ATG" 
			newType.Name = t.val; 
			EndOfStmt();

#line  462 "VBNET.ATG" 
			newType.BodyStartLocation = t.Location; 
			ModuleBody(
#line  463 "VBNET.ATG" 
newType);

#line  465 "VBNET.ATG" 
			compilationUnit.BlockEnd();
			
			break;
		}
		case 194: {
			lexer.NextToken();

#line  469 "VBNET.ATG" 
			m.Check(Modifiers.VBStructures);
			TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
			compilationUnit.AddChild(newType);
			compilationUnit.BlockStart(newType);
			newType.StartLocation = m.GetDeclarationLocation(t.Location);
			newType.Type = ClassType.Struct;
			
			Identifier();

#line  476 "VBNET.ATG" 
			newType.Name = t.val; 
			TypeParameterList(
#line  477 "VBNET.ATG" 
newType.Templates);
			EndOfStmt();

#line  479 "VBNET.ATG" 
			newType.BodyStartLocation = t.Location; 
			while (la.kind == 123) {
				TypeImplementsClause(
#line  480 "VBNET.ATG" 
out baseInterfaces);

#line  480 "VBNET.ATG" 
				newType.BaseTypes.AddRange(baseInterfaces);
			}
			StructureBody(
#line  481 "VBNET.ATG" 
newType);

#line  483 "VBNET.ATG" 
			compilationUnit.BlockEnd();
			
			break;
		}
		case 102: {
			lexer.NextToken();

#line  488 "VBNET.ATG" 
			m.Check(Modifiers.VBEnums);
			TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
			newType.StartLocation = m.GetDeclarationLocation(t.Location);
			compilationUnit.AddChild(newType);
			compilationUnit.BlockStart(newType);
			
			newType.Type = ClassType.Enum;
			
			Identifier();

#line  496 "VBNET.ATG" 
			newType.Name = t.val; 
			if (la.kind == 50) {
				lexer.NextToken();
				NonArrayTypeName(
#line  497 "VBNET.ATG" 
out typeRef, false);

#line  497 "VBNET.ATG" 
				SafeAdd(newType, newType.BaseTypes, typeRef); 
			}
			EndOfStmt();

#line  499 "VBNET.ATG" 
			newType.BodyStartLocation = t.Location; 
			EnumBody(
#line  500 "VBNET.ATG" 
newType);

#line  502 "VBNET.ATG" 
			compilationUnit.BlockEnd();
			
			break;
		}
		case 129: {
			lexer.NextToken();

#line  507 "VBNET.ATG" 
			m.Check(Modifiers.VBInterfacs);
			TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
			newType.StartLocation = m.GetDeclarationLocation(t.Location);
			compilationUnit.AddChild(newType);
			compilationUnit.BlockStart(newType);
			newType.Type = ClassType.Interface;
			
			Identifier();

#line  514 "VBNET.ATG" 
			newType.Name = t.val; 
			TypeParameterList(
#line  515 "VBNET.ATG" 
newType.Templates);
			EndOfStmt();

#line  517 "VBNET.ATG" 
			newType.BodyStartLocation = t.Location; 
			while (la.kind == 127) {
				InterfaceBase(
#line  518 "VBNET.ATG" 
out baseInterfaces);

#line  518 "VBNET.ATG" 
				newType.BaseTypes.AddRange(baseInterfaces); 
			}
			InterfaceBody(
#line  519 "VBNET.ATG" 
newType);

#line  521 "VBNET.ATG" 
			compilationUnit.BlockEnd();
			
			break;
		}
		case 90: {
			lexer.NextToken();

#line  526 "VBNET.ATG" 
			m.Check(Modifiers.VBDelegates);
			DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes);
			delegateDeclr.ReturnType = new TypeReference("System.Void", true);
			delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location);
			List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
			
			if (la.kind == 195) {
				lexer.NextToken();
				Identifier();

#line  533 "VBNET.ATG" 
				delegateDeclr.Name = t.val; 
				TypeParameterList(
#line  534 "VBNET.ATG" 
delegateDeclr.Templates);
				if (la.kind == 25) {
					lexer.NextToken();
					if (StartOf(4)) {
						FormalParameterList(
#line  535 "VBNET.ATG" 
p);
					}
					Expect(26);

#line  535 "VBNET.ATG" 
					delegateDeclr.Parameters = p; 
				}
			} else if (la.kind == 114) {
				lexer.NextToken();
				Identifier();

#line  537 "VBNET.ATG" 
				delegateDeclr.Name = t.val; 
				TypeParameterList(
#line  538 "VBNET.ATG" 
delegateDeclr.Templates);
				if (la.kind == 25) {
					lexer.NextToken();
					if (StartOf(4)) {
						FormalParameterList(
#line  539 "VBNET.ATG" 
p);
					}
					Expect(26);

#line  539 "VBNET.ATG" 
					delegateDeclr.Parameters = p; 
				}
				if (la.kind == 50) {
					lexer.NextToken();

#line  540 "VBNET.ATG" 
					TypeReference type; 
					TypeName(
#line  540 "VBNET.ATG" 
out type);

#line  540 "VBNET.ATG" 
					delegateDeclr.ReturnType = type; 
				}
			} else SynErr(231);

#line  542 "VBNET.ATG" 
			delegateDeclr.EndLocation = t.EndLocation; 
			EndOfStmt();

#line  545 "VBNET.ATG" 
			compilationUnit.AddChild(delegateDeclr);
			
			break;
		}
		default: SynErr(232); break;
		}
	}
        DelegateDeclaration ConvertDelegate(IMethod invokeMethod, Modifiers modifiers)
        {
            ITypeDefinition d = invokeMethod.DeclaringTypeDefinition;

            DelegateDeclaration decl = new DelegateDeclaration();
            decl.Modifiers = modifiers & ~Modifiers.Sealed;
            if (ShowAttributes) {
                decl.Attributes.AddRange (d.Attributes.Select (a => new AttributeSection (ConvertAttribute (a))));
                decl.Attributes.AddRange (invokeMethod.ReturnTypeAttributes.Select ((a) => new AttributeSection (ConvertAttribute (a)) {
                    AttributeTarget = "return"
                }));
            }
            decl.ReturnType = ConvertType(invokeMethod.ReturnType);
            decl.Name = d.Name;

            int outerTypeParameterCount = (d.DeclaringTypeDefinition == null) ? 0 : d.DeclaringTypeDefinition.TypeParameterCount;

            if (this.ShowTypeParameters) {
                foreach (ITypeParameter tp in d.TypeParameters.Skip(outerTypeParameterCount)) {
                    decl.TypeParameters.Add(ConvertTypeParameter(tp));
                }
            }

            foreach (IParameter p in invokeMethod.Parameters) {
                decl.Parameters.Add(ConvertParameter(p));
            }

            if (this.ShowTypeParameters && this.ShowTypeParameterConstraints) {
                foreach (ITypeParameter tp in d.TypeParameters.Skip(outerTypeParameterCount)) {
                    var constraint = ConvertTypeParameterConstraint(tp);
                    if (constraint != null)
                        decl.Constraints.Add(constraint);
                }
            }
            return decl;
        }
            public override object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
            {
                UnlockWith(delegateDeclaration);

                return base.VisitDelegateDeclaration(delegateDeclaration, data);
            }
		public static DelegateType Resolve(DelegateDeclaration dg, ResolutionContext ctxt)
		{
			var returnTypes = Resolve(dg.ReturnType, ctxt);

			ctxt.CheckForSingleResult(returnTypes, dg.ReturnType);

			if (returnTypes != null && returnTypes.Length != 0)
			{
				List<AbstractType> paramTypes=null;
				if(dg.Parameters!=null && 
				   dg.Parameters.Count != 0)
				{	
					paramTypes = new List<AbstractType>();
					foreach(var par in dg.Parameters)
						paramTypes.Add(ResolveSingle(par.Type, ctxt));
				}
				return new DelegateType(returnTypes[0], dg, paramTypes);
			}
			return null;
		}
Beispiel #40
0
        public void VisitDelegateDeclaration(DelegateDeclaration declaration)
        {
            Formatter.StartNode(declaration);

            if (declaration.CustomAttributeSections.Count > 0)
            {
                WriteNodes(declaration.CustomAttributeSections, true);
                Formatter.WriteLine();
            }

            if (declaration.ModifierElements.Count > 0)
            {
                WriteSpaceSeparatedNodes(declaration.ModifierElements);
                Formatter.WriteSpace();
            }

            Formatter.WriteKeyword("delegate");
            Formatter.WriteSpace();
            declaration.DelegateType.AcceptVisitor(this);
            Formatter.WriteSpace();
            declaration.Identifier.AcceptVisitor(this);
            WriteTypeParametersOrArguments(declaration.TypeParameters);
            Formatter.WriteToken("(");
            WriteCommaSeparatedNodes(declaration.Parameters);
            Formatter.WriteToken(")");
            WriteSemicolon();

            Formatter.EndNode();
        }
Beispiel #41
0
		public void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
		{
			StartNode(delegateDeclaration);
			WriteAttributes(delegateDeclaration.Attributes);
			WriteModifiers(delegateDeclaration.ModifierTokens);
			WriteKeyword(Roles.DelegateKeyword);
			delegateDeclaration.ReturnType.AcceptVisitor(this);
			Space();
			delegateDeclaration.NameToken.AcceptVisitor(this);
			WriteTypeParameters(delegateDeclaration.TypeParameters);
			Space(policy.SpaceBeforeDelegateDeclarationParentheses);
			WriteCommaSeparatedListInParenthesis(delegateDeclaration.Parameters, policy.SpaceWithinMethodDeclarationParentheses);
			foreach (Constraint constraint in delegateDeclaration.Constraints) {
				constraint.AcceptVisitor(this);
			}
			Semicolon();
			EndNode(delegateDeclaration);
		}
Beispiel #42
0
	void TypeDecl(
#line  359 "cs.ATG" 
ModifierList m, List<AttributeSection> attributes) {

#line  361 "cs.ATG" 
		TypeReference type;
		List<TypeReference> names;
		List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
		string name;
		List<TemplateDefinition> templates;
		
		if (la.kind == 59) {

#line  367 "cs.ATG" 
			m.Check(Modifiers.Classes); 
			lexer.NextToken();

#line  368 "cs.ATG" 
			TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
			templates = newType.Templates;
			compilationUnit.AddChild(newType);
			compilationUnit.BlockStart(newType);
			newType.StartLocation = m.GetDeclarationLocation(t.Location);
			
			newType.Type = Types.Class;
			
			Identifier();

#line  376 "cs.ATG" 
			newType.Name = t.val; 
			if (la.kind == 23) {
				TypeParameterList(
#line  379 "cs.ATG" 
templates);
			}
			if (la.kind == 9) {
				ClassBase(
#line  381 "cs.ATG" 
out names);

#line  381 "cs.ATG" 
				newType.BaseTypes = names; 
			}
			while (la.kind == 127) {
				TypeParameterConstraintsClause(
#line  384 "cs.ATG" 
templates);
			}

#line  386 "cs.ATG" 
			newType.BodyStartLocation = t.EndLocation; 
			Expect(16);
			ClassBody();
			Expect(17);
			if (la.kind == 11) {
				lexer.NextToken();
			}

#line  390 "cs.ATG" 
			newType.EndLocation = t.Location; 
			compilationUnit.BlockEnd();
			
		} else if (StartOf(9)) {

#line  393 "cs.ATG" 
			m.Check(Modifiers.StructsInterfacesEnumsDelegates); 
			if (la.kind == 109) {
				lexer.NextToken();

#line  394 "cs.ATG" 
				TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
				templates = newType.Templates;
				newType.StartLocation = m.GetDeclarationLocation(t.Location);
				compilationUnit.AddChild(newType);
				compilationUnit.BlockStart(newType);
				newType.Type = Types.Struct; 
				
				Identifier();

#line  401 "cs.ATG" 
				newType.Name = t.val; 
				if (la.kind == 23) {
					TypeParameterList(
#line  404 "cs.ATG" 
templates);
				}
				if (la.kind == 9) {
					StructInterfaces(
#line  406 "cs.ATG" 
out names);

#line  406 "cs.ATG" 
					newType.BaseTypes = names; 
				}
				while (la.kind == 127) {
					TypeParameterConstraintsClause(
#line  409 "cs.ATG" 
templates);
				}

#line  412 "cs.ATG" 
				newType.BodyStartLocation = t.EndLocation; 
				StructBody();
				if (la.kind == 11) {
					lexer.NextToken();
				}

#line  414 "cs.ATG" 
				newType.EndLocation = t.Location; 
				compilationUnit.BlockEnd();
				
			} else if (la.kind == 83) {
				lexer.NextToken();

#line  418 "cs.ATG" 
				TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
				templates = newType.Templates;
				compilationUnit.AddChild(newType);
				compilationUnit.BlockStart(newType);
				newType.StartLocation = m.GetDeclarationLocation(t.Location);
				newType.Type = Types.Interface;
				
				Identifier();

#line  425 "cs.ATG" 
				newType.Name = t.val; 
				if (la.kind == 23) {
					TypeParameterList(
#line  428 "cs.ATG" 
templates);
				}
				if (la.kind == 9) {
					InterfaceBase(
#line  430 "cs.ATG" 
out names);

#line  430 "cs.ATG" 
					newType.BaseTypes = names; 
				}
				while (la.kind == 127) {
					TypeParameterConstraintsClause(
#line  433 "cs.ATG" 
templates);
				}

#line  435 "cs.ATG" 
				newType.BodyStartLocation = t.EndLocation; 
				InterfaceBody();
				if (la.kind == 11) {
					lexer.NextToken();
				}

#line  437 "cs.ATG" 
				newType.EndLocation = t.Location; 
				compilationUnit.BlockEnd();
				
			} else if (la.kind == 68) {
				lexer.NextToken();

#line  441 "cs.ATG" 
				TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes);
				compilationUnit.AddChild(newType);
				compilationUnit.BlockStart(newType);
				newType.StartLocation = m.GetDeclarationLocation(t.Location);
				newType.Type = Types.Enum;
				
				Identifier();

#line  447 "cs.ATG" 
				newType.Name = t.val; 
				if (la.kind == 9) {
					lexer.NextToken();
					IntegralType(
#line  448 "cs.ATG" 
out name);

#line  448 "cs.ATG" 
					newType.BaseTypes.Add(new TypeReference(name, true)); 
				}

#line  450 "cs.ATG" 
				newType.BodyStartLocation = t.EndLocation; 
				EnumBody();
				if (la.kind == 11) {
					lexer.NextToken();
				}

#line  452 "cs.ATG" 
				newType.EndLocation = t.Location; 
				compilationUnit.BlockEnd();
				
			} else {
				lexer.NextToken();

#line  456 "cs.ATG" 
				DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes);
				templates = delegateDeclr.Templates;
				delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location);
				
				if (
#line  460 "cs.ATG" 
NotVoidPointer()) {
					Expect(123);

#line  460 "cs.ATG" 
					delegateDeclr.ReturnType = new TypeReference("System.Void", true); 
				} else if (StartOf(10)) {
					Type(
#line  461 "cs.ATG" 
out type);

#line  461 "cs.ATG" 
					delegateDeclr.ReturnType = type; 
				} else SynErr(152);
				Identifier();

#line  463 "cs.ATG" 
				delegateDeclr.Name = t.val; 
				if (la.kind == 23) {
					TypeParameterList(
#line  466 "cs.ATG" 
templates);
				}
				Expect(20);
				if (StartOf(11)) {
					FormalParameterList(
#line  468 "cs.ATG" 
p);

#line  468 "cs.ATG" 
					delegateDeclr.Parameters = p; 
				}
				Expect(21);
				while (la.kind == 127) {
					TypeParameterConstraintsClause(
#line  472 "cs.ATG" 
templates);
				}
				Expect(11);

#line  474 "cs.ATG" 
				delegateDeclr.EndLocation = t.Location;
				compilationUnit.AddChild(delegateDeclr);
				
			}
		} else SynErr(153);
	}
			public override void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
			{
				base.VisitDelegateDeclaration(delegateDeclaration);
				CheckName(delegateDeclaration, AffectedEntity.Delegate, delegateDeclaration.NameToken, GetAccessibiltiy(delegateDeclaration, delegateDeclaration.Parent is TypeDeclaration ? Modifiers.Private : Modifiers.Internal));
			}
		public override object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
		{
			// fix default inner type visibility
			if (currentType != null && (delegateDeclaration.Modifier & Modifiers.Visibility) == 0)
				delegateDeclaration.Modifier |= Modifiers.Private;
			
			return base.VisitDelegateDeclaration(delegateDeclaration, data);
		}
 void TestDelegateDeclaration(DelegateDeclaration dd)
 {
     Assert.AreEqual("System.Void", dd.ReturnType.SystemType);
     Assert.AreEqual("MyDelegate", dd.Name);
 }
		public virtual object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) {
			Debug.Assert((delegateDeclaration != null));
			Debug.Assert((delegateDeclaration.Attributes != null));
			Debug.Assert((delegateDeclaration.ReturnType != null));
			Debug.Assert((delegateDeclaration.Parameters != null));
			Debug.Assert((delegateDeclaration.Templates != null));
			foreach (AttributeSection o in delegateDeclaration.Attributes) {
				Debug.Assert(o != null);
				o.AcceptVisitor(this, data);
			}
			delegateDeclaration.ReturnType.AcceptVisitor(this, data);
			foreach (ParameterDeclarationExpression o in delegateDeclaration.Parameters) {
				Debug.Assert(o != null);
				o.AcceptVisitor(this, data);
			}
			foreach (TemplateDefinition o in delegateDeclaration.Templates) {
				Debug.Assert(o != null);
				o.AcceptVisitor(this, data);
			}
			return null;
		}
        DelegateDeclaration ConvertDelegate(IMethod invokeMethod, Modifiers modifiers)
        {
            ITypeDefinition d = invokeMethod.DeclaringTypeDefinition;

            DelegateDeclaration decl = new DelegateDeclaration();
            decl.Modifiers = modifiers & ~Modifiers.Sealed;
            decl.ReturnType = ConvertType(invokeMethod.ReturnType);
            decl.Name = d.Name;

            if (this.ShowTypeParameters) {
                foreach (ITypeParameter tp in d.TypeParameters) {
                    decl.TypeParameters.Add(ConvertTypeParameter(tp));
                }
            }

            foreach (IParameter p in invokeMethod.Parameters) {
                decl.Parameters.Add(ConvertParameter(p));
            }

            if (this.ShowTypeParameters && this.ShowTypeParameterConstraints) {
                foreach (ITypeParameter tp in d.TypeParameters) {
                    var constraint = ConvertTypeParameterConstraint(tp);
                    if (constraint != null)
                        decl.Constraints.Add(constraint);
                }
            }
            return decl;
        }
 public virtual object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
 {
     throw new global::System.NotImplementedException("DelegateDeclaration");
 }
		public virtual void Visit(DelegateDeclaration td)
		{
			VisitInner(td);
			// ReturnType == InnerDeclaration

			if (td.Modifiers != null && td.Modifiers.Length != 0)
				foreach (var attr in td.Modifiers)
					attr.Accept(this);

			foreach (var p in td.Parameters)
				p.Accept(this);
		}
        bool HandleDecl(TemplateTypeParameter par, DelegateDeclaration d, DelegateType dr)
        {
            // Delegate literals or other expressions are not allowed
            if (dr == null || dr.IsFunctionLiteral)
            {
                return(false);
            }

            var dr_decl = (DelegateDeclaration)dr.DeclarationOrExpressionBase;

            // Compare return types
            if (d.IsFunction == dr_decl.IsFunction &&
                dr.ReturnType != null &&
                HandleDecl(par, d.ReturnType, dr.ReturnType))
            {
                // If no delegate args expected, it's valid
                if ((d.Parameters == null || d.Parameters.Count == 0) &&
                    dr_decl.Parameters == null || dr_decl.Parameters.Count == 0)
                {
                    return(true);
                }

                // If parameter counts unequal, return false
                else if (d.Parameters == null || dr_decl.Parameters == null || d.Parameters.Count != dr_decl.Parameters.Count)
                {
                    return(false);
                }

                // Compare & Evaluate each expected with given parameter
                var dr_paramEnum = dr_decl.Parameters.GetEnumerator();
                foreach (var p in d.Parameters)
                {
                    // Compare attributes with each other
                    if (p is DNode)
                    {
                        if (!(dr_paramEnum.Current is DNode))
                        {
                            return(false);
                        }

                        var dn     = (DNode)p;
                        var dn_arg = (DNode)dr_paramEnum.Current;

                        if ((dn.Attributes == null || dn.Attributes.Count == 0) &&
                            (dn_arg.Attributes == null || dn_arg.Attributes.Count == 0))
                        {
                            return(true);
                        }

                        else if (dn.Attributes == null || dn_arg.Attributes == null ||
                                 dn.Attributes.Count != dn_arg.Attributes.Count)
                        {
                            return(false);
                        }

                        foreach (var attr in dn.Attributes)
                        {
                            if (!dn_arg.ContainsAttribute(attr))
                            {
                                return(false);
                            }
                        }
                    }

                    // Compare types
                    if (p.Type != null && dr_paramEnum.MoveNext() && dr_paramEnum.Current.Type != null)
                    {
                        var dr_resolvedParamType = TypeDeclarationResolver.ResolveSingle(dr_paramEnum.Current.Type, ctxt);

                        if (dr_resolvedParamType == null ||
                            !HandleDecl(par, p.Type, dr_resolvedParamType))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(false);
        }
Beispiel #51
0
        public void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
        {
            JsonObject declaration = new JsonObject();
            declaration.Comment = "VisitDelegateDeclaration";
            AddAttributes(declaration, delegateDeclaration);
            AddModifiers(declaration, delegateDeclaration);
            AddReturnType(declaration, delegateDeclaration);
            AddKeyword(declaration, Roles.DelegateKeyword);
            declaration.AddJsonValue("identifier", GetIdentifier(delegateDeclaration.NameToken));
            declaration.AddJsonValue("type-parameters", GetTypeParameters(delegateDeclaration.TypeParameters));
            declaration.AddJsonValue("parameters", GetCommaSeparatedList(delegateDeclaration.Parameters));

            JsonArray contraintList = new JsonArray();
            foreach (Constraint constraint in delegateDeclaration.Constraints)
            {
                constraint.AcceptVisitor(this);
                var temp = Pop();
                if (temp != null)
                {
                    contraintList.AddJsonValue(temp);
                }
            }
            if (contraintList.Count == 0)
            {
                contraintList = null;
            }
            declaration.AddJsonValue("constraint", contraintList);

            Push(declaration);
        }
 public override object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data)
 {
     HandleTypeDeclaration(delegateDeclaration);
     return(null);
 }
 public override void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
 {
 }
		public override void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
		{
			FormatAttributedNode(delegateDeclaration);
			
			ForceSpacesBefore(delegateDeclaration.LParToken, policy.SpaceBeforeDelegateDeclarationParentheses);
			if (delegateDeclaration.Parameters.Any()) {
				ForceSpacesAfter(delegateDeclaration.LParToken, policy.SpaceWithinDelegateDeclarationParentheses);
				ForceSpacesBefore(delegateDeclaration.RParToken, policy.SpaceWithinDelegateDeclarationParentheses);
			} else {
				ForceSpacesAfter(delegateDeclaration.LParToken, policy.SpaceBetweenEmptyDelegateDeclarationParentheses);
				ForceSpacesBefore(delegateDeclaration.RParToken, policy.SpaceBetweenEmptyDelegateDeclarationParentheses);
			}
			FormatCommas(delegateDeclaration, policy.SpaceBeforeDelegateDeclarationParameterComma, policy.SpaceAfterDelegateDeclarationParameterComma);

			if (delegateDeclaration.NextSibling is TypeDeclaration || delegateDeclaration.NextSibling is DelegateDeclaration) {
				EnsureBlankLinesAfter(delegateDeclaration, policy.BlankLinesBetweenTypes);
			} else if (IsMember(delegateDeclaration.NextSibling)) {
				EnsureBlankLinesAfter(delegateDeclaration, policy.BlankLinesBetweenMembers);
			}

			base.VisitDelegateDeclaration(delegateDeclaration);
		}
		public virtual void VisitDelegateDeclaration (DelegateDeclaration delegateDeclaration)
		{
			VisitChildren (delegateDeclaration);
		}
Beispiel #56
0
		/// <summary>
		/// Add some syntax possibilities here
		/// int (x);
		/// int(*foo);
		/// This way of declaring function pointers is deprecated
		/// </summary>
		void OldCStyleFunctionPointer(DNode ret, bool IsParam)
		{
			Step();
			//SynErr(OpenParenthesis,"C-style function pointers are deprecated. Use the function() syntax instead."); // Only deprecated in D2
			var cd = new DelegateDeclaration() as ITypeDeclaration;
			LastParsedObject = cd;
			ret.Type = cd;
			var deleg = cd as DelegateDeclaration;

			/*			 
			 * Parse all basictype2's that are following the initial '('
			 */
			while (IsBasicType2())
			{
				var ttd = BasicType2();

				if (deleg.ReturnType == null) 
					deleg.ReturnType = ttd;
				else
				{
					if(ttd!=null)
						ttd.InnerDeclaration = deleg.ReturnType;
					deleg.ReturnType = ttd;
				}
			}

			/*			
			 * Here can be an identifier with some optional DeclaratorSuffixes
			 */
			if (laKind != (CloseParenthesis))
			{
				if (IsParam && laKind != (Identifier))
				{
					/* If this Declarator is a parameter of a function, don't expect anything here
					 * except a '*' that means that here's an anonymous function pointer
					 */
					if (t.Kind != (Times))
						SynErr(Times);
				}
				else
				{
					if(Expect(Identifier))
						ret.Name = t.Value;

					/*					
					 * Just here suffixes can follow!
					 */
					if (laKind != (CloseParenthesis))
					{
						DeclaratorSuffixes(ret);
					}
				}
			}
			ret.Type = cd;
			Expect(CloseParenthesis);
		}
 public override void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
 {
     base.VisitDelegateDeclaration(delegateDeclaration);
     CheckName(delegateDeclaration, AffectedEntity.Delegate, delegateDeclaration.NameToken, GetAccessibiltiy(delegateDeclaration, delegateDeclaration.Parent is TypeDeclaration ? Modifiers.Private : Modifiers.Internal));
 }
Beispiel #58
0
 public override void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
 {
     VisitXmlChildren(delegateDeclaration);
 }
 public override void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration)
 {
 }
Beispiel #60
0
		ITypeDeclaration BasicType2()
		{
			// *
			if (laKind == (Times))
			{
				Step();
				return new PointerDecl() { Location=t.Location, EndLocation=t.EndLocation };
			}

			// [ ... ]
			else if (laKind == (OpenSquareBracket))
			{
				var startLoc = la.Location;
				Step();
				// [ ]
				if (laKind == (CloseSquareBracket)) 
				{ 
					Step();
					return new ArrayDecl() { Location=startLoc, EndLocation=t.EndLocation }; 
				}

				ITypeDeclaration cd = null;

				// [ Type ]
				Lexer.PushLookAheadBackup();
				bool weaktype = AllowWeakTypeParsing;
				AllowWeakTypeParsing = true;

				var keyType = Type();

				AllowWeakTypeParsing = weaktype;

				if (keyType != null && laKind == CloseSquareBracket && !(keyType is IdentifierDeclaration))
				{
					//HACK: Both new int[size_t] as well as new int[someConstNumber] are legal. So better treat them as expressions.
					cd = new ArrayDecl() { KeyType = keyType, ClampsEmpty = false, Location = startLoc };
					Lexer.PopLookAheadBackup();
				}
				else
				{
					Lexer.RestoreLookAheadBackup();

					var fromExpression = AssignExpression();

					// [ AssignExpression .. AssignExpression ]
					if (laKind == DoubleDot)
					{
						Step();
						cd = new ArrayDecl() {
							Location=startLoc,
							ClampsEmpty=false,
							KeyType=null,
							KeyExpression= new PostfixExpression_Slice() { 
								FromExpression=fromExpression,
								ToExpression=AssignExpression()}};
					}
					else
						cd = new ArrayDecl() { KeyType=null, KeyExpression=fromExpression,ClampsEmpty=false,Location=startLoc };
				}

				if ((AllowWeakTypeParsing && laKind != CloseSquareBracket) || IsEOF)
					return null;

				Expect(CloseSquareBracket);
				if(cd!=null)
					cd.EndLocation = t.EndLocation;
				return cd;
			}

			// delegate | function
			else if (laKind == (Delegate) || laKind == (Function))
			{
				Step();
				var dd = new DelegateDeclaration() { Location=t.Location};
				dd.IsFunction = t.Kind == Function;

				var lpo = LastParsedObject;

				if (AllowWeakTypeParsing && laKind != OpenParenthesis)
					return null;

				dd.Parameters = Parameters(null);

				if (!IsEOF)
					LastParsedObject = lpo;

				var attributes = new List<DAttribute>();
				FunctionAttributes(ref attributes);
				dd.Modifiers= attributes.Count > 0 ? attributes.ToArray() : null;

				dd.EndLocation = t.EndLocation;
				return dd;
			}
			else
				SynErr(Identifier);
			return null;
		}