Example #1
0
        internal static CompilerError AliasDefHasCircularReference(NsInfo aliasDefNsInfo)
        {
            var aliasDef = (AliasDefinition)aliasDefNsInfo.ModuleMember;

            return(Instantiate("MCE0005", new LexicalInfo(aliasDef.Module.FileName,
                                                          aliasDef.NameInterval.Begin.Line, aliasDef.NameInterval.Begin.Column, aliasDef.NameInterval.Begin.Index), false, aliasDef.Name));
        }
        public AliasDefinition GetAliasDefinition(string name)
        {
            NsInfo resultInfo =
                ModuleMembersNsInfo.FirstOrDefault(
                    a => (a.ModuleMember is DOM.AliasDefinition) && a.ModuleMember.Name == name);

            return((AliasDefinition)resultInfo?.ModuleMember);
        }
        private void CheckModuleMember(NsInfo nsInfo)
        {
            var document = nsInfo.ModuleMember as Document;

            if (document == null)
            {
                ValidateAliasDefDefaultParameter((AliasDefinition)nsInfo.ModuleMember);
                return;
            }
        }
 private void ResolveAliasesInModuleMember(NsInfo nsInfo)
 {
     foreach (var alias in nsInfo.Aliases)
     {
         NsInfo aliasNsInfo = ResolveAliasInModuleMember((Alias)alias, nsInfo);
         if (aliasNsInfo == null)
         {
             continue;
         }
         MergeNsInfo(nsInfo, aliasNsInfo);
     }
 }
        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));
        }
        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 DOM.NamespaceDefinition {
                    Name = prefix, Delimiter = DelimiterEnum.E, Value = ns.Value, ValueQuotesType = 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);
        }
 public void EnterAliasDef(AliasDefinition node)
 {
     _currentModuleMember       = node;
     _currentModuleMemberNsInfo = new NsInfo(_currentModuleMember);
     ModuleMembersNsInfo.Add(_currentModuleMemberNsInfo);
 }
 public void EnterDocument(Document node)
 {
     _currentModuleMember       = node;
     _currentModuleMemberNsInfo = new NsInfo(_currentModuleMember);
     ModuleMembersNsInfo.Add(_currentModuleMemberNsInfo);
 }