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

            return(Instantiate("MCE0005", new LexicalInfo(aliasDef.Module.FileName,
                                                          aliasDef.start.Line, aliasDef.start.Column + 1, aliasDef.start.Index), aliasDef.Name));
        }
示例#2
0
 private void ResolveAliasesInModuleMember(NsInfo nsInfo)
 {
     foreach (var alias in nsInfo.Aliases)
     {
         NsInfo aliasNsInfo = ResolveAliasInModuleMember(alias, nsInfo);
         if (aliasNsInfo == null)
         {
             continue;
         }
         MergeNsInfo(nsInfo, aliasNsInfo);
     }
 }
示例#3
0
        private NsInfo ResolveAliasInAliasDefinition(DOM.Alias alias, NsInfo aliasDefNsInfo)
        {
            //Finding AliasDef
            var aliasDef = _context.NamespaceResolver.GetAliasDefinition(alias.Name);

            if (aliasDef == null)
            {
                //Report Error
                _context.AddError(CompilerErrorFactory.AliasIsNotDefined(alias, aliasDefNsInfo.ModuleMember.Module.FileName));
                return(null);
            }
            return(ResolveAliasesInAliasDefinition(aliasDef));
        }
示例#4
0
        private void CheckModuleMember(NsInfo nsInfo)
        {
            var document = nsInfo.ModuleMember as Document;

            if (document == null)
            {
                CheckAliasDef((AliasDefinition)nsInfo.ModuleMember);
                return;
            }

            if (Path.GetExtension(document.Module.FileName) == ".mlx")
            {
                CheckDocumentElement(document);
            }
        }
示例#5
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.Namespace()
                {
                    Name = prefix, Value = ns.Value
                });
            }
        }
示例#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));
                    ((DOM.Antlr.AliasDefinition)info.ModuleMember).HasCircularReference = true;
                    if (info == aliasDefNsInfo)
                    {
                        break;
                    }
                }
                return(aliasDefNsInfo);
            }

            _aliasDefStack.Push(aliasDefNsInfo);

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

            _aliasDefStack.Pop();

            aliasDefNsInfo.AliasesResolved = true;

            return(aliasDefNsInfo);
        }
示例#7
0
        private NsInfo ResolveAliasInModuleMember(DOM.Antlr.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)
            {
                _context.AddError(aliasDef.IsValueNode
                    ? CompilerErrorFactory.CantUseValueAliasInTheBlock(alias, memberNsInfo.ModuleMember.Module.FileName)
                    : CompilerErrorFactory.CantUseBlockAliasAsValue(alias, memberNsInfo.ModuleMember.Module.FileName));
            }


            CheckAliasArguments(alias, aliasDef, memberNsInfo);

            return(ResolveAliasesInAliasDefinition(aliasDef));
        }
示例#8
0
 public void EnterAliasDef(DOM.Antlr.AliasDefinition node)
 {
     _currentModuleMember       = node;
     _currentModuleMemberNsInfo = new NsInfo(_currentModuleMember);
     ModuleMembersNsInfo.Add(_currentModuleMemberNsInfo);
 }
示例#9
0
 public void EnterDocument(DOM.Antlr.Document node)
 {
     _currentModuleMember       = node;
     _currentModuleMemberNsInfo = new NsInfo(_currentModuleMember);
     ModuleMembersNsInfo.Add(_currentModuleMemberNsInfo);
 }
示例#10
0
        private void CheckCompatibilityWithParameters(Alias alias, AliasDefinition aliasDef, NsInfo documentNsInfo)
        {
            foreach (var parameter in aliasDef.Parameters)
            {
                if (parameter.Name == "_") //Default parameter
                {
                    if (!parameter.IsValueNode)
                    {
                        if (alias.Entities.Count == 0 && alias.ValueType != ValueType.EmptyObject)
                        {
                            _context.AddError(CompilerErrorFactory.DefaultBlockArgumentIsMissing(alias,
                                                                                                 documentNsInfo.ModuleMember.Module.FileName));
                        }
                    }
                    else
                    {
                        if (parameter.HasValue())
                        {
                            continue;                       //if parameter has default value then skip check
                        }
                        if (!alias.HasValue())
                        {
                            _context.AddError(CompilerErrorFactory.DefaultValueArgumentIsMissing(alias,
                                                                                                 documentNsInfo.ModuleMember.Module.FileName));
                        }
                    }


                    continue;
                }

                //Non default parameter
                var argument = alias.Arguments.FirstOrDefault(a => a.Name == parameter.Name);
                if (argument == null)
                {
                    //Report Error if argument is missing and there is no default value for the parameter
                    if (parameter.Value == null && parameter.Entities.Count == 0 && parameter.ValueType != ValueType.EmptyObject)
                    {
                        _context.AddError(CompilerErrorFactory.ArgumentIsMissing(alias, parameter.Name,
                                                                                 documentNsInfo.ModuleMember.Module.FileName));
                    }

                    continue;
                }

                //Report error if type of argument (value/block) mismatch the type of parameter
                if (argument.IsValueNode != parameter.IsValueNode)
                {
                    _context.AddError(parameter.IsValueNode
                        ? CompilerErrorFactory.ValueArgumentIsExpected(argument,
                                                                       documentNsInfo.ModuleMember.Module.FileName)
                        : CompilerErrorFactory.BlockArgumentIsExpected(argument,
                                                                       documentNsInfo.ModuleMember.Module.FileName));
                }
            }
        }
示例#11
0
        private void CheckForUnexpectedArguments(Alias alias, AliasDefinition aliasDef, NsInfo documentNsInfo)
        {
            foreach (var argument in alias.Arguments)
            {
                if (aliasDef.Parameters.All(p => p.Name != argument.Name))
                {
                    _context.AddError(CompilerErrorFactory.UnexpectedArgument(argument, documentNsInfo.ModuleMember.Module.FileName));
                }
            }

            if (!aliasDef.HasDefaultBlockParameter && alias.Entities.Count > 0)
            {
                _context.AddError(CompilerErrorFactory.UnexpectedDefaultBlockArgument(alias.Entities[0],
                                                                                      documentNsInfo.ModuleMember.Module.FileName));
            }

            if (!aliasDef.HasDefaultValueParameter && alias.HasValue())
            {
                _context.AddError(CompilerErrorFactory.UnexpectedDefaultValueArgument(alias,
                                                                                      documentNsInfo.ModuleMember.Module.FileName));
            }
        }
示例#12
0
 private void CheckAliasArguments(DOM.Alias alias, DOM.Antlr.AliasDefinition aliasDef, NsInfo documentNsInfo)
 {
     CheckCompatibilityWithParameters(alias, aliasDef, documentNsInfo);
     CheckForUnexpectedArguments(alias, aliasDef, documentNsInfo);
 }
示例#13
0
        public AliasDefinition GetAliasDefinition(string name)
        {
            NsInfo resultInfo = ModuleMembersNsInfo.FirstOrDefault(a => (a.ModuleMember is DOM.AliasDefinition) && a.ModuleMember.Name == name);

            return((AliasDefinition)resultInfo?.ModuleMember);
        }