Ejemplo n.º 1
0
        /// <summary>
        /// Gets <see cref="AliasDefinition"/> by name.
        /// </summary>
        /// <param name="name">Alias name.</param>
        /// <returns>Returns instance of <see cref="AliasDefinition"/> or null if definition is not found.</returns>
        public AliasDefinition GetAliasDefinition(string name)
        {
            NsInfo resultInfo =
                ModuleMembersNsInfo.FirstOrDefault(a => (a.ModuleMember is DOM.AliasDefinition) && a.ModuleMember.Name == name);

            return((AliasDefinition)resultInfo?.ModuleMember);
        }
Ejemplo n.º 2
0
 private void CheckModuleMember(NsInfo nsInfo)
 {
     if (!(nsInfo.ModuleMember is Document))
     {
         ValidateAliasDefDefaultParameter((AliasDefinition)nsInfo.ModuleMember);
         return;
     }
 }
Ejemplo n.º 3
0
 private void ResolveAliasesInModuleMember(NsInfo nsInfo)
 {
     foreach (var alias in nsInfo.Aliases)
     {
         NsInfo aliasNsInfo = ResolveAliasInModuleMember((Alias)alias, nsInfo);
         if (aliasNsInfo == null)
         {
             continue;
         }
         MergeNsInfo(nsInfo, aliasNsInfo);
     }
 }
Ejemplo n.º 4
0
        private void MergeNsInfo(NsInfo destNsInfo, NsInfo nsInfo)
        {
            foreach (var ns in nsInfo.Namespaces)
            {
                var uri    = ns.Value;
                var destNs = destNsInfo.Namespaces.FirstOrDefault(n => n.Value == uri);

                if (destNs != null)
                {
                    continue;
                }

                var prefix = FindFreePrefix(ns.Name, destNsInfo.Namespaces);

                destNsInfo.Namespaces.Add(new NamespaceDefinition(prefix, AssignmentEnum.E, ns.Value));
            }
        }
Ejemplo n.º 5
0
        private NsInfo ResolveAliasInModuleMember(Alias alias, NsInfo memberNsInfo)
        {
            //Finding AliasDef
            var aliasDef = LookupAliasDef(alias);

            if (aliasDef == null)
            {
                //Report Error if alias is not defined
                //_context.AddError(CompilerErrorFactory.AliasIsNotDefined(alias, memberNsInfo.ModuleMember.Module.FileName));
                return(null);
            }

            if (aliasDef.IsValueNode != alias.IsValueNode && alias.IsValueNode)
            {
                _context.AddError(CompilerErrorFactory.CantUseBlockAliasAsValue(alias,
                                                                                memberNsInfo.ModuleMember.Module.FileName));
            }
            return(ResolveAliasesInAliasDefinition(aliasDef));
        }
Ejemplo n.º 6
0
        private NsInfo ResolveAliasesInAliasDefinition(NsInfo aliasDefNsInfo)
        {
            //Check if Alias is already being resolved (circular reference)

            if (_aliasDefStack.Any(n => n == aliasDefNsInfo))
            {
                //Report Error
                foreach (var info in _aliasDefStack)
                {
                    _context.AddError(CompilerErrorFactory.AliasDefHasCircularReference(info));
                    ((AliasDefinition)info.ModuleMember).HasCircularReference = true;
                    if (info == aliasDefNsInfo)
                    {
                        break;
                    }
                }
                return(aliasDefNsInfo);
            }

            _aliasDefStack.Push(aliasDefNsInfo);

            foreach (var alias in aliasDefNsInfo.Aliases)
            {
                NsInfo aliasNsInfo = ResolveAliasInAliasDefinition(alias);
                if (aliasNsInfo == null)
                {
                    continue;
                }
                MergeNsInfo(aliasDefNsInfo, aliasNsInfo);
            }

            _aliasDefStack.Pop();

            aliasDefNsInfo.AliasesResolved = true;

            return(aliasDefNsInfo);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Sets current <see cref="ModuleMember"/>.
 /// Method should be called from the visitor.
 /// </summary>
 /// <param name="aliasDefinition">Current <see cref="AliasDefinition"/>.</param>
 public void EnterAliasDef(AliasDefinition aliasDefinition)
 {
     _currentModuleMember       = aliasDefinition;
     _currentModuleMemberNsInfo = new NsInfo(_currentModuleMember);
     ModuleMembersNsInfo.Add(_currentModuleMemberNsInfo);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Sets current <see cref="ModuleMember"/>.
 /// Method should be called from the visitor.
 /// </summary>
 /// <param name="document">Current <see cref="Document"/>.</param>
 public void EnterDocument(Document document)
 {
     _currentModuleMember       = document;
     _currentModuleMemberNsInfo = new NsInfo(_currentModuleMember);
     ModuleMembersNsInfo.Add(_currentModuleMemberNsInfo);
 }