Skip to content

Commit bcc8da9

Browse files
author
florianlink
committed
merged Qt5 port and exception parsing
git-svn-id: http://svn.code.sf.net/p/pythonqt/code/trunk@256 ea8d5007-eb21-0410-b261-ccb3ea6e24a9
1 parent d20c722 commit bcc8da9

13 files changed

+91
-20
lines changed

generator/abstractmetabuilder.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -1383,8 +1383,11 @@ void AbstractMetaBuilder::traverseFunctions(ScopeModelItem scope_item, AbstractM
13831383
}
13841384

13851385
meta_class->addFunction(meta_function);
1386-
} else if (meta_function->isDestructor() && !meta_function->isPublic()) {
1387-
meta_class->setHasPublicDestructor(false);
1386+
} else if (meta_function->isDestructor()) {
1387+
meta_class->setDestructorException(meta_function->exception());
1388+
if (!meta_function->isPublic()) {
1389+
meta_class->setHasPublicDestructor(false);
1390+
}
13881391
}
13891392
}
13901393
}
@@ -1564,6 +1567,7 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
15641567

15651568
AbstractMetaFunction *meta_function = createMetaFunction();
15661569
meta_function->setConstant(function_item->isConstant());
1570+
meta_function->setException(function_item->exception());
15671571

15681572
ReportHandler::debugMedium(QString(" - %2()").arg(function_name));
15691573

@@ -1851,7 +1855,7 @@ AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei, boo
18511855
return t;
18521856

18531857
ClassModelItem item = m_dom->findClass(contexts.at(0));
1854-
if (item != 0)
1858+
if (item)
18551859
contexts += item->baseClasses();
18561860
contexts.pop_front();
18571861

generator/abstractmetalang.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ AbstractMetaFunction *AbstractMetaFunction::copy() const
313313
if (type())
314314
cpy->setType(type()->copy());
315315
cpy->setConstant(isConstant());
316+
cpy->setException(exception());
316317
cpy->setOriginalAttributes(originalAttributes());
317318

318319
foreach (AbstractMetaArgument *arg, arguments())

generator/abstractmetalang.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ class AbstractMetaFunction : public AbstractMetaAttributes
490490
void setFunctionType(FunctionType type) { m_function_type = type; }
491491

492492
bool isVirtual() const { return !(isFinal() || isSignal() || isStatic()); }
493-
494493
QStringList introspectionCompatibleSignatures(const QStringList &resolvedArguments = QStringList()) const;
495494
QString signature() const;
496495
QString targetLangSignature(bool minimal = false) const;
@@ -500,6 +499,8 @@ class AbstractMetaFunction : public AbstractMetaAttributes
500499
bool isConstant() const { return m_constant; }
501500
void setConstant(bool constant) { m_constant = constant; }
502501

502+
QString exception() const { return m_exception; }
503+
void setException(const QString &exception) { m_exception = exception; }
503504
QString toString() const { return m_name; }
504505

505506
uint compareTo(const AbstractMetaFunction *other) const;
@@ -559,6 +560,7 @@ class AbstractMetaFunction : public AbstractMetaAttributes
559560
const AbstractMetaClass *m_interface_class;
560561
QPropertySpec *m_property_spec;
561562
AbstractMetaArgumentList m_arguments;
563+
QString m_exception;
562564
uint m_constant : 1;
563565
uint m_invalid : 1;
564566
};
@@ -708,6 +710,8 @@ class AbstractMetaClass : public AbstractMetaAttributes
708710
bool hasPublicDestructor() const { return m_has_public_destructor; }
709711
void setHasPublicDestructor(bool on) { m_has_public_destructor = on; }
710712

713+
QString destructorException() const { return m_destructor_exception; }
714+
void setDestructorException(const QString &exception) { m_destructor_exception = exception; }
711715
AbstractMetaFunctionList queryFunctionsByName(const QString &name) const;
712716
AbstractMetaFunctionList queryFunctions(uint query) const;
713717
inline AbstractMetaFunctionList allVirtualFunctions() const;
@@ -797,7 +801,6 @@ class AbstractMetaClass : public AbstractMetaAttributes
797801
bool hasCloneOperator() const { return m_has_clone_operator; }
798802

799803
bool hasDefaultIsNull() const;
800-
801804
void addPropertySpec(QPropertySpec *spec) { m_property_specs << spec; }
802805
QList<QPropertySpec *> propertySpecs() const { return m_property_specs; }
803806

@@ -832,7 +835,6 @@ class AbstractMetaClass : public AbstractMetaAttributes
832835

833836
void setTypeAlias(bool typeAlias) { m_is_type_alias = typeAlias; }
834837
bool isTypeAlias() const { return m_is_type_alias; }
835-
836838
bool operator <(const AbstractMetaClass &a) const {
837839
return qualifiedCppName() < a.qualifiedCppName();
838840
}
@@ -852,6 +854,7 @@ class AbstractMetaClass : public AbstractMetaAttributes
852854
uint m_has_clone_operator :1;
853855
uint m_is_type_alias : 1;
854856
uint m_reserved : 19;
857+
QString m_destructor_exception;
855858

856859
const AbstractMetaClass *m_enclosing_class;
857860
AbstractMetaClass *m_base_class;

generator/asttoxml.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ void writeOutFunction(QXmlStreamWriter &s, FunctionModelItem &item) {
139139
s.writeStartElement("function");
140140
s.writeAttribute("name", qualified_name);
141141

142+
if (!item->exception().isEmpty()) {
143+
s.writeStartElement("exception");
144+
s.writeAttribute("throw", item->exception());
145+
s.writeEndElement();
146+
}
147+
142148
ArgumentList arguments = item->arguments();
143149
for(int i=0; i < arguments.size() ; i++) {
144150
s.writeStartElement("argument");

generator/main.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ struct Preprocess
8080
// Environment INCLUDE
8181
QString includePath = getenv("INCLUDE");
8282
if (!includePath.isEmpty())
83-
includes += includePath.split(path_splitter);
83+
includes += includePath.split(path_splitter);
8484

8585
// Includes from the command line
8686
if (!commandLineIncludes.isEmpty())
87-
includes += commandLineIncludes.split(path_splitter);
87+
includes += commandLineIncludes.split(path_splitter);
8888

8989
// Include Qt
9090
QString qtdir = getenv ("QTDIR");
@@ -111,12 +111,13 @@ struct Preprocess
111111
includes << qtdir;
112112
}
113113

114-
foreach (QString include, includes)
115-
preprocess.push_include_path(QDir::convertSeparators(include).toStdString());
114+
foreach (QString include, includes) {
115+
preprocess.push_include_path(QDir::toNativeSeparators(include).toStdString());
116+
}
116117

117118
QString currentDir = QDir::current().absolutePath();
118119
QFileInfo sourceInfo(sourceFile);
119-
QDir::setCurrent(sourceInfo.absolutePath());
120+
QDir::setCurrent(sourceInfo.absolutePath());
120121

121122
std::string result;
122123
result.reserve (20 * 1024); // 20K

generator/parser/binder.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ void Binder::declare_symbol(SimpleDeclarationAST *node, InitDeclaratorAST *init_
281281
fun->setName(name_cc.name());
282282
fun->setAbstract(init_declarator->initializer != 0);
283283
fun->setConstant(declarator->fun_cv != 0);
284+
fun->setException(exceptionSpecToString(declarator->exception_spec));
285+
284286
fun->setTemplateParameters(_M_current_template_parameters);
285287
applyStorageSpecifiers(node->storage_specifiers, model_static_cast<MemberModelItem>(fun));
286288
applyFunctionSpecifiers(node->function_specifiers, fun);
@@ -389,6 +391,7 @@ void Binder::visitFunctionDefinition(FunctionDefinitionAST *node)
389391
_M_current_function->setFunctionType(_M_current_function_type);
390392
_M_current_function->setConstant(declarator->fun_cv != 0);
391393
_M_current_function->setTemplateParameters(_M_current_template_parameters);
394+
_M_current_function->setException(exceptionSpecToString(declarator->exception_spec));
392395

393396
applyStorageSpecifiers(node->storage_specifiers,
394397
model_static_cast<MemberModelItem>(_M_current_function));
@@ -745,7 +748,7 @@ static QString strip_preprocessor_lines(const QString &name)
745748

746749
void Binder::visitEnumerator(EnumeratorAST *node)
747750
{
748-
Q_ASSERT(_M_current_enum != 0);
751+
Q_ASSERT(_M_current_enum.data() != 0);
749752
EnumeratorModelItem e = model()->create<EnumeratorModelItem>();
750753
updateItemPosition (e->toItem(), node);
751754
e->setName(decode_symbol(node->id)->as_string());
@@ -920,4 +923,16 @@ void Binder::updateItemPosition(CodeModelItem item, AST *node)
920923
item->setFileName (filename);
921924
}
922925

926+
QString Binder::exceptionSpecToString(ExceptionSpecificationAST* exception_spec)
927+
{
928+
QString exception;
929+
if (exception_spec) {
930+
const Token &start_token = _M_token_stream->token((int) exception_spec->start_token);
931+
const Token &end_token = _M_token_stream->token((int) exception_spec->end_token);
932+
933+
exception = QString::fromUtf8(&start_token.text[start_token.position],
934+
(int)(end_token.position - start_token.position));
935+
}
936+
return exception;
937+
}
923938
// kate: space-indent on; indent-width 2; replace-tabs on;

generator/parser/binder.h

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class Binder: protected DefaultVisitor
107107

108108
void updateItemPosition(CodeModelItem item, AST *node);
109109

110+
QString exceptionSpecToString(ExceptionSpecificationAST *exception_spec);
111+
110112
private:
111113
CodeModel *_M_model;
112114
LocationManager &_M_location;

generator/parser/codemodel.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,16 @@ void _FunctionModelItem::setFunctionType(CodeModel::FunctionType functionType)
660660
_M_functionType = functionType;
661661
}
662662

663+
QString _FunctionModelItem::exception() const
664+
{
665+
return _M_exception;
666+
}
667+
668+
void _FunctionModelItem::setException(const QString &exception)
669+
{
670+
_M_exception = exception;
671+
}
672+
663673
bool _FunctionModelItem::isVariadics() const
664674
{
665675
return _M_isVariadics;

generator/parser/codemodel.h

+4
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,9 @@ class _FunctionModelItem: public _MemberModelItem
541541
CodeModel::FunctionType functionType() const;
542542
void setFunctionType(CodeModel::FunctionType functionType);
543543

544+
QString exception() const;
545+
void setException(const QString &exception);
546+
544547
bool isVirtual() const;
545548
void setVirtual(bool isVirtual);
546549

@@ -571,6 +574,7 @@ class _FunctionModelItem: public _MemberModelItem
571574
private:
572575
ArgumentList _M_arguments;
573576
CodeModel::FunctionType _M_functionType;
577+
QString _M_exception;
574578
union
575579
{
576580
struct

generator/parser/codemodel_finder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ CodeModelFinder::~CodeModelFinder()
5959

6060
ScopeModelItem CodeModelFinder::resolveScope(NameAST *name, ScopeModelItem scope)
6161
{
62-
Q_ASSERT(scope != 0);
62+
Q_ASSERT(scope.data() != 0);
6363

6464
ResolvePolicy saved_resolve_policy = _M_resolve_policy;
6565
_M_resolve_policy = ResolveScope;

generator/parser/codemodel_pointer.h

+18
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ template <class T> class CodeModelPointer
119119
inline T *data() { return (T *) *this; }
120120
inline const T *data() const { return (const T *) *this; }
121121
inline const T *constData() const { return (const T *) *this; }
122+
123+
124+
# if QT_VERSION >= 0x050000
125+
operator T * () const {
126+
return QAtomicPointer<T>::load();
127+
}
128+
inline bool operator!() const { return !(bool)*this; }
129+
operator bool () const {
130+
return (bool)QAtomicPointer<T>::load();
131+
}
132+
133+
inline T *operator->() { return QAtomicPointer<T>::load(); }
134+
inline const T *operator->() const { return QAtomicPointer<T>::load(); }
135+
inline bool operator==(const CodeModelPointer<T> &other) const { return (T*)*this == (T*)other; }
136+
inline bool operator!=(const CodeModelPointer<T> &other) const { return (T*)*this != (T*)other; }
137+
inline bool operator==(const T *ptr) const { return (T*)*this == ptr; }
138+
inline bool operator!=(const T *ptr) const { return (T*)*this != ptr; }
139+
# endif
122140
#endif
123141
};
124142

generator/qtscript_masterinclude.h

+7
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,19 @@
4949

5050
#include <QtUiTools/QtUiTools>
5151

52+
#if QT_VERSION >= 0x050000
53+
#include <QtWidgets/QtWidgets>
54+
#endif
55+
5256
#ifndef QT_NO_XMLPATTERNS
5357
# include <QtXmlPatterns/QtXmlPatterns>
5458
#endif
5559

5660
#ifndef QT_NO_WEBKIT
5761
# include <QtWebKit/QtWebKit>
62+
#if QT_VERSION >= 0x050000
63+
# include <QtWebKitWidgets/QtWebKitWidgets>
64+
#endif
5865
#endif
5966

6067
#ifndef QT_NO_PHONON

generator/shellgenerator.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void ShellGenerator::writeTypeInfo(QTextStream &s, const AbstractMetaType *type,
107107

108108
if (type->isReference() && !(options & ExcludeReference) && !(options & ConvertReferenceToPtr))
109109
s << "&";
110-
110+
111111
if (type->isReference() && (options & ConvertReferenceToPtr)) {
112112
s << "*";
113113
}
@@ -135,7 +135,7 @@ void ShellGenerator::writeFunctionArguments(QTextStream &s, const AbstractMetaCl
135135
if ((option & IncludeDefaultExpression) && !arg->originalDefaultValueExpression().isEmpty()) {
136136
s << " = ";
137137

138-
QString expr = arg->originalDefaultValueExpression();
138+
QString expr = arg->originalDefaultValueExpression();
139139
if (expr != "0") {
140140
QString qualifier;
141141
if (arg->type()->typeEntry()->isEnum() && expr.indexOf("::") < 0) {
@@ -153,7 +153,7 @@ void ShellGenerator::writeFunctionArguments(QTextStream &s, const AbstractMetaCl
153153
if (expr == "MediaSource()") {
154154
expr = "Phonon::MediaSource()";
155155
}
156-
s << expr;
156+
s << expr;
157157
}
158158
}
159159
}
@@ -222,9 +222,9 @@ void ShellGenerator::writeFunctionSignature(QTextStream &s,
222222
function_name = meta_function->name();
223223
}
224224

225-
if (meta_function->attributes() & AbstractMetaAttributes::SetterFunction)
225+
if (meta_function->attributes() & AbstractMetaAttributes::SetterFunction)
226226
s << "py_set_";
227-
else if (meta_function->attributes() & AbstractMetaAttributes::GetterFunction)
227+
else if (meta_function->attributes() & AbstractMetaAttributes::GetterFunction)
228228
s << "py_get_";
229229

230230
s << name_prefix << function_name;
@@ -250,8 +250,9 @@ void ShellGenerator::writeFunctionSignature(QTextStream &s,
250250
s << ")";
251251
if (meta_function->isConstant())
252252
s << " const";
253+
if (!meta_function->exception().isEmpty())
254+
s << " " << meta_function->exception();
253255
}
254-
255256
bool function_sorter(AbstractMetaFunction *a, AbstractMetaFunction *b);
256257

257258
AbstractMetaFunctionList ShellGenerator::getFunctionsToWrap(const AbstractMetaClass* meta_class)
@@ -379,4 +380,3 @@ bool ShellGenerator::isBuiltIn(const QString& name) {
379380
}
380381
return builtIn.contains(name);
381382
}
382-

0 commit comments

Comments
 (0)