コード例 #1
0
        public virtual object VisitOperatorDeclaration(OperatorNode operatorDeclaration, object data)
        {
            stackMap.Push(operatorDeclaration);
            operatorDeclaration.Attributes.AcceptVisitor(this, data);



            if (operatorDeclaration.Param1 != null)
            {
                operatorDeclaration.Param1.AcceptVisitor(this, data);
            }

            if (operatorDeclaration.Param2 != null)
            {
                operatorDeclaration.Param2.AcceptVisitor(this, data);
            }

            operatorDeclaration.Type.AcceptVisitor(this, data);

            operatorDeclaration.Statements.AcceptVisitor(this, data);

            stackMap.Pop();
            return(null);
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: mintberry/stackrecaller
		private void ParseOperatorDecl(IType type)						
		{			
			OperatorNode node;

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

            if ( type != null //implicit/explicit operator 
                && type is TypeNode
                && iteratorsClass.Contains(((TypeNode)type).GenericIndependentIdentifier))
            {
                node = new OperatorNode(true, curtok);
                curIterator = node;
            }
            else
            {
                node = new OperatorNode(false, curtok);
            }

            curOperator = node;

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

			uint mask = ~(uint)Modifier.OperatorMods;
			if (((uint)curmods & mask) != (uint)Modifier.Empty)
				ReportError("operator 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 operator is declared in an unsafe type ?
            node.IsUnsafe = isUnsafe > 0;

            ClassNode cl = typeStack.Peek();
            cl.Operators.Add(node);

            CheckStaticClass(cl, node.Modifiers, true);
            
			if (type == null && curtok.ID == TokenID.Explicit)
			{
				Advance();
				node.IsExplicit = true;
				AssertAndAdvance(TokenID.Operator);
				type = ParseType();
			}
			else if (type == null && curtok.ID == TokenID.Implicit)
			{
				Advance();
				node.IsImplicit = true;
				AssertAndAdvance(TokenID.Operator);
				type = ParseType();
			}
			else
			{
				AssertAndAdvance(TokenID.Operator);
				node.Operator = curtok.ID;
				Advance();
			}
            node.Type = type;

			NodeCollection<ParamDeclNode> paramList = ParseParamList();
			if (paramList.Count == 0 || paramList.Count > 2)
			{
				ReportError("Operator declarations must only have one or two parameters.");
			}
			node.Param1 = paramList[0];
			if (paramList.Count == 2)
			{
				node.Param2 = paramList[1];
			}
			ParseBlock(node.Statements);

            if (node.IsIterator)
            {
                if ((node.Param1.Modifiers & (Modifier.Ref | Modifier.Out)) != Modifier.Empty)
                {
                    ReportError("Iterators can not have nor 'ref' nor 'out' parameter.");
                }

                if ((node.Param2.Modifiers & (Modifier.Ref | Modifier.Out)) != Modifier.Empty)
                {
                    ReportError("Iterators can not have nor 'ref' nor 'out' parameter.");
                }
            }

            curIterator = null;
            curOperator = null;

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

            // Doubt this will be in use.
            if (node.IsImplicit)
                this.nameTable.AddIdentifier(new OperatorName(TokenID.Implicit, this.currentContext));
            else if (node.IsExplicit)
                this.nameTable.AddIdentifier(new OperatorName(TokenID.Explicit, this.currentContext));
            else
                this.nameTable.AddIdentifier(new OperatorName(node.Operator, this.currentContext));
		}
コード例 #3
0
        public virtual object VisitOperatorDeclaration(OperatorNode operatorDeclaration, object data)
        {
            stackMap.Push(operatorDeclaration);
            operatorDeclaration.Attributes.AcceptVisitor(this, data);



            if (operatorDeclaration.Param1 != null)
            {
                operatorDeclaration.Param1.AcceptVisitor(this, data);
            }

            if (operatorDeclaration.Param2 != null)
            {
                operatorDeclaration.Param2.AcceptVisitor(this, data);
            }

            operatorDeclaration.Type.AcceptVisitor(this, data);

             operatorDeclaration.Statements.AcceptVisitor(this, data);

             stackMap.Pop();
             return null;

        }