diff --git a/cpp/src/Slice/MetadataValidation.cpp b/cpp/src/Slice/MetadataValidation.cpp index a4900ec15a8..82bca67642a 100644 --- a/cpp/src/Slice/MetadataValidation.cpp +++ b/cpp/src/Slice/MetadataValidation.cpp @@ -73,7 +73,7 @@ Slice::validateMetadata(const UnitPtr& p, string_view prefix, mapdirective() == directive) { @@ -981,7 +981,7 @@ Slice::Contained::hasMetadata(string_view directive) const optional Slice::Contained::getMetadataArgs(string_view directive) const { - for (const auto& p : getMetadata()) + for (const auto& p : _metadata) { if (p->directive() == directive) { @@ -2679,18 +2679,6 @@ Slice::ClassDef::compactId() const return _compactId; } -MetadataList -Slice::ClassDef::getMetadata() const -{ - return _declaration->getMetadata(); -} - -void -Slice::ClassDef::setMetadata(MetadataList metadata) -{ - _declaration->setMetadata(std::move(metadata)); -} - Slice::ClassDef::ClassDef(const ContainerPtr& container, const string& name, int id, const ClassDefPtr& base) : SyntaxTreeBase(container->unit()), Container(container->unit()), @@ -3112,18 +3100,6 @@ Slice::InterfaceDef::ids() const return ids; } -MetadataList -Slice::InterfaceDef::getMetadata() const -{ - return _declaration->getMetadata(); -} - -void -Slice::InterfaceDef::setMetadata(MetadataList metadata) -{ - _declaration->setMetadata(std::move(metadata)); -} - Slice::InterfaceDef::InterfaceDef(const ContainerPtr& container, const string& name, const InterfaceList& bases) : SyntaxTreeBase(container->unit()), Container(container->unit()), diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h index 3463858aed7..8ddbd85ae58 100644 --- a/cpp/src/Slice/Parser.h +++ b/cpp/src/Slice/Parser.h @@ -375,8 +375,8 @@ namespace Slice int includeLevel() const; - virtual MetadataList getMetadata() const; - virtual void setMetadata(MetadataList metadata); + MetadataList getMetadata() const; + void setMetadata(MetadataList metadata); bool hasMetadata(std::string_view directive) const; std::optional getMetadataArgs(std::string_view directive) const; @@ -572,9 +572,6 @@ namespace Slice int compactId() const; std::string kindOf() const final; - MetadataList getMetadata() const final; - void setMetadata(MetadataList metadata) final; - private: friend class Container; @@ -708,9 +705,6 @@ namespace Slice // Returns the type IDs of all the interfaces in the inheritance tree, in alphabetical order. StringList ids() const; - MetadataList getMetadata() const final; - void setMetadata(MetadataList metadata) final; - private: friend class Container; diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 1b002915892..3cc0f13ff19 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -976,8 +976,8 @@ Slice::Gen::validateMetadata(const UnitPtr& u) typeInfo.extraValidation = [](const MetadataPtr& meta, const SyntaxTreeBasePtr& p) -> optional { // 'cpp:type' can be placed on containers, but only if it is the 'string' flavor of the metadata. - if (dynamic_pointer_cast(p) || dynamic_pointer_cast(p) || - dynamic_pointer_cast(p) || dynamic_pointer_cast(p) || + if (dynamic_pointer_cast(p) || dynamic_pointer_cast(p) || + dynamic_pointer_cast(p) || dynamic_pointer_cast(p) || dynamic_pointer_cast(p)) { const string& argument = meta->arguments(); diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index b5a44b3c665..e1c4fda283a 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -1913,6 +1913,13 @@ Slice::CsGenerator::MetadataVisitor::visitClassDecl(const ClassDeclPtr& p) validate(p); } +bool +Slice::CsGenerator::MetadataVisitor::visitClassDefStart(const ClassDefPtr& p) +{ + validate(p); + return true; +} + bool Slice::CsGenerator::MetadataVisitor::visitExceptionStart(const ExceptionPtr& p) { @@ -2017,7 +2024,7 @@ Slice::CsGenerator::MetadataVisitor::validate(const ContainedPtr& cont) continue; } } - else if (dynamic_pointer_cast(cont) || dynamic_pointer_cast(cont)) + else if (dynamic_pointer_cast(cont) || dynamic_pointer_cast(cont)) { if (directive == "cs:property" && arguments.empty()) { @@ -2025,7 +2032,7 @@ Slice::CsGenerator::MetadataVisitor::validate(const ContainedPtr& cont) continue; } } - else if (dynamic_pointer_cast(cont)) + else if (dynamic_pointer_cast(cont)) { if (directive == "cs:implements" && !arguments.empty()) { @@ -2049,7 +2056,7 @@ Slice::CsGenerator::MetadataVisitor::validate(const ContainedPtr& cont) DataMemberPtr dataMember = dynamic_pointer_cast(cont); StructPtr st = dynamic_pointer_cast(dataMember->container()); ExceptionPtr ex = dynamic_pointer_cast(dataMember->container()); - ClassDeclPtr cl = dynamic_pointer_cast(dataMember->container()); + ClassDefPtr cl = dynamic_pointer_cast(dataMember->container()); static const string csTypePrefix = "cs:type:"; // TODO Seems like this validation only got half written?... } diff --git a/cpp/src/slice2cs/CsUtil.h b/cpp/src/slice2cs/CsUtil.h index 0cba5a0e166..69e44193c99 100644 --- a/cpp/src/slice2cs/CsUtil.h +++ b/cpp/src/slice2cs/CsUtil.h @@ -119,6 +119,7 @@ namespace Slice bool visitUnitStart(const UnitPtr&) final; bool visitModuleStart(const ModulePtr&) final; void visitClassDecl(const ClassDeclPtr&) final; + bool visitClassDefStart(const ClassDefPtr&) final; bool visitExceptionStart(const ExceptionPtr&) final; bool visitStructStart(const StructPtr&) final; void visitOperation(const OperationPtr&) final; diff --git a/cpp/src/slice2java/JavaUtil.cpp b/cpp/src/slice2java/JavaUtil.cpp index fc45c06edc1..51c4a0ca466 100644 --- a/cpp/src/slice2java/JavaUtil.cpp +++ b/cpp/src/slice2java/JavaUtil.cpp @@ -129,6 +129,14 @@ namespace p->setMetadata(std::move(metadata)); } + bool visitClassDefStart(const ClassDefPtr& p) final + { + MetadataList metadata = getMetadata(p); + metadata = validateType(p, metadata); + metadata = validateGetSet(p, metadata); + p->setMetadata(std::move(metadata)); + } + bool visitExceptionStart(const ExceptionPtr& p) final { MetadataList metadata = getMetadata(p); @@ -398,7 +406,7 @@ namespace } else if (directive == "java:implements") { - if (dynamic_pointer_cast(p) || dynamic_pointer_cast(p)) + if (dynamic_pointer_cast(p) || dynamic_pointer_cast(p)) { newMetadata.push_back(m); } @@ -438,7 +446,7 @@ namespace { // The "getset" metadata can only be specified on a class, struct, exception or data member. if (m->directive() == "java:getset" && - (!dynamic_pointer_cast(p) && !dynamic_pointer_cast(p) && + (!dynamic_pointer_cast(p) && !dynamic_pointer_cast(p) && !dynamic_pointer_cast(p) && !dynamic_pointer_cast(p))) { p->unit()->warning(m->file(), m->line(), InvalidMetadata, "invalid metadata for " + p->kindOf()); diff --git a/cpp/src/slice2py/PythonUtil.cpp b/cpp/src/slice2py/PythonUtil.cpp index 537d0fc1fce..ab33a7e37b4 100644 --- a/cpp/src/slice2py/PythonUtil.cpp +++ b/cpp/src/slice2py/PythonUtil.cpp @@ -137,7 +137,9 @@ namespace Slice bool visitUnitStart(const UnitPtr&) final; bool visitModuleStart(const ModulePtr&) final; void visitClassDecl(const ClassDeclPtr&) final; + bool visitClassDefStart(const ClassDefPtr&) final; void visitInterfaceDecl(const InterfaceDeclPtr&) final; + bool visitInterfaceDefStart(const InterfaceDefPtr&) final; bool visitExceptionStart(const ExceptionPtr&) final; bool visitStructStart(const StructPtr&) final; void visitOperation(const OperationPtr&) final; @@ -2973,12 +2975,26 @@ Slice::Python::MetadataVisitor::visitClassDecl(const ClassDeclPtr& p) reject(p); } +bool +Slice::Python::MetadataVisitor::visitClassDefStart(const ClassDefPtr& p) +{ + reject(p); + return true; +} + void Slice::Python::MetadataVisitor::visitInterfaceDecl(const InterfaceDeclPtr& p) { reject(p); } +bool +Slice::Python::MetadataVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) +{ + reject(p); + return true; +} + bool Slice::Python::MetadataVisitor::visitExceptionStart(const ExceptionPtr& p) { diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp index 410dc4f1ea2..203a64c2fd2 100644 --- a/cpp/src/slice2swift/SwiftUtil.cpp +++ b/cpp/src/slice2swift/SwiftUtil.cpp @@ -2118,12 +2118,12 @@ SwiftGenerator::MetadataVisitor::validate(const SyntaxTreeBasePtr& p, const Cont continue; } - if (dynamic_pointer_cast(p) && directive == "swift:inherits" && !arguments.empty()) + if (dynamic_pointer_cast(p) && directive == "swift:inherits" && !arguments.empty()) { continue; } - if ((dynamic_pointer_cast(p) || dynamic_pointer_cast(p) || + if ((dynamic_pointer_cast(p) || dynamic_pointer_cast(p) || dynamic_pointer_cast(p) || dynamic_pointer_cast(p)) && directive == "swift:attribute" && !arguments.empty()) { diff --git a/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err b/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err index f69994700d4..df2ade7c119 100644 --- a/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err +++ b/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err @@ -22,7 +22,7 @@ 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:44: warning: ignoring duplicate metadata: 'deprecated' has already been applied in this context 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'