aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/apiextractor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/ApiExtractor/apiextractor.cpp')
-rw-r--r--sources/shiboken2/ApiExtractor/apiextractor.cpp82
1 files changed, 42 insertions, 40 deletions
diff --git a/sources/shiboken2/ApiExtractor/apiextractor.cpp b/sources/shiboken2/ApiExtractor/apiextractor.cpp
index 78fa9e313..aa552cdd3 100644
--- a/sources/shiboken2/ApiExtractor/apiextractor.cpp
+++ b/sources/shiboken2/ApiExtractor/apiextractor.cpp
@@ -82,9 +82,9 @@ void ApiExtractor::setLogDirectory(const QString& logDir)
m_logDirectory = logDir;
}
-void ApiExtractor::setCppFileName(const QString& cppFileName)
+void ApiExtractor::setCppFileNames(const QFileInfoList &cppFileName)
{
- m_cppFileName = cppFileName;
+ m_cppFileNames = cppFileName;
}
void ApiExtractor::setTypeSystem(const QString& typeSystemFileName)
@@ -92,11 +92,6 @@ void ApiExtractor::setTypeSystem(const QString& typeSystemFileName)
m_typeSystemFileName = typeSystemFileName;
}
-void ApiExtractor::setDebugLevel(ReportHandler::DebugLevel debugLevel)
-{
- ReportHandler::setDebugLevel(debugLevel);
-}
-
void ApiExtractor::setSkipDeprecated(bool value)
{
m_skipDeprecated = value;
@@ -126,25 +121,25 @@ void ApiExtractor::setDropTypeEntries(QString dropEntries)
TypeDatabase::instance()->setDropTypeEntries(entries);
}
-AbstractMetaEnumList ApiExtractor::globalEnums() const
+const AbstractMetaEnumList &ApiExtractor::globalEnums() const
{
Q_ASSERT(m_builder);
return m_builder->globalEnums();
}
-AbstractMetaFunctionList ApiExtractor::globalFunctions() const
+const AbstractMetaFunctionList &ApiExtractor::globalFunctions() const
{
Q_ASSERT(m_builder);
return m_builder->globalFunctions();
}
-AbstractMetaClassList ApiExtractor::classes() const
+const AbstractMetaClassList &ApiExtractor::classes() const
{
Q_ASSERT(m_builder);
return m_builder->classes();
}
-AbstractMetaClassList ApiExtractor::smartPointers() const
+const AbstractMetaClassList &ApiExtractor::smartPointers() const
{
Q_ASSERT(m_builder);
return m_builder->smartPointers();
@@ -166,24 +161,6 @@ ContainerTypeEntryList ApiExtractor::containerTypes() const
return TypeDatabase::instance()->containerTypes();
}
-static const AbstractMetaEnum* findEnumOnClasses(AbstractMetaClassList metaClasses, const EnumTypeEntry* typeEntry)
-{
- const AbstractMetaEnum *result = nullptr;
- for (const AbstractMetaClass* metaClass : qAsConst(metaClasses)) {
- const AbstractMetaEnumList &enums = metaClass->enums();
- for (const AbstractMetaEnum *metaEnum : enums) {
- if (metaEnum->typeEntry() == typeEntry) {
- result = metaEnum;
- break;
- }
- }
- if (result)
- break;
- result = findEnumOnClasses(metaClass->innerClasses(), typeEntry);
- }
- return result;
-}
-
const AbstractMetaEnum* ApiExtractor::findAbstractMetaEnum(const TypeEntry* typeEntry) const
{
return m_builder->findEnum(typeEntry);
@@ -195,7 +172,20 @@ int ApiExtractor::classCount() const
return m_builder->classes().count();
}
-bool ApiExtractor::run()
+// Add defines required for parsing Qt code headers
+static void addPySideExtensions(QByteArrayList *a)
+{
+ // Make "signals:", "slots:" visible as access specifiers
+ a->append(QByteArrayLiteral("-DQT_ANNOTATE_ACCESS_SPECIFIER(a)=__attribute__((annotate(#a)))"));
+
+ // Q_PROPERTY is defined as class annotation which does not work since a
+ // sequence of properties will to expand to a sequence of annotations
+ // annotating nothing, causing clang to complain. Instead, define it away in a
+ // static assert with the stringified argument in a ','-operator (cf qdoc).
+ a->append(QByteArrayLiteral("-DQT_ANNOTATE_CLASS(type,...)=static_assert(sizeof(#__VA_ARGS__),#type);"));
+}
+
+bool ApiExtractor::run(bool usePySideExtensions)
{
if (m_builder)
return false;
@@ -205,8 +195,9 @@ bool ApiExtractor::run()
return false;
}
- const QString pattern = QDir::tempPath() + QLatin1Char('/') +
- QFileInfo(m_cppFileName).baseName() + QStringLiteral("_XXXXXX.hpp");
+ const QString pattern = QDir::tempPath() + QLatin1Char('/')
+ + m_cppFileNames.constFirst().baseName()
+ + QStringLiteral("_XXXXXX.hpp");
QTemporaryFile ppFile(pattern);
bool autoRemove = !qEnvironmentVariableIsSet("KEEP_TEMP_FILES");
// make sure that a tempfile can be written
@@ -215,14 +206,16 @@ bool ApiExtractor::run()
<< ": " << qPrintable(ppFile.errorString()) << '\n';
return false;
}
- ppFile.write("#include \"");
- ppFile.write(m_cppFileName.toLocal8Bit());
- ppFile.write("\"\n");
+ for (const auto &cppFileName : qAsConst(m_cppFileNames)) {
+ ppFile.write("#include \"");
+ ppFile.write(cppFileName.absoluteFilePath().toLocal8Bit());
+ ppFile.write("\"\n");
+ }
const QString preprocessedCppFileName = ppFile.fileName();
ppFile.close();
m_builder = new AbstractMetaBuilder;
m_builder->setLogDirectory(m_logDirectory);
- m_builder->setGlobalHeader(m_cppFileName);
+ m_builder->setGlobalHeaders(m_cppFileNames);
m_builder->setSkipDeprecated(m_skipDeprecated);
m_builder->setHeaderPaths(m_includePaths);
QByteArrayList arguments;
@@ -230,8 +223,15 @@ bool ApiExtractor::run()
for (const HeaderPath &headerPath : qAsConst(m_includePaths))
arguments.append(HeaderPath::includeOption(headerPath));
arguments.append(QFile::encodeName(preprocessedCppFileName));
- qCDebug(lcShiboken) << __FUNCTION__ << arguments
- << "level=" << int(m_languageLevel);
+ if (ReportHandler::isDebug(ReportHandler::SparseDebug)) {
+ qCInfo(lcShiboken).noquote().nospace()
+ << "clang language level: " << int(m_languageLevel)
+ << "\nclang arguments: " << arguments;
+ }
+
+ if (usePySideExtensions)
+ addPySideExtensions(&arguments);
+
const bool result = m_builder->build(arguments, m_languageLevel);
if (!result)
autoRemove = false;
@@ -273,8 +273,10 @@ QDebug operator<<(QDebug d, const ApiExtractor &ae)
QDebugStateSaver saver(d);
d.noquote();
d.nospace();
- d << "ApiExtractor(typeSystem=\"" << ae.typeSystem() << "\", cppFileName=\""
- << ae.cppFileName() << ", ";
+ if (ReportHandler::debugLevel() >= ReportHandler::FullDebug)
+ d.setVerbosity(3); // Trigger verbose output of AbstractMetaClass
+ d << "ApiExtractor(typeSystem=\"" << ae.typeSystem() << "\", cppFileNames=\""
+ << ae.cppFileNames() << ", ";
ae.m_builder->formatDebug(d);
d << ')';
return d;