~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/cppsupport_utils.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <qdir.h>
2
 
 
3
 
#include <kapplication.h>
4
 
#include <kconfig.h>
5
 
#include <kdebug.h>
6
 
 
7
 
#include <codemodel.h>
8
 
 
9
 
#include "cppsupport_utils.h"
10
 
 
11
 
static void typeNameList( QStringList& path, QStringList & lst, const CodeModel * model );
12
 
static void typeNameList( QStringList& path, QStringList & lst, NamespaceDom ns );
13
 
static void typeNameList( QStringList & path, QStringList & lst, ClassDom klass );
14
 
 
15
 
QStringList typeNameList( const CodeModel* model )
16
 
{
17
 
        QStringList lst;
18
 
        QStringList path;
19
 
        typeNameList( path, lst, model );
20
 
        return lst;
21
 
}
22
 
 
23
 
static void typeNameList( QStringList& path, QStringList & lst, const CodeModel * model )
24
 
{
25
 
        const FileList fileList = model->fileList();
26
 
        for( FileList::ConstIterator it=fileList.begin(); it!=fileList.end(); ++it )
27
 
                typeNameList( path, lst, model_cast<NamespaceDom>(*it) );
28
 
}
29
 
 
30
 
static void typeNameList( QStringList& path, QStringList & lst, NamespaceDom ns )
31
 
{
32
 
        if( !ns->isFile() )
33
 
                path.push_back( ns->name() );
34
 
        
35
 
        const NamespaceList namespaceList = ns->namespaceList();
36
 
        for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
37
 
                typeNameList( path, lst, *it );
38
 
        
39
 
        const ClassList classList = ns->classList();
40
 
        for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
41
 
                typeNameList( path, lst, *it );
42
 
        
43
 
        if( !ns->isFile() )
44
 
                path.pop_back();
45
 
}
46
 
 
47
 
static void typeNameList( QStringList & path, QStringList & lst, ClassDom klass )
48
 
{
49
 
        path.push_back( klass->name() );
50
 
        
51
 
        lst << path.join( "::" );
52
 
        
53
 
        const ClassList classList = klass->classList();
54
 
        for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
55
 
                typeNameList( path, lst, *it );
56
 
        
57
 
        path.pop_back();
58
 
}
59
 
 
60
 
static void typedefMap( QMap<QString, QString> & map, const CodeModel * model );
61
 
static void typedefMap( QMap<QString, QString> & map, NamespaceDom ns );
62
 
static void typedefMap( QMap<QString, QString> & map, ClassDom klass );
63
 
 
64
 
QMap<QString, QString> typedefMap( const CodeModel* model )
65
 
{
66
 
        QMap<QString, QString> map;
67
 
        typedefMap( map, model );
68
 
        
69
 
        /*We need to flatten the typedefs to avoid circular aliases. 
70
 
      Example:
71
 
                map["Foo"] = "int";
72
 
                map["Bar"] = "Foo";
73
 
                map["Baz"] = "Bar";*/
74
 
        
75
 
        QMap<QString, QString>::iterator it = map.begin();
76
 
        for ( ; it != map.end(); ++it )
77
 
        {
78
 
                while ( map.contains( map[ it.key() ] ) && 
79
 
                        it.key() != map[ it.key() ] )
80
 
                {
81
 
                        map[ it.key() ] = map[ map[ it.key() ] ];
82
 
                }
83
 
        }
84
 
        
85
 
        return map;
86
 
}
87
 
 
88
 
static void typedefMap( QMap<QString, QString> & map, const CodeModel * model )
89
 
{
90
 
        const FileList fileList = model->fileList();
91
 
        for( FileList::ConstIterator it=fileList.begin(); it!=fileList.end(); ++it )
92
 
                typedefMap( map, model_cast<NamespaceDom>(*it) );
93
 
}
94
 
 
95
 
static void typedefMap( QMap<QString, QString> & map, NamespaceDom ns )
96
 
{
97
 
        const TypeAliasList aliasList = ns->typeAliasList();
98
 
        for( TypeAliasList::ConstIterator it=aliasList.begin(); it!=aliasList.end(); ++it )
99
 
                map[ ( *it )->name() ] = ( *it )->type();
100
 
        
101
 
        const NamespaceList namespaceList = ns->namespaceList();
102
 
        for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
103
 
                typedefMap( map, *it );
104
 
        
105
 
        const ClassList classList = ns->classList();
106
 
        for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
107
 
                typedefMap( map, *it );
108
 
}
109
 
 
110
 
static void typedefMap( QMap<QString, QString> & map, ClassDom klass )
111
 
{
112
 
        const TypeAliasList aliasList = klass->typeAliasList();
113
 
        for( TypeAliasList::ConstIterator it=aliasList.begin(); it!=aliasList.end(); ++it )
114
 
                map[ ( *it )->name() ] = ( *it )->type();
115
 
        
116
 
        const ClassList classList = klass->classList();
117
 
        for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
118
 
                typedefMap( map, *it );
119
 
}
120
 
 
121
 
QString formattedOpeningParenthesis(bool suppressSpace)
122
 
{
123
 
        KConfig * config = kapp->config();
124
 
        config->setGroup("AStyle");
125
 
        bool use_spaces = config->readBoolEntry("PadParentheses", false);
126
 
        if (not use_spaces or suppressSpace) return "(";
127
 
        return "( ";
128
 
}
129
 
 
130
 
QString formattedClosingParenthesis(bool suppressSpace)
131
 
{
132
 
        KConfig * config = kapp->config();
133
 
        config->setGroup("AStyle");
134
 
        bool use_spaces = config->readBoolEntry("PadParentheses", false);
135
 
        if (not use_spaces or suppressSpace) return ")";
136
 
        return " )";
137
 
}
138
 
 
139
 
//kate: indent-mode csands; tab-width 4; space-indent off;