Skip to content

Commit c8226d1

Browse files
committed
[libSyntax] Make a typealias to unsigned to represent SyntaxNodeIds
1 parent 419ba04 commit c8226d1

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

include/swift/Parse/SyntaxParsingCache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class SyntaxParsingCache {
6262
llvm::SmallVector<SourceEdit, 4> Edits;
6363

6464
/// The IDs of all syntax nodes that got reused are collected in this vector.
65-
std::unordered_set<unsigned> ReusedNodeIds;
65+
std::unordered_set<SyntaxNodeId> ReusedNodeIds;
6666

6767
public:
6868
SyntaxParsingCache(SourceFileSyntax OldSyntaxTree)
@@ -80,7 +80,7 @@ class SyntaxParsingCache {
8080
/// reused for a new syntax tree.
8181
llvm::Optional<Syntax> lookUp(size_t NewPosition, SyntaxKind Kind);
8282

83-
const std::unordered_set<unsigned> &getReusedNodeIds() const {
83+
const std::unordered_set<SyntaxNodeId> &getReusedNodeIds() const {
8484
return ReusedNodeIds;
8585
}
8686

include/swift/Syntax/RawSyntax.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ struct SyntaxPrintOptions {
212212
bool PrintTrivialNodeKind = false;
213213
};
214214

215+
typedef unsigned SyntaxNodeId;
216+
215217
/// RawSyntax - the strictly immutable, shared backing nodes for all syntax.
216218
///
217219
/// This is implementation detail - do not expose it in public API.
@@ -223,10 +225,10 @@ class RawSyntax final
223225

224226
/// The ID that shall be used for the next node that is created and does not
225227
/// have a manually specified id
226-
static unsigned NextFreeNodeId;
228+
static SyntaxNodeId NextFreeNodeId;
227229

228230
/// An ID of this node that is stable across incremental parses
229-
unsigned NodeId;
231+
SyntaxNodeId NodeId;
230232

231233
union {
232234
uint64_t OpaqueBits;
@@ -283,13 +285,13 @@ class RawSyntax final
283285
/// the caller needs to assure that the node ID has not been used yet.
284286
RawSyntax(SyntaxKind Kind, ArrayRef<RC<RawSyntax>> Layout,
285287
SourcePresence Presence, bool ManualMemory,
286-
llvm::Optional<unsigned> NodeId);
288+
llvm::Optional<SyntaxNodeId> NodeId);
287289
/// Constructor for creating token nodes
288290
/// If \p NodeId is \c None, the next free NodeId is used, if it is passed,
289291
/// the caller needs to assure that the NodeId has not been used yet.
290292
RawSyntax(tok TokKind, OwnedString Text, ArrayRef<TriviaPiece> LeadingTrivia,
291293
ArrayRef<TriviaPiece> TrailingTrivia, SourcePresence Presence,
292-
bool ManualMemory, llvm::Optional<unsigned> NodeId);
294+
bool ManualMemory, llvm::Optional<SyntaxNodeId> NodeId);
293295

294296
public:
295297
~RawSyntax();
@@ -312,15 +314,15 @@ class RawSyntax final
312314
static RC<RawSyntax> make(SyntaxKind Kind, ArrayRef<RC<RawSyntax>> Layout,
313315
SourcePresence Presence,
314316
SyntaxArena *Arena = nullptr,
315-
llvm::Optional<unsigned> NodeId = llvm::None);
317+
llvm::Optional<SyntaxNodeId> NodeId = llvm::None);
316318

317319
/// Make a raw "token" syntax node.
318320
static RC<RawSyntax> make(tok TokKind, OwnedString Text,
319321
ArrayRef<TriviaPiece> LeadingTrivia,
320322
ArrayRef<TriviaPiece> TrailingTrivia,
321323
SourcePresence Presence,
322324
SyntaxArena *Arena = nullptr,
323-
llvm::Optional<unsigned> NodeId = llvm::None);
325+
llvm::Optional<SyntaxNodeId> NodeId = llvm::None);
324326

325327
/// Make a missing raw "layout" syntax node.
326328
static RC<RawSyntax> missing(SyntaxKind Kind, SyntaxArena *Arena = nullptr) {
@@ -349,7 +351,7 @@ class RawSyntax final
349351
}
350352

351353
/// Get an ID for this node that is stable across incremental parses
352-
unsigned getId() const { return NodeId; }
354+
SyntaxNodeId getId() const { return NodeId; }
353355

354356
/// Returns true if the node is "missing" in the source (i.e. it was
355357
/// expected (or optional) but not written.

include/swift/Syntax/Syntax.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Syntax {
8585
RC<RawSyntax> getRaw() const;
8686

8787
/// Get an ID for this node that is stable across incremental parses
88-
unsigned getId() const { return getRaw()->getId(); }
88+
SyntaxNodeId getId() const { return getRaw()->getId(); }
8989

9090
/// Get the number of child nodes in this piece of syntax, not including
9191
/// tokens.

include/swift/Syntax/SyntaxClassifier.h.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SyntaxClassifier: public SyntaxVisitor {
6969
ForceClassification(ForceClassification) {}
7070
};
7171

72-
std::map<unsigned, SyntaxClassification> ClassifiedTokens;
72+
std::map<SyntaxNodeId, SyntaxClassification> ClassifiedTokens;
7373
/// The top classification of this stack determines the color of identifiers
7474
std::stack<ContextStackEntry, llvm::SmallVector<ContextStackEntry, 16>> ContextStack;
7575

@@ -101,7 +101,7 @@ class SyntaxClassifier: public SyntaxVisitor {
101101
% end
102102

103103
public:
104-
std::map<unsigned, SyntaxClassification> classify(Syntax Node) {
104+
std::map<SyntaxNodeId, SyntaxClassification> classify(Syntax Node) {
105105
// Clean up the environment
106106
ContextStack = std::stack<ContextStackEntry, llvm::SmallVector<ContextStackEntry, 16>>();
107107
ContextStack.push({SyntaxClassification::None, false});

lib/Parse/SyntaxParsingCache.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ std::vector<SyntaxReuseRegion>
9494
SyntaxParsingCache::getReusedRegions(const SourceFileSyntax &SyntaxTree) const {
9595
/// Determines the reused source regions from reused syntax node IDs
9696
class ReusedRegionsCollector : public SyntaxVisitor {
97-
std::unordered_set<unsigned> ReusedNodeIds;
97+
std::unordered_set<SyntaxNodeId> ReusedNodeIds;
9898
std::vector<SyntaxReuseRegion> ReusedRegions;
9999

100-
bool didReuseNode(unsigned NodeId) {
100+
bool didReuseNode(SyntaxNodeId NodeId) {
101101
return ReusedNodeIds.count(NodeId) > 0;
102102
}
103103

104104
public:
105-
ReusedRegionsCollector(std::unordered_set<unsigned> ReusedNodeIds)
105+
ReusedRegionsCollector(std::unordered_set<SyntaxNodeId> ReusedNodeIds)
106106
: ReusedNodeIds(ReusedNodeIds) {}
107107

108108
const std::vector<SyntaxReuseRegion> &getReusedRegions() {

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,12 @@ struct SwiftSyntaxMap {
562562
class SyntaxToSyntaxMapConverter : public SyntaxVisitor {
563563
SwiftSyntaxMap &SyntaxMap;
564564

565-
std::map<unsigned, SyntaxClassification> TokenClassifications;
565+
std::map<SyntaxNodeId, SyntaxClassification> TokenClassifications;
566566

567567
public:
568568
SyntaxToSyntaxMapConverter(
569569
SwiftSyntaxMap &SyntaxMap,
570-
std::map<unsigned, SyntaxClassification> TokenClassifications)
570+
std::map<SyntaxNodeId, SyntaxClassification> TokenClassifications)
571571
: SyntaxMap(SyntaxMap), TokenClassifications(TokenClassifications) {}
572572

573573
private:

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ class PrintSyntaxColorWalker : public ide::SyntaxModelWalker {
960960
class ColoredSyntaxTreePrinter : public SyntaxVisitor {
961961
llvm::raw_ostream &OS;
962962

963-
std::map<unsigned, SyntaxClassification> TokenClassifications;
963+
std::map<SyntaxNodeId, SyntaxClassification> TokenClassifications;
964964

965965
/// The name of the tag that is currently open
966966
StringRef CurrentTag;
@@ -972,7 +972,7 @@ class ColoredSyntaxTreePrinter : public SyntaxVisitor {
972972
public:
973973
ColoredSyntaxTreePrinter(
974974
llvm::raw_ostream &OS,
975-
std::map<unsigned, SyntaxClassification> TokenClassifications)
975+
std::map<SyntaxNodeId, SyntaxClassification> TokenClassifications)
976976
: OS(OS), TokenClassifications(TokenClassifications) {}
977977

978978
private:

0 commit comments

Comments
 (0)