예제 #1
0
        public virtual object VisitStructNode(StructNode structNode, object data)
        {
            stackMap.Push(structNode);

            structNode.Attributes.AcceptVisitor(this, data);

            structNode.BaseClasses.AcceptVisitor(this, data);

            structNode.Classes.AcceptVisitor(this, data);

            structNode.Constants.AcceptVisitor(this, data);

            structNode.Constructors.AcceptVisitor(this, data);

            structNode.Delegates.AcceptVisitor(this, data);

            structNode.Destructors.AcceptVisitor(this, data);

            structNode.Enums.AcceptVisitor(this, data);

            structNode.Events.AcceptVisitor(this, data);

            structNode.Fields.AcceptVisitor(this, data);

            structNode.FixedBuffers.AcceptVisitor(this, data);

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

            structNode.Indexers.AcceptVisitor(this, data);

            structNode.Interfaces.AcceptVisitor(this, data);

            structNode.Methods.AcceptVisitor(this, data);

            structNode.Operators.AcceptVisitor(this, data);

            if (structNode.Partials != null)
            {
                structNode.Partials.AcceptVisitor(this, data);
            }

            structNode.Properties.AcceptVisitor(this, data);

            structNode.Structs.AcceptVisitor(this, data);

            stackMap.Pop();

            return(null);
        }
예제 #2
0
        public virtual object VisitStructNode(StructNode structNode, object data)
        {
            stackMap.Push(structNode);

            structNode.Attributes.AcceptVisitor(this, data);

            structNode.BaseClasses.AcceptVisitor(this, data);

            structNode.Classes.AcceptVisitor(this, data);

            structNode.Constants.AcceptVisitor(this, data);

            structNode.Constructors.AcceptVisitor(this, data);

            structNode.Delegates.AcceptVisitor(this, data);

            structNode.Destructors.AcceptVisitor(this, data);

            structNode.Enums.AcceptVisitor(this, data);

            structNode.Events.AcceptVisitor(this, data);

            structNode.Fields.AcceptVisitor(this, data);

            structNode.FixedBuffers.AcceptVisitor(this, data);

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

            structNode.Indexers.AcceptVisitor(this, data);

            structNode.Interfaces.AcceptVisitor(this, data);

            structNode.Methods.AcceptVisitor(this, data);

            structNode.Operators.AcceptVisitor(this, data);

            if (structNode.Partials != null)
            {
                structNode.Partials.AcceptVisitor(this, data);
            }

            structNode.Properties.AcceptVisitor(this, data);

            structNode.Structs.AcceptVisitor(this, data);

            stackMap.Pop();

            return null;
        }
예제 #3
0
        private void ParseFixedBuffer(StructNode st, FixedBufferNode node)
        {
            if (st == null)
            {
                ReportError("fixed buffer authorized only in structure declaration.");
            }

            if (!node.IsUnsafe)
            {
                ReportError("fixed buffer authorized only in unsafe context.");
            }

            if ((node.Modifiers & Modifier.Static) != Modifier.Empty)
            {
                ReportError("fixed buffer can not be declared as static.");
            }

            if ( node.Type is TypePointerNode )
            {
                ReportError("fixed buffer can not be pointer.");
            }
            else
            {
                StringCollection strColl = new StringCollection();
                string type_str = ((TypeNode)node.Type).Identifier.QualifiedIdentifier.ToLower();

                strColl.AddRange(new string[] { "sbyte", "byte", "short", "ushort", "int", "uint", "long", "ulong", "char", "float", "double", "bool" });

                if (!strColl.Contains(type_str))
                {
                    ReportError("fixed buffer element type must be of type sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double or bool.");    
                }
            }
            AssertAndAdvance(TokenID.LBracket);

            ConstantExpression expr = new ConstantExpression(curtok);
            expr.Value = ParseExpression(TokenID.RBracket);
            node.FixedBufferConstants.Add(  expr );

            AssertAndAdvance(TokenID.RBracket);
        }
예제 #4
0
		private void ParseStruct()											
		{
			StructNode node = new StructNode(curtok);

            node.IsPartial = nextIsPartial;
            nextIsPartial = false;

            ClassNode cl = typeStack.Count == 0 ? null : typeStack.Peek();

			typeStack.Push(node);

			uint structMask = ~(uint)Modifier.StructMods;
			if (((uint)curmods & structMask) != (uint)Modifier.Empty)
				ReportError("Struct contains illegal modifiers");

			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 struct is declared in an unsafe type ?
                node.IsUnsafe = isUnsafe > 0;

			Advance(); // advance over Struct token
            node.Name = (IdentifierExpression)ParseIdentifierOrKeyword(false, false, false, true);

            ParsePossibleTypeParameterNode(true, true, false);
            ApplyTypeParameters(node);

			if (curtok.ID == TokenID.Colon) // for base members
			{
				Advance();
				node.BaseClasses.Add(ParseType());
				while (curtok.ID == TokenID.Comma)
				{
					Advance();
					node.BaseClasses.Add(ParseType());
				}
			}

            ParsePossibleTypeParameterConstraintNode(node);
            ApplyTypeParameterConstraints(node);

            CheckTypeUnicityAndAdd(node);

            if (node.IsGeneric)
            {
                this.nameTable.AddIdentifier(new StructName(node.Name.Identifier,
                    ToVisibilityRestriction(node.Modifiers),
                    node.Generic.TypeParameters.ConvertAll<string>(delegate(TypeParameterNode input) { return input.Identifier.Identifier; }).ToArray(),
                    this.currentContext));
            }
            else
            {
                this.nameTable.AddIdentifier(new StructName(node.Name.Identifier,
                    ToVisibilityRestriction(node.Modifiers),
                    this.currentContext));
            }

            this.currentContext.Enter(node.Name.Identifier, false);

            if (cl == null)
            {
                namespaceStack.Peek().Structs.Add(node);
            }
            else
            {
                cl.Structs.Add(node);
            }

			AssertAndAdvance(TokenID.LCurly);

			while (curtok.ID != TokenID.RCurly) // guard for empty
			{
				ParseClassMember();
			}

			AssertAndAdvance(TokenID.RCurly);

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

            this.currentContext.Leave();

			typeStack.Pop();
		}