diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/Grammer.y | 41 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 481 | ||||
-rw-r--r-- | cpp/src/Slice/Scanner.l | 18 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 260 | ||||
-rw-r--r-- | cpp/src/slice2cpp/GenUtil.cpp | 79 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Main.cpp | 26 | ||||
-rw-r--r-- | cpp/src/slice2docbook/Gen.cpp | 101 | ||||
-rw-r--r-- | cpp/src/slice2docbook/GenUtil.cpp | 123 | ||||
-rw-r--r-- | cpp/src/slice2docbook/GenUtil.h | 6 | ||||
-rw-r--r-- | cpp/src/slice2docbook/Main.cpp | 29 |
10 files changed, 754 insertions, 410 deletions
diff --git a/cpp/src/Slice/Grammer.y b/cpp/src/Slice/Grammer.y index a5ebc96d816..8fe207bace5 100644 --- a/cpp/src/Slice/Grammer.y +++ b/cpp/src/Slice/Grammer.y @@ -171,7 +171,9 @@ module_def ContainerPtr cont = unit->currentContainer(); ModulePtr module = cont->createModule(ident->v); if (!module) + { YYERROR; // Can't continue, jump to next yyerrok + } unit->pushContainer(module); } '{' definitions '}' @@ -205,9 +207,7 @@ class_decl BoolTokPtr local = BoolTokPtr::dynamicCast($1); StringTokPtr ident = StringTokPtr::dynamicCast($3); ContainerPtr cont = unit->currentContainer(); - ClassDeclPtr cl = cont->createClassDecl(ident->v, - local->v, - false); + ClassDeclPtr cl = cont->createClassDecl(ident->v, local->v, false); } ; @@ -222,13 +222,14 @@ class_def ClassDefPtr base = ClassDefPtr::dynamicCast($4); ClassListTokPtr bases = ClassListTokPtr::dynamicCast($5); if (base) + { bases->v.push_front(base); - ClassDefPtr cl = cont->createClassDef(ident->v, - local->v, - false, - bases->v); + } + ClassDefPtr cl = cont->createClassDef(ident->v, local->v, false, bases->v); if (!cl) + { YYERROR; // Can't continue, jump to next yyerrok + } unit->pushContainer(cl); } '{' class_exports '}' @@ -300,9 +301,7 @@ interface_decl BoolTokPtr local = BoolTokPtr::dynamicCast($1); StringTokPtr ident = StringTokPtr::dynamicCast($3); ContainerPtr cont = unit->currentContainer(); - ClassDeclPtr cl = cont->createClassDecl(ident->v, - local->v, - true); + ClassDeclPtr cl = cont->createClassDecl(ident->v, local->v, true); } ; @@ -315,12 +314,11 @@ interface_def StringTokPtr ident = StringTokPtr::dynamicCast($3); ContainerPtr cont = unit->currentContainer(); ClassListTokPtr bases = ClassListTokPtr::dynamicCast($4); - ClassDefPtr cl = cont->createClassDef(ident->v, - local->v, - true, - bases->v); + ClassDefPtr cl = cont->createClassDef(ident->v, local->v, true, bases->v); if (!cl) + { YYERROR; // Can't continue, jump to next yyerrok + } unit->pushContainer(cl); } '{' interface_exports '}' @@ -426,8 +424,7 @@ operation TypeStringListTokPtr outParms = TypeStringListTokPtr::dynamicCast($4); TypeListTokPtr throws = TypeListTokPtr::dynamicCast($6); ClassDefPtr cl = ClassDefPtr::dynamicCast(unit->currentContainer()); - cl->createOperation(name->v, returnType, inParms->v, outParms->v, - throws->v); + cl->createOperation(name->v, returnType, inParms->v, outParms->v, throws->v); } // ---------------------------------------------------------------------- @@ -550,7 +547,9 @@ type ContainerPtr cont = unit->currentContainer(); list<TypePtr> types = cont->lookupType(scoped->v); if (types.empty()) + { YYERROR; // Can't continue, jump to next yyerrok + } $$ = types.front(); } | scoped_name '*' @@ -559,10 +558,10 @@ type ContainerPtr cont = unit->currentContainer(); list<TypePtr> types = cont->lookupType(scoped->v); if (types.empty()) + { YYERROR; // Can't continue, jump to next yyerrok - for (list<TypePtr>::iterator p = types.begin(); - p != types.end(); - ++p) + } + for (list<TypePtr>::iterator p = types.begin(); p != types.end(); ++p) { ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*p); if (!cl) @@ -657,7 +656,9 @@ identifier_list ContainerPtr cont = unit->currentContainer(); EnumeratorPtr en = cont->createEnumerator(ident->v); if (en) + { ens->v.push_front(ident->v); + } } | ICE_IDENTIFIER { @@ -667,7 +668,9 @@ identifier_list ContainerPtr cont = unit->currentContainer(); EnumeratorPtr en = cont->createEnumerator(ident->v); if (en) + { ens->v.push_front(ident->v); + } } ; diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 2122cad7cf1..97895eab9b6 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -79,8 +79,8 @@ Slice::SyntaxTreeBase::visit(ParserVisitor*) { } -Slice::SyntaxTreeBase::SyntaxTreeBase(const UnitPtr& unit) - : _unit(unit) +Slice::SyntaxTreeBase::SyntaxTreeBase(const UnitPtr& unit) : + _unit(unit) { } @@ -88,8 +88,8 @@ Slice::SyntaxTreeBase::SyntaxTreeBase(const UnitPtr& unit) // Type // ---------------------------------------------------------------------- -Slice::Type::Type(const UnitPtr& unit) - : SyntaxTreeBase(unit) +Slice::Type::Type(const UnitPtr& unit) : + SyntaxTreeBase(unit) { } @@ -103,10 +103,10 @@ Slice::Builtin::kind() return _kind; } -Slice::Builtin::Builtin(const UnitPtr& unit, Kind kind) - : Type(unit), - SyntaxTreeBase(unit), - _kind(kind) +Slice::Builtin::Builtin(const UnitPtr& unit, Kind kind) : + Type(unit), + SyntaxTreeBase(unit), + _kind(kind) { } @@ -146,15 +146,16 @@ Slice::Contained::comment() return _comment; } -Slice::Contained::Contained(const ContainerPtr& container, - const string& name) - : SyntaxTreeBase(container->unit()), - _container(container), - _name(name) +Slice::Contained::Contained(const ContainerPtr& container, const string& name) : + SyntaxTreeBase(container->unit()), + _container(container), + _name(name) { ContainedPtr cont = ContainedPtr::dynamicCast(_container); if (cont) + { _scoped = cont->scoped(); + } _scoped += "::" + _name; if (_unit) { @@ -167,16 +168,17 @@ bool Slice::operator<(Contained& l, Contained& r) { if (l.containedType() != r.containedType()) - return static_cast<int>(l.containedType()) < - static_cast<int>(r.containedType()); + { + return static_cast<int>(l.containedType()) < static_cast<int>(r.containedType()); + } - return l.name() < r.name(); + return l.scoped() < r.scoped(); } bool Slice::operator==(Contained& l, Contained& r) { - return l.name() == r.name(); + return l.scoped() == r.scoped(); } // ---------------------------------------------------------------------- @@ -186,8 +188,7 @@ Slice::operator==(Contained& l, Contained& r) void Slice::Container::destroy() { - for_each(_contents.begin(), _contents.end(), - ::Ice::voidMemFun(&Contained::destroy)); + for_each(_contents.begin(), _contents.end(), ::Ice::voidMemFun(&Contained::destroy)); _contents.clear(); SyntaxTreeBase::destroy(); } @@ -196,13 +197,13 @@ ModulePtr Slice::Container::createModule(const string& name) { ContainedList matches = _unit->findContents(thisScope() + name); - for (ContainedList::iterator p = matches.begin(); - p != matches.end(); - ++p) + for (ContainedList::iterator p = matches.begin(); p != matches.end(); ++p) { ModulePtr module = ModulePtr::dynamicCast(*p); if (module) + { continue; // Reopening modules is permissible + } string msg = "redefinition of `"; msg += name; @@ -217,21 +218,18 @@ Slice::Container::createModule(const string& name) } ClassDefPtr -Slice::Container::createClassDef(const string& name, bool local, bool intf, - const ClassList& bases) +Slice::Container::createClassDef(const string& name, bool local, bool intf, const ClassList& bases) { ContainedList matches = _unit->findContents(thisScope() + name); - for (ContainedList::iterator p = matches.begin(); - p != matches.end(); - ++p) + for (ContainedList::iterator p = matches.begin(); p != matches.end(); ++p) { ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*p); if (cl) { - if (checkInterfaceAndLocal(name, false, - intf, cl->isInterface(), - local, cl->isLocal())) + if (checkInterfaceAndLocal(name, false, intf, cl->isInterface(), local, cl->isLocal())) + { continue; + } return 0; } @@ -240,13 +238,19 @@ Slice::Container::createClassDef(const string& name, bool local, bool intf, if (def) { if (_unit->ignRedefs()) + { return def; + } string msg = "redefinition of "; if (intf) + { msg += "interface"; + } else + { msg += "class"; + } msg += " `"; msg += name; msg += "'"; @@ -258,9 +262,13 @@ Slice::Container::createClassDef(const string& name, bool local, bool intf, msg += name; msg += "' as "; if (intf) + { msg += "interface"; + } else + { msg += "class"; + } _unit->error(msg); return 0; } @@ -268,9 +276,7 @@ Slice::Container::createClassDef(const string& name, bool local, bool intf, ClassDefPtr def = new ClassDef(this, name, local, intf, bases); _contents.push_back(def); - for (ContainedList::iterator q = matches.begin(); - q != matches.end(); - ++q) + for (ContainedList::iterator q = matches.begin(); q != matches.end(); ++q) { ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*q); cl->_definition = def; @@ -292,16 +298,12 @@ Slice::Container::createClassDecl(const string& name, bool local, bool intf) ClassDefPtr def; ContainedList matches = _unit->findContents(thisScope() + name); - for (ContainedList::iterator p = matches.begin(); - p != matches.end(); - ++p) + for (ContainedList::iterator p = matches.begin(); p != matches.end(); ++p) { ClassDefPtr clDef = ClassDefPtr::dynamicCast(*p); if (clDef) { - if (checkInterfaceAndLocal(name, true, - intf, clDef->isInterface(), - local, clDef->isLocal())) + if (checkInterfaceAndLocal(name, true, intf, clDef->isInterface(), local, clDef->isLocal())) { assert(!def); def = clDef; @@ -314,10 +316,10 @@ Slice::Container::createClassDecl(const string& name, bool local, bool intf) ClassDeclPtr clDecl = ClassDeclPtr::dynamicCast(*p); if (clDecl) { - if (checkInterfaceAndLocal(name, false, - intf, clDecl->isInterface(), - local, clDecl->isLocal())) + if (checkInterfaceAndLocal(name, false, intf, clDecl->isInterface(), local, clDecl->isLocal())) + { continue; + } return 0; } @@ -326,9 +328,13 @@ Slice::Container::createClassDecl(const string& name, bool local, bool intf) msg += name; msg += "' as "; if (intf) + { msg += "interface"; + } else + { msg += "class"; + } _unit->error(msg); return 0; } @@ -338,15 +344,15 @@ 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 (ContainedList::iterator q = _contents.begin(); - q != _contents.end(); - ++q) + for (ContainedList::iterator q = _contents.begin(); q != _contents.end(); ++q) { if ((*q)->name() == name) { ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*q); if (cl) + { return cl; + } assert(ClassDefPtr::dynamicCast(*q)); } @@ -356,7 +362,9 @@ Slice::Container::createClassDecl(const string& name, bool local, bool intf) _contents.push_back(cl); if (def) + { cl->_definition = def; + } return cl; } @@ -371,7 +379,9 @@ Slice::Container::createVector(const string& name, const TypePtr& type) if (p) { if (_unit->ignRedefs()) + { return p; + } string msg = "redefinition of vector `"; msg += name; @@ -402,7 +412,9 @@ Slice::Container::createEnum(const string& name, const StringList& enumerators) if (p) { if (_unit->ignRedefs()) + { return p; + } string msg = "redefinition of enum `"; msg += name; @@ -433,7 +445,9 @@ Slice::Container::createEnumerator(const std::string& name) if (p) { if (_unit->ignRedefs()) + { return p; + } string msg = "redefinition of enumerator `"; msg += name; @@ -464,7 +478,9 @@ Slice::Container::createNative(const string& name) if (p) { if (_unit->ignRedefs()) + { return p; + } string msg = "redefinition of native `"; msg += name; @@ -506,9 +522,7 @@ Slice::Container::lookupType(const string& scoped, bool printError) "LocalObject" }; - for (unsigned int i = 0; - i < sizeof(builtinTable) / sizeof(const char*); - ++i) + for (unsigned int i = 0; i < sizeof(builtinTable) / sizeof(const char*); ++i) { if (scoped == builtinTable[i]) { @@ -527,10 +541,11 @@ Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError) assert(!scoped.empty()); if (scoped[0] == ':') + { return _unit->lookupTypeNoBuiltin(scoped.substr(2), printError); + } - ContainedList matches = - _unit->findContents(thisScope() + scoped); + ContainedList matches = _unit->findContents(thisScope() + scoped); if (matches.empty()) { ContainedPtr contained = ContainedPtr::dynamicCast(this); @@ -551,9 +566,7 @@ Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError) else { TypeList results; - for (ContainedList::iterator p = matches.begin(); - p != matches.end(); - ++p) + for (ContainedList::iterator p = matches.begin(); p != matches.end(); ++p) { ClassDefPtr cl = ClassDefPtr::dynamicCast(*p); if (cl) @@ -583,10 +596,11 @@ Slice::Container::lookupContained(const string& scoped, bool printError) assert(!scoped.empty()); if (scoped[0] == ':') + { return _unit->lookupContained(scoped.substr(2), printError); + } - ContainedList matches = - _unit->findContents(thisScope() + scoped); + ContainedList matches = _unit->findContents(thisScope() + scoped); if (matches.empty()) { ContainedPtr contained = ContainedPtr::dynamicCast(this); @@ -607,12 +621,12 @@ Slice::Container::lookupContained(const string& scoped, bool printError) else { ContainedList results; - for (ContainedList::iterator p = matches.begin(); - p != matches.end(); - ++p) + for (ContainedList::iterator p = matches.begin(); p != matches.end(); ++p) { if (!ClassDefPtr::dynamicCast(*p)) // Ignore class definitions + { results.push_back(*p); + } } return results; } @@ -622,13 +636,13 @@ ModuleList Slice::Container::modules() { ModuleList result; - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { ModulePtr q = ModulePtr::dynamicCast(*p); if (q) + { result.push_back(q); + } } return result; } @@ -637,13 +651,13 @@ ClassList Slice::Container::classes() { ClassList result; - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { ClassDefPtr q = ClassDefPtr::dynamicCast(*p); if (q) + { result.push_back(q); + } } return result; } @@ -652,13 +666,13 @@ VectorList Slice::Container::vectors() { VectorList result; - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { VectorPtr q = VectorPtr::dynamicCast(*p); if (q) + { result.push_back(q); + } } return result; } @@ -667,13 +681,13 @@ EnumList Slice::Container::enums() { EnumList result; - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { EnumPtr q = EnumPtr::dynamicCast(*p); if (q) + { result.push_back(q); + } } return result; } @@ -682,13 +696,13 @@ NativeList Slice::Container::natives() { NativeList result; - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { NativePtr q = NativePtr::dynamicCast(*p); if (q) + { result.push_back(q); + } } return result; } @@ -702,17 +716,19 @@ Slice::Container::includeLevel() bool Slice::Container::hasProxies() { - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*p); if (cl && !cl->isLocal()) + { return true; + } ContainerPtr container = ContainerPtr::dynamicCast(*p); if (container && container->hasProxies()) + { return true; + } } return false; @@ -721,16 +737,18 @@ Slice::Container::hasProxies() bool Slice::Container::hasClassDecls() { - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { if (ClassDeclPtr::dynamicCast(*p)) + { return true; + } ContainerPtr container = ContainerPtr::dynamicCast(*p); if (container && container->hasClassDecls()) + { return true; + } } return false; @@ -739,16 +757,18 @@ Slice::Container::hasClassDecls() bool Slice::Container::hasClassDefs() { - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { if (ClassDefPtr::dynamicCast(*p)) + { return true; + } ContainerPtr container = ContainerPtr::dynamicCast(*p); if (container && container->hasClassDefs()) + { return true; + } } return false; @@ -757,18 +777,18 @@ Slice::Container::hasClassDefs() bool Slice::Container::hasOtherConstructedTypes() { - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { - if (ConstructedPtr::dynamicCast(*p) && - !ClassDeclPtr::dynamicCast(*p) && - !ClassDefPtr::dynamicCast(*p)) + if (ConstructedPtr::dynamicCast(*p) && !ClassDeclPtr::dynamicCast(*p) && !ClassDefPtr::dynamicCast(*p)) + { return true; + } ContainerPtr container = ContainerPtr::dynamicCast(*p); if (container && container->hasOtherConstructedTypes()) + { return true; + } } return false; @@ -780,7 +800,9 @@ Slice::Container::thisScope() string s; ContainedPtr contained = ContainedPtr::dynamicCast(this); if (contained) + { s = contained->scoped(); + } s += "::"; return s; } @@ -788,13 +810,13 @@ Slice::Container::thisScope() void Slice::Container::mergeModules() { - for (ContainedList::iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::iterator p = _contents.begin(); p != _contents.end(); ++p) { ModulePtr mod1 = ModulePtr::dynamicCast(*p); if (!mod1) + { continue; + } ContainedList::iterator q = p; ++q; @@ -813,11 +835,12 @@ Slice::Container::mergeModules() continue; } - mod1->_contents.splice(mod1->_contents.end(), - mod2->_contents); + mod1->_contents.splice(mod1->_contents.end(), mod2->_contents); if (mod1->_comment.length() < mod2->_comment.length()) - mod1->_comment = mod2->_comment; + { + mod1->_comment.swap(mod2->_comment); + } _unit->removeContent(*q); q = _contents.erase(q); @@ -830,13 +853,13 @@ Slice::Container::mergeModules() void Slice::Container::sort() { - for (ContainedList::iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::iterator p = _contents.begin(); p != _contents.end(); ++p) { - ContainerPtr container = ModulePtr::dynamicCast(*p); + ContainerPtr container = ContainerPtr::dynamicCast(*p); if (container) + { container->sort(); + } } _contents.sort(); @@ -845,21 +868,23 @@ Slice::Container::sort() void Slice::Container::visit(ParserVisitor* visitor) { - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { (*p)->visit(visitor); } } -Slice::Container::Container(const UnitPtr& unit) - : SyntaxTreeBase(unit) +Slice::Container::Container(const UnitPtr& unit) : + SyntaxTreeBase(unit) { if (_unit) + { _includeLevel = _unit->currentIncludeLevel(); + } else + { _includeLevel = 0; + } } bool @@ -869,9 +894,13 @@ Slice::Container::checkInterfaceAndLocal(const string& name, bool defined, { string definedOrDeclared; if (defined) + { definedOrDeclared = "defined"; + } else + { definedOrDeclared = "declared"; + } if (!intf && intfOther) { @@ -934,18 +963,19 @@ void Slice::Module::visit(ParserVisitor* visitor) { if (_includeLevel > 0) + { return; + } visitor->visitModuleStart(this); Container::visit(visitor); visitor->visitModuleEnd(this); } -Slice::Module::Module(const ContainerPtr& container, - const string& name) - : Contained(container, name), - Container(container->unit()), - SyntaxTreeBase(container->unit()) +Slice::Module::Module(const ContainerPtr& container, const string& name) : + Contained(container, name), + Container(container->unit()), + SyntaxTreeBase(container->unit()) { } @@ -953,11 +983,10 @@ Slice::Module::Module(const ContainerPtr& container, // Constructed // ---------------------------------------------------------------------- -Slice::Constructed::Constructed(const ContainerPtr& container, - const string& name) - : Type(container->unit()), - Contained(container, name), - SyntaxTreeBase(container->unit()) +Slice::Constructed::Constructed(const ContainerPtr& container, const string& name) : + Type(container->unit()), + Contained(container, name), + SyntaxTreeBase(container->unit()) { } @@ -995,16 +1024,13 @@ Slice::ClassDecl::visit(ParserVisitor* visitor) visitor->visitClassDecl(this); } -Slice::ClassDecl::ClassDecl(const ContainerPtr& container, - const string& name, - bool local, - bool intf) - : Constructed(container, name), - Type(container->unit()), - Contained(container, name), - SyntaxTreeBase(container->unit()), - _local(local), - _interface(intf) +Slice::ClassDecl::ClassDecl(const ContainerPtr& container, const string& name, bool local, bool intf) : + Constructed(container, name), + Type(container->unit()), + Contained(container, name), + SyntaxTreeBase(container->unit()), + _local(local), + _interface(intf) { } @@ -1015,7 +1041,7 @@ Slice::ClassDecl::ClassDecl(const ContainerPtr& container, void Slice::ClassDef::destroy() { - _bases.empty(); + _bases.clear(); Container::destroy(); } @@ -1033,7 +1059,9 @@ Slice::ClassDef::createOperation(const string& name, if (p) { if (_unit->ignRedefs()) + { return p; + } string msg = "redefinition of operation `"; msg += name; @@ -1078,17 +1106,20 @@ Slice::ClassDef::createOperation(const string& name, { string msg; if (isInterface()) + { msg = "interface name `"; + } else + { msg = "class name `"; + } msg += name; msg += "' can not be used as operation"; _unit->error(msg); return 0; } - OperationPtr p = new Operation(this, name, returnType, - inParams, outParams, throws); + OperationPtr p = new Operation(this, name, returnType, inParams, outParams, throws); _contents.push_back(p); return p; } @@ -1105,7 +1136,9 @@ Slice::ClassDef::createDataMember(const string& name, const TypePtr& type) if (p) { if (_unit->ignRedefs()) + { return p; + } string msg = "redefinition of data member `"; msg += name; @@ -1125,9 +1158,13 @@ Slice::ClassDef::createDataMember(const string& name, const TypePtr& type) { string msg; if (isInterface()) + { msg = "interface name `"; + } else + { msg = "class name `"; + } msg += name; msg += "' can not be used as data member"; _unit->error(msg); @@ -1151,9 +1188,7 @@ Slice::ClassDef::allBases() ClassList result = _bases; result.sort(); result.unique(); - for (ClassList::iterator p = _bases.begin(); - p != _bases.end(); - ++p) + for (ClassList::iterator p = _bases.begin(); p != _bases.end(); ++p) { ClassList li = (*p)->allBases(); result.merge(li); @@ -1166,13 +1201,13 @@ OperationList Slice::ClassDef::operations() { OperationList result; - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { OperationPtr q = OperationPtr::dynamicCast(*p); if (q) + { result.push_back(q); + } } return result; } @@ -1183,9 +1218,7 @@ Slice::ClassDef::allOperations() OperationList result = operations(); result.sort(); result.unique(); - for (ClassList::iterator p = _bases.begin(); - p != _bases.end(); - ++p) + for (ClassList::iterator p = _bases.begin(); p != _bases.end(); ++p) { OperationList li = (*p)->allOperations(); result.merge(li); @@ -1198,13 +1231,13 @@ DataMemberList Slice::ClassDef::dataMembers() { DataMemberList result; - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { DataMemberPtr q = DataMemberPtr::dynamicCast(*p); if (q) + { result.push_back(q); + } } return result; } @@ -1213,17 +1246,21 @@ bool Slice::ClassDef::isAbstract() { if (isInterface()) + { return true; + } if (!_bases.empty() && _bases.front()->isAbstract()) + { return true; + } - for (ContainedList::const_iterator p = _contents.begin(); - p != _contents.end(); - ++p) + for (ContainedList::const_iterator p = _contents.begin(); p != _contents.end(); ++p) { if (OperationPtr::dynamicCast(*p)) + { return true; + } } return false; @@ -1251,33 +1288,30 @@ void Slice::ClassDef::visit(ParserVisitor* visitor) { if (_includeLevel > 0) + { return; + } visitor->visitClassDefStart(this); Container::visit(visitor); visitor->visitClassDefEnd(this); } -Slice::ClassDef::ClassDef(const ContainerPtr& container, - const string& name, - bool local, - bool intf, - const ClassList& bases) - : Contained(container, name), - Container(container->unit()), - SyntaxTreeBase(container->unit()), - _local(local), - _interface(intf), - _bases(bases) +Slice::ClassDef::ClassDef(const ContainerPtr& container, const string& name, bool local, bool intf, + const ClassList& bases) : + Contained(container, name), + Container(container->unit()), + SyntaxTreeBase(container->unit()), + _local(local), + _interface(intf), + _bases(bases) { // // First element of bases may be a class, all others must be // interfaces // #ifndef NDEBUG - for (ClassList::iterator p = _bases.begin(); - p != _bases.end(); - ++p) + for (ClassList::iterator p = _bases.begin(); p != _bases.end(); ++p) { assert(p == _bases.begin() || (*p)->isInterface()); } @@ -1294,10 +1328,10 @@ Slice::Proxy::_class() return __class; } -Slice::Proxy::Proxy(const ClassDeclPtr& cl) - : Type(cl->unit()), - SyntaxTreeBase(cl->unit()), - __class(cl) +Slice::Proxy::Proxy(const ClassDeclPtr& cl) : + Type(cl->unit()), + SyntaxTreeBase(cl->unit()), + __class(cl) { } @@ -1341,18 +1375,14 @@ Slice::Operation::visit(ParserVisitor* visitor) visitor->visitOperation(this); } -Slice::Operation::Operation(const ContainerPtr& container, - const string& name, - const TypePtr& returnType, - const TypeStringList& inParams, - const TypeStringList& outParams, - const TypeList& throws) - : Contained(container, name), - SyntaxTreeBase(container->unit()), - _returnType(returnType), - _inParams(inParams), - _outParams(outParams), - _throws(throws) +Slice::Operation::Operation(const ContainerPtr& container, const string& name, const TypePtr& returnType, + const TypeStringList& inParams, const TypeStringList& outParams, const TypeList& throws) : + Contained(container, name), + SyntaxTreeBase(container->unit()), + _returnType(returnType), + _inParams(inParams), + _outParams(outParams), + _throws(throws) { } @@ -1378,12 +1408,10 @@ Slice::DataMember::visit(ParserVisitor* visitor) visitor->visitDataMember(this); } -Slice::DataMember::DataMember(const ContainerPtr& container, - const string& name, - const TypePtr& type) - : Contained(container, name), - SyntaxTreeBase(container->unit()), - _type(type) +Slice::DataMember::DataMember(const ContainerPtr& container, const string& name, const TypePtr& type) : + Contained(container, name), + SyntaxTreeBase(container->unit()), + _type(type) { } @@ -1403,12 +1431,11 @@ Slice::Native::visit(ParserVisitor* visitor) visitor->visitNative(this); } -Slice::Native::Native(const ContainerPtr& container, - const string& name) - : Constructed(container, name), - Type(container->unit()), - Contained(container, name), - SyntaxTreeBase(container->unit()) +Slice::Native::Native(const ContainerPtr& container, const string& name) : + Constructed(container, name), + Type(container->unit()), + Contained(container, name), + SyntaxTreeBase(container->unit()) { } @@ -1434,14 +1461,12 @@ Slice::Vector::visit(ParserVisitor* visitor) visitor->visitVector(this); } -Slice::Vector::Vector(const ContainerPtr& container, - const string& name, - const TypePtr& type) - : Constructed(container, name), - Type(container->unit()), - Contained(container, name), - SyntaxTreeBase(container->unit()), - _type(type) +Slice::Vector::Vector(const ContainerPtr& container, const string& name, const TypePtr& type) : + Constructed(container, name), + Type(container->unit()), + Contained(container, name), + SyntaxTreeBase(container->unit()), + _type(type) { } @@ -1467,14 +1492,12 @@ Slice::Enum::visit(ParserVisitor* visitor) visitor->visitEnum(this); } -Slice::Enum::Enum(const ContainerPtr& container, - const string& name, - const StringList& enumerators) - : Constructed(container, name), - Type(container->unit()), - Contained(container, name), - SyntaxTreeBase(container->unit()), - _enumerators(enumerators) +Slice::Enum::Enum(const ContainerPtr& container, const string& name, const StringList& enumerators) : + Constructed(container, name), + Type(container->unit()), + Contained(container, name), + SyntaxTreeBase(container->unit()), + _enumerators(enumerators) { } @@ -1488,10 +1511,9 @@ Slice::Enumerator::containedType() return ContainedTypeEnumerator; } -Slice::Enumerator::Enumerator(const ContainerPtr& container, - const string& name) - : Contained(container, name), - SyntaxTreeBase(container->unit()) +Slice::Enumerator::Enumerator(const ContainerPtr& container, const string& name) : + Contained(container, name), + SyntaxTreeBase(container->unit()) { } @@ -1514,14 +1536,16 @@ Slice::Unit::ignRedefs() void Slice::Unit::setComment(const std::string& comment) { - _currentComment.empty(); + _currentComment.clear(); string::size_type end = 0; while (true) { string::size_type begin = comment.find_first_not_of(" \t\r\n*", end); if (begin == string::npos) + { break; + } end = comment.find('\n', begin); _currentComment += comment.substr(begin, end - begin + 1); @@ -1550,17 +1574,23 @@ Slice::Unit::scanPosition(const char* s) idx = line.find("line"); if (idx != string::npos) + { line.erase(0, idx + 4); + } idx = line.find_first_not_of(" \t\r#"); if (idx != string::npos) + { line.erase(0, idx); + } _currentLine = atoi(line.c_str()) - 1; idx = line.find_first_of(" \t\r"); if (idx != string::npos) + { line.erase(0, idx); + } idx = line.find_first_not_of(" \t\r\""); if (idx != string::npos) @@ -1574,7 +1604,9 @@ Slice::Unit::scanPosition(const char* s) line.erase(0, idx + 1); } else + { _currentFile = line; + } idx = line.find_first_not_of(" \t\r"); if (idx != string::npos) @@ -1585,8 +1617,7 @@ Slice::Unit::scanPosition(const char* s) { if (++_currentIncludeLevel == 1) { - if (find(_includeFiles.begin(), _includeFiles.end(), - _currentFile) == _includeFiles.end()) + if (find(_includeFiles.begin(), _includeFiles.end(), _currentFile) == _includeFiles.end()) { _includeFiles.push_back(_currentFile); } @@ -1596,11 +1627,14 @@ Slice::Unit::scanPosition(const char* s) { --_currentIncludeLevel; } + _currentComment.erase(); } else { if (_currentIncludeLevel == 0) + { _topLevelFile = _currentFile; + } } } } @@ -1609,9 +1643,13 @@ int Slice::Unit::currentIncludeLevel() { if (_all) + { return 0; + } else + { return _currentIncludeLevel; + } } void @@ -1692,9 +1730,13 @@ Slice::Unit::findContents(const string& scoped) map<string, ContainedList >::iterator p = _contentMap.find(scoped); if (p != _contentMap.end()) + { return p->second; + } else + { return ContainedList(); + } } StringList @@ -1712,6 +1754,7 @@ Slice::Unit::parse(FILE* file, bool debug) assert(!Slice::unit); Slice::unit = this; + _currentComment.clear(); _currentLine = 1; _currentIncludeLevel = 0; _currentFile = "<standard input>"; @@ -1723,10 +1766,18 @@ Slice::Unit::parse(FILE* file, bool debug) yyin = file; int status = yyparse(); if (yynerrs) + { status = EXIT_FAILURE; - - assert(_containerStack.size() == 1); - popContainer(); + while (!_containerStack.empty()) + { + popContainer(); + } + } + else + { + assert(_containerStack.size() == 1); + popContainer(); + } Slice::unit = 0; return status; @@ -1752,17 +1803,19 @@ Slice::Unit::builtin(Builtin::Kind kind) { map<Builtin::Kind, BuiltinPtr>::iterator p = _builtins.find(kind); if (p != _builtins.end()) + { return p->second; + } BuiltinPtr builtin = new Builtin(this, kind); _builtins.insert(make_pair(kind, builtin)); return builtin; } -Slice::Unit::Unit(bool ignRedefs, bool all) - : SyntaxTreeBase(0), - Container(0), - _ignRedefs(ignRedefs), - _all(all) +Slice::Unit::Unit(bool ignRedefs, bool all) : + SyntaxTreeBase(0), + Container(0), + _ignRedefs(ignRedefs), + _all(all) { _unit = this; } diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l index 959f9516533..3573030d7d9 100644 --- a/cpp/src/Slice/Scanner.l +++ b/cpp/src/Slice/Scanner.l @@ -21,10 +21,10 @@ using namespace Slice; %option noyywrap %option never-interactive -WS [ \t\v\n\r\f] -S [ \t] -D [0-9] -L [a-zA-Z_] +WS [ \t\v\n\r\f] +S [ \t] +D [0-9] +L [a-zA-Z_] %% @@ -53,7 +53,9 @@ L [a-zA-Z_] { c = yyinput(); if (c == '\n') + { unit->nextLine(); + } } while (c != '\n' && c != EOF); } @@ -88,7 +90,9 @@ L [a-zA-Z_] } if (comment[0] == '*') + { unit->setComment(comment); + } } "::" { @@ -187,7 +191,9 @@ L [a-zA-Z_] char* s = yytext; if (s[0] == '\\') // Strip leading backslash + { ++s; + } StringTokPtr ident = new StringTok; ident->v = s; @@ -199,7 +205,9 @@ L [a-zA-Z_] char* s = yytext; if (s[0] == '\\') // Strip leading backslash + { ++s; + } StringTokPtr ident = new StringTok; ident->v = s; @@ -212,7 +220,9 @@ L [a-zA-Z_] // Igore white-space if (yytext[0] == '\n') + { unit->nextLine(); + } } . { diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 8b86828b5f3..69118450893 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -31,36 +31,41 @@ struct ToIfdef char operator()(char c) { if (!isalnum(c)) + { return '_'; + } else + { return c; + } } }; -Slice::Gen::Gen(const string& name, - const string& base, - const string& include, - const vector<string>& includePaths, - const string& dllExport) - : _base(base), - _include(include), - _includePaths(includePaths), - _dllExport(dllExport) +Slice::Gen::Gen(const string& name, const string& base, const string& include, const vector<string>& includePaths, + const string& dllExport) : + _base(base), + _include(include), + _includePaths(includePaths), + _dllExport(dllExport) { - for (vector<string>::iterator p = _includePaths.begin(); - p != _includePaths.end(); - ++p) + for (vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p) { if (p->length() && (*p)[p->length() - 1] != '/') + { *p += '/'; + } } if (_dllExport.length()) + { _dllExport = " " + _dllExport; + } string::size_type pos = _base.rfind('/'); if (pos != string::npos) + { _base.erase(0, pos + 1); + } string fileH = _base + ".h"; string fileC = _base + ".cpp"; @@ -106,7 +111,9 @@ Slice::Gen::generate(const UnitPtr& unit) { C << "\n#include <"; if (_include.length()) + { C << _include << '/'; + } C << _base << ".h>"; H << "\n#include <Ice/ProxyF.h>"; @@ -128,9 +135,7 @@ Slice::Gen::generate(const UnitPtr& unit) } StringList includes = unit->includeFiles(); - for (StringList::iterator q = includes.begin(); - q != includes.end(); - ++q) + for (StringList::iterator q = includes.begin(); q != includes.end(); ++q) { H << "\n#include <" << changeInclude(*q) << ".h>"; } @@ -185,21 +190,23 @@ string Slice::Gen::changeInclude(const string& orig) { string file = orig; - for (vector<string>::iterator p = _includePaths.begin(); - p != _includePaths.end(); - ++p) + for (vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p) { if (orig.compare(0, p->length(), *p) == 0) { string s = orig.substr(p->length()); if (s.length() < file.length()) + { file = s; + } } } string::size_type pos = file.rfind('.'); if (pos != string::npos) + { file.erase(pos); + } return file; } @@ -225,8 +232,8 @@ Slice::Gen::printHeader(Output& out) out << '\n'; } -Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport) - : H(h), C(c), _dllExport(dllExport) +Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport) : + H(h), C(c), _dllExport(dllExport) { } @@ -234,7 +241,9 @@ void Slice::Gen::TypesVisitor::visitModuleStart(const ModulePtr& p) { if (!p->hasOtherConstructedTypes()) + { return; + } string name = p->name(); @@ -246,7 +255,9 @@ void Slice::Gen::TypesVisitor::visitModuleEnd(const ModulePtr& p) { if (!p->hasOtherConstructedTypes()) + { return; + } H << sp; H << nl << '}'; @@ -259,7 +270,9 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p) TypePtr subtype = p->type(); string s = typeToString(subtype); if (s[0] == ':') + { s.insert(0, " "); + } H << sp; H << nl << "typedef ::std::vector<" << s << "> " << name << ';'; @@ -269,7 +282,9 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p) string scoped = p->scoped(); string scope = p->scope(); if (scope.length()) + { scope.erase(0, 2); + } H << sp; H << nl << "class __U__" << name << " { };"; @@ -283,9 +298,9 @@ Slice::Gen::TypesVisitor::visitVector(const VectorPtr& p) C << nl << "__os->write(::Ice::Int(v.size()));"; C << nl << scoped << "::const_iterator p;"; C << nl << "for (p = v.begin(); p != v.end(); ++p)"; - C.inc(); + C << sb; writeMarshalUnmarshalCode(C, subtype, "*p", true); - C.dec(); + C << eb; C << eb; C << sp; C << nl << "void" << nl << scope << "::__read(::IceInternal::Stream* __is, " << scoped << "& v, ::" << scope @@ -327,14 +342,18 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) { H << nl << *en; if (++en != enumerators.end()) + { H << ','; + } } H << eb << ';'; string scoped = p->scoped(); string scope = p->scope(); if (scope.length()) + { scope.erase(0, 2); + } int sz = enumerators.size(); @@ -345,13 +364,21 @@ Slice::Gen::TypesVisitor::visitEnum(const EnumPtr& p) C << nl << "void" << nl << scope << "::__write(::IceInternal::Stream* __os, " << scoped << " v)"; C << sb; if (sz <= numeric_limits<Ice::Byte>::max()) + { C << nl << "__os->write(static_cast< ::Ice::Byte>(v));"; + } else if (sz <= numeric_limits<Ice::Short>::max()) + { C << nl << "__os->write(static_cast< ::Ice::Short>(v));"; + } else if (sz <= numeric_limits<Ice::Int>::max()) + { C << nl << "__os->write(static_cast< ::Ice::Int>(v));"; + } else + { C << nl << "__os->write(static_cast< ::Ice::Long>(v));"; + } C << eb; C << sp; C << nl << "void" << nl << scope << "::__read(::IceInternal::Stream* __is, " << scoped << "& v)"; @@ -392,8 +419,8 @@ Slice::Gen::TypesVisitor::visitNative(const NativePtr& p) H << nl << "typedef ::IceNative::" << name << ' ' << name << ';'; } -Slice::Gen::ProxyDeclVisitor::ProxyDeclVisitor(Output& h, Output& c, const string& dllExport) - : H(h), C(c), _dllExport(dllExport) +Slice::Gen::ProxyDeclVisitor::ProxyDeclVisitor(Output& h, Output& c, const string& dllExport) : + H(h), C(c), _dllExport(dllExport) { } @@ -401,7 +428,9 @@ void Slice::Gen::ProxyDeclVisitor::visitUnitStart(const UnitPtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << "namespace IceProxy" << nl << '{'; @@ -411,7 +440,9 @@ void Slice::Gen::ProxyDeclVisitor::visitUnitEnd(const UnitPtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << '}'; @@ -421,7 +452,9 @@ void Slice::Gen::ProxyDeclVisitor::visitModuleStart(const ModulePtr& p) { if (!p->hasProxies()) + { return; + } string name = p->name(); @@ -433,7 +466,9 @@ void Slice::Gen::ProxyDeclVisitor::visitModuleEnd(const ModulePtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << '}'; @@ -443,7 +478,9 @@ void Slice::Gen::ProxyDeclVisitor::visitClassDecl(const ClassDeclPtr& p) { if (p->isLocal()) + { return; + } string name = p->name(); @@ -451,8 +488,8 @@ Slice::Gen::ProxyDeclVisitor::visitClassDecl(const ClassDeclPtr& p) H << nl << "class " << name << ';'; } -Slice::Gen::ProxyVisitor::ProxyVisitor(Output& h, Output& c, const string& dllExport) - : H(h), C(c), _dllExport(dllExport) +Slice::Gen::ProxyVisitor::ProxyVisitor(Output& h, Output& c, const string& dllExport) : + H(h), C(c), _dllExport(dllExport) { } @@ -460,7 +497,9 @@ void Slice::Gen::ProxyVisitor::visitUnitStart(const UnitPtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << "namespace IceProxy" << nl << '{'; @@ -470,7 +509,9 @@ void Slice::Gen::ProxyVisitor::visitUnitEnd(const UnitPtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << '}'; @@ -480,7 +521,9 @@ void Slice::Gen::ProxyVisitor::visitModuleStart(const ModulePtr& p) { if (!p->hasProxies()) + { return; + } string name = p->name(); @@ -492,7 +535,9 @@ void Slice::Gen::ProxyVisitor::visitModuleEnd(const ModulePtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << '}'; @@ -502,7 +547,9 @@ void Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) { if (p->isLocal()) + { return; + } string name = p->name(); string scoped = p->scoped(); @@ -511,7 +558,9 @@ Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) H << sp; H << nl << "class" << _dllExport << ' ' << name << " : "; if (bases.empty()) + { H << "virtual public ::IceProxy::Ice::Object"; + } else { H.useCurrentPosAsIndent(); @@ -520,7 +569,9 @@ Slice::Gen::ProxyVisitor::visitClassDefStart(const ClassDefPtr& p) { H << "virtual public ::IceProxy" << (*q)->scoped(); if (++q != bases.end()) + { H << ',' << nl; + } } H.restoreIndent(); } @@ -542,7 +593,9 @@ void Slice::Gen::ProxyVisitor::visitClassDefEnd(const ClassDefPtr& p) { if (p->isLocal()) + { return; + } string scoped = p->scoped(); @@ -567,7 +620,9 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) ContainerPtr container = p->container(); ClassDefPtr cl = ClassDefPtr::dynamicCast(container); if (cl->isLocal()) + { return; + } string name = p->name(); string scoped = p->scoped(); @@ -633,13 +688,15 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p) C << nl << "::IceDelegate" << scope << "* __del = dynamic_cast< ::IceDelegate" << scope << "*>(__delBase.get());"; C << nl; if (ret) + { C << "return "; + } C << "__del->" << name << args << ";"; C << eb; } -Slice::Gen::DelegateVisitor::DelegateVisitor(Output& h, Output& c, const string& dllExport) - : H(h), C(c), _dllExport(dllExport) +Slice::Gen::DelegateVisitor::DelegateVisitor(Output& h, Output& c, const string& dllExport) : + H(h), C(c), _dllExport(dllExport) { } @@ -647,7 +704,9 @@ void Slice::Gen::DelegateVisitor::visitUnitStart(const UnitPtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << "namespace IceDelegate" << nl << '{'; @@ -657,7 +716,9 @@ void Slice::Gen::DelegateVisitor::visitUnitEnd(const UnitPtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << '}'; @@ -667,7 +728,9 @@ void Slice::Gen::DelegateVisitor::visitModuleStart(const ModulePtr& p) { if (!p->hasProxies()) + { return; + } string name = p->name(); @@ -679,7 +742,9 @@ void Slice::Gen::DelegateVisitor::visitModuleEnd(const ModulePtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << '}'; @@ -689,7 +754,9 @@ void Slice::Gen::DelegateVisitor::visitClassDefStart(const ClassDefPtr& p) { if (p->isLocal()) + { return; + } string name = p->name(); ClassList bases = p->bases(); @@ -697,7 +764,9 @@ Slice::Gen::DelegateVisitor::visitClassDefStart(const ClassDefPtr& p) H << sp; H << nl << "class" << _dllExport << ' ' << name << " : "; if (bases.empty()) + { H << "virtual public ::IceDelegate::Ice::Object"; + } else { H.useCurrentPosAsIndent(); @@ -706,7 +775,9 @@ Slice::Gen::DelegateVisitor::visitClassDefStart(const ClassDefPtr& p) { H << "virtual public ::IceDelegate" << (*q)->scoped(); if (++q != bases.end()) + { H << ',' << nl; + } } H.restoreIndent(); } @@ -720,7 +791,9 @@ void Slice::Gen::DelegateVisitor::visitClassDefEnd(const ClassDefPtr& p) { if (p->isLocal()) + { return; + } H << eb << ';'; } @@ -731,7 +804,9 @@ Slice::Gen::DelegateVisitor::visitOperation(const OperationPtr& p) ContainerPtr container = p->container(); ClassDefPtr cl = ClassDefPtr::dynamicCast(container); if (cl->isLocal()) + { return; + } string name = p->name(); @@ -780,8 +855,8 @@ Slice::Gen::DelegateVisitor::visitOperation(const OperationPtr& p) H << nl << "virtual " << retS << ' ' << name << params << " = 0;"; } -Slice::Gen::DelegateMVisitor::DelegateMVisitor(Output& h, Output& c, const string& dllExport) - : H(h), C(c), _dllExport(dllExport) +Slice::Gen::DelegateMVisitor::DelegateMVisitor(Output& h, Output& c, const string& dllExport) : + H(h), C(c), _dllExport(dllExport) { } @@ -789,7 +864,9 @@ void Slice::Gen::DelegateMVisitor::visitUnitStart(const UnitPtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << "namespace IceDelegateM" << nl << '{'; @@ -799,7 +876,9 @@ void Slice::Gen::DelegateMVisitor::visitUnitEnd(const UnitPtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << '}'; @@ -809,7 +888,9 @@ void Slice::Gen::DelegateMVisitor::visitModuleStart(const ModulePtr& p) { if (!p->hasProxies()) + { return; + } string name = p->name(); @@ -821,7 +902,9 @@ void Slice::Gen::DelegateMVisitor::visitModuleEnd(const ModulePtr& p) { if (!p->hasProxies()) + { return; + } H << sp; H << nl << '}'; @@ -831,7 +914,9 @@ void Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) { if (p->isLocal()) + { return; + } string name = p->name(); string scoped = p->scoped(); @@ -842,7 +927,9 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) H.useCurrentPosAsIndent(); H << "virtual public ::IceDelegate" << scoped << ','; if (bases.empty()) + { H << nl << "virtual public ::IceDelegateM::Ice::Object"; + } else { ClassList::iterator q = bases.begin(); @@ -850,7 +937,9 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p) { H << nl << "virtual public ::IceDelegateM" << (*q)->scoped(); if (++q != bases.end()) + { H << ','; + } } } H.restoreIndent(); @@ -864,7 +953,9 @@ void Slice::Gen::DelegateMVisitor::visitClassDefEnd(const ClassDefPtr& p) { if (p->isLocal()) + { return; + } H << eb << ';'; } @@ -875,7 +966,9 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) ContainerPtr container = p->container(); ClassDefPtr cl = ClassDefPtr::dynamicCast(container); if (cl->isLocal()) + { return; + } string name = p->name(); string scoped = p->scoped(); @@ -939,14 +1032,16 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) C << sb; C << nl << "::IceInternal::Outgoing __out(__emitter(), __reference());"; if (ret || !outParams.empty() || !throws.empty()) + { C << nl << "::IceInternal::Stream* __is = __out.is();"; + } C << nl << "::IceInternal::Stream* __os = __out.os();"; C << nl << "__os->write(\"" << name << "\");"; writeMarshalCode(C, inParams, 0); C << nl << "if (!__out.invoke())"; + C << sb; if (!throws.empty()) { - C << sb; C << nl << "::Ice::Int __exnum;"; C << nl << "__is->read(__exnum);"; C << nl << "switch (__exnum)"; @@ -962,30 +1057,34 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p) writeAllocateCode(C, li, 0); writeUnmarshalCode(C, li, 0); if (ClassDeclPtr::dynamicCast(*r) || ProxyPtr::dynamicCast(*r)) + { C << nl << "__ex->_throw();"; + } else + { C << nl << "throw __ex;"; + } C << eb; } C << eb; C << nl << "throw ::Ice::UnknownUserException(__FILE__, __LINE__);"; - C << eb; } else { - C.inc(); C << nl << "throw ::Ice::UnknownUserException(__FILE__, __LINE__);"; - C.dec(); } + C << eb; writeAllocateCode(C, TypeStringList(), ret); writeUnmarshalCode(C, outParams, ret); if (ret) + { C << nl << "return __ret;"; + } C << eb; } -Slice::Gen::ObjectDeclVisitor::ObjectDeclVisitor(Output& h, Output& c, const string& dllExport) - : H(h), C(c), _dllExport(dllExport) +Slice::Gen::ObjectDeclVisitor::ObjectDeclVisitor(Output& h, Output& c, const string& dllExport) : + H(h), C(c), _dllExport(dllExport) { } @@ -993,7 +1092,9 @@ void Slice::Gen::ObjectDeclVisitor::visitModuleStart(const ModulePtr& p) { if (!p->hasClassDecls()) + { return; + } string name = p->name(); @@ -1005,7 +1106,9 @@ void Slice::Gen::ObjectDeclVisitor::visitModuleEnd(const ModulePtr& p) { if (!p->hasClassDecls()) + { return; + } H << sp; H << nl << '}'; @@ -1020,8 +1123,8 @@ Slice::Gen::ObjectDeclVisitor::visitClassDecl(const ClassDeclPtr& p) H << nl << "class " << name << ';'; } -Slice::Gen::ObjectVisitor::ObjectVisitor(Output& h, Output& c, const string& dllExport) - : H(h), C(c), _dllExport(dllExport) +Slice::Gen::ObjectVisitor::ObjectVisitor(Output& h, Output& c, const string& dllExport) : + H(h), C(c), _dllExport(dllExport) { } @@ -1029,7 +1132,9 @@ void Slice::Gen::ObjectVisitor::visitModuleStart(const ModulePtr& p) { if (!p->hasClassDefs()) + { return; + } string name = p->name(); @@ -1041,7 +1146,9 @@ void Slice::Gen::ObjectVisitor::visitModuleEnd(const ModulePtr& p) { if (!p->hasClassDefs()) + { return; + } H << sp; H << nl << '}'; @@ -1060,9 +1167,13 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) if (bases.empty()) { if (p->isLocal()) + { H << "virtual public ::Ice::LocalObjectPtrE"; + } else + { H << "virtual public ::Ice::ObjectPtrE"; + } } else { @@ -1071,7 +1182,9 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) { H << "virtual public " << (*q)->scoped() << "PtrE"; if (++q != bases.end()) + { H << ',' << nl; + } } } H.restoreIndent(); @@ -1109,7 +1222,9 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) H << nl << "class" << _dllExport << ' ' << name << "PrxE : "; H.useCurrentPosAsIndent(); if (bases.empty()) + { H << "virtual public ::Ice::ObjectPrxE"; + } else { ClassList::iterator q = bases.begin(); @@ -1117,7 +1232,9 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) { H << "virtual public " << (*q)->scoped() << "PrxE"; if (++q != bases.end()) + { H << ',' << nl; + } } } H.restoreIndent(); @@ -1157,9 +1274,13 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) if (bases.empty()) { if (p->isLocal()) + { H << "virtual public ::Ice::LocalObject"; + } else + { H << "virtual public ::Ice::Object"; + } } else { @@ -1168,11 +1289,15 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) { H << "virtual public " << (*q)->scoped(); if (++q != bases.end()) + { H << ',' << nl; + } } } if (!p->isLocal()) + { H << ',' << nl << "virtual public ::IceDelegate" << scoped; + } H.restoreIndent(); H << sb; H.dec(); @@ -1190,9 +1315,7 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) { ClassList allBases = p->allBases(); StringList ids; - transform(allBases.begin(), allBases.end(), - back_inserter(ids), - ::Ice::memFun(&ClassDef::scoped)); + transform(allBases.begin(), allBases.end(), back_inserter(ids), ::Ice::memFun(&ClassDef::scoped)); StringList other; other.push_back(scoped); other.push_back("::Ice::Object"); @@ -1203,24 +1326,33 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) ClassList allBaseClasses; ClassDefPtr cl; if (!bases.empty()) + { cl = bases.front(); + } else + { cl = 0; + } while (cl && !cl->isInterface()) { allBaseClasses.push_back(cl); ClassList baseBases = cl->bases(); if (!baseBases.empty()) + { cl = baseBases.front(); + } else + { cl = 0; + } } StringList classIds; - transform(allBaseClasses.begin(), allBaseClasses.end(), - back_inserter(classIds), + transform(allBaseClasses.begin(), allBaseClasses.end(), back_inserter(classIds), ::Ice::memFun(&ClassDef::scoped)); if (!p->isInterface()) + { classIds.push_front(scoped); + } classIds.push_back("::Ice::Object"); StringList::iterator q; @@ -1241,7 +1373,9 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) { C << nl << '"' << *q << '"'; if (++q != ids.end()) + { C << ','; + } } C << eb << ';'; C << sp; @@ -1252,7 +1386,9 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p) { C << nl << '"' << *q << '"'; if (++q != classIds.end()) + { C << ','; + } } C << eb << ';'; C << sp; @@ -1280,7 +1416,9 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) ClassList bases = p->bases(); ClassDefPtr base; if (!bases.empty() && !bases.front()->isInterface()) + { base = bases.front(); + } if (!p->isLocal()) { @@ -1310,7 +1448,9 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) { C << nl << '"' << *q << '"'; if (++q != allOpNames.end()) + { C << ','; + } } C << eb << ';'; C << sp; @@ -1321,9 +1461,9 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) 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.inc(); + C << sb; C << nl << "return ::IceInternal::DispatchOperationNotExist;"; - C.dec(); + C << eb; C << sp; C << nl << "switch (r.first - __names)"; C << sb; @@ -1348,7 +1488,9 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) 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; C << nl << "void" << nl << scoped.substr(2) << "::__write(::IceInternal::Stream* __os)"; C << sb; @@ -1466,9 +1608,13 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) << "(::IceInternal::Incoming& __in)"; C << sb; if (!inParams.empty()) + { C << nl << "::IceInternal::Stream* __is = __in.is();"; + } if (ret || !outParams.empty() || !throws.empty()) + { C << nl << "::IceInternal::Stream* __os = __in.os();"; + } writeAllocateCode(C, inParams, 0); writeUnmarshalCode(C, inParams, 0); writeAllocateCode(C, outParams, 0); @@ -1479,7 +1625,9 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) } C << nl; if (ret) + { C << retS << " __ret = "; + } C << name << args << ';'; if (!throws.empty()) { @@ -1499,7 +1647,9 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) writeMarshalUnmarshalCode(C, *r, s, true); } else + { writeMarshalUnmarshalCode(C, *r, "__ex", true); + } C << nl << "return ::IceInternal::DispatchException;"; C << eb; } @@ -1519,8 +1669,8 @@ Slice::Gen::ObjectVisitor::visitDataMember(const DataMemberPtr& p) H << nl << s << ' ' << name << ';'; } -Slice::Gen::IceVisitor::IceVisitor(Output& h, Output& c, const string& dllExport) - : H(h), C(c), _dllExport(dllExport) +Slice::Gen::IceVisitor::IceVisitor(Output& h, Output& c, const string& dllExport) : + H(h), C(c), _dllExport(dllExport) { } @@ -1528,7 +1678,9 @@ void Slice::Gen::IceVisitor::visitUnitStart(const UnitPtr& p) { if (!p->hasClassDecls()) + { return; + } H << sp; H << nl << "namespace IceInternal" << nl << '{'; @@ -1538,7 +1690,9 @@ void Slice::Gen::IceVisitor::visitUnitEnd(const UnitPtr& p) { if (!p->hasClassDecls()) + { return; + } H << sp; H << nl << '}'; @@ -1600,8 +1754,8 @@ Slice::Gen::IceVisitor::visitClassDefStart(const ClassDefPtr& p) } } -Slice::Gen::HandleVisitor::HandleVisitor(Output& h, Output& c, const string& dllExport) - : H(h), C(c), _dllExport(dllExport) +Slice::Gen::HandleVisitor::HandleVisitor(Output& h, Output& c, const string& dllExport) : + H(h), C(c), _dllExport(dllExport) { } @@ -1609,7 +1763,9 @@ void Slice::Gen::HandleVisitor::visitModuleStart(const ModulePtr& p) { if (!p->hasClassDecls()) + { return; + } string name = p->name(); @@ -1621,7 +1777,9 @@ void Slice::Gen::HandleVisitor::visitModuleEnd(const ModulePtr& p) { if (!p->hasClassDecls()) + { return; + } H << sp; H << nl << '}'; @@ -1648,12 +1806,16 @@ void Slice::Gen::HandleVisitor::visitClassDefStart(const ClassDefPtr& p) { if (p->isLocal()) + { return; + } string scoped = p->scoped(); string scope = p->scope(); if (scope.length()) + { scope.erase(0, 2); + } C << sp; C << nl << "void" << nl << scope << "::__write(::IceInternal::Stream* __os, const " << scoped << "Prx& v)"; diff --git a/cpp/src/slice2cpp/GenUtil.cpp b/cpp/src/slice2cpp/GenUtil.cpp index d8537405028..8de9550af30 100644 --- a/cpp/src/slice2cpp/GenUtil.cpp +++ b/cpp/src/slice2cpp/GenUtil.cpp @@ -34,19 +34,27 @@ Slice::typeToString(const TypePtr& type) BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if (builtin) + { return builtinTable[builtin->kind()]; + } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if (cl) + { return cl->scoped() + "Ptr"; + } ProxyPtr proxy = ProxyPtr::dynamicCast(type); if (proxy) + { return proxy->_class()->scoped() + "Prx"; + } ContainedPtr contained = ContainedPtr::dynamicCast(type); if (contained) + { return contained->scoped(); + } return "???"; } @@ -55,7 +63,9 @@ string Slice::returnTypeToString(const TypePtr& type) { if (!type) + { return "void"; + } return typeToString(type); } @@ -81,27 +91,39 @@ Slice::inputTypeToString(const TypePtr& type) BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if (builtin) + { return inputBuiltinTable[builtin->kind()]; + } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if (cl) + { return "const " + cl->scoped() + "Ptr&"; + } ProxyPtr proxy = ProxyPtr::dynamicCast(type); if (proxy) + { return "const " + proxy->_class()->scoped() + "Prx&"; + } EnumPtr en = EnumPtr::dynamicCast(type); if (en) + { return en->scoped(); + } NativePtr native = NativePtr::dynamicCast(type); if (native) + { return native->scoped(); + } ContainedPtr contained = ContainedPtr::dynamicCast(type); if (contained) + { return "const " + contained->scoped() + "&"; + } return "???"; } @@ -127,23 +149,33 @@ Slice::outputTypeToString(const TypePtr& type) BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if (builtin) + { return outputBuiltinTable[builtin->kind()]; + } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if (cl) + { return cl->scoped() + "Ptr&"; + } ProxyPtr proxy = ProxyPtr::dynamicCast(type); if (proxy) + { return proxy->_class()->scoped() + "Prx&"; + } NativePtr native = NativePtr::dynamicCast(type); if (native) + { return native->scoped(); + } ContainedPtr contained = ContainedPtr::dynamicCast(type); if (contained) + { return contained->scoped() + "&"; + } return "???"; } @@ -169,27 +201,39 @@ Slice::exceptionTypeToString(const TypePtr& type) BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); if (builtin) + { return inputBuiltinTable[builtin->kind()]; + } ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); if (cl) + { return "const " + cl->scoped() + "PtrE&"; + } ProxyPtr proxy = ProxyPtr::dynamicCast(type); if (proxy) + { return "const " + proxy->_class()->scoped() + "PrxE&"; + } EnumPtr en = EnumPtr::dynamicCast(type); if (en) + { return en->scoped(); + } NativePtr native = NativePtr::dynamicCast(type); if (native) + { return native->scoped(); + } ContainedPtr contained = ContainedPtr::dynamicCast(type); if (contained) + { return "const " + contained->scoped() + "&"; + } return "???"; } @@ -220,25 +264,23 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& out << nl << "::Ice::ObjectPtr __obj;"; out << nl << stream << "->read(__obj, " << cl->scoped() << "::__classIds[0]);"; out << nl << "if (!__obj)"; + out << sb; ClassDefPtr def = cl->definition(); if (def && !def->isAbstract()) { - out << sb; out << nl << "__obj = new " << cl->scoped() << ";"; out << nl << "__obj->__read(__is);"; - out << eb; } else { - out.inc(); out << nl << "throw ::Ice::NoFactoryException(__FILE__, __LINE__);"; - out.dec(); } + out << eb; out << nl << param << " = " << cl->scoped() << "Ptr::dynamicCast(__obj);"; out << nl << "if (!" << param << ')'; - out.inc(); + out << sb; out << nl << "throw ::Ice::ValueUnmarshalException(__FILE__, __LINE__);"; - out.dec(); + out << eb; } out << eb; @@ -249,10 +291,14 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& if (vec) { if (BuiltinPtr::dynamicCast(vec->type())) + { out << nl << stream << "->" << func << param << ");"; + } else + { out << nl << vec->scope() << "::__" << func << stream << ", " << param << ", " << vec->scope() << "::__U__" << vec->name() << "());"; + } return; } @@ -273,21 +319,27 @@ Slice::writeMarshalUnmarshalCode(Output& out, const TypePtr& type, const string& void Slice::writeMarshalCode(Output& out, const list<pair<TypePtr, string> >& params, const TypePtr& ret) { - list<pair<TypePtr, string> >::const_iterator p; - for (p = params.begin(); p != params.end(); ++p) + for (list<pair<TypePtr, string> >::const_iterator p = params.begin(); p != params.end(); ++p) + { writeMarshalUnmarshalCode(out, p->first, p->second, true); + } if (ret) + { writeMarshalUnmarshalCode(out, ret, "__ret", true); + } } void Slice::writeUnmarshalCode(Output& out, const list<pair<TypePtr, string> >& params, const TypePtr& ret) { - list<pair<TypePtr, string> >::const_iterator p; - for (p = params.begin(); p != params.end(); ++p) + for (list<pair<TypePtr, string> >::const_iterator p = params.begin(); p != params.end(); ++p) + { writeMarshalUnmarshalCode(out, p->first, p->second, false); + } if (ret) + { writeMarshalUnmarshalCode(out, ret, "__ret", false); + } } void @@ -295,9 +347,12 @@ Slice::writeAllocateCode(Output& out, const list<pair<TypePtr, string> >& params { list<pair<TypePtr, string> > ps = params; if (ret) + { ps.push_back(make_pair(ret, string("__ret"))); + } - list<pair<TypePtr, string> >::const_iterator p; - for (p = ps.begin(); p != ps.end(); ++p) + for (list<pair<TypePtr, string> >::const_iterator p = ps.begin(); p != ps.end(); ++p) + { out << nl << typeToString(p->first) << ' ' << p->second << ';'; + } } diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 0a83cfa98d2..567ccc3ae2e 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -51,40 +51,44 @@ main(int argc, char* argv[]) string path = argv[idx] + 2; if (path.length()) + { includePaths.push_back(path); + } for (int i = idx ; i + 1 < argc ; ++i) + { argv[i] = argv[i + 1]; + } --argc; } - else if (strncmp(argv[idx], "-D", 2) == 0 || - strncmp(argv[idx], "-U", 2) == 0) + else if (strncmp(argv[idx], "-D", 2) == 0 || strncmp(argv[idx], "-U", 2) == 0) { cpp += ' '; cpp += argv[idx]; for (int i = idx ; i + 1 < argc ; ++i) + { argv[i] = argv[i + 1]; + } --argc; } - else if (strcmp(argv[idx], "-h") == 0 || - strcmp(argv[idx], "--help") == 0) + else if (strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) { usage(argv[0]); return EXIT_SUCCESS; } - else if (strcmp(argv[idx], "-v") == 0 || - strcmp(argv[idx], "--version") == 0) + else if (strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) { cout << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } - else if (strcmp(argv[idx], "-d") == 0 || - strcmp(argv[idx], "--debug") == 0) + else if (strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0) { debug = true; for (int i = idx ; i + 1 < argc ; ++i) + { argv[i] = argv[i + 1]; + } --argc; } else if (strcmp(argv[idx], "--include-dir") == 0) @@ -98,7 +102,9 @@ main(int argc, char* argv[]) include = argv[idx + 1]; for (int i = idx ; i + 2 < argc ; ++i) + { argv[i] = argv[i + 2]; + } argc -= 2; } else if (strcmp(argv[idx], "--dll-export") == 0) @@ -112,7 +118,9 @@ main(int argc, char* argv[]) dllExport = argv[idx + 1]; for (int i = idx ; i + 2 < argc ; ++i) + { argv[i] = argv[i + 2]; + } argc -= 2; } else if (argv[idx][0] == '-') @@ -122,7 +130,9 @@ main(int argc, char* argv[]) return EXIT_FAILURE; } else + { ++idx; + } } if (argc < 2) diff --git a/cpp/src/slice2docbook/Gen.cpp b/cpp/src/slice2docbook/Gen.cpp index d50b90f99dd..1cc4be16248 100644 --- a/cpp/src/slice2docbook/Gen.cpp +++ b/cpp/src/slice2docbook/Gen.cpp @@ -51,11 +51,14 @@ Slice::Gen::visitUnitStart(const UnitPtr& p) { if (_standAlone) { - O << "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\">"; + O << "<!DOCTYPE article PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\">"; + printHeader(); start("article"); } - - printHeader(); + else + { + printHeader(); + } if (!_noGlobals) { @@ -69,7 +72,9 @@ void Slice::Gen::visitUnitEnd(const UnitPtr& p) { if (_standAlone) + { end(); + } } void @@ -98,7 +103,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { start("varlistentry"); start("term"); - O << nl << addLink((*q)->name(), p); + O << nl << toString(*q, p); end(); start("listitem"); printSummary(*q); @@ -127,7 +132,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { start("varlistentry"); start("term"); - O << nl << addLink((*q)->name(), p); + O << nl << toString(*q, p); end(); start("listitem"); printSummary(*q); @@ -149,7 +154,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { start("varlistentry"); start("term"); - O << nl << addLink((*q)->name(), p); + O << nl << toString(*q, p); end(); start("listitem"); printSummary(*q); @@ -172,7 +177,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { start("varlistentry"); start("term"); - O << nl << addLink((*q)->name(), p); + O << nl << toString(*q, p); end(); start("listitem"); printSummary(*q); @@ -195,7 +200,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { start("varlistentry"); start("term"); - O << nl << addLink((*q)->name(), p); + O << nl << toString(*q, p); end(); start("listitem"); printSummary(*q); @@ -214,13 +219,11 @@ Slice::Gen::visitContainer(const ContainerPtr& p) start("section", "Native Index"); start("variablelist"); - for (NativeList::iterator q = natives.begin(); - q != natives.end(); - ++q) + for (NativeList::iterator q = natives.begin(); q != natives.end(); ++q) { start("varlistentry"); start("term"); - O << nl << addLink((*q)->name(), p); + O << nl << toString(*q, p); end(); start("listitem"); printSummary(*q); @@ -242,7 +245,7 @@ Slice::Gen::visitContainer(const ContainerPtr& p) start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); O.zeroIndent(); - O << nl << "<synopsis>vector< " << typeToString(type) << " > <type>" << (*q)->name() + O << nl << "<synopsis>vector< " << toString(type, p) << " > <type>" << (*q)->name() << "</type>;</synopsis>"; O.restoreIndent(); @@ -266,7 +269,9 @@ Slice::Gen::visitContainer(const ContainerPtr& p) { O << nl << "<structfield>" << *r << "</structfield>"; if (++r != enumerators.end()) + { O << ','; + } } O << eb << ";</synopsis>"; O.restoreIndent(); @@ -304,11 +309,17 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) O.zeroIndent(); O << nl << "<synopsis>"; if (p->isLocal()) + { O << "local "; + } if (p->isInterface()) + { O << "interface"; + } else + { O << "class"; + } O << " <classname>" << p->name() << "</classname>"; ClassList bases = p->bases(); if (!bases.empty() && !bases.front()->isInterface()) @@ -316,7 +327,7 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) O.inc(); O << nl << "extends "; O.inc(); - O << "<classname>" << bases.front()->scoped().substr(2) << "</classname>"; + O << nl << toString(bases.front(), p); bases.pop_front(); O.dec(); O.dec(); @@ -325,16 +336,22 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) { O.inc(); if (p->isInterface()) + { O << nl << "extends "; + } else + { O << nl << "implements "; + } O.inc(); ClassList::iterator q = bases.begin(); while (q != bases.end()) { - O << nl << "<classname>" << (*q)->scoped().substr(2) << "</classname>"; + O << nl << toString(*q, p); if (++q != bases.end()) + { O << ","; + } } O.dec(); O.dec(); @@ -355,7 +372,7 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) { start("varlistentry"); start("term"); - O << nl << addLink((*q)->name(), p); + O << nl << toString(*q, p); end(); start("listitem"); printSummary(*q); @@ -378,7 +395,7 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) { start("varlistentry"); start("term"); - O << nl << addLink((*q)->name(), p); + O << nl << toString(*q, p); end(); start("listitem"); printSummary(*q); @@ -403,15 +420,17 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); O.zeroIndent(); - O << nl << "<synopsis>" << (returnType ? typeToString(returnType) : "<type>void</type>") + O << nl << "<synopsis>" << (returnType ? toString(returnType, p) : "<type>void</type>") << " <function>" << (*q)->name() << "</function>("; O.inc(); TypeStringList::iterator r = inputParams.begin(); while (r != inputParams.end()) { - O << nl << typeToString(r->first) << " <parameter>" << r->second << "</parameter>"; + O << nl << toString(r->first, p) << " <parameter>" << r->second << "</parameter>"; if (++r != inputParams.end()) + { O << ','; + } } if (!outputParams.empty()) { @@ -419,9 +438,11 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) r = outputParams.begin(); while (r != outputParams.end()) { - O << nl << typeToString(r->first) << " <parameter>" << r->second << "</parameter>"; + O << nl << toString(r->first, p) << " <parameter>" << r->second << "</parameter>"; if (++r != outputParams.end()) + { O << ','; + } } } O << ')'; @@ -434,9 +455,11 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) TypeList::iterator r = throws.begin(); while (r != throws.end()) { - O << nl << typeToString(*r); + O << nl << toString(*r, p); if (++r != throws.end()) + { O << ','; + } } O.dec(); O.dec(); @@ -458,7 +481,7 @@ Slice::Gen::visitClassDefStart(const ClassDefPtr& p) start("section id=" + scopedToId((*q)->scoped()), (*q)->name()); O.zeroIndent(); - O << nl << "<synopsis>" << typeToString(type) << " <structfield>" << (*q)->name() + O << nl << "<synopsis>" << toString(type, p) << " <structfield>" << (*q)->name() << "</structfield>;</synopsis>"; O.restoreIndent(); @@ -502,7 +525,9 @@ Slice::Gen::getTagged(const string& tag, string& comment) { begin = comment.find("@" + tag, begin); if (begin == string::npos) + { return result; + } string::size_type pos1 = comment.find_first_not_of(" \t\r\n", begin + tag.size() + 1); if (pos1 == string::npos) @@ -517,7 +542,9 @@ Slice::Gen::getTagged(const string& tag, string& comment) string::size_type pos3 = line.find_last_not_of(" \t\r\n"); if (pos3 != string::npos) + { line.erase(pos3 + 1); + } result.push_back(line); } @@ -529,7 +556,9 @@ Slice::Gen::printComment(const ContainedPtr& p) { ContainerPtr container = ContainerPtr::dynamicCast(p); if (!container) + { container = p->container(); + } string comment = p->comment(); StringList par = getTagged("param", comment); @@ -552,19 +581,21 @@ Slice::Gen::printComment(const ContainedPtr& p) { start("section", "Parameters"); start("variablelist"); - for (StringList::iterator q = par.begin(); - q != par.end(); - ++q) + for (StringList::iterator q = par.begin(); q != par.end(); ++q) { string::size_type pos; string term; pos = q->find_first_of(" \t\r\n"); if (pos != string::npos) + { term = q->substr(0, pos); + } string item; pos = q->find_first_not_of(" \t\r\n", pos); if (pos != string::npos) + { item = q->substr(pos); + } start("varlistentry"); start("term"); @@ -598,23 +629,25 @@ Slice::Gen::printComment(const ContainedPtr& p) start("section", "Exceptions"); start("variablelist"); - for (StringList::iterator q = throws.begin(); - q != throws.end(); - ++q) + for (StringList::iterator q = throws.begin(); q != throws.end(); ++q) { string::size_type pos; string term; pos = q->find_first_of(" \t\r\n"); if (pos != string::npos) + { term = q->substr(0, pos); + } string item; pos = q->find_first_not_of(" \t\r\n", pos); if (pos != string::npos) + { item = q->substr(pos); + } start("varlistentry"); start("term"); - O << nl << addLink(term, container); + O << nl << toString(term, container); end(); start("listitem"); start("para"); @@ -634,12 +667,10 @@ Slice::Gen::printComment(const ContainedPtr& p) start("para"); start("simplelist type=\"inline\""); - for (StringList::iterator q = see.begin(); - q != see.end(); - ++q) + for (StringList::iterator q = see.begin(); q != see.end(); ++q) { start("member"); - O << nl << addLink(*q, container); + O << nl << toString(*q, container); end(); } @@ -674,9 +705,13 @@ Slice::Gen::start(const std::string& element) string::size_type pos = element.find_first_of(" \t"); if (pos == string::npos) + { _elementStack.push(element); + } else + { _elementStack.push(element.substr(0, pos)); + } } void diff --git a/cpp/src/slice2docbook/GenUtil.cpp b/cpp/src/slice2docbook/GenUtil.cpp index 81eede553e3..470eaa3ba9c 100644 --- a/cpp/src/slice2docbook/GenUtil.cpp +++ b/cpp/src/slice2docbook/GenUtil.cpp @@ -15,7 +15,30 @@ using namespace std; using namespace Slice; string -Slice::typeToString(const TypePtr& type) +Slice::getScopedMinimized(const ContainedPtr& contained, const ContainerPtr& container) +{ + string s = contained->scoped(); + ContainerPtr p = container; + ContainedPtr q; + + while((q = ContainedPtr::dynamicCast(p))) + { + string s2 = q->scoped(); + s2 += "::"; + + if (s.find(s2) == 0) + { + return s.substr(s2.size()); + } + + p = q->container(); + } + + return s; +} + +string +Slice::toString(const SyntaxTreeBasePtr& p, const ContainerPtr& container) { static const char* builtinTable[] = { @@ -33,71 +56,60 @@ Slice::typeToString(const TypePtr& type) "LocalObject" }; - string result; - - BuiltinPtr builtin = BuiltinPtr::dynamicCast(type); + BuiltinPtr builtin = BuiltinPtr::dynamicCast(p); if (builtin) - result = "<type>" + string(builtinTable[builtin->kind()]) + "</type>"; + { + return "<type>" + string(builtinTable[builtin->kind()]) + "</type>"; + } + + string tag; + string linkend; + string s; - ProxyPtr proxy = ProxyPtr::dynamicCast(type); + ProxyPtr proxy = ProxyPtr::dynamicCast(p); if (proxy) - result = "<classname>" + proxy->_class()->scoped().substr(2) + "*</classname>"; + { + tag = "classname"; + linkend = scopedToId(proxy->_class()->scoped()); + s = getScopedMinimized(proxy->_class(), container); + s += "*"; + } - ClassDeclPtr cl = ClassDeclPtr::dynamicCast(type); + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(p); if (cl) - result = "<classname>" + cl->scoped().substr(2) + "</classname>"; - - ContainedPtr contained = ContainedPtr::dynamicCast(type); - if (contained) { - if (result.empty()) - result = "<type>" + contained->scoped().substr(2) + "</type>"; - - result = "<link linkend=" + scopedToId(contained->scoped()) + ">" + result + "</link>"; + tag = "classname"; + linkend = scopedToId(cl->scoped()); + s = getScopedMinimized(cl, container); } - if (result.empty()) - result = "???"; + if (s.empty()) + { + ContainedPtr contained = ContainedPtr::dynamicCast(p); + assert(contained); + tag = "type"; + linkend = scopedToId(contained->scoped()); + s = getScopedMinimized(contained, container); + } - return result; + return "<link linkend=" + linkend + "><" + tag + ">" + s + "</" + tag + "></link>"; } string -Slice::addLink(const string& s, const ContainerPtr& container) +Slice::toString(const string& str, const ContainerPtr& container) { + string s = str; + TypeList types = container->lookupType(s, false); if (!types.empty()) { - string result; - - if (ClassDeclPtr::dynamicCast(types.front())) - result = "<classname>" + s + "</classname>"; - else - result = "<type>" + s + "</type>"; - - ContainedPtr p = ContainedPtr::dynamicCast(types.front()); - if (p) - result = "<link linkend=" + scopedToId(p->scoped()) + ">" + result + "</link>"; - - return result; + return toString(types.front(), container); } ContainedList contList = container->lookupContained(s, false); if (!contList.empty()) { - string result = "<link linkend=" + scopedToId(contList.front()->scoped()) + ">"; - - if (ModulePtr::dynamicCast(contList.front())) - result += "<classname>" + s + "</classname>"; - else if (OperationPtr::dynamicCast(contList.front())) - result += "<function>" + s + "</function>"; - else if (DataMemberPtr::dynamicCast(contList.front())) - result += "<structfield>" + s + "</structfield>"; - else - assert(false); - - result += "</link>"; - return result; + return toString(contList.front(), container); } return s; @@ -108,26 +120,17 @@ struct ToFile char operator()(char c) { if (c == ':') + { return '_'; + } else + { return c; + } } }; string -Slice::scopedToFile(const string& scoped) -{ - string result; - if (scoped[0] == ':') - result = scoped.substr(2); - else - result = scoped; - transform(result.begin(), result.end(), result.begin(), ToFile()); - result += ".sgml"; - return result; -} - -string Slice::scopedToId(const string& scoped) { static map<string, int> idMap; @@ -135,9 +138,13 @@ Slice::scopedToId(const string& scoped) string s; if (scoped[0] == ':') + { s = scoped.substr(2); + } else + { s = scoped; + } int id = idMap[s]; if (id == 0) diff --git a/cpp/src/slice2docbook/GenUtil.h b/cpp/src/slice2docbook/GenUtil.h index bec737d7fff..b353f4d0e1e 100644 --- a/cpp/src/slice2docbook/GenUtil.h +++ b/cpp/src/slice2docbook/GenUtil.h @@ -17,9 +17,9 @@ namespace Slice { -std::string typeToString(const TypePtr&); -std::string addLink(const std::string&, const ContainerPtr&); -std::string scopedToFile(const std::string&); +std::string getScopedMinimized(const ContainedPtr&, const ContainerPtr&); +std::string toString(const SyntaxTreeBasePtr&, const ContainerPtr&); +std::string toString(const std::string&, const ContainerPtr&); std::string scopedToId(const std::string&); } diff --git a/cpp/src/slice2docbook/Main.cpp b/cpp/src/slice2docbook/Main.cpp index 7e64961f534..9c59fe1fb80 100644 --- a/cpp/src/slice2docbook/Main.cpp +++ b/cpp/src/slice2docbook/Main.cpp @@ -51,55 +51,62 @@ main(int argc, char* argv[]) string path = argv[idx] + 2; if (path.length()) + { includePaths.push_back(path); + } for (int i = idx ; i + 1 < argc ; ++i) + { argv[i] = argv[i + 1]; + } --argc; } - else if (strncmp(argv[idx], "-D", 2) == 0 || - strncmp(argv[idx], "-U", 2) == 0) + else if (strncmp(argv[idx], "-D", 2) == 0 || strncmp(argv[idx], "-U", 2) == 0) { cpp += ' '; cpp += argv[idx]; for (int i = idx ; i + 1 < argc ; ++i) + { argv[i] = argv[i + 1]; + } --argc; } - else if (strcmp(argv[idx], "-s") == 0 || - strcmp(argv[idx], "--stand-alone") == 0) + else if (strcmp(argv[idx], "-s") == 0 || strcmp(argv[idx], "--stand-alone") == 0) { standAlone = true; for (int i = idx ; i + 1 < argc ; ++i) + { argv[i] = argv[i + 1]; + } --argc; } else if (strcmp(argv[idx], "--no-globals") == 0) { noGlobals = true; for (int i = idx ; i + 1 < argc ; ++i) + { argv[i] = argv[i + 1]; + } --argc; } - else if (strcmp(argv[idx], "-h") == 0 || - strcmp(argv[idx], "--help") == 0) + else if (strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) { usage(argv[0]); return EXIT_SUCCESS; } - else if (strcmp(argv[idx], "-v") == 0 || - strcmp(argv[idx], "--version") == 0) + else if (strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) { cout << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } - else if (strcmp(argv[idx], "-d") == 0 || - strcmp(argv[idx], "--debug") == 0) + else if (strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0) { debug = true; for (int i = idx ; i + 1 < argc ; ++i) + { argv[i] = argv[i + 1]; + } --argc; } else if (argv[idx][0] == '-') @@ -109,7 +116,9 @@ main(int argc, char* argv[]) return EXIT_FAILURE; } else + { ++idx; + } } if (argc < 2) |