示例#1
0
文件: DType.cs 项目: DinrusGroup/DRC
        public EponymousTemplateType(EponymousTemplate ep,
			ReadOnlyCollection<TemplateParameterSymbol> deducedTypes = null, ISyntaxRegion td = null)
            : base(ep, null, deducedTypes, td)
        {
        }
示例#2
0
文件: DType.cs 项目: windygu/DSharp
 public EponymousTemplateType(EponymousTemplate ep,
                              ReadOnlyCollection <TemplateParameterSymbol> deducedTypes = null, ISyntaxRegion td = null) : base(ep, null, deducedTypes, td)
 {
 }
示例#3
0
 public string Visit(EponymousTemplate ep)
 {
     return(TemplateType);
 }
示例#4
0
        INode[] AliasDeclaration(IBlockNode Scope)
        {
            Step();
            // _t is just a synthetic node which holds possible following attributes
            var _t = new DVariable();
            ApplyAttributes(_t);
            _t.Description = GetComments();
            List<INode> decls;

            // AliasThis
            if ((laKind == Identifier && Lexer.CurrentPeekToken.Kind == This) ||
                (laKind == This && Lexer.CurrentPeekToken.Kind == Assign))
                return new[]{AliasThisDeclaration(_t, Scope)};

            // AliasInitializerList
            else if(laKind == Identifier && (Lexer.CurrentPeekToken.Kind == Assign ||
                (Lexer.CurrentPeekToken.Kind == OpenParenthesis && OverPeekBrackets(OpenParenthesis) && Lexer.CurrentPeekToken.Kind == Assign)))
            {
                decls = new List<INode>();
                do{
                    if(laKind == Comma)
                        Step();
                    if(!Expect(Identifier))
                        break;
                    var dv = new DVariable{
                        IsAlias = true,
                        Attributes = _t.Attributes,
                        Description = _t.Description,
                        Name = t.Value,
                        NameLocation = t.Location,
                        Location = t.Location,
                        Parent = Scope
                    };

                    if(laKind == OpenParenthesis){
                        var ep = new EponymousTemplate();
                        ep.AssignFrom(dv);
                        dv = ep;
                        TemplateParameterList(ep);
                    }

                    if(Expect(Assign))
                    {
                        Lexer.PushLookAheadBackup();
                        var wkTypeParsingBackup = AllowWeakTypeParsing;
                        AllowWeakTypeParsing = true;
                        dv.Type = Type();
                        AllowWeakTypeParsing = wkTypeParsingBackup;
                        if(!(laKind == Comma || laKind == Semicolon))
                        {
                            Lexer.RestoreLookAheadBackup();
                            dv.Initializer = AssignExpression(Scope);
                        }
                        else
                            Lexer.PopLookAheadBackup();
                    }
                    decls.Add(dv);
                }
                while(laKind == Comma);

                Expect(Semicolon);
                decls[decls.Count-1].Description += CheckForPostSemicolonComment();
                return decls.ToArray();
            }

            // alias BasicType Declarator
            decls=Decl(Scope, laKind != Identifier || Lexer.CurrentPeekToken.Kind != OpenParenthesis ? null : new Modifier(DTokens.Alias));

            if(decls!=null){
                foreach (var n in decls) {
                    var dv = n as DVariable;
                    if (dv != null) {
                        if (n.NameHash == DTokens.IncompleteIdHash && n.Type == null) // 'alias |' shall trigger completion, 'alias int |' not
                            n.NameHash = 0;
                        dv.Attributes.AddRange (_t.Attributes);
                        dv.IsAlias = true;
                    }
                }

                decls[decls.Count-1].Description += CheckForPostSemicolonComment();
                return decls.ToArray ();
            }
            return null;
        }
示例#5
0
        /// <summary>
        /// Parses a type declarator
        /// </summary>
        /// <returns>A dummy node that contains the return type, the variable name and possible parameters of a function declaration</returns>
        DNode Declarator(ITypeDeclaration basicType,bool IsParam, INode parent)
        {
            DNode ret = new DVariable() { Type=basicType, Location = la.Location, Parent = parent };
            ApplyAttributes (ret);

            while (IsBasicType2())
            {
                if (ret.Type == null)
                    ret.Type = BasicType2();
                else {
                    var ttd = BasicType2();
                    if(ttd!=null)
                        ttd.InnerDeclaration = ret.Type;
                    ret.Type = ttd;
                }
            }

            if (laKind != (OpenParenthesis))
            {
                // On external function declarations, no parameter names are required.
                // extern void Cfoo(HANDLE,char**);
                if (IsParam && laKind != (Identifier))
                {
                    if ((!(ret.Type is DTokenDeclaration) ||
                        (ret.Type as DTokenDeclaration).Token != DTokens.Incomplete) && IsEOF)
                        ret.NameHash = DTokens.IncompleteIdHash;
                    return ret;
                }

                if (Expect(Identifier))
                {
                    ret.Name = t.Value;
                    ret.NameLocation = t.Location;

                    // enum asdf(...) = ...;
                    if (laKind == OpenParenthesis && OverPeekBrackets(DTokens.OpenParenthesis, true) &&
                        Lexer.CurrentPeekToken.Kind == Assign)
                    {
                        var eponymousTemplateDecl = new EponymousTemplate ();
                        eponymousTemplateDecl.AssignFrom (ret);
                        ret = eponymousTemplateDecl;

                        TemplateParameterList (eponymousTemplateDecl);

                        return ret;
                    }
                }
                else
                {
                    if (IsEOF)
                    {
                        ret.NameHash = DTokens.IncompleteIdHash;
                        return ret;
                    }

                    return null;
                    // Code error! - to prevent infinite declaration loops, step one token forward anyway!
                    if(laKind != CloseCurlyBrace && laKind != CloseParenthesis)
                        Step();
                    return null;
                }
            }
            else
                OldCStyleFunctionPointer(ret, IsParam);

            if (IsDeclaratorSuffix || IsFunctionAttribute)
            {
                var dm = new DMethod { Parent = parent, Parameters = null };
                dm.AssignFrom(ret);

                DeclaratorSuffixes(dm);

                if (dm.Parameters != null)
                    ret = dm;
            }

            return ret;
        }
 public virtual void Visit(EponymousTemplate ep)
 {
     Visit(ep as DVariable);
 }
示例#7
0
 public AbstractType Visit(EponymousTemplate ep)
 {
     return(new EponymousTemplateType(ep, GetInvisibleTypeParameters(ep).AsReadOnly(), typeBase));
 }
示例#8
0
        /// <summary>
        /// Parses a type declarator
        /// </summary>
        /// <returns>A dummy node that contains the return type, the variable name and possible parameters of a function declaration</returns>
        DNode Declarator(ITypeDeclaration basicType,bool IsParam, INode parent)
        {
            DNode ret = new DVariable() { Type=basicType, Location = la.Location, Parent = parent };
            ApplyAttributes (ret);
            LastParsedObject = ret;

            while (IsBasicType2())
            {
                if (ret.Type == null)
                    ret.Type = BasicType2();
                else {
                    var ttd = BasicType2();
                    if(ttd!=null)
                        ttd.InnerDeclaration = ret.Type;
                    ret.Type = ttd;
                }
            }

            // Only return no variable if the BasicType2 wasn't parsed properly to ensure good code completion
            if (IsEOF && ret != LastParsedObject)
                return null;

            if (laKind != (OpenParenthesis))
            {
                // On external function declarations, no parameter names are required.
                // extern void Cfoo(HANDLE,char**);
                if (IsParam && laKind != (Identifier))
                {
                    if(ret.Type!=null && IsEOF)
                        ExpectingNodeName = true;
                    return ret;
                }

                if (Expect(Identifier))
                {
                    ret.Name = t.Value;
                    ret.NameLocation = t.Location;

                    if (laKind == OpenParenthesis && ret.Type == null) {
                        OverPeekBrackets (DTokens.OpenParenthesis, true);

                        var k = Lexer.LastToken.Kind;
                        if (k == DTokens.Alias || k == DTokens.Enum) {
                            if (ret.Attributes == null)
                                ret.Attributes = new List<DAttribute> ();
                            ret.Attributes.Add (new Modifier (k));
                        }

                        // enum asdf(...) = ...;
                        if (Lexer.CurrentPeekToken.Kind == Assign) {
                            var eponymousTemplateDecl = new EponymousTemplate ();
                            eponymousTemplateDecl.AssignFrom (ret);
                            ret = eponymousTemplateDecl;

                            TemplateParameterList (eponymousTemplateDecl);

                            return ret;
                        }
                    }
                }
                else
                {
                    if (IsEOF || IsParam)
                    {
                        ExpectingNodeName = true;
                        return ret;
                    }

                    return null;
                    // Code error! - to prevent infinite declaration loops, step one token forward anyway!
                    if(laKind != CloseCurlyBrace && laKind != CloseParenthesis)
                        Step();
                    return null;
                }
            }
            else
                OldCStyleFunctionPointer(ret, IsParam);

            if (IsDeclaratorSuffix || IsFunctionAttribute)
            {
                var dm = new DMethod { Parent = parent, Parameters = null };
                dm.AssignFrom(ret);
                LastParsedObject = dm;

                DeclaratorSuffixes(dm);

                if (dm.Parameters != null)
                    ret = dm;
                else
                    LastParsedObject = ret;
            }

            return ret;
        }
示例#9
0
文件: DIcons.cs 项目: lenoil98/Mono-D
 public IconId Visit(EponymousTemplate n)
 {
     return(iconIdWithProtectionAttr(n, "template"));
 }
示例#10
0
		IEnumerable<INode> AliasDeclaration(IBlockNode Scope)
		{
			Step();
			// _t is just a synthetic node which holds possible following attributes
			var _t = new DVariable();
			ApplyAttributes(_t);
			_t.Description = GetComments();

			// AliasThis
			if ((laKind == Identifier && Lexer.CurrentPeekToken.Kind == This) ||
				(laKind == This && Lexer.CurrentPeekToken.Kind == Assign)){
				yield return AliasThisDeclaration(_t, Scope);
				yield break;
			}

			// AliasInitializerList
			else if(laKind == Identifier && (Lexer.CurrentPeekToken.Kind == Assign || 
				(Lexer.CurrentPeekToken.Kind == OpenParenthesis && OverPeekBrackets(OpenParenthesis) && Lexer.CurrentPeekToken.Kind == Assign)))
			{
				DVariable dv = null;
				do{
					if(laKind == Comma)
						Step();
					if(!Expect(Identifier))
						break;
					dv = new DVariable{
						IsAlias = true,
						Attributes = _t.Attributes,
						Description = _t.Description,
						Name = t.Value,
						NameLocation = t.Location,
						Location = t.Location,
						Parent = Scope
					};

					if(laKind == OpenParenthesis){
						var ep = new EponymousTemplate();
						ep.AssignFrom(dv);
						dv = ep;
						TemplateParameterList(ep);
					}

					if(Expect(Assign))
					{
						// alias fnRtlAllocateHeap = extern(Windows) void* function(void* HeapHandle, uint Flags, size_t Size) nothrow;
						CheckForStorageClasses(Scope);
						ApplyAttributes(dv);

						Lexer.PushLookAheadBackup();
						var wkTypeParsingBackup = AllowWeakTypeParsing;
						AllowWeakTypeParsing = true;
						dv.Type = Type(Scope);
						AllowWeakTypeParsing = wkTypeParsingBackup;
						if(!(laKind == Comma || laKind == Semicolon))
						{
							Lexer.RestoreLookAheadBackup();
							dv.Initializer = AssignExpression(Scope);
						}
						else
							Lexer.PopLookAheadBackup();
					}
					yield return dv;
				}
				while(laKind == Comma);

				Expect(Semicolon);
				if(dv != null)
					dv.Description += CheckForPostSemicolonComment();
				yield break;
			}

			// alias BasicType Declarator
			foreach(var n in Decl(Scope, laKind != Identifier || Lexer.CurrentPeekToken.Kind != OpenParenthesis ? null : new Modifier(DTokens.Alias), true))
			{
				var dv = n as DVariable;
				if (dv != null) {
					if (n.NameHash == DTokens.IncompleteIdHash && n.Type == null) // 'alias |' shall trigger completion, 'alias int |' not
						n.NameHash = 0;
					dv.Attributes.AddRange (_t.Attributes);
					dv.IsAlias = true;
				}
				yield return n;
			}
		}
示例#11
0
		/// <summary>
		/// Parses a type declarator
		/// </summary>
		/// <returns>A dummy node that contains the return type, the variable name and possible parameters of a function declaration</returns>
		DNode Declarator(ITypeDeclaration basicType,bool IsParam, INode parent)
		{
			DNode ret = new DVariable() { Location = la.Location, Parent = parent };
			ApplyAttributes (ret);

			ParseBasicType2 (ref basicType, parent as IBlockNode);
			ret.Type = basicType;

			if (laKind != (OpenParenthesis))
			{
				// On external function declarations, no parameter names are required.
				// extern void Cfoo(HANDLE,char**);
				if (IsParam && laKind != (Identifier))
				{
					if(IsEOF)
					{
						var tokDecl = ret.Type as DTokenDeclaration;
						var ad = ret.Type as ArrayDecl;
						if ((tokDecl == null || tokDecl.Token != DTokens.Incomplete) && // 'T!|' or similar
							(ad == null || !(ad.KeyExpression is TokenExpression) || (ad.KeyExpression as TokenExpression).Token != DTokens.Incomplete)) // 'string[|'
							ret.NameHash = DTokens.IncompleteIdHash;
					}
					return ret;
				}

				if (Expect(Identifier))
				{
					ret.Name = t.Value;
					ret.NameLocation = t.Location;

					// enum asdf(...) = ...;
					if (laKind == OpenParenthesis && OverPeekBrackets(DTokens.OpenParenthesis, true) &&
						Lexer.CurrentPeekToken.Kind == Assign)
					{
						var eponymousTemplateDecl = new EponymousTemplate ();
						eponymousTemplateDecl.AssignFrom (ret);
						ret = eponymousTemplateDecl;

						TemplateParameterList (eponymousTemplateDecl);

						return ret;
					}
				}
				else
				{
					if (IsEOF)
					{
						ret.NameHash = DTokens.IncompleteIdHash;
						return ret;
					}

					return null;
					// Code error! - to prevent infinite declaration loops, step one token forward anyway!
					if(laKind != CloseCurlyBrace && laKind != CloseParenthesis)
						Step();
					return null;
				}
			}
			else
				OldCStyleFunctionPointer(ret, IsParam);

			if (IsDeclaratorSuffix || IsFunctionAttribute)
				DeclaratorSuffixes(ref ret);

			return ret;
		}
示例#12
0
 public ulong Visit(EponymousTemplate ep)
 {
     return(1000231);
 }
示例#13
0
 public CompletionItemKind Visit(EponymousTemplate n)
 {
     return(CompletionItemKind.TypeParameter);
 }
示例#14
0
 public byte Visit(EponymousTemplate ep)
 {
     return((byte)TypeReferenceKind.Template);
 }