Simplify some code in SourceFile, NFC

This commit is contained in:
Xi Ge
2017-09-08 17:17:57 -07:00
parent ea3d0bbf82
commit ceec130b0a
2 changed files with 11 additions and 10 deletions

View File

@@ -1073,23 +1073,22 @@ public:
}
std::vector<Token> &getTokenVector() {
assert(EnabledAndAllCorrectedTokens.first && "Disabled");
return EnabledAndAllCorrectedTokens.second;
assert(pAllCorrectedTokens && "Disabled");
return *pAllCorrectedTokens;
}
ArrayRef<Token> getAllTokens() const {
assert(EnabledAndAllCorrectedTokens.first && "Disabled");
return EnabledAndAllCorrectedTokens.second;
assert(pAllCorrectedTokens && "Disabled");
return *pAllCorrectedTokens;
}
bool shouldKeepTokens() const {
return EnabledAndAllCorrectedTokens.first;
return (bool)pAllCorrectedTokens;
}
private:
/// Whether the SourceFile instance opts to collect underlying tokens and
/// the vector containing these tokens if so.
std::pair<bool, std::vector<Token>> EnabledAndAllCorrectedTokens;
/// If not null, the pointee vector should contain tokens of this source file.
std::unique_ptr<std::vector<Token>> pAllCorrectedTokens;
};

View File

@@ -1325,8 +1325,7 @@ SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
bool KeepTokens)
: FileUnit(FileUnitKind::Source, M),
BufferID(bufferID ? *bufferID : -1),
Kind(K),
EnabledAndAllCorrectedTokens(KeepTokens, std::vector<Token>()) {
Kind(K) {
M.getASTContext().addDestructorCleanup(*this);
performAutoImport(*this, ModImpKind);
@@ -1335,6 +1334,9 @@ SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
assert(!problem && "multiple main files?");
(void)problem;
}
if (KeepTokens) {
pAllCorrectedTokens.reset(new std::vector<Token>());
}
}
SourceFile::~SourceFile() {}