0
|
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 |
#ifndef __NODE_INDEX_H_
|
|
20 |
#define __NODE_INDEX_H_
|
|
21 |
|
|
22 |
#include "CmdGlobals.h"
|
|
23 |
#ifdef __WIN__
|
|
24 |
#pragma warning(disable:4786)
|
|
25 |
#endif
|
|
26 |
#include <assert.h>
|
|
27 |
#include <map>
|
|
28 |
#include <list>
|
|
29 |
#include <xercesc/dom/DOM.hpp>
|
|
30 |
|
|
31 |
using namespace std;
|
|
32 |
|
|
33 |
XERCES_CPP_NAMESPACE_USE
|
|
34 |
|
|
35 |
//The access specifiers in class
|
|
36 |
enum TAccess
|
|
37 |
{
|
|
38 |
EAccessGlobal,
|
|
39 |
EAccessPublic,
|
|
40 |
EAccessProtected,
|
|
41 |
EAccessPrivate,
|
|
42 |
EAccessHidden
|
|
43 |
};
|
|
44 |
|
|
45 |
// The compare function for the fully qualified name that takes
|
|
46 |
// into account the identity of the node
|
|
47 |
struct compareFQName
|
|
48 |
{
|
|
49 |
bool operator()(
|
|
50 |
const pair<const XMLCh *,const XMLCh *>& p1,
|
|
51 |
const pair<const XMLCh *,const XMLCh *>& p2) const;
|
|
52 |
};
|
|
53 |
|
|
54 |
// General compare function for XMLCh
|
|
55 |
struct ltstr
|
|
56 |
{
|
|
57 |
bool operator()(const XMLCh * s1,const XMLCh * s2) const;
|
|
58 |
};
|
|
59 |
|
|
60 |
// Struct for data members
|
|
61 |
struct DataMember
|
|
62 |
{
|
|
63 |
string iName;
|
|
64 |
DOMNode* iNode;
|
|
65 |
int iOffset;
|
|
66 |
TAccess iAccess;
|
|
67 |
int iLineNo;
|
|
68 |
|
|
69 |
DataMember(string name,DOMNode* node, int offset, TAccess access, int lineNo):
|
|
70 |
iName(name),
|
|
71 |
iNode(node),
|
|
72 |
iOffset(offset),
|
|
73 |
iAccess(access),
|
|
74 |
iLineNo(lineNo)
|
|
75 |
{
|
|
76 |
}
|
|
77 |
|
|
78 |
DataMember(const DataMember& other)
|
|
79 |
{
|
|
80 |
this->operator=(other);
|
|
81 |
}
|
|
82 |
|
|
83 |
const DataMember & operator=(const DataMember& other)
|
|
84 |
{
|
|
85 |
iName = other.iName;
|
|
86 |
iNode = other.iNode;
|
|
87 |
iOffset = other.iOffset;
|
|
88 |
iAccess = other.iAccess;
|
|
89 |
iLineNo = other.iLineNo;
|
|
90 |
return *this;
|
|
91 |
}
|
|
92 |
};
|
|
93 |
|
|
94 |
|
|
95 |
/**
|
|
96 |
* The NodeIndex class indexes the nodes of the XML node tree by
|
|
97 |
* the fully qualified name and node ID.
|
|
98 |
*/
|
|
99 |
class NodeIndex
|
|
100 |
{
|
|
101 |
public:
|
|
102 |
typedef map< pair<const XMLCh *,const XMLCh *> , DOMNode*, compareFQName > fqnamemap;
|
|
103 |
typedef map< const XMLCh *,pair<const XMLCh*,bool>, ltstr > fileidmap;
|
|
104 |
typedef vector<pair<string,DOMNode*> > vtable_t;
|
|
105 |
typedef map< string, vtable_t > vtableindex_t;
|
|
106 |
typedef vector<DataMember> dtable_t;
|
|
107 |
typedef map< string, dtable_t > dtableindex_t;
|
|
108 |
public:
|
|
109 |
|
|
110 |
/**
|
|
111 |
* Clears the node map
|
|
112 |
*/
|
|
113 |
void clear();
|
|
114 |
|
|
115 |
/**
|
|
116 |
* Add the node with its id to the map
|
|
117 |
*/
|
|
118 |
void AddNodeIdToMap(DOMNode * node);
|
|
119 |
|
|
120 |
/**
|
|
121 |
* Add the node with fully qualified name to the map
|
|
122 |
* @param node current DOMNode pointer
|
|
123 |
* @param fqname fully qualified name
|
|
124 |
*/
|
|
125 |
void AddNodeFQNameToMap(DOMNode * node, const pair<const XMLCh*,const XMLCh*>& fqname);
|
|
126 |
|
|
127 |
/**
|
|
128 |
* Add the file node to file map
|
|
129 |
* @param id the node id
|
|
130 |
* @param file filepair to add
|
|
131 |
*/
|
|
132 |
void AddFileNodeToMap(const XMLCh* id,pair<const XMLCh*,bool> file);
|
|
133 |
|
|
134 |
/**
|
|
135 |
* Finds the node with id.
|
|
136 |
* @param root DOMNode pointer
|
|
137 |
* @param id of the node
|
|
138 |
* @return NULL if not found
|
|
139 |
*/
|
|
140 |
DOMNode * FindNodeById(DOMNode * root, const XMLCh* id);
|
|
141 |
|
|
142 |
/**
|
|
143 |
* Finds the node with fully qualified name.
|
|
144 |
* @param root DOMNode pointer
|
|
145 |
* @param FQName fullu qualified name of the node
|
|
146 |
* @return pointer to DOMnode or NULL if not found
|
|
147 |
*/
|
|
148 |
DOMNode * FindNodeByFQName(DOMNode * root, pair<const XMLCh*,const XMLCh* > FQName);
|
|
149 |
|
|
150 |
/**
|
|
151 |
* Returns the file pair <filename,tobeanalysed> by file id
|
|
152 |
* @param fileid id to search
|
|
153 |
* @return found filepair
|
|
154 |
*/
|
|
155 |
const pair<const XMLCh*,bool>& FindFileByFileId(const XMLCh* fileid);
|
|
156 |
|
|
157 |
/**
|
|
158 |
* Dumps the tables (for debugging)
|
|
159 |
*/
|
|
160 |
void DumpTables();
|
|
161 |
|
|
162 |
/**
|
|
163 |
* Adds a virtual function to the table vtable
|
|
164 |
* @param vtable virtual table name
|
|
165 |
* @param functionsig function signature
|
|
166 |
* @param node pointer to DOMNode
|
|
167 |
*/
|
|
168 |
void AddVirtualFunction(const string& vtable,const string& functionsig, DOMNode* node);
|
|
169 |
|
|
170 |
/**
|
|
171 |
* Gets the virtual table vtable
|
|
172 |
* @param vtable virtual table name
|
|
173 |
* @return virtual table pointer
|
|
174 |
*/
|
|
175 |
const vtable_t* GetVirtualTable(const string& vtable);
|
|
176 |
|
|
177 |
/**
|
|
178 |
* Add empty virtual table
|
|
179 |
* @param vtable virtual table name
|
|
180 |
* @return virtual table pointer
|
|
181 |
*/
|
|
182 |
const vtable_t* AddEmptyVirtualTable(const string& vtable);
|
|
183 |
|
|
184 |
/**
|
|
185 |
* Adds a data member to the table vtable
|
|
186 |
* @param parentNode Node iterator pointing to the parent node.
|
|
187 |
* @param parentName Name of the parent node.
|
|
188 |
* @param memberName name of the data table
|
|
189 |
* @param memberNode
|
|
190 |
* @param index offset value of member
|
|
191 |
* @param access how restricted the access of member is
|
|
192 |
*/
|
|
193 |
void AddDataMember(const HANodeIterator& parentNode, const string& parentName, const string& memberName, DOMNode* memberNode, int index, TAccess access,int lineNo);
|
|
194 |
|
|
195 |
/**
|
|
196 |
* Gets the data member table
|
|
197 |
* @param node Node iterator pointing to the node whose members should be returned.
|
|
198 |
* @param nodeName Name of the node.
|
|
199 |
* @return table pointer
|
|
200 |
*/
|
|
201 |
const dtable_t* GetDataMemberTable(const HANodeIterator& node, const string& nodeName);
|
|
202 |
|
|
203 |
/**
|
|
204 |
* Add empty data member table
|
|
205 |
* @param node Reference to the node of the object, whose members will
|
|
206 |
* get the new (empty) table entry
|
|
207 |
* @param nodeName Name of the node.
|
|
208 |
* @return data table pointer
|
|
209 |
*/
|
|
210 |
const dtable_t* AddEmptyDataMemberTable(const HANodeIterator& node, const string& nodeName);
|
|
211 |
|
|
212 |
//Private methods
|
|
213 |
private:
|
|
214 |
|
|
215 |
/**
|
|
216 |
* Search from the tree
|
|
217 |
* @param root DOM root node
|
|
218 |
* @param id to search
|
|
219 |
* @return id table pointer
|
|
220 |
*/
|
|
221 |
DOMNode * FindNodeByIdFromTree(DOMNode * root, const XMLCh* id);
|
|
222 |
|
|
223 |
/**
|
|
224 |
* Inserts data member entry to the given table.
|
|
225 |
* @param parentName Name of the data member's parent.
|
|
226 |
* @param member Data member to be inserted to the data table.
|
|
227 |
* @param dataTable Reference to the data table.
|
|
228 |
*/
|
|
229 |
void InsertDataMember(const string& parentName, const DataMember& member, dtableindex_t& dataTable);
|
|
230 |
|
|
231 |
//Private member variables
|
|
232 |
private:
|
|
233 |
|
|
234 |
//! Maps node id string to node pointer
|
|
235 |
map< const XMLCh *,DOMNode*,ltstr > iIdToNodeMap;
|
|
236 |
|
|
237 |
//! Maps filename to list of nodes declared in that file
|
|
238 |
fileidmap iIdToFileMap;
|
|
239 |
|
|
240 |
//! File node map
|
|
241 |
fqnamemap iFQNameToNodeMap;
|
|
242 |
|
|
243 |
//! VTable map
|
|
244 |
vtableindex_t iVTableIndex;
|
|
245 |
|
|
246 |
//! DTable map
|
|
247 |
dtableindex_t iDTableIndex;
|
|
248 |
|
|
249 |
//! Data table for anonymous classes
|
|
250 |
dtableindex_t iAnonymousTable;
|
|
251 |
};
|
|
252 |
|
|
253 |
#endif
|