summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/PythonUtil.cpp17
-rw-r--r--cpp/src/Slice/RubyUtil.cpp27
-rw-r--r--cpp/src/slice2cpp/Gen.cpp47
-rw-r--r--cpp/src/slice2cpp/Gen.h1
-rwxr-xr-xcpp/src/slice2cs/Gen.cpp20
-rw-r--r--cpp/src/slice2java/Gen.cpp15
-rwxr-xr-xcpp/src/slice2vb/Gen.cpp20
7 files changed, 130 insertions, 17 deletions
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index 9815b210aea..7278922735d 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -742,13 +742,19 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
_out.inc();
_out << nl;
}
+ bool isProtected = p->hasMetaData("protected");
for(DataMemberList::iterator r = members.begin(); r != members.end(); ++r)
{
if(r != members.begin())
{
_out << ',' << nl;
}
- _out << "('" << fixIdent((*r)->name()) << "', ";
+ _out << "('";
+ if(isProtected || (*r)->hasMetaData("protected"))
+ {
+ _out << '_';
+ }
+ _out << fixIdent((*r)->name()) << "', ";
writeMetaData((*r)->getMetaData());
_out << ", ";
writeType((*r)->type());
@@ -1703,7 +1709,14 @@ Slice::Python::CodeVisitor::collectClassMembers(const ClassDefPtr& p, MemberInfo
for(DataMemberList::iterator q = members.begin(); q != members.end(); ++q)
{
MemberInfo m;
- m.fixedName = fixIdent((*q)->name());
+ if(p->hasMetaData("protected") || (*q)->hasMetaData("protected"))
+ {
+ m.fixedName = "_" + fixIdent((*q)->name());
+ }
+ else
+ {
+ m.fixedName = fixIdent((*q)->name());
+ }
m.type = (*q)->type();
m.inherited = inherited;
m.metaData = (*q)->getMetaData();
diff --git a/cpp/src/Slice/RubyUtil.cpp b/cpp/src/Slice/RubyUtil.cpp
index 39fcd879c66..f0c664629f8 100644
--- a/cpp/src/Slice/RubyUtil.cpp
+++ b/cpp/src/Slice/RubyUtil.cpp
@@ -353,14 +353,39 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p)
DataMemberList members = p->dataMembers();
if(!members.empty())
{
+ bool prot = p->hasMetaData("protected");
+ DataMemberList protectedMembers;
+ DataMemberList::iterator q;
+
_out << sp << nl << "attr_accessor ";
- for(DataMemberList::iterator q = members.begin(); q != members.end(); ++q)
+ for(q = members.begin(); q != members.end(); ++q)
{
if(q != members.begin())
{
_out << ", ";
}
_out << ":" << fixIdent((*q)->name(), IdentNormal);
+ if(prot || (*q)->hasMetaData("protected"))
+ {
+ protectedMembers.push_back(*q);
+ }
+ }
+
+ if(!protectedMembers.empty())
+ {
+ _out << nl << "protected ";
+ for(q = protectedMembers.begin(); q != protectedMembers.end(); ++q)
+ {
+ if(q != protectedMembers.begin())
+ {
+ _out << ", ";
+ }
+ //
+ // We need to list the symbols of the reader and the writer (e.g., ":member" and ":member=").
+ //
+ _out << ":" << fixIdent((*q)->name(), IdentNormal) << ", :"
+ << fixIdent((*q)->name(), IdentNormal) << '=';
+ }
}
}
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 539366963ed..dd7ccf7e8d3 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -3345,6 +3345,8 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
}
}
+ bool inProtected = false;
+
if(!p->isAbstract())
{
//
@@ -3359,6 +3361,42 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
{
H << sp << nl << "friend class " << p->name() << "__staticInit;";
}
+
+ inProtected = true;
+ }
+
+ //
+ // Emit data members. Access visibility may be specified by metadata.
+ //
+ DataMemberList dataMembers = p->dataMembers();
+ DataMemberList::const_iterator q;
+ bool prot = p->hasMetaData("protected");
+ for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
+ {
+ if(prot || (*q)->hasMetaData("protected"))
+ {
+ if(!inProtected)
+ {
+ H.dec();
+ H << sp << nl << "protected:";
+ H.inc();
+ inProtected = true;
+ }
+ }
+ else
+ {
+ if(inProtected)
+ {
+ H.dec();
+ H << sp << nl << "public:";
+ H.inc();
+ inProtected = false;
+ }
+ }
+
+ string name = fixKwd((*q)->name());
+ string s = typeToString((*q)->type(), _useWstring, (*q)->getMetaData());
+ H << sp << nl << s << ' ' << name << ';';
}
H << eb << ';';
@@ -3369,6 +3407,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
// We need an instance here to trigger initialization if the implementation is in a shared library.
// But we do this only once per source file, because a single instance is sufficient to initialize
// all of the globals in a shared library.
+ //
// For a Slice class Foo, we instantiate a dummy class Foo__staticInit instead of using a static
// Foo instance directly because Foo has a protected destructor.
//
@@ -3678,14 +3717,6 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p)
}
void
-Slice::Gen::ObjectVisitor::visitDataMember(const DataMemberPtr& p)
-{
- string name = fixKwd(p->name());
- string s = typeToString(p->type(), _useWstring, p->getMetaData());
- H << nl << s << ' ' << name << ';';
-}
-
-void
Slice::Gen::ObjectVisitor::emitGCFunctions(const ClassDefPtr& p)
{
string scoped = fixKwd(p->scoped());
diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h
index 11ae44bf575..221ccfd68c4 100644
--- a/cpp/src/slice2cpp/Gen.h
+++ b/cpp/src/slice2cpp/Gen.h
@@ -260,7 +260,6 @@ private:
virtual bool visitExceptionStart(const ExceptionPtr&);
virtual bool visitStructStart(const StructPtr&);
virtual void visitOperation(const OperationPtr&);
- virtual void visitDataMember(const DataMemberPtr&);
private:
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 93b926534e1..acc531ecd22 100755
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -3031,6 +3031,7 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
bool isClass = false;
bool propertyMapping = false;
bool isValue = false;
+ bool isProtected = false;
ContainedPtr cont = ContainedPtr::dynamicCast(p->container());
assert(cont);
if(StructPtr::dynamicCast(cont))
@@ -3057,6 +3058,7 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
{
propertyMapping = true;
}
+ isProtected = cont->hasMetaData("protected") || p->hasMetaData("protected");
}
_out << sp;
@@ -3072,14 +3074,28 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
{
dataMemberName += "_prop";
}
- _out << nl << (propertyMapping ? "private" : "public") << ' ' << type << ' ' << dataMemberName << ';';
+
+ _out << nl;
+ if(propertyMapping)
+ {
+ _out << "private";
+ }
+ else if(isProtected)
+ {
+ _out << "protected";
+ }
+ else
+ {
+ _out << "public";
+ }
+ _out << ' ' << type << ' ' << dataMemberName << ';';
if(!propertyMapping)
{
return;
}
- _out << nl << "public";
+ _out << nl << (isProtected ? "protected" : "public");
if(!isValue)
{
_out << " virtual";
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index fb07de4ca1c..1309eb43c52 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -2596,7 +2596,20 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
out << nl << " * @deprecated " << deprecateReason;
out << nl << " **/";
}
- out << nl << "public " << s << ' ' << name << ';';
+
+ //
+ // Access visibility for class data members can be controlled by metadata.
+ // If none is specified, the default is public.
+ //
+ if(contained->containedType() == Contained::ContainedTypeClass &&
+ (p->hasMetaData("protected") || contained->hasMetaData("protected")))
+ {
+ out << nl << "protected " << s << ' ' << name << ';';
+ }
+ else
+ {
+ out << nl << "public " << s << ' ' << name << ';';
+ }
//
// Getter/Setter.
diff --git a/cpp/src/slice2vb/Gen.cpp b/cpp/src/slice2vb/Gen.cpp
index 2cbb6103d1c..043148e2eac 100755
--- a/cpp/src/slice2vb/Gen.cpp
+++ b/cpp/src/slice2vb/Gen.cpp
@@ -3373,6 +3373,7 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
bool isClass = false;
bool propertyMapping = false;
bool isValue = false;
+ bool isProtected = false;
ContainedPtr cont = ContainedPtr::dynamicCast(p->container());
assert(cont);
if(StructPtr::dynamicCast(cont))
@@ -3399,6 +3400,7 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
{
propertyMapping = true;
}
+ isProtected = cont->hasMetaData("protected") || p->hasMetaData("protected");
}
_out << sp;
@@ -3414,14 +3416,28 @@ Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
dataMemberName += "_prop";
}
- _out << nl << (propertyMapping ? "Private" : "Public") << ' ' << dataMemberName << " As " << type;
+ _out << nl;
+ if(propertyMapping)
+ {
+ _out << "Private";
+ }
+ else if(isProtected)
+ {
+ _out << "Protected";
+ }
+ else
+ {
+ _out << "Public";
+ }
+
+ _out << ' ' << dataMemberName << " As " << type;
if(!propertyMapping)
{
return;
}
- _out << nl << "Public";
+ _out << nl << (isProtected ? "Protected" : "Public");
if(!isValue)
{
_out << " Overridable";