private DOM.Antlr.AliasDefinition LookupAliasDef(DOM.Antlr.Alias alias) { if (alias.AliasDefinition != null) { return(alias.AliasDefinition == AliasDefinition.Undefined ? null : alias.AliasDefinition); } var result = _context.NamespaceResolver.GetAliasDefinition(alias.Name); alias.AliasDefinition = result ?? AliasDefinition.Undefined; return(result); }
private int CalcNumOfRootElements(DOM.Antlr.Alias alias, List <DOM.AliasDefinition> aliasList) { int result = 0; var aliasDef = LookupAliasDef(alias); if (aliasDef == null) { return(0); } //Checking if there is circular reference to prevent infinite loop. if (aliasList == null) { aliasList = new List <DOM.AliasDefinition>(); } if (aliasList.Any(n => n == aliasDef)) { return(0); } aliasList.Add(aliasDef); foreach (var entity in aliasDef.Entities) { if (entity is DOM.Element) { result++; } var aliasEntity = entity as DOM.Antlr.Alias; if (aliasEntity != null) { result += CalcNumOfRootElements(aliasEntity, aliasList); } } return(result); }
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)); }
private void CheckDuplicateArguments(DOM.Antlr.Alias alias) { var dups = alias.Arguments.GroupBy(a => a.Name).Where(g => g.Count() > 1).SelectMany(g => g).ToList(); dups.ForEach(a => _context.AddError(CompilerErrorFactory.DuplicateArgumentName(a, _currentModule.FileName))); }
/// <summary> /// Adds Alias to the Namespace Info of the current Module Member. /// </summary> /// <param name="node"></param> public void AddAlias(DOM.Antlr.Alias node) { CurrentModuleMemberNsInfo.Aliases.Add(node); }
public void ProcessAlias(DOM.Antlr.Alias node) { CheckDuplicateArguments(node); }