diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 98a1c1165c7..a3ed6471ebb 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -96,43 +96,16 @@ namespace Slice // ---------------------------------------------------------------------- Slice::Metadata::Metadata(string rawMetadata, string file, int line) : GrammarBase() { - std::tie(_directive, _arguments) = parseRawMetadata(std::move(rawMetadata)); _file = std::move(file); _line = line; -} - -string_view -Slice::Metadata::directive() const -{ - return _directive; -} - -string_view -Slice::Metadata::arguments() const -{ - return _arguments; -} -string -Slice::Metadata::file() const -{ - return _file; -} - -int -Slice::Metadata::line() const -{ - return _line; -} - -pair -Slice::Metadata::parseRawMetadata(string rawMetadata) -{ // If the metadata contains no colons, then it must be a directive with no arguments. size_t firstColonPos = rawMetadata.find(':'); if (firstColonPos == string::npos) { - return {rawMetadata, ""}; + _directive = rawMetadata; + _arguments = ""; + return; } // Otherwise, we check whether the colon is for a language prefix or for arguments and split the string accordingly. @@ -148,7 +121,9 @@ Slice::Metadata::parseRawMetadata(string rawMetadata) if (isLanguage) { // If the piece before the colon was a language prefix, don't split up the string. - return {rawMetadata, ""}; + _directive = rawMetadata; + _arguments = ""; + return; } else { @@ -162,9 +137,32 @@ Slice::Metadata::parseRawMetadata(string rawMetadata) splitPos = secondColonPos; } - string directive = rawMetadata.substr(0, splitPos); - string arguments = rawMetadata.substr(splitPos + 1); - return {directive, arguments}; + _directive = rawMetadata.substr(0, splitPos); + _arguments = rawMetadata.substr(splitPos + 1); +} + +string_view +Slice::Metadata::directive() const +{ + return _directive; +} + +string_view +Slice::Metadata::arguments() const +{ + return _arguments; +} + +string +Slice::Metadata::file() const +{ + return _file; +} + +int +Slice::Metadata::line() const +{ + return _line; } // ---------------------------------------------------------------------- diff --git a/cpp/src/Slice/Parser.h b/cpp/src/Slice/Parser.h index bdf905879bd..aea82853498 100644 --- a/cpp/src/Slice/Parser.h +++ b/cpp/src/Slice/Parser.h @@ -189,9 +189,6 @@ namespace Slice friend std::ostream& operator<<(std::ostream& out, const Metadata& metadata); private: - /// Parses a metadata string into a pair of (directive, arguments) strings. - static std::pair parseRawMetadata(std::string rawMetadata); - std::string _directive; std::string _arguments; diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index cb2f9e72397..8c8c789735b 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -1097,7 +1097,7 @@ Slice::Gen::MetadataVisitor::visitConst(const ConstPtr& p) MetadataList Slice::Gen::MetadataVisitor::validate( const SyntaxTreeBasePtr& cont, - const MetadataList& metadata, + MetadataList metadata, const string& file, bool operation) { @@ -1105,9 +1105,9 @@ Slice::Gen::MetadataVisitor::validate( const DefinitionContextPtr dc = ut->findDefinitionContext(file); assert(dc); - MetadataList newMetadata = metadata; - for (const auto& meta : metadata) + for (MetadataList::const_iterator q = metadata.begin(); q != metadata.end();) { + MetadataPtr meta = *q++; string_view directive = meta->directive(); string_view arguments = meta->arguments(); @@ -1118,7 +1118,7 @@ Slice::Gen::MetadataVisitor::validate( ostringstream ostr; ostr << "ignoring invalid metadata '" << *meta << "'"; dc->warning(InvalidMetadata, meta->file(), meta->line(), ostr.str()); - newMetadata.remove(meta); + metadata.remove(meta); continue; } @@ -1184,9 +1184,9 @@ Slice::Gen::MetadataVisitor::validate( ostringstream ostr; ostr << "ignoring invalid metadata '" << *meta << "'"; dc->warning(InvalidMetadata, meta->file(), meta->line(), ostr.str()); - newMetadata.remove(meta); + metadata.remove(meta); } - return newMetadata; + return metadata; } TypeContext diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index 16a38821152..5e9b98afb5d 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -218,7 +218,7 @@ namespace Slice void visitConst(const ConstPtr&) final; private: - MetadataList validate(const SyntaxTreeBasePtr&, const MetadataList&, const std::string&, bool = false); + MetadataList validate(const SyntaxTreeBasePtr&, MetadataList, const std::string&, bool = false); }; static void validateMetadata(const UnitPtr&);