• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • TDevelop Interfaces Library
 

TDevelop Interfaces Library

  • lib
  • interfaces
codemodel_utils.h
Go to the documentation of this file.
1 /* This file is part of TDevelop
2  Copyright (C) 2003 Roberto Raggi <roberto@kdevelop.org>
3  Copyright (C) 2003-2004 Alexander Dymo <adymo@kdevelop.org>
4  Copyright (C) 2004 Jonas Jacobi<j.jacobi@gmx.de>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 #ifndef CODEMODEL_UTILS_H
22 #define CODEMODEL_UTILS_H
23 
24 #include "codemodel.h"
25 
63 namespace CodeModelUtils
64 {
65 
75 template <class Pred> void findFunctionDefinitions( Pred pred, const FileList& fileList, FunctionDefinitionList & lst );
76 
86 template <class Pred> void findFunctionDefinitions( Pred pred, const NamespaceDom& ns, FunctionDefinitionList & lst );
87 
97 template <class Pred> void findFunctionDefinitions( Pred pred, const NamespaceList& namespaceList, FunctionDefinitionList & lst );
98 
108 template <class Pred> void findFunctionDefinitions( Pred pred, const ClassList& classList, FunctionDefinitionList & lst );
109 
119 template <class Pred> void findFunctionDefinitions( Pred pred, const FunctionDefinitionList& functionDefinitionList, FunctionDefinitionList & lst );
120 
130 template <class Pred> void findFunctionDefinitions( Pred pred, const ClassDom& klass, FunctionDefinitionList & lst );
131 
141 template <class Pred> void findFunctionDefinitions( Pred pred, const FunctionDefinitionDom& fun, FunctionDefinitionList & lst );
142 
152 template <class Pred> void findFunctionDeclarations( Pred pred, const FileList& fileList, FunctionList & lst );
153 
163 template <class Pred> void findFunctionDeclarations( Pred pred, const NamespaceDom& ns, FunctionList & lst );
164 
174 template <class Pred> void findFunctionDeclarations( Pred pred, const NamespaceList& namespaceList, FunctionList & lst );
175 
185 template <class Pred> void findFunctionDeclarations( Pred pred, const ClassList& classList, FunctionList & lst );
186 
196 template <class Pred> void findFunctionDeclarations( Pred pred, const FunctionList& functionList, FunctionList & lst );
197 
207 template <class Pred> void findFunctionDeclarations( Pred pred, const ClassDom& klass, FunctionList & lst );
208 
218 template <class Pred> void findFunctionDeclarations( Pred pred, const FunctionDom& fun, FunctionList & lst );
219 
220 
221 //implementations of function templates defined above:
222 
223 template <class Pred>
224 void findFunctionDefinitions( Pred pred, const FileList& fileList, FunctionDefinitionList & lst )
225 {
226  for( FileList::ConstIterator it=fileList.begin(); it!=fileList.end(); ++it )
227  findFunctionDefinitions( pred, model_cast<NamespaceDom>(*it), lst );
228 }
229 
230 template <class Pred>
231 void findFunctionDefinitions( Pred pred, const NamespaceDom& ns, FunctionDefinitionList & lst )
232 {
233  findFunctionDefinitions( pred, ns->namespaceList(), lst );
234  findFunctionDefinitions( pred, ns->classList(), lst );
235  findFunctionDefinitions( pred, ns->functionDefinitionList(), lst );
236 }
237 
238 template <class Pred>
239 void findFunctionDefinitions( Pred pred, const NamespaceList& namespaceList, FunctionDefinitionList & lst )
240 {
241  for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
242  findFunctionDefinitions( pred, *it, lst );
243 }
244 
245 template <class Pred>
246 void findFunctionDefinitions( Pred pred, const ClassList& classList, FunctionDefinitionList & lst )
247 {
248  for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
249  findFunctionDefinitions( pred, *it, lst );
250 }
251 
252 template <class Pred>
253 void findFunctionDefinitions( Pred pred, const FunctionDefinitionList& functionDefinitionList, FunctionDefinitionList & lst )
254 {
255  for( FunctionDefinitionList::ConstIterator it=functionDefinitionList.begin(); it!=functionDefinitionList.end(); ++it )
256  findFunctionDefinitions( pred, *it, lst );
257 }
258 
259 template <class Pred>
260 void findFunctionDefinitions( Pred pred, const ClassDom& klass, FunctionDefinitionList & lst )
261 {
262  findFunctionDefinitions( pred, klass->classList(), lst );
263  findFunctionDefinitions( pred, klass->functionDefinitionList(), lst );
264 }
265 
266 template <class Pred>
267 void findFunctionDefinitions( Pred pred, const FunctionDefinitionDom& fun, FunctionDefinitionList & lst )
268 {
269  if( pred(fun) )
270  lst << fun;
271 }
272 
273 
274 
275 template <class Pred>
276 void findFunctionDeclarations( Pred pred, const FileList& fileList, FunctionList & lst )
277 {
278  for( FileList::ConstIterator it=fileList.begin(); it!=fileList.end(); ++it )
279  findFunctionDeclarations( pred, model_cast<NamespaceDom>(*it), lst );
280 }
281 
282 template <class Pred>
283 void findFunctionDeclarations( Pred pred, const NamespaceDom& ns, FunctionList & lst )
284 {
285  findFunctionDeclarations( pred, ns->namespaceList(), lst );
286  findFunctionDeclarations( pred, ns->classList(), lst );
287  findFunctionDeclarations( pred, ns->functionList(), lst );
288 }
289 
290 template <class Pred>
291 void findFunctionDeclarations( Pred pred, const NamespaceList& namespaceList, FunctionList & lst )
292 {
293  for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
294  findFunctionDeclarations( pred, *it, lst );
295 }
296 
297 template <class Pred>
298 void findFunctionDeclarations( Pred pred, const ClassList& classList, FunctionList & lst )
299 {
300  for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
301  findFunctionDeclarations( pred, *it, lst );
302 }
303 
304 template <class Pred>
305 void findFunctionDeclarations( Pred pred, const FunctionList& functionList, FunctionList & lst )
306 {
307  for( FunctionList::ConstIterator it=functionList.begin(); it!=functionList.end(); ++it )
308  findFunctionDeclarations( pred, *it, lst );
309 }
310 
311 template <class Pred>
312 void findFunctionDeclarations( Pred pred, const ClassDom& klass, FunctionList & lst )
313 {
314  findFunctionDeclarations( pred, klass->classList(), lst );
315  findFunctionDeclarations( pred, klass->functionList(), lst );
316 }
317 
318 template <class Pred>
319 void findFunctionDeclarations( Pred pred, const FunctionDom& fun, FunctionList & lst )
320 {
321  if( pred(fun) )
322  lst << fun;
323 }
324 
326 struct Scope{
328  ClassDom klass;
330  NamespaceDom ns;
331 };
332 
334 struct AllFunctions{
336  TQMap<FunctionDom, Scope> relations;
338  FunctionList functionList;
339 };
341 struct AllFunctionDefinitions{
343  TQMap<FunctionDefinitionDom, Scope> relations;
345  FunctionDefinitionList functionList;
346 };
347 
349 namespace Functions{
353 void processClasses(FunctionList &list, const ClassDom dom);
354 
358 void processNamespaces(FunctionList &list, const NamespaceDom dom);
359 
364 void processClasses(FunctionList &list, const ClassDom dom, TQMap<FunctionDom, Scope> &relations);
365 
372 void processClasses(FunctionList &list, const ClassDom dom, TQMap<FunctionDom, Scope> &relations, const NamespaceDom &nsdom);
373 
378 void processNamespaces(FunctionList &list, const NamespaceDom dom, TQMap<FunctionDom, Scope> &relations);
379 }
380 
382 namespace FunctionDefinitions{
386 void processClasses(FunctionDefinitionList &list, const ClassDom dom);
387 
391 void processNamespaces(FunctionDefinitionList &list, const NamespaceDom dom);
392 
397 void processClasses(FunctionDefinitionList &list, const ClassDom dom, TQMap<FunctionDefinitionDom, Scope> &relations);
398 
405 void processClasses(FunctionDefinitionList &list, const ClassDom dom, TQMap<FunctionDefinitionDom, Scope> &relations, const NamespaceDom &nsdom);
406 
411 void processNamespaces(FunctionDefinitionList &list, const NamespaceDom dom, TQMap<FunctionDefinitionDom, Scope> &relations);
412 }
413 
421 bool compareDeclarationToDefinition(const FunctionDom& dec, const FunctionDefinitionDom& def);
422 
430 bool compareDeclarationToDefinition(const FunctionDom& dec, const FunctionDefinitionDom& def, const std::set<NamespaceImportModel>& nsImports);
431 
437 class PredDefinitionMatchesDeclaration{
438 public:
439  PredDefinitionMatchesDeclaration(const FunctionDom& func) : m_declaration(func){};
440  bool operator() (const FunctionDefinitionDom& def) const
441  {
442  return compareDeclarationToDefinition(m_declaration, def);
443  }
444 
445 private:
446  const FunctionDom m_declaration;
447 };
448 
449 template <class InputDomType>
450 class PredAmOwner{
451  public:
452  PredAmOwner(const FileDom& file) : m_file(file){};
453  bool operator() (const InputDomType& def) const
454  {
455  return def->file() == m_file;
456  }
457 
458  private:
459  const FileDom m_file;
460 };
461 
464 FunctionList allFunctions(const FileDom &dom);
468 AllFunctions allFunctionsDetailed(const FileDom &dom);
472 AllFunctionDefinitions allFunctionDefinitionsDetailed(const FileDom &dom);
473 
481 FunctionList allFunctionsExhaustive(FileDom &dom);
482 
490 FunctionDefinitionList allFunctionDefinitionsExhaustive(FileDom &dom);
491 
501 ClassDom findClassByPosition( NamespaceModel* nameSpace, int line, int col );
502 
506 ClassDom findClassByPosition( ClassModel* aClass, int line, int col );
507 
517 int findLastMethodLine( ClassDom aClass, CodeModelItem::Access access );
518 
522 int findLastVariableLine( ClassDom aClass, CodeModelItem::Access access );
523 
530 TQString accessSpecifierToString( CodeModelItem::Access access );
531 
532 
533 class CodeModelHelper {
534  private:
535  CodeModel* m_model;
536  FileList m_files;
537  TQString m_fileName;
538 
539  FunctionDefinitionDom functionDefinitionAt(NamespaceDom ns, int line, int column);
540 
541  FunctionDefinitionDom functionDefinitionAt(ClassDom klass, int line, int column);
542 
543  FunctionDefinitionDom functionDefinitionAt(FunctionDefinitionDom fun, int line, int );
544 
545  FunctionDom functionDeclarationAt(NamespaceDom ns, int line, int column);
546 
547  FunctionDom functionDeclarationAt(ClassDom klass, int line, int column);
548 
549  FunctionDom functionDeclarationAt(FunctionDom fun, int line, int column );
550 
551 
552  ClassDom classAt(NamespaceDom ns, int line, int column);
553 
554  ClassDom classAt(ClassDom klass, int line, int column);
555 
556  public:
557  CodeModelHelper( CodeModel* model, FileDom file );
558 
559  enum FunctionTypes {
560  Declaration = 1,
561  Definition = 2
562  };
563 
564  FunctionDom functionAt( int line, int column, FunctionTypes types = (FunctionTypes)3 );
565  ClassDom classAt( int line, int column );
566 };
567 
568 }
569 
570 #endif
CodeModelUtils::allFunctionsDetailed
AllFunctions allFunctionsDetailed(const FileDom &dom)
Definition: codemodel_utils.cpp:245
CodeModelUtils::findLastMethodLine
int findLastMethodLine(ClassDom aClass, CodeModelItem::Access access)
Finds the last occurrence (line of file wise) of a method inside a class declaration with specific ac...
Definition: codemodel_utils.cpp:455
CodeModelUtils::allFunctionDefinitionsExhaustive
FunctionDefinitionList allFunctionDefinitionsExhaustive(FileDom &dom)
Definition: codemodel_utils.cpp:393
CodeModelUtils::AllFunctions::functionList
FunctionList functionList
List of functions.
Definition: codemodel_utils.h:338
CodeModelUtils::AllFunctions::relations
TQMap< FunctionDom, Scope > relations
Scope of functions.
Definition: codemodel_utils.h:336
CodeModelUtils::allFunctionDefinitionsDetailed
AllFunctionDefinitions allFunctionDefinitionsDetailed(const FileDom &dom)
Definition: codemodel_utils.cpp:271
CodeModelUtils::Scope::ns
NamespaceDom ns
Namespace.
Definition: codemodel_utils.h:330
CodeModelUtils::allFunctionsExhaustive
FunctionList allFunctionsExhaustive(FileDom &dom)
Definition: codemodel_utils.cpp:383
codemodel.h
Code Model - a memory symbol store.
CodeModelUtils::PredDefinitionMatchesDeclaration
Predicate for use with findFunctionDefintions.
Definition: codemodel_utils.h:437
CodeModelUtils::findFunctionDefinitions
void findFunctionDefinitions(Pred pred, const FileList &fileList, FunctionDefinitionList &lst)
Finds function definitions which match given predicate in files.
Definition: codemodel_utils.h:224
CodeModelUtils::Scope
A scope.
Definition: codemodel_utils.h:326
CodeModelUtils::AllFunctionDefinitions::functionList
FunctionDefinitionList functionList
List of function definitions.
Definition: codemodel_utils.h:345
CodeModelUtils::AllFunctionDefinitions
Information about function definitions.
Definition: codemodel_utils.h:341
NamespaceList
The list of code model namespaces.
FunctionDefinitionList
The list of code model function definitions.
CodeModelUtils::accessSpecifierToString
TQString accessSpecifierToString(CodeModelItem::Access access)
Get the string representation of an accesss pecifier.
Definition: codemodel_utils.cpp:489
CodeModelUtils::findLastVariableLine
int findLastVariableLine(ClassDom aClass, CodeModelItem::Access access)
Same as above, but finds a membervariable instead of a method.
Definition: codemodel_utils.cpp:472
CodeModelUtils::findClassByPosition
ClassDom findClassByPosition(NamespaceModel *nameSpace, int line, int col)
Finds a class by its position in a file(position inside the part of the file, where the class is decl...
Definition: codemodel_utils.cpp:404
ClassList
The list of code model classes.
CodeModelUtils::AllFunctions
Information about functions.
Definition: codemodel_utils.h:334
NamespaceModel
Namespace model.
Definition: codemodel.h:1039
FunctionDom
Safe pointer to the FunctionModel.
CodeModelUtils::Scope::klass
ClassDom klass
Class.
Definition: codemodel_utils.h:328
CodeModelItem::Access
Access
An access to the code model item.
Definition: codemodel.h:486
ClassDom
Safe pointer to the ClassModel.
CodeModelUtils::AllFunctionDefinitions::relations
TQMap< FunctionDefinitionDom, Scope > relations
Scope of function definitions.
Definition: codemodel_utils.h:343
CodeModel
Code Model - a memory symbol store.
Definition: codemodel.h:324
CodeModelUtils::findFunctionDeclarations
void findFunctionDeclarations(Pred pred, const FileList &fileList, FunctionList &lst)
Finds function declarations which match given predicate in files.
Definition: codemodel_utils.h:276
FileList
The list of code model files.
FunctionDefinitionDom
Safe pointer to the FunctionDefinitionModel.
FileDom
Safe pointer to the FileModel.
CodeModelUtils
Namespace which contains utility functions and classes for the CodeModel.
Definition: codemodel_utils.cpp:24
CodeModelUtils::allFunctions
FunctionList allFunctions(const FileDom &dom)
Definition: codemodel_utils.cpp:219
NamespaceDom
Safe pointer to the NamespaceModel.
FunctionList
The list of code model functions.
Pred
The predicate.
ClassModel
Class model.
Definition: codemodel.h:696
CodeModelUtils::compareDeclarationToDefinition
bool compareDeclarationToDefinition(const FunctionDom &dec, const FunctionDefinitionDom &def)
Compares a declaration and a defintion of a function.
Definition: codemodel_utils.cpp:320

TDevelop Interfaces Library

Skip menu "TDevelop Interfaces Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

TDevelop Interfaces Library

Skip menu "TDevelop Interfaces Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for TDevelop Interfaces Library by doxygen 1.8.13
This website is maintained by Timothy Pearson.