forked from OSchip/llvm-project
parent
766d48947a
commit
d53cf6c0c5
|
@ -0,0 +1,131 @@
|
|||
//===--- Arg.h - Parsed Argument Classes ------------------------*- 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_ARG_H_
|
||||
#define CLANG_DRIVER_ARG_H_
|
||||
|
||||
#include "Util.h"
|
||||
#include "llvm/ADT/ilist_node.h"
|
||||
|
||||
namespace clang {
|
||||
namespace driver {
|
||||
class ArgList;
|
||||
class Option;
|
||||
|
||||
/// Arg - A concrete instance of a particular driver option.
|
||||
///
|
||||
/// The Arg class encodes just enough information to be able to
|
||||
/// derive the argument values efficiently. In addition, Arg
|
||||
/// instances have an intrusive double linked list which is used by
|
||||
/// ArgList to provide efficient iteration over all instances of a
|
||||
/// particular option.
|
||||
class Arg : public llvm::ilist_node<Arg> {
|
||||
private:
|
||||
enum ArgClass {
|
||||
PositionalArg = 0,
|
||||
JoinedArg,
|
||||
SeparateArg,
|
||||
CommaJoinedArg,
|
||||
JoinedAndSeparateArg
|
||||
};
|
||||
|
||||
/// The option this argument is an instance of.
|
||||
const Option *Opt;
|
||||
|
||||
/// The index at which this argument appears in the containing
|
||||
/// ArgList.
|
||||
unsigned Index;
|
||||
|
||||
protected:
|
||||
Arg(ArgClass Kind, const Option *Opt, unsigned Index);
|
||||
|
||||
public:
|
||||
Arg(const Arg &);
|
||||
|
||||
/// render - Append the argument onto the given array as strings.
|
||||
virtual void render(const ArgList &Args, ArgStringList &Output) const = 0;
|
||||
|
||||
virtual unsigned getNumValues() const = 0;
|
||||
virtual const char *getValue(const ArgList &Args, unsigned N) const = 0;
|
||||
|
||||
const Option *getOption() const { return Opt; }
|
||||
|
||||
unsigned getIndex() const { return Index; }
|
||||
};
|
||||
|
||||
/// PositionalArg - A simple positional argument.
|
||||
class PositionalArg : public Arg {
|
||||
public:
|
||||
PositionalArg(const Option *Opt, unsigned Index);
|
||||
|
||||
virtual void render(const ArgList &Args, ArgStringList &Output) const = 0;
|
||||
|
||||
virtual unsigned getNumValues() const { return 1; }
|
||||
virtual const char *getValue(const ArgList &Args, unsigned N) const;
|
||||
};
|
||||
|
||||
/// JoinedArg - A single value argument where the value is joined
|
||||
/// (suffixed) to the option.
|
||||
class JoinedArg : public Arg {
|
||||
public:
|
||||
JoinedArg(const Option *Opt, unsigned Index);
|
||||
|
||||
virtual void render(const ArgList &Args, ArgStringList &Output) const = 0;
|
||||
|
||||
virtual unsigned getNumValues() const { return 1; }
|
||||
virtual const char *getValue(const ArgList &Args, unsigned N) const;
|
||||
};
|
||||
|
||||
/// SeparateArg - An argument where one or more values follow the
|
||||
/// option specifier immediately in the argument vector.
|
||||
class SeparateArg : public Arg {
|
||||
unsigned NumValues;
|
||||
|
||||
public:
|
||||
SeparateArg(const Option *Opt, unsigned Index, unsigned NumValues);
|
||||
|
||||
virtual void render(const ArgList &Args, ArgStringList &Output) const = 0;
|
||||
|
||||
virtual unsigned getNumValues() const { return NumValues; }
|
||||
virtual const char *getValue(const ArgList &Args, unsigned N) const;
|
||||
};
|
||||
|
||||
/// CommaJoinedArg - An argument with multiple values joined by
|
||||
/// commas and joined (suffixed) to the option specifier.
|
||||
///
|
||||
/// The key point of this arg is that it renders its values into
|
||||
/// separate arguments, which allows it to be used as a generic
|
||||
/// mechanism for passing arguments through to tools.
|
||||
class CommaJoinedArg : public Arg {
|
||||
unsigned NumValues;
|
||||
|
||||
public:
|
||||
CommaJoinedArg(const Option *Opt, unsigned Index, unsigned NumValues);
|
||||
|
||||
virtual void render(const ArgList &Args, ArgStringList &Output) const = 0;
|
||||
|
||||
virtual unsigned getNumValues() const { return NumValues; }
|
||||
virtual const char *getValue(const ArgList &Args, unsigned N) const;
|
||||
};
|
||||
|
||||
/// JoinedAndSeparateArg - An argument with both joined and separate
|
||||
/// values.
|
||||
class JoinedAndSeparateArg : public Arg {
|
||||
public:
|
||||
JoinedAndSeparateArg(const Option *Opt, unsigned Index);
|
||||
|
||||
virtual void render(const ArgList &Args, ArgStringList &Output) const = 0;
|
||||
|
||||
virtual unsigned getNumValues() const { return 2; }
|
||||
virtual const char *getValue(const ArgList &Args, unsigned N) const;
|
||||
};
|
||||
} // end namespace driver
|
||||
} // end namespace clang
|
||||
|
||||
#endif
|
|
@ -0,0 +1,67 @@
|
|||
//===--- ArgList.h - Argument List Management ----------*- 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_ARGLIST_H_
|
||||
#define CLANG_DRIVER_ARGLIST_H_
|
||||
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
|
||||
namespace clang {
|
||||
namespace driver {
|
||||
class Arg;
|
||||
|
||||
/// ArgList - Ordered collection of driver arguments.
|
||||
///
|
||||
/// The ArgList class manages a list of Arg instances as well as
|
||||
/// auxiliary data and convenience methods to allow Tools to quickly
|
||||
/// check for the presence of Arg instances for a particular Option
|
||||
/// and to iterate over groups of arguments.
|
||||
class ArgList {
|
||||
public:
|
||||
typedef llvm::SmallVector<Arg*, 16> arglist_type;
|
||||
typedef arglist_type::iterator iterator;
|
||||
typedef arglist_type::const_iterator const_iterator;
|
||||
|
||||
private:
|
||||
/// List of argument strings used by the contained Args.
|
||||
ArgStringList ArgStrings;
|
||||
|
||||
/// The full list of arguments.
|
||||
llvm::SmallVector<Arg*, 16> Args;
|
||||
|
||||
/// A map of arguments by option ID; in conjunction with the
|
||||
/// intrusive list in Arg instances this allows iterating over all
|
||||
/// arguments for a particular option.
|
||||
llvm::DenseMap<unsigned, Arg*> ArgMap;
|
||||
|
||||
public:
|
||||
ArgList(unsigned argc, const char **argv);
|
||||
ArgList(const ArgList &);
|
||||
~ArgList();
|
||||
|
||||
unsigned size() const { return Args.size(); }
|
||||
|
||||
iterator begin() { return Args.begin(); }
|
||||
iterator end() { return Args.end(); }
|
||||
|
||||
const_iterator begin() const { return Args.begin(); }
|
||||
const_iterator end() const { return Args.end(); }
|
||||
|
||||
Arg *getArgForID(unsigned ID) const {
|
||||
llvm::DenseMap<unsigned, Arg*>::iterator it = ArgMap.find(ID);
|
||||
if (it != ArgMap.end())
|
||||
return it->second;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
} // end namespace driver
|
||||
} // end namespace clang
|
||||
|
||||
#endif
|
|
@ -0,0 +1,23 @@
|
|||
//===--- Util.h - Common Driver Utilities -----------------------*- 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_UTIL_H_
|
||||
#define CLANG_DRIVER_UTIL_H_
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
|
||||
namespace clang {
|
||||
namespace driver {
|
||||
/// ArgStringList - Type used for constructing argv lists for subprocesses.
|
||||
typedef llvm::SmallVector<const char*, 16> ArgStringList;
|
||||
|
||||
} // end namespace driver
|
||||
} // end namespace clang
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue