diff options
author | Marc Laukien <marc@zeroc.com> | 2001-06-22 19:19:25 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-06-22 19:19:25 +0000 |
commit | 78f45ee8dada2cbf5d33833a813b4fca1b8720b4 (patch) | |
tree | aa84a9cc2b6f52a3f50a35bac41751456555bf63 /cpp | |
parent | started with splice2html (diff) | |
download | ice-78f45ee8dada2cbf5d33833a813b4fca1b8720b4.tar.bz2 ice-78f45ee8dada2cbf5d33833a813b4fca1b8720b4.tar.xz ice-78f45ee8dada2cbf5d33833a813b4fca1b8720b4.zip |
more slice2html
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 223 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.h | 27 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 24 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Main.cpp | 2 |
4 files changed, 212 insertions, 64 deletions
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 164edcac846..f2ba270b012 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -159,6 +159,10 @@ Slice::Contained::Contained(const Container_ptr& container, bool Slice::operator<(Contained& l, Contained& r) { + if(l.containedType() != r.containedType()) + return static_cast<int>(l.containedType()) < + static_cast<int>(r.containedType()); + return l.name() < r.name(); } @@ -193,7 +197,7 @@ Slice::Container::createModule(const string& name) if(module) continue; // Reopening modules is permissible - assert(false); // TODO: Already exits + assert(false); // TODO: Already exists and not a module } Module_ptr q = new Module(this, name); @@ -203,8 +207,8 @@ Slice::Container::createModule(const string& name) ClassDef_ptr Slice::Container::createClassDef(const string& name, - const ClassDef_ptr& base, - bool local) + const ClassDef_ptr& base, + bool local) { list<Contained_ptr> matches = parser_ -> findContents(thisScope() + name); for(list<Contained_ptr>::iterator p = matches.begin(); @@ -212,9 +216,17 @@ Slice::Container::createClassDef(const string& name, ++p) { ClassDecl_ptr cl = ClassDecl_ptr::dynamicCast(*p); - assert(cl); // TODO: Already exits + if(cl) + continue; // TODO: Check whether locality matches + + if(parser_ -> ignRedefs()) + { + ClassDef_ptr def = ClassDef_ptr::dynamicCast(*p); + if(def) + return def; + } - // TODO: Check whether locality matches + assert(false); // TODO: Already exists and not a class declaration } ClassDef_ptr def = new ClassDef(this, name, base, local); @@ -259,8 +271,9 @@ Slice::Container::createClassDecl(const string& name, bool local) ClassDecl_ptr clDecl = ClassDecl_ptr::dynamicCast(*p); if(clDecl) continue; // TODO: Check whether locality matches - - assert(false); // TODO: Not a class + + // TODO: Already defined as something other than a class + assert(false); } // @@ -295,7 +308,17 @@ Native_ptr Slice::Container::createNative(const string& name) { list<Contained_ptr> matches = parser_ -> findContents(thisScope() + name); - assert(matches.empty()); // TODO: Already exits + if(!matches.empty()) + { + if(parser_ -> ignRedefs()) + { + Native_ptr p = Native_ptr::dynamicCast(matches.front()); + if(p) + return p; + } + + assert(false); // TODO: Already exits + } Native_ptr p = new Native(this, name); contents_.push_back(p); @@ -306,7 +329,17 @@ Vector_ptr Slice::Container::createVector(const string& name, const Type_ptr& type) { list<Contained_ptr> matches = parser_ -> findContents(thisScope() + name); - assert(matches.empty()); // TODO: Already exits + if(!matches.empty()) + { + if(parser_ -> ignRedefs()) + { + Vector_ptr p = Vector_ptr::dynamicCast(matches.front()); + if(p) + return p; + } + + assert(false); // TODO: Already exits + } Vector_ptr p = new Vector(this, name, type); contents_.push_back(p); @@ -446,37 +479,51 @@ Slice::Container::mergeModules() for(list<Contained_ptr>::iterator p = contents_.begin(); p != contents_.end(); ++p) - { - Module_ptr mod1 = Module_ptr::dynamicCast(*p); - if(!mod1) - continue; - - list<Contained_ptr>::iterator q = p; - ++q; - while(q != contents_.end()) - { - Module_ptr mod2 = Module_ptr::dynamicCast(*q); - if(!mod2) - { - ++q; - continue; - } - - if(mod1 -> name() != mod2 -> name()) - { - ++q; - continue; - } - - copy(mod2 -> contents_.begin(), mod2 -> contents_.end(), - back_inserter(mod1 -> contents_)); - mod2 -> contents_.empty(); - parser_ -> removeContent(*q); - q = contents_.erase(q); - } - - mod1 -> mergeModules(); - } + { + Module_ptr mod1 = Module_ptr::dynamicCast(*p); + if(!mod1) + continue; + + list<Contained_ptr>::iterator q = p; + ++q; + while(q != contents_.end()) + { + Module_ptr mod2 = Module_ptr::dynamicCast(*q); + if(!mod2) + { + ++q; + continue; + } + + if(mod1 -> name() != mod2 -> name()) + { + ++q; + continue; + } + + mod1 -> contents_.splice(mod1 -> contents_.end(), + mod2 -> contents_); + parser_ -> removeContent(*q); + q = contents_.erase(q); + } + + mod1 -> mergeModules(); + } +} + +void +Slice::Container::sort() +{ + for(list<Contained_ptr>::iterator p = contents_.begin(); + p != contents_.end(); + ++p) + { + Container_ptr container = Module_ptr::dynamicCast(*p); + if(container) + container -> sort(); + } + + contents_.sort(); } void @@ -503,6 +550,12 @@ Slice::Container::Container(const Parser_ptr& parser) // Module // ---------------------------------------------------------------------- +Slice::Contained::ContainedType +Slice::Module::containedType() +{ + return ContainedTypeModule; +} + void Slice::Module::visit(ParserVisitor* visitor) { @@ -550,6 +603,12 @@ Slice::ClassDecl::local() return local_; } +Slice::Contained::ContainedType +Slice::ClassDecl::containedType() +{ + return ContainedTypeClass; +} + void Slice::ClassDecl::visit(ParserVisitor* visitor) { @@ -586,7 +645,17 @@ Slice::ClassDef::createOperation(const string& name, const TypeList& throws) { list<Contained_ptr> matches = parser_ -> findContents(thisScope() + name); - assert(matches.empty()); // TODO: Already exits + if(!matches.empty()) + { + if(parser_ -> ignRedefs()) + { + Operation_ptr p = Operation_ptr::dynamicCast(matches.front()); + if(p) + return p; + } + + assert(false); // TODO: Already exits + } Operation_ptr p = new Operation(this, name, returnType, inParams, outParams, throws); @@ -598,7 +667,17 @@ DataMember_ptr Slice::ClassDef::createDataMember(const string& name, const Type_ptr& type) { list<Contained_ptr> matches = parser_ -> findContents(thisScope() + name); - assert(matches.empty()); // TODO: Already exits + if(!matches.empty()) + { + if(parser_ -> ignRedefs()) + { + DataMember_ptr p = DataMember_ptr::dynamicCast(matches.front()); + if(p) + return p; + } + + assert(false); // TODO: Already exits + } DataMember_ptr p = new DataMember(this, name, type); contents_.push_back(p); @@ -664,6 +743,12 @@ Slice::ClassDef::local() return local_; } +Slice::Contained::ContainedType +Slice::ClassDef::containedType() +{ + return ContainedTypeClass; +} + void Slice::ClassDef::visit(ParserVisitor* visitor) { @@ -676,9 +761,9 @@ Slice::ClassDef::visit(ParserVisitor* visitor) } Slice::ClassDef::ClassDef(const Container_ptr& container, - const string& name, - const ClassDef_ptr& base, - bool local) + const string& name, + const ClassDef_ptr& base, + bool local) : Contained(container, name), Container(container -> parser()), SyntaxTreeBase(container -> parser()), @@ -732,6 +817,12 @@ Slice::Operation::throws() return throws_; } +Slice::Contained::ContainedType +Slice::Operation::containedType() +{ + return ContainedTypeOperation; +} + void Slice::Operation::visit(ParserVisitor* visitor) { @@ -762,6 +853,13 @@ Slice::DataMember::type() { return type_; } + +Slice::Contained::ContainedType +Slice::DataMember::containedType() +{ + return ContainedTypeDataMember; +} + void Slice::DataMember::visit(ParserVisitor* visitor) { @@ -781,6 +879,12 @@ Slice::DataMember::DataMember(const Container_ptr& container, // Native // ---------------------------------------------------------------------- +Slice::Contained::ContainedType +Slice::Native::containedType() +{ + return ContainedTypeNative; +} + void Slice::Native::visit(ParserVisitor* visitor) { @@ -806,6 +910,12 @@ Slice::Vector::type() return type_; } +Slice::Contained::ContainedType +Slice::Vector::containedType() +{ + return ContainedTypeVector; +} + void Slice::Vector::visit(ParserVisitor* visitor) { @@ -828,9 +938,15 @@ Slice::Vector::Vector(const Container_ptr& container, // ---------------------------------------------------------------------- Parser_ptr -Slice::Parser::createParser() +Slice::Parser::createParser(bool ignRedefs, bool all) +{ + return new Parser(ignRedefs, all); +} + +bool +Slice::Parser::ignRedefs() { - return new Parser; + return ignRedefs_; } void @@ -905,7 +1021,10 @@ Slice::Parser::scanPosition(const char* s) int Slice::Parser::currentIncludeLevel() { - return currentIncludeLevel_; + if(all_) + return 0; + else + return currentIncludeLevel_; } void @@ -955,11 +1074,13 @@ Slice::Parser::removeContent(const Contained_ptr& contained) assert(p != contentMap_.end()); list<Contained_ptr>::iterator q; for(q = p -> second.begin(); q != p -> second.end(); ++q) + { if(q -> get() == contained.get()) { p -> second.erase(q); return; } + } assert(false); } @@ -1036,9 +1157,11 @@ Slice::Parser::builtin(Builtin::Kind kind) return builtin; } -Slice::Parser::Parser() +Slice::Parser::Parser(bool ignRedefs, bool all) : SyntaxTreeBase(0), - Container(0) + Container(0), + ignRedefs_(ignRedefs), + all_(all) { parser_ = this; } diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h index 096a3cab578..67c1a26bfdf 100644 --- a/cpp/src/Slice/Parser.h +++ b/cpp/src/Slice/Parser.h @@ -274,6 +274,17 @@ public: std::string scoped(); std::string scope(); + enum ContainedType + { + ContainedTypeVector, + ContainedTypeNative, + ContainedTypeModule, + ContainedTypeClass, + ContainedTypeOperation, + ContainedTypeDataMember + }; + virtual ContainedType containedType() = 0; + protected: Contained(const Container_ptr&, @@ -310,6 +321,7 @@ public: bool hasOtherConstructedTypes(); // Other than classes std::string thisScope(); void mergeModules(); + void sort(); virtual void visit(ParserVisitor*); protected: @@ -328,6 +340,7 @@ class ICE_API Module : virtual public Container, virtual public Contained { public: + virtual ContainedType containedType(); virtual void visit(ParserVisitor*); protected: @@ -361,6 +374,7 @@ public: ClassDef_ptr definition(); bool local(); + virtual ContainedType containedType(); virtual void visit(ParserVisitor*); protected: @@ -394,6 +408,7 @@ public: std::list<DataMember_ptr> dataMembers(); bool abstract(); bool local(); + virtual ContainedType containedType(); virtual void visit(ParserVisitor*); protected: @@ -437,6 +452,7 @@ public: TypeNameList inputParameters(); TypeNameList outputParameters(); TypeList throws(); + virtual ContainedType containedType(); virtual void visit(ParserVisitor*); protected: @@ -464,6 +480,7 @@ class ICE_API DataMember : virtual public Contained public: Type_ptr type(); + virtual ContainedType containedType(); virtual void visit(ParserVisitor*); protected: @@ -484,6 +501,7 @@ class Native : virtual public Constructed { public: + virtual ContainedType containedType(); virtual void visit(ParserVisitor*); protected: @@ -502,6 +520,7 @@ class ICE_API Vector : virtual public Constructed public: Type_ptr type(); + virtual ContainedType containedType(); virtual void visit(ParserVisitor*); protected: @@ -522,7 +541,9 @@ class ICE_API Parser : virtual public Container { public: - static Parser_ptr createParser(); + static Parser_ptr createParser(bool, bool); + + bool ignRedefs(); void nextLine(); void scanPosition(const char*); @@ -550,8 +571,10 @@ public: private: - Parser(); + Parser(bool, bool); + bool ignRedefs_; + bool all_; int currentLine_; int currentIncludeLevel_; std::string currentFile_; diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index c57edcd6bed..794cfc4c061 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -117,8 +117,8 @@ Slice::Gen::generate(const Parser_ptr& parser) C << "\n#include <Ice/Stream.h>"; } - vector<string> includes = parser -> includeFiles(); - for(vector<string>::iterator q = includes.begin(); + list<string> includes = parser -> includeFiles(); + for(list<string>::iterator q = includes.begin(); q != includes.end(); ++q) { @@ -1021,13 +1021,13 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDef_ptr& p) string name = p -> name(); string scoped = p -> scoped(); - vector<Operation_ptr> operations = p -> operations(); + list<Operation_ptr> operations = p -> operations(); ClassDef_ptr base = p -> base(); if(!p -> local() && !operations.empty()) { - sort(operations.begin(), operations.end()); - vector<Operation_ptr>::iterator op; + operations.sort(); + list<Operation_ptr>::iterator op; H << sp; H << nl << "typedef ::__Ice::DispatchStatus (" << name @@ -1041,11 +1041,12 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDef_ptr& p) C << nl << scoped << "::__Op " << scoped.substr(2) << "::__ops[" << operations.size() << "] ="; C << sb; - for(op = operations.begin(); op != operations.end(); ++op) + op = operations.begin(); + while(op != operations.end()) { C << nl << '&' << scoped.substr(2) << "::___" << (*op) -> name(); - if(op + 1 != operations.end()) + if(++op != operations.end()) C << ','; } C << eb << ';'; @@ -1053,10 +1054,11 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDef_ptr& p) C << nl << "std::string " << scoped.substr(2) << "::__names[" << operations.size() << "] ="; C << sb; - for(op = operations.begin(); op != operations.end(); ++op) + op = operations.begin(); + while(op != operations.end()) { C << nl << '"' << (*op) -> name() << '"'; - if(op + 1 != operations.end()) + if(++op != operations.end()) C << ','; } C << eb << ';'; @@ -1102,8 +1104,8 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDef_ptr& p) H << nl << "virtual void __read(::__Ice::Stream*);"; H << eb << ';'; TypeNameList memberList; - vector<DataMember_ptr> dataMembers = p -> dataMembers(); - vector<DataMember_ptr>::const_iterator q; + list<DataMember_ptr> dataMembers = p -> dataMembers(); + list<DataMember_ptr>::const_iterator q; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) memberList.push_back(make_pair((*q) -> type(), (*q) -> name())); C << sp; diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 9220dc9b44c..5f7b9c3b4c1 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -168,7 +168,7 @@ main(int argc, char* argv[]) return EXIT_FAILURE; } - Parser_ptr parser = Parser::createParser(); + Parser_ptr parser = Parser::createParser(false, false); int status = parser -> parse(cppHandle, debug); #ifdef WIN32 |