InputElement was named that because it's an element of an InputGraph.
It's losing the origin because the InputGraph is now being removed.
InputElement's subclass is FileNode, that naming inconsistency needed
to be fixed.
llvm-svn: 226147
namespace lld {
-class InputElement;
+class Node;
class LinkingContext;
class InputGraph {
public:
- std::vector<std::unique_ptr<InputElement>> &members() {
+ std::vector<std::unique_ptr<Node>> &members() {
return _members;
}
protected:
- std::vector<std::unique_ptr<InputElement>> _members;
+ std::vector<std::unique_ptr<Node>> _members;
};
-/// \brief This describes each element in the InputGraph. The Kind
-/// determines what the current node contains.
-class InputElement {
+// A Node represents a FileNode or other type of Node. In the latter case,
+// the node contains meta information about the input file list.
+// Currently only GroupEnd node is defined as a meta node.
+class Node {
public:
- /// Each input element in the graph can be a File or a control
- enum class Kind : uint8_t {
- File, // Represents a type associated with File Nodes
- GroupEnd,
- };
-
- InputElement(Kind type) : _kind(type) {}
- virtual ~InputElement() {}
-
- /// Return the Element Type for an Input Element
+ enum class Kind { File, GroupEnd };
+ Node(Kind type) : _kind(type) {}
+ virtual ~Node() {}
virtual Kind kind() const { return _kind; }
-protected:
- Kind _kind; // The type of the Element
+private:
+ Kind _kind;
};
// This is a marker for --end-group. getSize() returns the number of
// files between the corresponding --start-group and this marker.
-class GroupEnd : public InputElement {
+class GroupEnd : public Node {
public:
- GroupEnd(int size) : InputElement(Kind::GroupEnd), _size(size) {}
+ GroupEnd(int size) : Node(Kind::GroupEnd), _size(size) {}
int getSize() const { return _size; }
- static inline bool classof(const InputElement *a) {
+ static inline bool classof(const Node *a) {
return a->kind() == Kind::GroupEnd;
}
};
// A container of File.
-class FileNode : public InputElement {
+class FileNode : public Node {
public:
explicit FileNode(std::unique_ptr<File> f)
- : InputElement(InputElement::Kind::File), _file(std::move(f)) {}
+ : Node(Node::Kind::File), _file(std::move(f)) {}
virtual ~FileNode() {}
- static inline bool classof(const InputElement *a) {
- return a->kind() == InputElement::Kind::File;
+ static inline bool classof(const Node *a) {
+ return a->kind() == Node::Kind::File;
}
File *getFile() { return _file.get(); }
class File;
class Writer;
class InputGraph;
-class InputElement;
+class Node;
class SharedLibraryFile;
/// \brief The LinkingContext class encapsulates "what and how" to link.
// Returns true if at least one of N previous files has created an
// undefined symbol.
bool Resolver::undefinesAdded(int begin, int end) {
- std::vector<std::unique_ptr<InputElement>> &inputs =
+ std::vector<std::unique_ptr<Node>> &inputs =
_context.getInputGraph().members();
for (int i = begin; i < end; ++i)
if (FileNode *node = dyn_cast<FileNode>(inputs[i].get()))
}
File *Resolver::getFile(int &index, int &groupLevel) {
- std::vector<std::unique_ptr<InputElement>> &inputs
+ std::vector<std::unique_ptr<Node>> &inputs
= _context.getInputGraph().members();
if ((size_t)index >= inputs.size())
return nullptr;
std::vector<std::unique_ptr<File>> files
= loadFile(ctx, inputArg->getValue(), false);
for (std::unique_ptr<File> &file : files) {
- inputGraph->members().push_back(std::unique_ptr<InputElement>(
+ inputGraph->members().push_back(std::unique_ptr<Node>(
new FileNode(std::move(file))));
}
break;
ScopedTask readTask(getDefaultDomain(), "Read Args");
TaskGroup tg;
std::mutex diagnosticsMutex;
- for (std::unique_ptr<InputElement> &ie : inputGraph.members()) {
+ for (std::unique_ptr<Node> &ie : inputGraph.members()) {
tg.spawn([&] {
// Writes to the same output stream is not guaranteed to be thread-safe.
// We buffer the diagnostics output to a separate string-backed output
if (ctx.logInputFiles())
diag << file->path() << "\n";
inputGraph->members().push_back(
- std::unique_ptr<InputElement>(new FileNode(std::move(file))));
+ std::unique_ptr<Node>(new FileNode(std::move(file))));
++numfiles;
}
}
if (ctx->logInputFiles())
diagnostics << file->path() << "\n";
inputGraph->members().push_back(
- std::unique_ptr<InputElement>(new FileNode(std::move(file))));
+ std::unique_ptr<Node>(new FileNode(std::move(file))));
}
numfiles += files.size();
break;
// graph.
static bool hasLibrary(const PECOFFLinkingContext &ctx, File *file) {
StringRef path = file->path();
- for (std::unique_ptr<InputElement> &p : ctx.getInputGraph().members())
+ for (std::unique_ptr<Node> &p : ctx.getInputGraph().members())
if (auto *f = dyn_cast<FileNode>(p.get()))
if (f->getFile()->path() == path)
return true;
return false;
ctx.getResolvableSymsFile()->add(file.get());
ctx.getInputGraph().members().push_back(
- std::unique_ptr<InputElement>(new FileNode(std::move(file))));
+ std::unique_ptr<Node>(new FileNode(std::move(file))));
}
// Add the library group to the input graph.
return true;
}
-static File *getFirstFile(const std::unique_ptr<InputElement> &elem) {
- FileNode *e = dyn_cast<FileNode>(const_cast<InputElement *>(elem.get()));
+static File *getFirstFile(const std::unique_ptr<Node> &elem) {
+ FileNode *e = dyn_cast<FileNode>(const_cast<Node *>(elem.get()));
return e ? e->getFile() : nullptr;
}
-static bool isLibrary(const std::unique_ptr<InputElement> &elem) {
+static bool isLibrary(const std::unique_ptr<Node> &elem) {
File *f = getFirstFile(elem);
return f && (isa<SharedLibraryFile>(f) || isa<ArchiveLibraryFile>(f));
}
// so that the Resolver will reiterate over the libraries as long as we find
// new undefines from libraries.
void MachOLinkingContext::maybeSortInputFiles() {
- std::vector<std::unique_ptr<InputElement>> &elements
+ std::vector<std::unique_ptr<Node>> &elements
= getInputGraph().members();
std::stable_sort(elements.begin(), elements.end(),
- [](const std::unique_ptr<InputElement> &a,
- const std::unique_ptr<InputElement> &b) {
+ [](const std::unique_ptr<Node> &a,
+ const std::unique_ptr<Node> &b) {
return !isLibrary(a) && isLibrary(b);
});
size_t numLibs = std::count_if(elements.begin(), elements.end(), isLibrary);
void PECOFFLinkingContext::addLibraryFile(std::unique_ptr<FileNode> file) {
GroupEnd *currentGroupEnd;
int pos = -1;
- std::vector<std::unique_ptr<InputElement>> &elements
+ std::vector<std::unique_ptr<Node>> &elements
= getInputGraph().members();
for (int i = 0, e = elements.size(); i < e; ++i) {
if ((currentGroupEnd = dyn_cast<GroupEnd>(elements[i].get()))) {
bool PECOFFLinkingContext::createImplicitFiles(
std::vector<std::unique_ptr<File>> &) {
pecoff::ResolvableSymbols* syms = getResolvableSymsFile();
- std::vector<std::unique_ptr<InputElement>> &members
+ std::vector<std::unique_ptr<Node>> &members
= getInputGraph().members();
// Create a file for the entry point function.
// Convenience method for getting i'th input files name.
std::string inputFile(int index) {
- InputElement &inputElement =
- *linkingContext()->getInputGraph().members()[index];
- if (inputElement.kind() == InputElement::Kind::File)
- return cast<FileNode>(&inputElement)->getFile()->path();
+ Node &node = *linkingContext()->getInputGraph().members()[index];
+ if (node.kind() == Node::Kind::File)
+ return cast<FileNode>(&node)->getFile()->path();
llvm_unreachable("not handling other types of input files");
}