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)); }
private void ResolveAliasesInModuleMember(NsInfo nsInfo) { foreach (var alias in nsInfo.Aliases) { NsInfo aliasNsInfo = ResolveAliasInModuleMember(alias, nsInfo); if (aliasNsInfo == null) { continue; } MergeNsInfo(nsInfo, aliasNsInfo); } }
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)); }
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); } }
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 }); } }
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); }
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)); }
public void EnterAliasDef(DOM.Antlr.AliasDefinition node) { _currentModuleMember = node; _currentModuleMemberNsInfo = new NsInfo(_currentModuleMember); ModuleMembersNsInfo.Add(_currentModuleMemberNsInfo); }
public void EnterDocument(DOM.Antlr.Document node) { _currentModuleMember = node; _currentModuleMemberNsInfo = new NsInfo(_currentModuleMember); ModuleMembersNsInfo.Add(_currentModuleMemberNsInfo); }
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)); } } }
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)); } }
private void CheckAliasArguments(DOM.Alias alias, DOM.Antlr.AliasDefinition aliasDef, NsInfo documentNsInfo) { CheckCompatibilityWithParameters(alias, aliasDef, documentNsInfo); CheckForUnexpectedArguments(alias, aliasDef, documentNsInfo); }
public AliasDefinition GetAliasDefinition(string name) { NsInfo resultInfo = ModuleMembersNsInfo.FirstOrDefault(a => (a.ModuleMember is DOM.AliasDefinition) && a.ModuleMember.Name == name); return((AliasDefinition)resultInfo?.ModuleMember); }