本文整理汇总了C++中DsymbolTable类的典型用法代码示例。如果您正苦于以下问题:C++ DsymbolTable类的具体用法?C++ DsymbolTable怎么用?C++ DsymbolTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DsymbolTable类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
void Import::load(Scope *sc)
{
//printf("Import::load('%s')\n", toChars());
// See if existing module
DsymbolTable *dst = Package::resolve(packages, NULL, &pkg);
Dsymbol *s = dst->lookup(id);
if (s)
{
#if TARGET_NET
mod = (Module *)s;
#else
if (s->isModule())
mod = (Module *)s;
else
error("package and module have the same name");
#endif
}
if (!mod)
{
// Load module
mod = Module::load(loc, packages, id);
dst->insert(id, mod); // id may be different from mod->ident,
// if so then insert alias
if (!mod->importedFrom)
mod->importedFrom = sc ? sc->module->importedFrom : Module::rootModule;
}
if (!pkg)
pkg = mod;
//printf("-Import::load('%s'), pkg = %p\n", toChars(), pkg);
}
示例2: load
void Import::load(Scope *sc)
{
//printf("Import::load('%s')\n", toChars());
// See if existing module
DsymbolTable *dst = Package::resolve(packages, NULL, &pkg);
#if TARGET_NET //dot net needs modules and packages with same name
#else
if (pkg && pkg->isModule())
{
::error(loc, "can only import from a module, not from a member of module %s. Did you mean `import %s : %s`?",
pkg->toChars(), pkg->toPrettyChars(), id->toChars());
mod = pkg->isModule(); // Error recovery - treat as import of that module
return;
}
#endif
Dsymbol *s = dst->lookup(id);
if (s)
{
#if TARGET_NET
mod = (Module *)s;
#else
if (s->isModule())
mod = (Module *)s;
else
{
if (pkg)
{
::error(loc, "can only import from a module, not from package %s.%s",
pkg->toPrettyChars(), id->toChars());
}
else
{
::error(loc, "can only import from a module, not from package %s",
id->toChars());
}
}
#endif
}
if (!mod)
{
// Load module
mod = Module::load(loc, packages, id);
if (mod)
{
dst->insert(id, mod); // id may be different from mod->ident,
// if so then insert alias
if (!mod->importedFrom)
mod->importedFrom = sc ? sc->module->importedFrom : Module::rootModule;
}
}
if (!pkg)
pkg = mod;
//printf("-Import::load('%s'), pkg = %p\n", toChars(), pkg);
}
示例3: Package
DsymbolTable *Package::resolve(Identifiers *packages, Dsymbol **pparent, Package **ppkg)
{
DsymbolTable *dst = Module::modules;
Dsymbol *parent = NULL;
//printf("Package::resolve()\n");
if (ppkg)
*ppkg = NULL;
if (packages)
{
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = (*packages)[i];
Package *pkg;
Dsymbol *p = dst->lookup(pid);
if (!p)
{
pkg = new Package(pid);
dst->insert(pkg);
pkg->parent = parent;
pkg->symtab = new DsymbolTable();
}
else
{
pkg = p->isPackage();
assert(pkg);
// It might already be a module, not a package, but that needs
// to be checked at a higher level, where a nice error message
// can be generated.
// dot net needs modules and packages with same name
// But we still need a symbol table for it
if (!pkg->symtab)
pkg->symtab = new DsymbolTable();
}
parent = pkg;
dst = pkg->symtab;
if (ppkg && !*ppkg)
*ppkg = pkg;
#if 0
if (pkg->isModule())
{ // Return the module so that a nice error message can be generated
if (ppkg)
*ppkg = (Package *)p;
break;
}
#endif
}
}
if (pparent)
*pparent = parent;
return dst;
}
示例4: Package
DsymbolTable *Package::resolve(Identifiers *packages, Dsymbol **pparent, Package **ppkg)
{
DsymbolTable *dst = Module::modules;
Dsymbol *parent = NULL;
//printf("Package::resolve()\n");
if (ppkg)
*ppkg = NULL;
if (packages)
{
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = packages->tdata()[i];
Dsymbol *p;
p = dst->lookup(pid);
if (!p)
{
p = new Package(pid);
dst->insert(p);
p->parent = parent;
((ScopeDsymbol *)p)->symtab = new DsymbolTable();
}
else
{
assert(p->isPackage());
// It might already be a module, not a package, but that needs
// to be checked at a higher level, where a nice error message
// can be generated.
// dot net needs modules and packages with same name
}
parent = p;
dst = ((Package *)p)->symtab;
if (ppkg && !*ppkg)
*ppkg = (Package *)p;
#if TARGET_NET
#else
if (p->isModule())
{ // Return the module so that a nice error message can be generated
if (ppkg)
*ppkg = (Package *)p;
break;
}
#endif
}
if (pparent)
{
*pparent = parent;
}
}
return dst;
}
示例5: Package
DsymbolTable *Package::resolve(Array *packages, Dsymbol **pparent, Package **ppkg)
{
DsymbolTable *dst = Module::modules;
Dsymbol *parent = NULL;
//printf("Package::resolve()\n");
if (ppkg)
*ppkg = NULL;
if (packages)
{ int i;
for (i = 0; i < packages->dim; i++)
{ Identifier *pid = (Identifier *)packages->data[i];
Dsymbol *p;
p = dst->lookup(pid);
if (!p)
{
p = new Package(pid);
dst->insert(p);
p->parent = parent;
((ScopeDsymbol *)p)->symtab = new DsymbolTable();
}
else
{
assert(p->isPackage());
#if TARGET_NET //dot net needs modules and packages with same name
#else
if (p->isModule())
{ p->error("module and package have the same name");
fatal();
break;
}
#endif
}
parent = p;
dst = ((Package *)p)->symtab;
if (ppkg && !*ppkg)
*ppkg = (Package *)p;
}
if (pparent)
{
*pparent = parent;
}
}
return dst;
}
示例6: error
//.........这里部分代码省略.........
if (buflen >= 2)
{
if (buf[1] == 0)
{ // UTF-16LE
le = 1;
goto Lutf16;
}
else if (buf[0] == 0)
{ // UTF-16BE
le = 0;
goto Lutf16;
}
}
// It's UTF-8
if (buf[0] >= 0x80)
{ error("source file must start with BOM or ASCII character, not \\x%02X", buf[0]);
fatal();
}
}
}
#ifdef IN_GCC
// dump utf-8 encoded source
if (dump_source)
{ // %% srcname could contain a path ...
d_gcc_dump_source(srcname, "utf-8", buf, buflen);
}
#endif
/* If it starts with the string "Ddoc", then it's a documentation
* source file.
*/
if (buflen >= 4 && memcmp(buf, "Ddoc", 4) == 0)
{
comment = buf + 4;
isDocFile = 1;
return;
}
if (isHtml)
{
OutBuffer *dbuf = new OutBuffer();
Html h(srcname, buf, buflen);
h.extractCode(dbuf);
buf = dbuf->data;
buflen = dbuf->offset;
#ifdef IN_GCC
// dump extracted source
if (dump_source)
d_gcc_dump_source(srcname, "d.utf-8", buf, buflen);
#endif
}
#if IN_LLVM
Parser p(this, buf, buflen, gen_docs);
#else
Parser p(this, buf, buflen, docfile != NULL);
#endif
p.nextToken();
members = p.parseModule();
md = p.md;
numlines = p.loc.linnum;
DsymbolTable *dst;
if (md)
{ this->ident = md->id;
dst = Package::resolve(md->packages, &this->parent, NULL);
}
else
{
dst = modules;
/* Check to see if module name is a valid identifier
*/
if (!Lexer::isValidIdentifier(this->ident->toChars()))
error("has non-identifier characters in filename, use module declaration instead");
}
// Update global list of modules
if (!dst->insert(this))
{
Dsymbol *prev = dst->lookup(ident);
assert(prev);
Module *mprev = prev->isModule();
if (mprev)
error(loc, "from file %s conflicts with another module %s from file %s",
srcname, mprev->toChars(), mprev->srcfile->toChars());
else
{
Package *pkg = prev->isPackage();
assert(pkg);
error(loc, "from file %s conflicts with package name %s",
srcname, pkg->toChars());
}
}
else
{
amodules.push(this);
}
}
示例7: error
//.........这里部分代码省略.........
if (buf[0] >= 0x80)
{ error("source file must start with BOM or ASCII character, not \\x%02X", buf[0]);
fatal();
}
}
}
/* If it starts with the string "Ddoc", then it's a documentation
* source file.
*/
if (buflen >= 4 && memcmp(buf, "Ddoc", 4) == 0)
{
comment = buf + 4;
isDocFile = 1;
if (!docfile)
setDocfile();
return;
}
{
Parser p(this, buf, buflen, docfile != NULL);
p.nextToken();
members = p.parseModule();
md = p.md;
numlines = p.scanloc.linnum;
}
if (srcfile->ref == 0)
::free(srcfile->buffer);
srcfile->buffer = NULL;
srcfile->len = 0;
/* The symbol table into which the module is to be inserted.
*/
DsymbolTable *dst;
if (md)
{
/* A ModuleDeclaration, md, was provided.
* The ModuleDeclaration sets the packages this module appears in, and
* the name of this module.
*/
this->ident = md->id;
this->safe = md->safe;
Package *ppack = NULL;
dst = Package::resolve(md->packages, &this->parent, &ppack);
assert(dst);
Module *m = ppack ? ppack->isModule() : NULL;
if (m && strcmp(m->srcfile->name->name(), "package.d") != 0)
{
::error(md->loc, "package name '%s' conflicts with usage as a module name in file %s",
ppack->toPrettyChars(), m->srcfile->toChars());
}
}
else
{
/* The name of the module is set to the source file name.
* There are no packages.
*/
dst = modules; // and so this module goes into global module symbol table
/* Check to see if module name is a valid identifier
*/
if (!Lexer::isValidIdentifier(this->ident->toChars()))
error("has non-identifier characters in filename, use module declaration instead");
}
示例8: load
void Import::load(Scope *sc)
{
//printf("Import::load('%s') %p\n", toPrettyChars(), this);
// See if existing module
DsymbolTable *dst = Package::resolve(packages, NULL, &pkg);
#if 0
if (pkg && pkg->isModule())
{
::error(loc, "can only import from a module, not from a member of module %s. Did you mean `import %s : %s`?",
pkg->toChars(), pkg->toPrettyChars(), id->toChars());
mod = pkg->isModule(); // Error recovery - treat as import of that module
return;
}
#endif
Dsymbol *s = dst->lookup(id);
if (s)
{
if (s->isModule())
mod = (Module *)s;
else
{
if (s->isAliasDeclaration())
{
::error(loc, "%s %s conflicts with %s", s->kind(), s->toPrettyChars(), id->toChars());
}
else if (Package *p = s->isPackage())
{
if (p->isPkgMod == PKGunknown)
{
mod = Module::load(loc, packages, id);
if (!mod)
p->isPkgMod = PKGpackage;
else
assert(p->isPkgMod == PKGmodule);
}
else
{
mod = p->isPackageMod();
}
if (!mod)
{
::error(loc, "can only import from a module, not from package %s.%s",
p->toPrettyChars(), id->toChars());
}
}
else if (pkg)
{
::error(loc, "can only import from a module, not from package %s.%s",
pkg->toPrettyChars(), id->toChars());
}
else
{
::error(loc, "can only import from a module, not from package %s",
id->toChars());
}
}
}
if (!mod)
{
// Load module
mod = Module::load(loc, packages, id);
if (mod)
{
dst->insert(id, mod); // id may be different from mod->ident,
// if so then insert alias
}
}
if (mod && !mod->importedFrom)
mod->importedFrom = sc ? sc->module->importedFrom : Module::rootModule;
if (!pkg)
pkg = mod;
//printf("-Import::load('%s'), pkg = %p\n", toChars(), pkg);
}
示例9: hasPackageAccess
/****************************************
* Determine if scope sc has package level access to s.
*/
bool hasPackageAccess(Scope *sc, Dsymbol *s)
{
#if LOG
printf("hasPackageAccess(s = '%s', sc = '%p', s->protection.pkg = '%s')\n",
s->toChars(), sc,
s->prot().pkg ? s->prot().pkg->toChars() : "NULL");
#endif
Package *pkg = NULL;
if (s->prot().pkg)
pkg = s->prot().pkg;
else
{
// no explicit package for protection, inferring most qualified one
for (; s; s = s->parent)
{
if (Module *m = s->isModule())
{
DsymbolTable *dst = Package::resolve(m->md ? m->md->packages : NULL, NULL, NULL);
assert(dst);
Dsymbol *s2 = dst->lookup(m->ident);
assert(s2);
Package *p = s2->isPackage();
if (p && p->isPackageMod())
{
pkg = p;
break;
}
}
else if ((pkg = s->isPackage()) != NULL)
break;
}
}
#if LOG
if (pkg)
printf("\tsymbol access binds to package '%s'\n", pkg->toChars());
#endif
if (pkg)
{
if (pkg == sc->module->parent)
{
#if LOG
printf("\tsc is in permitted package for s\n");
#endif
return true;
}
if (pkg->isPackageMod() == sc->module)
{
#if LOG
printf("\ts is in same package.d module as sc\n");
#endif
return true;
}
Dsymbol* ancestor = sc->module->parent;
for (; ancestor; ancestor = ancestor->parent)
{
if (ancestor == pkg)
{
#if LOG
printf("\tsc is in permitted ancestor package for s\n");
#endif
return true;
}
}
}
#if LOG
printf("\tno package access\n");
#endif
return false;
}