Rename InputElement Node.
authorRui Ueyama <ruiu@google.com>
Thu, 15 Jan 2015 08:31:46 +0000 (08:31 +0000)
committerRui Ueyama <ruiu@google.com>
Thu, 15 Jan 2015 08:31:46 +0000 (08:31 +0000)
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

lld/include/lld/Core/InputGraph.h
lld/include/lld/Core/LinkingContext.h
lld/lib/Core/Resolver.cpp
lld/lib/Driver/CoreDriver.cpp
lld/lib/Driver/Driver.cpp
lld/lib/Driver/GnuLdDriver.cpp
lld/lib/Driver/WinLinkDriver.cpp
lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
lld/unittests/DriverTests/DriverTest.h

index 32b1dfe..a2e9c2d 100644 (file)
 
 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;
   }
 
@@ -80,15 +74,15 @@ private:
 };
 
 // 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(); }
index fb1e9da..9528b17 100644 (file)
@@ -26,7 +26,7 @@ class PassManager;
 class File;
 class Writer;
 class InputGraph;
-class InputElement;
+class Node;
 class SharedLibraryFile;
 
 /// \brief The LinkingContext class encapsulates "what and how" to link.
index ce398ff..1af8233 100644 (file)
@@ -232,7 +232,7 @@ void Resolver::addAtoms(const std::vector<const DefinedAtom *> &newAtoms) {
 // 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()))
@@ -242,7 +242,7 @@ bool Resolver::undefinesAdded(int begin, int end) {
 }
 
 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;
index 4a16b02..1a49577 100644 (file)
@@ -153,7 +153,7 @@ bool CoreDriver::parse(int argc, const char *argv[], CoreLinkingContext &ctx,
       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;
index eac75bf..c9058cc 100644 (file)
@@ -84,7 +84,7 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) {
   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
index 2e7ef17..7c6982c 100644 (file)
@@ -275,7 +275,7 @@ evaluateLinkerScript(ELFLinkingContext &ctx, InputGraph *inputGraph,
         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;
       }
     }
@@ -616,7 +616,7 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
         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;
index 77f3a22..9aa447a 100644 (file)
@@ -801,7 +801,7 @@ parseArgs(int argc, const char **argv, PECOFFLinkingContext &ctx,
 // 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;
@@ -1417,7 +1417,7 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
         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.
index ca1e11a..7d6587f 100644 (file)
@@ -928,12 +928,12 @@ bool MachOLinkingContext::customAtomOrderer(const DefinedAtom *left,
   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));
 }
@@ -946,11 +946,11 @@ static bool isLibrary(const std::unique_ptr<InputElement> &elem) {
 // 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);
index de4ddca..76ab852 100644 (file)
@@ -90,7 +90,7 @@ std::unique_ptr<File> PECOFFLinkingContext::createUndefinedSymbolFile() const {
 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()))) {
@@ -107,7 +107,7 @@ void PECOFFLinkingContext::addLibraryFile(std::unique_ptr<FileNode> file) {
 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.
index 41c5bc5..c854e38 100644 (file)
@@ -32,10 +32,9 @@ protected:
 
   // 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");
   }