diff --git a/cpp/src/Slice/Scanner.cpp b/cpp/src/Slice/Scanner.cpp index a9551ccbe6d..0bde7d88f00 100644 --- a/cpp/src/Slice/Scanner.cpp +++ b/cpp/src/Slice/Scanner.cpp @@ -1721,7 +1721,7 @@ case 16: YY_RULE_SETUP #line 233 "src/Slice/Scanner.l" { - currentUnit->warning(All, "unknown escape sequence in string literal: `" + string(yytext) + "'"); + currentUnit->warning(All, "unknown escape sequence in string literal: '" + string{yytext} + "'"); StringTokPtr str = dynamic_pointer_cast(*yylval); // Escape the entire sequence. diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l index 16f69c58716..3f19cc96ad1 100644 --- a/cpp/src/Slice/Scanner.l +++ b/cpp/src/Slice/Scanner.l @@ -230,7 +230,7 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?{dec}+{expo /* Matches an unknown escape value. This rule has a lower priority than all the other escape rules because * it only matches 2 characters (the lowest any match), and it's beneath the others. */ "\\". { - currentUnit->warning(All, "unknown escape sequence in string literal: `" + string(yytext) + "'"); + currentUnit->warning(All, "unknown escape sequence in string literal: '" + string{yytext} + "'"); StringTokPtr str = dynamic_pointer_cast(*yylval); // Escape the entire sequence. diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 2827198fa92..8c8c789735b 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -786,7 +786,7 @@ Slice::Gen::generate(const UnitPtr& p) { ostringstream ostr; ostr << "ignoring invalid file metadata '" << *metadata << "'"; - dc->warning(InvalidMetadata, file, -1, ostr.str()); + dc->warning(InvalidMetadata, metadata->file(), metadata->line(), ostr.str()); fileMetadata.remove(metadata); } } @@ -800,7 +800,7 @@ Slice::Gen::generate(const UnitPtr& p) { ostringstream ostr; ostr << "ignoring invalid file metadata '" << *metadata << "'"; - dc->warning(InvalidMetadata, file, -1, ostr.str()); + dc->warning(InvalidMetadata, metadata->file(), metadata->line(), ostr.str()); fileMetadata.remove(metadata); } } @@ -947,7 +947,7 @@ Slice::Gen::MetadataVisitor::visitUnitStart(const UnitPtr& unit) ostringstream ostr; ostr << "ignoring invalid file metadata '" << *s << "': directive can appear only once per file"; - dc->warning(InvalidMetadata, file, -1, ostr.str()); + dc->warning(InvalidMetadata, s->file(), s->line(), ostr.str()); fileMetadata.remove(s); } seenHeaderExtension = true; @@ -960,7 +960,7 @@ Slice::Gen::MetadataVisitor::visitUnitStart(const UnitPtr& unit) ostringstream ostr; ostr << "ignoring invalid file metadata '" << *s << "': directive can appear only once per file"; - dc->warning(InvalidMetadata, file, -1, ostr.str()); + dc->warning(InvalidMetadata, s->file(), s->line(), ostr.str()); fileMetadata.remove(s); } seenSourceExtension = true; @@ -973,7 +973,7 @@ Slice::Gen::MetadataVisitor::visitUnitStart(const UnitPtr& unit) ostringstream ostr; ostr << "ignoring invalid file metadata '" << *s << "': directive can appear only once per file"; - dc->warning(InvalidMetadata, file, -1, ostr.str()); + dc->warning(InvalidMetadata, s->file(), s->line(), ostr.str()); fileMetadata.remove(s); } seenDllExport = true; @@ -986,7 +986,7 @@ Slice::Gen::MetadataVisitor::visitUnitStart(const UnitPtr& unit) ostringstream ostr; ostr << "ignoring invalid file metadata '" << *s << "'"; - dc->warning(InvalidMetadata, file, -1, ostr.str()); + dc->warning(InvalidMetadata, s->file(), s->line(), ostr.str()); fileMetadata.remove(s); } } @@ -999,34 +999,34 @@ Slice::Gen::MetadataVisitor::visitUnitStart(const UnitPtr& unit) bool Slice::Gen::MetadataVisitor::visitModuleStart(const ModulePtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p->getMetadata(), p->file())); return true; } void Slice::Gen::MetadataVisitor::visitClassDecl(const ClassDeclPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p->getMetadata(), p->file())); } bool Slice::Gen::MetadataVisitor::visitClassDefStart(const ClassDefPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p->getMetadata(), p->file())); return true; } bool Slice::Gen::MetadataVisitor::visitExceptionStart(const ExceptionPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p->getMetadata(), p->file())); return true; } bool Slice::Gen::MetadataVisitor::visitStructStart(const StructPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p->getMetadata(), p->file())); return true; } @@ -1047,7 +1047,7 @@ Slice::Gen::MetadataVisitor::visitOperation(const OperationPtr& p) { ostringstream ostr; ostr << "ignoring invalid metadata '" << *s << "' for operation with void return type"; - dc->warning(InvalidMetadata, p->file(), p->line(), ostr.str()); + dc->warning(InvalidMetadata, s->file(), s->line(), ostr.str()); metadata.remove(s); } } @@ -1055,43 +1055,43 @@ Slice::Gen::MetadataVisitor::visitOperation(const OperationPtr& p) } else { - p->setMetadata(validate(returnType, p->getMetadata(), p->file(), p->line(), true)); + p->setMetadata(validate(returnType, p->getMetadata(), p->file(), true)); } for (const auto& param : p->parameters()) { - param->setMetadata(validate(param->type(), param->getMetadata(), p->file(), param->line(), true)); + param->setMetadata(validate(param->type(), param->getMetadata(), p->file(), true)); } } void Slice::Gen::MetadataVisitor::visitDataMember(const DataMemberPtr& p) { - p->setMetadata(validate(p->type(), p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p->type(), p->getMetadata(), p->file())); } void Slice::Gen::MetadataVisitor::visitSequence(const SequencePtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p->getMetadata(), p->file())); } void Slice::Gen::MetadataVisitor::visitDictionary(const DictionaryPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p->getMetadata(), p->file())); } void Slice::Gen::MetadataVisitor::visitEnum(const EnumPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p->getMetadata(), p->file())); } void Slice::Gen::MetadataVisitor::visitConst(const ConstPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p->getMetadata(), p->file())); } MetadataList @@ -1099,7 +1099,6 @@ Slice::Gen::MetadataVisitor::validate( const SyntaxTreeBasePtr& cont, MetadataList metadata, const string& file, - int line, bool operation) { const UnitPtr ut = cont->unit(); @@ -1118,7 +1117,7 @@ Slice::Gen::MetadataVisitor::validate( { ostringstream ostr; ostr << "ignoring invalid metadata '" << *meta << "'"; - dc->warning(InvalidMetadata, file, line, ostr.str()); + dc->warning(InvalidMetadata, meta->file(), meta->line(), ostr.str()); metadata.remove(meta); continue; } @@ -1184,7 +1183,7 @@ Slice::Gen::MetadataVisitor::validate( ostringstream ostr; ostr << "ignoring invalid metadata '" << *meta << "'"; - dc->warning(InvalidMetadata, file, line, ostr.str()); + dc->warning(InvalidMetadata, meta->file(), meta->line(), ostr.str()); metadata.remove(meta); } return metadata; diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index 8409c5809dd..85040c90094 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -218,7 +218,14 @@ namespace Slice void visitConst(const ConstPtr&) final; private: - MetadataList validate(const SyntaxTreeBasePtr&, MetadataList, const std::string&, int, bool = false); + /// Validates any 'cpp' specific metadata that's been applied to `cont`. + /// Additional metadata to validate can also be passed in with the `metadata` field. + /// For example, type metadata applied to a sequence where it's being used instead of just defined. + MetadataList validate( + const SyntaxTreeBasePtr& cont, + MetadataList metadata, + const std::string& file, + bool operation = false); }; static void validateMetadata(const UnitPtr&); diff --git a/cpp/src/slice2cs/CsUtil.cpp b/cpp/src/slice2cs/CsUtil.cpp index eea19193cd8..25b06e91cb7 100644 --- a/cpp/src/slice2cs/CsUtil.cpp +++ b/cpp/src/slice2cs/CsUtil.cpp @@ -1982,7 +1982,7 @@ Slice::CsGenerator::MetadataVisitor::visitUnitStart(const UnitPtr& unit) { ostringstream msg; msg << "ignoring invalid file metadata '" << *metadata << "'"; - dc->warning(InvalidMetadata, file, -1, msg.str()); + dc->warning(InvalidMetadata, metadata->file(), metadata->line(), msg.str()); continue; } newFileMetadata.push_back(metadata); @@ -2173,7 +2173,7 @@ Slice::CsGenerator::MetadataVisitor::validate(const ContainedPtr& cont) ostringstream msg; msg << "ignoring invalid metadata '" << *metadata << "'"; - dc->warning(InvalidMetadata, cont->file(), cont->line(), msg.str()); + dc->warning(InvalidMetadata, metadata->file(), metadata->line(), msg.str()); continue; } newLocalMetadata.push_back(metadata); diff --git a/cpp/src/slice2java/JavaUtil.cpp b/cpp/src/slice2java/JavaUtil.cpp index a073dfad9dc..efb40928197 100644 --- a/cpp/src/slice2java/JavaUtil.cpp +++ b/cpp/src/slice2java/JavaUtil.cpp @@ -102,7 +102,7 @@ namespace { ostringstream msg; msg << "ignoring invalid file metadata '" << *metadata << "'"; - dc->warning(InvalidMetadata, file, -1, msg.str()); + dc->warning(InvalidMetadata, metadata->file(), metadata->line(), msg.str()); fileMetadata.remove(metadata); } } @@ -115,7 +115,7 @@ namespace bool visitModuleStart(const ModulePtr& p) final { MetadataList metadata = getMetadata(p); - metadata = validateType(p, metadata, p->file(), p->line()); + metadata = validateType(p, metadata, p->file()); metadata = validateGetSet(p, metadata); p->setMetadata(std::move(metadata)); return true; @@ -124,7 +124,7 @@ namespace void visitClassDecl(const ClassDeclPtr& p) final { MetadataList metadata = getMetadata(p); - metadata = validateType(p, metadata, p->file(), p->line()); + metadata = validateType(p, metadata, p->file()); metadata = validateGetSet(p, metadata); p->setMetadata(std::move(metadata)); } @@ -132,7 +132,7 @@ namespace bool visitClassDefStart(const ClassDefPtr& p) final { MetadataList metadata = getMetadata(p); - metadata = validateType(p, metadata, p->file(), p->line()); + metadata = validateType(p, metadata, p->file()); metadata = validateGetSet(p, metadata); p->setMetadata(std::move(metadata)); return true; @@ -141,7 +141,7 @@ namespace bool visitExceptionStart(const ExceptionPtr& p) final { MetadataList metadata = getMetadata(p); - metadata = validateType(p, metadata, p->file(), p->line()); + metadata = validateType(p, metadata, p->file()); metadata = validateGetSet(p, metadata); p->setMetadata(std::move(metadata)); return true; @@ -150,7 +150,7 @@ namespace bool visitStructStart(const StructPtr& p) final { MetadataList metadata = getMetadata(p); - metadata = validateType(p, metadata, p->file(), p->line()); + metadata = validateType(p, metadata, p->file()); metadata = validateGetSet(p, metadata); p->setMetadata(std::move(metadata)); return true; @@ -182,7 +182,7 @@ namespace } else { - metadata = validateType(returnType, metadata, p->file(), p->line()); + metadata = validateType(returnType, metadata, p->file()); metadata = validateGetSet(p, metadata); } p->setMetadata(std::move(metadata)); @@ -190,7 +190,7 @@ namespace for (const auto& param : p->parameters()) { metadata = getMetadata(param); - metadata = validateType(param->type(), metadata, param->file(), param->line()); + metadata = validateType(param->type(), metadata, param->file()); metadata = validateGetSet(param, metadata); param->setMetadata(std::move(metadata)); } @@ -199,7 +199,7 @@ namespace void visitDataMember(const DataMemberPtr& p) final { MetadataList metadata = getMetadata(p); - metadata = validateType(p->type(), metadata, p->file(), p->line()); + metadata = validateType(p->type(), metadata, p->file()); metadata = validateGetSet(p, metadata); p->setMetadata(std::move(metadata)); } @@ -210,7 +210,6 @@ namespace MetadataList newMetadata; const string file = p->file(); - int line = p->line(); const UnitPtr unt = p->unit(); const DefinitionContextPtr dc = unt->findDefinitionContext(file); @@ -228,7 +227,7 @@ namespace ostringstream msg; msg << "ignoring invalid metadata '" << *m << "': this metadata can only be used with a byte sequence"; - dc->warning(InvalidMetadata, file, line, msg.str()); + dc->warning(InvalidMetadata, m->file(), m->line(), msg.str()); continue; } newMetadata.push_back(m); @@ -244,14 +243,14 @@ namespace { ostringstream msg; msg << "ignoring invalid metadata '" << *m << "': this metadata can not be used with this type"; - dc->warning(InvalidMetadata, file, line, msg.str()); + dc->warning(InvalidMetadata, m->file(), m->line(), msg.str()); continue; } newMetadata.push_back(m); } } - metadata = validateType(p, metadata, file, line); + metadata = validateType(p, metadata, file); metadata = validateGetSet(p, metadata); newMetadata.insert(newMetadata.begin(), metadata.begin(), metadata.end()); p->setMetadata(std::move(newMetadata)); @@ -260,7 +259,7 @@ namespace void visitDictionary(const DictionaryPtr& p) final { MetadataList metadata = getMetadata(p); - metadata = validateType(p, metadata, p->file(), p->line()); + metadata = validateType(p, metadata, p->file()); metadata = validateGetSet(p, metadata); p->setMetadata(std::move(metadata)); } @@ -268,7 +267,7 @@ namespace void visitEnum(const EnumPtr& p) final { MetadataList metadata = getMetadata(p); - metadata = validateType(p, metadata, p->file(), p->line()); + metadata = validateType(p, metadata, p->file()); metadata = validateGetSet(p, metadata); p->setMetadata(std::move(metadata)); } @@ -276,7 +275,7 @@ namespace void visitConst(const ConstPtr& p) final { MetadataList metadata = getMetadata(p); - metadata = validateType(p, metadata, p->file(), p->line()); + metadata = validateType(p, metadata, p->file()); metadata = validateGetSet(p, metadata); p->setMetadata(std::move(metadata)); } @@ -366,8 +365,7 @@ namespace return result; } - MetadataList - validateType(const SyntaxTreeBasePtr& p, const MetadataList& metadata, const string& file, int line) + MetadataList validateType(const SyntaxTreeBasePtr& p, const MetadataList& metadata, const string& file) { const UnitPtr unt = p->unit(); const DefinitionContextPtr dc = unt->findDefinitionContext(file); @@ -396,7 +394,7 @@ namespace } ostringstream msg; msg << "ignoring invalid metadata '" << *m << "' for " << str; - dc->warning(InvalidMetadata, file, line, msg.str()); + dc->warning(InvalidMetadata, m->file(), m->line(), msg.str()); } else if (directive == "java:buffer") { @@ -416,14 +414,14 @@ namespace ostringstream msg; msg << "ignoring invalid metadata '" << *m << "'"; - dc->warning(InvalidMetadata, file, line, msg.str()); + dc->warning(InvalidMetadata, m->file(), m->line(), msg.str()); } else if (directive == "java:serializable") { // Only valid in sequence definition which is checked in visitSequence ostringstream msg; msg << "ignoring invalid metadata '" << *m << "'"; - dc->warning(InvalidMetadata, file, line, msg.str()); + dc->warning(InvalidMetadata, m->file(), m->line(), msg.str()); } else if (directive == "java:implements") { @@ -435,7 +433,7 @@ namespace { ostringstream msg; msg << "ignoring invalid metadata '" << *m << "'"; - dc->warning(InvalidMetadata, file, line, msg.str()); + dc->warning(InvalidMetadata, m->file(), m->line(), msg.str()); } } else if (directive == "java:package") @@ -449,7 +447,7 @@ namespace { ostringstream msg; msg << "ignoring invalid metadata '" << *m << "'"; - dc->warning(InvalidMetadata, file, line, msg.str()); + dc->warning(InvalidMetadata, m->file(), m->line(), msg.str()); } } else diff --git a/cpp/src/slice2py/PythonUtil.cpp b/cpp/src/slice2py/PythonUtil.cpp index 75c733ead6c..b9d5dabf8a0 100644 --- a/cpp/src/slice2py/PythonUtil.cpp +++ b/cpp/src/slice2py/PythonUtil.cpp @@ -151,7 +151,7 @@ namespace Slice private: /// Validates sequence metadata. - MetadataList validateSequence(const string&, int, const TypePtr&, const MetadataList&); + MetadataList validateSequence(const ContainedPtr&, const TypePtr&); /// Checks a definition that doesn't currently support Python metadata. void reject(const ContainedPtr&); @@ -2933,7 +2933,7 @@ Slice::Python::MetadataVisitor::visitUnitStart(const UnitPtr& unit) ostringstream msg; msg << "ignoring invalid file metadata '" << *meta << "'"; - dc->warning(InvalidMetadata, file, -1, msg.str()); + dc->warning(InvalidMetadata, meta->file(), meta->line(), msg.str()); fileMetadata.remove(meta); } } @@ -2961,7 +2961,7 @@ Slice::Python::MetadataVisitor::visitModuleStart(const ModulePtr& p) ostringstream msg; msg << "ignoring invalid file metadata '" << *meta << "'"; - p->definitionContext()->warning(InvalidMetadata, p->file(), -1, msg.str()); + p->definitionContext()->warning(InvalidMetadata, meta->file(), meta->line(), msg.str()); metadata.remove(meta); } } @@ -3016,25 +3016,25 @@ Slice::Python::MetadataVisitor::visitOperation(const OperationPtr& p) TypePtr ret = p->returnType(); if (ret) { - validateSequence(p->file(), p->line(), ret, p->getMetadata()); + validateSequence(p, ret); } for (const auto& param : p->parameters()) { - validateSequence(p->file(), param->line(), param->type(), param->getMetadata()); + validateSequence(param, param->type()); } } void Slice::Python::MetadataVisitor::visitDataMember(const DataMemberPtr& p) { - validateSequence(p->file(), p->line(), p->type(), p->getMetadata()); + validateSequence(p, p->type()); } void Slice::Python::MetadataVisitor::visitSequence(const SequencePtr& p) { - p->setMetadata(validateSequence(p->file(), p->line(), p, p->getMetadata())); + p->setMetadata(validateSequence(p, p)); } void @@ -3056,18 +3056,14 @@ Slice::Python::MetadataVisitor::visitConst(const ConstPtr& p) } MetadataList -Slice::Python::MetadataVisitor::validateSequence( - const string& file, - int line, - const TypePtr& type, - const MetadataList& metadata) +Slice::Python::MetadataVisitor::validateSequence(const ContainedPtr& cont, const TypePtr& type) { const UnitPtr ut = type->unit(); - const DefinitionContextPtr dc = ut->findDefinitionContext(file); + const DefinitionContextPtr dc = ut->findDefinitionContext(cont->file()); assert(dc); static const string prefix = "python:"; - MetadataList newMetadata = metadata; + MetadataList newMetadata = cont->getMetadata(); for (MetadataList::const_iterator p = newMetadata.begin(); p != newMetadata.end();) { MetadataPtr s = *p++; @@ -3123,7 +3119,7 @@ Slice::Python::MetadataVisitor::validateSequence( } ostringstream msg; msg << "ignoring invalid metadata '" << *s << "'"; - dc->warning(InvalidMetadata, file, line, msg.str()); + dc->warning(InvalidMetadata, s->file(), s->line(), msg.str()); newMetadata.remove(s); } } @@ -3146,7 +3142,7 @@ Slice::Python::MetadataVisitor::reject(const ContainedPtr& cont) { ostringstream msg; msg << "ignoring invalid metadata '" << *s << "'"; - dc->warning(InvalidMetadata, cont->file(), cont->line(), msg.str()); + dc->warning(InvalidMetadata, s->file(), s->line(), msg.str()); localMetadata.remove(s); } } diff --git a/cpp/src/slice2swift/SwiftUtil.cpp b/cpp/src/slice2swift/SwiftUtil.cpp index 227174e3b40..b1afc0b0863 100644 --- a/cpp/src/slice2swift/SwiftUtil.cpp +++ b/cpp/src/slice2swift/SwiftUtil.cpp @@ -1709,7 +1709,7 @@ SwiftGenerator::MetadataVisitor::visitModuleStart(const ModulePtr& p) } } } - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p)); return true; } @@ -2376,12 +2376,12 @@ SwiftGenerator::writeDispatchOperation(::IceInternal::Output& out, const Operati bool SwiftGenerator::MetadataVisitor::visitClassDefStart(const ClassDefPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p)); for (const auto& member : p->dataMembers()) { // TODO we should probably be passing `member` instead of `member->type()`. // Otherwise I'm pretty sure we're just skipping the data-member metadata. - member->setMetadata(validate(member->type(), member->getMetadata(), p->file(), member->line())); + member->setMetadata(validate(member->type(), member)); } return true; } @@ -2389,27 +2389,27 @@ SwiftGenerator::MetadataVisitor::visitClassDefStart(const ClassDefPtr& p) bool SwiftGenerator::MetadataVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p)); return true; } void SwiftGenerator::MetadataVisitor::visitOperation(const OperationPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p)); for (const auto& param : p->parameters()) { - param->setMetadata(validate(param->type(), param->getMetadata(), param->file(), param->line())); + param->setMetadata(validate(param->type(), param)); } } bool SwiftGenerator::MetadataVisitor::visitExceptionStart(const ExceptionPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p)); for (const auto& member : p->dataMembers()) { - member->setMetadata(validate(member->type(), member->getMetadata(), member->file(), member->line())); + member->setMetadata(validate(member->type(), member)); } return true; } @@ -2417,10 +2417,10 @@ SwiftGenerator::MetadataVisitor::visitExceptionStart(const ExceptionPtr& p) bool SwiftGenerator::MetadataVisitor::visitStructStart(const StructPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p)); for (const auto& member : p->dataMembers()) { - member->setMetadata(validate(member->type(), member->getMetadata(), member->file(), member->line())); + member->setMetadata(validate(member->type(), member)); } return true; } @@ -2428,7 +2428,7 @@ SwiftGenerator::MetadataVisitor::visitStructStart(const StructPtr& p) void SwiftGenerator::MetadataVisitor::visitSequence(const SequencePtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p)); } void @@ -2444,7 +2444,7 @@ SwiftGenerator::MetadataVisitor::visitDictionary(const DictionaryPtr& p) { ostringstream msg; msg << "ignoring invalid metadata '" << *metadata << "' for dictionary key type"; - dc->warning(InvalidMetadata, p->file(), p->line(), msg.str()); + dc->warning(InvalidMetadata, metadata->file(), metadata->line(), msg.str()); } } @@ -2454,40 +2454,36 @@ SwiftGenerator::MetadataVisitor::visitDictionary(const DictionaryPtr& p) { ostringstream msg; msg << "ignoring invalid metadata '" << *metadata << "' for dictionary value type"; - dc->warning(InvalidMetadata, p->file(), p->line(), msg.str()); + dc->warning(InvalidMetadata, metadata->file(), metadata->line(), msg.str()); } } - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p)); } void SwiftGenerator::MetadataVisitor::visitEnum(const EnumPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p)); } void SwiftGenerator::MetadataVisitor::visitConst(const ConstPtr& p) { - p->setMetadata(validate(p, p->getMetadata(), p->file(), p->line())); + p->setMetadata(validate(p, p)); } MetadataList -SwiftGenerator::MetadataVisitor::validate( - const SyntaxTreeBasePtr& cont, - const MetadataList& metadata, - const string& file, - int line) +SwiftGenerator::MetadataVisitor::validate(const SyntaxTreeBasePtr& p, const ContainedPtr& cont) { - MetadataList newMetadata = metadata; - const UnitPtr ut = cont->unit(); - const DefinitionContextPtr dc = ut->findDefinitionContext(file); + MetadataList newMetadata = cont->getMetadata(); + const UnitPtr ut = p->unit(); + const DefinitionContextPtr dc = ut->findDefinitionContext(cont->file()); assert(dc); - for (MetadataList::const_iterator p = newMetadata.begin(); p != newMetadata.end();) + for (MetadataList::const_iterator m = newMetadata.begin(); m != newMetadata.end();) { - MetadataPtr meta = *p++; + MetadataPtr meta = *m++; string_view directive = meta->directive(); string_view arguments = meta->arguments(); @@ -2496,18 +2492,18 @@ SwiftGenerator::MetadataVisitor::validate( continue; } - if (dynamic_pointer_cast(cont) && directive == "swift:module" && !arguments.empty()) + if (dynamic_pointer_cast(p) && directive == "swift:module" && !arguments.empty()) { continue; } - if (dynamic_pointer_cast(cont) && directive == "swift:inherits" && !arguments.empty()) + if (dynamic_pointer_cast(p) && directive == "swift:inherits" && !arguments.empty()) { continue; } - if ((dynamic_pointer_cast(cont) || dynamic_pointer_cast(cont) || - dynamic_pointer_cast(cont) || dynamic_pointer_cast(cont)) && + if ((dynamic_pointer_cast(p) || dynamic_pointer_cast(p) || + dynamic_pointer_cast(p) || dynamic_pointer_cast(p)) && directive == "swift:attribute" && !arguments.empty()) { continue; @@ -2515,7 +2511,7 @@ SwiftGenerator::MetadataVisitor::validate( ostringstream msg; msg << "ignoring invalid metadata '" << *meta << "'"; - dc->warning(InvalidMetadata, file, line, msg.str()); + dc->warning(InvalidMetadata, meta->file(), meta->line(), msg.str()); newMetadata.remove(meta); continue; } diff --git a/cpp/src/slice2swift/SwiftUtil.h b/cpp/src/slice2swift/SwiftUtil.h index 184470ee1ae..d0d8e4c2268 100644 --- a/cpp/src/slice2swift/SwiftUtil.h +++ b/cpp/src/slice2swift/SwiftUtil.h @@ -159,7 +159,7 @@ namespace Slice bool shouldVisitIncludedDefinitions() const final { return true; } private: - MetadataList validate(const SyntaxTreeBasePtr&, const MetadataList&, const std::string&, int); + MetadataList validate(const SyntaxTreeBasePtr&, const ContainedPtr&); typedef std::map ModuleMap; typedef std::map ModulePrefix; diff --git a/cpp/test/Slice/errorDetection/ConstDef.err b/cpp/test/Slice/errorDetection/ConstDef.err index 3188d5f65d8..9a1e8e244c5 100644 --- a/cpp/test/Slice/errorDetection/ConstDef.err +++ b/cpp/test/Slice/errorDetection/ConstDef.err @@ -22,7 +22,7 @@ ConstDef.ice:118: initializer `256' for constant `b4' out of range for type byte ConstDef.ice:130: initializer `32767' for constant `c5' out of range for type byte ConstDef.ice:131: initializer `2147483647' for constant `c6' out of range for type short ConstDef.ice:132: initializer `9223372036854775807' for constant `c7' out of range for type int -ConstDef.ice:143: warning: unknown escape sequence in string literal: `\g' +ConstDef.ice:143: warning: unknown escape sequence in string literal: '\g' ConstDef.ice:144: unknown escape sequence in string literal: `\u000N' ConstDef.ice:145: unknown escape sequence in string literal: `\U0000000K' ConstDef.ice:146: octal escape sequence out of range: `\455' diff --git a/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err b/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err index efd49bc27d4..35d855bc865 100644 --- a/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err +++ b/cpp/test/Slice/errorDetection/WarningInvalidMetadata.err @@ -1,21 +1,21 @@ -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:header-ext:hh': directive can appear only once per file -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:source-ext:cc': directive can appear only once per file -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:dll-export:Test': directive can appear only once per file -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:header-ext' -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:header-ext' -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:source-ext' -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:source-ext' -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:dll-export' -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:dll-export' -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:include' -WarningInvalidMetadata.ice: warning: ignoring invalid file metadata 'cpp:include' -WarningInvalidMetadata.ice:35: warning: ignoring invalid metadata 'cpp:type:std::list<::std::string>' for operation with void return type -WarningInvalidMetadata.ice:38: warning: ignoring invalid metadata 'cpp:array' for operation with void return type +WarningInvalidMetadata.ice:6: warning: ignoring invalid file metadata 'cpp:header-ext:hh': directive can appear only once per file +WarningInvalidMetadata.ice:9: warning: ignoring invalid file metadata 'cpp:source-ext:cc': directive can appear only once per file +WarningInvalidMetadata.ice:12: warning: ignoring invalid file metadata 'cpp:dll-export:Test': directive can appear only once per file +WarningInvalidMetadata.ice:14: warning: ignoring invalid file metadata 'cpp:header-ext' +WarningInvalidMetadata.ice:15: warning: ignoring invalid file metadata 'cpp:header-ext' +WarningInvalidMetadata.ice:17: warning: ignoring invalid file metadata 'cpp:source-ext' +WarningInvalidMetadata.ice:18: warning: ignoring invalid file metadata 'cpp:source-ext' +WarningInvalidMetadata.ice:20: warning: ignoring invalid file metadata 'cpp:dll-export' +WarningInvalidMetadata.ice:21: warning: ignoring invalid file metadata 'cpp:dll-export' +WarningInvalidMetadata.ice:23: warning: ignoring invalid file metadata 'cpp:include' +WarningInvalidMetadata.ice:24: warning: ignoring invalid file metadata 'cpp:include' +WarningInvalidMetadata.ice:34: warning: ignoring invalid metadata 'cpp:type:std::list<::std::string>' for operation with void return type +WarningInvalidMetadata.ice:37: warning: ignoring invalid metadata 'cpp:array' for operation with void return type WarningInvalidMetadata.ice:40: warning: ignoring invalid metadata 'cpp:type:my_string' WarningInvalidMetadata.ice:42: warning: ignoring invalid metadata 'cpp:view-type:my_string' -WarningInvalidMetadata.ice:47: warning: ignoring invalid metadata 'cpp:const' -WarningInvalidMetadata.ice:47: warning: ignoring invalid metadata 'cpp:ice_print' -WarningInvalidMetadata.ice:53: warning: ignoring invalid metadata 'cpp:virtual' -WarningInvalidMetadata.ice:58: warning: ignoring invalid metadata 'cpp:bad' -WarningInvalidMetadata.ice:63: warning: ignoring invalid metadata 'cpp98:foo' -WarningInvalidMetadata.ice:63: warning: ignoring invalid metadata 'cpp11:bar' +WarningInvalidMetadata.ice:45: warning: ignoring invalid metadata 'cpp:const' +WarningInvalidMetadata.ice:45: warning: ignoring invalid metadata 'cpp:ice_print' +WarningInvalidMetadata.ice:51: warning: ignoring invalid metadata 'cpp:virtual' +WarningInvalidMetadata.ice:56: warning: ignoring invalid metadata 'cpp:bad' +WarningInvalidMetadata.ice:61: warning: ignoring invalid metadata 'cpp98:foo' +WarningInvalidMetadata.ice:61: warning: ignoring invalid metadata 'cpp11:bar'