Пример #1
0
        /// <summary>
        /// </summary>
        /// <param name="ast">Сканируемое синтаксическое дерево</param>
        /// <param name="symbol">Не может быть символом-пасынком АСТ</param>
        /// <param name="ctxt">Контекст, необходимый для поиска символов</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 == DSharp.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);
        }
Пример #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(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 == DSharp.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;
		}