mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
libSyntax: Root parsing context should hold a reference to the current token in the parser, NFC.
Since all parsing contexts need a reference to the current token of the parser, we should pass the token reference to the root context. Therefore, the derived sub-contexts can just copy it while being spawned.
This commit is contained in:
@@ -58,11 +58,12 @@ enum class SyntaxParsingContextKind: uint8_t {
|
||||
/// create syntax nodes.
|
||||
class SyntaxParsingContext {
|
||||
protected:
|
||||
SyntaxParsingContext(SourceFile &SF, unsigned BufferID);
|
||||
SyntaxParsingContext(SourceFile &SF, unsigned BufferID, Token &Tok);
|
||||
SyntaxParsingContext(SyntaxParsingContext &Another);
|
||||
public:
|
||||
struct ContextInfo;
|
||||
ContextInfo &ContextData;
|
||||
const Token &Tok;
|
||||
|
||||
// Add a token syntax at the given source location to the context; this
|
||||
// token node can be used to build more complex syntax nodes in later call
|
||||
@@ -86,8 +87,8 @@ public:
|
||||
class SyntaxParsingContextRoot: public SyntaxParsingContext {
|
||||
SourceFile &File;
|
||||
public:
|
||||
SyntaxParsingContextRoot(SourceFile &File, unsigned BufferID):
|
||||
SyntaxParsingContext(File, BufferID), File(File) {}
|
||||
SyntaxParsingContextRoot(SourceFile &File, unsigned BufferID, Token &Tok):
|
||||
SyntaxParsingContext(File, BufferID, Tok), File(File) {}
|
||||
~SyntaxParsingContextRoot();
|
||||
void addTokenSyntax(SourceLoc Loc) override {};
|
||||
void makeNode(SyntaxKind Kind) override {};
|
||||
@@ -109,10 +110,9 @@ class SyntaxParsingContextChild: public SyntaxParsingContext {
|
||||
SyntaxParsingContext *Parent;
|
||||
SyntaxParsingContext *&ContextHolder;
|
||||
const SyntaxContextKind Kind;
|
||||
Token &Tok;
|
||||
public:
|
||||
SyntaxParsingContextChild(SyntaxParsingContext *&ContextHolder,
|
||||
SyntaxContextKind Kind, Token &Tok);
|
||||
SyntaxContextKind Kind);
|
||||
~SyntaxParsingContextChild();
|
||||
void makeNode(SyntaxKind Kind) override;
|
||||
void addTokenSyntax(SourceLoc Loc) override;
|
||||
|
||||
Reference in New Issue
Block a user