/// <summary> /// Walks the parents of the item and gets the closest type scope /// </summary> /// <param name="item">The item to get the type scope for</param> /// <returns>The type scope</returns> public ScopeState TryFindScopeForItem <T>(TypedVisitedItem <T> item) where T : AST.ParsedItem { // No need to attempt to find the scope for a literal if (item.Current is AST.LiteralExpression) { return(null); } foreach (var n in item.Parents.Prepend(item.Current)) { if (LocalScopes.TryGetValue(n, out var res)) { return(res); } if (n is Parser.Instance.IInstance pi && LocalScopes.TryGetValue(pi.Name, out res)) { return(res); } } return(null); }
/// <summary> /// Walks the parents of the item and gets the closest type scope /// </summary> /// <param name="item">The item to get the type scope for</param> /// <returns>The type scope</returns> public ScopeState FindScopeForItem <T>(TypedVisitedItem <T> item) where T : AST.ParsedItem { return(TryFindScopeForItem(item) ?? throw new Exception("No symbol table found for item")); }