apicompatanamdw/compatanalysercmd/headeranalyser/src/HANodeIterator.cpp
changeset 0 638b9c697799
child 3 ebe3f8f03b59
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 
       
    21 #ifdef __WIN__
       
    22 #pragma warning(disable:4786)
       
    23 #endif
       
    24 
       
    25 #include <assert.h>
       
    26 #include <map>
       
    27 #include <list>
       
    28 #include <string>
       
    29 
       
    30 #include <xercesc/dom/DOM.hpp>
       
    31 
       
    32 #include "Issues.h"
       
    33 #include "ReportGenerator.h"
       
    34 #include "ReportIssue.h"
       
    35 #include "NodeIndex.h"
       
    36 #include "HANodeIterator.h"
       
    37 #include "XMLStringConst.h"
       
    38 #include "ClassNodeAnalysis.h"
       
    39 #include "Utils.h"
       
    40 using namespace std;
       
    41 
       
    42 XERCES_CPP_NAMESPACE_USE
       
    43 
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // HANodeIterator::HANodeIterator
       
    47 // Constructor
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 HANodeIterator::HANodeIterator(DOMNode * aRootnode, NodeIndex & aNodemap, ReportGenerator & aReport,
       
    51                                const list< pair<string,string> >& aFilesToAnalyse, bool aBaselineNode ):
       
    52             root(aRootnode),
       
    53             current(aRootnode),
       
    54             iNodeIndex(aNodemap),
       
    55             iReport(aReport),
       
    56             iFilesToAnalyse(aFilesToAnalyse),
       
    57             iBaselineNode(aBaselineNode)
       
    58     {
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // HANodeIterator::toBeAnalysed
       
    63 // 
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 bool HANodeIterator::toBeAnalysed()
       
    67     {
       
    68     const XMLCh* fileid = this->GetAttribute(KXMLFileIdString);
       
    69     const pair<const XMLCh*,bool>& file = iNodeIndex.FindFileByFileId(fileid);
       
    70     return file.second;
       
    71     }
       
    72 
       
    73 XMLCh* GClassString=NULL;
       
    74 
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // HANodeIterator::GetFullyQualifiedName
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 pair<const XMLCh *,const XMLCh *> HANodeIterator::GetFullyQualifiedName()
       
    81     {
       
    82     const XMLCh * fqname=NULL;
       
    83     const XMLCh * nodename=NULL;
       
    84 
       
    85     fqname = this->GetAttribute(KXMLBBCFQNameString);
       
    86     nodename = current->getNodeName();
       
    87     pair<const XMLCh *,const XMLCh *> ret;
       
    88     ret.first = fqname;
       
    89     ret.second = nodename;
       
    90 
       
    91     if (Equals(ret.second,KXMLStructString))
       
    92     {
       
    93 /*
       
    94 #ifdef __WIN__
       
    95         ret.second = KXMLClassString;
       
    96 #else
       
    97         if (!GClassString)
       
    98         {
       
    99             GClassString = XMLString::transcode(KXMLClassString);
       
   100         }
       
   101 
       
   102         ret.second = GClassString;
       
   103 #endif*/
       
   104      GET_FULLY_QUALIFIED_NAME;
       
   105     }
       
   106     return ret;
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // HANodeIterator::operator->
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 DOMNode* HANodeIterator::operator->() const
       
   114     {
       
   115         return (this->current); 
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // HANodeIterator::IndexFileNode
       
   120 // ----------------------------------------------------------------------------
       
   121 //
       
   122 void HANodeIterator::IndexFileNode(bool analysedfile)
       
   123     {
       
   124     //id="f0" name="../src/Headeranal.cpp"/
       
   125     const XMLCh * id = this->GetAttribute(KXMLIdString);
       
   126     const XMLCh * name = this->GetAttribute(KXMLNameString);
       
   127     pair<const XMLCh*,bool> file;
       
   128     file.first = name;
       
   129     file.second = analysedfile;
       
   130     iNodeIndex.AddFileNodeToMap(id,file);
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // HANodeIterator::IndexNode
       
   135 // ----------------------------------------------------------------------------
       
   136 //    
       
   137 void HANodeIterator::IndexNode()
       
   138     {
       
   139         iNodeIndex.AddNodeIdToMap(current);
       
   140     }
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // HANodeIterator::NameNode
       
   144 // Name node
       
   145 // ----------------------------------------------------------------------------
       
   146 //
       
   147 void HANodeIterator::NameNode(bool index)
       
   148     {
       
   149     
       
   150         const XMLCh* fqname = this->GetAttribute(KXMLBBCFQNameString);
       
   151         if ( !fqname )
       
   152         {
       
   153             string generatedname;
       
   154 
       
   155             const XMLCh* name = this->GetAttribute(KXMLNameString);
       
   156 
       
   157             if ( Equals(name,"") )
       
   158                 return;
       
   159 
       
   160             if ( Equals(current->getNodeName(),KXMLEnumValueString) )
       
   161             {
       
   162                 //We are naming the members of anonymous enumeration
       
   163                 // Generate the name for the parents context
       
   164 
       
   165                 HANodeIterator tempnode(*this);
       
   166                 tempnode.current = current->getParentNode();
       
   167 
       
   168                 const XMLCh * parentContext = tempnode.GetAttribute(KXMLContextString);
       
   169                 bool found = tempnode.FindNodeById(parentContext);
       
   170                 assert(found);
       
   171 
       
   172                 generatedname = GenerateFullyQualifiedName(tempnode);
       
   173                 generatedname += "::";
       
   174                 generatedname += toString(name);
       
   175             }else
       
   176             {
       
   177                 generatedname = GenerateFullyQualifiedName(*this);
       
   178             }
       
   179 
       
   180             //DEBUG_PRINT("Fullyqualified name: ");
       
   181             //DEBUG_PRINT(generatedname);
       
   182             //DEBUG_PRINT("\n");
       
   183 
       
   184             XMLCh* fqnamep = XMLString::transcode(generatedname.c_str());
       
   185             this->SetAttribute(KXMLBBCFQNameString, fqnamep);
       
   186             XMLString::release(&fqnamep);
       
   187         }
       
   188         if (index)
       
   189         {
       
   190             fqname = this->GetAttribute(KXMLBBCFQNameString);
       
   191             pair<const XMLCh*,const XMLCh*>  fqname = this->GetFullyQualifiedName();
       
   192             iNodeIndex.AddNodeFQNameToMap(current,fqname);
       
   193         }
       
   194     }
       
   195 
       
   196 // ----------------------------------------------------------------------------
       
   197 // HANodeIterator::FindNodeById
       
   198 // Constructor
       
   199 // 
       
   200 // ----------------------------------------------------------------------------
       
   201 //
       
   202 bool HANodeIterator::FindNodeById(const XMLCh * nodeId)
       
   203     {
       
   204     DOMNode * node = iNodeIndex.FindNodeById(root, nodeId);
       
   205 
       
   206     if (node)
       
   207         {
       
   208             current = node;
       
   209             return true;
       
   210         }
       
   211 
       
   212     return false;
       
   213     }
       
   214 
       
   215 // ----------------------------------------------------------------------------
       
   216 // HANodeIterator::IsSameNodeType
       
   217 // Constructor
       
   218 // 
       
   219 // ----------------------------------------------------------------------------
       
   220 //
       
   221 bool HANodeIterator::IsSameNodeType(const HANodeIterator& other)
       
   222 {
       
   223     if ( Equals(current->getNodeName(),other->getNodeName()) )
       
   224     {
       
   225         return true;
       
   226     }
       
   227 
       
   228     if ( (Equals( KXMLClassString,other->getNodeName()) && Equals( KXMLStructString,current->getNodeName()))
       
   229              ||
       
   230          (Equals( KXMLClassString,current->getNodeName()) && Equals( KXMLStructString,other->getNodeName()))
       
   231         )
       
   232     {
       
   233         return true;
       
   234     }
       
   235 
       
   236     return false;
       
   237 }
       
   238 
       
   239 // ----------------------------------------------------------------------------
       
   240 // HANodeIterator::FindNodeByName
       
   241 // Find node by name
       
   242 // 
       
   243 // ----------------------------------------------------------------------------
       
   244 //
       
   245 bool HANodeIterator::FindNodeByName(pair<const XMLCh *,const XMLCh *> nodeName)
       
   246     {
       
   247     DOMNode * node = iNodeIndex.FindNodeByFQName(root, nodeName);
       
   248 
       
   249     if (node)
       
   250         {
       
   251             current = node;
       
   252             return true;
       
   253         }
       
   254 
       
   255     return false;
       
   256     }
       
   257 
       
   258 // ----------------------------------------------------------------------------
       
   259 // HANodeIterator::GetAttribute
       
   260 // 
       
   261 // ----------------------------------------------------------------------------
       
   262 //
       
   263 const XMLCh* HANodeIterator::GetAttribute(const char* attribute) const
       
   264     {
       
   265     return ::GetAttribute(this->current,attribute);
       
   266     }
       
   267 
       
   268 // ----------------------------------------------------------------------------
       
   269 // HANodeIterator::GetAttribute
       
   270 // 
       
   271 // ----------------------------------------------------------------------------
       
   272 //
       
   273 const XMLCh* HANodeIterator::GetAttribute(const XMLCh* attribute) const
       
   274     {
       
   275     return ::GetAttribute(this->current,attribute);
       
   276     }
       
   277 // ----------------------------------------------------------------------------
       
   278 // HANodeIterator::HANodeIterator
       
   279 // 
       
   280 // ----------------------------------------------------------------------------
       
   281 //
       
   282 bool HANodeIterator::CheckForBooleanAttribute(const XMLCh* attribute) const
       
   283     {
       
   284     return ::CheckForBooleanAttribute(current, attribute);
       
   285     }
       
   286 
       
   287 // ----------------------------------------------------------------------------
       
   288 // HANodeIterator::CheckForBooleanAttribute
       
   289 // 
       
   290 // ----------------------------------------------------------------------------
       
   291 //
       
   292 bool HANodeIterator::CheckForBooleanAttribute(const char* attribute) const
       
   293     {
       
   294     return ::CheckForBooleanAttribute(current, attribute);
       
   295     }
       
   296 
       
   297 // ----------------------------------------------------------------------------
       
   298 // HANodeIterator::SetAttribute
       
   299 // Constructor
       
   300 // 
       
   301 // ----------------------------------------------------------------------------
       
   302 //
       
   303 void HANodeIterator::SetAttribute(const char* attribute, const char* value)
       
   304     {
       
   305         ::SetAttribute(current, attribute, value);
       
   306     }
       
   307 
       
   308 // ----------------------------------------------------------------------------
       
   309 // HANodeIterator::SetAttribute
       
   310 // Set attribute value
       
   311 // 
       
   312 // ----------------------------------------------------------------------------
       
   313 //
       
   314 void HANodeIterator::SetAttribute(const char* attribute, const XMLCh* value)
       
   315     {
       
   316     XMLCh* chattribute = XMLString::transcode(attribute);
       
   317     ::SetAttribute(current, chattribute, value);
       
   318     XMLString::release(&chattribute);
       
   319     }
       
   320 
       
   321 // ----------------------------------------------------------------------------
       
   322 // HANodeIterator::SetAttribute
       
   323 // Set attribute value
       
   324 // 
       
   325 // ----------------------------------------------------------------------------
       
   326 //
       
   327 void HANodeIterator::SetAttribute(const XMLCh* attribute, const char* value)
       
   328     {
       
   329     XMLCh* chvalue = XMLString::transcode(value);
       
   330     ::SetAttribute(current, attribute, chvalue);
       
   331     XMLString::release(&chvalue);
       
   332     }
       
   333 
       
   334 // ----------------------------------------------------------------------------
       
   335 // HANodeIterator::SetAttribute
       
   336 // Set attribute value
       
   337 // 
       
   338 // ----------------------------------------------------------------------------
       
   339 //
       
   340 void HANodeIterator::SetAttribute(const XMLCh* attribute, const XMLCh* value)
       
   341     {
       
   342     ::SetAttribute(current, attribute, value);
       
   343     }
       
   344 
       
   345 
       
   346 // ----------------------------------------------------------------------------
       
   347 // HANodeIterator::GetElementsByTagName
       
   348 // 
       
   349 // ----------------------------------------------------------------------------
       
   350 //
       
   351 DOMNodeList* HANodeIterator::GetElementsByTagName(const char* tag) const
       
   352     {
       
   353     XMLCh * enumvaltag = XMLString::transcode(tag);
       
   354     DOMNodeList* childs = GetElementsByTagName(enumvaltag);
       
   355     XMLString::release(&enumvaltag);
       
   356 
       
   357     return childs;
       
   358     }
       
   359 
       
   360 // ----------------------------------------------------------------------------
       
   361 // HANodeIterator::GetElementsByTagName
       
   362 // 
       
   363 // ----------------------------------------------------------------------------
       
   364 //
       
   365 DOMNodeList* HANodeIterator::GetElementsByTagName(const XMLCh* tag) const
       
   366     {
       
   367     return (static_cast<DOMElement*>(this->current))->getElementsByTagName(tag);
       
   368     }
       
   369 
       
   370 // ----------------------------------------------------------------------------
       
   371 // HANodeIterator::addIssue
       
   372 // Add issue found in analysis
       
   373 // ----------------------------------------------------------------------------
       
   374 //
       
   375 void HANodeIterator::addIssue(TIssueIdentity aIdentityId, TIssueType aTypeId, TBCSeverity bcseverity, TSCSeverity scseverity, string ignoreinfo, const XMLCh* fileid, const string name,int lineNumber) const
       
   376     {
       
   377     bool lFlag = false;
       
   378     if ( !fileid )
       
   379     {
       
   380         fileid = this->GetAttribute(KXMLFileIdString);
       
   381     }
       
   382 
       
   383     string fqname(GenerateFullyQualifiedName(*this));
       
   384     fqname += name;
       
   385     const pair<const XMLCh*,bool>& file = iNodeIndex.FindFileByFileId(fileid);
       
   386 
       
   387     string compareFileName("");
       
   388 
       
   389     list< pair<string,string> >::const_iterator it = iFilesToAnalyse.begin();
       
   390 
       
   391     /*int linenumber = 0;
       
   392     const XMLCh* strlinenumber = this->GetAttribute(KXMLLineString);
       
   393 
       
   394     if ( strlinenumber )
       
   395     {
       
   396         linenumber = atoi(toString(strlinenumber).c_str());
       
   397     }
       
   398    */
       
   399     string filename(toString(file.first));
       
   400 
       
   401     string::size_type dirSepInd = filename.find_first_of("\\/");
       
   402     if( dirSepInd != string::npos && filename.at(dirSepInd) != DIR_SEPARATOR )
       
   403     {
       
   404         // We need to convert to proper dir-separator
       
   405         replaceChar(filename, filename.at(dirSepInd), DIR_SEPARATOR);
       
   406     }
       
   407 
       
   408     for (; it != iFilesToAnalyse.end(); ++it)
       
   409     {
       
   410         if (iBaselineNode)
       
   411         {
       
   412             if ( CompareFileNames(((*it).first),filename ) )
       
   413             {
       
   414                 filename = ((*it).first);
       
   415                 compareFileName = ((*it).second);
       
   416                 lFlag = true;
       
   417                 break;
       
   418             }
       
   419         }
       
   420         else
       
   421         {
       
   422             if ( CompareFileNames(((*it).second),filename ) )
       
   423             {
       
   424                 compareFileName = ((*it).first);
       
   425                 filename = ((*it).second);
       
   426                 lFlag = true;
       
   427                 break;
       
   428             }
       
   429         }
       
   430     }
       
   431     if(lFlag == true )
       
   432     {
       
   433         if ( iBaselineNode )
       
   434         {
       
   435             this->iReport.addIssue(filename, 
       
   436                 fqname, aIdentityId, aTypeId, bcseverity, scseverity, ignoreinfo, lineNumber,
       
   437                 compareFileName, "");
       
   438         }
       
   439         else
       
   440         {
       
   441             this->iReport.addIssue(compareFileName, 
       
   442                 fqname, aIdentityId, aTypeId, bcseverity, scseverity, ignoreinfo, lineNumber,
       
   443                 filename, "");
       
   444         }
       
   445     }
       
   446     }