mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[libSyntax] Only keep track of range in ParsedRawSyntaxNode if verifying element ranges
This makes ParsedRawSyntaxNode a zero-cost wrapper around RecordedOrDeferredNode in the case that ranges are not verified.
This commit is contained in:
@@ -20,12 +20,12 @@
|
||||
#define SWIFT_PARSE_PARSEDRAWSYNTAXRECORDER_H
|
||||
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Parse/ParsedRawSyntaxNode.h"
|
||||
#include <memory>
|
||||
|
||||
namespace swift {
|
||||
|
||||
class CharSourceRange;
|
||||
class ParsedRawSyntaxNode;
|
||||
struct ParsedTrivia;
|
||||
class ParsedTriviaPiece;
|
||||
class SyntaxParseActions;
|
||||
@@ -38,6 +38,18 @@ namespace syntax {
|
||||
enum class SyntaxKind;
|
||||
}
|
||||
|
||||
/// The information returned from the \c lookupNode method in \c
|
||||
/// SyntaxParseActions.
|
||||
struct ParseLookupResult {
|
||||
ParsedRawSyntaxNode Node;
|
||||
|
||||
/// The length of \c Node spelled out in source, including trivia.
|
||||
size_t Length;
|
||||
|
||||
ParseLookupResult(ParsedRawSyntaxNode &&Node, size_t Length)
|
||||
: Node(std::move(Node)), Length(Length) {}
|
||||
};
|
||||
|
||||
class ParsedRawSyntaxRecorder final {
|
||||
std::shared_ptr<SyntaxParseActions> SPActions;
|
||||
|
||||
@@ -92,8 +104,8 @@ public:
|
||||
ParsedRawSyntaxNode makeDeferredMissing(tok tokKind, SourceLoc loc);
|
||||
|
||||
/// Used for incremental re-parsing.
|
||||
ParsedRawSyntaxNode lookupNode(size_t lexerOffset, SourceLoc loc,
|
||||
syntax::SyntaxKind kind);
|
||||
ParseLookupResult lookupNode(size_t lexerOffset, SourceLoc loc,
|
||||
syntax::SyntaxKind kind);
|
||||
|
||||
/// For a deferred layout node \p parent, retrieve the deferred child node
|
||||
/// at \p ChildIndex.
|
||||
@@ -103,8 +115,11 @@ public:
|
||||
/// For a deferred layout node \p node, retrieve the number of children.
|
||||
size_t getDeferredNumChildren(const ParsedRawSyntaxNode &node) const;
|
||||
|
||||
#ifndef NDEBUG
|
||||
static void verifyElementRanges(ArrayRef<ParsedRawSyntaxNode> elements);
|
||||
#ifdef PARSEDRAWSYNTAXNODE_VERIFY_RANGES
|
||||
/// Verify that the ranges of \p elements are all consecutive and return the
|
||||
/// range spanned by all \p elements.
|
||||
static CharSourceRange
|
||||
verifyElementRanges(ArrayRef<ParsedRawSyntaxNode> elements);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user