Implement preamble macros to augment a function body

Implement type checking support for preamble macros, which expands the
preamble macros and introduces them at the beginning of the function
body prior to type checking. Ensure that the resulting function bodies
type-check properly, including when composing multiple preamble macros
and with a preamble macro applied to the body of a function that
itself came from a body macro.
This commit is contained in:
Doug Gregor
2023-11-27 17:00:40 -08:00
parent 36a2dcd927
commit 380bad4e07
7 changed files with 172 additions and 7 deletions

View File

@@ -1209,11 +1209,12 @@ llvm::Optional<MacroRole> SourceFile::getFulfilledMacroRole() const {
}
SourceFile *SourceFile::getEnclosingSourceFile() const {
auto macroExpansion = getMacroExpansion();
if (!macroExpansion)
if (Kind != SourceFileKind::MacroExpansion)
return nullptr;
auto sourceLoc = macroExpansion.getStartLoc();
auto genInfo =
*getASTContext().SourceMgr.getGeneratedSourceInfo(*getBufferID());
auto sourceLoc = genInfo.originalSourceRange.getStart();
return getParentModule()->getSourceFileContainingLocation(sourceLoc);
}