bool Slice::ChecksumVisitor::visitExceptionStart(const ExceptionPtr& p) { if (p->isLocal()) { return false; } ExceptionPtr base = p->base(); ostringstream ostr; ostr << "exception " << p->name(); if (base) { ostr << " extends " << base->scoped(); } ostr << endl; DataMemberList members = p->dataMembers(); for (DataMemberList::iterator q = members.begin(); q != members.end(); ++q) { ostr << typeToString((*q)->type()) << ' ' << (*q)->name() << endl; } updateMap(p->scoped(), ostr.str()); return false; }
void CodeVisitor::collectExceptionMembers(const ExceptionPtr& p, MemberInfoList& allMembers, bool inherited) { ExceptionPtr base = p->base(); if(base) { collectExceptionMembers(base, allMembers, true); } DataMemberList members = p->dataMembers(); for(DataMemberList::iterator q = members.begin(); q != members.end(); ++q) { MemberInfo m; m.fixedName = fixIdent((*q)->name()); m.inherited = inherited; m.dataMember = *q; allMembers.push_back(m); } }
bool CodeVisitor::visitExceptionStart(const ExceptionPtr& p) { string scoped = p->scoped(); string name = getName(p); string type = getTypeVar(p); string abs = getAbsolute(p, _ns); startNamespace(p); _out << sp << nl << "if(!class_exists('" << escapeName(abs) << "'))"; _out << sb; _out << nl << "class " << name << " extends "; ExceptionPtr base = p->base(); string baseName; if(base) { baseName = getAbsolute(base, _ns); _out << baseName; } else if(p->isLocal()) { _out << scopedToName("::Ice::LocalException", _ns); } else { _out << scopedToName("::Ice::UserException", _ns); } _out << sb; DataMemberList members = p->dataMembers(); DataMemberList::iterator dmli; // // __construct // _out << nl << "public function __construct("; MemberInfoList allMembers; collectExceptionMembers(p, allMembers, false); writeConstructorParams(allMembers); _out << ")"; _out << sb; if(base) { _out << nl << "parent::__construct("; int count = 0; for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) { if(q->inherited) { if(count) { _out << ", "; } _out << '$' << q->fixedName; ++count; } } _out << ");"; } for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) { if(!q->inherited) { writeAssign(*q); } } _out << eb; // // ice_name // _out << sp << nl << "public function ice_name()"; _out << sb; _out << nl << "return '" << scoped.substr(2) << "';"; _out << eb; // // __toString // _out << sp << nl << "public function __toString()"; _out << sb; _out << nl << "global " << type << ';'; _out << nl << "return IcePHP_stringifyException($this, " << type << ");"; _out << eb; if(!members.empty()) { _out << sp; for(dmli = members.begin(); dmli != members.end(); ++dmli) { _out << nl << "public $" << fixIdent((*dmli)->name()) << ";"; } } _out << eb; // // Emit the type information. // _out << sp << nl << type << " = IcePHP_defineException('" << scoped << "', '" << escapeName(abs) << "', "; if(!base) { _out << "null"; } else { _out << getTypeVar(base); } _out << ", "; // // Data members are represented as an array: // // ('MemberName', MemberType) // // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type. // if(!members.empty()) { _out << "array("; for(dmli = members.begin(); dmli != members.end(); ++dmli) { if(dmli != members.begin()) { _out << ',' << nl; } _out.inc(); _out << nl << "array('" << fixIdent((*dmli)->name()) << "', "; writeType((*dmli)->type()); _out << ')'; _out.dec(); } _out << ')'; } else { _out << "null"; } _out << ");"; _out << eb; endNamespace(); return false; }
bool Slice::Ruby::CodeVisitor::visitExceptionStart(const ExceptionPtr& p) { string scoped = p->scoped(); string name = fixIdent(p->name(), IdentToUpper); _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper) << ')'; _out.inc(); _out << nl << "class " << name << " < "; ExceptionPtr base = p->base(); string baseName; if(base) { baseName = getAbsolute(base, IdentToUpper); _out << baseName; } else if(p->isLocal()) { _out << "Ice::LocalException"; } else { _out << "Ice::UserException"; } _out.inc(); DataMemberList members = p->dataMembers(); DataMemberList::iterator dmli; // // initialize // _out << nl << "def initialize"; MemberInfoList allMembers; collectExceptionMembers(p, allMembers, false); bool inheritsMembers = false; if(!allMembers.empty()) { _out << '('; writeConstructorParams(allMembers); _out << ')'; for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) { if(q->inherited) { inheritsMembers = true; } } } _out.inc(); if(!allMembers.empty()) { if(inheritsMembers) { _out << nl << "super" << spar; for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) { if(q->inherited) { _out << q->lowerName; } } _out << epar; } for(MemberInfoList::iterator q = allMembers.begin(); q != allMembers.end(); ++q) { if(!q->inherited) { _out << nl << '@' << q->fixedName << " = " << q->lowerName; } } } _out.dec(); _out << nl << "end"; // // to_s // _out << sp << nl << "def to_s"; _out.inc(); _out << nl << "'" << scoped.substr(2) << "'"; _out.dec(); _out << nl << "end"; // // read/write accessors for data members. // if(!members.empty()) { _out << sp << nl << "attr_accessor "; for(dmli = members.begin(); dmli != members.end(); ++dmli) { if(dmli != members.begin()) { _out << ", "; } _out << ':' << fixIdent((*dmli)->name(), IdentNormal); } } _out.dec(); _out << nl << "end"; // End of class. // // Emit the type information. // _out << sp << nl << "T_" << name << " = ::Ice::__defineException('" << scoped << "', " << name << ", "; if(!base) { _out << "nil"; } else { _out << getAbsolute(base, IdentToUpper, "T_"); } _out << ", ["; if(members.size() > 1) { _out.inc(); _out << nl; } // // Data members are represented as an array: // // ['MemberName', MemberType] // // where MemberType is either a primitive type constant (T_INT, etc.) or the id of a constructed type. // for(dmli = members.begin(); dmli != members.end(); ++dmli) { if(dmli != members.begin()) { _out << ',' << nl; } _out << "[\"" << fixIdent((*dmli)->name(), IdentNormal) << "\", "; writeType((*dmli)->type()); _out << ']'; } if(members.size() > 1) { _out.dec(); _out << nl; } _out << "])"; _out << nl << name << "::ICE_TYPE = T_" << name; _out.dec(); _out << nl << "end"; // if not defined?() return false; }