[incrParse] Support incremental parsing for edited files

This commit is contained in:
Alex Hoppen
2018-05-03 16:07:48 -07:00
parent ea5e4e224a
commit de9737c946
15 changed files with 230 additions and 7 deletions

View File

@@ -20,6 +20,7 @@
namespace swift {
class SourceFile;
class SyntaxParsingCache;
class Token;
class DiagnosticEngine;
@@ -97,6 +98,9 @@ private:
// Discard all parts in the context.
Discard,
// The node has been loaded from the cache and all parts shall be discarded.
LoadedFromCache,
// Construct SourceFile syntax to the specified SF.
Root,
@@ -112,6 +116,9 @@ private:
// Reference to the
SyntaxParsingContext *&CtxtHolder;
/// A cache of nodes that can be reused when creating the current syntax tree
SyntaxParsingCache *SyntaxParsingCache = nullptr;
SyntaxArena &Arena;
std::vector<RC<RawSyntax>> &Storage;
@@ -154,11 +161,13 @@ public:
/// Designated constructor for child context.
SyntaxParsingContext(SyntaxParsingContext *&CtxtHolder)
: RootDataOrParent(CtxtHolder), CtxtHolder(CtxtHolder),
Arena(CtxtHolder->Arena),
Storage(CtxtHolder->Storage), Offset(Storage.size()),
Enabled(CtxtHolder->isEnabled()) {
SyntaxParsingCache(CtxtHolder->SyntaxParsingCache),
Arena(CtxtHolder->Arena), Storage(CtxtHolder->Storage),
Offset(Storage.size()), Enabled(CtxtHolder->isEnabled()) {
assert(CtxtHolder->isTopOfContextStack() &&
"SyntaxParsingContext cannot have multiple children");
assert(CtxtHolder->Mode != AccumulationMode::LoadedFromCache &&
"Cannot create child context for a node loaded from the cache");
CtxtHolder = this;
}
@@ -174,6 +183,15 @@ public:
~SyntaxParsingContext();
/// Try loading the current node from the \c SyntaxParsingCache by looking up
/// if an unmodified node exists at \p LexerOffset of the same kind. If a node
/// is found, replace the node that is currently being constructed by the
/// parsing context with the node from the cache and return the number of
/// bytes the loaded node took up in the original source. The lexer should
/// pretend it has read these bytes and continue from the advanced offset.
/// If nothing is found \c 0 is returned.
size_t loadFromCache(size_t LexerOffset);
void disable() { Enabled = false; }
bool isEnabled() const { return Enabled; }
bool isRoot() const { return RootDataOrParent.is<RootContextData*>(); }