CLK_LexAfterModuleImport
} CurLexerKind;
- /// \brief True if the current lexer is for a submodule.
- bool CurIsSubmodule;
+ /// \brief If the current lexer is for a submodule that is being built, this
+ /// is that submodule.
+ Module *CurSubmodule;
/// \brief Keeps track of the stack of files currently
/// \#included, and macros currently being expanded from, not counting
/// CurLexer/CurTokenLexer.
struct IncludeStackInfo {
enum CurLexerKind CurLexerKind;
- bool IsSubmodule;
+ Module *TheSubmodule;
Lexer *TheLexer;
PTHLexer *ThePTHLexer;
PreprocessorLexer *ThePPLexer;
TokenLexer *TheTokenLexer;
const DirectoryLookup *TheDirLookup;
- IncludeStackInfo(enum CurLexerKind K, bool SM, Lexer *L, PTHLexer *P,
+ IncludeStackInfo(enum CurLexerKind K, Module *M, Lexer *L, PTHLexer *P,
PreprocessorLexer *PPL, TokenLexer *TL,
const DirectoryLookup *D)
- : CurLexerKind(K), IsSubmodule(SM), TheLexer(L), ThePTHLexer(P),
+ : CurLexerKind(K), TheSubmodule(M), TheLexer(L), ThePTHLexer(P),
ThePPLexer(PPL), TheTokenLexer(TL), TheDirLookup(D) {}
};
std::vector<IncludeStackInfo> IncludeMacroStack;
void EndSourceFile();
/// \brief Add a source file to the top of the include stack and
- /// start lexing tokens from it instead of the current buffer.
+ /// start lexing tokens from it instead of the current buffer.
///
- /// Emit an error and don't enter the file on error.
- void EnterSourceFile(FileID CurFileID, const DirectoryLookup *Dir,
- SourceLocation Loc, bool IsSubmodule = false);
+ /// Emits a diagnostic, doesn't enter the file, and returns true on error.
+ bool EnterSourceFile(FileID CurFileID, const DirectoryLookup *Dir,
+ SourceLocation Loc);
/// \brief Add a Macro to the top of the include stack and start lexing
- /// tokens from it instead of the current buffer.
+ /// tokens from it instead of the current buffer.
///
/// \param Args specifies the tokens input to a function-like macro.
/// \param ILEnd specifies the location of the ')' for a function-like macro
void PushIncludeMacroStack() {
IncludeMacroStack.push_back(IncludeStackInfo(CurLexerKind,
- CurIsSubmodule,
+ CurSubmodule,
CurLexer.take(),
CurPTHLexer.take(),
CurPPLexer,
CurPPLexer = IncludeMacroStack.back().ThePPLexer;
CurTokenLexer.reset(IncludeMacroStack.back().TheTokenLexer);
CurDirLookup = IncludeMacroStack.back().TheDirLookup;
+ CurSubmodule = IncludeMacroStack.back().TheSubmodule;
CurLexerKind = IncludeMacroStack.back().CurLexerKind;
- CurIsSubmodule = IncludeMacroStack.back().IsSubmodule;
IncludeMacroStack.pop_back();
}
/// \brief Add a lexer to the top of the include stack and
/// start lexing tokens from it instead of the current buffer.
- void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir,
- bool IsSubmodule = false);
+ void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir);
/// \brief Add a lexer to the top of the include stack and
/// start getting tokens from it using the PTH cache.
- void EnterSourceFileWithPTH(PTHLexer *PL, const DirectoryLookup *Dir,
- bool IsSubmodule = false);
+ void EnterSourceFileWithPTH(PTHLexer *PL, const DirectoryLookup *Dir);
/// \brief Set the FileID for the preprocessor predefines.
void setPredefinesFileID(FileID FID) {
}
// If all is good, enter the new file!
- EnterSourceFile(FID, CurDir, FilenameTok.getLocation(),
- static_cast<bool>(BuildingModule));
+ if (EnterSourceFile(FID, CurDir, FilenameTok.getLocation()))
+ return;
// If we're walking into another part of the same module, let the parser
// know that any future declarations are within that other submodule.
- if (BuildingModule)
+ if (BuildingModule) {
+ assert(!CurSubmodule && "should not have marked this as a module yet");
+ CurSubmodule = BuildingModule.getModule();
+
EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_begin,
- BuildingModule.getModule());
+ CurSubmodule);
+ }
}
/// HandleIncludeNextDirective - Implements \#include_next.
/// EnterSourceFile - Add a source file to the top of the include stack and
/// start lexing tokens from it instead of the current buffer.
-void Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir,
- SourceLocation Loc, bool IsSubmodule) {
+bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir,
+ SourceLocation Loc) {
assert(!CurTokenLexer && "Cannot #include a file inside a macro!");
++NumEnteredSourceFiles;
if (PTH) {
if (PTHLexer *PL = PTH->CreateLexer(FID)) {
- EnterSourceFileWithPTH(PL, CurDir, IsSubmodule);
- return;
+ EnterSourceFileWithPTH(PL, CurDir);
+ return false;
}
}
SourceLocation FileStart = SourceMgr.getLocForStartOfFile(FID);
Diag(Loc, diag::err_pp_error_opening_file)
<< std::string(SourceMgr.getBufferName(FileStart)) << "";
- return;
+ return true;
}
if (isCodeCompletionEnabled() &&
CodeCompletionFileLoc.getLocWithOffset(CodeCompletionOffset);
}
- EnterSourceFileWithLexer(new Lexer(FID, InputFile, *this), CurDir,
- IsSubmodule);
- return;
+ EnterSourceFileWithLexer(new Lexer(FID, InputFile, *this), CurDir);
+ return false;
}
/// EnterSourceFileWithLexer - Add a source file to the top of the include stack
/// and start lexing tokens from it instead of the current buffer.
void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer,
- const DirectoryLookup *CurDir,
- bool IsSubmodule) {
+ const DirectoryLookup *CurDir) {
// Add the current lexer to the include stack.
if (CurPPLexer || CurTokenLexer)
CurLexer.reset(TheLexer);
CurPPLexer = TheLexer;
CurDirLookup = CurDir;
- CurIsSubmodule = IsSubmodule;
+ CurSubmodule = 0;
if (CurLexerKind != CLK_LexAfterModuleImport)
CurLexerKind = CLK_Lexer;
/// EnterSourceFileWithPTH - Add a source file to the top of the include stack
/// and start getting tokens from it using the PTH cache.
void Preprocessor::EnterSourceFileWithPTH(PTHLexer *PL,
- const DirectoryLookup *CurDir,
- bool IsSubmodule) {
+ const DirectoryLookup *CurDir) {
if (CurPPLexer || CurTokenLexer)
PushIncludeMacroStack();
CurDirLookup = CurDir;
CurPTHLexer.reset(PL);
CurPPLexer = CurPTHLexer.get();
- CurIsSubmodule = IsSubmodule;
+ CurSubmodule = 0;
if (CurLexerKind != CLK_LexAfterModuleImport)
CurLexerKind = CLK_PTHLexer;
if (Callbacks && !isEndOfMacro && CurPPLexer)
ExitedFID = CurPPLexer->getFileID();
- // If this file corresponded to a submodule, notify the parser that we've
- // left that submodule.
- bool LeavingSubmodule = CurIsSubmodule && CurLexer;
+ bool LeavingSubmodule = CurSubmodule && CurLexer;
if (LeavingSubmodule) {
+ // Notify the parser that we've left the module.
const char *EndPos = getCurLexerEndPos();
Result.startToken();
CurLexer->BufferPtr = EndPos;
CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_module_end);
Result.setAnnotationEndLoc(Result.getLocation());
- Result.setAnnotationValue(0);
+ Result.setAnnotationValue(CurSubmodule);
}
// We're done with the #included file.
CodeComplete(0), CodeCompletionFile(0), CodeCompletionOffset(0),
LastTokenWasAt(false), ModuleImportExpectsIdentifier(false),
CodeCompletionReached(0), SkipMainFilePreamble(0, true), CurPPLexer(0),
- CurDirLookup(0), CurLexerKind(CLK_Lexer), CurIsSubmodule(false),
+ CurDirLookup(0), CurLexerKind(CLK_Lexer), CurSubmodule(0),
Callbacks(0), MacroArgCache(0), Record(0), MIChainHead(0), MICache(0),
DeserialMIChainHead(0) {
OwnsHeaderSearch = OwnsHeaders;