Ejemplo n.º 1
0
        /// <summary>
        /// </summary>
        /// <param name="ast">The syntax tree to scan</param>
        /// <param name="symbol">Might not be a child symbol of ast</param>
        /// <param name="ctxt">The context required to search for symbols</param>
        /// <returns></returns>
        public static IEnumerable<ISyntaxRegion> Scan(DModule ast, INode symbol, ResolutionContext ctxt, bool includeDefinition = true)
        {
            if (ast == null || symbol == null || ctxt == null)
                return null;

            var f = new ReferencesFinder(symbol, ast, ctxt);

            using(ctxt.Push(ast))
                ast.Accept (f);

            var nodeRoot = symbol.NodeRoot as DModule;
            if (includeDefinition && nodeRoot != null && nodeRoot.FileName == ast.FileName)
            {
                var dc = symbol.Parent as DClassLike;
                if (dc != null && dc.ClassType == D_Parser.Parser.DTokens.Template &&
                    dc.NameHash == symbol.NameHash)
                {
                    f.l.Insert(0, new IdentifierDeclaration(dc.NameHash)
                        {
                            Location = dc.NameLocation,
                            EndLocation = new CodeLocation(dc.NameLocation.Column + dc.Name.Length, dc.NameLocation.Line)
                        });
                }

                f.l.Insert(0, new IdentifierDeclaration(symbol.NameHash)
                    {
                        Location = symbol.NameLocation,
                        EndLocation = new CodeLocation(symbol.NameLocation.Column + symbol.Name.Length,	symbol.NameLocation.Line)
                    });
            }

            return f.l;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="ast">The syntax tree to scan</param>
        /// <param name="symbol">Might not be a child symbol of ast</param>
        /// <param name="ctxt">The context required to search for symbols</param>
        /// <returns></returns>
        public static IEnumerable<ISyntaxRegion> Scan(IAbstractSyntaxTree ast, INode symbol, ResolverContextStack ctxt)
        {
            if (ast == null || symbol == null || ctxt == null)
                return null;

            ctxt.PushNewScope(ast);

            var f = new ReferencesFinder(symbol, ast, ctxt);

            f.S(ast);

            ctxt.Pop();

            return f.l;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <param name="ast">The syntax tree to scan</param>
        /// <param name="symbol">Might not be a child symbol of ast</param>
        /// <param name="ctxt">The context required to search for symbols</param>
        /// <returns></returns>
        public static IEnumerable <ISyntaxRegion> Scan(IAbstractSyntaxTree ast, INode symbol, ResolverContextStack ctxt)
        {
            if (ast == null || symbol == null || ctxt == null)
            {
                return(null);
            }

            ctxt.PushNewScope(ast);

            var f = new ReferencesFinder(symbol, ast, ctxt);

            f.S(ast);

            ctxt.Pop();

            return(f.l);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// </summary>
        /// <param name="ast">The syntax tree to scan</param>
        /// <param name="symbol">Might not be a child symbol of ast</param>
        /// <param name="ctxt">The context required to search for symbols</param>
        /// <returns></returns>
        public static IEnumerable <ISyntaxRegion> Scan(DModule ast, INode symbol, ResolutionContext ctxt, bool includeDefinition = true)
        {
            if (ast == null || symbol == null || ctxt == null)
            {
                return(null);
            }

            var f = new ReferencesFinder(symbol, ast, ctxt);

            using (ctxt.Push(ast))
                ast.Accept(f);

            var nodeRoot = symbol.NodeRoot as DModule;

            if (includeDefinition && nodeRoot != null && nodeRoot.FileName == ast.FileName)
            {
                var dc = symbol.Parent as DClassLike;
                if (dc != null && dc.ClassType == D_Parser.Parser.DTokens.Template &&
                    dc.NameHash == symbol.NameHash)
                {
                    f.l.Insert(0, new IdentifierDeclaration(dc.NameHash)
                    {
                        Location    = dc.NameLocation,
                        EndLocation = new CodeLocation(dc.NameLocation.Column + dc.Name.Length, dc.NameLocation.Line)
                    });
                }

                var  loc = symbol.NameLocation;
                bool add = !f.l.AsParallel().Any(
                    (o) => (o is TemplateParameter && (o as TemplateParameter).NameLocation == loc) ||
                    (o is INode && (o as INode).NameLocation == loc));

                if (add)
                {
                    f.l.Insert(0, new IdentifierDeclaration(symbol.NameHash)
                    {
                        Location    = loc,
                        EndLocation = new CodeLocation(loc.Column + symbol.Name.Length, loc.Line)
                    });
                }
            }

            return(f.l);
        }
Ejemplo n.º 5
0
		/// <summary>
		/// </summary>
		/// <param name="ast">The syntax tree to scan</param>
		/// <param name="symbol">Might not be a child symbol of ast</param>
		/// <param name="ctxt">The context required to search for symbols</param>
		/// <returns></returns>
		public static IEnumerable<ISyntaxRegion> SearchModuleForASTNodeReferences(DModule ast, INode symbol, ResolutionContext ctxt, bool includeDefinition = true)
		{
			if (ast == null || symbol == null || ctxt == null)
				return null;

			var f = new ReferencesFinder(symbol, ast, ctxt);

			using(ctxt.Push(ast))
				ast.Accept (f);

			var nodeRoot = symbol.NodeRoot as DModule;
			if (includeDefinition && nodeRoot != null && nodeRoot.FileName == ast.FileName)
			{
				var dc = symbol.Parent as DClassLike;
				if (dc != null && dc.ClassType == D_Parser.Parser.DTokens.Template &&
					dc.NameHash == symbol.NameHash)
				{
					f.l.Insert(0, new IdentifierDeclaration(dc.NameHash)
						{
							Location = dc.NameLocation,
							EndLocation = new CodeLocation(dc.NameLocation.Column + dc.Name.Length, dc.NameLocation.Line)
						});
				}

				var loc = symbol.NameLocation;
				bool add = !f.l.AsParallel().Any(
					(o) =>	(o is TemplateParameter && (o as TemplateParameter).NameLocation == loc) ||
							(o is INode && (o as INode).NameLocation == loc));

				if(add)
					f.l.Insert(0, new IdentifierDeclaration(symbol.NameHash)
						{
							Location = loc,
							EndLocation = new CodeLocation(loc.Column + symbol.Name.Length,	loc.Line)
						});
			}

			return f.l;
		}
Ejemplo n.º 6
0
        /// <summary>
        /// </summary>
        /// <param name="ast">The syntax tree to scan</param>
        /// <param name="symbol">Might not be a child symbol of ast</param>
        /// <param name="ctxt">The context required to search for symbols</param>
        /// <returns></returns>
        public static IEnumerable <ISyntaxRegion> Scan(DModule ast, INode symbol, ResolutionContext ctxt, bool includeDefinition = true)
        {
            if (ast == null || symbol == null || ctxt == null)
            {
                return(null);
            }

            ctxt.PushNewScope(ast);

            var f = new ReferencesFinder(symbol, ast, ctxt);

            ast.Accept(f);

            ctxt.Pop();

            var nodeRoot = symbol.NodeRoot as DModule;

            if (includeDefinition && nodeRoot != null && nodeRoot.FileName == ast.FileName)
            {
                var dc = symbol.Parent as DClassLike;
                if (dc != null && dc.ClassType == D_Parser.Parser.DTokens.Template &&
                    dc.NameHash == symbol.NameHash)
                {
                    f.l.Insert(0, new IdentifierDeclaration(dc.NameHash)
                    {
                        Location    = dc.NameLocation,
                        EndLocation = new CodeLocation(dc.NameLocation.Column + dc.Name.Length, dc.NameLocation.Line)
                    });
                }

                f.l.Insert(0, new IdentifierDeclaration(symbol.NameHash)
                {
                    Location    = symbol.NameLocation,
                    EndLocation = new CodeLocation(symbol.NameLocation.Column + symbol.Name.Length, symbol.NameLocation.Line)
                });
            }

            return(f.l);
        }