Esempio n. 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"> type of the method</param>
        /// <param name="name"> name in qualified form ( if it is an explicit interface declaration) </param>
		private void ParseMethod(IType type, QualifiedIdentifierExpression name)	
		{
			uint mask = ~(uint)Modifier.MethodMods;
			if (((uint)curmods & mask) != (uint)Modifier.Empty)
				ReportError("method declaration contains illegal modifiers");

            MethodNode node;

            //we check the return type of the method.
            // -> it dertimes if the method is an iterator.

            if ( type is TypeNode
                    && iteratorsClass.Contains(((TypeNode)type).GenericIndependentIdentifier))
            {
                node = new MethodNode(true, curtok);
                curIterator = node;
            }
            else
            {
                node = new MethodNode(false, curtok);
            }

            curMethod = node;

			ClassNode cl = typeStack.Peek();
            cl.Methods.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 method is declared in an unsafe context ?
            node.IsUnsafe = isUnsafe > 0;

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

			node.Type = type;
            QualifiedIdentifierExpression methName = new QualifiedIdentifierExpression(name.RelatedToken);
            methName.Expressions.Add(name);
			node.Names.Add(methName);

            if (methName.IsGeneric)
            {
                //move generic from identifier to method
                node.Generic = methName.Generic;
                methName.Generic = null;
            }

            ParsePossibleTypeParameterNode(true, true, false);
            //if generic applies type parameter collection to the node
            ApplyTypeParameters(node);

			// starts at LParen
			node.Params = ParseParamList();

            ParsePossibleTypeParameterConstraintNode(node);
            ApplyTypeParameterConstraints(node);

			ParseBlock(node.StatementBlock);

            //we parse all parameter, if only one is ref or out, we raise an exception
            if (node.IsIterator)
            {
                foreach (ParamDeclNode param in node.Params)
                {
                    if ((param.Modifiers & (Modifier.Ref | Modifier.Out)) != Modifier.Empty)
                    {
                        ReportError("Iterators can not have nor 'ref' nor 'out' parameter.");
                        break;
                    }
                }
            }

            curMethod = null;
            curIterator = null;

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

            this.nameTable.AddIdentifier(new MethodName(name.QualifiedIdentifier,
                ToVisibilityRestriction(node.Modifiers),
                ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                this.currentContext));
		}
Esempio n. 2
0
        public virtual object VisitMethodDeclaration(MethodNode methodDeclaration, object data)
        {
            stackMap.Push(methodDeclaration);
            methodDeclaration.Attributes.AcceptVisitor(this, data);

            methodDeclaration.Params.AcceptVisitor(this, data);

            if (methodDeclaration.Generic != null) 
            {
                methodDeclaration.Generic.AcceptVisitor(this, data);
            }
            
            methodDeclaration.Type.AcceptVisitor(this, data);

            methodDeclaration.StatementBlock.AcceptVisitor(this, data);

            stackMap.Pop();
            return null;

        }