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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/***************************************************************************
begin : Sat Jul 21 2001
copyright : (C) 2001 by Victor R�er
email : [email protected]
copyright : (C) 2002,2003 by Roberto Raggi
email : [email protected]
copyright : (C) 2005 by Adam Treat
email : [email protected]
copyright : (C) 2006 by David Nolden
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef __COMPUTERECOVERYPOINTS_H__
#define __COMPUTERECOVERYPOINTS_H__
#include <tqvaluestack.h>
#include "simpletype.h"
#include "simpletypenamespace.h"
#include "tree_parser.h"
static TQString toSimpleName( NameAST* name )
{
if ( !name )
return TQString::null;
TQString s;
TQPtrList<ClassOrNamespaceNameAST> l = name->classOrNamespaceNameList();
TQPtrListIterator<ClassOrNamespaceNameAST> nameIt( l );
while ( nameIt.current() )
{
if ( nameIt.current() ->name() )
{
s += nameIt.current() ->name() ->text() + "::";
}
++nameIt;
}
if ( name->unqualifiedName() && name->unqualifiedName() ->name() )
s += name->unqualifiedName() ->name() ->text();
return s;
}
struct RecoveryPoint
{
int kind;
TQStringList scope;
TQValueList<TQStringList> imports;
int startLine, startColumn;
int endLine, endColumn;
RecoveryPoint()
: kind( 0 ), startLine( 0 ), startColumn( 0 ),
endLine( 0 ), endColumn( 0 )
{}
///Registers the recovery-points imports into the given namespace
void registerImports( SimpleType ns, TQString hardCodedAliases ) {
SimpleTypeNamespace* n = dynamic_cast<SimpleTypeNamespace*>( &(*ns) );
if( !n ) {
kdDebug( 9007 ) << "the global namespace was not resolved correctly " << endl;
} else {
///put the imports into the global namespace
for( TQValueList<TQStringList>::iterator it = imports.begin(); it != imports.end(); ++it ) {
kdDebug( 9007 ) << "inserting import " << *it << " into the global scope" << endl;
n->addAliasMap( TQString(""), (*it).join("::"), IncludeFiles() ); ///@TODO: remove this
}
n->addAliases( hardCodedAliases );
}
}
private:
RecoveryPoint( const RecoveryPoint& source );
void operator = ( const RecoveryPoint& source );
};
// namespace?
class ComputeRecoveryPoints: public TreeParser
{
public:
ComputeRecoveryPoints( TQPtrList<RecoveryPoint>& points )
: recoveryPoints( points )
{}
virtual void parseTranslationUnit( const ParsedFile& ast )
{
TQValueList<TQStringList> dummy;
m_imports.push( dummy );
TreeParser::parseTranslationUnit( ast );
m_imports.pop();
kdDebug( 9007 ) << "found " << recoveryPoints.count() << " recovery points" << endl;
}
virtual void parseUsingDirective( UsingDirectiveAST* ast )
{
if ( !ast->name() )
return ;
//TQStringList type = CppCodeCompletion::typeName( ast->name() ->text() ).scope();
m_imports.top().push_back( ast->name() ->text() );
}
virtual void parseNamespace( NamespaceAST* ast )
{
m_currentScope.push_back( ast->namespaceName() ->text() );
insertRecoveryPoint( ast );
m_imports.push( m_imports.top() ); // dup
// m_imports.top().push_back( m_currentScope );
TreeParser::parseNamespace( ast );
m_imports.pop();
m_currentScope.pop_back();
}
void parseTemplateDeclaration( TemplateDeclarationAST* ast )
{
if ( ast->declaration() )
parseDeclaration( ast->declaration() );
TreeParser::parseTemplateDeclaration( ast );
}
virtual void parseSimpleDeclaration( SimpleDeclarationAST* ast )
{
TypeSpecifierAST * typeSpec = ast->typeSpec();
//InitDeclaratorListAST* declarators = ast->initDeclaratorList();
if ( typeSpec )
parseTypeSpecifier( typeSpec );
//insertRecoveryPoint( ast );
TreeParser::parseSimpleDeclaration( ast );
}
virtual void parseFunctionDefinition( FunctionDefinitionAST* ast )
{
m_imports.push( m_imports.top() ); // dup
insertRecoveryPoint( ast );
m_imports.pop();
}
virtual void parseClassSpecifier( ClassSpecifierAST* ast )
{
insertRecoveryPoint( ast );
m_currentScope.push_back( toSimpleName( ast->name() ) );
TreeParser::parseClassSpecifier( ast );
m_currentScope.pop_back();
}
void insertRecoveryPoint( AST* ast )
{
if ( !ast )
return ;
RecoveryPoint* pt = new RecoveryPoint();
pt->kind = ast->nodeType();
pt->scope = m_currentScope;
ast->getStartPosition( &pt->startLine, &pt->startColumn );
ast->getEndPosition( &pt->endLine, &pt->endColumn );
pt->imports = m_imports.top();
recoveryPoints.append( pt );
}
private:
TQPtrList<RecoveryPoint>& recoveryPoints;
TQValueStack< TQValueList<TQStringList> > m_imports;
TQStringList m_currentScope;
};
#endif
// kate: indent-mode csands; tab-width 4;
|