Exemple #1
0
        public virtual object VisitIndexerDeclaration(IndexerNode indexerDeclaration, object data)
        {
            stackMap.Push(indexerDeclaration);
            indexerDeclaration.Attributes.AcceptVisitor(this, data);

            indexerDeclaration.Params.AcceptVisitor(this, data);

            indexerDeclaration.Type.AcceptVisitor(this, data);

            if (indexerDeclaration.Getter != null)
            {
                indexerDeclaration.Getter.AcceptVisitor(this, data);
            }

            if (indexerDeclaration.Setter != null)
            {
                indexerDeclaration.Setter.AcceptVisitor(this, data);
            }

            if (indexerDeclaration.InterfaceType != null)
            {
                indexerDeclaration.InterfaceType.AcceptVisitor(this, data);
            }

            stackMap.Pop();
            return(null);
        }
Exemple #2
0
		private void ParseIndexer(IType type, QualifiedIdentifierExpression interfaceType)
		{
			IndexerNode node = new IndexerNode(curtok);
			ClassNode cl = typeStack.Peek();
            cl.Indexers.Add(node);

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

			uint mask = ~(uint)Modifier.IndexerMods;
			if (((uint)curmods & mask) != (uint)Modifier.Empty)
				ReportError("indexer declaration contains illegal modifiers");


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

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

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

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

			node.Type = type;
			if (interfaceType != null)
			{
                node.InterfaceType = new TypeNode(interfaceType );
			}

			AssertAndAdvance(TokenID.This);
			node.Params = ParseParamList(TokenID.LBracket, TokenID.RBracket);

			// parse accessor part
			AssertAndAdvance(TokenID.LCurly);

            ParseModifiers();

			if (curtok.ID != TokenID.Ident)
			{
				RecoverFromError("At least one get or set required in accessor", curtok.ID);
			}
			bool parsedGet = false;
			if (strings[curtok.Data] == "get")
			{
				node.Getter = ParseAccessor(type);
				parsedGet = true;
			}

            ParseModifiers();

			if (curtok.ID == TokenID.Ident && strings[curtok.Data] == "set")
			{
				node.Setter = ParseAccessor(type);
			}

            ParseModifiers();
			// get might follow set
			if (!parsedGet && curtok.ID == TokenID.Ident && strings[curtok.Data] == "get")
			{
				node.Getter = ParseAccessor(type);
			}

            if (node.Setter != null
                && node.Getter != null)
            {
                if (node.Getter.Modifiers != Modifier.Empty
                        && node.Setter.Modifiers != Modifier.Empty)
                {
                    ReportError("Modifiers is permitted only for one of the acessors.");
                }
            }
            else
            {
                if (node.Setter == null && node.Getter.Modifiers != Modifier.Empty
                    || node.Getter == null && node.Setter.Modifiers != Modifier.Empty)
                {
                   ReportError("Accessor modifier is authorized only if the 'get' and the 'set' are declared.");
                }

            }

            switch (node.Modifiers)
            {
                case Modifier.Public:
                    break;
                case (Modifier.Protected | Modifier.Internal):
                    if ( node.Getter != null
                        && node.Getter.Modifiers != Modifier.Empty
                        && (node.Getter.Modifiers != Modifier.Protected
                                || node.Getter.Modifiers != Modifier.Private
                                || node.Getter.Modifiers != Modifier.Internal
                            )
                        )
                    {
                        ReportError("The property is protected internal, so the accessor can be only protected, private or internal.");
                    }

                    if (node.Setter != null
                        && node.Setter.Modifiers != Modifier.Empty
                        && (node.Setter.Modifiers != Modifier.Protected
                                || node.Setter.Modifiers != Modifier.Private
                                || node.Setter.Modifiers != Modifier.Internal
                            )
                        )
                    {
                        ReportError("The property is protected internal, so the accessor can be only protected, private or internal.");
                    }
                    break;
                case Modifier.Protected:
                case Modifier.Internal:
                    if (node.Getter != null
                        && node.Getter.Modifiers != Modifier.Empty
                        && node.Getter.Modifiers != Modifier.Private)
                    {
                        ReportError("The property is protected or internal, so the accessor can be only private.");
                    }

                    if (node.Setter != null
                        && node.Setter.Modifiers != Modifier.Empty
                        && node.Setter.Modifiers != Modifier.Private)
                    {
                        ReportError("The property is protected or internal, so the accessor can be only private.");
                    }
                    break;
                case Modifier.Private:
                    if (node.Getter != null
                        && node.Getter.Modifiers != Modifier.Empty)
                    {
                        ReportError("The property is private or internal, so the accessor can not have any modifier.");
                    }

                    if (node.Setter != null
                        && node.Setter.Modifiers != Modifier.Empty)
                    {
                        ReportError("The property is private or internal, so the accessor can not have any modifier.");
                    }

                    break;
            }

			AssertAndAdvance(TokenID.RCurly);

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

            #region Save name in the name table
            if (node.Getter != null)
            {
                if (node.Setter != null)
                {
                    if (node.Getter.Modifiers != Modifier.Empty)
                    {
                        this.nameTable.AddIdentifier(new IndexerName(
                            ToVisibilityRestriction(node.Setter.Modifiers),
                            ToVisibilityRestriction(node.Modifiers),
                            ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                            PropertyAccessors.Both,
                            this.currentContext));
                    }
                    else if (node.Setter.Modifiers != Modifier.Empty)
                    {
                        this.nameTable.AddIdentifier(new IndexerName(
                            ToVisibilityRestriction(node.Modifiers),
                            ToVisibilityRestriction(node.Setter.Modifiers),
                            ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                            PropertyAccessors.Both,
                            this.currentContext));
                    }
                    else
                    {
                        this.nameTable.AddIdentifier(new IndexerName(
                            ToVisibilityRestriction(node.Modifiers),
                            ToVisibilityRestriction(node.Modifiers),
                            ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                            PropertyAccessors.Both,
                            this.currentContext));
                    }
                }
                else
                {
                    this.nameTable.AddIdentifier(new IndexerName(
                        ToVisibilityRestriction(node.Modifiers),
                        NameVisibilityRestriction.Self,
                        ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                        PropertyAccessors.Get,
                        this.currentContext));
                }
            }
            else
            {
                this.nameTable.AddIdentifier(new IndexerName(
                    NameVisibilityRestriction.Self,
                    ToVisibilityRestriction(node.Modifiers),
                    ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                    PropertyAccessors.Set,
                    this.currentContext));
            }
            #endregion
		}
        public virtual object VisitIndexerDeclaration(IndexerNode indexerDeclaration, object data)
        {
            stackMap.Push(indexerDeclaration);
            indexerDeclaration.Attributes.AcceptVisitor(this, data);

            indexerDeclaration.Params.AcceptVisitor(this, data);

            indexerDeclaration.Type.AcceptVisitor(this, data);

            if (indexerDeclaration.Getter != null)
            {
                indexerDeclaration.Getter.AcceptVisitor(this, data);
            }

            if (indexerDeclaration.Setter != null)
            {
                indexerDeclaration.Setter.AcceptVisitor(this, data);
            }

            if (indexerDeclaration.InterfaceType != null)
            {
                indexerDeclaration.InterfaceType.AcceptVisitor(this, data);
            }

            stackMap.Pop();
            return null;

        }