Skip to content

Commit

Permalink
[Refactoring] Add Package::isPackageMod()
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Mar 14, 2014
1 parent 85220de commit cca9dd3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/access.c
Expand Up @@ -281,9 +281,8 @@ bool hasPackageAccess(Scope *sc, Dsymbol *s)
Dsymbol *s2 = dst->lookup(m->ident);
assert(s2);
Package *p = s2->isPackage();
if (p && p->isPkgMod == PKGmodule)
if (p && p->isPackageMod())
{
assert(p->mod == m);
pkg = p;
break;
}
Expand All @@ -305,7 +304,7 @@ bool hasPackageAccess(Scope *sc, Dsymbol *s)
#endif
return true;
}
if (pkg->isPkgMod == PKGmodule && pkg->mod == sc->module)
if (pkg->isPackageMod() == sc->module)
{
#if LOG
printf("\ts is in same package.d module as sc\n");
Expand Down
6 changes: 3 additions & 3 deletions src/import.c
Expand Up @@ -141,11 +141,11 @@ void Import::load(Scope *sc)
else
assert(p->isPkgMod == PKGmodule);
}
else if (p->isPkgMod == PKGmodule)
else
{
mod = p->mod;
mod = p->isPackageMod();
}
if (p->isPkgMod != PKGmodule)
if (!mod)
{
::error(loc, "can only import from a module, not from package %s.%s",
p->toPrettyChars(), id->toChars());
Expand Down
9 changes: 9 additions & 0 deletions src/module.c
Expand Up @@ -1077,6 +1077,15 @@ const char *Package::kind()
return "package";
}

Module *Package::isPackageMod()
{
if (isPkgMod == PKGmodule)
{
return mod;
}
return NULL;
}

/****************************************************
* Input:
* packages[] the pkg1.pkg2 of pkg1.pkg2.mod
Expand Down
2 changes: 2 additions & 0 deletions src/module.h
Expand Up @@ -55,6 +55,8 @@ class Package : public ScopeDsymbol
virtual void semantic(Scope *) { }
Dsymbol *search(Loc loc, Identifier *ident, int flags = IgnoreNone);
void accept(Visitor *v) { v->visit(this); }

Module *isPackageMod();
};

class Module : public Package
Expand Down

0 comments on commit cca9dd3

Please sign in to comment.