Beispiel #1
0
        public static IModuleBlock GetModuleBlock(this IModuleDeclaration moduleDeclaration)
        {
            var resultCandidate = moduleDeclaration.Body.AsModuleBlock();

            if (resultCandidate != null)
            {
                return(resultCandidate);
            }

            return(GetModuleBlock(moduleDeclaration.Body));
        }
Beispiel #2
0
        private void AnalyzeNamespaceDeclaration(IModuleDeclaration source)
        {
            // Namespace name could be chained together in a form of 'namespace A.B'
            // in this case we need to get full name, not just source.Name.Text
            string fullName = string.Join(".", source.GetFullName());

            AddOrCreateDeclarationSymbol(SymbolKind.NamespaceDeclaration, fullName);

            using (m_currentLocationStack.AutoPush(fullName))
            {
                AnalyzeDeclarationStatements(source.GetModuleBlock().Statements);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns set of identifiers for module declaration.
        /// </summary>
        public static IEnumerable <IdentifierOrLiteralExpression> CompoundName(IModuleDeclaration moduleDeclaration)
        {
            yield return(moduleDeclaration.Name);

            var nestedModule = moduleDeclaration.Body.AsModuleDeclaration();

            if (nestedModule != null)
            {
                foreach (var n in CompoundName(nestedModule))
                {
                    yield return(n);
                }
            }
        }
Beispiel #4
0
        /// <nodoc/>
        public static IEnumerable <SymbolInformation> GetModuleDeclarationChildren(IModuleDeclaration moduleDeclaration, Uri uri)
        {
            // dive into the module, grab the full namespace name and list all the exported variables
            var namespacePrefix = moduleDeclaration.GetFullNameString() + ".";

            return(moduleDeclaration.GetModuleBlock().GetChildNodes()
                   .Where(childNode => childNode.IsTopLevelOrNamespaceLevelDeclaration())
                   .Where(childNode => !childNode.IsInjectedForDScript())
                   .Select(childNode => new SymbolInformation()
            {
                Name = namespacePrefix + GetIdentifierForNode(childNode),
                Kind = GetSymbolKind(childNode),
                Location = new Location()
                {
                    Uri = uri,
                    Range = childNode.ToRange(),
                },
            }));
        }
Beispiel #5
0
        internal static ILocalIdentifierScope AddModule(this IContext context, IModuleDeclaration moduleDeclaration)
        {
            var existing = context.Identifiers[moduleDeclaration.Name];

            if (existing == null)
            {
                var newInstance = new ModuleInstance(moduleDeclaration);
                context.Identifiers.Add(newInstance);
                return(newInstance.Identifiers);
            }
            else if (existing is IModuleInstance instance)
            {
                instance.Declarations.Add(moduleDeclaration);
                return(instance.Identifiers);
            }
            else
            {
                // TODO: report error name clash!
                return(null);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Returns a full name for compound namespace.
 /// </summary>
 /// <remarks>
 /// This property returns A.B for 'namespace A.B {}' declaration.
 /// Technically, such a declaration is nested and has 'A' as a name and IModuleDeclaration as a body.
 /// </remarks>
 public static IEnumerable <string> GetFullName(this IModuleDeclaration moduleDeclaration)
 {
     return(CompoundName(moduleDeclaration).Select(m => m.Text));
 }
Beispiel #7
0
 /// <summary>
 /// Returns a full name for compound namespace.
 /// </summary>
 /// <remarks>
 /// This method returns A.B for 'namespace A.B {}' declaration.
 /// </remarks>
 public static string GetFullNameString(this IModuleDeclaration moduleDeclaration)
 {
     return(string.Join(".", moduleDeclaration.GetFullName()));
 }
Beispiel #8
0
 public ModuleInstance(IModuleDeclaration decl)
 {
     Name = decl.Name;
     Declarations.Add(decl);
 }
 /// <inheritdoc />
 public override void VisitModuleDeclaration(IModuleDeclaration node)
 {
     Register(node, node.Flags, DocNodeType.Namespace, node.Name.Text, base.VisitModuleDeclaration);
 }