Skip to content

Commit 2cc4cd8

Browse files
committed
Fixup
1 parent 2e1950d commit 2cc4cd8

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/SlangProjectLookup.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "slang/ast/Lookup.h"
1919
#include "slang/ast/Scope.h"
2020
#include "slang/ast/Symbol.h"
21+
#include "slang/ast/Scope.h"
2122
#include "slang/ast/symbols/CompilationUnitSymbols.h"
2223
#include "slang/diagnostics/Diagnostics.h"
2324
#include "slang/syntax/AllSyntax.h"
@@ -39,7 +40,6 @@ struct DefIndex {
3940
std::unordered_map<std::string, slang::SourceLocation> byName;
4041
};
4142

42-
4343
static void indexDeclarators(const slang::syntax::SyntaxNode &node,
4444
DefIndex &out) {
4545
using namespace slang::syntax;
@@ -60,12 +60,22 @@ static void indexDeclarators(const slang::syntax::SyntaxNode &node,
6060

6161
/// Walk the syntax tree from its root down to collect all declarators;
6262
/// declarators contain symbol definitions we can lookup later.
63-
static void walk(const slang::syntax::SyntaxNode &node, DefIndex &out) {
64-
indexDeclarators(node, out);
63+
static void walk(const slang::syntax::SyntaxNode &root, DefIndex &out) {
64+
llvm::SmallVector<const slang::syntax::SyntaxNode *, 32> worklist;
65+
worklist.push_back(&root);
66+
67+
while (!worklist.empty()) {
68+
const slang::syntax::SyntaxNode *node = worklist.pop_back_val();
6569

66-
for (size_t i = 0, e = node.getChildCount(); i < e; ++i)
67-
if (auto *c = node.childNode(i))
68-
walk(*c, out);
70+
// Collect declarators at this node.
71+
indexDeclarators(*node, out);
72+
73+
// Push children to the stack.
74+
for (size_t i = 0, e = node->getChildCount(); i < e; ++i) {
75+
if (auto *c = node->childNode(i))
76+
worklist.push_back(c);
77+
}
78+
}
6979
}
7080

7181
static bool isLocationInRange(slang::SourceRange r, slang::SourceLocation loc) {
@@ -84,7 +94,7 @@ struct DefinitionVisitor : public slang::syntax::SyntaxVisitor<
8494

8595
DefinitionVisitor(const slang::ast::Compilation &comp,
8696
const slang::ast::Scope &rootScope,
87-
slang::SourceLocation queryLoc, DefIndex &defIndex)
97+
slang::SourceLocation queryLoc, const DefIndex &defIndex)
8898
: comp(comp), rootScope(rootScope), queryLoc(queryLoc),
8999
defIndex(defIndex) {}
90100

@@ -129,7 +139,7 @@ struct DefinitionVisitor : public slang::syntax::SyntaxVisitor<
129139
const slang::ast::Compilation &comp;
130140
const slang::ast::Scope &rootScope;
131141
slang::SourceLocation queryLoc;
132-
DefIndex &defIndex;
142+
const DefIndex &defIndex;
133143
};
134144

135145
} // namespace

lib/Tools/circt-verilog-lsp-server/VerilogServerImpl/VerilogServer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717

1818
#include "circt/Support/LLVM.h"
1919
#include "circt/Tools/circt-verilog-lsp-server/CirctVerilogLspServerMain.h"
20+
#include "slang/analysis/AnalysisManager.h"
2021
#include "slang/ast/Compilation.h"
2122
#include "slang/ast/Scope.h"
23+
#include "slang/ast/symbols/CompilationUnitSymbols.h"
2224
#include "slang/diagnostics/DiagnosticClient.h"
2325
#include "slang/diagnostics/Diagnostics.h"
2426
#include "slang/driver/Driver.h"
27+
#include "slang/syntax/AllSyntax.h"
2528
#include "slang/syntax/SyntaxTree.h"
2629
#include "slang/text/SourceLocation.h"
2730
#include "slang/text/SourceManager.h"
@@ -295,7 +298,7 @@ VerilogDocument::getDefinitionAt(const llvm::lsp::Position &pos) {
295298
const auto &sm = comp.getSourceManager();
296299

297300
SlangProjectLookup sl =
298-
SlangProjectLookup(comp, comp.getRootNoFinalize(), *sm);
301+
SlangProjectLookup(comp, comp.getRoot(), *sm);
299302
slang::SourceLocation loc = sl.lspPositionToSlangLocation(mainBufferId, pos);
300303

301304
// Identify a name-like syntax under the cursor.

0 commit comments

Comments
 (0)