Skip to content

Commit

Permalink
Make imports inside imported C++ modules invisible to the importing m…
Browse files Browse the repository at this point in the history
…odule.

Semi-hack but needed to prevent conflicts between imported symbols, caused by the choice to name C++ modules after records.
  • Loading branch information
Syniurge committed May 3, 2015
1 parent b13a606 commit 7cc1ca0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions dmd2/cpp/cppmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ Module::Module(const char* filename, Identifier* ident, Identifiers *packages)
arg = objfn;
}

Dsymbol *Module::search(Loc loc, Identifier *ident, int flags)
{
auto result = ::Module::search(loc, ident, flags);

if ((flags & IgnorePrivateMembers) && result && result->isImport())
return nullptr; // semi-HACK? this makes the imports inside an imported module invisible to D code,
// but also prevents conflicts caused by the choice to name C++ modules after record names.

return result;
}

void Module::addPreambule()
{
// Statically import object.d for object and size_t (used by buildXtoHash)
Expand Down
1 change: 1 addition & 0 deletions dmd2/cpp/cppmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Module : public ::Module
Module(const char *filename, Identifier *ident, Identifiers *packages);

static Module *load(Loc loc, Identifiers *packages, Identifier *ident);
Dsymbol *search(Loc loc, Identifier *ident, int flags = IgnoreNone) override;
void addPreambule() override;
const char *manglePrefix() override { return "_Cpp"; }
};
Expand Down
2 changes: 1 addition & 1 deletion dmd2/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Module : public Package
void gensymfile();
#endif
int needModuleInfo();
Dsymbol *search(Loc loc, Identifier *ident, int flags = IgnoreNone);
virtual Dsymbol *search(Loc loc, Identifier *ident, int flags = IgnoreNone); // CALYPSO
Dsymbol *symtabInsert(Dsymbol *s);
void deleteObjFile();
static void addDeferredSemantic(Dsymbol *s);
Expand Down

0 comments on commit 7cc1ca0

Please sign in to comment.