本文整理汇总了C++中Dsymbol::setScope方法的典型用法代码示例。如果您正苦于以下问题:C++ Dsymbol::setScope方法的具体用法?C++ Dsymbol::setScope怎么用?C++ Dsymbol::setScope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dsymbol
的用法示例。
在下文中一共展示了Dsymbol::setScope方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: importAll
void Module::importAll(Scope *prevsc)
{
//printf("+Module::importAll(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
if (scope)
return; // already done
if (isDocFile)
{
error("is a Ddoc file, cannot import it");
return;
}
if (md && md->msg)
{
if (StringExp *se = md->msg->toStringExp())
md->msg = se;
else
md->msg->error("string expected, not '%s'", md->msg->toChars());
}
/* Note that modules get their own scope, from scratch.
* This is so regardless of where in the syntax a module
* gets imported, it is unaffected by context.
* Ignore prevsc.
*/
Scope *sc = Scope::createGlobal(this); // create root scope
// Add import of "object", even for the "object" module.
// If it isn't there, some compiler rewrites, like
// classinst == classinst -> .object.opEquals(classinst, classinst)
// would fail inside object.d.
if (members->dim == 0 || ((*members)[0])->ident != Id::object)
{
Import *im = new Import(Loc(), NULL, Id::object, NULL, 0);
members->shift(im);
}
if (!symtab)
{
// Add all symbols into module's symbol table
symtab = new DsymbolTable();
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->addMember(sc, sc->scopesym, 1);
}
}
// anything else should be run after addMember, so version/debug symbols are defined
/* Set scope for the symbols so that if we forward reference
* a symbol, it can possibly be resolved on the spot.
* If this works out well, it can be extended to all modules
* before any semantic() on any of them.
*/
setScope(sc); // remember module scope for semantic
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->setScope(sc);
}
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->importAll(sc);
}
sc = sc->pop();
sc->pop(); // 2 pops because Scope::createGlobal() created 2
}
示例2: semantic
//.........这里部分代码省略.........
if (vtblOffset())
vtbl.push(this); // leave room at vtbl[0] for classinfo
// Cat together the vtbl[]'s from base interfaces
for (size_t i = 0; i < interfaces_dim; i++)
{ BaseClass *b = interfaces[i];
// Skip if b has already appeared
for (size_t k = 0; k < i; k++)
{
if (b == interfaces[k])
goto Lcontinue;
}
// Copy vtbl[] from base class
if (b->base->vtblOffset())
{ size_t d = b->base->vtbl.dim;
if (d > 1)
{
vtbl.reserve(d - 1);
for (size_t j = 1; j < d; j++)
vtbl.push(b->base->vtbl[j]);
}
}
else
{
vtbl.append(&b->base->vtbl);
}
Lcontinue:
;
}
protection = sc->protection;
storage_class |= sc->stc & STC_TYPECTOR;
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->addMember(sc, this, 1);
}
sc = sc->push(this);
sc->stc &= STCsafe | STCtrusted | STCsystem;
sc->parent = this;
if (com)
sc->linkage = LINKwindows;
else if (cpp)
sc->linkage = LINKcpp;
sc->structalign = STRUCTALIGN_DEFAULT;
sc->protection = PROTpublic;
sc->explicitProtection = 0;
// structalign = sc->structalign;
sc->offset = Target::ptrsize * 2;
sc->userAttributes = NULL;
structsize = sc->offset;
inuse++;
/* Set scope so if there are forward references, we still might be able to
* resolve individual members like enums.
*/
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
/* There are problems doing this in the general case because
* Scope keeps track of things like 'offset'
*/
if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident))
{
//printf("setScope %s %s\n", s->kind(), s->toChars());
s->setScope(sc);
}
}
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
// Ungag errors when not speculative
Ungag ungag = ungagSpeculative();
s->semantic(sc);
}
if (global.errors != errors)
{ // The type is no good.
type = Type::terror;
}
inuse--;
//members->print();
sc->pop();
//printf("-InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type);
if (type->ty == Tclass && ((TypeClass *)type)->sym != this)
{
error("failed semantic analysis");
this->errors = true;
type = Type::terror;
}
}
示例3: semantic
//.........这里部分代码省略.........
sc->linkage = LINKc;
#endif
}
sc->protection = PROTpublic;
sc->explicitProtection = 0;
sc->structalign = 8;
structalign = sc->structalign;
if (baseClass)
{ sc->offset = baseClass->structsize;
alignsize = baseClass->alignsize;
// if (isnested)
// sc->offset += PTRSIZE; // room for uplevel context pointer
}
else
{ sc->offset = PTRSIZE * 2; // allow room for __vptr and __monitor
alignsize = PTRSIZE;
}
structsize = sc->offset;
Scope scsave = *sc;
size_t members_dim = members->dim;
sizeok = 0;
/* Set scope so if there are forward references, we still might be able to
* resolve individual members like enums.
*/
for (size_t i = 0; i < members_dim; i++)
{ Dsymbol *s = members->tdata()[i];
/* There are problems doing this in the general case because
* Scope keeps track of things like 'offset'
*/
if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident))
{
//printf("setScope %s %s\n", s->kind(), s->toChars());
s->setScope(sc);
}
}
for (size_t i = 0; i < members_dim; i++)
{ Dsymbol *s = members->tdata()[i];
s->semantic(sc);
}
if (global.gag && global.gaggedErrors != errors)
{ // The type is no good, yet the error messages were gagged.
type = Type::terror;
}
if (sizeok == 2) // failed due to forward references
{ // semantic() failed due to forward references
// Unwind what we did, and defer it for later
fields.setDim(0);
structsize = 0;
alignsize = 0;
structalign = 0;
sc = sc->pop();
scope = scx ? scx : new Scope(*sc);
scope->setNoFree();
scope->module->addDeferredSemantic(this);
Module::dprogress = dprogress_save;
//printf("\tsemantic('%s') failed due to forward references\n", toChars());
return;
示例4: semantic
void Module::semantic()
{
if (semanticstarted)
return;
//printf("+Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
semanticstarted = 1;
// Note that modules get their own scope, from scratch.
// This is so regardless of where in the syntax a module
// gets imported, it is unaffected by context.
Scope *sc = scope; // see if already got one from importAll()
if (!sc)
{ printf("test2\n");
Scope::createGlobal(this); // create root scope
}
//printf("Module = %p, linkage = %d\n", sc->scopesym, sc->linkage);
#if 0
// Add import of "object" if this module isn't "object"
if (ident != Id::object)
{
Import *im = new Import(0, NULL, Id::object, NULL, 0);
members->shift(im);
}
// Add all symbols into module's symbol table
symtab = new DsymbolTable();
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
s->addMember(NULL, sc->scopesym, 1);
}
/* Set scope for the symbols so that if we forward reference
* a symbol, it can possibly be resolved on the spot.
* If this works out well, it can be extended to all modules
* before any semantic() on any of them.
*/
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
s->setScope(sc);
}
#endif
// Do semantic() on members that don't depend on others
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
//printf("\tModule('%s'): '%s'.semantic0()\n", toChars(), s->toChars());
s->semantic0(sc);
}
// Pass 1 semantic routines: do public side of the definition
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
//printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars());
s->semantic(sc);
runDeferredSemantic();
}
if (!scope)
{ sc = sc->pop();
sc->pop(); // 2 pops because Scope::createGlobal() created 2
}
semanticRun = semanticstarted;
//printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
}
示例5: semantic
void StructDeclaration::semantic(Scope *sc)
{
Scope *sc2;
//printf("+StructDeclaration::semantic(this=%p, %s '%s', sizeok = %d)\n", this, parent->toChars(), toChars(), sizeok);
//static int count; if (++count == 20) halt();
assert(type);
if (!members) // if opaque declaration
{
return;
}
if (symtab)
{ if (sizeok == SIZEOKdone || !scope)
{ //printf("already completed\n");
scope = NULL;
return; // semantic() already completed
}
}
else
symtab = new DsymbolTable();
Scope *scx = NULL;
if (scope)
{ sc = scope;
scx = scope; // save so we don't make redundant copies
scope = NULL;
}
int errors = global.errors;
unsigned dprogress_save = Module::dprogress;
parent = sc->parent;
type = type->semantic(loc, sc);
handle = type;
protection = sc->protection;
alignment = sc->structalign;
storage_class |= sc->stc;
if (sc->stc & STCdeprecated)
isdeprecated = true;
assert(!isAnonymous());
if (sc->stc & STCabstract)
error("structs, unions cannot be abstract");
userAttributes = sc->userAttributes;
if (sizeok == SIZEOKnone) // if not already done the addMember step
{
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
//printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars());
s->addMember(sc, this, 1);
}
}
sizeok = SIZEOKnone;
sc2 = sc->push(this);
sc2->stc &= STCsafe | STCtrusted | STCsystem;
sc2->parent = this;
if (isUnionDeclaration())
sc2->inunion = 1;
sc2->protection = PROTpublic;
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttributes = NULL;
/* Set scope so if there are forward references, we still might be able to
* resolve individual members like enums.
*/
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
/* There are problems doing this in the general case because
* Scope keeps track of things like 'offset'
*/
//if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident))
{
//printf("struct: setScope %s %s\n", s->kind(), s->toChars());
s->setScope(sc2);
}
}
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
/* If this is the last member, see if we can finish setting the size.
* This could be much better - finish setting the size after the last
* field was processed. The problem is the chicken-and-egg determination
* of when that is. See Bugzilla 7426 for more info.
*/
if (i + 1 == members->dim)
{
if (sizeok == SIZEOKnone && s->isAliasDeclaration())
finalizeSize(sc2);
}
// Ungag errors when not speculative
unsigned oldgag = global.gag;
//.........这里部分代码省略.........
示例6: semantic
void StructDeclaration::semantic(Scope *sc)
{
Scope *sc2;
//printf("+StructDeclaration::semantic(this=%p, %s '%s', sizeok = %d)\n", this, parent->toChars(), toChars(), sizeok);
//static int count; if (++count == 20) halt();
assert(type);
if (!members) // if opaque declaration
{
return;
}
if (symtab)
{ if (sizeok == SIZEOKdone || !scope)
{ //printf("already completed\n");
scope = NULL;
return; // semantic() already completed
}
}
else
symtab = new DsymbolTable();
Scope *scx = NULL;
if (scope)
{
sc = scope;
scx = scope; // save so we don't make redundant copies
scope = NULL;
}
unsigned dprogress_save = Module::dprogress;
int errors = global.errors;
parent = sc->parent;
type = type->semantic(loc, sc);
handle = type;
protection = sc->protection;
alignment = sc->structalign;
storage_class |= sc->stc;
if (sc->stc & STCdeprecated)
isdeprecated = true;
assert(!isAnonymous());
if (sc->stc & STCabstract)
error("structs, unions cannot be abstract");
userAttributes = sc->userAttributes;
if (sizeok == SIZEOKnone) // if not already done the addMember step
{
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
//printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars());
s->addMember(sc, this, 1);
}
}
sizeok = SIZEOKnone;
sc2 = sc->push(this);
sc2->stc &= STCsafe | STCtrusted | STCsystem;
sc2->parent = this;
if (isUnionDeclaration())
sc2->inunion = 1;
sc2->protection = PROTpublic;
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttributes = NULL;
/* Set scope so if there are forward references, we still might be able to
* resolve individual members like enums.
*/
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
//printf("struct: setScope %s %s\n", s->kind(), s->toChars());
s->setScope(sc2);
}
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
/* If this is the last member, see if we can finish setting the size.
* This could be much better - finish setting the size after the last
* field was processed. The problem is the chicken-and-egg determination
* of when that is. See Bugzilla 7426 for more info.
*/
if (i + 1 == members->dim)
{
if (sizeok == SIZEOKnone && s->isAliasDeclaration())
finalizeSize(sc2);
}
// Ungag errors when not speculative
Ungag ungag = ungagSpeculative();
s->semantic(sc2);
}
finalizeSize(sc2);
if (sizeok == SIZEOKfwd)
//.........这里部分代码省略.........
示例7: semantic
void Nspace::semantic(Scope *sc)
{
if (semanticRun >= PASSsemantic)
return;
semanticRun = PASSsemantic;
#if LOG
printf("+Nspace::semantic('%s')\n", toChars());
#endif
if (scope)
{
sc = scope;
scope = NULL;
}
parent = sc->parent;
if (members)
{
if (!symtab)
symtab = new DsymbolTable();
// The namespace becomes 'imported' into the enclosing scope
for (Scope *sce = sc; 1; sce = sce->enclosing)
{
ScopeDsymbol *sds = (ScopeDsymbol *)sce->scopesym;
if (sds)
{
sds->importScope(this, Prot(PROTpublic));
break;
}
}
assert(sc);
sc = sc->push(this);
sc->linkage = LINKcpp; // note that namespaces imply C++ linkage
sc->parent = this;
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
//printf("add %s to scope %s\n", s->toChars(), toChars());
s->addMember(sc, this);
}
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->setScope(sc);
}
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->importAll(sc);
}
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
#if LOG
printf("\tmember '%s', kind = '%s'\n", s->toChars(), s->kind());
#endif
s->semantic(sc);
}
sc->pop();
}
#if LOG
printf("-Nspace::semantic('%s')\n", toChars());
#endif
}
示例8: semantic
void StructDeclaration::semantic(Scope *sc)
{
//printf("+StructDeclaration::semantic(this=%p, %s '%s', sizeok = %d)\n", this, parent->toChars(), toChars(), sizeok);
//static int count; if (++count == 20) halt();
if (semanticRun >= PASSsemanticdone)
return;
unsigned dprogress_save = Module::dprogress;
int errors = global.errors;
Scope *scx = NULL;
if (scope)
{
sc = scope;
scx = scope; // save so we don't make redundant copies
scope = NULL;
}
if (!parent)
{
assert(sc->parent && sc->func);
parent = sc->parent;
}
assert(parent && !isAnonymous());
type = type->semantic(loc, sc);
if (type->ty == Tstruct && ((TypeStruct *)type)->sym != this)
{
TemplateInstance *ti = ((TypeStruct *)type)->sym->isInstantiated();
if (ti && isError(ti))
((TypeStruct *)type)->sym = this;
}
// Ungag errors when not speculative
Ungag ungag = ungagSpeculative();
if (semanticRun == PASSinit)
{
protection = sc->protection;
alignment = sc->structalign;
storage_class |= sc->stc;
if (storage_class & STCdeprecated)
isdeprecated = true;
if (storage_class & STCabstract)
error("structs, unions cannot be abstract");
userAttribDecl = sc->userAttribDecl;
}
else if (symtab)
{
if (sizeok == SIZEOKdone || !scx)
{
semanticRun = PASSsemanticdone;
return;
}
}
semanticRun = PASSsemantic;
if (!members) // if opaque declaration
{
semanticRun = PASSsemanticdone;
return;
}
if (!symtab)
symtab = new DsymbolTable();
if (sizeok == SIZEOKnone) // if not already done the addMember step
{
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
//printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars());
s->addMember(sc, this, 1);
}
}
sizeok = SIZEOKnone;
Scope *sc2 = sc->push(this);
sc2->stc &= STCsafe | STCtrusted | STCsystem;
sc2->parent = this;
if (isUnionDeclaration())
sc2->inunion = 1;
sc2->protection = Prot(PROTpublic);
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;
/* Set scope so if there are forward references, we still might be able to
* resolve individual members like enums.
*/
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
//printf("struct: setScope %s %s\n", s->kind(), s->toChars());
s->setScope(sc2);
}
for (size_t i = 0; i < members->dim; i++)
//.........这里部分代码省略.........
示例9: semantic
//.........这里部分代码省略.........
if (t->ty == Tstruct)
t = Type::tvoidptr; // t should not be a ref type
assert(!vthis);
vthis = new ThisDeclaration(loc, t);
//vthis->storage_class |= STCref;
members->push(vthis);
}
}
}
}
sizeok = 0;
sc2 = sc->push(this);
sc2->stc &= STCsafe | STCtrusted | STCsystem;
sc2->parent = this;
if (isUnionDeclaration())
sc2->inunion = 1;
sc2->protection = PROTpublic;
sc2->explicitProtection = 0;
size_t members_dim = members->dim;
/* Set scope so if there are forward references, we still might be able to
* resolve individual members like enums.
*/
for (size_t i = 0; i < members_dim; i++)
{ Dsymbol *s = (*members)[i];
/* There are problems doing this in the general case because
* Scope keeps track of things like 'offset'
*/
if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident))
{
//printf("setScope %s %s\n", s->kind(), s->toChars());
s->setScope(sc2);
}
}
for (size_t i = 0; i < members_dim; i++)
{
Dsymbol *s = (*members)[i];
/* If this is the last member, see if we can finish setting the size.
* This could be much better - finish setting the size after the last
* field was processed. The problem is the chicken-and-egg determination
* of when that is. See Bugzilla 7426 for more info.
*/
if (i + 1 == members_dim)
{
if (sizeok == 0 && s->isAliasDeclaration())
finalizeSize();
}
// Ungag errors when not speculative
unsigned oldgag = global.gag;
if (global.isSpeculativeGagging() && !isSpeculative())
global.gag = 0;
s->semantic(sc2);
global.gag = oldgag;
}
if (sizeok == 2)
{ // semantic() failed because of forward references.
// Unwind what we did, and defer it for later
fields.setDim(0);
structsize = 0;
alignsize = 0;
structalign = 0;