apicompatanamdw/compatanalysercmd/headeranalyser/src/NodeIndex.cpp
changeset 0 638b9c697799
equal deleted inserted replaced
-1:000000000000 0:638b9c697799
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CmdGlobals.h"
       
    20 #ifdef __WIN__
       
    21 #pragma warning(disable:4786)
       
    22 #endif
       
    23 
       
    24 #include <assert.h>
       
    25 #include <map>
       
    26 #include <list>
       
    27 #include <string>
       
    28 //#include <sstream>
       
    29 
       
    30 #include <xercesc/dom/DOM.hpp>
       
    31 
       
    32 #include "BBCAnalyser.h"
       
    33 #include "Issues.h"
       
    34 #include "ReportGenerator.h"
       
    35 #include "ReportIssue.h"
       
    36 #include "NodeIndex.h"
       
    37 #include "XMLStringConst.h"
       
    38 
       
    39 
       
    40 
       
    41 using namespace std;
       
    42 
       
    43 XERCES_CPP_NAMESPACE_USE
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // NodeIndex::AddNodeFQNameToMap
       
    47 // 
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 const pair<const XMLCh*,bool>& NodeIndex::FindFileByFileId(const XMLCh* fileid)
       
    51     {
       
    52     return iIdToFileMap[fileid];
       
    53     }
       
    54 
       
    55 // ----------------------------------------------------------------------------
       
    56 // NodeIndex::AddFileNodeToMap
       
    57 // 
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 void NodeIndex::AddFileNodeToMap(const XMLCh* id,pair<const XMLCh*,bool> file)
       
    61     {
       
    62         this->iIdToFileMap[id] = file;
       
    63     }
       
    64 
       
    65 // ----------------------------------------------------------------------------
       
    66 // NodeIndex::AddNodeFQNameToMap
       
    67 // 
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 void NodeIndex::AddNodeFQNameToMap(DOMNode * node, const pair<const XMLCh*,const XMLCh*>& fqname)
       
    71     {	
       
    72         this->iFQNameToNodeMap[fqname] = node;
       
    73     }
       
    74 
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // NodeIndex::clear
       
    78 // 
       
    79 // ----------------------------------------------------------------------------
       
    80 // 
       
    81 void NodeIndex::clear()
       
    82     {
       
    83         iIdToNodeMap.clear();
       
    84         iFQNameToNodeMap.clear();
       
    85     }
       
    86    
       
    87 // ----------------------------------------------------------------------------
       
    88 // NodeIndex::AddNodeIdToMap
       
    89 // Add the node with its id to the map
       
    90 // 
       
    91 // ----------------------------------------------------------------------------
       
    92 //  
       
    93 void NodeIndex::AddNodeIdToMap(DOMNode * node)
       
    94     {
       
    95         const XMLCh * attributeId = ::GetAttribute(node,KXMLIdString);
       
    96         
       
    97         if ( attributeId )
       
    98         {
       
    99             iIdToNodeMap[attributeId] = node;
       
   100         }
       
   101         
       
   102     }
       
   103 
       
   104  
       
   105 // ----------------------------------------------------------------------------
       
   106 // NodeIndex::FindNodeById
       
   107 // Finds the node with id
       
   108 // 
       
   109 // ----------------------------------------------------------------------------
       
   110 //   
       
   111 DOMNode * NodeIndex::FindNodeById(DOMNode * root, const XMLCh* id)
       
   112     {
       
   113         map<const XMLCh*, DOMNode*, ltstr>::iterator cur = iIdToNodeMap.find(id);
       
   114 
       
   115         if ( cur == iIdToNodeMap.end() )
       
   116         {
       
   117             //The node was not found so start traveling the tree
       
   118             DOMNode * node = FindNodeByIdFromTree(root,id);
       
   119             //We have found the node
       
   120             if ( node )
       
   121             {
       
   122                 AddNodeIdToMap(node);
       
   123             }
       
   124             return node;
       
   125         } else
       
   126         {
       
   127             return cur->second;
       
   128         }
       
   129     }
       
   130     
       
   131  
       
   132 // ----------------------------------------------------------------------------
       
   133 // NodeIndex::FindNodeByFQName
       
   134 // Finds the node with fully qualified name
       
   135 // 
       
   136 // ----------------------------------------------------------------------------
       
   137 // 
       
   138 DOMNode * NodeIndex::FindNodeByFQName(DOMNode * root, pair<const XMLCh*,const XMLCh* > FQName)
       
   139     {
       
   140         fqnamemap::iterator cur = iFQNameToNodeMap.find(FQName);
       
   141 
       
   142         if ( cur == iFQNameToNodeMap.end() )
       
   143         {
       
   144             //The node was not found so return NULL
       
   145             return NULL;
       
   146         } else
       
   147         {
       
   148             return cur->second;
       
   149         }
       
   150     }
       
   151  
       
   152 // ----------------------------------------------------------------------------
       
   153 // NodeIndex::FindNodeByIdFromTree
       
   154 // Search from the tree
       
   155 // 
       
   156 // ----------------------------------------------------------------------------
       
   157 //
       
   158 DOMNode * NodeIndex::FindNodeByIdFromTree(DOMNode * root, const XMLCh* id)
       
   159     {
       
   160         DOMNodeList * childs = root->getChildNodes();
       
   161         
       
   162         XMLSize_t childcount = childs->getLength();
       
   163         
       
   164         for (unsigned int i = 0; i < childcount; ++i)
       
   165         {
       
   166             DOMNode* child = childs->item(i);
       
   167             
       
   168             const XMLCh* attributeValue = GetAttribute(child,KXMLIdString);
       
   169 
       
   170             if ( attributeValue )
       
   171             {
       
   172                 if ( XMLString::equals(id, attributeValue) )
       
   173                 {
       
   174                     //The node was found
       
   175                     return child;
       
   176                 }
       
   177             }
       
   178             
       
   179         }
       
   180         // Not found
       
   181         return NULL;
       
   182     }
       
   183  
       
   184 // ----------------------------------------------------------------------------
       
   185 // NodeIndex::DumpTables
       
   186 // 
       
   187 // ----------------------------------------------------------------------------
       
   188 // 
       
   189 void NodeIndex::DumpTables()
       
   190 {
       
   191 /*
       
   192 	map< const XMLCh *,DOMNode*,ltstr >::iterator it = iIdToNodeMap.begin();
       
   193     DEBUG_PRINT("NodeIndex: ")
       
   194     DEBUG_PRINT(this)
       
   195     DEBUG_PRINT("\n")
       
   196     for (; it != iIdToNodeMap.end(); ++it)
       
   197     {
       
   198         DEBUG_PRINT_XMLCh((*it).first)
       
   199         DEBUG_PRINT(" ")
       
   200         DEBUG_PRINT((*it).second)
       
   201         DEBUG_PRINT("\n")
       
   202    }
       
   203     fqnamemap::iterator it2 = iFQNameToNodeMap.begin();
       
   204 #ifndef NO_DBG
       
   205     LOG(" ")
       
   206     DEBUG_PRINT("NodeIndex: ")
       
   207     DEBUG_PRINT(this)
       
   208     DEBUG_PRINT("\n")
       
   209 #endif
       
   210     for (; it2 != iFQNameToNodeMap.end(); ++it2)
       
   211     {
       
   212         DEBUG_PRINT_XMLCh((*it).first.first)
       
   213         DEBUG_PRINT(" ")
       
   214         DEBUG_PRINT_XMLCh((*it).first.second)
       
   215         DEBUG_PRINT("\n")
       
   216     }
       
   217 */
       
   218 }
       
   219 
       
   220  
       
   221 // ----------------------------------------------------------------------------
       
   222 // NodeIndex::AddVirtualFunction
       
   223 // Adds a virtual function to the table vtable
       
   224 // 
       
   225 // ----------------------------------------------------------------------------
       
   226 // 
       
   227 void NodeIndex::AddVirtualFunction(const string& vtablename, const string& functionsig, DOMNode * node)
       
   228 {
       
   229 	vtableindex_t::iterator it = iVTableIndex.find(vtablename);
       
   230 
       
   231 	if ( it != iVTableIndex.end() )
       
   232 	{
       
   233 		it->second.push_back(pair<string, DOMNode*>(functionsig,node));
       
   234 	}
       
   235 	else
       
   236 	{
       
   237 		vtable_t tmp_vtable;
       
   238 		tmp_vtable.push_back(pair<string, DOMNode*>(functionsig,node));		
       
   239 		iVTableIndex.insert(pair<string,vtable_t >(vtablename,tmp_vtable));
       
   240 	}
       
   241 }
       
   242  
       
   243 // ----------------------------------------------------------------------------
       
   244 // NodeIndex::GetVirtualTable
       
   245 // Gets the virtual table vtable
       
   246 // 
       
   247 // ----------------------------------------------------------------------------
       
   248 //
       
   249 const NodeIndex::vtable_t* NodeIndex::GetVirtualTable(const string& vtablename)
       
   250 {
       
   251 	vtableindex_t::iterator it = iVTableIndex.find(vtablename);
       
   252 
       
   253 	if ( it != iVTableIndex.end() )
       
   254 	{
       
   255 		return &(it->second);
       
   256 	}
       
   257 	return NULL;
       
   258 }
       
   259  
       
   260 // ----------------------------------------------------------------------------
       
   261 // NodeIndex::AddEmptyVirtualTable
       
   262 // Inserts empty vtable if one does not already exists. Returns a pointer
       
   263 // to the vtable.
       
   264 // 
       
   265 // ----------------------------------------------------------------------------
       
   266 // 
       
   267 const NodeIndex::vtable_t* NodeIndex::AddEmptyVirtualTable(const string& vtable)
       
   268 {
       
   269 	vtable_t tmp_vtable;
       
   270 	pair<vtableindex_t::iterator,bool> ret = iVTableIndex.insert(pair<string,vtable_t >(vtable,tmp_vtable));
       
   271 
       
   272 	return &(ret.first->second);
       
   273 }
       
   274 // ----------------------------------------------------------------------------
       
   275 // NodeIndex::InsertDataMember
       
   276 // Adds a data member to the given table
       
   277 // 
       
   278 // ----------------------------------------------------------------------------
       
   279 //
       
   280  void NodeIndex::InsertDataMember(const string& parentName, const DataMember& member, dtableindex_t& dataMap)
       
   281 {
       
   282     dtableindex_t::iterator it = dataMap.find(parentName);
       
   283     if( it != dataMap.end() )
       
   284     {
       
   285         it->second.push_back(member);
       
   286     }
       
   287     else
       
   288     {
       
   289         it = dataMap.insert(make_pair(parentName, dtable_t())).first;
       
   290         it->second.push_back(member);
       
   291     }
       
   292 }
       
   293 // ----------------------------------------------------------------------------
       
   294 // NodeIndex::AddDataMember
       
   295 // Adds a data member to the member data table.
       
   296 // 
       
   297 // ----------------------------------------------------------------------------
       
   298 // 
       
   299 void NodeIndex::AddDataMember(const HANodeIterator& parentNode, const string& parentName, const string& memberName, DOMNode* memberNode, int index, TAccess access,int lineNo)
       
   300 {
       
   301 	if( IsAnonymousType(parentNode) )
       
   302 	{
       
   303         InsertDataMember(parentName, DataMember(memberName, memberNode, index, access,lineNo), iAnonymousTable);
       
   304     }
       
   305     else
       
   306     {
       
   307         InsertDataMember(parentName, DataMember(memberName, memberNode, index, access,lineNo), iDTableIndex);
       
   308     }
       
   309 }
       
   310  
       
   311 // ----------------------------------------------------------------------------
       
   312 // NodeIndex::GetDataMemberTable
       
   313 // Gets the data member table
       
   314 // 
       
   315 // ----------------------------------------------------------------------------
       
   316 // 
       
   317 const NodeIndex::dtable_t* NodeIndex::GetDataMemberTable(const HANodeIterator& node, const string& nodeName)
       
   318 {	
       
   319 	dtableindex_t::iterator it;
       
   320 	if( IsAnonymousType(node) )
       
   321 	{
       
   322 		it = iAnonymousTable.find(nodeName);
       
   323 		if( it != iAnonymousTable.end() )
       
   324 		{
       
   325 			return &(it->second);
       
   326 		}
       
   327 	}
       
   328 	else
       
   329 	{
       
   330 		it = iDTableIndex.find(nodeName);
       
   331 		if( it != iDTableIndex.end() )
       
   332 		{
       
   333 		return &(it->second);
       
   334 		}
       
   335     }
       
   336     return NULL;
       
   337 }
       
   338  
       
   339 // ----------------------------------------------------------------------------
       
   340 // NodeIndex::AddEmptyDataMemberTable
       
   341 // Add empty data table
       
   342 // 
       
   343 // ----------------------------------------------------------------------------
       
   344 // 
       
   345 const NodeIndex::dtable_t* NodeIndex::AddEmptyDataMemberTable(const HANodeIterator& node, const string& nodeName)
       
   346 {
       
   347 	if( IsAnonymousType(node) )
       
   348 	{
       
   349 		return &(iAnonymousTable.insert(make_pair(nodeName, dtable_t()))).first->second;
       
   350 	}
       
   351 	
       
   352     return &(iDTableIndex.insert(make_pair(nodeName, dtable_t()))).first->second;
       
   353 }
       
   354 
       
   355 // ----------------------------------------------------------------------------
       
   356 // ltstr::operator
       
   357 // Finds the node with id id. Returns NULL if not found
       
   358 // 
       
   359 // ----------------------------------------------------------------------------
       
   360 // 
       
   361 bool ltstr::operator()(const XMLCh * s1,const XMLCh * s2) const
       
   362   {
       
   363     return XMLString::compareString(s1, s2) < 0;
       
   364   }
       
   365 
       
   366  
       
   367 // ----------------------------------------------------------------------------
       
   368 // compareFQName::operator
       
   369 // Finds the node with id id. Returns NULL if not found
       
   370 // 
       
   371 // ----------------------------------------------------------------------------
       
   372 //
       
   373 bool compareFQName::operator()(
       
   374     const pair<const XMLCh *,const XMLCh *>&  p1,
       
   375     const pair<const XMLCh *,const XMLCh *>&  p2) const
       
   376   {
       
   377     if ( 0 == XMLString::compareString(p1.first,p2.first) )
       
   378     {
       
   379         return XMLString::compareString(p1.second,p2.second) < 0;
       
   380     }
       
   381     else
       
   382     {
       
   383         return XMLString::compareString(p1.first,p2.first) < 0;
       
   384     }
       
   385   }