mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Source manager] Start tracking generated-source info in the source manager
Establish the relationship for generated sources, whether for macro expansions or (via a small stretch) replacing function bodies with other bodies, in the source manager itself. This makes the information available for diagnostic rendering, and unifies a little bit of the representation, although it isn't used for much yet.
This commit is contained in:
@@ -877,10 +877,20 @@ void SourceFile::lookupClassMembers(ImportPath::Access accessPath,
|
||||
cache.lookupClassMembers(accessPath, consumer);
|
||||
}
|
||||
|
||||
SourceFile *SourceFile::getEnclosingSourceFile() const {
|
||||
ASTNode SourceFile::getMacroExpansion() const {
|
||||
if (Kind != SourceFileKind::MacroExpansion)
|
||||
return nullptr;
|
||||
|
||||
auto genInfo =
|
||||
*getASTContext().SourceMgr.getGeneratedSourceInfo(*getBufferID());
|
||||
return ASTNode::getFromOpaqueValue(genInfo.astNode);
|
||||
}
|
||||
|
||||
SourceFile *SourceFile::getEnclosingSourceFile() const {
|
||||
auto macroExpansion = getMacroExpansion();
|
||||
if (!macroExpansion)
|
||||
return nullptr;
|
||||
|
||||
auto sourceLoc = macroExpansion.getStartLoc();
|
||||
return getParentModule()->getSourceFileContainingLocation(sourceLoc);
|
||||
}
|
||||
@@ -3263,17 +3273,13 @@ ModuleDecl::computeFileIDMap(bool shouldDiagnose) const {
|
||||
|
||||
SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
|
||||
Optional<unsigned> bufferID,
|
||||
ParsingOptions parsingOpts, bool isPrimary,
|
||||
ASTNode macroExpansion)
|
||||
ParsingOptions parsingOpts, bool isPrimary)
|
||||
: FileUnit(FileUnitKind::Source, M), BufferID(bufferID ? *bufferID : -1),
|
||||
ParsingOpts(parsingOpts), IsPrimary(isPrimary),
|
||||
macroExpansion(macroExpansion), Kind(K) {
|
||||
ParsingOpts(parsingOpts), IsPrimary(isPrimary), Kind(K) {
|
||||
M.getASTContext().addDestructorCleanup(*this);
|
||||
|
||||
assert(!IsPrimary || M.isMainModule() &&
|
||||
"A primary cannot appear outside the main module");
|
||||
assert(macroExpansion.isNull() == (K != SourceFileKind::MacroExpansion) &&
|
||||
"Macro expansions always need an expansion node");
|
||||
|
||||
if (isScriptMode()) {
|
||||
bool problem = M.registerEntryPointFile(this, SourceLoc(), None);
|
||||
|
||||
Reference in New Issue
Block a user