summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/Parser.cpp96
-rw-r--r--cpp/src/Slice/Parser.h20
-rw-r--r--cpp/src/slice2cpp/Gen.cpp110
3 files changed, 116 insertions, 110 deletions
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index 590ee475113..c96b4cf9be6 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -195,8 +195,8 @@ Slice::Container::destroy()
Module_ptr
Slice::Container::createModule(const string& name)
{
- list<Contained_ptr> matches = unit_ -> findContents(thisScope() + name);
- for(list<Contained_ptr>::iterator p = matches.begin();
+ ContainedList matches = unit_ -> findContents(thisScope() + name);
+ for(ContainedList::iterator p = matches.begin();
p != matches.end();
++p)
{
@@ -216,8 +216,8 @@ ClassDef_ptr
Slice::Container::createClassDef(const string& name, bool local, bool intf,
const ClassList& bases)
{
- list<Contained_ptr> matches = unit_ -> findContents(thisScope() + name);
- for(list<Contained_ptr>::iterator p = matches.begin();
+ ContainedList matches = unit_ -> findContents(thisScope() + name);
+ for(ContainedList::iterator p = matches.begin();
p != matches.end();
++p)
{
@@ -238,7 +238,7 @@ Slice::Container::createClassDef(const string& name, bool local, bool intf,
ClassDef_ptr def = new ClassDef(this, name, local, intf, bases);
contents_.push_back(def);
- for(list<Contained_ptr>::iterator q = matches.begin();
+ for(ContainedList::iterator q = matches.begin();
q != matches.end();
++q)
{
@@ -261,8 +261,8 @@ Slice::Container::createClassDecl(const string& name, bool local, bool intf)
{
ClassDef_ptr def;
- list<Contained_ptr> matches = unit_ -> findContents(thisScope() + name);
- for(list<Contained_ptr>::iterator p = matches.begin();
+ ContainedList matches = unit_ -> findContents(thisScope() + name);
+ for(ContainedList::iterator p = matches.begin();
p != matches.end();
++p)
{
@@ -287,7 +287,7 @@ Slice::Container::createClassDecl(const string& name, bool local, bool intf)
// have a declaration for the class in this container, we don't
// create another one.
//
- for(list<Contained_ptr>::iterator q = contents_.begin();
+ for(ContainedList::iterator q = contents_.begin();
q != contents_.end();
++q)
{
@@ -313,7 +313,7 @@ Slice::Container::createClassDecl(const string& name, bool local, bool intf)
Vector_ptr
Slice::Container::createVector(const string& name, const Type_ptr& type)
{
- list<Contained_ptr> matches = unit_ -> findContents(thisScope() + name);
+ ContainedList matches = unit_ -> findContents(thisScope() + name);
if(!matches.empty())
{
if(unit_ -> ignRedefs())
@@ -334,7 +334,7 @@ Slice::Container::createVector(const string& name, const Type_ptr& type)
Enum_ptr
Slice::Container::createEnum(const string& name, const StringList& enumerators)
{
- list<Contained_ptr> matches = unit_ -> findContents(thisScope() + name);
+ ContainedList matches = unit_ -> findContents(thisScope() + name);
if(!matches.empty())
{
if(unit_ -> ignRedefs())
@@ -355,7 +355,7 @@ Slice::Container::createEnum(const string& name, const StringList& enumerators)
Enumerator_ptr
Slice::Container::createEnumerator(const std::string& name)
{
- list<Contained_ptr> matches = unit_ -> findContents(thisScope() + name);
+ ContainedList matches = unit_ -> findContents(thisScope() + name);
if(!matches.empty())
{
if(unit_ -> ignRedefs())
@@ -376,7 +376,7 @@ Slice::Container::createEnumerator(const std::string& name)
Native_ptr
Slice::Container::createNative(const string& name)
{
- list<Contained_ptr> matches = unit_ -> findContents(thisScope() + name);
+ ContainedList matches = unit_ -> findContents(thisScope() + name);
if(!matches.empty())
{
if(unit_ -> ignRedefs())
@@ -394,7 +394,7 @@ Slice::Container::createNative(const string& name)
return p;
}
-list<Type_ptr>
+TypeList
Slice::Container::lookupType(const string& scoped)
{
assert(!scoped.empty());
@@ -402,7 +402,7 @@ Slice::Container::lookupType(const string& scoped)
if(scoped[0] == ':')
return unit_ -> lookupType(scoped.substr(2));
- list<Contained_ptr> matches =
+ ContainedList matches =
unit_ -> findContents(thisScope() + scoped);
if(matches.empty())
{
@@ -412,8 +412,8 @@ Slice::Container::lookupType(const string& scoped)
}
else
{
- list<Type_ptr> results;
- for(list<Contained_ptr>::iterator p = matches.begin();
+ TypeList results;
+ for(ContainedList::iterator p = matches.begin();
p != matches.end();
++p)
{
@@ -438,7 +438,7 @@ Slice::Container::includeLevel()
bool
Slice::Container::hasProxies()
{
- for(list<Contained_ptr>::const_iterator p = contents_.begin();
+ for(ContainedList::const_iterator p = contents_.begin();
p != contents_.end();
++p)
{
@@ -457,7 +457,7 @@ Slice::Container::hasProxies()
bool
Slice::Container::hasClassDecls()
{
- for(list<Contained_ptr>::const_iterator p = contents_.begin();
+ for(ContainedList::const_iterator p = contents_.begin();
p != contents_.end();
++p)
{
@@ -475,7 +475,7 @@ Slice::Container::hasClassDecls()
bool
Slice::Container::hasClassDefs()
{
- for(list<Contained_ptr>::const_iterator p = contents_.begin();
+ for(ContainedList::const_iterator p = contents_.begin();
p != contents_.end();
++p)
{
@@ -493,7 +493,7 @@ Slice::Container::hasClassDefs()
bool
Slice::Container::hasOtherConstructedTypes()
{
- for(list<Contained_ptr>::const_iterator p = contents_.begin();
+ for(ContainedList::const_iterator p = contents_.begin();
p != contents_.end();
++p)
{
@@ -524,7 +524,7 @@ Slice::Container::thisScope()
void
Slice::Container::mergeModules()
{
- for(list<Contained_ptr>::iterator p = contents_.begin();
+ for(ContainedList::iterator p = contents_.begin();
p != contents_.end();
++p)
{
@@ -532,7 +532,7 @@ Slice::Container::mergeModules()
if(!mod1)
continue;
- list<Contained_ptr>::iterator q = p;
+ ContainedList::iterator q = p;
++q;
while(q != contents_.end())
{
@@ -566,7 +566,7 @@ Slice::Container::mergeModules()
void
Slice::Container::sort()
{
- for(list<Contained_ptr>::iterator p = contents_.begin();
+ for(ContainedList::iterator p = contents_.begin();
p != contents_.end();
++p)
{
@@ -581,7 +581,7 @@ Slice::Container::sort()
void
Slice::Container::visit(ParserVisitor* visitor)
{
- for(list<Contained_ptr>::const_iterator p = contents_.begin();
+ for(ContainedList::const_iterator p = contents_.begin();
p != contents_.end();
++p)
{
@@ -704,7 +704,7 @@ Slice::ClassDef::createOperation(const string& name,
const TypeStringList& outParams,
const TypeList& throws)
{
- list<Contained_ptr> matches = unit_ -> findContents(thisScope() + name);
+ ContainedList matches = unit_ -> findContents(thisScope() + name);
if(!matches.empty())
{
if(unit_ -> ignRedefs())
@@ -728,7 +728,7 @@ Slice::ClassDef::createDataMember(const string& name, const Type_ptr& type)
{
assert(!isInterface());
- list<Contained_ptr> matches = unit_ -> findContents(thisScope() + name);
+ ContainedList matches = unit_ -> findContents(thisScope() + name);
if(!matches.empty())
{
if(unit_ -> ignRedefs())
@@ -769,11 +769,11 @@ Slice::ClassDef::allBases()
return result;
}
-list<Operation_ptr>
+OperationList
Slice::ClassDef::operations()
{
- list<Operation_ptr> result;
- for(list<Contained_ptr>::const_iterator p = contents_.begin();
+ OperationList result;
+ for(ContainedList::const_iterator p = contents_.begin();
p != contents_.end();
++p)
{
@@ -784,11 +784,29 @@ Slice::ClassDef::operations()
return result;
}
-list<DataMember_ptr>
+OperationList
+Slice::ClassDef::allOperations()
+{
+ OperationList result = operations();
+ result.sort();
+ result.unique();
+ ClassList all = allBases();
+ for(ClassList::iterator p = all.begin();
+ p != all.end();
+ ++p)
+ {
+ OperationList li = (*p) -> operations();
+ result.merge(li);
+ result.unique();
+ }
+ return result;
+}
+
+DataMemberList
Slice::ClassDef::dataMembers()
{
- list<DataMember_ptr> result;
- for(list<Contained_ptr>::const_iterator p = contents_.begin();
+ DataMemberList result;
+ for(ContainedList::const_iterator p = contents_.begin();
p != contents_.end();
++p)
{
@@ -808,7 +826,7 @@ Slice::ClassDef::isAbstract()
if(!bases_.empty() && bases_.front() -> isAbstract())
return true;
- for(list<Contained_ptr>::const_iterator p = contents_.begin();
+ for(ContainedList::const_iterator p = contents_.begin();
p != contents_.end();
++p)
{
@@ -1247,9 +1265,9 @@ void
Slice::Unit::removeContent(const Contained_ptr& contained)
{
string scoped = contained -> scoped();
- map<string, list<Contained_ptr> >::iterator p = contentMap_.find(scoped);
+ map<string, ContainedList >::iterator p = contentMap_.find(scoped);
assert(p != contentMap_.end());
- list<Contained_ptr>::iterator q;
+ ContainedList::iterator q;
for(q = p -> second.begin(); q != p -> second.end(); ++q)
{
if(q -> get() == contained.get())
@@ -1261,21 +1279,21 @@ Slice::Unit::removeContent(const Contained_ptr& contained)
assert(false);
}
-list<Contained_ptr>
+ContainedList
Slice::Unit::findContents(const string& scoped)
{
assert(!scoped.empty());
assert(scoped[0] == ':');
- map<string, list<Contained_ptr> >::iterator p = contentMap_.find(scoped);
+ map<string, ContainedList >::iterator p = contentMap_.find(scoped);
if(p != contentMap_.end())
return p -> second;
else
- return list<Contained_ptr>();
+ return ContainedList();
}
-list<string>
+StringList
Slice::Unit::includeFiles()
{
return includeFiles_;
diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h
index 22a8db4f475..6dbd1826c0e 100644
--- a/cpp/src/Slice/Parser.h
+++ b/cpp/src/Slice/Parser.h
@@ -120,7 +120,10 @@ typedef std::list<Type_ptr> TypeList;
typedef std::list<std::string> StringList;
typedef std::pair<Type_ptr, std::string> TypeString;
typedef std::list<TypeString> TypeStringList;
+typedef std::list<Contained_ptr> ContainedList;
typedef std::list<ClassDef_ptr> ClassList;
+typedef std::list<Operation_ptr> OperationList;
+typedef std::list<DataMember_ptr> DataMemberList;
// ----------------------------------------------------------------------
// ParserVisitor
@@ -279,7 +282,7 @@ public:
Enum_ptr createEnum(const std::string&, const StringList&);
Enumerator_ptr createEnumerator(const std::string&);
Native_ptr createNative(const std::string&);
- std::list<Type_ptr> lookupType(const std::string&);
+ TypeList lookupType(const std::string&);
int includeLevel();
bool hasProxies();
bool hasClassDecls();
@@ -295,7 +298,7 @@ protected:
Container(const Unit_ptr&);
int includeLevel_;
- std::list<Contained_ptr> contents_;
+ ContainedList contents_;
};
// ----------------------------------------------------------------------
@@ -373,8 +376,9 @@ public:
DataMember_ptr createDataMember(const std::string&, const Type_ptr&);
ClassList bases();
ClassList allBases();
- std::list<Operation_ptr> operations();
- std::list<DataMember_ptr> dataMembers();
+ OperationList operations();
+ OperationList allOperations();
+ DataMemberList dataMembers();
bool isAbstract();
bool isLocal();
bool isInterface();
@@ -572,9 +576,9 @@ public:
void addContent(const Contained_ptr&);
void removeContent(const Contained_ptr&);
- std::list<Contained_ptr> findContents(const std::string&);
+ ContainedList findContents(const std::string&);
- std::list<std::string> includeFiles();
+ StringList includeFiles();
int parse(FILE*, bool);
@@ -594,10 +598,10 @@ private:
int currentIncludeLevel_;
std::string currentFile_;
std::string topLevelFile_;
- std::list<std::string> includeFiles_;
+ StringList includeFiles_;
std::stack<Container_ptr> containerStack_;
std::map<Builtin::Kind, Builtin_ptr> builtins_;
- std::map<std::string, std::list<Contained_ptr> > contentMap_;
+ std::map<std::string, ContainedList > contentMap_;
};
extern Unit* unit; // The current parser for bison/flex
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index b2f302223d4..c9dd04cbe6d 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -128,8 +128,8 @@ Slice::Gen::generate(const Unit_ptr& unit)
C << "\n#include <Ice/Stream.h>";
}
- list<string> includes = unit -> includeFiles();
- for(list<string>::iterator q = includes.begin();
+ StringList includes = unit -> includeFiles();
+ for(StringList::iterator q = includes.begin();
q != includes.end();
++q)
{
@@ -1091,11 +1091,11 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDef_ptr& p)
if(!p -> isLocal())
{
ClassList allBases = p -> allBases();
- list<string> ids;
+ StringList ids;
transform(allBases.begin(), allBases.end(),
back_inserter(ids),
::Ice::memFun(&ClassDef::scoped));
- list<string> other;
+ StringList other;
other.push_back(scoped);
other.push_back("::Ice::Object");
other.sort();
@@ -1117,7 +1117,7 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDef_ptr& p)
else
cl = 0;
}
- list<string> classIds;
+ StringList classIds;
transform(allBaseClasses.begin(), allBaseClasses.end(),
back_inserter(classIds),
::Ice::memFun(&ClassDef::scoped));
@@ -1125,7 +1125,7 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDef_ptr& p)
classIds.push_front(scoped);
classIds.push_back("::Ice::Object");
- list<string>::iterator q;
+ StringList::iterator q;
H << sp;
H << nl << "static std::string __ids[" << ids.size() << "];";
@@ -1184,47 +1184,39 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDef_ptr& p)
string name = p -> name();
string scoped = p -> scoped();
- list<Operation_ptr> operations = p -> operations();
ClassList bases = p -> bases();
ClassDef_ptr base;
if(!bases.empty() && !bases.front() -> isInterface())
base = bases.front();
- if(!p -> isLocal() && !operations.empty())
+ if(!p -> isLocal() && !p -> operations().empty())
{
- operations.sort();
- list<Operation_ptr>::iterator op;
-
+ OperationList allOperations = p -> allOperations();
+ StringList allOpNames;
+ transform(allOperations.begin(), allOperations.end(),
+ back_inserter(allOpNames),
+ ::Ice::memFun(&Operation::name));
+ StringList other;
+ other.push_back("_isA");
+ //other.sort();
+ allOpNames.merge(other);
+ allOpNames.unique();
+
+ StringList::iterator q;
+
H << sp;
- H << nl << "typedef ::__Ice::DispatchStatus (" << name
- << "::*__Op)(::__Ice::Incoming&);";
- H << nl << "static __Op __ops[" << operations.size() << "];";
- H << nl << "static std::string __names[" << operations.size()
- << "];";
+ H << nl << "static std::string __names[" << allOpNames.size() << "];";
H << nl << "virtual ::__Ice::DispatchStatus "
<< "__dispatch(::__Ice::Incoming&, const std::string&);";
C << sp;
- C << nl << scoped << "::__Op " << scoped.substr(2)
- << "::__ops[" << operations.size() << "] =";
- C << sb;
- op = operations.begin();
- while(op != operations.end())
- {
- C << nl << '&' << scoped.substr(2) << "::___"
- << (*op) -> name();
- if(++op != operations.end())
- C << ',';
- }
- C << eb << ';';
- C << sp;
- C << nl << "std::string " << scoped.substr(2)
- << "::__names[" << operations.size() << "] =";
+ C << nl << "std::string " << scoped.substr(2) << "::__names["
+ << allOpNames.size() << "] =";
C << sb;
- op = operations.begin();
- while(op != operations.end())
+ q = allOpNames.begin();
+ while(q != allOpNames.end())
{
- C << nl << '"' << (*op) -> name() << '"';
- if(++op != operations.end())
+ C << nl << '"' << *q << '"';
+ if(++q != allOpNames.end())
C << ',';
}
C << eb << ';';
@@ -1233,36 +1225,28 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDef_ptr& p)
<< "::__dispatch(::__Ice::Incoming& in, const std::string& s)";
C << sb;
C << nl << "std::string* b = __names;";
- C << nl << "std::string* e = __names + " << operations.size()
- << ';';
+ C << nl << "std::string* e = __names + " << allOpNames.size() << ';';
C << nl << "std::pair<std::string*, std::string*> r = "
<< "std::equal_range(b, e, s);";
- C << nl << "if(r.first != r.second)";
+ C << nl << "if(r.first == r.second)";
C.inc();
- C << nl << "return (this ->* __ops[r.first - b])(in);";
- C.dec();
- C << nl << "else";
- C.inc();
- C.zeroIndent();
- C << nl << "#ifdef WIN32"; // COMPILERBUG
- C.restoreIndent();
- if(base)
- C << nl << "return " << base -> name();
- else
- C << nl << "return Object";
- C << "::__dispatch(in, s);";
- C.zeroIndent();
- C << nl << "#else";
- C.restoreIndent();
- if(base)
- C << nl << "return " << base -> scoped();
- else
- C << nl << "return ::Ice::Object";
- C << "::__dispatch(in, s);";
- C.zeroIndent();
- C << nl << "#endif";
- C.restoreIndent();
+ C << nl << "return ::__Ice::DispatchOperationNotExist;";
C.dec();
+ C << sp;
+ C << nl << "switch(r.first - __names)";
+ C << sb;
+ int i = 0;
+ for(q = allOpNames.begin(); q != allOpNames.end(); ++q)
+ {
+ C.dec();
+ C << nl << "case " << i++ << ':';
+ C.inc();
+ C << nl << "return ___" << *q << "(in);";
+ }
+ C << eb;
+ C << sp;
+ C << nl << "assert(false);";
+ C << nl << "return ::__Ice::DispatchOperationNotExist;";
C << eb;
}
H << sp;
@@ -1270,8 +1254,8 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDef_ptr& p)
H << nl << "virtual void __read(::__Ice::Stream*);";
H << eb << ';';
TypeStringList memberList;
- list<DataMember_ptr> dataMembers = p -> dataMembers();
- list<DataMember_ptr>::const_iterator q;
+ DataMemberList dataMembers = p -> dataMembers();
+ DataMemberList::const_iterator q;
for(q = dataMembers.begin(); q != dataMembers.end(); ++q)
memberList.push_back(make_pair((*q) -> type(), (*q) -> name()));
C << sp;