aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-11-14 11:28:14 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-12-05 15:49:20 +0100
commit96d8bc01639c3ef83d16a45428758aa0e4420165 (patch)
tree907068ddb4e2651b43a29ae81e559211a4c8048f /sources
parentd0fbcc90bd02090f921313dafecba20065fb2eb5 (diff)
shiboken: Add a way of specifying system includes to be parsed
Task-number: PYSIDE-454 Change-Id: I9302cf74544315875a65bc09b75741c7fe6399e8 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp1
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp12
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h2
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.cpp5
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.h4
-rw-r--r--sources/shiboken2/ApiExtractor/typesystemparser.cpp21
-rw-r--r--sources/shiboken2/ApiExtractor/typesystemparser.h2
-rw-r--r--sources/shiboken2/doc/typesystem_specifying_types.rst15
8 files changed, 61 insertions, 1 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
index 70728b6a2..443471836 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
@@ -410,6 +410,7 @@ FileModelItem AbstractMetaBuilderPrivate::buildDom(QByteArrayList arguments,
unsigned clangFlags)
{
clang::Builder builder;
+ builder.setSystemIncludes(TypeDatabase::instance()->systemIncludes());
if (level == LanguageLevel::Default)
level = clang::emulatedCompilerLanguageLevel();
arguments.prepend(QByteArrayLiteral("-std=")
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
index edb7a58f7..78f34c87f 100644
--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
@@ -222,6 +222,7 @@ public:
FunctionModelItem m_currentFunction;
ArgumentModelItem m_currentArgument;
VariableModelItem m_currentField;
+ QByteArrayList m_systemIncludes;
int m_anonymousEnumCount = 0;
CodeModel::FunctionType m_currentFunctionType = CodeModel::Normal;
@@ -720,6 +721,12 @@ bool BuilderPrivate::visitHeader(const char *cFileName) const
return true;
}
#endif // Q_OS_MACOS
+ if (baseName) {
+ for (const auto &systemInclude : m_systemIncludes) {
+ if (systemInclude == baseName)
+ return true;
+ }
+ }
return false;
}
@@ -742,6 +749,11 @@ bool Builder::visitLocation(const CXSourceLocation &location) const
return result;
}
+void Builder::setSystemIncludes(const QByteArrayList &systemIncludes)
+{
+ d->m_systemIncludes = systemIncludes;
+}
+
FileModelItem Builder::dom() const
{
Q_ASSERT(!d->m_scopeStack.isEmpty());
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h
index fa79acb2a..dc37dff0f 100644
--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h
+++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h
@@ -44,6 +44,8 @@ public:
Builder();
~Builder();
+ void setSystemIncludes(const QByteArrayList &systemIncludes);
+
bool visitLocation(const CXSourceLocation &location) const override;
StartTokenResult startToken(const CXCursor &cursor) override;
diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp
index dd1ed35c3..effb8b6a7 100644
--- a/sources/shiboken2/ApiExtractor/typedatabase.cpp
+++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp
@@ -144,6 +144,11 @@ IncludeList TypeDatabase::extraIncludes(const QString& className) const
return typeEntry ? typeEntry->extraIncludes() : IncludeList();
}
+void TypeDatabase::addSystemInclude(const QString &name)
+{
+ m_systemIncludes.append(name.toUtf8());
+}
+
ContainerTypeEntry* TypeDatabase::findContainerType(const QString &name) const
{
QString template_name = name;
diff --git a/sources/shiboken2/ApiExtractor/typedatabase.h b/sources/shiboken2/ApiExtractor/typedatabase.h
index 334e88a14..6d800a3f0 100644
--- a/sources/shiboken2/ApiExtractor/typedatabase.h
+++ b/sources/shiboken2/ApiExtractor/typedatabase.h
@@ -84,6 +84,9 @@ public:
IncludeList extraIncludes(const QString &className) const;
+ const QByteArrayList &systemIncludes() const { return m_systemIncludes; }
+ void addSystemInclude(const QString &name);
+
PrimitiveTypeEntry *findPrimitiveType(const QString &name) const;
ComplexTypeEntry *findComplexType(const QString &name) const;
ObjectTypeEntry *findObjectType(const QString &name) const;
@@ -189,6 +192,7 @@ private:
QVector<TypeRejection> m_rejections;
QStringList m_dropTypeEntries;
+ QByteArrayList m_systemIncludes;
};
#ifndef QT_NO_DEBUG_STREAM
diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
index 77c36df9a..a5d28c2e2 100644
--- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
@@ -61,6 +61,7 @@ static inline QString deleteInMainThreadAttribute() { return QStringLiteral("del
static inline QString deprecatedAttribute() { return QStringLiteral("deprecated"); }
static inline QString exceptionHandlingAttribute() { return QStringLiteral("exception-handling"); }
static inline QString extensibleAttribute() { return QStringLiteral("extensible"); }
+static inline QString fileNameAttribute() { return QStringLiteral("file-name"); }
static inline QString flagsAttribute() { return QStringLiteral("flags"); }
static inline QString forceAbstractAttribute() { return QStringLiteral("force-abstract"); }
static inline QString forceIntegerAttribute() { return QStringLiteral("force-integer"); }
@@ -382,6 +383,7 @@ ENUM_LOOKUP_BEGIN(StackElement::ElementType, Qt::CaseInsensitive,
{u"replace-type", StackElement::ReplaceType},
{u"smart-pointer-type", StackElement::SmartPointerTypeEntry},
{u"suppress-warning", StackElement::SuppressedWarning},
+ {u"system-include", StackElement::SystemInclude},
{u"target-to-native", StackElement::TargetToNative},
{u"template", StackElement::Template},
{u"typedef-type", StackElement::TypedefTypeEntry},
@@ -2536,7 +2538,7 @@ bool TypeSystemParser::parseInclude(const QXmlStreamReader &,
QString location;
for (int i = attributes->size() - 1; i >= 0; --i) {
const QStringRef name = attributes->at(i).qualifiedName();
- if (name == QLatin1String("file-name"))
+ if (name == fileNameAttribute())
fileName = attributes->takeAt(i).value().toString();
else if (name == locationAttribute())
location = attributes->takeAt(i).value().toString();
@@ -2564,6 +2566,18 @@ bool TypeSystemParser::parseInclude(const QXmlStreamReader &,
return true;
}
+bool TypeSystemParser::parseSystemInclude(const QXmlStreamReader &,
+ QXmlStreamAttributes *attributes)
+{
+ const int index = indexOfAttribute(*attributes, fileNameAttribute());
+ if (index == -1) {
+ m_error = msgMissingAttribute(fileNameAttribute());
+ return false;
+ }
+ TypeDatabase::instance()->addSystemInclude(attributes->takeAt(index).value().toString());
+ return true;
+}
+
TemplateInstance *
TypeSystemParser::parseTemplateInstanceEnum(const QXmlStreamReader &,
const StackElement &topElement,
@@ -2849,6 +2863,7 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader)
|| element->type == StackElement::LoadTypesystem
|| element->type == StackElement::InjectCode
|| element->type == StackElement::ExtraIncludes
+ || element->type == StackElement::SystemInclude
|| element->type == StackElement::ConversionRule
|| element->type == StackElement::AddFunction
|| element->type == StackElement::Template;
@@ -3001,6 +3016,10 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader)
if (!addRejection(m_database, &attributes, &m_error))
return false;
break;
+ case StackElement::SystemInclude:
+ if (!parseSystemInclude(reader, &attributes))
+ return false;
+ break;
case StackElement::Template: {
const int nameIndex = indexOfAttribute(attributes, nameAttribute());
if (nameIndex == -1) {
diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.h b/sources/shiboken2/ApiExtractor/typesystemparser.h
index d3ea54fc6..f56e8e0fc 100644
--- a/sources/shiboken2/ApiExtractor/typesystemparser.h
+++ b/sources/shiboken2/ApiExtractor/typesystemparser.h
@@ -86,6 +86,7 @@ class StackElement
NativeToTarget = 0x1100,
TargetToNative = 0x1200,
AddConversion = 0x1300,
+ SystemInclude = 0x1400,
SimpleMask = 0x3f00,
// Code snip tags (0x1000, 0x2000, ... , 0xf000)
@@ -247,6 +248,7 @@ private:
StackElement* element, QXmlStreamAttributes *);
bool parseInclude(const QXmlStreamReader &, const StackElement &topElement,
TypeEntry *entry, QXmlStreamAttributes *);
+ bool parseSystemInclude(const QXmlStreamReader &, QXmlStreamAttributes *);
TemplateInstance
*parseTemplateInstanceEnum(const QXmlStreamReader &, const StackElement &topElement,
QXmlStreamAttributes *);
diff --git a/sources/shiboken2/doc/typesystem_specifying_types.rst b/sources/shiboken2/doc/typesystem_specifying_types.rst
index 2eb78335a..fac801cff 100644
--- a/sources/shiboken2/doc/typesystem_specifying_types.rst
+++ b/sources/shiboken2/doc/typesystem_specifying_types.rst
@@ -471,3 +471,18 @@ function
The function tag has two *optional* attributes: **since**, whose value is used to specify
the API version of this function, and **rename**, to modify the function name.
+.. _system_include:
+
+system-include
+^^^^^^^^^^^^^^
+
+ The optional **system-include** specifies the name of a system include
+ file to be parsed. Normally, include files considered to be system
+ include files are skipped by the C++ code parser. Its primary use case
+ is exposing classes from the STL library.
+
+ .. code-block:: xml
+
+ <typesystem>
+ <system-include file-name="memory"/>
+ </typesystem>