예제 #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));
        }
예제 #2
0
        public AliasDefinition GetAliasDefinition(string name)
        {
            NsInfo resultInfo =
                ModuleMembersNsInfo.FirstOrDefault(
                    a => (a.ModuleMember is DOM.AliasDefinition) && a.ModuleMember.Name == name);

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

            if (document == null)
            {
                ValidateAliasDefDefaultParameter((AliasDefinition)nsInfo.ModuleMember);
                return;
            }
        }
예제 #4
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);
     }
 }
예제 #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));
        }
예제 #6
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 DOM.NamespaceDefinition {
                    Name = prefix, Delimiter = DelimiterEnum.E, Value = ns.Value, ValueQuotesType = 0
                });
            }
        }
예제 #7
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);
        }
예제 #8
0
 public void EnterAliasDef(AliasDefinition node)
 {
     _currentModuleMember       = node;
     _currentModuleMemberNsInfo = new NsInfo(_currentModuleMember);
     ModuleMembersNsInfo.Add(_currentModuleMemberNsInfo);
 }
예제 #9
0
 public void EnterDocument(Document node)
 {
     _currentModuleMember       = node;
     _currentModuleMemberNsInfo = new NsInfo(_currentModuleMember);
     ModuleMembersNsInfo.Add(_currentModuleMemberNsInfo);
 }