aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-02-16 08:14:45 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-09 19:10:15 -0300
commiteab5d72e3f7727f5726fa49267985cfcbd8e2c07 (patch)
tree67040918dc9a23e45b598ffbfd7a13bfb31bf4ac
parentf66bede561b7e1b282c835395f14f08437c407f8 (diff)
Type system parser has now the ability to ignore entries as demanded by the user.
The entries that could be dropped are: * Object and Value types * Global functions * Namespaces * Enums The entry name must be fully qualified with scope items separated by a dot (.) and beginning with the module/package name. Example: to drop the class "Bar" inside the namespace "Foo" from the "Pkg" package specify it with: "Pkg.Foo.Bar". TODO: The parser will later complain that dropped entries found on the headers are not found in the type system. That's obviously incorrect, but to fix it all the type entries should store the name of the package from where the came. And that's a needed improvement!
-rw-r--r--typedatabase.cpp11
-rw-r--r--typedatabase.h15
-rw-r--r--typesystem.cpp39
-rw-r--r--typesystem_p.h1
4 files changed, 66 insertions, 0 deletions
diff --git a/typedatabase.cpp b/typedatabase.cpp
index d97959820..4e0ab5b80 100644
--- a/typedatabase.cpp
+++ b/typedatabase.cpp
@@ -401,3 +401,14 @@ bool TypeDatabase::supportedApiVersion(double version) const
return version <= m_apiVersion;
}
+bool TypeDatabase::shouldDropTypeEntry(const QString& fullTypeName) const
+{
+ return m_dropTypeEntries.contains(fullTypeName);
+}
+
+void TypeDatabase::setDropTypeEntries(QStringList dropTypeEntries)
+{
+ m_dropTypeEntries = dropTypeEntries;
+ m_dropTypeEntries.sort();
+}
+
diff --git a/typedatabase.h b/typedatabase.h
index ff7ffc303..583813882 100644
--- a/typedatabase.h
+++ b/typedatabase.h
@@ -180,6 +180,20 @@ public:
bool supportedApiVersion(double version) const;
+ const QStringList& dropTypeEntries() const
+ {
+ return m_dropTypeEntries;
+ }
+
+ bool hasDroppedTypeEntries() const
+ {
+ return !m_dropTypeEntries.isEmpty();
+ }
+
+ bool shouldDropTypeEntry(const QString& fullTypeName) const;
+
+ void setDropTypeEntries(QStringList dropTypeEntries);
+
private:
bool m_suppressWarnings;
TypeEntryHash m_entries;
@@ -199,6 +213,7 @@ private:
QStringList m_rebuildClasses;
double m_apiVersion;
+ QStringList m_dropTypeEntries;
};
#endif
diff --git a/typesystem.cpp b/typesystem.cpp
index 93e81eaa9..3ccb33543 100644
--- a/typesystem.cpp
+++ b/typesystem.cpp
@@ -38,6 +38,7 @@ Handler::Handler(TypeDatabase* database, bool generate)
{
m_currentEnum = 0;
m_current = 0;
+ m_currentOptional = 0;
tagNames["rejection"] = StackElement::Rejection;
tagNames["primitive-type"] = StackElement::PrimitiveTypeEntry;
@@ -123,6 +124,13 @@ void Handler::fetchAttributeValues(const QString &name, const QXmlAttributes &at
bool Handler::endElement(const QString &, const QString &localName, const QString &)
{
+ if (m_currentOptional) {
+ m_current = m_currentOptional->parent;
+ delete m_currentOptional;
+ m_currentOptional = 0;
+ return true;
+ }
+
QString tagName = localName.toLower();
if (tagName == "import-file")
return true;
@@ -208,6 +216,9 @@ bool Handler::endElement(const QString &, const QString &localName, const QStrin
bool Handler::characters(const QString &ch)
{
+ if (m_currentOptional)
+ return true;
+
if (m_current->type == StackElement::Template) {
m_current->value.templateEntry->addCode(ch);
return true;
@@ -345,6 +356,21 @@ static bool convertRemovalAttribute(const QString& removalAttribute, Modificatio
return true;
}
+static void getNamePrefixRecursive(StackElement* element, QStringList& names)
+{
+ if (!element->parent || !element->parent->entry)
+ return;
+ getNamePrefixRecursive(element->parent, names);
+ names << element->parent->entry->name();
+}
+
+static QString getNamePrefix(StackElement* element)
+{
+ QStringList names;
+ getNamePrefixRecursive(element, names);
+ return names.join(".");
+}
+
bool Handler::startElement(const QString &, const QString &n,
const QString &, const QXmlAttributes &atts)
{
@@ -357,6 +383,9 @@ bool Handler::startElement(const QString &, const QString &n,
return false;
}
+ if (m_currentOptional)
+ return true;
+
StackElement* element = new StackElement(m_current);
element->type = tagNames[tagName];
@@ -428,6 +457,16 @@ bool Handler::startElement(const QString &, const QString &n,
QString name = attributes["name"];
double since = attributes["since"].toDouble();
+ if (m_database->hasDroppedTypeEntries()) {
+ QString identifier = getNamePrefix(element) + '.';
+ identifier += (element->type == StackElement::FunctionTypeEntry ? attributes["signature"] : name);
+ if (m_database->shouldDropTypeEntry(identifier)) {
+ m_currentOptional = element;
+ ReportHandler::debugSparse(QString("Optional type system entry '%1' was dropped from generation.").arg(identifier));
+ return true;
+ }
+ }
+
// The top level tag 'function' has only the 'signature' tag
// and we should extract the 'name' value from it.
if (element->type == StackElement::FunctionTypeEntry) {
diff --git a/typesystem_p.h b/typesystem_p.h
index e70a4fa4c..97859425a 100644
--- a/typesystem_p.h
+++ b/typesystem_p.h
@@ -149,6 +149,7 @@ private:
TypeDatabase* m_database;
StackElement* m_current;
+ StackElement* m_currentOptional;
QString m_defaultPackage;
QString m_defaultSuperclass;
QString m_error;