2009-03-04 20:10:42 +03:00
|
|
|
//===--- ArgList.cpp - Argument List Management -------------------------*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Driver/ArgList.h"
|
|
|
|
#include "clang/Driver/Arg.h"
|
2009-03-05 01:40:08 +03:00
|
|
|
#include "clang/Driver/Option.h"
|
2009-03-04 20:10:42 +03:00
|
|
|
|
|
|
|
using namespace clang::driver;
|
|
|
|
|
|
|
|
ArgList::ArgList(const char **ArgBegin, const char **ArgEnd) {
|
|
|
|
ArgStrings.append(ArgBegin, ArgEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArgList::~ArgList() {
|
|
|
|
for (iterator it = begin(), ie = end(); it != ie; ++ie)
|
|
|
|
delete *it;
|
|
|
|
}
|
2009-03-05 01:40:08 +03:00
|
|
|
|
|
|
|
void ArgList::append(Arg *A) {
|
|
|
|
if (A->getOption().isUnsupported()) {
|
|
|
|
assert(0 && "FIXME: unsupported unsupported.");
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.push_back(A);
|
|
|
|
}
|
2009-03-12 04:36:44 +03:00
|
|
|
|
2009-03-12 19:03:38 +03:00
|
|
|
Arg *ArgList::getLastArg(options::ID Id) const {
|
2009-03-12 04:36:44 +03:00
|
|
|
// FIXME: Make search efficient?
|
|
|
|
|
|
|
|
// FIXME: This needs to not require loading of the option.
|
2009-03-12 11:45:11 +03:00
|
|
|
for (const_iterator it = begin(), ie = end(); it != ie; ++it)
|
2009-03-12 04:36:44 +03:00
|
|
|
if ((*it)->getOption().matches(Id))
|
2009-03-12 19:03:38 +03:00
|
|
|
return *it;
|
2009-03-12 04:36:44 +03:00
|
|
|
|
2009-03-12 19:03:38 +03:00
|
|
|
return 0;
|
2009-03-12 04:36:44 +03:00
|
|
|
}
|
2009-03-12 21:20:18 +03:00
|
|
|
|
|
|
|
unsigned ArgList::MakeIndex(const char *String0) {
|
|
|
|
unsigned Index = ArgStrings.size();
|
|
|
|
|
|
|
|
// Tuck away so we have a reliable const char *.
|
|
|
|
SynthesizedStrings.push_back(String0);
|
|
|
|
ArgStrings.push_back(SynthesizedStrings.back().c_str());
|
|
|
|
|
|
|
|
return Index;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ArgList::MakeIndex(const char *String0, const char *String1) {
|
|
|
|
unsigned Index0 = MakeIndex(String0);
|
|
|
|
unsigned Index1 = MakeIndex(String1);
|
2009-03-13 20:25:24 +03:00
|
|
|
assert(Index0 + 1 == Index1 && "Unexpected non-consecutive indices!");
|
2009-03-12 21:20:18 +03:00
|
|
|
(void) Index1;
|
|
|
|
return Index0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Arg *ArgList::MakeFlagArg(const Option *Opt) {
|
|
|
|
return new FlagArg(Opt, MakeIndex(Opt->getName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Arg *ArgList::MakePositionalArg(const Option *Opt, const char *Value) {
|
|
|
|
return new PositionalArg(Opt, MakeIndex(Value));
|
|
|
|
}
|
|
|
|
|
|
|
|
Arg *ArgList::MakeSeparateArg(const Option *Opt, const char *Value) {
|
|
|
|
return new SeparateArg(Opt, MakeIndex(Opt->getName(), Value), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Arg *ArgList::MakeJoinedArg(const Option *Opt, const char *Value) {
|
|
|
|
std::string Joined(Opt->getName());
|
|
|
|
Joined += Value;
|
|
|
|
return new JoinedArg(Opt, MakeIndex(Joined.c_str()));
|
|
|
|
}
|