[clang] 1744f4c - [clang][cli] NFC: Promote ParseLangArgs and ParseCodeGenArgs to members

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 15 07:41:55 PST 2021


Author: Jan Svoboda
Date: 2021-01-15T16:41:34+01:00
New Revision: 1744f4c676411ebd2e38afd5a6b56e5dd533c6ac

URL: https://github.com/llvm/llvm-project/commit/1744f4c676411ebd2e38afd5a6b56e5dd533c6ac
DIFF: https://github.com/llvm/llvm-project/commit/1744f4c676411ebd2e38afd5a6b56e5dd533c6ac.diff

LOG: [clang][cli] NFC: Promote ParseLangArgs and ParseCodeGenArgs to members

This patch promotes `ParseLangArgs` and `ParseCodeGenArgs` to members of `CompilerInvocation`. That will be useful in the following patch D94682, where we need to access protected members of `LangOptions` and `CodeGenOptions`. Both of those classes already have `friend CompilerInvocation`.

This is cleaner than keeping those functions freestanding and having to specify the exact signature of both in extra `friend` declarations.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D94681

Added: 
    

Modified: 
    clang/include/clang/Frontend/CompilerInvocation.h
    clang/lib/Frontend/CompilerInvocation.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h
index 9f16c5077154..b65b087510ce 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -247,6 +247,18 @@ class CompilerInvocation : public CompilerInvocationBase {
   /// \returns - True if parsing was successful, false otherwise
   bool parseSimpleArgs(const llvm::opt::ArgList &Args,
                        DiagnosticsEngine &Diags);
+
+  /// Parse command line options that map to LangOptions.
+  static void ParseLangArgs(LangOptions &Opts, llvm::opt::ArgList &Args,
+                            InputKind IK, const llvm::Triple &T,
+                            std::vector<std::string> &Includes,
+                            DiagnosticsEngine &Diags);
+
+  /// Parse command line options that map to CodeGenOptions.
+  static bool ParseCodeGenArgs(CodeGenOptions &Opts, llvm::opt::ArgList &Args,
+                               InputKind IK, DiagnosticsEngine &Diags,
+                               const llvm::Triple &T,
+                               const std::string &OutputFile);
 };
 
 IntrusiveRefCntPtr<llvm::vfs::FileSystem>

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index c672834a7970..25b3610e50db 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -907,9 +907,11 @@ static void setPGOUseInstrumentor(CodeGenOptions &Opts,
     Opts.setProfileUse(CodeGenOptions::ProfileClangInstr);
 }
 
-static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
-                             DiagnosticsEngine &Diags, const llvm::Triple &T,
-                             const std::string &OutputFile) {
+bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
+                                          InputKind IK,
+                                          DiagnosticsEngine &Diags,
+                                          const llvm::Triple &T,
+                                          const std::string &OutputFile) {
   bool Success = true;
 
   unsigned OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
@@ -2151,10 +2153,10 @@ static void GenerateLangArgs(const LangOptions &Opts,
     Args.push_back(SA(GetOptName(OPT_fdeclare_opencl_builtins)));
 }
 
-static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
-                          const llvm::Triple &T,
-                          std::vector<std::string> &Includes,
-                          DiagnosticsEngine &Diags) {
+void CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
+                                       InputKind IK, const llvm::Triple &T,
+                                       std::vector<std::string> &Includes,
+                                       DiagnosticsEngine &Diags) {
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
   if (const Arg *A = Args.getLastArg(OPT_std_EQ)) {


        


More information about the cfe-commits mailing list