[lld] r226147 - Rename InputElement Node.

Rui Ueyama ruiu at google.com
Thu Jan 15 00:31:46 PST 2015


Author: ruiu
Date: Thu Jan 15 02:31:46 2015
New Revision: 226147

URL: http://llvm.org/viewvc/llvm-project?rev=226147&view=rev
Log:
Rename InputElement Node.

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.

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

Modified: lld/trunk/include/lld/Core/InputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=226147&r1=226146&r2=226147&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/InputGraph.h (original)
+++ lld/trunk/include/lld/Core/InputGraph.h Thu Jan 15 02:31:46 2015
@@ -30,48 +30,42 @@
 
 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(); }

Modified: lld/trunk/include/lld/Core/LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkingContext.h?rev=226147&r1=226146&r2=226147&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkingContext.h (original)
+++ lld/trunk/include/lld/Core/LinkingContext.h Thu Jan 15 02:31:46 2015
@@ -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.

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=226147&r1=226146&r2=226147&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Thu Jan 15 02:31:46 2015
@@ -232,7 +232,7 @@ void Resolver::addAtoms(const std::vecto
 // 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,
 }
 
 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;

Modified: lld/trunk/lib/Driver/CoreDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/CoreDriver.cpp?rev=226147&r1=226146&r2=226147&view=diff
==============================================================================
--- lld/trunk/lib/Driver/CoreDriver.cpp (original)
+++ lld/trunk/lib/Driver/CoreDriver.cpp Thu Jan 15 02:31:46 2015
@@ -153,7 +153,7 @@ bool CoreDriver::parse(int argc, const c
       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;

Modified: lld/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=226147&r1=226146&r2=226147&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Driver.cpp (original)
+++ lld/trunk/lib/Driver/Driver.cpp Thu Jan 15 02:31:46 2015
@@ -84,7 +84,7 @@ bool Driver::link(LinkingContext &contex
   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

Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=226147&r1=226146&r2=226147&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Thu Jan 15 02:31:46 2015
@@ -275,7 +275,7 @@ evaluateLinkerScript(ELFLinkingContext &
         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
         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;

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=226147&r1=226146&r2=226147&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Thu Jan 15 02:31:46 2015
@@ -801,7 +801,7 @@ parseArgs(int argc, const char **argv, P
 // 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, cons
         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.

Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=226147&r1=226146&r2=226147&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Thu Jan 15 02:31:46 2015
@@ -928,12 +928,12 @@ bool MachOLinkingContext::customAtomOrde
   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_
 // 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);

Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=226147&r1=226146&r2=226147&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Thu Jan 15 02:31:46 2015
@@ -90,7 +90,7 @@ std::unique_ptr<File> PECOFFLinkingConte
 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::addLibraryFil
 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.

Modified: lld/trunk/unittests/DriverTests/DriverTest.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/DriverTest.h?rev=226147&r1=226146&r2=226147&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/DriverTest.h (original)
+++ lld/trunk/unittests/DriverTests/DriverTest.h Thu Jan 15 02:31:46 2015
@@ -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");
   }
 





More information about the llvm-commits mailing list