Testcase and fix for bug 24074

Summary:
In bug 24074, the type information is not shown
correctly. This commit includes the following -
-> Changes for displaying correct type based on
current lexical scope for the command "image
lookup -t"

-> The corresponding testcase.

-> This patch was reverted due to segfaults in
FreeBSD and Mac, I fixed the problems for both now.

Reviewers: emaste, granata.enrico, jingham, clayborg

Differential Revision: http://reviews.llvm.org/D13290

llvm-svn: 249673
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 8f6a4a1..63bbba9 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -36,6 +36,7 @@
 #include "lldb/Target/Target.h"
 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
 #include "Plugins/Language/ObjC/ObjCLanguage.h"
+#include "lldb/Symbol/TypeMap.h"
 
 #include "Plugins/ObjectFile/JIT/ObjectFileJIT.h"
 
@@ -940,7 +941,7 @@
                         const CompilerDeclContext *parent_decl_ctx,
                         bool append,
                         size_t max_matches,
-                        TypeList& types)
+                        TypeMap& types)
 {
     Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
     if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)
@@ -960,7 +961,11 @@
                               TypeList& type_list)
 {
     const bool append = true;
-    return FindTypes_Impl(sc, type_name, parent_decl_ctx, append, max_matches, type_list);
+    TypeMap types_map;
+    size_t num_types = FindTypes_Impl(sc, type_name, parent_decl_ctx, append, max_matches, types_map);
+    if (num_types > 0)
+        sc.SortTypeList(types_map, type_list);
+    return num_types;
 }
 
 lldb::TypeSP
@@ -989,6 +994,7 @@
     std::string type_basename;
     const bool append = true;
     TypeClass type_class = eTypeClassAny;
+    TypeMap typesmap;
     if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class))
     {
         // Check if "name" starts with "::" which means the qualified type starts
@@ -1002,10 +1008,10 @@
             exact_match = true;
         }
         ConstString type_basename_const_str (type_basename.c_str());
-        if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types))
+        if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, typesmap))
         {
-            types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
-            num_matches = types.GetSize();
+            typesmap.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
+            num_matches = typesmap.GetSize();
         }
     }
     else
@@ -1015,18 +1021,18 @@
         {
             // The "type_name_cstr" will have been modified if we have a valid type class
             // prefix (like "struct", "class", "union", "typedef" etc).
-            FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types);
-            types.RemoveMismatchedTypes (type_class);
-            num_matches = types.GetSize();
+            FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, typesmap);
+            typesmap.RemoveMismatchedTypes (type_class);
+            num_matches = typesmap.GetSize();
         }
         else
         {
-            num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types);
+            num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, typesmap);
         }
     }
-    
+    if (num_matches > 0)
+        sc.SortTypeList(typesmap, types);
     return num_matches;
-    
 }
 
 SymbolVendor*