[PATCH] [lld] Make SimpleFileNode inherit from FileNode
Joey Gouly
joey.gouly at gmail.com
Thu Dec 19 14:15:16 PST 2013
There was a lot of duplicated code between these two classes, if we subclass FileNode we can remove a lot of code.
Nothing seemed to rely on actually checking if something was a SimpleFileNode, so I removed the casting for it. If something does need that, we can add it back in.
http://llvm-reviews.chandlerc.com/D2448
Files:
include/lld/Core/InputGraph.h
lib/Core/InputGraph.cpp
lib/Driver/Driver.cpp
Index: include/lld/Core/InputGraph.h
===================================================================
--- include/lld/Core/InputGraph.h
+++ include/lld/Core/InputGraph.h
@@ -129,7 +129,6 @@
/// Each input element in the graph can be a File or a control
enum class Kind : uint8_t {
Control, // Represents a type associated with ControlNodes
- SimpleFile, // Represents a type reserved for internal files
File // Represents a type associated with File Nodes
};
@@ -354,44 +353,17 @@
};
/// \brief Represents Internal Input files
-class SimpleFileNode : public InputElement {
+class SimpleFileNode : public FileNode {
public:
SimpleFileNode(StringRef path, int64_t ordinal = -1);
- virtual ErrorOr<StringRef> path(const LinkingContext &) const {
- return _path;
- }
-
- // The saved input path thats used when a file is not found while
- // trying to parse a file
- StringRef getUserPath() const { return _path; }
-
virtual ~SimpleFileNode() {}
- /// \brief Casting support
- static inline bool classof(const InputElement *a) {
- return a->kind() == InputElement::Kind::SimpleFile;
- }
-
- /// \brief Get the list of files
- range<InputGraph::FileIterT> files() {
- return make_range(_files.begin(), _files.end());
- }
-
- /// \brief number of files.
- size_t numFiles() const { return _files.size(); }
-
/// \brief add a file to the list of files
virtual void appendInputFile(std::unique_ptr<File> f) {
_files.push_back(std::move(f));
}
- /// \brief add a file to the list of files
- virtual void appendInputFiles(InputGraph::FileVectorT files) {
- for (auto &ai : files)
- _files.push_back(std::move(ai));
- }
-
/// \brief validates the Input Element
virtual bool validate() { return true; }
@@ -411,23 +383,8 @@
return *_files[_nextFileIndex++];
}
- /// \brief Set the resolver state.
- virtual void setResolveState(uint32_t resolveState) {
- _resolveState = resolveState;
- }
-
- /// \brief Retrieve the resolve state.
- virtual uint32_t getResolveState() const { return _resolveState; }
-
// Do nothing here.
virtual void resetNextIndex() {}
-
-protected:
- StringRef _path; // A string associated with this file.
- InputGraph::FileVectorT _files; // Vector of lld::File objects
- uint32_t _nextFileIndex; // The next file that would be processed by the
- // resolver
- uint32_t _resolveState; // The resolve state associated with this Node
};
} // namespace lld
Index: lib/Core/InputGraph.cpp
===================================================================
--- lib/Core/InputGraph.cpp
+++ lib/Core/InputGraph.cpp
@@ -177,8 +177,7 @@
/// SimpleFileNode
SimpleFileNode::SimpleFileNode(StringRef path, int64_t ordinal)
- : InputElement(InputElement::Kind::SimpleFile, ordinal), _path(path),
- _nextFileIndex(0), _resolveState(Resolver::StateNoChange) {}
+ : FileNode(path, ordinal) {}
/// Group
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -90,13 +90,13 @@
context.createInternalFiles(internalFiles);
if (internalFiles.size())
- fileNode->appendInputFiles(std::move(internalFiles));
+ fileNode->addFiles(std::move(internalFiles));
// Give target a chance to add files.
InputGraph::FileVectorT implicitFiles;
context.createImplicitFiles(implicitFiles);
if (implicitFiles.size())
- fileNode->appendInputFiles(std::move(implicitFiles));
+ fileNode->addFiles(std::move(implicitFiles));
context.inputGraph().insertOneElementAt(std::move(fileNode),
InputGraph::Position::BEGIN);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2448.1.patch
Type: text/x-patch
Size: 3770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131219/e27b92fa/attachment.bin>
More information about the llvm-commits
mailing list