Referring to types from other namespaces in C++ now works correctly.

Previously, it would ignore the fact that the type comes from a
different namespace. Now they are pre-declared in their own namespace,
and referenced with a qualified name if necessary.

Bug: 16851682
Change-Id: I5cb625b86d28e7436b9e93c70a0fa16a600d9884
Tested: on Linux
This commit is contained in:
Wouter van Oortmerssen
2014-08-19 16:37:46 -07:00
parent be894f09df
commit c2ba7fd251
7 changed files with 158 additions and 77 deletions

View File

@@ -585,24 +585,24 @@ static bool SaveType(const Parser &parser, const Definition &def,
bool needs_imports) {
if (!classcode.length()) return true;
std::string name_space_name;
std::string name_space_dir = path;
for (auto it = parser.name_space_.begin();
it != parser.name_space_.end(); ++it) {
if (name_space_name.length()) {
name_space_name += ".";
name_space_dir += PATH_SEPARATOR;
std::string namespace_name;
std::string namespace_dir = path;
auto &namespaces = parser.namespaces_.back()->components;
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
if (namespace_name.length()) {
namespace_name += ".";
namespace_dir += PATH_SEPARATOR;
}
name_space_name = *it;
name_space_dir += *it;
mkdir(name_space_dir.c_str(), S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
namespace_name = *it;
namespace_dir += *it;
mkdir(namespace_dir.c_str(), S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
}
std::string code = "";
BeginFile(name_space_name, needs_imports, &code);
BeginFile(namespace_name, needs_imports, &code);
code += classcode;
std::string filename = name_space_dir + PATH_SEPARATOR + def.name + ".go";
std::string filename = namespace_dir + PATH_SEPARATOR + def.name + ".go";
return SaveFile(filename.c_str(), code, false);
}