[haiku-commits] haiku: hrev48592 - in src/apps/debugger: debug_info source_language/c_family .

  • From: anevilyak@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 1 Jan 2015 23:51:27 +0100 (CET)

hrev48592 adds 3 changesets to branch 'master'
old head: 5b690a810c82462d8e945957f8b55d46b44c3d54
new head: 4d9388f38924cffde0db7bf3d8e02be5cd4505e6
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=4d9388f+%5E5b690a8

----------------------------------------------------------------------------

492a649: Debugger: Optimize type lookups.
  
  DwarfImageDebugInfo:
  - On initialization, we now walk the list of compilation units and
    build a hash table of all of their contained types. The table is then
    used by GetType() to quickly find the subset of DIEType objects that
    match the requested name, and then compare only those to the
    given constraints to find the best match.
  
  For a more complex image such as libbe or Debugger itself, this reduces
  the time for an uncached type lookup from around 50 msec to < 10 usec on
  my i7.

d21bcbb: Debugger: Extend TeamTypeInformation interface.
  
  TeamTypeInformation:
  - Add interface function to allow simply querying for whether a
    type is known to exist by a name + constraints, without actually
    requesting that it be instantiated, and implement in TeamDebugInfo.
  
  GlobalTypeLookup:
  - Add analogous type lookup function to the above, and implement in
    TeamDebugInfo.
  
  {Specific,Debugger,Dwarf}ImageDebugInfo:
  - Add function for type existence query, and implement in subclasses.

4d9388f: Debugger: Adjustments to syntax highlighter.
  
  SyntaxHighlighter/CLanguageFamilySyntaxHighlighter/SourceView:
  - TeamTypeInformation is now passed as a parameter when requesting parsing,
    so highlighters can make use of it to identify types. Adjust callers.
  
  CLanguageFamilySyntaxHighlightInfo:
  - Use TeamTypeInformation to check if identifiers map to types, and highlight
    accordingly if they do.

                                         [ Rene Gollent <rene@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

17 files changed, 355 insertions(+), 60 deletions(-)
.../debug_info/DebuggerImageDebugInfo.cpp        |  10 +-
.../debugger/debug_info/DebuggerImageDebugInfo.h |   6 +-
.../debugger/debug_info/DwarfImageDebugInfo.cpp  | 256 +++++++++++++++----
.../debugger/debug_info/DwarfImageDebugInfo.h    |  21 +-
src/apps/debugger/debug_info/GlobalTypeLookup.h  |   6 +
src/apps/debugger/debug_info/ImageDebugInfo.cpp  |  14 +
src/apps/debugger/debug_info/ImageDebugInfo.h    |   5 +
.../debugger/debug_info/SpecificImageDebugInfo.h |   6 +-
src/apps/debugger/debug_info/TeamDebugInfo.cpp   |  51 ++++
src/apps/debugger/debug_info/TeamDebugInfo.h     |   5 +
src/apps/debugger/model/TeamTypeInformation.h    |   6 +-
.../debugger/source_language/SyntaxHighlighter.h |   2 +
.../CLanguageFamilySyntaxHighlightInfo.cpp       |  11 +-
.../CLanguageFamilySyntaxHighlightInfo.h         |   6 +-
.../CLanguageFamilySyntaxHighlighter.cpp         |   4 +-
.../c_family/CLanguageFamilySyntaxHighlighter.h  |   1 +
.../gui/team_window/SourceView.cpp               |   5 +-

############################################################################

Commit:      492a649b19527cc0e5b835cbcdd717027c30f8e0
URL:         http://cgit.haiku-os.org/haiku/commit/?id=492a649
Author:      Rene Gollent <rene@xxxxxxxxxxx>
Date:        Thu Jan  1 22:32:52 2015 UTC

Debugger: Optimize type lookups.

DwarfImageDebugInfo:
- On initialization, we now walk the list of compilation units and
  build a hash table of all of their contained types. The table is then
  used by GetType() to quickly find the subset of DIEType objects that
  match the requested name, and then compare only those to the
  given constraints to find the best match.

For a more complex image such as libbe or Debugger itself, this reduces
the time for an uncached type lookup from around 50 msec to < 10 usec on
my i7.

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp 
b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp
index 5daff70..78faee2 100644
--- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp
+++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp
@@ -232,6 +232,97 @@ struct DwarfImageDebugInfo::EntryListWrapper {
 };
 
 
+// #pragma mark - DwarfImageDebugInfo::TypeNameKey
+
+
+struct DwarfImageDebugInfo::TypeNameKey {
+       BString                 typeName;
+
+       TypeNameKey(const BString& typeName)
+               :
+               typeName(typeName)
+       {
+       }
+
+       uint32 HashValue() const
+       {
+               return StringUtils::HashValue(typeName);
+       }
+
+       bool operator==(const TypeNameKey& other) const
+       {
+               return typeName == other.typeName;
+       }
+};
+
+
+// #pragma mark - DwarfImageDebugInfo::TypeNameEntry
+
+
+struct DwarfImageDebugInfo::TypeNameEntry : TypeNameKey {
+       TypeNameEntry* next;
+       TypeEntryList types;
+
+       TypeNameEntry(const BString& name)
+               :
+               TypeNameKey(name),
+               types(10, false)
+       {
+       }
+
+       ~TypeNameEntry()
+       {
+       }
+
+};
+
+
+// #pragma mark - DwarfImageDebugInfo::TypeNameEntryHashDefinition
+
+
+struct DwarfImageDebugInfo::TypeNameEntryHashDefinition {
+       typedef TypeNameKey             KeyType;
+       typedef TypeNameEntry   ValueType;
+
+       size_t HashKey(const TypeNameKey& key) const
+       {
+               return key.HashValue();
+       }
+
+       size_t Hash(const TypeNameEntry* value) const
+       {
+               return value->HashValue();
+       }
+
+       bool Compare(const TypeNameKey& key,
+               const TypeNameEntry* value) const
+       {
+               return key == *value;
+       }
+
+       TypeNameEntry*& GetLink(TypeNameEntry* value) const
+       {
+               return value->next;
+       }
+};
+
+
+// #pragma mark - DwarfImageDebugInfo::TypeEntryInfo
+
+
+struct DwarfImageDebugInfo::TypeEntryInfo {
+       DIEType* type;
+       CompilationUnit* unit;
+
+       TypeEntryInfo(DIEType* type, CompilationUnit* unit)
+               :
+               type(type),
+               unit(unit)
+       {
+       }
+};
+
+
 // #pragma mark - DwarfImageDebugInfo
 
 
@@ -247,6 +338,7 @@ DwarfImageDebugInfo::DwarfImageDebugInfo(const ImageInfo& 
imageInfo,
        fFileManager(fileManager),
        fTypeLookup(typeLookup),
        fTypeCache(typeCache),
+       fTypeNameTable(NULL),
        fFile(file),
        fTextSegment(NULL),
        fRelocationDelta(0),
@@ -266,6 +358,8 @@ DwarfImageDebugInfo::~DwarfImageDebugInfo()
        fDebuggerInterface->ReleaseReference();
        fFile->ReleaseReference();
        fTypeCache->ReleaseReference();
+
+       delete fTypeNameTable;
 }
 
 
@@ -294,7 +388,7 @@ DwarfImageDebugInfo::Init()
                fPLTSectionEnd = fPLTSectionStart + section->Size();
        }
 
-       return B_OK;
+       return _BuildTypeNameTable();
 }
 
 
@@ -426,64 +520,47 @@ DwarfImageDebugInfo::GetFunctions(const 
BObjectList<SymbolInfo>& symbols,
 
 
 status_t
-DwarfImageDebugInfo::GetType(GlobalTypeCache* cache,
-       const BString& name, const TypeLookupConstraints& constraints,
-       Type*& _type)
+DwarfImageDebugInfo::GetType(GlobalTypeCache* cache, const BString& name,
+       const TypeLookupConstraints& constraints, Type*& _type)
 {
-       // iterate through all compilation units
-       for (int32 i = 0; CompilationUnit* unit = fFile->CompilationUnitAt(i);
-               i++) {
-               DwarfTypeContext* typeContext = NULL;
-               BReference<DwarfTypeContext> typeContextReference;
-
-               // iterate through all types of the compilation unit
-               for (DebugInfoEntryList::ConstIterator it
-                               = unit->UnitEntry()->Types().GetIterator();
-                       DIEType* typeEntry = 
dynamic_cast<DIEType*>(it.Next());) {
-                       if (typeEntry->IsDeclaration())
-                               continue;
+       TypeNameEntry* entry = fTypeNameTable->Lookup(name);
+       if (entry == NULL)
+               return B_ENTRY_NOT_FOUND;
 
-                       if (constraints.HasTypeKind()) {
-                               if (dwarf_tag_to_type_kind(typeEntry->Tag())
-                                       != constraints.TypeKind())
+       for (int32 i = 0; TypeEntryInfo* info = entry->types.ItemAt(i); i++) {
+               DIEType* typeEntry = info->type;
+               if (constraints.HasTypeKind()) {
+                       if (dwarf_tag_to_type_kind(typeEntry->Tag())
+                               != constraints.TypeKind()) {
                                continue;
-
-                               if (!_EvaluateBaseTypeConstraints(typeEntry,
-                                       constraints))
-                                       continue;
                        }
 
-                       if (constraints.HasSubtypeKind()
-                               && dwarf_tag_to_subtype_kind(typeEntry->Tag())
-                                       != constraints.SubtypeKind())
+                       if (!_EvaluateBaseTypeConstraints(typeEntry, 
constraints))
                                continue;
+               }
 
-                       BString typeEntryName;
-                       DwarfUtils::GetFullyQualifiedDIEName(typeEntry, 
typeEntryName);
-                       if (typeEntryName != name)
-                               continue;
+               if (constraints.HasSubtypeKind()
+                       && dwarf_tag_to_subtype_kind(typeEntry->Tag())
+                               != constraints.SubtypeKind()) {
+                       continue;
+               }
 
-                       // The name matches and the entry is not just a 
declaration --
-                       // create the type. First create the type context 
lazily.
-                       if (typeContext == NULL) {
-                               typeContext = new(std::nothrow)
-                                       DwarfTypeContext(fArchitecture, 
fImageInfo.ImageID(), fFile,
-                                       unit, NULL, 0, 0, fRelocationDelta, 
NULL, NULL);
-                               if (typeContext == NULL)
-                                       return B_NO_MEMORY;
-                               typeContextReference.SetTo(typeContext, true);
-                       }
+               DwarfTypeContext* typeContext = new(std::nothrow)
+                       DwarfTypeContext(fArchitecture, fImageInfo.ImageID(), 
fFile,
+                               info->unit, NULL, 0, 0, fRelocationDelta, NULL, 
NULL);
+               if (typeContext == NULL)
+                       return B_NO_MEMORY;
+               BReference<DwarfTypeContext> typeContextReference(typeContext, 
true);
 
-                       // create the type
-                       DwarfType* type;
-                       DwarfTypeFactory typeFactory(typeContext, fTypeLookup, 
cache);
-                       status_t error = typeFactory.CreateType(typeEntry, 
type);
-                       if (error != B_OK)
-                               continue;
+               // create the type
+               DwarfType* type;
+               DwarfTypeFactory typeFactory(typeContext, fTypeLookup, cache);
+               status_t error = typeFactory.CreateType(typeEntry, type);
+               if (error != B_OK)
+                       continue;
 
-                       _type = type;
-                       return B_OK;
-               }
+               _type = type;
+               return B_OK;
        }
 
        return B_ENTRY_NOT_FOUND;
@@ -1162,7 +1239,7 @@ 
DwarfImageDebugInfo::_CreateReturnValues(ReturnValueInfoList* returnValueInfos,
 
 bool
 DwarfImageDebugInfo::_EvaluateBaseTypeConstraints(DIEType* type,
-       const TypeLookupConstraints& constraints)
+       const TypeLookupConstraints& constraints) const
 {
        if (constraints.HasBaseTypeName()) {
                BString baseEntryName;
@@ -1204,3 +1281,55 @@ 
DwarfImageDebugInfo::_EvaluateBaseTypeConstraints(DIEType* type,
 
        return true;
 }
+
+
+status_t
+DwarfImageDebugInfo::_BuildTypeNameTable()
+{
+       fTypeNameTable = new(std::nothrow) TypeNameTable;
+       if (fTypeNameTable == NULL)
+               return B_NO_MEMORY;
+
+       status_t error = fTypeNameTable->Init();
+       if (error != B_OK)
+               return error;
+
+       // iterate through all compilation units
+       for (int32 i = 0; CompilationUnit* unit = fFile->CompilationUnitAt(i);
+               i++) {
+
+               // iterate through all types of the compilation unit
+               for (DebugInfoEntryList::ConstIterator it
+                               = unit->UnitEntry()->Types().GetIterator();
+                       DIEType* typeEntry = 
dynamic_cast<DIEType*>(it.Next());) {
+                       if (typeEntry->IsDeclaration())
+                               continue;
+
+                       BString typeEntryName;
+                       DwarfUtils::GetFullyQualifiedDIEName(typeEntry, 
typeEntryName);
+
+                       TypeNameEntry* entry = 
fTypeNameTable->Lookup(typeEntryName);
+                       if (entry == NULL) {
+                               entry = new(std::nothrow) 
TypeNameEntry(typeEntryName);
+                               if (entry == NULL)
+                                       return B_NO_MEMORY;
+
+                               error = fTypeNameTable->Insert(entry);
+                               if (error != B_OK)
+                                       return error;
+                       }
+
+                       TypeEntryInfo* info = new(std::nothrow) 
TypeEntryInfo(typeEntry,
+                               unit);
+                       if (info == NULL)
+                               return B_NO_MEMORY;
+
+                       if (!entry->types.AddItem(info)) {
+                               delete info;
+                               return B_NO_MEMORY;
+                       }
+               }
+       }
+
+       return B_OK;
+}
diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h 
b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h
index 0a2daf2..41f1198 100644
--- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h
+++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2010-2013, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2010-2014, Rene Gollent, rene@xxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 #ifndef DWARF_IMAGE_DEBUG_INFO_H
@@ -90,6 +90,16 @@ private:
                        struct UnwindTargetInterface;
                        struct EntryListWrapper;
 
+                       struct TypeNameKey;
+                       struct TypeNameEntry;
+                       struct TypeNameEntryHashDefinition;
+
+                       typedef BOpenHashTable<TypeNameEntryHashDefinition>
+                               TypeNameTable;
+
+                       struct TypeEntryInfo;
+                       typedef BObjectList<TypeEntryInfo> TypeEntryList;
+
 private:
                        status_t                        
_AddSourceCodeInfo(CompilationUnit* unit,
                                                                        
FileSourceCode* sourceCode,
@@ -112,7 +122,10 @@ private:
                                                                        
DwarfStackFrameDebugInfo& factory);
 
                        bool                            
_EvaluateBaseTypeConstraints(DIEType* type,
-                                                                       const 
TypeLookupConstraints& constraints);
+                                                                       const 
TypeLookupConstraints& constraints)
+                                                                       const;
+
+                       status_t                        _BuildTypeNameTable();
 
 private:
                        BLocker                         fLock;
@@ -122,6 +135,7 @@ private:
                        FileManager*            fFileManager;
                        GlobalTypeLookup*       fTypeLookup;
                        GlobalTypeCache*        fTypeCache;
+                       TypeNameTable*          fTypeNameTable;
                        DwarfFile*                      fFile;
                        ElfSegment*                     fTextSegment;
                        target_addr_t           fRelocationDelta;

############################################################################

Commit:      d21bcbb0ac2ceae18cdc1e684b36e9280a35cdf1
URL:         http://cgit.haiku-os.org/haiku/commit/?id=d21bcbb
Author:      Rene Gollent <rene@xxxxxxxxxxx>
Date:        Thu Jan  1 22:33:32 2015 UTC

Debugger: Extend TeamTypeInformation interface.

TeamTypeInformation:
- Add interface function to allow simply querying for whether a
  type is known to exist by a name + constraints, without actually
  requesting that it be instantiated, and implement in TeamDebugInfo.

GlobalTypeLookup:
- Add analogous type lookup function to the above, and implement in
  TeamDebugInfo.

{Specific,Debugger,Dwarf}ImageDebugInfo:
- Add function for type existence query, and implement in subclasses.

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp 
b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp
index 4cd65c4..07a6fe7 100644
--- a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp
+++ b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2013, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2013-2014, Rene Gollent, rene@xxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 
@@ -60,6 +60,14 @@ DebuggerImageDebugInfo::GetType(GlobalTypeCache* cache,
 }
 
 
+bool
+DebuggerImageDebugInfo::HasType(const BString& name,
+       const TypeLookupConstraints& constraints) const
+{
+       return false;
+}
+
+
 AddressSectionType
 DebuggerImageDebugInfo::GetAddressSectionType(target_addr_t address)
 {
diff --git a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h 
b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h
index e491f50..fcc395d 100644
--- a/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h
+++ b/src/apps/debugger/debug_info/DebuggerImageDebugInfo.h
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2013, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2013-2014, Rene Gollent, rene@xxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 #ifndef DEBUGGER_IMAGE_DEBUG_INFO_H
@@ -33,6 +33,10 @@ public:
                                                                        const 
BString& name,
                                                                        const 
TypeLookupConstraints& constraints,
                                                                        Type*& 
_type);
+       virtual bool                            HasType(const BString& name,
+                                                                       const 
TypeLookupConstraints& constraints)
+                                                                       const;
+
        virtual AddressSectionType      GetAddressSectionType(target_addr_t 
address);
        virtual status_t                        CreateFrame(Image* image,
                                                                        
FunctionInstance* functionInstance,
diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp 
b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp
index 78faee2..29fb16f 100644
--- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp
+++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp
@@ -567,6 +567,39 @@ DwarfImageDebugInfo::GetType(GlobalTypeCache* cache, const 
BString& name,
 }
 
 
+bool
+DwarfImageDebugInfo::HasType(const BString& name,
+       const TypeLookupConstraints& constraints) const
+{
+       TypeNameEntry* entry = fTypeNameTable->Lookup(name);
+       if (entry == NULL)
+               return false;
+
+       for (int32 i = 0; TypeEntryInfo* info = entry->types.ItemAt(i); i++) {
+               DIEType* typeEntry = info->type;
+               if (constraints.HasTypeKind()) {
+                       if (dwarf_tag_to_type_kind(typeEntry->Tag())
+                               != constraints.TypeKind()) {
+                               continue;
+                       }
+
+                       if (!_EvaluateBaseTypeConstraints(typeEntry, 
constraints))
+                               continue;
+               }
+
+               if (constraints.HasSubtypeKind()
+                       && dwarf_tag_to_subtype_kind(typeEntry->Tag())
+                               != constraints.SubtypeKind()) {
+                       continue;
+               }
+
+               return true;
+       }
+
+       return false;
+}
+
+
 AddressSectionType
 DwarfImageDebugInfo::GetAddressSectionType(target_addr_t address)
 {
diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h 
b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h
index 41f1198..db48b9b 100644
--- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.h
+++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.h
@@ -58,6 +58,9 @@ public:
                                                                        const 
BString& name,
                                                                        const 
TypeLookupConstraints& constraints,
                                                                        Type*& 
_type);
+       virtual bool                            HasType(const BString& name,
+                                                                       const 
TypeLookupConstraints& constraints)
+                                                                       const;
 
        virtual AddressSectionType      GetAddressSectionType(target_addr_t 
address);
 
diff --git a/src/apps/debugger/debug_info/GlobalTypeLookup.h 
b/src/apps/debugger/debug_info/GlobalTypeLookup.h
index 6a28117..f727c41 100644
--- a/src/apps/debugger/debug_info/GlobalTypeLookup.h
+++ b/src/apps/debugger/debug_info/GlobalTypeLookup.h
@@ -1,5 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
+ * Copyright 2014, Rene Gollent, rene@xxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 #ifndef GLOBAL_TYPE_LOOKUP_H
@@ -69,6 +70,11 @@ public:
                                                                        const 
TypeLookupConstraints& constraints,
                                                                        Type*& 
_type) = 0;
                                                                        // 
returns a reference
+
+       virtual bool                            HasType(GlobalTypeCache* cache,
+                                                                       const 
BString& name,
+                                                                       const 
TypeLookupConstraints& constraints)
+                                                                       = 0;
 };
 
 
diff --git a/src/apps/debugger/debug_info/ImageDebugInfo.cpp 
b/src/apps/debugger/debug_info/ImageDebugInfo.cpp
index c503873..2c7c86c 100644
--- a/src/apps/debugger/debug_info/ImageDebugInfo.cpp
+++ b/src/apps/debugger/debug_info/ImageDebugInfo.cpp
@@ -105,6 +105,20 @@ ImageDebugInfo::GetType(GlobalTypeCache* cache, const 
BString& name,
 }
 
 
+bool
+ImageDebugInfo::HasType(const BString& name,
+       const TypeLookupConstraints& constraints) const
+{
+       for (int32 i = 0; SpecificImageDebugInfo* specificInfo
+                       = fSpecificInfos.ItemAt(i); i++) {
+               if (specificInfo->HasType(name, constraints))
+                       return true;
+       }
+
+       return false;
+}
+
+
 AddressSectionType
 ImageDebugInfo::GetAddressSectionType(target_addr_t address) const
 {
diff --git a/src/apps/debugger/debug_info/ImageDebugInfo.h 
b/src/apps/debugger/debug_info/ImageDebugInfo.h
index 00a5f9a..5017630 100644
--- a/src/apps/debugger/debug_info/ImageDebugInfo.h
+++ b/src/apps/debugger/debug_info/ImageDebugInfo.h
@@ -45,6 +45,11 @@ public:
                                                                        const 
TypeLookupConstraints& constraints,
                                                                        Type*& 
_type);
                                                                        // 
returns a reference
+
+                       bool                            HasType(const BString& 
name,
+                                                                       const 
TypeLookupConstraints& constraints)
+                                                                       const;
+
                        AddressSectionType      
GetAddressSectionType(target_addr_t address)
                                                                        const;
 
diff --git a/src/apps/debugger/debug_info/SpecificImageDebugInfo.h 
b/src/apps/debugger/debug_info/SpecificImageDebugInfo.h
index 40d9f83..00110d3 100644
--- a/src/apps/debugger/debug_info/SpecificImageDebugInfo.h
+++ b/src/apps/debugger/debug_info/SpecificImageDebugInfo.h
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2013, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2013-2014, Rene Gollent, rene@xxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 #ifndef SPECIFIC_IMAGE_DEBUG_INFO_H
@@ -52,6 +52,10 @@ public:
                                                                        const 
TypeLookupConstraints& constraints,
                                                                        Type*& 
_type) = 0;
                                                                        // 
returns a reference
+       virtual bool                            HasType(const BString& name,
+                                                                       const 
TypeLookupConstraints& constraints)
+                                                                       const = 
0;
+
        virtual AddressSectionType      GetAddressSectionType(target_addr_t 
address)
                                                                        = 0;
 
diff --git a/src/apps/debugger/debug_info/TeamDebugInfo.cpp 
b/src/apps/debugger/debug_info/TeamDebugInfo.cpp
index 1cdb193..6424786 100644
--- a/src/apps/debugger/debug_info/TeamDebugInfo.cpp
+++ b/src/apps/debugger/debug_info/TeamDebugInfo.cpp
@@ -380,12 +380,22 @@ TeamDebugInfo::LookupTypeByName(const BString& name,
        return GetType(fTypeCache, name, constraints, _type);
 }
 
+
+bool
+TeamDebugInfo::TypeExistsByName(const BString& name,
+       const TypeLookupConstraints& constraints)
+{
+       return HasType(fTypeCache, name, constraints);
+}
+
+
 status_t
 TeamDebugInfo::GetType(GlobalTypeCache* cache, const BString& name,
        const TypeLookupConstraints& constraints, Type*& _type)
 {
        // maybe the type is already cached
        AutoLocker<GlobalTypeCache> cacheLocker(cache);
+
        Type* type = cache->GetType(name, constraints);
        if (type != NULL) {
                type->AcquireReference();
@@ -425,6 +435,47 @@ TeamDebugInfo::GetType(GlobalTypeCache* cache, const 
BString& name,
 }
 
 
+bool
+TeamDebugInfo::HasType(GlobalTypeCache* cache, const BString& name,
+       const TypeLookupConstraints& constraints)
+{
+       // maybe the type is already cached
+       AutoLocker<GlobalTypeCache> cacheLocker(cache);
+
+       Type* type = cache->GetType(name, constraints);
+       if (type != NULL)
+               return true;
+
+       cacheLocker.Unlock();
+
+       // Clone the image list and get references to the images, so we can 
iterate
+       // through them without locking.
+       AutoLocker<BLocker> locker(fLock);
+
+       ImageList images;
+       for (int32 i = 0; ImageDebugInfo* imageDebugInfo = fImages.ItemAt(i); 
i++) {
+               if (images.AddItem(imageDebugInfo))
+                       imageDebugInfo->AcquireReference();
+       }
+
+       locker.Unlock();
+
+       bool found = false;
+       for (int32 i = 0; ImageDebugInfo* imageDebugInfo = images.ItemAt(i); 
i++) {
+               if (imageDebugInfo->HasType(name, constraints)) {
+                       found = true;
+                       break;
+               }
+       }
+
+       // release the references
+       for (int32 i = 0; ImageDebugInfo* imageDebugInfo = images.ItemAt(i); 
i++)
+               imageDebugInfo->ReleaseReference();
+
+       return found;
+}
+
+
 status_t
 TeamDebugInfo::LoadImageDebugInfo(const ImageInfo& imageInfo,
        LocatableFile* imageFile, ImageDebugInfoLoadingState& _state,
diff --git a/src/apps/debugger/debug_info/TeamDebugInfo.h 
b/src/apps/debugger/debug_info/TeamDebugInfo.h
index b3dff5e..e95202a 100644
--- a/src/apps/debugger/debug_info/TeamDebugInfo.h
+++ b/src/apps/debugger/debug_info/TeamDebugInfo.h
@@ -49,10 +49,15 @@ public:
                                                                        const 
BString& name,
                                                                        const 
TypeLookupConstraints& constraints,
                                                                        Type*& 
_type);
+       virtual bool                            HasType(GlobalTypeCache* cache,
+                                                                       const 
BString& name,
+                                                                       const 
TypeLookupConstraints& constraints);
 
        virtual status_t                        LookupTypeByName(const BString& 
name,
                                                                        const 
TypeLookupConstraints& constraints,
                                                                        Type*& 
_type);
+       virtual bool                            TypeExistsByName(const BString& 
name,
+                                                                       const 
TypeLookupConstraints& constraints);
 
                        status_t                        
LoadImageDebugInfo(const ImageInfo& imageInfo,
                                                                        
LocatableFile* imageFile,
diff --git a/src/apps/debugger/model/TeamTypeInformation.h 
b/src/apps/debugger/model/TeamTypeInformation.h
index 3f6b25e..6748056 100644
--- a/src/apps/debugger/model/TeamTypeInformation.h
+++ b/src/apps/debugger/model/TeamTypeInformation.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2011-2014, Rene Gollent, rene@xxxxxxxxxxx.
  * Distributed under the terms of the MIT License.
  */
 #ifndef TEAM_TYPE_INFORMATION_H
@@ -24,6 +24,10 @@ public:
                                                                        const 
TypeLookupConstraints& constraints,
                                                                        Type*& 
_type) = 0;
                                                                        // 
returns reference
+
+       virtual bool                            TypeExistsByName(const BString& 
name,
+                                                                       const 
TypeLookupConstraints& constraints)
+                                                                       = 0;
 };
 
 

############################################################################

Revision:    hrev48592
Commit:      4d9388f38924cffde0db7bf3d8e02be5cd4505e6
URL:         http://cgit.haiku-os.org/haiku/commit/?id=4d9388f
Author:      Rene Gollent <rene@xxxxxxxxxxx>
Date:        Thu Jan  1 22:19:08 2015 UTC

Debugger: Adjustments to syntax highlighter.

SyntaxHighlighter/CLanguageFamilySyntaxHighlighter/SourceView:
- TeamTypeInformation is now passed as a parameter when requesting parsing,
  so highlighters can make use of it to identify types. Adjust callers.

CLanguageFamilySyntaxHighlightInfo:
- Use TeamTypeInformation to check if identifiers map to types, and highlight
  accordingly if they do.

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/source_language/SyntaxHighlighter.h 
b/src/apps/debugger/source_language/SyntaxHighlighter.h
index 7a72a36..0fae05a 100644
--- a/src/apps/debugger/source_language/SyntaxHighlighter.h
+++ b/src/apps/debugger/source_language/SyntaxHighlighter.h
@@ -13,6 +13,7 @@
 
 
 class LineDataSource;
+class TeamTypeInformation;
 
 
 enum syntax_highlight_type {
@@ -48,6 +49,7 @@ public:
        virtual                                         ~SyntaxHighlighter();
 
        virtual status_t                        ParseText(LineDataSource* 
source,
+                                                                       
TeamTypeInformation* typeInfo,
                                                                        
SyntaxHighlightInfo*& _info) = 0;
                                                                                
// caller owns the returned info
 };
diff --git 
a/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlightInfo.cpp
 
b/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlightInfo.cpp
index 1537606..7ad0a51 100644
--- 
a/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlightInfo.cpp
+++ 
b/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlightInfo.cpp
@@ -10,6 +10,8 @@
 
 #include "CLanguageTokenizer.h"
 #include "LineDataSource.h"
+#include "TeamTypeInformation.h"
+#include "TypeLookupConstraints.h"
 
 
 using namespace CLanguage;
@@ -167,11 +169,13 @@ private:
 
 
 CLanguageFamilySyntaxHighlightInfo::CLanguageFamilySyntaxHighlightInfo(
-       LineDataSource* source, Tokenizer* tokenizer)
+       LineDataSource* source, Tokenizer* tokenizer,
+       TeamTypeInformation* typeInfo)
        :
        SyntaxHighlightInfo(),
        fHighlightSource(source),
        fTokenizer(tokenizer),
+       fTypeInfo(typeInfo),
        fLineInfos(10, true)
 {
        fHighlightSource->AcquireReference();
@@ -310,11 +314,14 @@ CLanguageFamilySyntaxHighlightInfo::_ParseLine(int32 line,
 syntax_highlight_type
 CLanguageFamilySyntaxHighlightInfo::_MapTokenToSyntaxType(const Token& token)
 {
+       static TypeLookupConstraints constraints;
+
        switch (token.type) {
                case TOKEN_IDENTIFIER:
-                       // TODO: recognize types
                        if (IsLanguageKeyword(token))
                                return SYNTAX_HIGHLIGHT_KEYWORD;
+                       else if (fTypeInfo->TypeExistsByName(token.string, 
constraints))
+                               return SYNTAX_HIGHLIGHT_TYPE;
                        break;
 
                case TOKEN_CONSTANT:
diff --git 
a/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlightInfo.h
 
b/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlightInfo.h
index 7827942..5bfe24b 100644
--- 
a/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlightInfo.h
+++ 
b/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlightInfo.h
@@ -16,12 +16,15 @@ namespace CLanguage {
        class Tokenizer;
 }
 
+class TeamTypeInformation;
+
 
 class CLanguageFamilySyntaxHighlightInfo : public SyntaxHighlightInfo {
 public:
                                                                
CLanguageFamilySyntaxHighlightInfo(
                                                                        
LineDataSource* source,
-                                                                       
CLanguage::Tokenizer* tokenizer);
+                                                                       
CLanguage::Tokenizer* tokenizer,
+                                                                       
TeamTypeInformation* info);
        virtual                                         
~CLanguageFamilySyntaxHighlightInfo();
 
        virtual int32                           GetLineHighlightRanges(int32 
line,
@@ -44,6 +47,7 @@ private:
 private:
        LineDataSource*                         fHighlightSource;
        CLanguage::Tokenizer*           fTokenizer;
+       TeamTypeInformation*            fTypeInfo;
        LineInfoList                            fLineInfos;
 };
 
diff --git 
a/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlighter.cpp
 
b/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlighter.cpp
index 097c329..6217514 100644
--- 
a/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlighter.cpp
+++ 
b/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlighter.cpp
@@ -31,7 +31,7 @@ 
CLanguageFamilySyntaxHighlighter::~CLanguageFamilySyntaxHighlighter()
 
 status_t
 CLanguageFamilySyntaxHighlighter::ParseText(LineDataSource* source,
-       SyntaxHighlightInfo*& _info)
+       TeamTypeInformation* typeInfo, SyntaxHighlightInfo*& _info)
 {
        Tokenizer* tokenizer = new(std::nothrow) Tokenizer();
        if (tokenizer == NULL)
@@ -39,7 +39,7 @@ CLanguageFamilySyntaxHighlighter::ParseText(LineDataSource* 
source,
        ObjectDeleter<Tokenizer> deleter(tokenizer);
 
        _info = new(std::nothrow) CLanguageFamilySyntaxHighlightInfo(source,
-               tokenizer);
+               tokenizer, typeInfo);
        if (_info == NULL)
                return B_NO_MEMORY;
 
diff --git 
a/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlighter.h 
b/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlighter.h
index 25a5736..5a347d2 100644
--- 
a/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlighter.h
+++ 
b/src/apps/debugger/source_language/c_family/CLanguageFamilySyntaxHighlighter.h
@@ -15,6 +15,7 @@ public:
        virtual                                         
~CLanguageFamilySyntaxHighlighter();
 
        virtual status_t                        ParseText(LineDataSource* 
source,
+                                                                       
TeamTypeInformation* typeInfo,
                                                                        
SyntaxHighlightInfo*& _info);
                                                                                
// caller owns the returned info
 };
diff --git a/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp 
b/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp
index 0beeaf7..fdb9328 100644
--- a/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp
+++ b/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp
@@ -76,7 +76,7 @@ static rgb_color kSyntaxColors[] = {
        {0, 0x64, 0, 255},                      // 
SYNTAX_HIGHLIGHT_PREPROCESSOR_KEYWORD
        {0, 0, 0, 255},                         // SYNTAX_HIGHLIGHT_IDENTIFIER
        {0x44, 0x8a, 0, 255},           // SYNTAX_HIGHLIGHT_OPERATOR
-       {0, 0, 0, 255},                         // SYNTAX_HIGHLIGHT_TYPE
+       {0x70, 0x70, 0x70, 255},        // SYNTAX_HIGHLIGHT_TYPE
        {0x85, 0x19, 0x19, 255},        // SYNTAX_HIGHLIGHT_NUMERIC_LITERAL
        {0x3f, 0x48, 0x84, 255},        // SYNTAX_HIGHLIGHT_STRING_LITERAL
        {0xa1, 0x64, 0xe, 255},         // SYNTAX_HIGHLIGHT_COMMENT
@@ -2254,7 +2254,8 @@ SourceView::SetSourceCode(SourceCode* sourceCode)
                        if (highlighter != NULL) {
                                BReference<SyntaxHighlighter> 
syntaxReference(highlighter,
                                        true);
-                               highlighter->ParseText(fSourceCode, 
fCurrentSyntaxInfo);
+                               highlighter->ParseText(fSourceCode,
+                                       fTeam->GetTeamTypeInformation(), 
fCurrentSyntaxInfo);
                        }
                }
        }


Other related posts:

  • » [haiku-commits] haiku: hrev48592 - in src/apps/debugger: debug_info source_language/c_family . - anevilyak