本文整理汇总了C++中Dsymbol::addMember方法的典型用法代码示例。如果您正苦于以下问题:C++ Dsymbol::addMember方法的具体用法?C++ Dsymbol::addMember怎么用?C++ Dsymbol::addMember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dsymbol
的用法示例。
在下文中一共展示了Dsymbol::addMember方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Prot
Scope *Scope::createGlobal(Module *_module)
{
Scope *sc = Scope::alloc();
*sc = Scope(); // memset
sc->aligndecl = NULL;
sc->linkage = LINKd;
sc->inlining = PINLINEdefault;
sc->protection = Prot(PROTpublic);
sc->_module = _module;
sc->tinst = NULL;
sc->minst = _module;
sc->scopesym = new ScopeDsymbol();
sc->scopesym->symtab = new DsymbolTable();
// Add top level package as member of this global scope
Dsymbol *m = _module;
while (m->parent)
m = m->parent;
m->addMember(NULL, sc->scopesym);
m->parent = NULL; // got changed by addMember()
// Create the module scope underneath the global scope
sc = sc->push(_module);
sc->parent = _module;
return sc;
}
示例2: memset
Scope *Scope::createGlobal(Module *module)
{
Scope *sc = Scope::alloc();
memset(sc, 0, sizeof(Scope));
sc->structalign = STRUCTALIGN_DEFAULT;
sc->linkage = LINKd;
sc->inlining = PINLINEdefault;
sc->protection = Prot(PROTpublic);
sc->module = module;
sc->tinst = NULL;
sc->minst = module;
sc->scopesym = new ScopeDsymbol();
sc->scopesym->symtab = new DsymbolTable();
// Add top level package as member of this global scope
Dsymbol *m = module;
while (m->parent)
m = m->parent;
m->addMember(NULL, sc->scopesym);
m->parent = NULL; // got changed by addMember()
// Create the module scope underneath the global scope
sc = sc->push(module);
sc->parent = module;
return sc;
}
示例3: addMember
void Nspace::addMember(Scope *sc, ScopeDsymbol *sds)
{
if (mangleOnly)
parent = sds;
else
ScopeDsymbol::addMember(sc, sds);
if (members)
{
if (!symtab)
symtab = new DsymbolTable();
// The namespace becomes 'imported' into the enclosing scope
for (Scope *sce = sc; 1; sce = sce->enclosing)
{
ScopeDsymbol *sds2 = sce->scopesym;
if (sds2)
{
sds2->importScope(this, Prot(PROTpublic));
break;
}
}
assert(sc);
sc = sc->push(this);
sc->linkage = LINKcpp; // namespaces default to 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);
}
sc->pop();
}
}
示例4: importAll
void Module::importAll(Scope *prevsc)
{
//printf("+Module::importAll(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
if (scope)
return; // already done
/* 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" if this module isn't "object"
if (ident != Id::object)
{
if (members->dim == 0 || ((Dsymbol *)members->data[0])->ident != Id::object)
{
Import *im = new Import(0, NULL, Id::object, NULL, 0);
members->shift(im);
}
}
if (!symtab)
{
// Add all symbols into module's symbol table
symtab = new DsymbolTable();
for (int i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
s->addMember(NULL, 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 (int i = 0; i < members->dim; i++)
{ Dsymbol *s = (Dsymbol *)members->data[i];
s->setScope(sc);
}
for (int i = 0; i < members->dim; i++)
{
Dsymbol *s = (Dsymbol *)members->data[i];
s->importAll(sc);
}
sc = sc->pop();
sc->pop(); // 2 pops because Scope::createGlobal() created 2
}
示例5: addMember
int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
{
int m = 0;
Array *d = include(sc, sd);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
{ Dsymbol *s = (Dsymbol *)d->data[i];
m |= s->addMember(sc, sd, m | memnum);
}
}
return m;
}
示例6: addMember
int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
{
int m = 0;
Dsymbols *d = include(sc, sd);
if (d)
{
for (size_t i = 0; i < d->dim; i++)
{ Dsymbol *s = (*d)[i];
//printf("\taddMember %s to %s\n", s->toChars(), sd->toChars());
m |= s->addMember(sc, sd, m | memnum);
}
}
return m;
}
示例7: addMember
void AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sds)
{
Dsymbols *d = include(sc, sds);
if (d)
{
Scope *sc2 = newScope(sc);
for (size_t i = 0; i < d->dim; i++)
{
Dsymbol *s = (*d)[i];
//printf("\taddMember %s to %s\n", s->toChars(), sds->toChars());
s->addMember(sc2, sds);
}
if (sc2 != sc)
sc2->pop();
}
}
示例8: Scope
Scope *Scope::createGlobal(Module *module)
{
Scope *sc;
sc = new Scope();
sc->module = module;
sc->scopesym = new ScopeDsymbol();
sc->scopesym->symtab = new DsymbolTable();
// Add top level package as member of this global scope
Dsymbol *m = module;
while (m->parent)
m = m->parent;
m->addMember(NULL, sc->scopesym, 1);
m->parent = NULL; // got changed by addMember()
// Create the module scope underneath the global scope
sc = sc->push(module);
sc->parent = module;
return sc;
}
示例9: include
/****************************************
* Different from other AttribDeclaration subclasses, include() call requires
* the completion of addMember and setScope phases.
*/
Dsymbols *StaticIfDeclaration::include(Scope *sc, ScopeDsymbol *sds)
{
//printf("StaticIfDeclaration::include(sc = %p) scope = %p\n", sc, scope);
if (condition->inc == 0)
{
assert(scopesym); // addMember is already done
assert(scope); // setScope is already done
Dsymbols *d = ConditionalDeclaration::include(scope, scopesym);
if (d && !addisdone)
{
// Add members lazily.
for (size_t i = 0; i < d->dim; i++)
{
Dsymbol *s = (*d)[i];
s->addMember(scope, scopesym);
}
// Set the member scopes lazily.
for (size_t i = 0; i < d->dim; i++)
{
Dsymbol *s = (*d)[i];
s->setScope(scope);
}
addisdone = 1;
}
return d;
}
else
{
return ConditionalDeclaration::include(sc, scopesym);
}
}
示例10: semantic
//.........这里部分代码省略.........
if (baseClass->storage_class & STCfinal)
error("cannot inherit from final class %s", baseClass->toChars());
interfaces_dim--;
interfaces++;
// Copy vtbl[] from base class
vtbl.setDim(baseClass->vtbl.dim);
memcpy(vtbl.tdata(), baseClass->vtbl.tdata(), sizeof(void *) * vtbl.dim);
// Inherit properties from base class
com = baseClass->isCOMclass();
isscope = baseClass->isscope;
vthis = baseClass->vthis;
storage_class |= baseClass->storage_class & STC_TYPECTOR;
}
else
{
// No base class, so this is the root of the class hierarchy
vtbl.setDim(0);
vtbl.push(this); // leave room for classinfo as first member
}
protection = sc->protection;
storage_class |= sc->stc;
if (sizeok == SIZEOKnone)
{
interfaceSemantic(sc);
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->addMember(sc, this, 1);
}
/* If this is a nested class, add the hidden 'this'
* member which is a pointer to the enclosing scope.
*/
if (vthis) // if inheriting from nested class
{ // Use the base class's 'this' member
isnested = true;
if (storage_class & STCstatic)
error("static class cannot inherit from nested class %s", baseClass->toChars());
if (toParent2() != baseClass->toParent2() &&
(!toParent2() ||
!baseClass->toParent2()->getType() ||
!baseClass->toParent2()->getType()->isBaseOf(toParent2()->getType(), NULL)))
{
if (toParent2())
{
error("is nested within %s, but super class %s is nested within %s",
toParent2()->toChars(),
baseClass->toChars(),
baseClass->toParent2()->toChars());
}
else
{
error("is not nested, but super class %s is nested within %s",
baseClass->toChars(),
baseClass->toParent2()->toChars());
}
isnested = false;
}
}
else if (!(storage_class & STCstatic))
示例11: include
int IftypeCondition::include(Scope *sc, ScopeDsymbol *sd)
{
//printf("IftypeCondition::include()\n");
if (inc == 0)
{
if (!sc)
{
error(loc, "iftype conditional cannot be at global scope");
inc = 2;
return 0;
}
Type *t = targ->trySemantic(loc, sc);
if (t)
targ = t;
else
inc = 2; // condition is false
if (!t)
{
}
else if (id && tspec)
{
/* Evaluate to TRUE if targ matches tspec.
* If TRUE, declare id as an alias for the specialized type.
*/
MATCH m;
TemplateTypeParameter tp(loc, id, NULL, NULL);
TemplateParameters parameters;
parameters.setDim(1);
parameters[0] = &tp;
Objects dedtypes;
dedtypes.setDim(1);
m = targ->deduceType(sc, tspec, ¶meters, &dedtypes);
if (m == MATCHnomatch ||
(m != MATCHexact && tok == TOKequal))
inc = 2;
else
{
inc = 1;
Type *tded = (Type *)dedtypes[0];
if (!tded)
tded = targ;
Dsymbol *s = new AliasDeclaration(loc, id, tded);
s->semantic(sc);
sc->insert(s);
if (sd)
s->addMember(sc, sd, 1);
}
}
else if (id)
{
/* Declare id as an alias for type targ. Evaluate to TRUE
*/
Dsymbol *s = new AliasDeclaration(loc, id, targ);
s->semantic(sc);
sc->insert(s);
if (sd)
s->addMember(sc, sd, 1);
inc = 1;
}
else if (tspec)
{
/* Evaluate to TRUE if targ matches tspec
*/
tspec = tspec->semantic(loc, sc);
//printf("targ = %s\n", targ->toChars());
//printf("tspec = %s\n", tspec->toChars());
if (tok == TOKcolon)
{ if (targ->implicitConvTo(tspec))
inc = 1;
else
inc = 2;
}
else /* == */
{ if (targ->equals(tspec))
inc = 1;
else
inc = 2;
}
}
else
inc = 1;
//printf("inc = %d\n", inc);
}
return (inc == 1);
}
示例12: semantic
//.........这里部分代码省略.........
interfaces_dim--;
interfaces++;
// Copy vtbl[] from base class
vtbl.setDim(baseClass->vtbl.dim);
memcpy(vtbl.tdata(), baseClass->vtbl.tdata(), sizeof(void *) * vtbl.dim);
// Inherit properties from base class
com = baseClass->isCOMclass();
if (baseClass->isCPPclass())
cpp = 1;
isscope = baseClass->isscope;
vthis = baseClass->vthis;
enclosing = baseClass->enclosing;
storage_class |= baseClass->storage_class & STC_TYPECTOR;
}
else
{
// No base class, so this is the root of the class hierarchy
vtbl.setDim(0);
if (vtblOffset())
vtbl.push(this); // leave room for classinfo as first member
}
protection = sc->protection;
storage_class |= sc->stc;
interfaceSemantic(sc);
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->addMember(sc, this, 1);
}
/* If this is a nested class, add the hidden 'this'
* member which is a pointer to the enclosing scope.
*/
if (vthis) // if inheriting from nested class
{
// Use the base class's 'this' member
if (storage_class & STCstatic)
error("static class cannot inherit from nested class %s", baseClass->toChars());
if (toParent2() != baseClass->toParent2() &&
(!toParent2() ||
!baseClass->toParent2()->getType() ||
!baseClass->toParent2()->getType()->isBaseOf(toParent2()->getType(), NULL)))
{
if (toParent2())
{
error("is nested within %s, but super class %s is nested within %s",
toParent2()->toChars(),
baseClass->toChars(),
baseClass->toParent2()->toChars());
}
else
{
error("is not nested, but super class %s is nested within %s",
baseClass->toChars(),
baseClass->toParent2()->toChars());
}
enclosing = NULL;
}
}
else
示例13: if
//.........这里部分代码省略.........
if (dtor)
{
tmp = new VarDeclaration(loc, type, idtmp, new VoidInitializer(loc));
tmp->noscope = 1;
tmp->storage_class |= STCctfe;
e = new DeclarationExp(loc, tmp);
ec = new AssignExp(loc,
new VarExp(loc, tmp),
new ThisExp(loc)
);
ec->op = TOKblit;
e = Expression::combine(e, ec);
}
ec = new AssignExp(loc,
new ThisExp(loc),
new IdentifierExp(loc, Id::p));
ec->op = TOKblit;
e = Expression::combine(e, ec);
if (dtor)
{
/* Instead of running the destructor on s, run it
* on tmp. This avoids needing to copy tmp back in to s.
*/
Expression *ec2 = new DotVarExp(loc, new VarExp(loc, tmp), dtor, 0);
ec2 = new CallExp(loc, ec2);
e = Expression::combine(e, ec2);
}
}
else
{
/* Do memberwise copy
*/
//printf("\tmemberwise copy\n");
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->isField());
// this.v = s.v;
AssignExp *ec = new AssignExp(loc,
new DotVarExp(loc, new ThisExp(loc), v, 0),
new DotVarExp(loc, new IdentifierExp(loc, Id::p), v, 0));
e = Expression::combine(e, ec);
}
}
if (e)
{
Statement *s1 = new ExpStatement(loc, e);
/* Add:
* return this;
*/
e = new ThisExp(loc);
Statement *s2 = new ReturnStatement(loc, e);
fop->fbody = new CompoundStatement(loc, s1, s2);
}
Dsymbol *s = fop;
#if 1 // workaround until fixing issue 1528
Dsymbol *assign = search_function(this, Id::assign);
if (assign && assign->isTemplateDeclaration())
{
// Wrap a template around the function declaration
TemplateParameters *tpl = new TemplateParameters();
Dsymbols *decldefs = new Dsymbols();
decldefs->push(s);
TemplateDeclaration *tempdecl =
new TemplateDeclaration(assign->loc, fop->ident, tpl, NULL, decldefs, 0);
s = tempdecl;
}
#endif
members->push(s);
s->addMember(sc, this, 1);
this->hasIdentityAssign = 1; // temporary mark identity assignable
unsigned errors = global.startGagging(); // Do not report errors, even if the
unsigned oldspec = global.speculativeGag; // template opAssign fbody makes it.
global.speculativeGag = global.gag;
Scope *sc2 = sc->push();
sc2->stc = 0;
sc2->linkage = LINKd;
sc2->speculative = true;
s->semantic(sc2);
s->semantic2(sc2);
s->semantic3(sc2);
sc2->pop();
global.speculativeGag = oldspec;
if (global.endGagging(errors)) // if errors happened
{ // Disable generated opAssign, because some members forbid identity assignment.
fop->storage_class |= STCdisable;
fop->fbody = NULL; // remove fbody which contains the error
}
//printf("-StructDeclaration::buildOpAssign() %s %s, errors = %d\n", toChars(), s->kind(), (fop->storage_class & STCdisable) != 0);
return fop;
}
示例14: 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
}
示例15: if
//.........这里部分代码省略.........
}
Parameters *fparams = new Parameters;
fparams->push(new Parameter(STCnodtor, sd->type, Id::p, NULL));
Type *tf = new TypeFunction(fparams, sd->handleType(), 0, LINKd, stc | STCref);
FuncDeclaration *fop = new FuncDeclaration(declLoc, Loc(), Id::assign, stc, tf);
Expression *e = NULL;
if (stc & STCdisable)
{
}
else if (sd->dtor || sd->postblit)
{
/* Do swap this and rhs
* tmp = this; this = s; tmp.dtor();
*/
//printf("\tswap copy\n");
Identifier *idtmp = Lexer::uniqueId("__tmp");
VarDeclaration *tmp = NULL;
AssignExp *ec = NULL;
if (sd->dtor)
{
tmp = new VarDeclaration(loc, sd->type, idtmp, new VoidInitializer(loc));
tmp->noscope = 1;
tmp->storage_class |= STCtemp | STCctfe;
e = new DeclarationExp(loc, tmp);
ec = new BlitExp(loc, new VarExp(loc, tmp), new ThisExp(loc));
e = Expression::combine(e, ec);
}
ec = new BlitExp(loc, new ThisExp(loc), new IdentifierExp(loc, Id::p));
e = Expression::combine(e, ec);
if (sd->dtor)
{
/* Instead of running the destructor on s, run it
* on tmp. This avoids needing to copy tmp back in to s.
*/
Expression *ec2 = new DotVarExp(loc, new VarExp(loc, tmp), sd->dtor, 0);
ec2 = new CallExp(loc, ec2);
e = Expression::combine(e, ec2);
}
}
else
{
/* Do memberwise copy
*/
//printf("\tmemberwise copy\n");
for (size_t i = 0; i < sd->fields.dim; i++)
{
VarDeclaration *v = sd->fields[i];
// this.v = s.v;
AssignExp *ec = new AssignExp(loc,
new DotVarExp(loc, new ThisExp(loc), v, 0),
new DotVarExp(loc, new IdentifierExp(loc, Id::p), v, 0));
e = Expression::combine(e, ec);
}
}
if (e)
{
Statement *s1 = new ExpStatement(loc, e);
/* Add:
* return this;
*/
e = new ThisExp(loc);
Statement *s2 = new ReturnStatement(loc, e);
fop->fbody = new CompoundStatement(loc, s1, s2);
}
Dsymbol *s = fop;
sd->members->push(s);
s->addMember(sc, sd, 1);
sd->hasIdentityAssign = true; // temporary mark identity assignable
unsigned errors = global.startGagging(); // Do not report errors, even if the
unsigned oldspec = global.speculativeGag; // template opAssign fbody makes it.
global.speculativeGag = global.gag;
Scope *sc2 = sc->push();
sc2->stc = 0;
sc2->linkage = LINKd;
sc2->speculative = true;
s->semantic(sc2);
s->semantic2(sc2);
s->semantic3(sc2);
sc2->pop();
global.speculativeGag = oldspec;
if (global.endGagging(errors)) // if errors happened
{
// Disable generated opAssign, because some members forbid identity assignment.
fop->storage_class |= STCdisable;
fop->fbody = NULL; // remove fbody which contains the error
}
//printf("-StructDeclaration::buildOpAssign() %s %s, errors = %d\n", toChars(), s->kind(), (fop->storage_class & STCdisable) != 0);
return fop;
}