forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPersistentParserState.cpp
88 lines (78 loc) · 3.92 KB
/
PersistentParserState.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//===--- PersistentParserState.cpp - Parser State Implementation ----------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file implements parser state persistent across multiple parses.
//
//===----------------------------------------------------------------------===//
#include "swift/AST/Decl.h"
#include "swift/AST/Expr.h"
#include "swift/Parse/PersistentParserState.h"
using namespace swift;
void PersistentParserState::delayFunctionBodyParsing(AbstractFunctionDecl *AFD,
SourceRange BodyRange,
SourceLoc PreviousLoc) {
std::unique_ptr<FunctionBodyState> State;
State.reset(new FunctionBodyState(BodyRange, PreviousLoc,
ScopeInfo.saveCurrentScope()));
assert(DelayedFunctionBodies.find(AFD) == DelayedFunctionBodies.end() &&
"Already recorded state for this body");
DelayedFunctionBodies[AFD] = std::move(State);
}
std::unique_ptr<PersistentParserState::FunctionBodyState>
PersistentParserState::takeFunctionBodyState(AbstractFunctionDecl *AFD) {
assert(AFD->getBodyKind() == AbstractFunctionDecl::BodyKind::Unparsed);
DelayedFunctionBodiesTy::iterator I = DelayedFunctionBodies.find(AFD);
assert(I != DelayedFunctionBodies.end() && "State should be saved");
std::unique_ptr<FunctionBodyState> State = std::move(I->second);
DelayedFunctionBodies.erase(I);
return State;
}
bool PersistentParserState::hasFunctionBodyState(AbstractFunctionDecl *AFD) {
return DelayedFunctionBodies.find(AFD) != DelayedFunctionBodies.end();
}
void PersistentParserState::delayAccessorBodyParsing(AbstractFunctionDecl *AFD,
SourceRange BodyRange,
SourceLoc PreviousLoc,
SourceLoc LBLoc) {
std::unique_ptr<AccessorBodyState> State;
State.reset(new AccessorBodyState(BodyRange, PreviousLoc,
ScopeInfo.saveCurrentScope(), LBLoc));
assert(DelayedAccessorBodies.find(AFD) == DelayedAccessorBodies.end() &&
"Already recorded state for this body");
DelayedAccessorBodies[AFD] = std::move(State);
}
std::unique_ptr<PersistentParserState::AccessorBodyState>
PersistentParserState::takeAccessorBodyState(AbstractFunctionDecl *AFD) {
assert(AFD->getBodyKind() == AbstractFunctionDecl::BodyKind::Unparsed);
DelayedAccessorBodiesTy::iterator I = DelayedAccessorBodies.find(AFD);
assert(I != DelayedAccessorBodies.end() && "State should be saved");
std::unique_ptr<AccessorBodyState> State = std::move(I->second);
DelayedAccessorBodies.erase(I);
return State;
}
void PersistentParserState::delayDecl(DelayedDeclKind Kind,
unsigned Flags,
DeclContext *ParentContext,
SourceRange BodyRange,
SourceLoc PreviousLoc) {
assert(!CodeCompletionDelayedDeclState.get() &&
"only one decl can be delayed for code completion");
CodeCompletionDelayedDeclState.reset(new DelayedDeclState(
Kind, Flags, ParentContext, BodyRange, PreviousLoc,
ScopeInfo.saveCurrentScope()));
}
void PersistentParserState::delayTopLevel(TopLevelCodeDecl *TLCD,
SourceRange BodyRange,
SourceLoc PreviousLoc) {
delayDecl(DelayedDeclKind::TopLevelCodeDecl, 0U, TLCD, BodyRange,
PreviousLoc);
}