zcov: / include/clang/Driver/Option.h


Files: 1 Branches Taken: 29.5% 13 / 44
Generated: 2010-02-10 01:31 Branches Executed: 54.5% 24 / 44
Line Coverage: 86.5% 32 / 37


Programs: 16 Runs 24144


       1                 : //===--- Option.h - Abstract Driver Options ---------------------*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : 
      10                 : #ifndef CLANG_DRIVER_OPTION_H_
      11                 : #define CLANG_DRIVER_OPTION_H_
      12                 : 
      13                 : #include "clang/Driver/OptSpecifier.h"
      14                 : #include "llvm/Support/Casting.h"
      15                 : using llvm::isa;
      16                 : using llvm::cast;
      17                 : using llvm::cast_or_null;
      18                 : using llvm::dyn_cast;
      19                 : using llvm::dyn_cast_or_null;
      20                 : 
      21                 : namespace clang {
      22                 : namespace driver {
      23                 :   class Arg;
      24                 :   class InputArgList;
      25                 :   class OptionGroup;
      26                 : 
      27                 :   /// Option - Abstract representation for a single form of driver
      28                 :   /// argument.
      29                 :   ///
      30                 :   /// An Option class represents a form of option that the driver
      31                 :   /// takes, for example how many arguments the option has and how
      32                 :   /// they can be provided. Individual option instances store
      33                 :   /// additional information about what group the option is a member
      34                 :   /// of (if any), if the option is an alias, and a number of
      35                 :   /// flags. At runtime the driver parses the command line into
      36                 :   /// concrete Arg instances, each of which corresponds to a
      37                 :   /// particular Option instance.
      38                 :   class Option {
      39                 :   public:
      40                 :     enum OptionClass {
      41                 :       GroupClass = 0,
      42                 :       InputClass,
      43                 :       UnknownClass,
      44                 :       FlagClass,
      45                 :       JoinedClass,
      46                 :       SeparateClass,
      47                 :       CommaJoinedClass,
      48                 :       MultiArgClass,
      49                 :       JoinedOrSeparateClass,
      50                 :       JoinedAndSeparateClass
      51                 :     };
      52                 : 
      53                 :   private:
      54                 :     OptionClass Kind;
      55                 : 
      56                 :     /// The option ID.
      57                 :     OptSpecifier ID;
      58                 : 
      59                 :     /// The option name.
      60                 :     const char *Name;
      61                 : 
      62                 :     /// Group this option is a member of, if any.
      63                 :     const OptionGroup *Group;
      64                 : 
      65                 :     /// Option that this is an alias for, if any.
      66                 :     const Option *Alias;
      67                 : 
      68                 :     /// Unsupported options will not be rejected.
      69                 :     bool Unsupported : 1;
      70                 : 
      71                 :     /// Treat this option like a linker input?
      72                 :     bool LinkerInput : 1;
      73                 : 
      74                 :     /// When rendering as an input, don't render the option.
      75                 : 
      76                 :     // FIXME: We should ditch the render/renderAsInput distinction.
      77                 :     bool NoOptAsInput : 1;
      78                 : 
      79                 :     /// Always render this option as separate form its value.
      80                 :     bool ForceSeparateRender : 1;
      81                 : 
      82                 :     /// Always render this option joined with its value.
      83                 :     bool ForceJoinedRender : 1;
      84                 : 
      85                 :     /// This option is only consumed by the driver.
      86                 :     bool DriverOption : 1;
      87                 : 
      88                 :     /// This option should not report argument unused errors.
      89                 :     bool NoArgumentUnused : 1;
      90                 : 
      91                 :   protected:
      92                 :     Option(OptionClass Kind, OptSpecifier ID, const char *Name,
      93                 :            const OptionGroup *Group, const Option *Alias);
      94                 :   public:
      95                 :     virtual ~Option();
      96                 : 
      97             2874:     unsigned getID() const { return ID.getID(); }
      98             7968:     OptionClass getKind() const { return Kind; }
      99            10188:     const char *getName() const { return Name; }
     100                 :     const OptionGroup *getGroup() const { return Group; }
     101                 :     const Option *getAlias() const { return Alias; }
     102                 : 
     103             1426:     bool isUnsupported() const { return Unsupported; }
     104                1:     void setUnsupported(bool Value) { Unsupported = Value; }
     105                 : 
     106             1167:     bool isLinkerInput() const { return LinkerInput; }
     107                7:     void setLinkerInput(bool Value) { LinkerInput = Value; }
     108                 : 
     109                7:     bool hasNoOptAsInput() const { return NoOptAsInput; }
     110               72:     void setNoOptAsInput(bool Value) { NoOptAsInput = Value; }
     111                 : 
     112               52:     bool hasForceSeparateRender() const { return ForceSeparateRender; }
     113                0:     void setForceSeparateRender(bool Value) { ForceSeparateRender = Value; }
     114                 : 
     115               60:     bool hasForceJoinedRender() const { return ForceJoinedRender; }
     116                0:     void setForceJoinedRender(bool Value) { ForceJoinedRender = Value; }
     117                 : 
     118                2:     bool isDriverOption() const { return DriverOption; }
     119             3401:     void setDriverOption(bool Value) { DriverOption = Value; }
     120                 : 
     121               29:     bool hasNoArgumentUnused() const { return NoArgumentUnused; }
     122                8:     void setNoArgumentUnused(bool Value) { NoArgumentUnused = Value; }
     123                 : 
                        4: branch 0 taken
                       38: branch 1 taken
                        4: branch 2 taken
                        0: branch 3 not taken
     124               42:     bool hasForwardToGCC() const { return !DriverOption && !LinkerInput; }
     125                 : 
     126                 :     /// getUnaliasedOption - Return the final option this option
     127                 :     /// aliases (itself, if the option has no alias).
     128                 :     const Option *getUnaliasedOption() const {
     129                 :       if (Alias) return Alias->getUnaliasedOption();
     130                 :       return this;
     131                 :     }
     132                 : 
     133                 :     /// getRenderName - Return the name to use when rendering this
     134                 :     /// option.
     135                 :     const char *getRenderName() const {
     136                 :       return getUnaliasedOption()->getName();
     137                 :     }
     138                 : 
     139                 :     /// matches - Predicate for whether this option is part of the
     140                 :     /// given option (which may be a group).
     141                 :     ///
     142                 :     /// Note that matches against options which are an alias should never be
     143                 :     /// done -- aliases do not participate in matching and so such a query will
     144                 :     /// always be false.
     145                 :     bool matches(OptSpecifier ID) const;
     146                 : 
     147                 :     /// accept - Potentially accept the current argument, returning a
     148                 :     /// new Arg instance, or 0 if the option does not accept this
     149                 :     /// argument (or the argument is missing values).
     150                 :     ///
     151                 :     /// If the option accepts the current argument, accept() sets
     152                 :     /// Index to the position where argument parsing should resume
     153                 :     /// (even if the argument is missing values).
     154                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const = 0;
     155                 : 
     156                 :     void dump() const;
     157                 : 
     158                 :     static bool classof(const Option *) { return true; }
     159                 :   };
     160                 : 
     161                 :   /// OptionGroup - A set of options which are can be handled uniformly
     162                 :   /// by the driver.
                     3056: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     163             3056:   class OptionGroup : public Option {
     164                 :   public:
     165                 :     OptionGroup(OptSpecifier ID, const char *Name, const OptionGroup *Group);
     166                 : 
     167                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
     168                 : 
     169             6540:     static bool classof(const Option *O) {
     170             6540:       return O->getKind() == Option::GroupClass;
     171                 :     }
     172                 :     static bool classof(const OptionGroup *) { return true; }
     173                 :   };
     174                 : 
     175                 :   // Dummy option classes.
     176                 : 
     177                 :   /// InputOption - Dummy option class for representing driver inputs.
                     2771: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     178             2771:   class InputOption : public Option {
     179                 :   public:
     180                 :     InputOption(OptSpecifier ID);
     181                 : 
     182                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
     183                 : 
     184             1401:     static bool classof(const Option *O) {
     185             1401:       return O->getKind() == Option::InputClass;
     186                 :     }
     187                 :     static bool classof(const InputOption *) { return true; }
     188                 :   };
     189                 : 
     190                 :   /// UnknownOption - Dummy option class for represent unknown arguments.
                     2771: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     191             2771:   class UnknownOption : public Option {
     192                 :   public:
     193                 :     UnknownOption(OptSpecifier ID);
     194                 : 
     195                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
     196                 : 
     197                 :     static bool classof(const Option *O) {
     198                 :       return O->getKind() == Option::UnknownClass;
     199                 :     }
     200                 :     static bool classof(const UnknownOption *) { return true; }
     201                 :   };
     202                 : 
     203                 :   // Normal options.
     204                 : 
                     6069: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     205             6069:   class FlagOption : public Option {
     206                 :   public:
     207                 :     FlagOption(OptSpecifier ID, const char *Name, const OptionGroup *Group,
     208                 :                const Option *Alias);
     209                 : 
     210                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
     211                 : 
     212               27:     static bool classof(const Option *O) {
     213               27:       return O->getKind() == Option::FlagClass;
     214                 :     }
     215                 :     static bool classof(const FlagOption *) { return true; }
     216                 :   };
     217                 : 
                      877: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     218              877:   class JoinedOption : public Option {
     219                 :   public:
     220                 :     JoinedOption(OptSpecifier ID, const char *Name, const OptionGroup *Group,
     221                 :                  const Option *Alias);
     222                 : 
     223                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
     224                 : 
     225                 :     static bool classof(const Option *O) {
     226                 :       return O->getKind() == Option::JoinedClass;
     227                 :     }
     228                 :     static bool classof(const JoinedOption *) { return true; }
     229                 :   };
     230                 : 
                     2985: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     231             2985:   class SeparateOption : public Option {
     232                 :   public:
     233                 :     SeparateOption(OptSpecifier ID, const char *Name,
     234                 :                    const OptionGroup *Group, const Option *Alias);
     235                 : 
     236                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
     237                 : 
     238                 :     static bool classof(const Option *O) {
     239                 :       return O->getKind() == Option::SeparateClass;
     240                 :     }
     241                 :     static bool classof(const SeparateOption *) { return true; }
     242                 :   };
     243                 : 
                        1: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     244                1:   class CommaJoinedOption : public Option {
     245                 :   public:
     246                 :     CommaJoinedOption(OptSpecifier ID, const char *Name,
     247                 :                       const OptionGroup *Group, const Option *Alias);
     248                 : 
     249                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
     250                 : 
     251                 :     static bool classof(const Option *O) {
     252                 :       return O->getKind() == Option::CommaJoinedClass;
     253                 :     }
     254                 :     static bool classof(const CommaJoinedOption *) { return true; }
     255                 :   };
     256                 : 
     257                 :   // FIXME: Fold MultiArgOption into SeparateOption?
     258                 : 
     259                 :   /// MultiArgOption - An option which takes multiple arguments (these
     260                 :   /// are always separate arguments).
                        9: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     261                9:   class MultiArgOption : public Option {
     262                 :     unsigned NumArgs;
     263                 : 
     264                 :   public:
     265                 :     MultiArgOption(OptSpecifier ID, const char *Name, const OptionGroup *Group,
     266                 :                    const Option *Alias, unsigned NumArgs);
     267                 : 
     268                0:     unsigned getNumArgs() const { return NumArgs; }
     269                 : 
     270                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
     271                 : 
     272                0:     static bool classof(const Option *O) {
     273                0:       return O->getKind() == Option::MultiArgClass;
     274                 :     }
     275                 :     static bool classof(const MultiArgOption *) { return true; }
     276                 :   };
     277                 : 
     278                 :   /// JoinedOrSeparateOption - An option which either literally
     279                 :   /// prefixes its (non-empty) value, or is follwed by a value.
                      230: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     280              230:   class JoinedOrSeparateOption : public Option {
     281                 :   public:
     282                 :     JoinedOrSeparateOption(OptSpecifier ID, const char *Name,
     283                 :                            const OptionGroup *Group, const Option *Alias);
     284                 : 
     285                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
     286                 : 
     287                 :     static bool classof(const Option *O) {
     288                 :       return O->getKind() == Option::JoinedOrSeparateClass;
     289                 :     }
     290                 :     static bool classof(const JoinedOrSeparateOption *) { return true; }
     291                 :   };
     292                 : 
     293                 :   /// JoinedAndSeparateOption - An option which literally prefixes its
     294                 :   /// value and is followed by another value.
                        4: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     295                4:   class JoinedAndSeparateOption : public Option {
     296                 :   public:
     297                 :     JoinedAndSeparateOption(OptSpecifier ID, const char *Name,
     298                 :                             const OptionGroup *Group, const Option *Alias);
     299                 : 
     300                 :     virtual Arg *accept(const InputArgList &Args, unsigned &Index) const;
     301                 : 
     302                 :     static bool classof(const Option *O) {
     303                 :       return O->getKind() == Option::JoinedAndSeparateClass;
     304                 :     }
     305                 :     static bool classof(const JoinedAndSeparateOption *) { return true; }
     306                 :   };
     307                 : 
     308                 : } // end namespace driver
     309                 : } // end namespace clang
     310                 : 
     311                 : #endif

Generated: 2010-02-10 01:31 by zcov