aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-10-19 17:10:15 -0300
committerLuciano Miguel Wolf <luciano.wolf@indt.org.br>2009-10-21 16:34:20 -0300
commitac27d38d44bef714b08d8b675ae105ac41047bfa (patch)
treede5c420ebce75d8a1e9ecfab6e29024b0ed07f2c
parentfa5c2fa99cd0dae464f3cfa6686e2a31f2684687 (diff)
improved AddedFunction struct with more informations;
extended ComplexTypeEntry with a list of AddedFunctions
-rw-r--r--typesystem.cpp45
-rw-r--r--typesystem.h49
2 files changed, 89 insertions, 5 deletions
diff --git a/typesystem.cpp b/typesystem.cpp
index bed0b3512..b58c42152 100644
--- a/typesystem.cpp
+++ b/typesystem.cpp
@@ -199,6 +199,7 @@ private:
EnumTypeEntry *m_currentEnum;
CodeSnipList m_codeSnips;
+ AddedFunctionList m_addedFunctions;
FunctionModificationList m_functionMods;
FieldModificationList m_fieldMods;
DocModificationList m_docModifications;
@@ -262,6 +263,7 @@ bool Handler::endElement(const QString &, const QString &localName, const QStrin
case StackElement::InterfaceTypeEntry:
case StackElement::NamespaceTypeEntry: {
ComplexTypeEntry *centry = static_cast<ComplexTypeEntry *>(m_current->entry);
+ centry->setAddedFunctions(m_addedFunctions);
centry->setFunctionModifications(m_functionMods);
centry->setFieldModifications(m_fieldMods);
centry->setCodeSnips(m_codeSnips);
@@ -272,6 +274,7 @@ bool Handler::endElement(const QString &, const QString &localName, const QStrin
centry->designatedInterface()->setFunctionModifications(m_functionMods);
}
m_codeSnips = CodeSnipList();
+ m_addedFunctions = AddedFunctionList();
m_functionMods = FunctionModificationList();
m_fieldMods = FieldModificationList();
m_docModifications = DocModificationList();
@@ -348,6 +351,9 @@ bool Handler::characters(const QString &ch)
m_functionMods.last().snips.last().addCode(ch);
m_functionMods.last().modifiers |= FunctionModification::CodeInjection;
break;
+ case StackElement::AddFunction:
+ m_addedFunctions.last().codeSnips().last().addCode(ch);
+ break;
case StackElement::NamespaceTypeEntry:
case StackElement::ObjectTypeEntry:
case StackElement::ValueTypeEntry:
@@ -826,6 +832,11 @@ bool Handler::startElement(const QString &, const QString &n,
attributes["class"] = "target";
attributes["owner"] = "";
break;
+ case StackElement::AddFunction:
+ attributes["signature"] = QString();
+ attributes["return-type"] = QString("void");
+ attributes["access"] = QString("public");
+ break;
case StackElement::ModifyFunction:
attributes["signature"] = QString();
attributes["access"] = QString();
@@ -1256,6 +1267,40 @@ bool Handler::startElement(const QString &, const QString &n,
m_fieldMods << fm;
}
break;
+ case StackElement::AddFunction: {
+ if (!(topElement.type & StackElement::ComplexTypeEntryMask)) {
+ m_error = QString::fromLatin1("Add function requires complex type as parent"
+ ", was=%1").arg(topElement.type, 0, 16);
+ return false;
+ }
+ QString signature = attributes["signature"];
+
+ signature = QMetaObject::normalizedSignature(signature.toLocal8Bit().constData());
+ if (signature.isEmpty()) {
+ m_error = "No signature for the added function";
+ return false;
+ }
+
+ AddedFunction func(signature);
+ m_currentSignature = signature;
+
+ QString access = attributes["access"].toLower();
+ if (!access.isEmpty()) {
+ if (access == QLatin1String("private"))
+ func.setAccess(AddedFunction::Private);
+ else if (access == QLatin1String("protected"))
+ func.setAccess(AddedFunction::Protected);
+ else if (access == QLatin1String("public"))
+ func.setAccess(AddedFunction::Public);
+ else {
+ m_error = QString::fromLatin1("Bad access type '%1'").arg(access);
+ return false;
+ }
+ }
+
+ m_addedFunctions << func;
+ }
+ break;
case StackElement::ModifyFunction: {
if (!(topElement.type & StackElement::ComplexTypeEntryMask)) {
m_error = QString::fromLatin1("Modify function requires complex type as parent"
diff --git a/typesystem.h b/typesystem.h
index 80e5bfdc1..8a8f7277b 100644
--- a/typesystem.h
+++ b/typesystem.h
@@ -35,6 +35,7 @@ class Indentor;
class AbstractMetaType;
class QTextStream;
+class TypeEntry;
class EnumTypeEntry;
class FlagsTypeEntry;
@@ -443,13 +444,39 @@ typedef QList<FieldModification> FieldModificationList;
struct AddedFunction
{
- AddedFunction(QString signature, TypeEntry* returnType);
+
+ enum Access {
+ Private = 0x1,
+ Protected = 0x2,
+ Public = 0x3
+ };
+
+ // ArgumentPair.first: argument name
+ // ArgumentPair.second: default value
+ typedef QPair<QString, QString> ArgumentPair;
+
+ AddedFunction(QString signature, TypeEntry* returnType = 0);
QString name() const
{
return m_name;
}
+ void setAccess(Access access)
+ {
+ m_access = access;
+ }
+
+ Access access() const
+ {
+ return m_access;
+ }
+
+ void setReturnType(TypeEntry* returnType)
+ {
+ m_returnType = returnType;
+ }
+
TypeEntry* returnType() const
{
return m_returnType;
@@ -475,12 +502,9 @@ struct AddedFunction
return m_arguments;
}
- // ArgumentPair.first: argument name
- // ArgumentPair.second: default value
- typedef QPair<QString, QString> ArgumentPair;
-
private:
QString m_name;
+ Access m_access;
QList<QPair<ArgumentPair, const TypeEntry*> > m_arguments;
TypeEntry* m_returnType;
CodeSnipList m_codeSnips;
@@ -1289,6 +1313,7 @@ public:
ComplexTypeEntry *centry = new ComplexTypeEntry(name(), type());
centry->setInclude(include());
centry->setExtraIncludes(extraIncludes());
+ centry->setAddedFunctions(addedFunctions());
centry->setFunctionModifications(functionModifications());
centry->setFieldModifications(fieldModifications());
centry->setQObject(isQObject());
@@ -1338,6 +1363,19 @@ public:
}
FunctionModificationList functionModifications(const QString &signature) const;
+ AddedFunctionList addedFunctions() const
+ {
+ return m_addedFunctions;
+ }
+ void setAddedFunctions(const AddedFunctionList &addedFunctions)
+ {
+ m_addedFunctions = addedFunctions;
+ }
+ void addNewFunction(const AddedFunction &addedFunction)
+ {
+ m_addedFunctions << addedFunction;
+ }
+
FieldModification fieldModification(const QString &name) const;
void setFieldModifications(const FieldModificationList &mods)
{
@@ -1467,6 +1505,7 @@ public:
private:
+ AddedFunctionList m_addedFunctions;
FunctionModificationList m_functionMods;
FieldModificationList m_fieldMods;
QString m_package;