• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevplatform/language/codegen

  • sources
  • kfour-appscomplete
  • kdevelop
  • kdevplatform
  • language
  • codegen
codedescription.cpp
Go to the documentation of this file.
1 /* This file is part of KDevelop
2  Copyright 2012 Miha Čančula <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 
20 #include "codedescription.h"
21 #include <debug.h>
22 #include <language/duchain/duchainutils.h>
23 #include <language/duchain/duchainlock.h>
24 #include <language/duchain/duchain.h>
25 #include <language/duchain/declaration.h>
26 #include <language/duchain/types/functiontype.h>
27 #include <language/duchain/classfunctiondeclaration.h>
28 #include <language/duchain/functiondeclaration.h>
29 
30 #include <KLocalizedString>
31 
32 using namespace KDevelop;
33 
40 QString accessPolicyName(const DeclarationPointer& declaration)
41 {
42  DUChainPointer<ClassMemberDeclaration> member = declaration.dynamicCast<ClassMemberDeclaration>();
43  if (member) {
44  switch (member->accessPolicy())
45  {
46  case Declaration::Private:
47  return QStringLiteral("private");
48  case Declaration::Protected:
49  return QStringLiteral("protected");
50  case Declaration::Public:
51  return QStringLiteral("public");
52  default:
53  break;
54  }
55  }
56  return QString();
57 }
58 
59 VariableDescription::VariableDescription()
60 {
61 }
62 
63 VariableDescription::VariableDescription(const QString& type, const QString& name)
64  : name(name)
65  , type(type)
66 {
67 }
68 
69 VariableDescription::VariableDescription(const DeclarationPointer& declaration)
70 {
71  DUChainReadLocker lock;
72 
73  if (declaration) {
74  name = declaration->identifier().toString();
75  if (auto abstractType = declaration->abstractType()) {
76  type = abstractType->toString();
77  }
78  }
79 
80  access = accessPolicyName(declaration);
81 }
82 
83 FunctionDescription::FunctionDescription()
84  : FunctionDescription::FunctionDescription({}, {}, {})
85 {
86 }
87 
88 FunctionDescription::FunctionDescription(const QString& name, const VariableDescriptionList& arguments,
89  const VariableDescriptionList& returnArguments)
90  : name(name)
91  , arguments(arguments)
92  , returnArguments(returnArguments)
93  , isConstructor(false)
94  , isDestructor(false)
95  , isVirtual(false)
96  , isStatic(false)
97  , isSlot(false)
98  , isSignal(false)
99  , isConst(false)
100 {
101 }
102 
103 FunctionDescription::FunctionDescription(const DeclarationPointer& declaration)
104  : FunctionDescription::FunctionDescription({}, {}, {})
105 {
106  DUChainReadLocker lock;
107 
108  if (declaration) {
109  name = declaration->identifier().toString();
110  DUContext* context = declaration->internalContext();
111 
112  DUChainPointer<FunctionDeclaration> function = declaration.dynamicCast<FunctionDeclaration>();
113  if (function) {
114  context = DUChainUtils::argumentContext(declaration.data());
115  }
116 
117  DUChainPointer<ClassFunctionDeclaration> method = declaration.dynamicCast<ClassFunctionDeclaration>();
118 
119  if (method) {
120  isConstructor = method->isConstructor();
121  isDestructor = method->isDestructor();
122  isVirtual = method->isVirtual();
123  isAbstract = method->isAbstract();
124  isFinal = method->isFinal();
125  isOverriding = (DUChainUtils::overridden(method.data()) != nullptr);
126  isStatic = method->isStatic();
127  isSlot = method->isSlot();
128  isSignal = method->isSignal();
129  }
130 
131  int i = 0;
132  const auto localDeclarations = context->localDeclarations();
133  arguments.reserve(localDeclarations.size());
134  for (Declaration* arg : localDeclarations) {
135  VariableDescription var = VariableDescription(DeclarationPointer(arg));
136  if (function) {
137  var.value = function->defaultParameterForArgument(i).str();
138  qCDebug(LANGUAGE) << var.name << var.value;
139  }
140  arguments << var;
141  ++i;
142  }
143 
144  FunctionType::Ptr functionType = declaration->abstractType().cast<FunctionType>();
145 
146  if (functionType) {
147  isConst = (functionType->modifiers() & AbstractType::ConstModifier);
148  }
149 
150  if (functionType && functionType->returnType()) {
151  returnArguments << VariableDescription(functionType->returnType()->toString(), QString());
152  }
153 
154  access = accessPolicyName(declaration);
155  }
156 }
157 
158 QString FunctionDescription::returnType() const
159 {
160  if (returnArguments.isEmpty()) {
161  return QString();
162  }
163  return returnArguments.first().type;
164 }
165 
166 ClassDescription::ClassDescription()
167 {
168 }
169 
170 ClassDescription::ClassDescription(const QString& name)
171  : name(name)
172 {
173 }
accessPolicyName
QString accessPolicyName(const DeclarationPointer &declaration)
The access policy as a string, or an empty string if the policy is set to default.
Definition: codedescription.cpp:40
QVector::isEmpty
bool isEmpty() const
KDevelop::ClassDescription::ClassDescription
ClassDescription()
Creates an empty class.
Definition: codedescription.cpp:166
KDevelop::FunctionDescription::FunctionDescription
FunctionDescription()
Creates a function with no name and no arguments.
Definition: codedescription.cpp:83
QVector::first
T & first()
codedescription.h
KDevelop::VariableDescription::VariableDescription
VariableDescription()
Creates a variable with no type and no name.
Definition: codedescription.cpp:59
KDevelop::FunctionDescription::returnArguments
QVector< VariableDescription > returnArguments
This function's return values.
Definition: codedescription.h:134
KDevelop::VariableDescription::value
QString value
The default value of this variable.
Definition: codedescription.h:80
QString
KDevelop::VariableDescription::name
QString name
The name of this variable.
Definition: codedescription.h:64
KDevelop::FunctionDescription
Represents a function.
Definition: codedescription.h:93
KDevelop::VariableDescription
Represents a variable.
Definition: codedescription.h:41
KDevelop
NOTE: changes in this file will quite probably also require changes in codedescriptionmetatype....
Definition: applychangeswidget.cpp:42
QVector< VariableDescription >
KDevelop::FunctionDescription::isConstructor
bool isConstructor
Specifies whether this function is a class constructor.
Definition: codedescription.h:145
KDevelop::FunctionDescription::returnType
QString returnType() const
Convenience method, returns the type of the first variable in returnArguments or an empty string if t...
Definition: codedescription.cpp:158
KDevelop::VariableDescription::access
QString access
Access specifier, only relevant for class members.
Definition: codedescription.h:76
KDevelop::VariableDescription::type
QString type
The type of this variable.
Definition: codedescription.h:70
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Mar 8 2021 23:29:45 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevplatform/language/codegen

Skip menu "kdevplatform/language/codegen"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  • kdevplatform
  •   debugger
  •   documentation
  •   interfaces
  •   language
  •     assistant
  •     backgroundparser
  •     checks
  •     classmodel
  •     codecompletion
  •     codegen
  •     duchain
  •     editor
  •     highlighting
  •     interfaces
  •     util
  •   outputview
  •   project
  •   serialization
  •   shell
  •   sublime
  •   tests
  •   util
  •   vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal