summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Arthur <mike@kdab.net>2010-03-19 12:20:23 +0100
committerKent Hansen <kent.hansen@nokia.com>2010-03-19 12:20:23 +0100
commitfa393b2f059caf9e44f0b2e02128112b13b33d0b (patch)
tree97b1a4739ad4265e927e5d5e49d8aa6fe1a776e3
parent0bc6b7c2547b618969f276eedcf6da6d772d9ab3 (diff)
Add support for throwing exceptions through the bindings to allow compilation
of code that already uses exceptions. Merge-request: 1853 Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
-rw-r--r--generator/abstractmetabuilder.cpp7
-rw-r--r--generator/abstractmetalang.cpp1
-rw-r--r--generator/abstractmetalang.h9
-rw-r--r--generator/asttoxml.cpp6
-rw-r--r--generator/parser/binder.cpp15
-rw-r--r--generator/parser/binder.h2
-rw-r--r--generator/parser/codemodel.cpp10
-rw-r--r--generator/parser/codemodel.h4
-rw-r--r--generator/shellgenerator.cpp3
-rw-r--r--generator/shellheadergenerator.cpp5
-rw-r--r--generator/shellimplgenerator.cpp6
11 files changed, 63 insertions, 5 deletions
diff --git a/generator/abstractmetabuilder.cpp b/generator/abstractmetabuilder.cpp
index db7ed9e..34fb4db 100644
--- a/generator/abstractmetabuilder.cpp
+++ b/generator/abstractmetabuilder.cpp
@@ -1328,8 +1328,10 @@ void AbstractMetaBuilder::traverseFunctions(ScopeModelItem scope_item, AbstractM
}
meta_class->addFunction(meta_function);
- } else if (meta_function->isDestructor() && !meta_function->isPublic()) {
- meta_class->setHasPublicDestructor(false);
+ } else if (meta_function->isDestructor()) {
+ meta_class->setDestructorException(meta_function->exception());
+ if (!meta_function->isPublic())
+ meta_class->setHasPublicDestructor(false);
}
}
}
@@ -1509,6 +1511,7 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
AbstractMetaFunction *meta_function = createMetaFunction();
meta_function->setConstant(function_item->isConstant());
+ meta_function->setException(function_item->exception());
ReportHandler::debugMedium(QString(" - %2()").arg(function_name));
diff --git a/generator/abstractmetalang.cpp b/generator/abstractmetalang.cpp
index 1b18a12..463227d 100644
--- a/generator/abstractmetalang.cpp
+++ b/generator/abstractmetalang.cpp
@@ -313,6 +313,7 @@ AbstractMetaFunction *AbstractMetaFunction::copy() const
if (type())
cpy->setType(type()->copy());
cpy->setConstant(isConstant());
+ cpy->setException(exception());
cpy->setOriginalAttributes(originalAttributes());
foreach (AbstractMetaArgument *arg, arguments())
diff --git a/generator/abstractmetalang.h b/generator/abstractmetalang.h
index 37fb4e2..80360d8 100644
--- a/generator/abstractmetalang.h
+++ b/generator/abstractmetalang.h
@@ -498,6 +498,9 @@ public:
bool isConstant() const { return m_constant; }
void setConstant(bool constant) { m_constant = constant; }
+ QString exception() const { return m_exception; }
+ void setException(QString type) { m_exception = type; }
+
QString toString() const { return m_name; }
uint compareTo(const AbstractMetaFunction *other) const;
@@ -557,6 +560,7 @@ private:
const AbstractMetaClass *m_interface_class;
QPropertySpec *m_property_spec;
AbstractMetaArgumentList m_arguments;
+ QString m_exception;
uint m_constant : 1;
uint m_invalid : 1;
};
@@ -706,6 +710,9 @@ public:
bool hasPublicDestructor() const { return m_has_public_destructor; }
void setHasPublicDestructor(bool on) { m_has_public_destructor = on; }
+ QString destructorException() const { return m_destructor_exception; }
+ void setDestructorException(const QString &exception) { m_destructor_exception = exception; }
+
AbstractMetaFunctionList queryFunctionsByName(const QString &name) const;
AbstractMetaFunctionList queryFunctions(uint query) const;
inline AbstractMetaFunctionList allVirtualFunctions() const;
@@ -845,6 +852,8 @@ private:
uint m_is_type_alias : 1;
uint m_reserved : 19;
+ QString m_destructor_exception;
+
const AbstractMetaClass *m_enclosing_class;
AbstractMetaClass *m_base_class;
const AbstractMetaClass *m_template_base_class;
diff --git a/generator/asttoxml.cpp b/generator/asttoxml.cpp
index a215eaf..0c351ac 100644
--- a/generator/asttoxml.cpp
+++ b/generator/asttoxml.cpp
@@ -139,6 +139,12 @@ void writeOutFunction(QXmlStreamWriter &s, FunctionModelItem &item) {
s.writeStartElement("function");
s.writeAttribute("name", qualified_name);
+ if (!item->exception().isEmpty()) {
+ s.writeStartElement("exception");
+ s.writeAttribute("throw", item->exception());
+ s.writeEndElement();
+ }
+
ArgumentList arguments = item->arguments();
for(int i=0; i < arguments.size() ; i++) {
s.writeStartElement("argument");
diff --git a/generator/parser/binder.cpp b/generator/parser/binder.cpp
index 044c6d0..884a724 100644
--- a/generator/parser/binder.cpp
+++ b/generator/parser/binder.cpp
@@ -281,6 +281,8 @@ void Binder::declare_symbol(SimpleDeclarationAST *node, InitDeclaratorAST *init_
fun->setName(name_cc.name());
fun->setAbstract(init_declarator->initializer != 0);
fun->setConstant(declarator->fun_cv != 0);
+ fun->setException(exceptionSpecToString(declarator->exception_spec));
+
fun->setTemplateParameters(_M_current_template_parameters);
applyStorageSpecifiers(node->storage_specifiers, model_static_cast<MemberModelItem>(fun));
applyFunctionSpecifiers(node->function_specifiers, fun);
@@ -389,6 +391,7 @@ void Binder::visitFunctionDefinition(FunctionDefinitionAST *node)
_M_current_function->setFunctionType(_M_current_function_type);
_M_current_function->setConstant(declarator->fun_cv != 0);
_M_current_function->setTemplateParameters(_M_current_template_parameters);
+ _M_current_function->setException(exceptionSpecToString(declarator->exception_spec));
applyStorageSpecifiers(node->storage_specifiers,
model_static_cast<MemberModelItem>(_M_current_function));
@@ -920,4 +923,16 @@ void Binder::updateItemPosition(CodeModelItem item, AST *node)
item->setFileName (filename);
}
+QString Binder::exceptionSpecToString(ExceptionSpecificationAST* exception_spec)
+{
+ QString exception;
+ if (exception_spec) {
+ const Token &start_token = _M_token_stream->token((int) exception_spec->start_token);
+ const Token &end_token = _M_token_stream->token((int) exception_spec->end_token);
+
+ exception = QString::fromUtf8(&start_token.text[start_token.position],
+ (int)(end_token.position - start_token.position));
+ }
+ return exception;
+}
// kate: space-indent on; indent-width 2; replace-tabs on;
diff --git a/generator/parser/binder.h b/generator/parser/binder.h
index f8413ca..f87247e 100644
--- a/generator/parser/binder.h
+++ b/generator/parser/binder.h
@@ -107,6 +107,8 @@ private:
void updateItemPosition(CodeModelItem item, AST *node);
+ QString exceptionSpecToString(ExceptionSpecificationAST *exception_spec);
+
private:
CodeModel *_M_model;
LocationManager &_M_location;
diff --git a/generator/parser/codemodel.cpp b/generator/parser/codemodel.cpp
index 4eb0230..f709ffe 100644
--- a/generator/parser/codemodel.cpp
+++ b/generator/parser/codemodel.cpp
@@ -660,6 +660,16 @@ void _FunctionModelItem::setFunctionType(CodeModel::FunctionType functionType)
_M_functionType = functionType;
}
+QString _FunctionModelItem::exception() const
+{
+ return _M_exception;
+}
+
+void _FunctionModelItem::setException(QString exception)
+{
+ _M_exception = exception;
+}
+
bool _FunctionModelItem::isVariadics() const
{
return _M_isVariadics;
diff --git a/generator/parser/codemodel.h b/generator/parser/codemodel.h
index 8878807..999b60d 100644
--- a/generator/parser/codemodel.h
+++ b/generator/parser/codemodel.h
@@ -541,6 +541,9 @@ public:
CodeModel::FunctionType functionType() const;
void setFunctionType(CodeModel::FunctionType functionType);
+ QString exception() const;
+ void setException(QString);
+
bool isVirtual() const;
void setVirtual(bool isVirtual);
@@ -571,6 +574,7 @@ protected:
private:
ArgumentList _M_arguments;
CodeModel::FunctionType _M_functionType;
+ QString _M_exception;
union
{
struct
diff --git a/generator/shellgenerator.cpp b/generator/shellgenerator.cpp
index a978dfb..7d9f4ba 100644
--- a/generator/shellgenerator.cpp
+++ b/generator/shellgenerator.cpp
@@ -212,4 +212,7 @@ void ShellGenerator::writeFunctionSignature(QTextStream &s,
s << ")";
if (meta_function->isConstant())
s << " const";
+
+ if (!meta_function->exception().isEmpty())
+ s << " " << meta_function->exception();
}
diff --git a/generator/shellheadergenerator.cpp b/generator/shellheadergenerator.cpp
index a574c17..bbd4459 100644
--- a/generator/shellheadergenerator.cpp
+++ b/generator/shellheadergenerator.cpp
@@ -101,7 +101,10 @@ void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_c
}
}
- s << " ~" << shellClassName(meta_class) << "();" << endl;
+ s << " ~" << shellClassName(meta_class) << "()";
+ if (!meta_class->destructorException().isEmpty())
+ s << " " << meta_class->destructorException();
+ s << ";" << endl;
s << endl;
AbstractMetaFunctionList functions = meta_class->queryFunctions(
diff --git a/generator/shellimplgenerator.cpp b/generator/shellimplgenerator.cpp
index 42629c2..047a4c0 100644
--- a/generator/shellimplgenerator.cpp
+++ b/generator/shellimplgenerator.cpp
@@ -141,8 +141,10 @@ void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla
// write destructor
s << "QtScriptShell_" << meta_class->name() << "::"
- << "~QtScriptShell_" << meta_class->name() << "()"
- << " {}" << endl << endl;
+ << "~QtScriptShell_" << meta_class->name() << "()";
+ if (!meta_class->destructorException().isEmpty())
+ s << " " << meta_class->destructorException();
+ s << " {}" << endl << endl;
// write member functions
for (int i = 0; i < functions.size(); ++i) {