Ejemplo n.º 1
0
		private void ParseConst()											
		{
			uint mask = ~(uint)Modifier.ConstantMods;
			if (((uint)curmods & mask) != (uint)Modifier.Empty)
				ReportError("const declaration contains illegal modifiers");

            ConstantNode node = new ConstantNode(curtok);

            ClassNode cl = typeStack.Count == 0 ? null : typeStack.Peek();
            cl.Constants.Add(node); // TODO: If cl is null, then this will throw an exception... Better throw a specialized one.

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

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

            if (cl != null)
            {
                CheckStaticClass(cl, node.Modifiers, false);
            }

			Advance(); // advance over const keyword

			node.Type = ParseType();

			bool hasEqual = false;
            QualifiedIdentifierExpression name = ParseQualifiedIdentifier(false, false, true);
            node.Names.Add(name);
			
            if (curtok.ID == TokenID.Equal)
			{
				Advance();
				hasEqual = true;
			}

            this.nameTable.AddIdentifier(new FieldName(name.QualifiedIdentifier,
                ToVisibilityRestriction(node.Modifiers),
                Scope.Static, 
                this.currentContext));

			while (curtok.ID == TokenID.Comma)
			{
				Advance();

                name = ParseQualifiedIdentifier(false, false, true);
                node.Names.Add(name);
				
                if (curtok.ID == TokenID.Equal)
				{
					Advance();
					hasEqual = true;
				}
				else
				{
					hasEqual = false;
				}

                // TODO: Robin - make sure when you fix the constants that this is still relevant.
                this.nameTable.AddIdentifier(new FieldName(name.QualifiedIdentifier,
                    ToVisibilityRestriction(node.Modifiers),
                    Scope.Static, 
                    this.currentContext));
			}

			if (hasEqual)
			{
				node.Value = ParseConstExpr();
			}

			AssertAndAdvance(TokenID.Semi);
		}
Ejemplo n.º 2
0
        public virtual object VisitConstantNode(ConstantNode constantNode, object data)
        {
            stackMap.Push(constantNode);
            constantNode.Attributes.AcceptVisitor( this, data );
            constantNode.Type.AcceptVisitor( this, data );
            constantNode.Value.AcceptVisitor( this, data);
            stackMap.Pop();

            return null;
        }