File: cppsupport_utils.cpp

package info (click to toggle)
kdevelop 4%3A3.3.5-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 48,900 kB
  • ctags: 30,911
  • sloc: cpp: 289,305; sh: 18,675; makefile: 3,890; perl: 3,261; ruby: 2,081; ansic: 1,779; python: 1,636; xml: 577; yacc: 421; java: 359; lex: 252; php: 20; ada: 5; fortran: 4; pascal: 4; haskell: 2; sql: 1
file content (118 lines) | stat: -rw-r--r-- 3,718 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

#include "cppsupport_utils.h"
#include <codemodel.h>
#include <qdir.h>

#include <kdebug.h>

static void typeNameList( QStringList& path, QStringList & lst, const CodeModel * model );
static void typeNameList( QStringList& path, QStringList & lst, NamespaceDom ns );
static void typeNameList( QStringList & path, QStringList & lst, ClassDom klass );

QStringList typeNameList( const CodeModel* model )
{
	QStringList lst;
	QStringList path;
	typeNameList( path, lst, model );
	return lst;
}

static void typeNameList( QStringList& path, QStringList & lst, const CodeModel * model )
{
	const FileList fileList = model->fileList();
	for( FileList::ConstIterator it=fileList.begin(); it!=fileList.end(); ++it )
		typeNameList( path, lst, model_cast<NamespaceDom>(*it) );
}

static void typeNameList( QStringList& path, QStringList & lst, NamespaceDom ns )
{
	if( !ns->isFile() )
		path.push_back( ns->name() );
	
	const NamespaceList namespaceList = ns->namespaceList();
	for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
		typeNameList( path, lst, *it );
	
	const ClassList classList = ns->classList();
	for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
		typeNameList( path, lst, *it );
	
	if( !ns->isFile() )
		path.pop_back();
}

static void typeNameList( QStringList & path, QStringList & lst, ClassDom klass )
{
	path.push_back( klass->name() );
	
	lst << path.join( "::" );
	
	const ClassList classList = klass->classList();
	for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
		typeNameList( path, lst, *it );
	
	path.pop_back();
}

static void typedefMap( QMap<QString, QString> & map, const CodeModel * model );
static void typedefMap( QMap<QString, QString> & map, NamespaceDom ns );
static void typedefMap( QMap<QString, QString> & map, ClassDom klass );

QMap<QString, QString> typedefMap( const CodeModel* model )
{
	QMap<QString, QString> map;
	typedefMap( map, model );
	
	/*We need to flatten the typedefs to avoid circular aliases. 
      Example:
		map["Foo"] = "int";
		map["Bar"] = "Foo";
		map["Baz"] = "Bar";*/
	
	QMap<QString, QString>::iterator it = map.begin();
	for ( ; it != map.end(); ++it )
	{
		while ( map.contains( map[ it.key() ] ) && 
		        it.key() != map[ it.key() ] )
		{
	 		map[ it.key() ] = map[ map[ it.key() ] ];
		}
	}
	
	return map;
}

static void typedefMap( QMap<QString, QString> & map, const CodeModel * model )
{
	const FileList fileList = model->fileList();
	for( FileList::ConstIterator it=fileList.begin(); it!=fileList.end(); ++it )
		typedefMap( map, model_cast<NamespaceDom>(*it) );
}

static void typedefMap( QMap<QString, QString> & map, NamespaceDom ns )
{
	const TypeAliasList aliasList = ns->typeAliasList();
	for( TypeAliasList::ConstIterator it=aliasList.begin(); it!=aliasList.end(); ++it )
		map[ ( *it )->name() ] = ( *it )->type();
	
	const NamespaceList namespaceList = ns->namespaceList();
	for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
		typedefMap( map, *it );
	
	const ClassList classList = ns->classList();
	for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
		typedefMap( map, *it );
}

static void typedefMap( QMap<QString, QString> & map, ClassDom klass )
{
	const TypeAliasList aliasList = klass->typeAliasList();
	for( TypeAliasList::ConstIterator it=aliasList.begin(); it!=aliasList.end(); ++it )
		map[ ( *it )->name() ] = ( *it )->type();
	
	const ClassList classList = klass->classList();
	for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
		typedefMap( map, *it );
}

//kate: indent-mode csands; tab-width 4; space-indent off;