Ejemplo n.º 1
0
        public virtual object VisitFixedBufferNode(FixedBufferNode fixedBufferNode, object data)
        {
            stackMap.Push(fixedBufferNode);
            fixedBufferNode.Attributes.AcceptVisitor(this, data);
            fixedBufferNode.FixedBufferConstants.AcceptVisitor(this, data);
            fixedBufferNode.Type.AcceptVisitor(this, data);

            if (fixedBufferNode.Value != null)
            {
                fixedBufferNode.Value.AcceptVisitor(this, data);
            }

            stackMap.Pop();
            return(null);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"> type of the field</param>
        /// <param name="name"> name in qualified form ( if it is an explicit interface declaration) </param>
		private void ParseFixedBuffer(IType type, QualifiedIdentifierExpression name)	
		{
			uint mask = ~(uint)Modifier.FxedBufferdMods;
			if (((uint)curmods & mask) != (uint)Modifier.Empty)
				ReportError("field declaration contains illegal modifiers");

            FixedBufferNode node = new FixedBufferNode(curtok);
			StructNode st = (StructNode)typeStack.Peek();
            st.FixedBuffers.Add(node);

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

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

            node.IsUnsafe = isUnsafe > 0;

            CheckStaticClass(st, node.Modifiers, true);

			if (curAttributes.Count > 0)
			{
				node.Attributes = curAttributes;
				curAttributes = new NodeCollection<AttributeNode>();
			}
			
			node.Type = type;
            QualifiedIdentifierExpression fieldName = new QualifiedIdentifierExpression(name.RelatedToken);
            fieldName.Expressions.Add(name);
			node.Names.Add(fieldName);

            //fixed buffer
            // if the current type is not a structure, it is invalid
            ParseFixedBuffer(st, node);

			while (curtok.ID == TokenID.Comma)
			{
				Advance(); // over comma
				QualifiedIdentifierExpression ident = ParseQualifiedIdentifier(false, false, true);
				node.Names.Add(ident);

                ParseFixedBuffer(st, node);
			}

			 if (curtok.ID == TokenID.Semi)
			{
				Advance();
			}

		}
Ejemplo n.º 4
0
        public virtual object VisitFixedBufferNode(FixedBufferNode fixedBufferNode, object data)
        {
            stackMap.Push(fixedBufferNode);
            fixedBufferNode.Attributes.AcceptVisitor(this, data);
            fixedBufferNode.FixedBufferConstants.AcceptVisitor(this, data);
            fixedBufferNode.Type.AcceptVisitor(this, data);

            if (fixedBufferNode.Value != null )
            {
                fixedBufferNode.Value.AcceptVisitor(this, data);
            }

            stackMap.Pop();
            return null;

        }