Example #1
0
        public override Object Visit(QualifiedIdentifierExpression node, Object obj)
        {
            node.IdName.Accept(this, obj);
            node.IdExpression.Accept(this, obj);

            return(null);
        }
Example #2
0
        public override object Visit(QualifiedIdentifierExpression node)
        {
            foreach (var item in _evaluationVisitor.Scope)
            {
                var enumScope = item as Enum;
                if (enumScope != null)
                {
                    if (enumScope.Items.ContainsKey(node.QualifiedName.ToString()))
                    {
                        return(enumScope.Items[node.QualifiedName.ToString()]);
                    }

                    continue;
                }

                var translationUnitScope = item as TranslationUnit;
                if (translationUnitScope != null)
                {
                    foreach (var @enum in translationUnitScope.Enums)
                    {
                        if (@enum.Items.ContainsKey(node.QualifiedName.ToString()))
                        {
                            return(@enum.Items[node.QualifiedName.ToString()]);
                        }
                    }

                    continue;
                }
            }
            return(base.Visit(node));
        }
Example #3
0
 public override Object Visit(QualifiedIdentifierExpression node, Object obj)
 {
     node.IdName.LeftExpression       = node.LeftExpression;
     node.IdExpression.LeftExpression = node.LeftExpression;
     node.IdName.Accept(this, false);
     node.IdExpression.Accept(this, true);
     return(null);
 }
 public override object Visit(QualifiedIdentifierExpression node, object obj)
 {
     if (node.Location == ((AstNode)obj).Location || found)
     {
         found = true;
         return(this.table);
     }
     return(base.Visit(node, obj));
 }
Example #5
0
        public override Object Visit(QualifiedIdentifierExpression node, Object obj)
        {
            int indent = Convert.ToInt32(obj);

            this.printIndentation(indent);
            this.output.WriteLine("QualifiedIdentifierExpression Type: {0} [{1}:{2}]", printType(node.ExpressionType), node.Location.Line, node.Location.Column);
            node.IdName.Accept(this, indent + 1);
            node.IdExpression.Accept(this, indent + 1);
            return(null);
        }
 public abstract Object Visit(QualifiedIdentifierExpression node, Object obj);
        public virtual object VisitQualifiedIdentifierExpression(QualifiedIdentifierExpression qualifiedIdentifierExpression, object data)
        {
            stackMap.Push(qualifiedIdentifierExpression);
            qualifiedIdentifierExpression.Expressions.AcceptVisitor( this, data );
            
            if ( qualifiedIdentifierExpression.Generic != null )
            {
                qualifiedIdentifierExpression.Generic.AcceptVisitor( this, data );
            }

            stackMap.Pop();
            return null;

        }
Example #8
0
        /// <summary>
        /// it parse expressions like
        /// 
        /// A.B.type1<int>.type2
        /// 
        /// </summary>
        /// <returns></returns>
        private QualifiedIdentifierExpression ParseQualifiedIdentifier(bool consumeTypeParameter, bool allowTypeParameterAttributes, bool inDeclaration)
        {
            QualifiedIdentifierExpression result = new QualifiedIdentifierExpression(curtok);

            result.Expressions.Add(ParseIdentifierOrKeyword(true, consumeTypeParameter, allowTypeParameterAttributes, inDeclaration));
            while (curtok.ID == TokenID.Dot || curtok.ID == TokenID.ColonColon )
            {
                if (curtok.ID == TokenID.ColonColon)
                {
                    // 'global' is not a kw so it is treated as an identifier
                    if (result.IsNamespaceAliasQualifier)
                    {
                        ReportError("Qualified name can not have more than one qualificator alias name.");
                    }
                    result.IsNamespaceAliasQualifier = true;
                }

                Advance();
                if (curtok.ID == TokenID.This)
                {
                    // this is an indexer with a prepended interface, do nothing (but consume dot)
                }
                else
                {
                    result.Expressions.Add(ParseIdentifierOrKeyword(true, consumeTypeParameter, allowTypeParameterAttributes, inDeclaration));                    
                }
            }

            return result;
        }
Example #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"> type of the property</param>
        /// <param name="name"> name in qualified form ( if it is an explicit interface declaration) </param>
		private void ParseProperty(IType type, QualifiedIdentifierExpression name)
		{
			uint mask = ~(uint)Modifier.PropertyMods;
			if (((uint)curmods & mask) != (uint)Modifier.Empty)
				ReportError("field declaration contains illegal modifiers");

            PropertyNode node = new PropertyNode(curtok);
			ClassNode cl = typeStack.Peek();
            cl.Properties.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 property is declared in an unsafe type ?
            node.IsUnsafe = isUnsafe > 0;

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

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

			// opens on lcurly
			AssertAndAdvance(TokenID.LCurly);

			// todo: AddNode attributes to get and setters
			ParsePossibleAttributes(false);

            ParseModifiers();

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

			if (curtok.ID != TokenID.Ident)
			{
				RecoverFromError("At least one get or set required in accessor", curtok.ID);
			}

			bool parsedGet = false;
			if (strings[curtok.Data] == "get")
			{
				node.Getter = ParseAccessor(type);
				parsedGet = true;
			}

			// todo: AddNode attributes to get and setters
			ParsePossibleAttributes(false);

            ParseModifiers();

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

			if (curtok.ID == TokenID.Ident && strings[curtok.Data] == "set")
			{
				node.Setter = ParseAccessor(type);
			}

            if (!parsedGet)
            {
                // todo: AddNode attributes to get and setters
                ParsePossibleAttributes(false);

                ParseModifiers();

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

                // get might follow set
                if (curtok.ID == TokenID.Ident && strings[curtok.Data] == "get")
                {
                    node.Getter = ParseAccessor(type);
                }
            }

            if (node.Setter != null
                && node.Getter != null)
            {
                if (node.Getter.Modifiers != Modifier.Empty
                        && node.Setter.Modifiers != Modifier.Empty)
                {
                    ReportError("Modifiers is permitted only for one of the acessors.");
                }
            }
            else
            {
                if (node.Setter == null && node.Getter != null && node.Getter.Modifiers != Modifier.Empty
                    || node.Getter == null && node.Setter != null && node.Setter.Modifiers != Modifier.Empty)
                {
                    ReportError("Accessor modifier is authorized only if the 'get' and the 'set' are declared.");
                }

            }

			AssertAndAdvance(TokenID.RCurly);

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

            #region Save name in the name table
            if (node.Getter != null)
            {
                if (node.Setter != null)
                {
                    if (node.Getter.Modifiers != Modifier.Empty)
                    {
                        this.nameTable.AddIdentifier(new PropertyName(name.QualifiedIdentifier,
                            ToVisibilityRestriction(node.Setter.Modifiers),
                            ToVisibilityRestriction(node.Modifiers),
                            ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                            PropertyAccessors.Both,
                            this.currentContext));
                    }
                    else if (node.Setter.Modifiers != Modifier.Empty)
                    {
                        this.nameTable.AddIdentifier(new PropertyName(name.QualifiedIdentifier,
                            ToVisibilityRestriction(node.Modifiers),
                            ToVisibilityRestriction(node.Setter.Modifiers),
                            ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                            PropertyAccessors.Both,
                            this.currentContext));
                    }
                    else
                    {
                        this.nameTable.AddIdentifier(new PropertyName(name.QualifiedIdentifier,
                            ToVisibilityRestriction(node.Modifiers),
                            ToVisibilityRestriction(node.Modifiers),
                            ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                            PropertyAccessors.Both,
                            this.currentContext));
                    }
                }
                else
                {
                    this.nameTable.AddIdentifier(new PropertyName(name.QualifiedIdentifier,
                        ToVisibilityRestriction(node.Modifiers),
                        NameVisibilityRestriction.Self,
                        ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                        PropertyAccessors.Get,
                        this.currentContext));
                }
            }
            else
            {
                this.nameTable.AddIdentifier(new PropertyName(name.QualifiedIdentifier,
                    NameVisibilityRestriction.Self,
                    ToVisibilityRestriction(node.Modifiers),
                    ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                    PropertyAccessors.Set,
                    this.currentContext));
            }
            #endregion
		}
Example #10
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 ParseField(IType type, QualifiedIdentifierExpression name)	
		{
			uint mask = ~(uint)Modifier.FieldMods;
			if (((uint)curmods & mask) != (uint)Modifier.Empty)
				ReportError("field declaration contains illegal modifiers");

			FieldNode node = new FieldNode(curtok);
			ClassNode cl = typeStack.Peek();
            cl.Fields.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(cl, 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);

            this.nameTable.AddIdentifier(new FieldName(name.QualifiedIdentifier,
                ToVisibilityRestriction(node.Modifiers),
                ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                this.currentContext));

			//eg: int ok = 0, error, xx = 0;
			if (curtok.ID == TokenID.Equal)
			{
				Advance();
				node.Value = ParseConstExpr();
				if (curtok.ID == TokenID.Comma)
				{
					node = new FieldNode(curtok);
					typeStack.Peek().Fields.Add(node);
					node.Modifiers = curmods;
					node.Type = type;
				}
			}

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

				if (curtok.ID == TokenID.Equal)
				{
					Advance();
					node.Value = ParseConstExpr();

					if (curtok.ID == TokenID.Comma)
					{
                        node = new FieldNode(curtok);
						typeStack.Peek().Fields.Add(node);
						node.Modifiers = curmods;
						node.Type = type;
					}
				}

                this.nameTable.AddIdentifier(new FieldName(ident.QualifiedIdentifier,
                    ToVisibilityRestriction(node.Modifiers),
                    ((node.Modifiers & Modifier.Static) != Modifier.Empty ? Scope.Instance : Scope.Static),
                    this.currentContext));
            }

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


		}
Example #11
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();
			}

		}
Example #12
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));
		}
Example #13
0
		private void ParseIndexer(IType type, QualifiedIdentifierExpression interfaceType)
		{
			IndexerNode node = new IndexerNode(curtok);
			ClassNode cl = typeStack.Peek();
            cl.Indexers.Add(node);

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

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

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

			node.Type = type;
			if (interfaceType != null)
			{
                node.InterfaceType = new TypeNode(interfaceType );
			}

			AssertAndAdvance(TokenID.This);
			node.Params = ParseParamList(TokenID.LBracket, TokenID.RBracket);

			// parse accessor part
			AssertAndAdvance(TokenID.LCurly);

            ParseModifiers();

			if (curtok.ID != TokenID.Ident)
			{
				RecoverFromError("At least one get or set required in accessor", curtok.ID);
			}
			bool parsedGet = false;
			if (strings[curtok.Data] == "get")
			{
				node.Getter = ParseAccessor(type);
				parsedGet = true;
			}

            ParseModifiers();

			if (curtok.ID == TokenID.Ident && strings[curtok.Data] == "set")
			{
				node.Setter = ParseAccessor(type);
			}

            ParseModifiers();
			// get might follow set
			if (!parsedGet && curtok.ID == TokenID.Ident && strings[curtok.Data] == "get")
			{
				node.Getter = ParseAccessor(type);
			}

            if (node.Setter != null
                && node.Getter != null)
            {
                if (node.Getter.Modifiers != Modifier.Empty
                        && node.Setter.Modifiers != Modifier.Empty)
                {
                    ReportError("Modifiers is permitted only for one of the acessors.");
                }
            }
            else
            {
                if (node.Setter == null && node.Getter.Modifiers != Modifier.Empty
                    || node.Getter == null && node.Setter.Modifiers != Modifier.Empty)
                {
                   ReportError("Accessor modifier is authorized only if the 'get' and the 'set' are declared.");
                }

            }

            switch (node.Modifiers)
            {
                case Modifier.Public:
                    break;
                case (Modifier.Protected | Modifier.Internal):
                    if ( node.Getter != null
                        && node.Getter.Modifiers != Modifier.Empty
                        && (node.Getter.Modifiers != Modifier.Protected
                                || node.Getter.Modifiers != Modifier.Private
                                || node.Getter.Modifiers != Modifier.Internal
                            )
                        )
                    {
                        ReportError("The property is protected internal, so the accessor can be only protected, private or internal.");
                    }

                    if (node.Setter != null
                        && node.Setter.Modifiers != Modifier.Empty
                        && (node.Setter.Modifiers != Modifier.Protected
                                || node.Setter.Modifiers != Modifier.Private
                                || node.Setter.Modifiers != Modifier.Internal
                            )
                        )
                    {
                        ReportError("The property is protected internal, so the accessor can be only protected, private or internal.");
                    }
                    break;
                case Modifier.Protected:
                case Modifier.Internal:
                    if (node.Getter != null
                        && node.Getter.Modifiers != Modifier.Empty
                        && node.Getter.Modifiers != Modifier.Private)
                    {
                        ReportError("The property is protected or internal, so the accessor can be only private.");
                    }

                    if (node.Setter != null
                        && node.Setter.Modifiers != Modifier.Empty
                        && node.Setter.Modifiers != Modifier.Private)
                    {
                        ReportError("The property is protected or internal, so the accessor can be only private.");
                    }
                    break;
                case Modifier.Private:
                    if (node.Getter != null
                        && node.Getter.Modifiers != Modifier.Empty)
                    {
                        ReportError("The property is private or internal, so the accessor can not have any modifier.");
                    }

                    if (node.Setter != null
                        && node.Setter.Modifiers != Modifier.Empty)
                    {
                        ReportError("The property is private or internal, so the accessor can not have any modifier.");
                    }

                    break;
            }

			AssertAndAdvance(TokenID.RCurly);

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

            #region Save name in the name table
            if (node.Getter != null)
            {
                if (node.Setter != null)
                {
                    if (node.Getter.Modifiers != Modifier.Empty)
                    {
                        this.nameTable.AddIdentifier(new IndexerName(
                            ToVisibilityRestriction(node.Setter.Modifiers),
                            ToVisibilityRestriction(node.Modifiers),
                            ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                            PropertyAccessors.Both,
                            this.currentContext));
                    }
                    else if (node.Setter.Modifiers != Modifier.Empty)
                    {
                        this.nameTable.AddIdentifier(new IndexerName(
                            ToVisibilityRestriction(node.Modifiers),
                            ToVisibilityRestriction(node.Setter.Modifiers),
                            ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                            PropertyAccessors.Both,
                            this.currentContext));
                    }
                    else
                    {
                        this.nameTable.AddIdentifier(new IndexerName(
                            ToVisibilityRestriction(node.Modifiers),
                            ToVisibilityRestriction(node.Modifiers),
                            ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                            PropertyAccessors.Both,
                            this.currentContext));
                    }
                }
                else
                {
                    this.nameTable.AddIdentifier(new IndexerName(
                        ToVisibilityRestriction(node.Modifiers),
                        NameVisibilityRestriction.Self,
                        ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                        PropertyAccessors.Get,
                        this.currentContext));
                }
            }
            else
            {
                this.nameTable.AddIdentifier(new IndexerName(
                    NameVisibilityRestriction.Self,
                    ToVisibilityRestriction(node.Modifiers),
                    ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                    PropertyAccessors.Set,
                    this.currentContext));
            }
            #endregion
		}
Example #14
0
		private void ParseCtor(TypeNode type)								
		{
			ConstructorNode node = new ConstructorNode(curtok);

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

			if ((curmods & Modifier.Static) != Modifier.Empty)
			{
				node.IsStaticConstructor = true;
				curmods = curmods & ~Modifier.Static;
			}
			uint mask = ~(uint)Modifier.ConstructorMods;
			if (((uint)curmods & mask) != (uint)Modifier.Empty)
				ReportError("constructor declaration contains illegal modifiers");

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

			//node.Attributes.Add(curAttributes);
			//curAttributes.Clear();
			node.Modifiers = curmods;
			curmods = Modifier.Empty;

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

            //the constructor is declared in an unsafe type ?
            node.IsUnsafe = isUnsafe > 0;

            if (node.IsStaticConstructor)
            {
                CheckStaticClass(cl, node.Modifiers | Modifier.Static, true);
            }
            else
            {
                CheckStaticClass(cl, node.Modifiers, true);
            }

            node.Type = type;
            QualifiedIdentifierExpression nameCtor = new QualifiedIdentifierExpression(node.RelatedToken);
            nameCtor.Expressions.Add(typeStack.Peek().Name);
			node.Names.Add( nameCtor );

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

			if (curtok.ID == TokenID.Colon)
			{
				Advance();
				if (curtok.ID == TokenID.Base)
				{
					Advance();
					node.HasBase = true;
					node.ThisBaseArgs = ParseArgs();
				}
				else if (curtok.ID == TokenID.This)
				{
					Advance();
					node.HasThis = true;
					node.ThisBaseArgs = ParseArgs();
				}
				else
				{
					RecoverFromError("constructor requires this or base calls after colon", TokenID.Base);
				}
			}
			ParseBlock(node.StatementBlock);

            if ((node.Modifiers & Modifier.Unsafe) != Modifier.Empty)
            {
                //unsafe modifier -> unsafe type.
                isUnsafe--;
            }
		}
Example #15
0
        private void BuilderType(InterfaceNode type, NamespaceNode nspace)
        {
            DDW.ClassNode cls = new ClassNode(new Token(TokenID.Public));
            cls.Modifiers = Modifier.Public;
            cls.BaseClasses.Add(new TypeNode(new IdentifierExpression("Peanut.Mappings.DataObject", new Token(TokenID.Typeof))));
            foreach (AttributeNode attr in type.Attributes)
            {
                cls.Attributes.Add(attr);
            }
            mTableName    = GetTableName(type);
            mClassName    = type.Name.Identifier.Substring(1, type.Name.Identifier.Length - 1);
            cls.Name      = new IdentifierExpression(mClassName, new Token(TokenID.String | TokenID.Public));
            cls.IsPartial = true;
            nspace.Classes.Add(cls);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("///<summary>");
            sb.AppendLine("///Peanut Generator Copyright @ FanJianHan 2010-2013");
            sb.AppendLine("///website:http://www.ikende.com");
            if (!string.IsNullOrEmpty(type.Comment))
            {
                sb.AppendLine(type.Comment);
            }
            StringReader sr    = new StringReader(type.DocComment);
            string       value = sr.ReadLine();

            while (value != null)
            {
                if (value.IndexOf("summary>") == -1)
                {
                    sb.AppendLine(value);
                }
                value = sr.ReadLine();
            }
            sb.AppendLine("///</summary>");
            cls.DocComment = sb.ToString();

            foreach (InterfacePropertyNode property in type.Properties)
            {
                string    propertyname = property.Names[0].GenericIdentifier;
                string    fieldname    = GetFieldName(property);
                FieldNode field        = new FieldNode(new Token(TokenID.False));
                field.Modifiers = Modifier.Private;
                QualifiedIdentifierExpression name = new QualifiedIdentifierExpression(new Token(TokenID.String));
                name.Expressions.Add(new IdentifierExpression("m" + property.Names[0].GenericIdentifier, new Token(TokenID.String)));
                field.Names.Add(name);
                field.Type = property.Type;
                cls.Fields.Add(field);

                IType fieldtype = new TypeNode(new IdentifierExpression("Peanut.FieldInfo<" + ((TypeNode)property.Type).GenericIdentifier + ">", new Token(TokenID.Typeof)));
                field           = new FieldNode(new Token(TokenID.False));
                field.Modifiers = Modifier.Public | Modifier.Static;

                NodeCollection <ArgumentNode> args = new NodeCollection <ArgumentNode>();
                args.Add(new ArgumentNode(new Token(TokenID.String)));
                args.Add(new ArgumentNode(new Token(TokenID.String)));
                args[0].Expression = new StringPrimitive(mTableName, new Token(TokenID.String));
                args[1].Expression = new StringPrimitive(fieldname, new Token(TokenID.String));

                name = new QualifiedIdentifierExpression(new Token(TokenID.String));
                name.Expressions.Add(new AssignmentExpression(TokenID.Equal,
                                                              new IdentifierExpression(propertyname.Substring(0, 1).ToLower() + propertyname.Substring(1, propertyname.Length - 1)
                                                                                       , new Token(TokenID.String)), new ObjectCreationExpression(fieldtype, args, new Token(TokenID.New))));
                field.Names.Add(name);
                field.Type = fieldtype;

                cls.Fields.Add(field);


                PropertyNode pn = new PropertyNode(new Token(TokenID.Newline));
                foreach (AttributeNode attr in property.Attributes)
                {
                    pn.Attributes.Add(attr);
                }
                pn.Names       = property.Names;
                pn.Modifiers   = Modifier.Public | Modifier.Virtual;
                pn.Type        = property.Type;
                pn.Setter      = new AccessorNode(true, new Token(TokenID.Newline));
                pn.Setter.Kind = "set";
                ExpressionStatement setvalue = new ExpressionStatement(
                    new AssignmentExpression(TokenID.Equal,
                                             new IdentifierExpression("m" + property.Names[0].GenericIdentifier, new Token(TokenID.String))
                                             , new IdentifierExpression("value", new Token(TokenID.String)))
                    );
                pn.Setter.StatementBlock.Statements.Add(setvalue);

                args = new NodeCollection <ArgumentNode>();
                args.Add(new ArgumentNode(new Token(TokenID.String)));
                args[0].Expression = new StringPrimitive(propertyname, new Token(TokenID.String));
                QualifiedIdentifierExpression invoke = new QualifiedIdentifierExpression(new Token(TokenID.String));
                invoke.Expressions.Add(new IdentifierExpression("EntityState", new Token(TokenID.String)));
                invoke.Expressions.Add(new InvocationExpression(new IdentifierExpression("FieldChange", new Token(TokenID.Default)), args));
                setvalue = new ExpressionStatement(invoke);
                pn.Setter.StatementBlock.Statements.Add(setvalue);

                pn.Getter      = new AccessorNode(true, new Token(TokenID.Newline));
                pn.Getter.Kind = "get";
                ReturnStatement rs = new ReturnStatement(new Token(TokenID.Return));
                rs.ReturnValue = new IdentifierExpression("m" + property.Names[0].GenericIdentifier, new Token(TokenID.String));
                pn.Getter.StatementBlock.Statements.Add(rs);

                sb = new StringBuilder();
                sb.AppendLine("///<summary>");
                sb.AppendLine("///Type:" + ((TypeNode)property.Type).GenericIdentifier);
                if (!string.IsNullOrEmpty(property.Comment))
                {
                    sb.AppendLine(type.Comment);
                }
                sr    = new StringReader(property.DocComment);
                value = sr.ReadLine();
                while (value != null)
                {
                    if (value.IndexOf("summary>") == -1)
                    {
                        sb.AppendLine(value);
                    }
                    value = sr.ReadLine();
                }
                sb.AppendLine("///</summary>");
                pn.DocComment = sb.ToString();


                cls.Properties.Add(pn);
            }
            //CodeTypeDeclaration entity = new CodeTypeDeclaration(mClassName);
            //CodeCommentStatement comm;
            //cns.Types.Add(entity);


            //comm = new CodeCommentStatement("<summary>");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //comm = new CodeCommentStatement("Peanut Generator Copyright © FanJianHan 2010-2013");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //comm = new CodeCommentStatement("website:http://www.ikende.com");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //if (!string.IsNullOrEmpty(type.Comment))
            //{
            //    comm = new CodeCommentStatement(type.Comment);
            //    comm.Comment.DocComment = true;
            //    entity.Comments.Add(comm);
            //}

            //StringReader sr = new StringReader(type.DocComment);
            //string value = sr.ReadLine();
            //while (value != null)
            //{
            //    if (value.IndexOf("summary>") == -1)
            //    {
            //        comm = new CodeCommentStatement(value.Replace("///", ""));
            //        comm.Comment.DocComment = true;
            //        entity.Comments.Add(comm);
            //    }
            //    value = sr.ReadLine();
            //}
            //comm = new CodeCommentStatement("</summary>");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //// }
            //entity.BaseTypes.Add(new CodeTypeReference("Peanut.Mappings.DataObject"));
            //entity.BaseTypes.Add(new CodeTypeReference(type.Name.Identifier));
            //entity.Attributes = MemberAttributes.Public;
            //entity.IsPartial = true;
            //entity.CustomAttributes.Add(new CodeAttributeDeclaration("Serializable"));
            //entity.IsClass = true;
            //foreach (AttributeNode aitem in type.Attributes)
            //{
            //    CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(aitem.Name.GenericIdentifier);
            //    entity.CustomAttributes.Add(attribute);
            //    if (attribute.Name.ToLower() == "table")
            //    {
            //        if (aitem.Arguments.Count > 0)
            //        {

            //            DDW.StringPrimitive pe = (DDW.StringPrimitive)aitem.Arguments[0].Expression;
            //            if (pe != null)
            //            {
            //                mTableName = pe.Value.ToString();
            //            }
            //            else
            //            {
            //                mTableName = mClassName;

            //            }
            //            attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(mTableName)));
            //        }
            //        else
            //        {
            //            mTableName = mClassName;
            //        }
            //    }

            //}
            //foreach (InterfacePropertyNode mitem in type.Properties)
            //{


            //    BuilderProperty(entity, mitem);

            //}
        }
Example #16
0
 public override Object Visit(QualifiedIdentifierExpression node, Object obj)
 {
     return(null);
 }
Example #17
0
        private void BuilderType(InterfaceNode type,NamespaceNode nspace)
        {
            DDW.ClassNode cls = new ClassNode(new Token(TokenID.Public));
            cls.Modifiers = Modifier.Public;
            cls.BaseClasses.Add(new TypeNode(new IdentifierExpression("Peanut.Mappings.DataObject", new Token(TokenID.Typeof))));
            foreach (AttributeNode attr in type.Attributes)
            {
                cls.Attributes.Add(attr);
            }
            mTableName = GetTableName(type);
            mClassName = type.Name.Identifier.Substring(1, type.Name.Identifier.Length - 1);
            cls.Name = new IdentifierExpression(mClassName, new Token(TokenID.String|TokenID.Public));
            cls.IsPartial = true;
            nspace.Classes.Add(cls);

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("///<summary>");
            sb.AppendLine("///Peanut Generator Copyright @ FanJianHan 2010-2013");
            sb.AppendLine("///website:http://www.ikende.com");
            if (!string.IsNullOrEmpty(type.Comment))
            {
                sb.AppendLine(type.Comment);
            }
            StringReader sr = new StringReader(type.DocComment);
            string value = sr.ReadLine();
            while (value != null)
            {
                if (value.IndexOf("summary>") == -1)
                {
                    sb.AppendLine(value);
                }
                value = sr.ReadLine();
            }
            sb.AppendLine("///</summary>");
            cls.DocComment = sb.ToString();

            foreach (InterfacePropertyNode property in type.Properties)
            {
                string propertyname = property.Names[0].GenericIdentifier;
                string fieldname= GetFieldName(property);
                FieldNode field = new FieldNode(new Token(TokenID.False));
                field.Modifiers = Modifier.Private;
                QualifiedIdentifierExpression name = new QualifiedIdentifierExpression(new Token(TokenID.String));
                name.Expressions.Add(new IdentifierExpression("m" + property.Names[0].GenericIdentifier, new Token(TokenID.String)));
                field.Names.Add(name);
                field.Type = property.Type;
                cls.Fields.Add(field);

                IType fieldtype=new TypeNode(new IdentifierExpression("Peanut.FieldInfo<"+((TypeNode)property.Type).GenericIdentifier+">", new Token(TokenID.Typeof)));
                field = new FieldNode(new Token(TokenID.False));
                field.Modifiers = Modifier.Public| Modifier.Static;
               
                NodeCollection<ArgumentNode> args = new NodeCollection<ArgumentNode>();
                args.Add(new ArgumentNode(new Token(TokenID.String)));
                args.Add(new ArgumentNode(new Token(TokenID.String)));
                args[0].Expression = new StringPrimitive(mTableName, new Token(TokenID.String));
                args[1].Expression = new StringPrimitive(fieldname, new Token(TokenID.String));

                name = new QualifiedIdentifierExpression(new Token(TokenID.String));
                name.Expressions.Add(new AssignmentExpression(TokenID.Equal,
                    new IdentifierExpression(propertyname.Substring(0, 1).ToLower() + propertyname.Substring(1, propertyname.Length - 1)
                    , new Token(TokenID.String)), new ObjectCreationExpression(fieldtype, args, new Token(TokenID.New))));
                field.Names.Add(name);
                field.Type = fieldtype;
               
                cls.Fields.Add(field);


                PropertyNode pn = new PropertyNode(new Token(TokenID.Newline));
                foreach (AttributeNode attr in property.Attributes)
                {
                    pn.Attributes.Add(attr);
                }
                pn.Names = property.Names;
                pn.Modifiers = Modifier.Public | Modifier.Virtual;
                pn.Type = property.Type;
                pn.Setter = new AccessorNode(true, new Token(TokenID.Newline));
                pn.Setter.Kind = "set";
                ExpressionStatement setvalue = new ExpressionStatement(
                    new AssignmentExpression(TokenID.Equal,
                    new IdentifierExpression("m" + property.Names[0].GenericIdentifier, new Token(TokenID.String))
                    , new IdentifierExpression("value", new Token(TokenID.String)))
                    );
                pn.Setter.StatementBlock.Statements.Add(setvalue);

                args = new NodeCollection<ArgumentNode>();
                args.Add(new ArgumentNode(new Token(TokenID.String)));
                args[0].Expression = new StringPrimitive(propertyname, new Token(TokenID.String));
                QualifiedIdentifierExpression invoke = new QualifiedIdentifierExpression(new Token(TokenID.String));
                invoke.Expressions.Add(new IdentifierExpression("EntityState", new Token(TokenID.String)));
                invoke.Expressions.Add(new InvocationExpression(new IdentifierExpression("FieldChange", new Token(TokenID.Default)), args));
                setvalue = new ExpressionStatement(invoke);
                pn.Setter.StatementBlock.Statements.Add(setvalue);

                pn.Getter = new AccessorNode(true, new Token(TokenID.Newline));
                pn.Getter.Kind = "get";
                ReturnStatement rs = new ReturnStatement(new Token(TokenID.Return));
                rs.ReturnValue = new IdentifierExpression("m" + property.Names[0].GenericIdentifier, new Token(TokenID.String));
                pn.Getter.StatementBlock.Statements.Add(rs);

                sb = new StringBuilder();
                sb.AppendLine("///<summary>");
                sb.AppendLine("///Type:" + ((TypeNode)property.Type).GenericIdentifier);
                if (!string.IsNullOrEmpty(property.Comment))
                {
                    sb.AppendLine(type.Comment);
                }
                sr = new StringReader(property.DocComment);
                value = sr.ReadLine();
                while (value != null)
                {
                    if (value.IndexOf("summary>") == -1)
                    {
                        sb.AppendLine(value);
                    }
                    value = sr.ReadLine();
                }
                sb.AppendLine("///</summary>");
                pn.DocComment = sb.ToString();
                

                cls.Properties.Add(pn);
                
            }
            //CodeTypeDeclaration entity = new CodeTypeDeclaration(mClassName);
            //CodeCommentStatement comm;
            //cns.Types.Add(entity);

           
            //comm = new CodeCommentStatement("<summary>");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //comm = new CodeCommentStatement("Peanut Generator Copyright © FanJianHan 2010-2013");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //comm = new CodeCommentStatement("website:http://www.ikende.com");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //if (!string.IsNullOrEmpty(type.Comment))
            //{
            //    comm = new CodeCommentStatement(type.Comment);
            //    comm.Comment.DocComment = true;
            //    entity.Comments.Add(comm);
            //}

            //StringReader sr = new StringReader(type.DocComment);
            //string value = sr.ReadLine();
            //while (value != null)
            //{
            //    if (value.IndexOf("summary>") == -1)
            //    {
            //        comm = new CodeCommentStatement(value.Replace("///", ""));
            //        comm.Comment.DocComment = true;
            //        entity.Comments.Add(comm);
            //    }
            //    value = sr.ReadLine();
            //}
            //comm = new CodeCommentStatement("</summary>");
            //comm.Comment.DocComment = true;
            //entity.Comments.Add(comm);
            //// }
            //entity.BaseTypes.Add(new CodeTypeReference("Peanut.Mappings.DataObject"));
            //entity.BaseTypes.Add(new CodeTypeReference(type.Name.Identifier));
            //entity.Attributes = MemberAttributes.Public;
            //entity.IsPartial = true;
            //entity.CustomAttributes.Add(new CodeAttributeDeclaration("Serializable"));
            //entity.IsClass = true;
            //foreach (AttributeNode aitem in type.Attributes)
            //{
            //    CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(aitem.Name.GenericIdentifier);
            //    entity.CustomAttributes.Add(attribute);
            //    if (attribute.Name.ToLower() == "table")
            //    {
            //        if (aitem.Arguments.Count > 0)
            //        {

            //            DDW.StringPrimitive pe = (DDW.StringPrimitive)aitem.Arguments[0].Expression;
            //            if (pe != null)
            //            {
            //                mTableName = pe.Value.ToString();
            //            }
            //            else
            //            {
            //                mTableName = mClassName;

            //            }
            //            attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(mTableName)));
            //        }
            //        else
            //        {
            //            mTableName = mClassName;
            //        }
            //    }

            //}
            //foreach (InterfacePropertyNode mitem in type.Properties)
            //{


            //    BuilderProperty(entity, mitem);

            //}



        }
Example #18
0
        private ExpressionNode ParsePrimaryExpression()
        {
            Token tok = curtok;
            ExpressionNode result;	// TODO: handle error cases (result = null)
            switch (curtok.ID)
            {
                #region Literals
                case TokenID.Null:
                    result = new NullPrimitive(curtok);
                    Advance();
                    break;

                case TokenID.True:
                    result = new BooleanPrimitive(true, curtok);
                    Advance();
                    break;

                case TokenID.False:
                    result = new BooleanPrimitive(false, curtok);
                    Advance();
                    break;

                case TokenID.IntLiteral:
                    result = new IntegralPrimitive(strings[curtok.Data], IntegralType.Int, curtok);
                    Advance();
                    break;
                case TokenID.UIntLiteral:
                    result = new IntegralPrimitive(strings[curtok.Data], IntegralType.UInt, curtok);
                    Advance();
                    break;
                case TokenID.LongLiteral:
                    result = new IntegralPrimitive(strings[curtok.Data], IntegralType.Long, curtok);
                    Advance();
                    break;
                case TokenID.ULongLiteral:
                    result = new IntegralPrimitive(strings[curtok.Data], IntegralType.ULong, curtok);
                    Advance();
                    break;

                case TokenID.RealLiteral:
                    result = new RealPrimitive(strings[curtok.Data], curtok);
                    Advance();
                    break;

                case TokenID.CharLiteral:
                    result = new CharPrimitive(strings[curtok.Data], curtok);
                    Advance();
                    break;

                case TokenID.StringLiteral:
                    result = new StringPrimitive(strings[curtok.Data], curtok);
                    Advance();
                    break;
                #endregion

                #region Predefined Types

                case TokenID.Bool:
                case TokenID.Byte:
                case TokenID.Char:
                case TokenID.Decimal:
                case TokenID.Double:
                case TokenID.Float:
                case TokenID.Int:
                case TokenID.Long:
                case TokenID.Object:
                case TokenID.SByte:
                case TokenID.Short:
                case TokenID.String:
                case TokenID.UInt:
                case TokenID.ULong:
                case TokenID.UShort:
                    result = new PredefinedTypeNode(tok.ID, tok);
                    Advance();
                    result = ParseMemberAccess(result);
                    break;

                #endregion

                #region Keywords
                case TokenID.This:
                    {
                        Advance();
                        IdentifierExpression idExpr = new IdentifierExpression("this", tok);
                        idExpr.StartingPredefinedType = tok.ID;
                        result = idExpr;
                        break;
                    }

                case TokenID.Base:
                    Advance();   // over base
                    if (curtok.ID == TokenID.LBracket)         // base indexer expression
                    {
                        Advance();
                        result = new ElementAccessExpression(new IdentifierExpression("base", tok), ParseExpressionList());
                        AssertAndAdvance(TokenID.RBracket);
                        break;
                    }

                    if (curtok.ID != TokenID.Dot)
                    {
                        RecoverFromError(TokenID.Dot, TokenID.LBracket);
                        result = null;
                        break;
                    }

                    // base access expression
                    Advance();   // advance over dot
                    result = new BaseAccessExpression(ParseMember(false));
                    break;

                case TokenID.Checked:
                    Advance();
                    AssertAndAdvance(TokenID.LParen);
                    result = new CheckedExpression(ParseExpression());
                    AssertAndAdvance(TokenID.RParen);
                    break;

                case TokenID.Unchecked:
                    Advance();
                    AssertAndAdvance(TokenID.LParen);
                    result = new UncheckedExpression(ParseExpression());
                    AssertAndAdvance(TokenID.RParen);
                    break;

                case TokenID.Default:
                    Advance();
                    AssertAndAdvance(TokenID.LParen);
                    result = new DefaultConstantExpression(ParseType(false));
                    AssertAndAdvance(TokenID.RParen);
                    break;

                case TokenID.New:
                    Advance();

                    isNewStatement = true;

                    IType newType = ParseType(false);

                    //ApplyTypeParameters(newType); -> not sure, but a type pointer can not be generic!

                    if (curtok.ID == TokenID.LParen)
                    {
                        Advance();
                        result = new ObjectCreationExpression(newType, ParseArgumentList(), tok);
                        AssertAndAdvance(TokenID.RParen);
                    }
                    else if (curtok.ID == TokenID.LBracket)
                    {
                        result = ParseArrayCreation(newType);
                    }
                    else
                    {
                        RecoverFromError(TokenID.LParen, TokenID.LBracket);
                        result = null;
                    }

                    isNewStatement = false;
                    break;

                case TokenID.Typeof:
                    Advance();
                    AssertAndAdvance(TokenID.LParen);
                    result = new TypeOfExpression(ParseType(false));
                    CheckRankSpecifier(result);
                    AssertAndAdvance(TokenID.RParen);
                    break;

                case TokenID.Sizeof:
                    Advance();
                    AssertAndAdvance(TokenID.LParen);
                    result = new SizeOfExpression(ParseType(false));
                    AssertAndAdvance(TokenID.RParen);
                    break;

                case TokenID.Delegate:    //anonymous method
                    Advance();
                    result = ParseAnonymousMethod();
                    break;

                #endregion Keywords

                case TokenID.Ident:
                    result = ParseIdentifierOrKeyword(false, false, false, false, false);
                    if (curtok.ID == TokenID.ColonColon)
                    {
                        // id :: id type-parameter-list_opt . id type-parameter-list_opt

                        QualifiedIdentifierExpression qualID = new QualifiedIdentifierExpression(curtok);	// TODO: Replace by QualifiedAliasMember instance
                        qualID.IsNamespaceAliasQualifier = true;
                        qualID.Expressions.Add(result);

                        Advance(); // over ColonColon
                        qualID.Expressions.Add(ParseMember(false));

                        result = ParseMemberAccess(qualID);
                    }
                    else if (ParsePossibleTypeParameterNode(false, false, false, false))
                    {
                        result = new TypeNode(result);
                        ApplyTypeParameters((TypeNode)result);
                    }
                    break;

                case TokenID.LParen:
                    Advance();
                    result = ParseCastOrGroup();
                    break;

                default:
                    RecoverFromError("Unexpected token in primary expression");
                    return null;		// TODO: Invalid expression
            }
            return result;
        }
Example #19
0
        private ExpressionNode ParseExpressionOrType(bool inStatementContext)
        {
            // Can the interior be a type? (A.2.2)
            switch (curtok.ID)
            {
                // type-name
                case TokenID.Ident:

                // simple-type
                case TokenID.SByte:
                case TokenID.Byte:
                case TokenID.Short:
                case TokenID.UShort:
                case TokenID.Int:
                case TokenID.UInt:
                case TokenID.Long:
                case TokenID.ULong:
                case TokenID.Char:

                case TokenID.Float:
                case TokenID.Double:

                case TokenID.Decimal:

                case TokenID.Bool:

                // class-type
                case TokenID.Object:
                case TokenID.String:
                    // yes, it can
                    break;

                default:
                    // no, it can not
                    return ParseExpression();
            }

            ExpressionNode expr = ParseIdentifierOrKeyword(false, false, false, false, false);
            if (curtok.ID == TokenID.ColonColon)
            {
                // id :: id type-parameter-list_opt

                QualifiedIdentifierExpression qualID = new QualifiedIdentifierExpression(curtok);	// TODO: Replace by QualifiedAliasMember instance
                qualID.IsNamespaceAliasQualifier = true;
                qualID.Expressions.Add(expr);

                Advance(); // over ColonColon
                qualID.Expressions.Add(ParseMember(inStatementContext));

                expr = qualID;
            }
            else if (ParsePossibleTypeParameterNode(false, false, false, inStatementContext))
            {
                expr = new TypeNode(expr);
                ApplyTypeParameters((TypeNode)expr);
            }

            while (curtok.ID == TokenID.Dot)
            {
                Advance(); // over Dot
                if (curtok.ID != TokenID.Ident)
                {
                    RecoverFromError(TokenID.Ident);
                    return expr;
                }
                expr = new MemberAccessExpression(expr, ParseMember(inStatementContext), TokenID.Dot);
            }

            bool hasQuestionMark = false;
            int starCount = 0;
            bool hasBracket = false;

            if (curtok.ID == TokenID.Question)
            {
                Advance();
                hasQuestionMark = true;
            }

            while (curtok.ID == TokenID.Star)
            {
                Advance();
                starCount++;
            }

            // return (a * b);
            // return (a ? b : c);
            // a* b = c;
            // a? b = c;
            // a b = c;

            //if(curtok.ID == TokenID.Ident || (hasQuestionMark || starCount > 0) && curtok.ID == TokenID.RParen) goto foundType;

            if (curtok.ID == TokenID.Ident)
            {
                if (inStatementContext) goto foundType;
                else if (!hasQuestionMark && starCount == 0) goto foundType;	// it is a parse error
            }
            else if (curtok.ID == TokenID.RParen)
            {
                if (hasQuestionMark || starCount > 0) goto foundType;
            }
            else if (curtok.ID == TokenID.LBracket)
            {
                Advance();
                hasBracket = true;
                if (hasQuestionMark || starCount > 0 || curtok.ID == TokenID.Comma || curtok.ID == TokenID.RBracket) goto foundType;
            }

            //
            // treat as expression
            //
            if (hasQuestionMark)
            {
                // hasBracket is false
                ExpressionNode trueExpr = ParseSubexpression(starCount > 0 ? (int)PRECEDENCE_UNARY : 1);
                while (starCount-- > 0)
                    trueExpr = new DereferenceExpression(trueExpr);
                AssertAndAdvance(TokenID.Colon);
                return new ConditionalExpression(expr, trueExpr, ParseExpression());
            }
            else if (starCount > 0)
            {
                // hasBracket is false
                starCount--;
                ExpressionNode right = ParseSubexpression(starCount > 0 ? PRECEDENCE_UNARY : PRECEDENCE_MULTIPLICATIVE + ASSOC_LEFT);
                while (starCount-- > 0)
                    right = new DereferenceExpression(right);
                expr = new BinaryExpression(TokenID.Star, expr, right);
            }
            else if (hasBracket)
            {
                expr = new ElementAccessExpression(expr, ParseExpressionList());
                AssertAndAdvance(TokenID.RBracket);
            }
            return ParseSubexpression(1, expr);


            //
        // treat as type
        //
        foundType:
            TypeNode typeNode = new TypeNode(expr);
            if (hasQuestionMark)
                typeNode.IsNullableType = true;
            while (starCount-- > 0)
                typeNode = new TypePointerNode(typeNode);
            if (hasBracket)
            {
                while (true)
                {
                    int numCommas = 0;
                    while (curtok.ID == TokenID.Comma)
                    {
                        Advance();
                        numCommas++;
                    }
                    AssertAndAdvance(TokenID.RBracket);
                    typeNode.RankSpecifiers.Add(numCommas);

                    if (curtok.ID != TokenID.LBracket) break;
                    Advance();
                }
            }
            return typeNode;
        }
Example #20
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 BaseNode ParseField(IType type, QualifiedIdentifierExpression name)
        {
            uint mask = ~(uint)Modifier.FieldMods;
            if (((uint)curmods & mask) != (uint)Modifier.Empty)
                ReportError("field declaration contains illegal modifiers");

            FieldNode node = new FieldNode(curtok);
            ClassNode cl = typeStack.Peek();
            cl.Fields.Add(node);

            Modifier fieldMods = curmods;
            curmods = Modifier.Empty;

            node.Modifiers = fieldMods;

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

            node.IsUnsafe = isUnsafe > 0;

            CheckStaticClass(cl, node.Modifiers, true);

            ApplyAttributes(node);
            ApplyDocComment(node);

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

            while (true)
            {
                nameTable.AddIdentifier(new FieldName(name.QualifiedIdentifier,
                    ToVisibilityRestriction(node.Modifiers),
                    ((node.Modifiers & Modifier.Static) != Modifier.Static ? Scope.Instance : Scope.Static),
                    currentContext));

                //eg: int ok = 0, error, xx = 0;
                if (curtok.ID == TokenID.Equal)
                {
                    Advance();

                    if (curtok.ID == TokenID.LCurly)
                        node.Value = ParseArrayInitializer();
                    else
                        node.Value = ParseExpression();

                    if (curtok.ID == TokenID.Comma)
                    {
                        node = new FieldNode(curtok);
                        typeStack.Peek().Fields.Add(node);
                        node.Modifiers = fieldMods;
                        node.Type = type;
                    }
                }
                if (curtok.ID != TokenID.Comma) break;

                Advance(); // over comma
                QualifiedIdentifierExpression ident = ParseQualifiedIdentifier(false, false, true);
                node.Names.Add(ident);
            }

            AssertAndAdvance(TokenID.Semi);

            return node;
        }