From 752c74d99b647710a495c2ff5f815c30a30c3264 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 3 Jan 2012 17:07:34 +0000 Subject: [PATCH] Add a "Modules" language option, which subsumes the previous "AutoModuleImport" preprocessor option and is tied to -fmodules. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147448 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/LangOptions.def | 2 +- include/clang/Frontend/PreprocessorOptions.h | 5 ----- include/clang/Lex/Preprocessor.h | 6 ------ lib/Frontend/CompilerInvocation.cpp | 4 +++- lib/Frontend/InitPreprocessor.cpp | 4 ---- lib/Lex/PPDirectives.cpp | 4 ++-- lib/Lex/Preprocessor.cpp | 1 - 7 files changed, 6 insertions(+), 20 deletions(-) diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def index 6c1038ee1d..e6530afceb 100644 --- a/include/clang/Basic/LangOptions.def +++ b/include/clang/Basic/LangOptions.def @@ -90,7 +90,7 @@ LANGOPT(Blocks , 1, 0, "blocks extension to C") BENIGN_LANGOPT(EmitAllDecls , 1, 0, "support for emitting all declarations") LANGOPT(MathErrno , 1, 1, "errno support for math functions") BENIGN_LANGOPT(HeinousExtensions , 1, 0, "Extensions that we really don't like and may be ripped out at any time") - +LANGOPT(Modules , 1, 0, "modules extension to C") LANGOPT(Optimize , 1, 0, "__OPTIMIZE__ predefined macro") LANGOPT(OptimizeSize , 1, 0, "__OPTIMIZE_SIZE__ predefined macro") LANGOPT(Static , 1, 0, "__STATIC__ predefined macro (as opposed to __DYNAMIC__)") diff --git a/include/clang/Frontend/PreprocessorOptions.h b/include/clang/Frontend/PreprocessorOptions.h index 0ee8cb3874..2394b63304 100644 --- a/include/clang/Frontend/PreprocessorOptions.h +++ b/include/clang/Frontend/PreprocessorOptions.h @@ -50,10 +50,6 @@ public: /// record of all macro definitions and /// expansions. - /// \brief Whether we should automatically translate #include or #import - /// operations into module imports when possible. - unsigned AutoModuleImport : 1; - /// \brief Whether the detailed preprocessing record includes nested macro /// expansions. unsigned DetailedRecordIncludesNestedMacroExpansions : 1; @@ -166,7 +162,6 @@ public: public: PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), - AutoModuleImport(false), DetailedRecordIncludesNestedMacroExpansions(true), DisablePCHValidation(false), DisableStatCache(false), DumpDeserializedPCHDecls(false), diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 8e7ab5edbf..1716ba3b9e 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -107,7 +107,6 @@ class Preprocessor : public llvm::RefCountedBase { bool KeepComments : 1; bool KeepMacroComments : 1; bool SuppressIncludeNotFoundError : 1; - bool AutoModuleImport : 1; // State that changes while the preprocessor runs: bool InMacroArgs : 1; // True if parsing fn macro invocation args. @@ -397,11 +396,6 @@ public: return SuppressIncludeNotFoundError; } - /// \brief Specify whether automatic module imports are enabled. - void setAutoModuleImport(bool AutoModuleImport = true) { - this->AutoModuleImport = AutoModuleImport; - } - /// isCurrentLexer - Return true if we are lexing directly from the specified /// lexer. bool isCurrentLexer(const PreprocessorLexer *L) const { diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 1b335c63f9..60e3442837 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -716,6 +716,8 @@ static void LangOptsToArgs(const LangOptions &Opts, Res.push_back("-fblocks"); if (Opts.BlocksRuntimeOptional) Res.push_back("-fblocks-runtime-optional"); + if (Opts.Modules) + Res.push_back("-fmodules"); if (Opts.EmitAllDecls) Res.push_back("-femit-all-decls"); if (Opts.MathErrno) @@ -1814,6 +1816,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.RTTI = !Args.hasArg(OPT_fno_rtti); Opts.Blocks = Args.hasArg(OPT_fblocks); Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional); + Opts.Modules = Args.hasArg(OPT_fmodules); Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char); Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar); Opts.ShortEnums = Args.hasArg(OPT_fshort_enums); @@ -1903,7 +1906,6 @@ static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, Opts.TokenCache = Opts.ImplicitPTHInclude; Opts.UsePredefines = !Args.hasArg(OPT_undef); Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record); - Opts.AutoModuleImport = Args.hasArg(OPT_fmodules); Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch); Opts.DumpDeserializedPCHDecls = Args.hasArg(OPT_dump_deserialized_pch_decls); diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 74c2ec90ec..c736ca3ccc 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -627,10 +627,6 @@ void clang::InitializePreprocessor(Preprocessor &PP, InitializeFileRemapping(PP.getDiagnostics(), PP.getSourceManager(), PP.getFileManager(), InitOpts); - // Specify whether the preprocessor should replace #include/#import with - // module imports when plausible. - PP.setAutoModuleImport(InitOpts.AutoModuleImport); - // Emit line markers for various builtin sections of the file. We don't do // this in asm preprocessor mode, because "# 4" is not a line marker directive // in this mode. diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 4d700aef03..2dfae872e2 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -1294,7 +1294,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, const FileEntry *File = LookupFile( Filename, isAngled, LookupFrom, CurDir, Callbacks ? &SearchPath : NULL, Callbacks ? &RelativePath : NULL, - AutoModuleImport? &SuggestedModule : 0); + getLangOptions().Modules? &SuggestedModule : 0); if (Callbacks) { if (!File) { @@ -1308,7 +1308,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, // Try the lookup again, skipping the cache. File = LookupFile(Filename, isAngled, LookupFrom, CurDir, 0, 0, - AutoModuleImport ? &SuggestedModule : 0, + getLangOptions().Modules? &SuggestedModule : 0, /*SkipCache*/true); } } diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 90b6798466..08d8b920d1 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -130,7 +130,6 @@ void Preprocessor::Initialize(const TargetInfo &Target) { KeepComments = false; KeepMacroComments = false; SuppressIncludeNotFoundError = false; - AutoModuleImport = false; // Macro expansion is enabled. DisableMacroExpansion = false; -- 2.40.0