Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 9 additions & 133 deletions generator/abstractmetalang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,103 +875,6 @@ QList<ReferenceCount> AbstractMetaClass::referenceCounts() const
return returned;
}

/*******************************************************************************
* Returns a list of all the functions retrieved during parsing which should
* be added to the Java API.
*/
AbstractMetaFunctionList AbstractMetaClass::functionsInTargetLang() const
{
int default_flags = NormalFunctions | Visible | NotRemovedFromTargetLang;

// Interfaces don't implement functions
default_flags |= isInterface() ? 0 : ClassImplements;

// Only public functions in final classes
// default_flags |= isFinal() ? WasPublic : 0;
int public_flags = isFinal() ? WasPublic : 0;

// Constructors
AbstractMetaFunctionList returned = queryFunctions(Constructors | default_flags | public_flags);

// Final functions
returned += queryFunctions(FinalInTargetLangFunctions | NonStaticFunctions | default_flags | public_flags);

// Virtual functions
returned += queryFunctions(VirtualInTargetLangFunctions | NonStaticFunctions | default_flags | public_flags);

// Static functions
returned += queryFunctions(StaticFunctions | default_flags | public_flags);

// Empty, private functions, since they aren't caught by the other ones
returned += queryFunctions(Empty | Invisible);

return returned;
}

AbstractMetaFunctionList AbstractMetaClass::virtualFunctions() const
{
const AbstractMetaFunctionList list = functionsInShellClass();

AbstractMetaFunctionList returned;
for (AbstractMetaFunction* f : list) {
if (!f->isFinalInCpp() || f->isVirtualSlot())
returned += f;
}

return returned;
}

AbstractMetaFunctionList AbstractMetaClass::nonVirtualShellFunctions() const
{
AbstractMetaFunctionList list = functionsInShellClass();
AbstractMetaFunctionList returned;
for (AbstractMetaFunction* f : list) {
if (f->isFinalInCpp() && !f->isVirtualSlot())
returned += f;
}

return returned;
}

/*******************************************************************************
* Returns a list of all functions that should be declared and implemented in
* the shell class which is generated as a wrapper on top of the actual C++ class
*/
AbstractMetaFunctionList AbstractMetaClass::functionsInShellClass() const
{
// Only functions and only protected and public functions
int default_flags = NormalFunctions | Visible | WasVisible | NotRemovedFromShell;

// All virtual functions
AbstractMetaFunctionList returned = queryFunctions(VirtualFunctions | default_flags);

// All functions explicitly set to be implemented by the shell class
// (mainly superclass functions that are hidden by other declarations)
returned += queryFunctions(ForcedShellFunctions | default_flags);

// All functions explicitly set to be virtual slots
returned += queryFunctions(VirtualSlots | default_flags);

return returned;
}

/*******************************************************************************
* Returns a list of all functions that require a public override function to
* be generated in the shell class. This includes all functions that were originally
* protected in the superclass.
*/
AbstractMetaFunctionList AbstractMetaClass::publicOverrideFunctions() const
{
return queryFunctions(NormalFunctions | WasProtected | FinalInCppFunctions | NotRemovedFromTargetLang)
+ queryFunctions(Signals | WasProtected | FinalInCppFunctions | NotRemovedFromTargetLang);
}

AbstractMetaFunctionList AbstractMetaClass::virtualOverrideFunctions() const
{
return queryFunctions(NormalFunctions | NonEmptyFunctions | Visible | VirtualInCppFunctions | NotRemovedFromShell)
+ queryFunctions(Signals | NonEmptyFunctions | Visible | VirtualInCppFunctions | NotRemovedFromShell);
}

void AbstractMetaClass::sortFunctions()
{
std::sort(m_functions.begin(), m_functions.end(), function_sorter);
Expand Down Expand Up @@ -1063,16 +966,6 @@ void AbstractMetaClass::setFunctions(const AbstractMetaFunctionList& functions)
#endif
}

bool AbstractMetaClass::hasFieldAccessors() const
{
for (const AbstractMetaField* field : fields()) {
if (field->getter() || field->setter())
return true;
}

return false;
}

bool AbstractMetaClass::hasDefaultToStringFunction() const
{
for (AbstractMetaFunction* f : queryFunctionsByName("toString")) {
Expand Down Expand Up @@ -1137,25 +1030,13 @@ bool AbstractMetaClass::hasFunction(const QString& str) const
return false;
}

/* Returns true if this class has one or more functions that are
protected. If a class has protected members we need to generate a
shell class with public accessors to the protected functions, so
they can be called from the native functions.
*/
bool AbstractMetaClass::hasProtectedFunctions() const
{
for (AbstractMetaFunction* func : m_functions) {
if (func->isProtected())
return true;
}
return false;
}

bool AbstractMetaClass::generateShellClass() const
{
return typeEntry()->shouldCreateShell()
// require that classes that get a shell have a virtual destructor
// (required for proper working of derived class)
&& (m_force_shell_class
|| (!isFinal() && (hasVirtualFunctions() || hasProtectedFunctions() || hasFieldAccessors())));
|| (!isFinal() && hasVirtualDestructor() && (hasVirtualFunctions() || hasProtectedConstructors())));
}

QPropertySpec* AbstractMetaClass::propertySpecForRead(const QString& name) const
Expand Down Expand Up @@ -1312,7 +1193,12 @@ const AbstractMetaFunction* AbstractMetaField::getter() const

bool AbstractMetaClass::hasConstructors() const
{
return queryFunctions(Constructors).size() != 0;
return queryFunctions(Constructors).size() > 0;
}

bool AbstractMetaClass::hasProtectedConstructors() const
{
return queryFunctions(Constructors | WasProtected).size() > 0;
}

void AbstractMetaClass::addDefaultConstructor()
Expand Down Expand Up @@ -1472,16 +1358,6 @@ AbstractMetaFunctionList AbstractMetaClass::queryFunctions(uint query) const
return functions;
}

bool AbstractMetaClass::hasInconsistentFunctions() const
{
return cppInconsistentFunctions().size() > 0;
}

bool AbstractMetaClass::hasSignals() const
{
return cppSignalFunctions().size() > 0;
}

/**
* Adds the specified interface to this class by adding all the
* functions in the interface to this class.
Expand Down
36 changes: 1 addition & 35 deletions generator/abstractmetalang.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ class AbstractMetaClass : public AbstractMetaAttributes
bool hasSignal(const AbstractMetaFunction* f) const;

bool hasConstructors() const;
bool hasProtectedConstructors() const;

void addDefaultConstructor();

Expand All @@ -711,16 +712,6 @@ class AbstractMetaClass : public AbstractMetaAttributes
void setDestructorException(const QString& exception) { m_destructor_exception = exception; }
AbstractMetaFunctionList queryFunctionsByName(const QString& name) const;
AbstractMetaFunctionList queryFunctions(uint query) const;
inline AbstractMetaFunctionList allVirtualFunctions() const;
inline AbstractMetaFunctionList allFinalFunctions() const;
AbstractMetaFunctionList functionsInTargetLang() const;
AbstractMetaFunctionList functionsInShellClass() const;
inline AbstractMetaFunctionList cppInconsistentFunctions() const;
inline AbstractMetaFunctionList cppSignalFunctions() const;
AbstractMetaFunctionList publicOverrideFunctions() const;
AbstractMetaFunctionList virtualOverrideFunctions() const;
AbstractMetaFunctionList virtualFunctions() const;
AbstractMetaFunctionList nonVirtualShellFunctions() const;

AbstractMetaFieldList fields() const { return m_fields; }
void setFields(const AbstractMetaFieldList& fields) { m_fields = fields; }
Expand Down Expand Up @@ -760,22 +751,17 @@ class AbstractMetaClass : public AbstractMetaAttributes
bool isQtNamespace() const { return isNamespace() && name() == "Qt"; }
QString qualifiedCppName() const { return m_type_entry->qualifiedCppName(); }

bool hasInconsistentFunctions() const;
bool hasSignals() const;
bool inheritsFrom(const AbstractMetaClass* other) const;

void setForceShellClass(bool on) { m_force_shell_class = on; }
bool generateShellClass() const;

bool hasVirtualSlots() const { return m_has_virtual_slots; }
bool hasVirtualFunctions() const { return !isFinal() && m_has_virtuals; }
bool hasProtectedFunctions() const;

QList<TypeEntry*> templateArguments() const { return m_template_args; }
void setTemplateArguments(const QList<TypeEntry*>& args) { m_template_args = args; }

bool hasFieldAccessors() const;

// only valid during metajavabuilder's run
QStringList baseClassNames() const { return m_base_class_names; }
void setBaseClassNames(const QStringList& names) { m_base_class_names = names; }
Expand Down Expand Up @@ -931,24 +917,4 @@ class QPropertySpec
int m_index {-1};
};

inline AbstractMetaFunctionList AbstractMetaClass::allVirtualFunctions() const
{
return queryFunctions(VirtualFunctions | NotRemovedFromTargetLang);
}

inline AbstractMetaFunctionList AbstractMetaClass::allFinalFunctions() const
{
return queryFunctions(FinalInTargetLangFunctions | FinalInCppFunctions | NotRemovedFromTargetLang);
}

inline AbstractMetaFunctionList AbstractMetaClass::cppInconsistentFunctions() const
{
return queryFunctions(Inconsistent | NormalFunctions | Visible | NotRemovedFromTargetLang);
}

inline AbstractMetaFunctionList AbstractMetaClass::cppSignalFunctions() const
{
return queryFunctions(Signals | Visible | NotRemovedFromTargetLang);
}

#endif // ABSTRACTMETALANG_H
10 changes: 5 additions & 5 deletions generator/shellheadergenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ void ShellHeaderGenerator::write(QTextStream& s, const AbstractMetaClass* meta_c
}

// Shell-------------------------------------------------------------------
if (meta_class->generateShellClass() && !ctors.isEmpty()) {
bool generateShell = meta_class->generateShellClass() && !ctors.isEmpty();
if (generateShell) {

AbstractMetaFunctionList virtualsForShell = getVirtualFunctionsForShell(meta_class);

Expand Down Expand Up @@ -348,12 +349,12 @@ void ShellHeaderGenerator::write(QTextStream& s, const AbstractMetaClass* meta_c
}
}
s << "public Q_SLOTS:" << Qt::endl;
if (meta_class->generateShellClass() || !meta_class->isAbstract()) {
if (generateShell || !meta_class->isAbstract()) {

bool copyConstructorSeen = false;
bool defaultConstructorSeen = false;
for (const AbstractMetaFunction* fun : ctors) {
if (fun->isAbstract() || (!meta_class->generateShellClass() && !fun->isPublic())) {
if (fun->isAbstract() || (!generateShell && !fun->isPublic())) {
continue;
}

Expand All @@ -373,8 +374,7 @@ void ShellHeaderGenerator::write(QTextStream& s, const AbstractMetaClass* meta_c
if (meta_class->typeEntry()->isValue() && !copyConstructorSeen && defaultConstructorSeen
&& !meta_class->typeEntry()->hasNoCopy())
{
QString className =
meta_class->generateShellClass() ? shellClassName(meta_class) : meta_class->qualifiedCppName();
QString className = generateShell ? shellClassName(meta_class) : meta_class->qualifiedCppName();
s << meta_class->qualifiedCppName() << "* new_" << meta_class->name() << "(const "
<< meta_class->qualifiedCppName() << "& other) {" << Qt::endl;
s << className << "* a = new " << className << "();" << Qt::endl;
Expand Down
8 changes: 3 additions & 5 deletions generator/shellimplgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ void ShellImplGenerator::write(QTextStream& s, const AbstractMetaClass* meta_cla
}
}

if (meta_class->generateShellClass() || !meta_class->isAbstract()) {
if (generateShell || !meta_class->isAbstract()) {

// write constructors
for (const AbstractMetaFunction* ctor : ctors) {
if (ctor->isAbstract() || (!meta_class->generateShellClass() && !ctor->isPublic())) {
if (ctor->isAbstract() || (!generateShell && !ctor->isPublic())) {
continue;
}

Expand All @@ -241,8 +241,7 @@ void ShellImplGenerator::write(QTextStream& s, const AbstractMetaClass* meta_cla
writeFunctionSignature(s, ctor, 0, "new_", Option(AddOwnershipTemplates | ShowStatic));
s << Qt::endl;
s << "{ " << Qt::endl;
s << "return new "
<< (meta_class->generateShellClass() ? shellClassName(meta_class) : meta_class->qualifiedCppName()) << "(";
s << "return new " << (generateShell ? shellClassName(meta_class) : meta_class->qualifiedCppName()) << "(";
AbstractMetaArgumentList args = ctor->arguments();
for (int i = 0; i < args.size(); ++i) {
if (i > 0)
Expand Down Expand Up @@ -333,7 +332,6 @@ void ShellImplGenerator::write(QTextStream& s, const AbstractMetaClass* meta_cla
}
} else {
if (fun->wasProtected()) {
//|| (fun->isVirtual() && meta_class->typeEntry()->shouldCreatePromoter())) {
s << " ((" << promoterClassName(meta_class) << "*)theWrappedObject)->promoted_";
} else {
s << " theWrappedObject->";
Expand Down
Loading