Add support for UndefinedAtom in yaml and native format.  Add test cases with undefined atoms

llvm-svn: 149962
diff --git a/lld/lib/Core/YamlReader.cpp b/lld/lib/Core/YamlReader.cpp
index 39c0643..37c6382 100644
--- a/lld/lib/Core/YamlReader.cpp
+++ b/lld/lib/Core/YamlReader.cpp
@@ -267,6 +267,10 @@
        it != _definedAtoms.end(); ++it) {
     handler.doDefinedAtom(**it);
   }
+  for (std::vector<UndefinedAtom *>::const_iterator it = _undefinedAtoms.begin();
+       it != _undefinedAtoms.end(); ++it) {
+    handler.doUndefinedAtom(**it);
+  }
   return true;
 }
 
@@ -424,6 +428,32 @@
 };
 
 
+class YAMLUndefinedAtom : public UndefinedAtom {
+public:
+        YAMLUndefinedAtom(YAMLFile& f, int32_t ord, const char* nm, bool wi)
+            : _file(f), _name(nm), _ordinal(ord), _weakImport(wi) { }
+
+  virtual const class File& file() const {
+    return _file;
+  }
+
+  virtual llvm::StringRef name() const {
+    return _name;
+  }
+
+  virtual bool weakImport() const {
+    return _weakImport;
+  }
+  
+private:
+  YAMLFile&                   _file;
+  const char *                _name;
+  uint32_t                    _ordinal;
+  bool                        _weakImport;
+};
+
+
+
 class YAMLAtomState {
 public:
   YAMLAtomState();
@@ -455,6 +485,7 @@
   bool                        _internalName;
   bool                        _isThumb;
   bool                        _isAlias;
+  bool                        _weakImport;
   Reference                   _ref;
 };
 
@@ -477,6 +508,7 @@
   , _internalName(KeyValues::internalNameDefault)
   , _isThumb(KeyValues::isThumbDefault)
   , _isAlias(KeyValues::isAliasDefault) 
+  , _weakImport(false)
   {
   _ref.target       = NULL;
   _ref.addend       = 0;
@@ -496,6 +528,12 @@
     f._definedAtoms.push_back(a);
     ++_ordinal;
   }
+  else if ( _definition == Atom::definitionUndefined ) {
+    UndefinedAtom *a = new YAMLUndefinedAtom(f, _ordinal, _name, _weakImport);
+
+    f._undefinedAtoms.push_back(a);
+    ++_ordinal;
+  }
   
   // reset state for next atom
   _name             = NULL;
@@ -515,6 +553,7 @@
   _permissions      = KeyValues::permissionsDefault;
   _isThumb          = KeyValues::isThumbDefault;
   _isAlias          = KeyValues::isAliasDefault;
+  _weakImport       = KeyValues::weakImportDefault;
   _ref.target       = NULL;
   _ref.addend       = 0;
   _ref.offsetInAtom = 0;
@@ -664,6 +703,10 @@
           atomState._isAlias = KeyValues::isAlias(entry->value);
           haveAtom = true;
         }
+        else if (strcmp(entry->key, KeyValues::weakImportKeyword) == 0) {
+          atomState._weakImport = KeyValues::weakImport(entry->value);
+          haveAtom = true;
+        }
         else if (strcmp(entry->key, KeyValues::sectionNameKeyword) == 0) {
           atomState._sectionName = entry->value;
           haveAtom = true;