[cfe-commits] r67086 - in /cfe/trunk: include/clang/Driver/ArgList.h lib/Driver/ArgList.cpp
Daniel Dunbar
daniel at zuster.org
Tue Mar 17 10:51:20 PDT 2009
Author: ddunbar
Date: Tue Mar 17 12:51:18 2009
New Revision: 67086
URL: http://llvm.org/viewvc/llvm-project?rev=67086&view=rev
Log:
Add ArgList::MakeArgString and make ArgList::Make* const.
- Slightly strange, but the idea is that the ArgList data structure
is primarily a list of arguments; we want to allow clients to still
add argument strings to an ArgList to avoid worrying about string
lifetimes (or unnecessary string copying).
Modified:
cfe/trunk/include/clang/Driver/ArgList.h
cfe/trunk/lib/Driver/ArgList.cpp
Modified: cfe/trunk/include/clang/Driver/ArgList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ArgList.h?rev=67086&r1=67085&r2=67086&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ArgList.h (original)
+++ cfe/trunk/include/clang/Driver/ArgList.h Tue Mar 17 12:51:18 2009
@@ -35,14 +35,22 @@
private:
/// List of argument strings used by the contained Args.
- ArgStringList ArgStrings;
+ ///
+ /// This is mutable since we treat the ArgList as being the list
+ /// of Args, and allow routines to add new strings (to have a
+ /// convenient place to store the memory) via MakeIndex.
+ mutable ArgStringList ArgStrings;
+
+ /// Strings for synthesized arguments.
+ ///
+ /// This is mutable since we treat the ArgList as being the list
+ /// of Args, and allow routines to add new strings (to have a
+ /// convenient place to store the memory) via MakeIndex.
+ mutable std::list<std::string> SynthesizedStrings;
/// The full list of arguments.
arglist_type Args;
- /// Strings for synthesized arguments.
- std::list<std::string> SynthesizedStrings;
-
public:
ArgList(const char **ArgBegin, const char **ArgEnd);
ArgList(const ArgList &);
@@ -79,25 +87,29 @@
private:
/// MakeIndex - Get an index for the given string(s).
- unsigned MakeIndex(const char *String0);
- unsigned MakeIndex(const char *String0, const char *String1);
+ unsigned MakeIndex(const char *String0) const;
+ unsigned MakeIndex(const char *String0, const char *String1) const;
public:
+ /// MakeArgString - Construct a constant string pointer whose
+ /// lifetime will match that of the ArgList.
+ const char *MakeArgString(const char *Str) const;
+
/// MakeFlagArg - Construct a new FlagArg for the given option
/// \arg Id.
- Arg *MakeFlagArg(const Option *Opt);
+ Arg *MakeFlagArg(const Option *Opt) const;
/// MakePositionalArg - Construct a new Positional arg for the
/// given option \arg Id, with the provided \arg Value.
- Arg *MakePositionalArg(const Option *Opt, const char *Value);
+ Arg *MakePositionalArg(const Option *Opt, const char *Value) const;
/// MakeSeparateArg - Construct a new Positional arg for the
/// given option \arg Id, with the provided \arg Value.
- Arg *MakeSeparateArg(const Option *Opt, const char *Value);
+ Arg *MakeSeparateArg(const Option *Opt, const char *Value) const;
/// MakeJoinedArg - Construct a new Positional arg for the
/// given option \arg Id, with the provided \arg Value.
- Arg *MakeJoinedArg(const Option *Opt, const char *Value);
+ Arg *MakeJoinedArg(const Option *Opt, const char *Value) const;
/// @}
};
Modified: cfe/trunk/lib/Driver/ArgList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ArgList.cpp?rev=67086&r1=67085&r2=67086&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ArgList.cpp (original)
+++ cfe/trunk/lib/Driver/ArgList.cpp Tue Mar 17 12:51:18 2009
@@ -44,7 +44,7 @@
return 0;
}
-unsigned ArgList::MakeIndex(const char *String0) {
+unsigned ArgList::MakeIndex(const char *String0) const {
unsigned Index = ArgStrings.size();
// Tuck away so we have a reliable const char *.
@@ -54,7 +54,7 @@
return Index;
}
-unsigned ArgList::MakeIndex(const char *String0, const char *String1) {
+unsigned ArgList::MakeIndex(const char *String0, const char *String1) const {
unsigned Index0 = MakeIndex(String0);
unsigned Index1 = MakeIndex(String1);
assert(Index0 + 1 == Index1 && "Unexpected non-consecutive indices!");
@@ -62,19 +62,23 @@
return Index0;
}
-Arg *ArgList::MakeFlagArg(const Option *Opt) {
+const char *ArgList::MakeArgString(const char *Str) const {
+ return getArgString(MakeIndex(Str));
+}
+
+Arg *ArgList::MakeFlagArg(const Option *Opt) const {
return new FlagArg(Opt, MakeIndex(Opt->getName()));
}
-Arg *ArgList::MakePositionalArg(const Option *Opt, const char *Value) {
+Arg *ArgList::MakePositionalArg(const Option *Opt, const char *Value) const {
return new PositionalArg(Opt, MakeIndex(Value));
}
-Arg *ArgList::MakeSeparateArg(const Option *Opt, const char *Value) {
+Arg *ArgList::MakeSeparateArg(const Option *Opt, const char *Value) const {
return new SeparateArg(Opt, MakeIndex(Opt->getName(), Value), 1);
}
-Arg *ArgList::MakeJoinedArg(const Option *Opt, const char *Value) {
+Arg *ArgList::MakeJoinedArg(const Option *Opt, const char *Value) const {
std::string Joined(Opt->getName());
Joined += Value;
return new JoinedArg(Opt, MakeIndex(Joined.c_str()));
More information about the cfe-commits
mailing list