summaryrefslogtreecommitdiffstats
path: root/languages/cpp/cppsupport_utils.cpp
blob: b4be045d483db0334295582fdf3dd5d15a444ab7 (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <tqdir.h>

#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>

#include <codemodel.h>

#include "cppsupport_utils.h"

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

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

static void typeNameList( TQStringList& path, TQStringList & 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( TQStringList& path, TQStringList & 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( TQStringList & path, TQStringList & 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( TQMap<TQString, TQString> & map, const CodeModel * model );
static void typedefMap( TQMap<TQString, TQString> & map, NamespaceDom ns );
static void typedefMap( TQMap<TQString, TQString> & map, ClassDom klass );

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

static void typedefMap( TQMap<TQString, TQString> & 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( TQMap<TQString, TQString> & 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( TQMap<TQString, TQString> & 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 );
}

TQString formattedOpeningParenthesis(bool suppressSpace)
{
	KConfig * config = kapp->config();
	config->setGroup("AStyle");
	bool use_spaces = config->readBoolEntry("PadParentheses", false);
	if (not use_spaces or suppressSpace) return "(";
	return "( ";
}

TQString formattedClosingParenthesis(bool suppressSpace)
{
	KConfig * config = kapp->config();
	config->setGroup("AStyle");
	bool use_spaces = config->readBoolEntry("PadParentheses", false);
	if (not use_spaces or suppressSpace) return ")";
	return " )";
}

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