Beispiel #1
0
		private void ParseEvent()											
		{
			uint mask = ~(uint)Modifier.EventMods;
			if (((uint)curmods & mask) != (uint)Modifier.Empty)
				ReportError("Event contains illegal modifiers");

            EventNode node = new EventNode(curtok);

            ClassNode cl = typeStack.Peek();

			cl.Events.Add(node);

			if (curAttributes.Count > 0)
			{
				node.Attributes = curAttributes;
				curAttributes = new NodeCollection<AttributeNode>();
			}

			node.Modifiers = curmods;
			curmods = Modifier.Empty;

            if ((node.Modifiers & Modifier.Unsafe) != Modifier.Empty)
            {
                //unsafe modifier -> unsafe type.
                isUnsafe++;
                node.IsUnsafeDeclared = true;
            }

            //the event is declared in an unsafe type ?
            node.IsUnsafe = isUnsafe > 0;

            CheckStaticClass(cl, node.Modifiers, true); ;

			Advance(); // advance over event keyword

			node.Type = ParseType();

			if (curtok.ID != TokenID.Ident)
				ReportError("Expected event member name.");

			while (curtok.ID == TokenID.Ident)
			{
                node.Names.Add(ParseQualifiedIdentifier(true, false, true));
			}

            //TODO: Omer - Add all of the events in that line to the name table once Robin fixes the code.

            switch (curtok.ID)
            {
                case TokenID.Semi:
                    AssertAndAdvance(TokenID.Semi);
                    break;
                case TokenID.Equal:
                    Advance();
                    node.Value = ParseConstExpr();
                    AssertAndAdvance(TokenID.Semi);
                    break;
                case TokenID.LCurly:
                    Advance(); // over lcurly

                    ParsePossibleAttributes(false);

                    if (curtok.ID != TokenID.Ident)
                    {
                        ReportError("Event accessor requires add or remove clause.");
                    }

                    string curAccessor = strings[curtok.Data];
                    Advance(); // over ident
                    if (curAccessor == "add")
                    {
                        node.AddBlock = new AccessorNode(false, curtok);
                        node.AddBlock.Kind = "add";
                        node.AddBlock.IsUnsafe = isUnsafe > 0;
                        ApplyAttributes( node.AddBlock );
                        ParseBlock( node.AddBlock.StatementBlock );

                        ParsePossibleAttributes(false);
                        if (curtok.ID == TokenID.Ident && strings[curtok.Data] == "remove")
                        {
                            node.RemoveBlock = new AccessorNode( false, curtok );
                            node.RemoveBlock.IsUnsafe = isUnsafe > 0;
                            node.RemoveBlock.Kind = "remove";
                            ApplyAttributes( node.RemoveBlock );
                            Advance(); // over ident
                            ParseBlock( node.RemoveBlock.StatementBlock );
                        }
                        else
                        {
                            ReportError("Event accessor expected remove clause.");
                        }
                    }
                    else if (curAccessor == "remove")
                    {
                        node.RemoveBlock = new AccessorNode(false, curtok);
                        node.RemoveBlock.IsUnsafe = isUnsafe > 0;
                        node.RemoveBlock.Kind = "remove";
                        ApplyAttributes( node.RemoveBlock );
                        ParseBlock( node.RemoveBlock.StatementBlock );

                        ParsePossibleAttributes(false);
                        if (curtok.ID == TokenID.Ident && strings[curtok.Data] == "add")
                        {
                            node.AddBlock = new AccessorNode(false, curtok);
                            node.AddBlock.IsUnsafe = isUnsafe > 0;
                            node.AddBlock.Kind = "remove";
                            Advance(); // over ident
                            ApplyAttributes(node.AddBlock);
                            ParseBlock(node.AddBlock.StatementBlock);
                        }
                        else
                        {
                            ReportError("Event accessor expected add clause.");
                        }
                    }
                    else
                    {
                        ReportError("Event accessor requires add or remove clause.");
                    }

                    AssertAndAdvance(TokenID.RCurly);

                    break;
            }

            if ((node.Modifiers & Modifier.Unsafe) != Modifier.Empty)
            {
                //unsafe modifier -> unsafe type.
                isUnsafe--;
            }


		}
        public virtual object VisitEventDeclaration(EventNode eventDeclaration, object data)
        {
            stackMap.Push(eventDeclaration);
            eventDeclaration.Attributes.AcceptVisitor(this, data);

            if (eventDeclaration.AddBlock != null)
            {
                eventDeclaration.AddBlock.AcceptVisitor(this, data);
            }

            if (eventDeclaration.RemoveBlock != null)
            {
                eventDeclaration.RemoveBlock.AcceptVisitor(this, data);
            }

            eventDeclaration.Type.AcceptVisitor(this, data);

            if (eventDeclaration.Value != null)
            {
                eventDeclaration.Value.AcceptVisitor(this, data);
            }

            stackMap.Pop();
            return null;

        }