+// A file or library, or a group, from the command line.
+
+class Input_argument
+{
+ public:
+ // Create a file or library argument.
+ explicit Input_argument(Input_file_argument file)
+ : is_file_(true), file_(file), group_(NULL)
+ { }
+
+ // Create a group argument.
+ explicit Input_argument(Input_file_group* group)
+ : is_file_(false), group_(group)
+ { }
+
+ // Return whether this is a file.
+ bool
+ is_file() const
+ { return this->is_file_; }
+
+ // Return whether this is a group.
+ bool
+ is_group() const
+ { return !this->is_file_; }
+
+ // Return the information about the file.
+ const Input_file_argument&
+ file() const
+ {
+ gold_assert(this->is_file_);
+ return this->file_;
+ }
+
+ // Return the information about the group.
+ const Input_file_group*
+ group() const
+ {
+ gold_assert(!this->is_file_);
+ return this->group_;
+ }
+
+ Input_file_group*
+ group()
+ {
+ gold_assert(!this->is_file_);
+ return this->group_;
+ }
+
+ private:
+ bool is_file_;
+ Input_file_argument file_;
+ Input_file_group* group_;
+};
+
+// A group from the command line. This is a set of arguments within
+// --start-group ... --end-group.
+
+class Input_file_group
+{
+ public:
+ typedef std::vector<Input_argument> Files;
+ typedef Files::const_iterator const_iterator;
+
+ Input_file_group()
+ : files_()
+ { }
+
+ // Add a file to the end of the group.
+ void
+ add_file(const Input_file_argument& arg)
+ { this->files_.push_back(Input_argument(arg)); }
+
+ // Iterators to iterate over the group contents.
+
+ const_iterator
+ begin() const
+ { return this->files_.begin(); }
+
+ const_iterator
+ end() const
+ { return this->files_.end(); }
+
+ private:
+ Files files_;
+};
+
+// A list of files from the command line or a script.
+
+class Input_arguments
+{
+ public:
+ typedef std::vector<Input_argument> Input_argument_list;
+ typedef Input_argument_list::const_iterator const_iterator;
+
+ Input_arguments()
+ : input_argument_list_(), in_group_(false)
+ { }
+
+ // Add a file.
+ void
+ add_file(const Input_file_argument& arg);
+
+ // Start a group (the --start-group option).
+ void
+ start_group();
+
+ // End a group (the --end-group option).
+ void
+ end_group();
+
+ // Return whether we are currently in a group.
+ bool
+ in_group() const
+ { return this->in_group_; }
+
+ // Iterators to iterate over the list of input files.
+
+ const_iterator
+ begin() const
+ { return this->input_argument_list_.begin(); }
+
+ const_iterator
+ end() const
+ { return this->input_argument_list_.end(); }
+
+ // Return whether the list is empty.
+ bool
+ empty() const
+ { return this->input_argument_list_.empty(); }
+
+ private:
+ Input_argument_list input_argument_list_;
+ bool in_group_;
+};
+