private void RegisterLocation(ISymbol symbol, Boogie.IToken token, Range name, Range declaration) { if (token.filename != null) { // The filename is null if we have a default or System based symbol. This is also reflected by the ranges being usually -1. Locations.Add(symbol, new SymbolLocation(DocumentUri.FromFileSystemPath(token.filename), name, declaration)); } }
private void ProcessNestedScope(AstElement node, Boogie.IToken token, System.Action visit) { if (!_program.IsPartOfEntryDocument(token)) { return; } var oldScope = _currentScope; _currentScope = _declarations[node]; visit(); _currentScope = oldScope; }
private void RegisterDesignator(ISymbol scope, AstElement node, Boogie.IToken token, string identifier) { var symbol = GetSymbolDeclarationByName(scope, identifier); if (symbol != null) { // Many resolutions for automatically generated nodes (e.g. Decreases, Update when initializating a variable // at declaration) cause duplicated visits. These cannot be prevented at this time as it seems there's no way // to distinguish nodes from automatically created one (i.e. nodes of the original syntax tree vs. nodes of the // abstract syntax tree). We could just ignore such duplicates. However, we may miss programatic errors if we // do so. var range = token.GetLspRange(); SymbolLookup.Add(range.Start, range.End, symbol); _designators.Add(node, symbol); } else { _logger.LogWarning("could not resolve the symbol of designator named {} in {}@({},{})", identifier, Path.GetFileName(token.filename), token.line, token.col); } }
// Double-dispatching would be convenient here, but requirees adaptions to the AST. // TODO Is visiting Attributes necessary, i.e., does it belong to the AST? /// <summary> /// This method is invoked as soon as the visitor encounters an unknown syntax node. /// </summary> /// <param name="node">The unknown node that is being visited.</param> /// <param name="token">The token asociated with the unknown node.</param> public abstract void VisitUnknown(object node, Boogie.IToken token);
/// <summary> /// Gets the filename of the document where the given boogie token is located in. /// </summary> /// <param name="token">The token to get the document filename from.</param> /// <returns>The filename (without path) of the document containing the given token.</returns> public static string GetDocumentFileName(this Boogie.IToken token) { return(Path.GetFileName(token.filename)); }
/// <summary> /// Gets the document uri for the specified boogie token. /// </summary> /// <param name="token">The token to get the boogie token from.</param> /// <returns>The uri of the document where the token is located.</returns> public static DocumentUri GetDocumentUri(this Boogie.IToken token) { return(DocumentUri.FromFileSystemPath(token.filename)); }
/// <summary> /// Checks if the given token is part of the entrypoint document. /// </summary> /// <param name="program">The dafny program to check the token against.</param> /// <param name="token">The token to check.</param> /// <returns><c>true</c> if the given token is part of the entrypoint document of the given program.</returns> public static bool IsPartOfEntryDocument(this Dafny.Program program, Boogie.IToken token) { // The token filename happens to be null if it's representing a default module or class. return(token.filename == null || token.filename == program.FullName); }
public override void VisitUnknown(object node, Boogie.IToken token) { _logger.LogWarning("encountered unknown syntax node of type {} in {}@({},{})", node.GetType(), Path.GetFileName(token.filename), token.line, token.col); }
/// <summary> /// Checks if the specified token is part of this document. /// </summary> /// <param name="token">The token to check.</param> /// <returns><c>true</c> if the given token belongs to this document.</returns> public bool IsPartOf(Boogie.IToken token) { return(Program.IsPartOfEntryDocument(token)); }
private IEnumerable <DocumentSymbol> CreateSymbolsOfEntryDocument(ILocalizableSymbol symbol, Boogie.IToken token, SymbolKind kind) { var children = symbol.Children.SelectMany(Visit); if (!IsPartOfEntryDocument(token)) { return(children); } var documentSymbol = new DocumentSymbol { Name = symbol.Name, Kind = kind, Detail = symbol.GetDetailText(_cancellationToken), Children = children.ToArray() }; if (_symbolTable.TryGetLocationOf(symbol, out var location)) { documentSymbol = documentSymbol with { Range = location.Declaration, SelectionRange = location.Name }; } return(new[] { documentSymbol }); } }
private bool IsPartOfEntryDocument(Boogie.IToken token) { // Tokens with line=0 usually represent a default/implicit class/module/etc. We do not want // to show these in the symbol listing. return(token.line != 0 && _symbolTable.CompilationUnit.Program.IsPartOfEntryDocument(token)); }
private IEnumerable <DocumentSymbol> CreateSymbolsOfEntryDocument(ILocalizableSymbol symbol, Boogie.IToken token, SymbolKind kind) { var children = symbol.Children.SelectMany(Visit); if (!IsPartOfEntryDocument(token)) { return(children); } if (!symbolTable.TryGetLocationOf(symbol, out var location)) { return(Enumerable.Empty <DocumentSymbol>()); } var documentSymbol = new DocumentSymbol { Name = symbol.Name, Kind = kind, Children = children.ToArray(), Range = location.Declaration, SelectionRange = location.Name }; return(new[] { documentSymbol }); }
public override void VisitUnknown(object node, Boogie.IToken token) { _logger.LogDebug("encountered unknown syntax node of type {NodeType} in {Filename}@({Line},{Column})", node.GetType(), Path.GetFileName(token.filename), token.line, token.col); }