[PATCH] Separate file parsing from File's constructors.

kledzik at apple.com kledzik at apple.com
Fri Dec 12 12:25:13 PST 2014


The method Reader::parseFile() no longer has an appropriate name (since it no longer parses).  It now just constructs a File object.


================
Comment at: include/lld/Core/File.h:157-171
@@ -155,1 +156,17 @@
 
+  /// \brief Subclasses should override this method to parse the
+  /// memory buffer passed to this file's constructor.
+  virtual std::error_code doParse() { return std::error_code(); }
+
+  /// \brief If a file is parsed using a different method than doParse(),
+  /// one must use this method to set the last error status, so that
+  /// doParse will not be called twice. Only YAML reader uses this
+  /// (because YAML reader does not read blobs but structured data).
+  void setLastError(std::error_code err) { _lastError = err; }
+
+  std::error_code parse() {
+    if (!_lastError.hasValue())
+      _lastError = doParse();
+    return _lastError.getValue();
+  }
+
----------------
It is not clear why we need "lastError".  You say it is for YAML, but the YAML reader could be changed to return some File object which you can later call parse() on.   With that gone, you don't need to parse() and doParse().  You can have just parse() which subclasses override to do the actual parsing.

http://reviews.llvm.org/D6633

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list