예제 #1
0
파일: DNode.cs 프로젝트: EnergonV/D_Parser
 public bool ContainsAttribute(DAttribute attr)
 {
     if(attr is Modifier)
         return ContainsAttribute((attr as Modifier).Token);
     else if(attr is BuiltInAtAttribute)
         return ContainsPropertyAttribute((attr as BuiltInAtAttribute).Kind);
     else if(attr is UserDeclarationAttribute)
         return ContainsPropertyAttribute((attr as UserDeclarationAttribute).AttributeExpression);
     return false;
 }
예제 #2
0
파일: DNode.cs 프로젝트: Orvid/D_Parser
 public bool ContainsAttribute(DAttribute attr)
 {
     if (attr is Modifier)
     {
         return(ContainsAttribute((attr as Modifier).Token));
     }
     else if (attr is BuiltInAtAttribute)
     {
         return(ContainsPropertyAttribute((attr as BuiltInAtAttribute).Kind));
     }
     else if (attr is UserDeclarationAttribute)
     {
         return(ContainsPropertyAttribute((attr as UserDeclarationAttribute).AttributeExpression));
     }
     return(false);
 }
예제 #3
0
        public static DModule ParseMixinDeclaration(MixinStatement mx, ResolutionContext ctxt)
        {
            ISyntaxRegion sr;
            var literal = GetMixinContent(mx, ctxt, false, out sr);

            if(sr is DModule)
                return (DModule)sr;
            else if(literal == null)
                return null;

            var ast = (DModule)DParser.ParseString(literal, true);
            mixinDeclCache.Add(ctxt, mx, ast);

            if(ast == null)
                return null;

            foreach(var ch in ast)
            {
                if(mx.Attributes!=null)
                {
                    var dn = ch as DNode;
                    if(dn!=null)
                    {
                        if(dn.Attributes==null)
                            dn.Attributes = new List<DAttribute>(mx.Attributes);
                        else
                            dn.Attributes.AddRange(mx.Attributes);
                    }
                }
                ch.Parent = mx.ParentNode;
            }

            if(mx.Attributes!=null)
                foreach(var ss in ast.StaticStatements)
                {
                    if(ss.Attributes == null)
                        ss.Attributes = mx.Attributes;
                    else{
                        var attrs = new DAttribute[mx.Attributes.Length + ss.Attributes.Length];
                        mx.Attributes.CopyTo(attrs,0);
                        ss.Attributes.CopyTo(attrs,mx.Attributes.Length);
                    }
                }

            return ast;
        }
예제 #4
0
        static bool CanShowAttribute(DAttribute attr, bool showStorageClasses)
        {
            if (attr is DeclarationCondition)
                return false;

            var mod = attr as Modifier;
            if (showStorageClasses || mod == null)
                return true;

            switch (mod.Token)
            {
                case DTokens.Auto:
                case DTokens.Enum:
                    return false;
                default:
                    return true;
            }
        }
예제 #5
0
 /// <summary>
 /// Checks if modifier array contains member attributes. If so, it returns the last found attribute. Otherwise 0.
 /// </summary>
 /// <param name="mods"></param>
 /// <returns></returns>
 public static DAttribute ContainsStorageClass(DAttribute[] mods)
 {
     var r=DAttribute.Empty;
     foreach (var attr in mods)
     {
         if (attr.IsStorageClass || attr.IsProperty)
             r = attr;
     }
     return r;
 }
예제 #6
0
        List<INode> Decl(IBlockNode Scope, DAttribute StorageClass = null)
        {
            var startLocation = la.Location;
            var initialComment = GetComments();
            ITypeDeclaration ttd = null;

            CheckForStorageClasses(Scope);

            // Autodeclaration
            if(StorageClass == null)
                StorageClass = DTokens.ContainsStorageClass(DeclarationAttributes);

            if (laKind == Enum)
            {
                Step();
                PushAttribute(StorageClass = new Modifier(Enum) { Location = t.Location, EndLocation = t.EndLocation },false);
            }

            // If there's no explicit type declaration, leave our node's type empty!
            if ((StorageClass != Modifier.Empty &&
                laKind == (Identifier) && (DeclarationAttributes.Count > 0 || Lexer.CurrentPeekToken.Kind == OpenParenthesis))) // public auto var=0; // const foo(...) {}
            {
                if (Lexer.CurrentPeekToken.Kind == Assign || Lexer.CurrentPeekToken.Kind ==OpenParenthesis)
                { }
                else if (Lexer.CurrentPeekToken.Kind == Semicolon)
                {
                    SemErr(t.Kind, "Initializer expected for auto type, semicolon found!");
                }
                else
                    ttd = BasicType();
            }
            else if(!IsEOF)
                ttd = BasicType();

            if (IsEOF)
            {
                /*
                 * T! -- tix.Arguments == null
                 * T!(int, -- last argument == null
                 * T!(int, bool, -- ditto
                 * T!(int) -- now every argument is complete
                 */
                var tix=ttd as TemplateInstanceExpression;
                if (tix != null) {
                    if (tix.Arguments == null || tix.Arguments.Length == 0 ||
                        (tix.Arguments [tix.Arguments.Length - 1] is TokenExpression &&
                        (tix.Arguments [tix.Arguments.Length - 1] as TokenExpression).Token == DTokens.INVALID)) {
                        return null;
                    }
                } else if (ttd is MemberFunctionAttributeDecl && (ttd as MemberFunctionAttributeDecl).InnerType == null) {
                    return null;
                }
            }

            // Declarators
            var firstNode = Declarator(ttd,false, Scope);
            if (firstNode == null)
                return null;
            firstNode.Description = initialComment;
            firstNode.Location = startLocation;

            // Check for declaration constraints
            if (laKind == (If))
                Constraint(firstNode);

            // BasicType Declarators ;
            if (laKind==Assign || laKind==Comma || laKind==Semicolon)
            {
                // DeclaratorInitializer
                if (laKind == (Assign))
                {
                    var init = Initializer (Scope);
                    var dv = firstNode as DVariable;
                    if (dv != null)
                        dv.Initializer = init;
                }
                firstNode.EndLocation = t.EndLocation;
                var ret = new List<INode>();
                ret.Add(firstNode);

                // DeclaratorIdentifierList
                while (laKind == Comma)
                {
                    Step();
                    if (IsEOF || Expect (Identifier)) {
                        var otherNode = new DVariable ();

                        // Note: In DDoc, all declarations that are made at once (e.g. int a,b,c;) get the same pre-declaration-description!
                        otherNode.Description = initialComment;

                        otherNode.AssignFrom (firstNode);
                        otherNode.Location = t.Location;
                        if (t.Kind == DTokens.Identifier)
                            otherNode.Name = t.Value;
                        else if(IsEOF)
                            otherNode.NameHash = IncompleteIdHash;
                        otherNode.NameLocation = t.Location;

                        if (laKind == OpenParenthesis)
                            TemplateParameterList (otherNode);

                        if (laKind == Assign)
                            otherNode.Initializer = Initializer (Scope);

                        otherNode.EndLocation = t.EndLocation;
                        ret.Add (otherNode);
                    } else
                        break;
                }

                Expect(Semicolon);

                // Note: In DDoc, only the really last declaration will get the post semicolon comment appended
                if (ret.Count > 0)
                    ret[ret.Count - 1].Description += CheckForPostSemicolonComment();

                return ret;
            }

            // BasicType Declarator FunctionBody
            else if (firstNode is DMethod && (IsFunctionBody || IsEOF))
            {
                firstNode.Description += CheckForPostSemicolonComment();

                FunctionBody((DMethod)firstNode);

                firstNode.Description += CheckForPostSemicolonComment();

                var ret = new List<INode> ();
                ret.Add (firstNode);
                return ret;
            }
            else
                SynErr(OpenCurlyBrace, "; or function body expected after declaration stub.");

            if (IsEOF)
                return new List<INode>{ firstNode };

            return null;
        }
예제 #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="module"></param>
        /// <param name="previouslyParsedAttribute"></param>
        /// <param name="RequireDeclDef">If no colon and no open curly brace is given as lookahead, a DeclDef may be parsed otherwise, if parameter is true.</param>
        /// <returns></returns>
        IMetaDeclaration AttributeTrail(DBlockNode module, DAttribute previouslyParsedAttribute, bool RequireDeclDef = false)
        {
            if (laKind == Colon)
            {
                Step();
                PushAttribute(previouslyParsedAttribute, true);

                AttributeMetaDeclarationSection metaDecl = null;
                //TODO: Put all remaining block/decl(?) attributes into the section definition..
                if(module!=null)
                    module.Add(metaDecl = new AttributeMetaDeclarationSection(previouslyParsedAttribute) { EndLocation = t.EndLocation });
                return metaDecl;
            }
            else
                PushAttribute(previouslyParsedAttribute, false);

            if (laKind == OpenCurlyBrace)
                return AttributeBlock(module);
            else
            {
                if (IsEOF && module != null && previouslyParsedAttribute != null) // To enable attribute completion, add dummy node
                    module.Add (new DVariable{ Attributes = new List<DAttribute>{ previouslyParsedAttribute } });

                if (RequireDeclDef)
                    DeclDef(module);
                return new AttributeMetaDeclaration(previouslyParsedAttribute) { EndLocation = previouslyParsedAttribute.EndLocation };
            }
        }
예제 #8
0
        private void AttributeSpecifier()
        {
            var attr = new DAttribute(laKind,la.Value);
            LastParsedObject = attr;
            if (laKind == Extern && Lexer.CurrentPeekToken.Kind == OpenParenthesis)
            {
                Step(); // Skip extern
                Step(); // Skip (

                TrackerVariables.ExpectingIdentifier = true;
                var n = "";
                while (!IsEOF && laKind != CloseParenthesis)
                {
                    Step();
                    n += t.ToString();

                    TrackerVariables.ExpectingIdentifier = false;

                    if (t.Kind == Identifier && laKind == Identifier)
                        n += ' ';
                }

                attr.LiteralContent = n;

                if (!Expect(CloseParenthesis))
                    return;
            }
            else if (laKind == Align && Lexer.CurrentPeekToken.Kind == OpenParenthesis)
            {
                Step();
                Step();
                if (Expect(Literal))
                    attr.LiteralContent = new IdentifierExpression(t.LiteralValue, t.LiteralFormat);

                if (!Expect(CloseParenthesis))
                    return;
            }
            else if (laKind == Pragma)
                 attr=_Pragma();
            else
                Step();

            if (laKind == Colon)
            {
                PushAttribute(attr, true);
                Step();
                LastParsedObject = null;
            }

            else if (laKind != Semicolon)
                PushAttribute(attr, false);
        }
예제 #9
0
        /// <summary>
        /// Note:
        /// http://www.digitalmars.com/d/2.0/declaration.html#DeclaratorSuffix
        /// The definition of a sequence of declarator suffixes is buggy here! Theoretically template parameters can be declared without a surrounding ( and )!
        /// Also, more than one parameter sequences are possible!
        /// 
        /// TemplateParameterList[opt] Parameters MemberFunctionAttributes[opt]
        /// </summary>
        ITypeDeclaration DeclaratorSuffixes(out ITemplateParameter[] TemplateParameters, out List<INode> _Parameters, List<DAttribute> _Attributes)
        {
            DAttribute attr = null;
            ITypeDeclaration td = null;
            TemplateParameters = null;
            _Parameters = null;

            while (MemberFunctionAttribute[laKind])
            {
                _Attributes.Add(attr=new DAttribute(laKind, la.Value));
                LastParsedObject = attr;
                Step();
            }

            while (laKind == (OpenSquareBracket))
            {
                Step();
                var ad = new ArrayDecl() { Location=t.Location };
                LastParsedObject = ad;
                ad.InnerDeclaration = td;
                if (laKind != (CloseSquareBracket))
                {
                    ad.ClampsEmpty = false;
                    ITypeDeclaration keyType=null;
                    var la_backup = la;
                    if (!IsAssignExpression())
                    {

                        var weakType = AllowWeakTypeParsing;
                        AllowWeakTypeParsing = true;

                        keyType= ad.KeyType = Type();

                        AllowWeakTypeParsing = weakType;
                    }
                    if (keyType == null || laKind != CloseSquareBracket)
                    {
                        keyType = ad.KeyType = null;
                        la = la_backup;
                        ad.KeyExpression = AssignExpression();
                    }
                }
                Expect(CloseSquareBracket);
                ad.EndLocation = t.EndLocation;
                td = ad;
            }

            if (laKind == (OpenParenthesis))
            {
                if (IsTemplateParameterList())
                {
                    TemplateParameters = TemplateParameterList();
                }
                _Parameters = Parameters(null);

                while (StorageClass[laKind] || laKind==PropertyAttribute)
                {
                    _Attributes.Add(attr=new DAttribute(laKind, la.Value));
                    LastParsedObject = attr;
                    Step();
                }
            }

            while (MemberFunctionAttribute[laKind])
            {
                _Attributes.Add(attr=new DAttribute(laKind,la.Value));
                LastParsedObject = attr;
                Step();
            }
            return td;
        }
예제 #10
0
 public static bool ContainsAttribute(DAttribute[] HayStack,params int[] NeedleToken)
 {
     var l = new List<int>(NeedleToken);
     if(HayStack!=null)
         foreach (var attr in HayStack)
             if (l.Contains(attr.Token))
                 return true;
     return false;
 }
예제 #11
0
 public virtual void VisitAttribute(DAttribute attribute)
 {
 }
예제 #12
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="module"></param>
		/// <param name="previouslyParsedAttribute"></param>
		/// <param name="RequireDeclDef">If no colon and no open curly brace is given as lookahead, a DeclDef may be parsed otherwise, if parameter is true.</param>
		/// <returns></returns>
		IMetaDeclaration AttributeSpecifier(DBlockNode module, DAttribute previouslyParsedAttribute, bool RequireDeclDef = false)
		{
			DAttribute[] attrs;

			if (laKind == Colon)
			{
				Step();
				PushAttribute(previouslyParsedAttribute, true);

				attrs = new DAttribute[1 + DeclarationAttributes.Count];
				DeclarationAttributes.CopyTo(attrs, 0);
				DeclarationAttributes.Clear();
				attrs[attrs.Length - 1] = previouslyParsedAttribute;

				AttributeMetaDeclarationSection metaDecl = null;
				//TODO: Put all remaining block/decl(?) attributes into the section definition..
				if(module!=null)
					module.Add(metaDecl = new AttributeMetaDeclarationSection(attrs) { EndLocation = t.EndLocation });
				return metaDecl;
			}
			else 
				PushAttribute(previouslyParsedAttribute, false);

			if (laKind == OpenCurlyBrace)
				return AttributeBlock(module);
			else
			{
				if (IsEOF && module != null && previouslyParsedAttribute != null) // To enable attribute completion, add dummy node
					module.Add (new DVariable{ Attributes = new List<DAttribute>{ previouslyParsedAttribute } });

				if (RequireDeclDef)
				{
					DeclDef(module);

					attrs = new DAttribute[1 + DeclarationAttributes.Count];
					DeclarationAttributes.CopyTo(attrs, 0);
					DeclarationAttributes.Clear();
					attrs[attrs.Length - 1] = previouslyParsedAttribute;

					return new AttributeMetaDeclaration(attrs) { EndLocation = previouslyParsedAttribute.EndLocation };
				}
			}

			return null;
		}
예제 #13
0
        private void AttributeSpecifier()
        {
            var attr = new DAttribute(laKind,la.Value);
            if (laKind == (Extern) && Lexer.CurrentPeekToken.Kind == (OpenParenthesis))
            {
                Step(); // Skip extern
                Step(); // Skip (
                while (!IsEOF && laKind != (CloseParenthesis))
                    Step();
                Expect(CloseParenthesis);
            }
            else if (laKind == (Align) && Lexer.CurrentPeekToken.Kind == (OpenParenthesis))
            {
                Step();
                Step();
                Expect(Literal);
                Expect(CloseParenthesis);
            }
            else if (laKind == (Pragma))
                _Pragma();
            else
                Step();

            if (laKind == (Colon))
            {
                PushAttribute(attr, true);
                Step();
            }

            else if (laKind != Semicolon)
                PushAttribute(attr,false);
        }
예제 #14
0
파일: DNode.cs 프로젝트: nazriel/Mono-D
 public bool ContainsAttribute(params int[] Token)
 {
     return(DAttribute.ContainsAttribute(Attributes, Token));
 }
예제 #15
0
파일: Parser.cs 프로젝트: EnergonV/D_Parser
        void PushAttribute(DAttribute attr, bool BlockAttributes)
        {
            var stk=BlockAttributes?this.BlockAttributes:this.DeclarationAttributes;

            var m = attr as Modifier;
            if(m!=null)
            // If attr would change the accessability of an item, remove all previously found (so the most near attribute that's next to the item is significant)
            if (DTokens.VisModifiers[m.Token])
                Modifier.CleanupAccessorAttributes(stk, m.Token);
            else
                Modifier.RemoveFromStack(stk, m.Token);

            stk.Push(attr);
        }
예제 #16
0
        void PushAttribute(DAttribute attr, bool BlockAttributes)
        {
            var stk=BlockAttributes?this.BlockAttributes:this.DeclarationAttributes;

            // If attr would change the accessability of an item, remove all previously found (so the most near attribute that's next to the item is significant)
            if (DTokens.VisModifiers[attr.Token])
                DAttribute.CleanupAccessorAttributes(stk, attr.Token);
            else
                DAttribute.RemoveFromStack(stk, attr.Token);

            LastParsedObject = attr;

            stk.Push(attr);
        }
		public AttributeCompletionProvider(DAttribute attr,ICompletionDataGenerator gen) : base(gen) {
			this.Attribute = attr;
		}