diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 1105e8a4ee7..473f2f30f64 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -1173,10 +1173,8 @@ Slice::Container::createClassDef(const string& name, int id, const ClassDefPtr& } else { - bool declared = dynamic_pointer_cast(matches.front()) != nullptr; ostringstream os; - os << "class '" << name << "' was previously " << (declared ? "declared" : "defined") << " as " - << prependA(matches.front()->kindOf()); + os << "class '" << name << "' was previously defined as " << prependA(matches.front()->kindOf()); _unit->error(os.str()); } return nullptr; @@ -1187,29 +1185,27 @@ Slice::Container::createClassDef(const string& name, int id, const ClassDefPtr& return nullptr; } + // Implicitly create a class declaration for each class definition. + // This way the code generator can rely on always having a class declaration available for lookup. ClassDefPtr def = make_shared(shared_from_this(), name, id, base); - _unit->addContent(def); - _contents.push_back(def); + ClassDeclPtr decl = createClassDecl(name); + def->_declaration = decl; + decl->_definition = def; + // Patch forward declarations which may of been created in other openings of this class' module. for (const auto& q : matches) { - ClassDeclPtr decl = dynamic_pointer_cast(q); - decl->_definition = def; + dynamic_pointer_cast(q)->_definition = def; } - // Implicitly create a class declaration for each class definition. - // This way the code generator can rely on always having a class declaration available for lookup. - ClassDeclPtr decl = createClassDecl(name); - def->_declaration = decl; - + _unit->addContent(def); + _contents.push_back(def); return def; } ClassDeclPtr Slice::Container::createClassDecl(const string& name) { - ClassDefPtr def; - ContainedList matches = _unit->findContents(thisScope() + name); for (const auto& p : matches) { @@ -1235,10 +1231,8 @@ Slice::Container::createClassDecl(const string& name) } else { - bool declared = dynamic_pointer_cast(matches.front()) != nullptr; ostringstream os; - os << "class '" << name << "' was previously " << (declared ? "declared" : "defined") << " as " - << prependA(matches.front()->kindOf()); + os << "class '" << name << "' was previously defined as " << prependA(matches.front()->kindOf()); _unit->error(os.str()); } return nullptr; @@ -1263,21 +1257,12 @@ Slice::Container::createClassDecl(const string& name) { return decl; } - - def = dynamic_pointer_cast(q); - assert(def); } } ClassDeclPtr decl = make_shared(shared_from_this(), name); _unit->addContent(decl); _contents.push_back(decl); - - if (def) - { - decl->_definition = def; - } - return decl; } @@ -1320,10 +1305,8 @@ Slice::Container::createInterfaceDef(const string& name, const InterfaceList& ba } else { - bool declared = dynamic_pointer_cast(matches.front()) != nullptr; ostringstream os; - os << "interface '" << name << "' was previously " << (declared ? "declared" : "defined") << " as " - << prependA(matches.front()->kindOf()); + os << "interface '" << name << "' was previously defined as " << prependA(matches.front()->kindOf()); _unit->error(os.str()); } return nullptr; @@ -1336,29 +1319,27 @@ Slice::Container::createInterfaceDef(const string& name, const InterfaceList& ba InterfaceDecl::checkBasesAreLegal(name, bases, _unit); + // Implicitly create an interface declaration for each interface definition. + // This way the code generator can rely on always having an interface declaration available for lookup. InterfaceDefPtr def = make_shared(shared_from_this(), name, bases); - _unit->addContent(def); - _contents.push_back(def); + InterfaceDeclPtr decl = createInterfaceDecl(name); + def->_declaration = decl; + decl->_definition = def; + // Patch forward declarations which may of been created in other openings of this interface's module. for (const auto& q : matches) { - InterfaceDeclPtr decl = dynamic_pointer_cast(q); - decl->_definition = def; + dynamic_pointer_cast(q)->_definition = def; } - // Implicitly create an interface declaration for each interface definition. - // This way the code generator can rely on always having an interface declaration available for lookup. - InterfaceDeclPtr decl = createInterfaceDecl(name); - def->_declaration = decl; - + _unit->addContent(def); + _contents.push_back(def); return def; } InterfaceDeclPtr Slice::Container::createInterfaceDecl(const string& name) { - InterfaceDefPtr def; - ContainedList matches = _unit->findContents(thisScope() + name); for (const auto& p : matches) { @@ -1384,10 +1365,8 @@ Slice::Container::createInterfaceDecl(const string& name) } else { - bool declared = dynamic_pointer_cast(matches.front()) != nullptr; ostringstream os; - os << "interface '" << name << "' was previously " << (declared ? "declared" : "defined") << " as " - << prependA(matches.front()->kindOf()); + os << "interface '" << name << "' was previously defined as " << prependA(matches.front()->kindOf()); _unit->error(os.str()); } return nullptr; @@ -1409,21 +1388,12 @@ Slice::Container::createInterfaceDecl(const string& name) { return decl; } - - def = dynamic_pointer_cast(q); - assert(def); } } InterfaceDeclPtr decl = make_shared(shared_from_this(), name); _unit->addContent(decl); _contents.push_back(decl); - - if (def) - { - decl->_definition = def; - } - return decl; } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index d22fc93c786..d2830c433d1 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1057,9 +1057,7 @@ Slice::Gen::ForwardDeclVisitor::visitModuleEnd(const ModulePtr&) void Slice::Gen::ForwardDeclVisitor::visitClassDecl(const ClassDeclPtr& p) { - ClassDefPtr def = p->definition(); string name = fixKwd(p->name()); - H << nl << "class " << name << ';'; H << nl << "using " << p->name() << "Ptr " << getDeprecatedAttribute(p) << "= ::std::shared_ptr<" << name << ">;" << sp; diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index ee034d11a4e..ffc4baf15d6 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -131,11 +131,7 @@ CodeVisitor::visitClassDecl(const ClassDeclPtr& p) string type = getTypeVar(p); _out << sp << nl << "global " << type << ';'; - - _out << nl << "if(!isset(" << type << "))"; - _out << sb; _out << nl << type << " = IcePHP_declareClass('" << scoped << "');"; - _out << eb; endNamespace(); @@ -156,10 +152,7 @@ CodeVisitor::visitInterfaceDecl(const InterfaceDeclPtr& p) _out << sp << nl << "global " << type << ';'; _out << nl << "global " << type << "Prx;"; - _out << nl << "if(!isset(" << type << "))"; - _out << sb; _out << nl << type << "Prx = IcePHP_declareProxy('" << scoped << "');"; - _out << eb; endNamespace(); @@ -271,12 +264,6 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out << eb; // End of class. - if (_classHistory.count(scoped) == 0 && p->canBeCyclic()) - { - // Emit a forward declaration for the class in case a data member refers to this type. - _out << sp << nl << type << " = IcePHP_declareClass('" << scoped << "');"; - } - { string type; vector seenType; @@ -348,11 +335,6 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) endNamespace(); - if (_classHistory.count(scoped) == 0) - { - _classHistory.insert(scoped); // Avoid redundant declarations. - } - return false; } @@ -583,11 +565,6 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) endNamespace(); - if (_classHistory.count(scoped) == 0) - { - _classHistory.insert(scoped); // Avoid redundant declarations. - } - return false; } diff --git a/cpp/src/slice2py/PythonUtil.cpp b/cpp/src/slice2py/PythonUtil.cpp index 9e81ab114b4..1afa402b87f 100644 --- a/cpp/src/slice2py/PythonUtil.cpp +++ b/cpp/src/slice2py/PythonUtil.cpp @@ -551,7 +551,6 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) { string scoped = p->scoped(); string type = getAbsolute(p, "_t_"); - string classType = getAbsolute(p, "_t_", "Disp"); string abs = getAbsolute(p); string valueName = fixIdent(p->name()); ClassDefPtr base = p->base(); @@ -639,13 +638,6 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out.dec(); - if (_classHistory.count(scoped) == 0 && p->canBeCyclic()) - { - // - // Emit a forward declaration for the class in case a data member refers to this type. - // - _out << sp << nl << "_M_" << type << " = IcePy.declareValue('" << scoped << "')"; - } DataMemberList members = p->dataMembers(); _out << sp << nl << "_M_" << type << " = IcePy.defineValue('" << scoped << "', " << valueName << ", " << p->compactId() << ", "; @@ -708,11 +700,6 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out.dec(); - if (_classHistory.count(scoped) == 0) - { - _classHistory.insert(scoped); // Avoid redundant declarations. - } - return false; } @@ -720,7 +707,6 @@ bool Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { string scoped = p->scoped(); - string type = getAbsolute(p, "_t_"); string classType = getAbsolute(p, "_t_", "Disp"); string abs = getAbsolute(p); string className = fixIdent(p->name()); @@ -977,7 +963,7 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) // _out << sp << nl << "def __str__(self):"; _out.inc(); - _out << nl << "return IcePy.stringify(self, _M_" << getAbsolute(p, "_t_", "Disp") << ")"; + _out << nl << "return IcePy.stringify(self, _M_" << classType << ")"; _out.dec(); _out << sp << nl << "__repr__ = __str__"; @@ -1114,11 +1100,6 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) registerName(className); _out.dec(); - if (_classHistory.count(scoped) == 0) - { - _classHistory.insert(scoped); // Avoid redundant declarations. - } - return false; } diff --git a/cpp/src/slice2rb/RubyUtil.cpp b/cpp/src/slice2rb/RubyUtil.cpp index 801301f5ac0..9be419e8b26 100644 --- a/cpp/src/slice2rb/RubyUtil.cpp +++ b/cpp/src/slice2rb/RubyUtil.cpp @@ -370,17 +370,6 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) _out.dec(); _out << nl << "end"; // End of class. - // - // Emit type descriptions. - // - _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_"); - _out << ')'; - _out.inc(); - _out << nl << "T_" << name << " = ::Ice::__declareClass('" << scoped << "')"; - _out.dec(); - _out << nl << "end"; - _classHistory.insert(scoped); // Avoid redundant declarations. - _out << sp << nl << "T_" << name << ".defineClass(" << name << ", " << p->compactId() << ", " << "false, "; if (!base) @@ -502,18 +491,6 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) _out.dec(); _out << nl << "end"; // End of proxy class. - // - // Emit type descriptions. - // - _out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_"); - _out << "Prx"; - _out << ')'; - _out.inc(); - _out << nl << "T_" << name << "Prx = ::Ice::__declareProxy('" << scoped << "')"; - _out.dec(); - _out << nl << "end"; - _classHistory.insert(scoped); // Avoid redundant declarations. - // // Define each operation. The arguments to __defineOperation are: // diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp index 51231820ce7..3a316a571b3 100644 --- a/cpp/src/slice2swift/SwiftUtil.cpp +++ b/cpp/src/slice2swift/SwiftUtil.cpp @@ -260,6 +260,7 @@ Slice::getTopLevelModule(const ContainedPtr& cont) ModulePtr Slice::getTopLevelModule(const TypePtr& type) { + // TODO this check is redundant. `InterfaceDecl` _is_ a `Contained`. This whole function is weird though. assert(dynamic_pointer_cast(type) || dynamic_pointer_cast(type)); InterfaceDeclPtr proxy = dynamic_pointer_cast(type); diff --git a/cpp/test/Slice/errorDetection/InterfaceMismatch.err b/cpp/test/Slice/errorDetection/InterfaceMismatch.err index 9f0a1fc8fb9..497b507499f 100644 --- a/cpp/test/Slice/errorDetection/InterfaceMismatch.err +++ b/cpp/test/Slice/errorDetection/InterfaceMismatch.err @@ -1,6 +1,6 @@ -InterfaceMismatch.ice:9: class 'Foo1' was previously declared as an interface -InterfaceMismatch.ice:10: class 'Foo1' was previously declared as an interface +InterfaceMismatch.ice:9: class 'Foo1' was previously defined as an interface +InterfaceMismatch.ice:10: class 'Foo1' was previously defined as an interface InterfaceMismatch.ice:13: class 'Foo2' was previously defined as an interface -InterfaceMismatch.ice:16: interface 'Foo3' was previously declared as a class -InterfaceMismatch.ice:17: interface 'Foo3' was previously declared as a class +InterfaceMismatch.ice:16: interface 'Foo3' was previously defined as a class +InterfaceMismatch.ice:17: interface 'Foo3' was previously defined as a class InterfaceMismatch.ice:20: interface 'Foo4' was previously defined as a class diff --git a/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err b/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err index ee131bc6c61..efb925a906f 100644 --- a/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err +++ b/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err @@ -22,13 +22,13 @@ WarningInvalidMetadata.ice:31: warning: the 'cpp:no-default-include' metadata do WarningInvalidMetadata.ice:34: warning: 'amd' metadata cannot be specified as file metadata WarningInvalidMetadata.ice:40: warning: the 'cpp:header-ext' metadata only accepts one argument but a list was provided WarningInvalidMetadata.ice:40: warning: 'cpp:header-ext' metadata cannot be applied to sequences +WarningInvalidMetadata.ice:44: warning: ignoring duplicate metadata: 'deprecated:do not use this' does not match previously applied metadata of 'deprecated' WarningInvalidMetadata.ice:48: warning: ignoring unknown metadata: 'unknown' WarningInvalidMetadata.ice:48: warning: ignoring unknown metadata: 'cpp:unknown' WarningInvalidMetadata.ice:48: warning: ignoring unknown metadata: 'bad:unknown' WarningInvalidMetadata.ice:56: warning: the 'protected' metadata does not take any arguments WarningInvalidMetadata.ice:56: warning: the 'cpp:array' metadata does not take any arguments WarningInvalidMetadata.ice:56: warning: 'cpp:array' metadata can only be applied to operation parameters and return types -WarningInvalidMetadata.ice:44: warning: ignoring duplicate metadata: 'deprecated:do not use this' does not match previously applied metadata of 'deprecated' WarningInvalidMetadata.ice:62: warning: 'cpp:type' metadata cannot be applied to operations with void return type WarningInvalidMetadata.ice:65: warning: 'cpp:array' metadata cannot be applied to operations with void return type WarningInvalidMetadata.ice:68: warning: invalid argument 'my_string' supplied to 'cpp:type' metadata in this context