2009-03-04 16:33:23 +08:00
|
|
|
//===--- Options.cpp - Option info table --------------------------------*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Driver/Options.h"
|
|
|
|
|
|
|
|
#include "clang/Driver/Option.h"
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::driver;
|
|
|
|
using namespace clang::driver::options;
|
|
|
|
|
|
|
|
struct Info {
|
|
|
|
Option::OptionClass Kind;
|
|
|
|
const char *Name;
|
|
|
|
unsigned GroupID;
|
|
|
|
unsigned AliasID;
|
|
|
|
const char *Flags;
|
|
|
|
unsigned Param;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Info OptionInfos[] = {
|
2009-03-05 05:53:04 +08:00
|
|
|
// The InputOption info
|
|
|
|
{ Option::InputClass, "<input>", 0, 0, "", 0 },
|
|
|
|
// The UnknownOption info
|
|
|
|
{ Option::UnknownClass, "<unknown>", 0, 0, "", 0 },
|
|
|
|
|
2009-03-04 16:33:23 +08:00
|
|
|
#define OPTION(ID, KIND, NAME, GROUP, ALIAS, FLAGS, PARAM) \
|
|
|
|
{ Option::KIND##Class, NAME, GROUP, ALIAS, FLAGS, PARAM },
|
|
|
|
#include "clang/Driver/Options.def"
|
|
|
|
};
|
|
|
|
static const unsigned numOptions = sizeof(OptionInfos) / sizeof(OptionInfos[0]);
|
|
|
|
|
|
|
|
static Info &getInfo(unsigned id) {
|
|
|
|
assert(id > 0 && id - 1 < numOptions && "Invalid Option ID.");
|
|
|
|
return OptionInfos[id - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
OptTable::OptTable() : Options(new Option*[numOptions]) {
|
|
|
|
}
|
|
|
|
|
|
|
|
OptTable::~OptTable() {
|
|
|
|
for (unsigned i=0; i<numOptions; ++i)
|
|
|
|
delete Options[i];
|
|
|
|
delete[] Options;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned OptTable::getNumOptions() const {
|
|
|
|
return numOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *OptTable::getOptionName(options::ID id) const {
|
|
|
|
return getInfo(id).Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Option *OptTable::getOption(options::ID id) const {
|
2009-03-05 05:53:04 +08:00
|
|
|
if (id == NotOption)
|
2009-03-04 16:33:23 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
assert((unsigned) (id - 1) < numOptions && "Invalid ID.");
|
|
|
|
|
|
|
|
Option *&Entry = Options[id - 1];
|
|
|
|
if (!Entry)
|
|
|
|
Entry = constructOption(id);
|
|
|
|
|
|
|
|
return Entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
Option *OptTable::constructOption(options::ID id) const {
|
|
|
|
Info &info = getInfo(id);
|
|
|
|
const OptionGroup *Group =
|
|
|
|
cast_or_null<OptionGroup>(getOption((options::ID) info.GroupID));
|
|
|
|
const Option *Alias = getOption((options::ID) info.AliasID);
|
|
|
|
|
|
|
|
Option *Opt = 0;
|
|
|
|
switch (info.Kind) {
|
2009-03-05 05:53:04 +08:00
|
|
|
case Option::InputClass:
|
|
|
|
Opt = new InputOption(); break;
|
|
|
|
case Option::UnknownClass:
|
|
|
|
Opt = new UnknownOption(); break;
|
2009-03-04 16:33:23 +08:00
|
|
|
case Option::GroupClass:
|
2009-03-05 05:53:04 +08:00
|
|
|
Opt = new OptionGroup(id, info.Name, Group); break;
|
2009-03-04 16:33:23 +08:00
|
|
|
case Option::FlagClass:
|
2009-03-05 05:53:04 +08:00
|
|
|
Opt = new FlagOption(id, info.Name, Group, Alias); break;
|
2009-03-04 16:33:23 +08:00
|
|
|
case Option::JoinedClass:
|
2009-03-05 05:53:04 +08:00
|
|
|
Opt = new JoinedOption(id, info.Name, Group, Alias); break;
|
2009-03-04 16:33:23 +08:00
|
|
|
case Option::SeparateClass:
|
2009-03-05 05:53:04 +08:00
|
|
|
Opt = new SeparateOption(id, info.Name, Group, Alias); break;
|
2009-03-04 16:33:23 +08:00
|
|
|
case Option::CommaJoinedClass:
|
2009-03-05 05:53:04 +08:00
|
|
|
Opt = new CommaJoinedOption(id, info.Name, Group, Alias); break;
|
2009-03-04 16:33:23 +08:00
|
|
|
case Option::MultiArgClass:
|
2009-03-05 05:53:04 +08:00
|
|
|
Opt = new MultiArgOption(id, info.Name, Group, Alias, info.Param); break;
|
2009-03-04 16:33:23 +08:00
|
|
|
case Option::JoinedOrSeparateClass:
|
2009-03-05 05:53:04 +08:00
|
|
|
Opt = new JoinedOrSeparateOption(id, info.Name, Group, Alias); break;
|
2009-03-04 16:33:23 +08:00
|
|
|
case Option::JoinedAndSeparateClass:
|
2009-03-05 05:53:04 +08:00
|
|
|
Opt = new JoinedAndSeparateOption(id, info.Name, Group, Alias); break;
|
2009-03-04 16:33:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const char *s = info.Flags; *s; ++s) {
|
|
|
|
switch (*s) {
|
2009-03-05 05:05:23 +08:00
|
|
|
default: assert(0 && "Invalid option flag.");
|
|
|
|
case 'l': Opt->setLinkerInput(true); break;
|
|
|
|
case 'i': Opt->setNoOptAsInput(true); break;
|
|
|
|
case 'J': Opt->setForceJoinedRender(true); break;
|
|
|
|
case 'S': Opt->setForceSeparateRender(true); break;
|
|
|
|
case 'U': Opt->setUnsupported(true); break;
|
2009-03-04 16:33:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Opt;
|
|
|
|
}
|