diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-11-30 18:02:36 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-11-30 18:02:36 +0000 |
commit | 41e115a81a3cb03964646321e630b7e64cb88f89 (patch) | |
tree | 70c0b863c6c5c40d9befcaf0097b75d689bc36e8 /clang/lib/Lex/PPDirectives.cpp | |
parent | 0a1801015c939c02b397fcd52a15c94b027fc897 (diff) | |
download | bcm5719-llvm-41e115a81a3cb03964646321e630b7e64cb88f89.tar.gz bcm5719-llvm-41e115a81a3cb03964646321e630b7e64cb88f89.zip |
Introduce an opt-in warning indicating when the compiler is treating
an #include/#import as a module import.
llvm-svn: 145500
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 140f793234a..5047be34853 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -22,6 +22,7 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/APInt.h" +#include "llvm/Support/ErrorHandling.h" using namespace clang; //===----------------------------------------------------------------------===// @@ -1208,6 +1209,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, llvm::SmallString<128> FilenameBuffer; StringRef Filename; SourceLocation End; + SourceLocation CharEnd; // the end of this directive, in characters switch (FilenameTok.getKind()) { case tok::eod: @@ -1218,6 +1220,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, case tok::string_literal: Filename = getSpelling(FilenameTok, FilenameBuffer); End = FilenameTok.getLocation(); + CharEnd = End.getLocWithOffset(Filename.size()); break; case tok::less: @@ -1227,6 +1230,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, if (ConcatenateIncludeName(FilenameBuffer, End)) return; // Found <eod> but no ">"? Diagnostic already emitted. Filename = FilenameBuffer.str(); + CharEnd = getLocForEndOfToken(End); break; default: Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename); @@ -1288,6 +1292,44 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, FilenameTok.getLocation())); std::reverse(Path.begin(), Path.end()); + // Warn that we're replacing the include/import with a module import. + llvm::SmallString<128> PathString; + for (unsigned I = 0, N = Path.size(); I != N; ++I) { + if (I) + PathString += '.'; + PathString += Path[I].first->getName(); + } + int IncludeKind = 0; + + switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) { + case tok::pp_include: + IncludeKind = 0; + break; + + case tok::pp_import: + IncludeKind = 1; + break; + + case tok::pp_include_next: + IncludeKind = 2; + break; + + case tok::pp___include_macros: + IncludeKind = 3; + break; + + default: + llvm_unreachable("unknown include directive kind"); + break; + } + + CharSourceRange ReplaceRange(SourceRange(HashLoc, CharEnd), + /*IsTokenRange=*/false); + Diag(HashLoc, diag::warn_auto_module_import) + << IncludeKind << PathString + << FixItHint::CreateReplacement(ReplaceRange, + "__import_module__ " + PathString.str().str() + ";"); + // Load the module. TheModuleLoader.loadModule(IncludeTok.getLocation(), Path); return; |