On Wed, Oct 10, 2012 at 3:08 PM, Michael Spencer <[email protected]> wrote: > This patch extracts non-option-paring specific flags from the Option class. > > http://llvm-reviews.chandlerc.com/D58 > > Files: > include/clang/Driver/Option.h > lib/Driver/Driver.cpp > lib/Driver/ToolChains.cpp > lib/Driver/Tools.cpp > lib/Frontend/CompilerInvocation.cpp > > Index: include/clang/Driver/Option.h > =================================================================== > --- include/clang/Driver/Option.h > +++ include/clang/Driver/Option.h > @@ -21,15 +21,20 @@ > class ArgList; > > namespace options { > + /// Base flags for all options. Custom flags may be added after. > enum DriverFlag { > - DriverOption = (1 << 0), > - HelpHidden = (1 << 1), > - LinkerInput = (1 << 2), > - NoArgumentUnused = (1 << 3), > - NoForward = (1 << 4), > - RenderAsInput = (1 << 5), > - RenderJoined = (1 << 6), > - RenderSeparate = (1 << 7), > + HelpHidden = (1 << 0), > + RenderAsInput = (1 << 1), > + RenderJoined = (1 << 2), > + RenderSeparate = (1 << 3), > + }; > + > + /// Flags specifically for clang options. > + enum ClangFlags { > + DriverOption = (1 << 4), > + LinkerInput = (1 << 5), > + NoArgumentUnused = (1 << 6), > + NoForward = (1 << 7), > Unsupported = (1 << 8), > CC1Option = (1 << 9) > }; > @@ -68,7 +73,7 @@ > RenderValuesStyle > }; > > - private: > + protected: > const OptTable::Info *Info; > const OptTable *Owner; > > @@ -80,18 +85,15 @@ > return Info != 0; > } > > + const Option getGroup() const { return Owner->getOption(Info->GroupID); } > + const Option getAlias() const { return Owner->getOption(Info->AliasID); } > + > unsigned getID() const { return Info->ID; } > OptionClass getKind() const { return OptionClass(Info->Kind); } > StringRef getName() const { return Info->Name; } > - const Option getGroup() const { return Owner->getOption(Info->GroupID); } > - const Option getAlias() const { return Owner->getOption(Info->AliasID); } > > unsigned getNumArgs() const { return Info->Param; } > > - bool isUnsupported() const { return Info->Flags & options::Unsupported; } > - > - bool isLinkerInput() const { return Info->Flags & options::LinkerInput; } > - > bool hasNoOptAsInput() const { return Info->Flags & > options::RenderAsInput;} > > RenderStyleKind getRenderStyle() const { > @@ -118,18 +120,9 @@ > llvm_unreachable("Unexpected kind!"); > } > > - bool isDriverOption() const { return Info->Flags & > options::DriverOption; } > - > - bool hasNoArgumentUnused() const { > - return Info->Flags & options::NoArgumentUnused; > - } > - > - bool hasNoForward() const { return Info->Flags & options::NoForward; } > - > - bool isCC1Option() const { return Info->Flags & options::CC1Option; } > - > - bool hasForwardToGCC() const { > - return !hasNoForward() && !isDriverOption() && !isLinkerInput(); > + /// Test if this option has the flag \a Val. > + bool hasFlag(unsigned Val) const { > + return Info->Flags & Val; > } > > /// getUnaliasedOption - Return the final option this option > Index: lib/Driver/Driver.cpp > =================================================================== > --- lib/Driver/Driver.cpp > +++ lib/Driver/Driver.cpp > @@ -98,7 +98,7 @@ > for (ArgList::const_iterator it = Args->begin(), ie = Args->end(); > it != ie; ++it) { > Arg *A = *it; > - if (A->getOption().isUnsupported()) { > + if (A->getOption().hasFlag(options::Unsupported)) { > Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(*Args); > continue; > } > @@ -1033,7 +1033,7 @@ > } else > Inputs.push_back(std::make_pair(Ty, A)); > > - } else if (A->getOption().isLinkerInput()) { > + } else if (A->getOption().hasFlag(options::LinkerInput)) { > // Just treat as object type, we could make a special type for this if > // necessary. > Inputs.push_back(std::make_pair(types::TY_Object, A)); > @@ -1300,7 +1300,7 @@ > // DiagnosticsEngine, so that extra values, position, and so on could be > // printed. > if (!A->isClaimed()) { > - if (A->getOption().hasNoArgumentUnused()) > + if (A->getOption().hasFlag(options::NoArgumentUnused)) > continue; > > // Suppress the warning automatically if this is just a flag, and it > is an > Index: lib/Driver/ToolChains.cpp > =================================================================== > --- lib/Driver/ToolChains.cpp > +++ lib/Driver/ToolChains.cpp > @@ -737,7 +737,7 @@ > getDriver().Diag(diag::err_drv_invalid_Xarch_argument_with_args) > << A->getAsString(Args); > continue; > - } else if (XarchArg->getOption().isDriverOption()) { > + } else if (XarchArg->getOption().hasFlag(options::DriverOption)) { > getDriver().Diag(diag::err_drv_invalid_Xarch_argument_isdriver) > << A->getAsString(Args); > continue; > @@ -751,7 +751,7 @@ > // Linker input arguments require custom handling. The problem is that > we > // have already constructed the phase actions, so we can not treat > them as > // "input arguments". > - if (A->getOption().isLinkerInput()) { > + if (A->getOption().hasFlag(options::LinkerInput)) { > // Convert the argument into individual Zlinker_input_args. > for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) { > DAL->AddSeparateArg(OriginalArg, > Index: lib/Driver/Tools.cpp > =================================================================== > --- lib/Driver/Tools.cpp > +++ lib/Driver/Tools.cpp > @@ -200,6 +200,12 @@ > CmdArgs.push_back(Args.MakeArgString(ProfileRT)); > } > > +static bool forwardToGCC(const Option &O) { > + return !O.hasFlag(options::NoForward) && > + !O.hasFlag(options::DriverOption) && > + !O.hasFlag(options::LinkerInput); > +} > + > void Clang::AddPreprocessingOptions(Compilation &C, > const Driver &D, > const ArgList &Args, > @@ -3193,7 +3199,7 @@ > for (ArgList::const_iterator > it = Args.begin(), ie = Args.end(); it != ie; ++it) { > Arg *A = *it; > - if (A->getOption().hasForwardToGCC()) { > + if (forwardToGCC(A->getOption())) { > // Don't forward any -g arguments to assembly steps. > if (isa<AssembleJobAction>(JA) && > A->getOption().matches(options::OPT_g_Group)) > @@ -3418,7 +3424,7 @@ > for (ArgList::const_iterator > it = Args.begin(), ie = Args.end(); it != ie; ++it) { > Arg *A = *it; > - if (A->getOption().hasForwardToGCC()) { > + if (forwardToGCC(A->getOption())) { > // Don't forward any -g arguments to assembly steps. > if (isa<AssembleJobAction>(JA) && > A->getOption().matches(options::OPT_g_Group)) > Index: lib/Frontend/CompilerInvocation.cpp > =================================================================== > --- lib/Frontend/CompilerInvocation.cpp > +++ lib/Frontend/CompilerInvocation.cpp > @@ -2325,7 +2325,7 @@ > // Issue errors on arguments that are not valid for CC1. > for (ArgList::iterator I = Args->begin(), E = Args->end(); > I != E; ++I) { > - if (!(*I)->getOption().isCC1Option()) { > + if (!(*I)->getOption().hasFlag(options::CC1Option)) { > Diags.Report(diag::err_drv_unknown_argument) << > (*I)->getAsString(*Args); > Success = false; > }
CCing Daniel. Can't add arbitrary addresses on Phabricator. - Michael Spencer _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
