[Kde-bindings] [PATCH 1/2] add support for Q_DISABLE_COPY
Sylvain Joyeux
sylvain.joyeux at m4x.org
Mon Nov 10 18:04:08 UTC 2014
---
generators/smoke/helpers.cpp | 3 +++
generatorvisitor.cpp | 1 +
parser/ast.h | 1 +
parser/lexer.cpp | 1 +
parser/parser.cpp | 7 +++++++
parser/tokens.cpp | 2 ++
parser/tokens.h | 1 +
type.h | 4 ++++
8 files changed, 20 insertions(+)
diff --git a/generators/smoke/helpers.cpp b/generators/smoke/helpers.cpp
index 43c6844..51ef5d4 100644
--- a/generators/smoke/helpers.cpp
+++ b/generators/smoke/helpers.cpp
@@ -271,6 +271,9 @@ bool Util::canClassBeCopied(const Class* klass)
if (cache.contains(klass))
return cache[klass];
+ if (klass->hasCopyDisabled())
+ return false;
+
bool privateCopyCtorFound = false;
foreach (const Method& meth, klass->methods()) {
if (meth.access() != Access_private)
diff --git a/generatorvisitor.cpp b/generatorvisitor.cpp
index 5fdcf64..a83ce6c 100644
--- a/generatorvisitor.cpp
+++ b/generatorvisitor.cpp
@@ -375,6 +375,7 @@ void GeneratorVisitor::visitClassSpecifier(ClassSpecifierAST* node)
klass.top()->setFileName(m_header);
klass.top()->setIsForwardDecl(false);
+ klass.top()->setCopyDisabled(node->copy_disabled);
if (klass.count() > 1) {
// get the element before the last element, which is the parent
Class* parent = klass[klass.count() - 2];
diff --git a/parser/ast.h b/parser/ast.h
index ad69bb7..1e63e3d 100644
--- a/parser/ast.h
+++ b/parser/ast.h
@@ -289,6 +289,7 @@ struct ClassSpecifierAST: public TypeSpecifierAST
NameAST *name;
BaseClauseAST *base_clause;
const ListNode<DeclarationAST*> *member_specs;
+ bool copy_disabled;
};
struct CompoundStatementAST: public StatementAST
diff --git a/parser/lexer.cpp b/parser/lexer.cpp
index 4467ffe..5fa370a 100644
--- a/parser/lexer.cpp
+++ b/parser/lexer.cpp
@@ -125,6 +125,7 @@ QVarLengthArray<QVarLengthArray<QPair<uint, TOKEN_KIND>, 10 >, index_size > crea
#define ADD_MAPPED_TOKEN(string, token) ret[IndexedString(#string).index() % index_size].append(qMakePair(IndexedString(#string).index(), token));
ADD_TOKEN(K_DCOP);
ADD_TOKEN(Q_OBJECT);
+ ADD_TOKEN(Q_DISABLE_COPY);
ADD_MAPPED_TOKEN(Q_SIGNALS, Token_signals);
ADD_MAPPED_TOKEN(Q_SLOTS, Token_slots);
ADD_TOKEN(__attribute__);
diff --git a/parser/parser.cpp b/parser/parser.cpp
index bd989d7..273834a 100644
--- a/parser/parser.cpp
+++ b/parser/parser.cpp
@@ -2055,9 +2055,16 @@ bool Parser::parseClassSpecifier(TypeSpecifierAST *&node)
ast->class_key = class_key;
ast->name = name;
ast->base_clause = bases;
+ ast->copy_disabled = false;
while (session->token_stream->lookAhead())
{
+ if (session->token_stream->lookAhead() == Token_Q_DISABLE_COPY)
+ {
+ ast->copy_disabled = true;
+ advance(); // skip at least one token
+ continue;
+ }
if (session->token_stream->lookAhead() == '}')
break;
diff --git a/parser/tokens.cpp b/parser/tokens.cpp
index b49941a..5a0dcf5 100644
--- a/parser/tokens.cpp
+++ b/parser/tokens.cpp
@@ -24,6 +24,7 @@
static char const * const _S_token_names[] = {
"K_DCOP",
"Q_OBJECT",
+ "Q_DISABLE_COPY",
"__attribute__",
"__typeof",
"and",
@@ -130,6 +131,7 @@ static char const * const _S_token_names[] = {
static char const * const _S_token_texts[] = {
"K_DCOP",
"Q_OBJECT",
+ "Q_DISABLE_COPY",
"__attribute__",
"__typeof",
"&&",
diff --git a/parser/tokens.h b/parser/tokens.h
index de57563..8d7a5c7 100644
--- a/parser/tokens.h
+++ b/parser/tokens.h
@@ -32,6 +32,7 @@ enum TOKEN_KIND
Token_K_DCOP = 1000,
Token_Q_OBJECT,
+ Token_Q_DISABLE_COPY,
Token___attribute__,
Token___typeof,
Token_and,
diff --git a/type.h b/type.h
index 2bf48d7..5be6897 100644
--- a/type.h
+++ b/type.h
@@ -107,6 +107,9 @@ public:
void setKind(Kind kind) { m_kind = kind; }
Kind kind() const { return m_kind; }
+
+ void setCopyDisabled(bool flag) { m_hasCopyDisabled = flag; }
+ bool hasCopyDisabled() const { return m_hasCopyDisabled; }
void setIsForwardDecl(bool forward) { m_forward = forward; }
bool isForwardDecl() const { return m_forward; }
@@ -136,6 +139,7 @@ private:
bool m_forward;
bool m_isNamespace;
bool m_isTemplate;
+ bool m_hasCopyDisabled;
QList<Method> m_methods;
QList<Field> m_fields;
QList<BaseClassSpecifier> m_bases;
--
2.1.3
More information about the Kde-bindings
mailing list