summaryrefslogtreecommitdiff
path: root/include/clang
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-04 08:33:23 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-04 08:33:23 +0000
commit2c6f6f3c170502c5b810102cf85f05732a2aa9d0 (patch)
tree9b60aa209aa4ea9b4fd9bcb135871b86f8614758 /include/clang
parent7f0f5dce3adcfce88d5c9a0ad0146a33c01a1e8f (diff)
downloadclang-2c6f6f3c170502c5b810102cf85f05732a2aa9d0.tar.gz
Driver: More Option implementation.
- Add Options.def file, collects option information. - Actual option instantiation is handled lazily by OptTable to allow the driver to not need to instantiate all options. - cast<> support for Option, other minor tweaks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66028 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r--include/clang/Driver/Option.h117
-rw-r--r--include/clang/Driver/Options.def57
-rw-r--r--include/clang/Driver/Options.h55
3 files changed, 205 insertions, 24 deletions
diff --git a/include/clang/Driver/Option.h b/include/clang/Driver/Option.h
index d5c667791e..dea44002db 100644
--- a/include/clang/Driver/Option.h
+++ b/include/clang/Driver/Option.h
@@ -10,6 +10,13 @@
#ifndef CLANG_DRIVER_OPTION_H_
#define CLANG_DRIVER_OPTION_H_
+#include "llvm/Support/Casting.h"
+using llvm::isa;
+using llvm::cast;
+using llvm::cast_or_null;
+using llvm::dyn_cast;
+using llvm::dyn_cast_or_null;
+
namespace clang {
namespace driver {
class Arg;
@@ -30,16 +37,16 @@ namespace driver {
class Option {
public:
enum OptionClass {
- GroupOption = 0,
- InputOption,
- UnknownOption,
- FlagOption,
- JoinedOption,
- SeparateOption,
- CommaJoinedOption,
- MultiArgOption,
- JoinedOrSeparateOption,
- JoinedAndSeparateOption
+ GroupClass = 0,
+ InputClass,
+ UnknownClass,
+ FlagClass,
+ JoinedClass,
+ SeparateClass,
+ CommaJoinedClass,
+ MultiArgClass,
+ JoinedOrSeparateClass,
+ JoinedAndSeparateClass
};
private:
@@ -56,7 +63,7 @@ namespace driver {
protected:
Option(OptionClass Kind, const char *Name,
- OptionGroup *Group, Option *Alias);
+ const OptionGroup *Group, const Option *Alias);
public:
virtual ~Option();
@@ -88,17 +95,24 @@ namespace driver {
///
/// May issue a missing argument error.
virtual Arg *accept(ArgList &Args, unsigned Index) const = 0;
+
+ void dump() const;
+
+ static bool classof(const Option *) { return true; }
};
/// OptionGroup - A set of options which are can be handled uniformly
/// by the driver.
class OptionGroup : public Option {
- OptionGroup *Group;
-
public:
- OptionGroup(const char *Name, OptionGroup *Group);
+ OptionGroup(const char *Name, const OptionGroup *Group);
virtual Arg *accept(ArgList &Args, unsigned Index) const;
+
+ static bool classof(const Option *O) {
+ return O->getKind() == Option::GroupClass;
+ }
+ static bool classof(const OptionGroup *) { return true; }
};
// Dummy option classes.
@@ -109,6 +123,11 @@ namespace driver {
InputOption();
virtual Arg *accept(ArgList &Args, unsigned Index) const;
+
+ static bool classof(const Option *O) {
+ return O->getKind() == Option::InputClass;
+ }
+ static bool classof(const InputOption *) { return true; }
};
/// UnknownOption - Dummy option class for represent unknown arguments.
@@ -117,33 +136,64 @@ namespace driver {
UnknownOption();
virtual Arg *accept(ArgList &Args, unsigned Index) const;
+
+ static bool classof(const Option *O) {
+ return O->getKind() == Option::UnknownClass;
+ }
+ static bool classof(const UnknownOption *) { return true; }
};
// Normal options.
class FlagOption : public Option {
public:
- FlagOption(const char *Name, OptionGroup *Group, Option *Alias);
+ FlagOption(const char *Name, const OptionGroup *Group, const Option *Alias);
virtual Arg *accept(ArgList &Args, unsigned Index) const;
+
+ static bool classof(const Option *O) {
+ return O->getKind() == Option::FlagClass;
+ }
+ static bool classof(const FlagOption *) { return true; }
};
class JoinedOption : public Option {
- JoinedOption(const char *Name, OptionGroup *Group, Option *Alias);
+ public:
+ JoinedOption(const char *Name, const OptionGroup *Group,
+ const Option *Alias);
virtual Arg *accept(ArgList &Args, unsigned Index) const;
+
+ static bool classof(const Option *O) {
+ return O->getKind() == Option::JoinedClass;
+ }
+ static bool classof(const JoinedOption *) { return true; }
};
- class CommaJoinedOption : public Option {
- CommaJoinedOption(const char *Name, OptionGroup *Group, Option *Alias);
+ class SeparateOption : public Option {
+ public:
+ SeparateOption(const char *Name, const OptionGroup *Group,
+ const Option *Alias);
virtual Arg *accept(ArgList &Args, unsigned Index) const;
+
+ static bool classof(const Option *O) {
+ return O->getKind() == Option::SeparateClass;
+ }
+ static bool classof(const SeparateOption *) { return true; }
};
- class SeparateOption : public Option {
- SeparateOption(const char *Name, OptionGroup *Group, Option *Alias);
+ class CommaJoinedOption : public Option {
+ public:
+ CommaJoinedOption(const char *Name, const OptionGroup *Group,
+ const Option *Alias);
virtual Arg *accept(ArgList &Args, unsigned Index) const;
+
+ static bool classof(const Option *O) {
+ return O->getKind() == Option::CommaJoinedClass;
+ }
+ static bool classof(const CommaJoinedOption *) { return true; }
};
/// MultiArgOption - An option which takes multiple arguments (these
@@ -152,28 +202,47 @@ namespace driver {
unsigned NumArgs;
public:
- MultiArgOption(const char *Name, OptionGroup *Group, Option *Alias,
- unsigned NumArgs);
+ MultiArgOption(const char *Name, const OptionGroup *Group,
+ const Option *Alias, unsigned NumArgs);
unsigned getNumArgs() const { return NumArgs; }
virtual Arg *accept(ArgList &Args, unsigned Index) const;
+
+ static bool classof(const Option *O) {
+ return O->getKind() == Option::MultiArgClass;
+ }
+ static bool classof(const MultiArgOption *) { return true; }
};
/// JoinedOrSeparateOption - An option which either literally
/// prefixes its (non-empty) value, or is follwed by a value.
class JoinedOrSeparateOption : public Option {
- JoinedOrSeparateOption(const char *Name, OptionGroup *Group, Option *Alias);
+ public:
+ JoinedOrSeparateOption(const char *Name, const OptionGroup *Group,
+ const Option *Alias);
virtual Arg *accept(ArgList &Args, unsigned Index) const;
+
+ static bool classof(const Option *O) {
+ return O->getKind() == Option::JoinedOrSeparateClass;
+ }
+ static bool classof(const JoinedOrSeparateOption *) { return true; }
};
/// JoinedAndSeparateOption - An option which literally prefixes its
/// value and is followed by another value.
class JoinedAndSeparateOption : public Option {
- JoinedAndSeparateOption(const char *Name, OptionGroup *Group, Option *Alias);
+ public:
+ JoinedAndSeparateOption(const char *Name, const OptionGroup *Group,
+ const Option *Alias);
virtual Arg *accept(ArgList &Args, unsigned Index) const;
+
+ static bool classof(const Option *O) {
+ return O->getKind() == Option::JoinedAndSeparateClass;
+ }
+ static bool classof(const JoinedAndSeparateOption *) { return true; }
};
} // end namespace driver
diff --git a/include/clang/Driver/Options.def b/include/clang/Driver/Options.def
new file mode 100644
index 0000000000..816678af6b
--- /dev/null
+++ b/include/clang/Driver/Options.def
@@ -0,0 +1,57 @@
+//===--- Options.def - Driver option info -----------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the driver option information. Users of this file
+// must define the OPTION macro to make use of this information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OPTION
+#error "Define OPTION prior to including this file!"
+#endif
+
+// OPTION(ID, KIND, NAME, GROUP, ALIAS, FLAGS, PARAM)
+
+// The first value provided to the macro specifies the internal name
+// of the option, and results in a clang::driver::options::XX enum
+// value for XX.
+
+// The second value is the option type, one of Group, Flag, Joined,
+// Separate, CommaJoined, JoinedOrSeparate, JoinedAndSeparate.
+
+// The third value is the option name.
+
+// The fourth value is the internal name of the option group, or 0 if
+// the option is not part of a group.
+
+// The fifth value is the internal name of an aliased option, or 0 if
+// the option is not an alias.
+
+// The sixth value is a string containing option flags. Valid values:
+// l: The option is a linker input.
+//
+// i: The option should not render the name when rendered as an
+// input.
+//
+// S: The option should be rendered separately, even if joined (only
+// sensible on joined options).
+//
+// J: The option should be rendered joined, even if separate (only
+// sensible on single value separate options).
+//
+// U: The option is unsupported, and the driver will reject command
+// lines that use it.
+
+/// The seventh value is an arbitrary integer parameter; currently
+/// this is only used for specifying the number of arguments for
+/// Separate options.
+
+OPTION(ArchOpt, Separate, "-arch", 0, 0, "", 0)
+OPTION(PassExitCodesFlag, Flag, "-pass-exit-codes", 0, 0, "", 0)
+OPTION(PrintFileNameOpt, Joined, "-print-file-name=", 0, 0, "", 0)
diff --git a/include/clang/Driver/Options.h b/include/clang/Driver/Options.h
new file mode 100644
index 0000000000..ad737635c4
--- /dev/null
+++ b/include/clang/Driver/Options.h
@@ -0,0 +1,55 @@
+//===--- Options.h - Option info & table ------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_DRIVER_OPTIONS_H_
+#define CLANG_DRIVER_OPTIONS_H_
+
+namespace clang {
+namespace driver {
+namespace options {
+ enum ID {
+ NotOption = 0, // This is not an option ID.
+#define OPTION(ID, KIND, NAME, GROUP, ALIAS, FLAGS, PARAM) ID,
+#include "clang/Driver/Options.def"
+ LastOption
+#undef OPTION
+ };
+}
+
+ class Option;
+
+ /// OptTable - Provide access to the Option info table.
+ ///
+ /// The OptTable class provides a layer of indirection which allows
+ /// Option instance to be created lazily. In the common case, only a
+ /// few options will be needed at runtime; the OptTable class
+ /// maintains enough information to parse command lines without
+ /// instantiating Options, while letting other parts of the driver
+ /// still use Option instances where convient.
+ class OptTable {
+ mutable Option **Options;
+
+ Option *constructOption(options::ID id) const;
+
+ public:
+ OptTable();
+ ~OptTable();
+
+ unsigned getNumOptions() const;
+
+ const char *getOptionName(options::ID id) const;
+
+ /// getOption - Get the given \arg id's Option instance, lazily
+ /// creating it if necessary.
+ const Option *getOption(options::ID id) const;
+ };
+}
+}
+
+#endif