summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorBrent Eagles <brent@zeroc.com>2005-04-05 14:26:15 +0000
committerBrent Eagles <brent@zeroc.com>2005-04-05 14:26:15 +0000
commit2193aade3cbd82d1adcc7404fe2eeccd094f7ba1 (patch)
treeec617fdfe093a1c92b06b2860d6a48e7124d88d8 /cpp/src
parentremoving some more unnecessary code from Slice to C++ generation for IceE (diff)
downloadice-2193aade3cbd82d1adcc7404fe2eeccd094f7ba1.tar.bz2
ice-2193aade3cbd82d1adcc7404fe2eeccd094f7ba1.tar.xz
ice-2193aade3cbd82d1adcc7404fe2eeccd094f7ba1.zip
removing GC code emitters for translator
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/slice2cppe/Gen.cpp260
1 files changed, 0 insertions, 260 deletions
diff --git a/cpp/src/slice2cppe/Gen.cpp b/cpp/src/slice2cppe/Gen.cpp
index 3c8ccd7b9c1..87297ff8c9e 100644
--- a/cpp/src/slice2cppe/Gen.cpp
+++ b/cpp/src/slice2cppe/Gen.cpp
@@ -1601,8 +1601,6 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
C << sb;
C << nl << "return " << flatName << '[' << scopedPos << "];";
C << eb;
-
- emitGCFunctions(p);
}
return true;
@@ -1986,264 +1984,6 @@ Slice::Gen::ObjectVisitor::visitDataMember(const DataMemberPtr& p)
H << nl << s << ' ' << name << ';';
}
-//
-// XXX
-//
-void
-Slice::Gen::ObjectVisitor::emitGCFunctions(const ClassDefPtr& p)
-{
- string scoped = fixKwd(p->scoped());
- ClassList bases = p->bases();
- DataMemberList dataMembers = p->dataMembers();
-
- //
- // A class can potentially be part of a cycle if it (recursively) contains class
- // members. If so, we override __incRef() and __decRef() and, hence, consider instances
- // of the class as candidates for collection by the garbage collector.
- // We override __incRef() and __decRef() only once, in the basemost potentially cyclic class
- // in an inheritance hierarchy.
- //
- bool hasBaseClass = !bases.empty() && !bases.front()->isInterface();
- bool canBeCyclic = p->canBeCyclic();
- bool override = canBeCyclic && (!hasBaseClass || !bases.front()->canBeCyclic());
-
- if(override)
- {
- H << nl << "virtual void __incRef();";
-
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__incRef()";
- C << sb;
- C << nl << "IceUtil::gcRecMutex._m->lock();";
- C << nl << "assert(_ref >= 0);";
- C << nl << "if(_ref == 0)";
- C << sb;
- C.zeroIndent();
- C << nl << "#ifdef NDEBUG // To avoid annoying warnings about variables that are not used...";
- C.restoreIndent();
- C << nl << "IceUtil::gcObjects.insert(this);";
- C.zeroIndent();
- C << nl << "#else";
- C.restoreIndent();
- C << nl << "std::pair<IceUtil::GCObjectSet::iterator, bool> rc = IceUtil::gcObjects.insert(this);";
- C << nl << "assert(rc.second);";
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- C << eb;
- C << nl << "++_ref;";
- C << nl << "IceUtil::gcRecMutex._m->unlock();";
- C << eb;
-
- H << nl << "virtual void __decRef();";
-
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__decRef()";
- C << sb;
- C << nl << "IceUtil::gcRecMutex._m->lock();";
- C << nl << "bool doDelete = false;";
- C << nl << "assert(_ref > 0);";
- C << nl << "if(--_ref == 0)";
- C << sb;
- C << nl << "doDelete = !_noDelete;";
- C << nl << "_noDelete = true;";
- C.zeroIndent();
- C << nl << "#ifdef NDEBUG // To avoid annoying warnings about variables that are not used...";
- C.restoreIndent();
- C << nl << "IceUtil::gcObjects.erase(this);";
- C.zeroIndent();
- C << nl << "#else";
- C.restoreIndent();
- C << nl << "IceUtil::GCObjectSet::size_type num = IceUtil::gcObjects.erase(this);";
- C << nl << "assert(num == 1);";
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- C << eb;
- C << nl << "IceUtil::gcRecMutex._m->unlock();";
- C << nl << "if(doDelete)";
- C << sb;
- C << nl << "delete this;";
- C << eb;
- C << eb;
- }
-
- //
- // __gcReachable() and __gcClear() are overridden by the basemost class that
- // can be cyclic, plus all classes derived from that class.
- //
- if(canBeCyclic)
- {
- H << nl << "virtual void __gcReachable(::IceUtil::GCObjectMultiSet&) const;";
-
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__gcReachable(::IceUtil::GCObjectMultiSet& _c) const";
- C << sb;
-
- string vc6Prefix;
- string otherPrefix;
-
- bool hasCyclicBase = hasBaseClass && bases.front()->canBeCyclic();
- if(hasCyclicBase)
- {
- vc6Prefix = bases.front()->name();
- otherPrefix = bases.front()->scoped();
-
- //
- // Up-call to the base's __gcReachable() member function.
- //
- C.zeroIndent();
- C << nl << "#if defined(_MSC_VER) && (MSC_VER < 1300) // VC++ 6 compiler bug";
- C.restoreIndent();
- C << nl << vc6Prefix << "::__gcReachable(_c);";
- C.zeroIndent();
- C << nl << "#else";
- C.restoreIndent();
- C << nl << otherPrefix << "::__gcReachable(_c);";
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- }
- for(DataMemberList::const_iterator i = dataMembers.begin(); i != dataMembers.end(); ++i)
- {
- if((*i)->type()->usesClasses())
- {
- emitGCInsertCode((*i)->type(), fixKwd((*i)->name()), "", 0);
- }
- }
- C << eb;
-
- H << nl << "virtual void __gcClear();";
-
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__gcClear()";
- C << sb;
- if(hasCyclicBase)
- {
- //
- // Up-call to the base's __gcClear() member function.
- //
- C.zeroIndent();
- C << nl << "#if defined(_MSC_VER) && (MSC_VER < 1300) // VC++ 6 compiler bug";
- C.restoreIndent();
- C << nl << vc6Prefix<< "::__gcClear();";
- C.zeroIndent();
- C << nl << "#else";
- C.restoreIndent();
- C << nl << otherPrefix << "::__gcClear();";
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
- }
- for(DataMemberList::const_iterator j = dataMembers.begin(); j != dataMembers.end(); ++j)
- {
- if((*j)->type()->usesClasses())
- {
- emitGCClearCode((*j)->type(), fixKwd((*j)->name()), "", 0);
- }
- }
- C << eb;
- }
-}
-
-void
-Slice::Gen::ObjectVisitor::emitGCInsertCode(const TypePtr& p, const string& prefix, const string& name, int level)
-{
- if((BuiltinPtr::dynamicCast(p) && BuiltinPtr::dynamicCast(p)->kind() == Builtin::KindObject)
- || ClassDeclPtr::dynamicCast(p))
- {
- C << nl << "__addObject(_c, " << prefix << name << ".get());";
- }
- else if(StructPtr s = StructPtr::dynamicCast(p))
- {
- DataMemberList dml = s->dataMembers();
- for(DataMemberList::const_iterator i = dml.begin(); i != dml.end(); ++i)
- {
- if((*i)->type()->usesClasses())
- {
- emitGCInsertCode((*i)->type(), prefix + name + ".", fixKwd((*i)->name()), ++level);
- }
- }
- }
- else if(DictionaryPtr d = DictionaryPtr::dynamicCast(p))
- {
- string scoped = fixKwd(d->scoped());
- stringstream tmp;
- tmp << "_i" << level;
- string iterName = tmp.str();
- C << sb;
- C << nl << "for(" << scoped << "::const_iterator " << iterName << " = " << prefix + name
- << ".begin(); " << iterName << " != " << prefix + name << ".end(); ++" << iterName << ")";
- C << sb;
- emitGCInsertCode(d->valueType(), "", string("(*") + iterName + ").second", ++level);
- C << eb;
- C << eb;
- }
- else if(SequencePtr s = SequencePtr::dynamicCast(p))
- {
- string scoped = fixKwd(s->scoped());
- stringstream tmp;
- tmp << "_i" << level;
- string iterName = tmp.str();
- C << sb;
- C << nl << "for(" << scoped << "::const_iterator " << iterName << " = " << prefix + name
- << ".begin(); " << iterName << " != " << prefix + name << ".end(); ++" << iterName << ")";
- C << sb;
- emitGCInsertCode(s->type(), string("(*") + iterName + ")", "", ++level);
- C << eb;
- C << eb;
- }
-}
-
-void
-Slice::Gen::ObjectVisitor::emitGCClearCode(const TypePtr& p, const string& prefix, const string& name, int level)
-{
- if((BuiltinPtr::dynamicCast(p) && BuiltinPtr::dynamicCast(p)->kind() == Builtin::KindObject)
- || ClassDeclPtr::dynamicCast(p))
- {
- C << nl << "if(" << prefix << name << ")";
- C << sb;
- C << nl << prefix << name << "->__decRefUnsafe();";
- C << nl << prefix << name << ".__clearHandleUnsafe();";
- C << eb;
- }
- else if(StructPtr s = StructPtr::dynamicCast(p))
- {
- DataMemberList dml = s->dataMembers();
- for(DataMemberList::const_iterator i = dml.begin(); i != dml.end(); ++i)
- {
- if((*i)->type()->usesClasses())
- {
- emitGCClearCode((*i)->type(), prefix + name + ".", fixKwd((*i)->name()), ++level);
- }
- }
- }
- else if(DictionaryPtr d = DictionaryPtr::dynamicCast(p))
- {
- string scoped = fixKwd(d->scoped());
- stringstream tmp;
- tmp << "_i" << level;
- string iterName = tmp.str();
- C << sb;
- C << nl << "for(" << scoped << "::iterator " << iterName << " = " << prefix + name
- << ".begin(); " << iterName << " != " << prefix + name << ".end(); ++" << iterName << ")";
- C << sb;
- emitGCClearCode(d->valueType(), "", string("(*") + iterName + ").second", ++level);
- C << eb;
- C << eb;
- }
- else if(SequencePtr s = SequencePtr::dynamicCast(p))
- {
- string scoped = fixKwd(s->scoped());
- stringstream tmp;
- tmp << "_i" << level;
- string iterName = tmp.str();
- C << sb;
- C << nl << "for(" << scoped << "::iterator " << iterName << " = " << prefix + name
- << ".begin(); " << iterName << " != " << prefix + name << ".end(); ++" << iterName << ")";
- C << sb;
- emitGCClearCode(s->type(), "", string("(*") + iterName + ")", ++level);
- C << eb;
- C << eb;;
- }
-}
-
Slice::Gen::IceInternalVisitor::IceInternalVisitor(Output& h, Output& c, const string& dllExport) :
H(h), C(c), _dllExport(dllExport)
{