diff options
author | Mark Spruiell <mes@zeroc.com> | 2018-02-01 10:42:02 -0800 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2018-02-01 10:42:02 -0800 |
commit | a34dfc0906d5e3b09b5dc333e1e1d373b850a314 (patch) | |
tree | c63751eb56112774df48956c08c7d7eac40e7f12 /cpp | |
parent | Added ice_fixed to generated Java proxy class, added test to check proxy retu... (diff) | |
download | ice-a34dfc0906d5e3b09b5dc333e1e1d373b850a314.tar.bz2 ice-a34dfc0906d5e3b09b5dc333e1e1d373b850a314.tar.xz ice-a34dfc0906d5e3b09b5dc333e1e1d373b850a314.zip |
ICE-8544 - Updates to packaging metadata
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/Slice/JavaUtil.cpp | 119 | ||||
-rw-r--r-- | cpp/src/Slice/JavaUtil.h | 6 | ||||
-rw-r--r-- | cpp/src/Slice/PythonUtil.cpp | 71 | ||||
-rw-r--r-- | cpp/src/Slice/PythonUtil.h | 2 |
4 files changed, 162 insertions, 36 deletions
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp index 3cc4a2e3967..0f506c1a391 100644 --- a/cpp/src/Slice/JavaUtil.cpp +++ b/cpp/src/Slice/JavaUtil.cpp @@ -431,6 +431,11 @@ private: result.push_back(s); continue; } + else if(s.substr(prefix.size(), pos - prefix.size()) == "package") + { + result.push_back(s); + continue; + } dc->warning(InvalidMetaData, cont->file(), cont->line(), "ignoring invalid metadata `" + s + "'"); } @@ -444,7 +449,8 @@ private: return result; } - StringList validateType(const SyntaxTreeBasePtr& p, const StringList& metaData, const string& file, const string& line) + StringList validateType(const SyntaxTreeBasePtr& p, const StringList& metaData, const string& file, + const string& line) { const UnitPtr unit = p->unit(); const DefinitionContextPtr dc = unit->findDefinitionContext(file); @@ -520,6 +526,18 @@ private: dc->warning(InvalidMetaData, file, line, "ignoring invalid metadata `" + *i + "'"); } } + else if(i->find("java:package:") == 0) + { + ModulePtr m = ModulePtr::dynamicCast(p); + if(m && UnitPtr::dynamicCast(m->container())) + { + newMetaData.push_back(*i); + } + else + { + dc->warning(InvalidMetaData, file, line, "ignoring invalid metadata `" + *i + "'"); + } + } else { newMetaData.push_back(*i); @@ -528,7 +546,8 @@ private: return newMetaData; } - StringList validateGetSet(const SyntaxTreeBasePtr& p, const StringList& metaData, const string& file, const string& line) + StringList validateGetSet(const SyntaxTreeBasePtr& p, const StringList& metaData, const string& file, + const string& line) { const UnitPtr unit = p->unit(); const DefinitionContextPtr dc= unit->findDefinitionContext(file); @@ -921,25 +940,51 @@ Slice::JavaCompatGenerator::convertScopedName(const string& scoped, const string string Slice::JavaCompatGenerator::getPackagePrefix(const ContainedPtr& cont) const { - UnitPtr unit = cont->container()->unit(); - string file = cont->file(); - assert(!file.empty()); - - map<string, string>::const_iterator p = _filePackagePrefix.find(file); - if(p != _filePackagePrefix.end()) + // + // Traverse to the top-level module. + // + ModulePtr m; + ContainedPtr p = cont; + while(true) { - return p->second; + if(ModulePtr::dynamicCast(p)) + { + m = ModulePtr::dynamicCast(p); + } + + ContainerPtr c = p->container(); + p = ContainedPtr::dynamicCast(c); // This cast fails for Unit. + if(!p) + { + break; + } } + assert(m); + + // + // The java:package metadata can be defined as global metadata or applied to a top-level module. + // We check for the metadata at the top-level module first and then fall back to the global scope. + // static const string prefix = "java:package:"; - DefinitionContextPtr dc = unit->findDefinitionContext(file); - assert(dc); - string q = dc->findMetaData(prefix); + + string q; + if(!m->findMetaData(prefix, q)) + { + UnitPtr unit = cont->unit(); + string file = cont->file(); + assert(!file.empty()); + + DefinitionContextPtr dc = unit->findDefinitionContext(file); + assert(dc); + q = dc->findMetaData(prefix); + } + if(!q.empty()) { q = q.substr(prefix.size()); } - _filePackagePrefix[file] = q; + return q; } @@ -3375,25 +3420,51 @@ Slice::JavaGenerator::convertScopedName(const string& scoped, const string& pref string Slice::JavaGenerator::getPackagePrefix(const ContainedPtr& cont) const { - UnitPtr unit = cont->container()->unit(); - string file = cont->file(); - assert(!file.empty()); - - map<string, string>::const_iterator p = _filePackagePrefix.find(file); - if(p != _filePackagePrefix.end()) + // + // Traverse to the top-level module. + // + ModulePtr m; + ContainedPtr p = cont; + while(true) { - return p->second; + if(ModulePtr::dynamicCast(p)) + { + m = ModulePtr::dynamicCast(p); + } + + ContainerPtr c = p->container(); + p = ContainedPtr::dynamicCast(c); // This cast fails for Unit. + if(!p) + { + break; + } } + assert(m); + + // + // The java:package metadata can be defined as global metadata or applied to a top-level module. + // We check for the metadata at the top-level module first and then fall back to the global scope. + // static const string prefix = "java:package:"; - DefinitionContextPtr dc = unit->findDefinitionContext(file); - assert(dc); - string q = dc->findMetaData(prefix); + + string q; + if(!m->findMetaData(prefix, q)) + { + UnitPtr unit = cont->unit(); + string file = cont->file(); + assert(!file.empty()); + + DefinitionContextPtr dc = unit->findDefinitionContext(file); + assert(dc); + q = dc->findMetaData(prefix); + } + if(!q.empty()) { q = q.substr(prefix.size()); } - _filePackagePrefix[file] = q; + return q; } diff --git a/cpp/src/Slice/JavaUtil.h b/cpp/src/Slice/JavaUtil.h index efb0297ea7d..01ad098c1da 100644 --- a/cpp/src/Slice/JavaUtil.h +++ b/cpp/src/Slice/JavaUtil.h @@ -98,7 +98,7 @@ protected: const std::string& = std::string()) const; // - // Returns the package prefix for a give Slice file. + // Returns the package prefix of a Contained entity. // std::string getPackagePrefix(const ContainedPtr&) const; @@ -223,7 +223,6 @@ private: std::string _dir; ::IceUtilInternal::Output* _out; - mutable std::map<std::string, std::string> _filePackagePrefix; }; class JavaGenerator : private ::IceUtil::noncopyable @@ -265,7 +264,7 @@ protected: const std::string& = std::string()) const; // - // Returns the package prefix for a give Slice file. + // Returns the package prefix of a Contained entity. // std::string getPackagePrefix(const ContainedPtr&) const; @@ -397,7 +396,6 @@ private: std::string _dir; ::IceUtilInternal::Output* _out; - mutable std::map<std::string, std::string> _filePackagePrefix; }; } diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp index 188a5617c0c..8f4b466d6c7 100644 --- a/cpp/src/Slice/PythonUtil.cpp +++ b/cpp/src/Slice/PythonUtil.cpp @@ -3015,18 +3015,51 @@ Slice::Python::fixIdent(const string& ident) string Slice::Python::getPackageMetadata(const ContainedPtr& cont) { - UnitPtr unit = cont->container()->unit(); - string file = cont->file(); - assert(!file.empty()); + // + // Traverse to the top-level module. + // + ModulePtr m; + ContainedPtr p = cont; + while(true) + { + if(ModulePtr::dynamicCast(p)) + { + m = ModulePtr::dynamicCast(p); + } + + ContainerPtr c = p->container(); + p = ContainedPtr::dynamicCast(c); // This cast fails for Unit. + if(!p) + { + break; + } + } + assert(m); + + // + // The python:package metadata can be defined as global metadata or applied to a top-level module. + // We check for the metadata at the top-level module first and then fall back to the global scope. + // static const string prefix = "python:package:"; - DefinitionContextPtr dc = unit->findDefinitionContext(file); - assert(dc); - string q = dc->findMetaData(prefix); + + string q; + if(!m->findMetaData(prefix, q)) + { + UnitPtr unit = cont->unit(); + string file = cont->file(); + assert(!file.empty()); + + DefinitionContextPtr dc = unit->findDefinitionContext(file); + assert(dc); + q = dc->findMetaData(prefix); + } + if(!q.empty()) { q = q.substr(prefix.size()); } + return q; } @@ -3114,7 +3147,31 @@ Slice::Python::MetaDataVisitor::visitUnitStart(const UnitPtr& p) bool Slice::Python::MetaDataVisitor::visitModuleStart(const ModulePtr& p) { - reject(p); + static const string prefix = "python:package:"; + + StringList metaData = p->getMetaData(); + for(StringList::const_iterator r = metaData.begin(); r != metaData.end();) + { + string s = *r++; + if(s.find(prefix) == 0) + { + // + // Must be a top-level module. + // + if(UnitPtr::dynamicCast(p->container())) + { + continue; + } + } + + if(s.find("python:") == 0) + { + p->definitionContext()->warning(InvalidMetaData, p->file(), "", "ignoring invalid metadata `" + s + "'"); + metaData.remove(s); + } + } + + p->setMetaData(metaData); return true; } diff --git a/cpp/src/Slice/PythonUtil.h b/cpp/src/Slice/PythonUtil.h index d0967fce529..6f29643be36 100644 --- a/cpp/src/Slice/PythonUtil.h +++ b/cpp/src/Slice/PythonUtil.h @@ -46,7 +46,7 @@ std::string scopedToName(const std::string&); std::string fixIdent(const std::string&); // -// Return the package specified in the global metadata for the given definition, +// Return the package specified by metadata for the given definition, // or an empty string if no metadata was found. // std::string getPackageMetadata(const Slice::ContainedPtr&); |