Skip to content

Commit

Permalink
Handle constexpr, auto (#126)
Browse files Browse the repository at this point in the history
These changes use the new and existing support inside the parser to
handle constexpr in Qt6 files and to ignore (with a warning) 'auto'
functions.
  • Loading branch information
jbowler authored and mrbean-bremen committed Oct 29, 2023
1 parent 8db0ff4 commit a4cafc5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
17 changes: 17 additions & 0 deletions generator/abstractmetabuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,19 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
return 0;
}

if (function_item->isAuto()) {
/*TODO: it might work just to output 'auto', but this would require
* understanding what AbstractMetabuild::translateType() does and
* changing it. auto is only used once anyway.
*/
ReportHandler::warning(QString("%1: skipping auto function type '%2'")
.arg(function_name)
.arg(function_item->type().toString()));
m_rejected_functions[class_name + "::" + function_name + " " + function_item->type().toString()] =
UnmatchedReturnType;
return 0;
}

QString cast_type;

if (function_name.startsWith("operator")) {
Expand All @@ -1504,6 +1517,8 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu

AbstractMetaFunction *meta_function = createMetaFunction();
meta_function->setConstant(function_item->isConstant());
meta_function->setConstexpr(function_item->isConstexpr());
meta_function->setAuto(function_item->isAuto());
meta_function->setException(function_item->exception());

ReportHandler::debugMedium(QString(" - %2()").arg(function_name));
Expand Down Expand Up @@ -1707,10 +1722,12 @@ AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, boo
//newInfo.setArguments(typei.arguments());
newInfo.setIndirections(typei.indirections());
newInfo.setConstant(typei.isConstant());
newInfo.setConstexpr(typei.isConstexpr());
newInfo.setFunctionPointer(typei.isFunctionPointer());
newInfo.setQualifiedName(typei.qualifiedName());
newInfo.setReference(typei.isReference());
newInfo.setVolatile(typei.isVolatile());
newInfo.setMutable(typei.isMutable());

AbstractMetaType *elementType = translateType(newInfo, ok);
if (!(*ok))
Expand Down
6 changes: 6 additions & 0 deletions generator/abstractmetalang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ AbstractMetaFunction *AbstractMetaFunction::copy() const
if (type())
cpy->setType(type()->copy());
cpy->setConstant(isConstant());
cpy->setConstexpr(isConstexpr());
cpy->setAuto(isAuto());
cpy->setException(exception());
cpy->setOriginalAttributes(originalAttributes());

Expand Down Expand Up @@ -366,6 +368,8 @@ QString AbstractMetaFunction::signature() const

if (isConstant())
s += " const";
if (isConstexpr())
s += " constexpr";

return s;
}
Expand Down Expand Up @@ -657,6 +661,8 @@ QString AbstractMetaFunction::minimalSignature() const
minimalSignature += ")";
if (isConstant())
minimalSignature += "const";
if (isConstexpr())
minimalSignature += "constexpr";

minimalSignature = TypeSystem::normalizedSignature(minimalSignature.toLocal8Bit().constData());
m_cached_minimal_signature = minimalSignature;
Expand Down
9 changes: 9 additions & 0 deletions generator/abstractmetalang.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class AbstractMetaFunction : public AbstractMetaAttributes

AbstractMetaFunction() :
m_constant(false),
m_constexpr(false),
m_invalid(false)
{
}
Expand Down Expand Up @@ -487,6 +488,12 @@ class AbstractMetaFunction : public AbstractMetaAttributes
bool isConstant() const { return m_constant; }
void setConstant(bool constant) { m_constant = constant; }

bool isConstexpr() const { return m_constexpr; }
void setConstexpr(bool constant) { m_constexpr = constant; }

bool isAuto() const { return m_auto; }
void setAuto(bool isAuto) { m_auto = isAuto; }

QString exception() const { return m_exception; }
void setException(const QString &exception) { m_exception = exception; }
QString toString() const { return m_name; }
Expand Down Expand Up @@ -550,6 +557,8 @@ class AbstractMetaFunction : public AbstractMetaAttributes
AbstractMetaArgumentList m_arguments;
QString m_exception;
uint m_constant : 1;
uint m_constexpr : 1;
uint m_auto : 1;
uint m_invalid : 1;
};

Expand Down

0 comments on commit a4cafc5

Please sign in to comment.