本文整理汇总了C++中Dsymbol::toChars方法的典型用法代码示例。如果您正苦于以下问题:C++ Dsymbol::toChars方法的具体用法?C++ Dsymbol::toChars怎么用?C++ Dsymbol::toChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dsymbol
的用法示例。
在下文中一共展示了Dsymbol::toChars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toChars
const char *Dsymbol::toPrettyChars()
{ Dsymbol *p;
char *s;
char *q;
size_t len;
//printf("Dsymbol::toPrettyChars() '%s'\n", toChars());
if (!parent)
return toChars();
len = 0;
for (p = this; p; p = p->parent)
len += strlen(p->toChars()) + 1;
s = (char *)mem.malloc(len);
q = s + len - 1;
*q = 0;
for (p = this; p; p = p->parent)
{
char *t = p->toChars();
len = strlen(t);
q -= len;
memcpy(q, t, len);
if (q == s)
break;
q--;
*q = '.';
}
return s;
}
示例2: toAlias
Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, RootObject *id)
{
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars());
Dsymbol *s = toAlias();
Dsymbol *sm;
if (Declaration *d = s->isDeclaration())
{
if (d->inuse)
{
::error(loc, "circular reference to '%s'", d->toPrettyChars());
return NULL;
}
}
switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
sm = s->search(loc, (Identifier *)id);
break;
case DYNCAST_DSYMBOL:
{
// It's a template instance
//printf("\ttemplate instance id\n");
Dsymbol *st = (Dsymbol *)id;
TemplateInstance *ti = st->isTemplateInstance();
sm = s->search(loc, ti->name);
if (!sm)
{
sm = s->search_correct(ti->name);
if (sm)
error("template identifier '%s' is not a member of '%s %s', did you mean '%s %s'?",
ti->name->toChars(), s->kind(), s->toChars(), sm->kind(), sm->toChars());
else
error("template identifier '%s' is not a member of '%s %s'",
ti->name->toChars(), s->kind(), s->toChars());
return NULL;
}
sm = sm->toAlias();
TemplateDeclaration *td = sm->isTemplateDeclaration();
if (!td)
{
error("%s is not a template, it is a %s", ti->name->toChars(), sm->kind());
return NULL;
}
ti->tempdecl = td;
if (!ti->semanticRun)
ti->semantic(sc);
sm = ti->toAlias();
break;
}
default:
assert(0);
}
return sm;
}
示例3: semantic
void AliasThis::semantic(Scope *sc)
{
Dsymbol *p = sc->parent->pastMixin();
AggregateDeclaration *ad = p->isAggregateDeclaration();
if (!ad)
{
::error(loc, "alias this can only be a member of aggregate, not %s %s",
p->kind(), p->toChars());
return;
}
assert(ad->members);
Dsymbol *s = ad->search(loc, ident);
if (!s)
{
s = sc->search(loc, ident, NULL);
if (s)
::error(loc, "%s is not a member of %s", s->toChars(), ad->toChars());
else
::error(loc, "undefined identifier %s", ident->toChars());
return;
}
else if (ad->aliasthis && s != ad->aliasthis)
{
::error(loc, "there can be only one alias this");
return;
}
if (ad->type->ty == Tstruct && ((TypeStruct *)ad->type)->sym != ad)
{
AggregateDeclaration *ad2 = ((TypeStruct *)ad->type)->sym;
assert(ad2->type == Type::terror);
ad->aliasthis = ad2->aliasthis;
return;
}
/* disable the alias this conversion so the implicit conversion check
* doesn't use it.
*/
ad->aliasthis = NULL;
Dsymbol *sx = s;
if (sx->isAliasDeclaration())
sx = sx->toAlias();
Declaration *d = sx->isDeclaration();
if (d && !d->isTupleDeclaration())
{
Type *t = d->type;
assert(t);
if (ad->type->implicitConvTo(t) > MATCHnomatch)
{
::error(loc, "alias this is not reachable as %s already converts to %s", ad->toChars(), t->toChars());
}
}
ad->aliasthis = s;
}
示例4: printf
void Nspace::semantic2(Scope *sc)
{
if (semanticRun >= PASSsemantic2)
return;
semanticRun = PASSsemantic2;
#if LOG
printf("+Nspace::semantic2('%s')\n", toChars());
#endif
if (members)
{
assert(sc);
sc = sc->push(this);
sc->linkage = LINKcpp;
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->semantic2(sc);
}
sc->pop();
}
#if LOG
printf("-Nspace::semantic2('%s')\n", toChars());
#endif
}
示例5: semantic
void AnonDeclaration::semantic(Scope *sc)
{
//printf("\tAnonDeclaration::semantic %s %p\n", isunion ? "union" : "struct", this);
assert(sc->parent);
Dsymbol *p = sc->parent->pastMixin();
AggregateDeclaration *ad = p->isAggregateDeclaration();
if (!ad)
{
::error(loc, "%s can only be a part of an aggregate, not %s %s",
kind(), p->kind(), p->toChars());
return;
}
alignment = sc->structalign;
if (decl)
{
sc = sc->push();
sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCgshared);
sc->inunion = isunion;
sc->flags = 0;
for (size_t i = 0; i < decl->dim; i++)
{
Dsymbol *s = (*decl)[i];
s->semantic(sc);
}
sc = sc->pop();
}
}
示例6: semantic
void AliasThis::semantic(Scope *sc)
{
Dsymbol *parent = sc->parent;
if (parent)
parent = parent->pastMixin();
AggregateDeclaration *ad = NULL;
if (parent)
ad = parent->isAggregateDeclaration();
if (ad)
{
assert(ad->members);
Dsymbol *s = ad->search(loc, ident, 0);
if (!s)
{ s = sc->search(loc, ident, 0);
if (s)
::error(loc, "%s is not a member of %s", s->toChars(), ad->toChars());
else
::error(loc, "undefined identifier %s", ident->toChars());
}
else if (ad->aliasthis && s != ad->aliasthis)
error("there can be only one alias this");
ad->aliasthis = s;
}
else
error("alias this can only appear in struct or class declaration, not %s", parent ? parent->toChars() : "nowhere");
}
示例7: toChars
const char *Dsymbol::toPrettyChars()
{ Dsymbol *p;
char *s;
char *q;
size_t len;
//printf("Dsymbol::toPrettyChars() '%s'\n", toChars());
if (!parent)
return toChars();
len = 0;
for (p = this; p; p = p->parent)
len += strlen(p->toChars()) + 1;
s = (char *)mem.malloc(len);
q = s + len - 1;
*q = 0;
for (p = this; p; p = p->parent)
{
char *t = p->toChars();
len = strlen(t);
q -= len;
memcpy(q, t, len);
if (q == s)
break;
q--;
#if TARGET_NET
if (AggregateDeclaration* ad = p->isAggregateDeclaration())
{
if (ad->isNested() && p->parent && p->parent->isAggregateDeclaration())
{
*q = '/';
continue;
}
}
#endif
*q = '.';
}
return s;
}
示例8: toAlias
Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id)
{
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars());
Dsymbol *s = toAlias();
Dsymbol *sm;
switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
sm = s->search(loc, id, 0);
break;
case DYNCAST_DSYMBOL:
{ // It's a template instance
//printf("\ttemplate instance id\n");
Dsymbol *st = (Dsymbol *)id;
TemplateInstance *ti = st->isTemplateInstance();
id = ti->name;
sm = s->search(loc, id, 0);
if (!sm)
{ error("template identifier %s is not a member of %s %s",
id->toChars(), s->kind(), s->toChars());
return NULL;
}
sm = sm->toAlias();
TemplateDeclaration *td = sm->isTemplateDeclaration();
if (!td)
{
error("%s is not a template, it is a %s", id->toChars(), sm->kind());
return NULL;
}
ti->tempdecl = td;
if (!ti->semanticRun)
ti->semantic(sc);
sm = ti->toAlias();
break;
}
default:
assert(0);
}
return sm;
}
示例9: ErrorExp
Expression *semanticTraits(TraitsExp *e, Scope *sc)
{
#if LOGSEMANTIC
printf("TraitsExp::semantic() %s\n", e->toChars());
#endif
if (e->ident != Id::compiles && e->ident != Id::isSame &&
e->ident != Id::identifier && e->ident != Id::getProtection)
{
if (!TemplateInstance::semanticTiargs(e->loc, sc, e->args, 1))
return new ErrorExp();
}
size_t dim = e->args ? e->args->dim : 0;
if (e->ident == Id::isArithmetic)
{
return isTypeX(e, &isTypeArithmetic);
}
else if (e->ident == Id::isFloating)
{
return isTypeX(e, &isTypeFloating);
}
else if (e->ident == Id::isIntegral)
{
return isTypeX(e, &isTypeIntegral);
}
else if (e->ident == Id::isScalar)
{
return isTypeX(e, &isTypeScalar);
}
else if (e->ident == Id::isUnsigned)
{
return isTypeX(e, &isTypeUnsigned);
}
else if (e->ident == Id::isAssociativeArray)
{
return isTypeX(e, &isTypeAssociativeArray);
}
else if (e->ident == Id::isStaticArray)
{
return isTypeX(e, &isTypeStaticArray);
}
else if (e->ident == Id::isAbstractClass)
{
return isTypeX(e, &isTypeAbstractClass);
}
else if (e->ident == Id::isFinalClass)
{
return isTypeX(e, &isTypeFinalClass);
}
else if (e->ident == Id::isPOD)
{
if (dim != 1)
goto Ldimerror;
RootObject *o = (*e->args)[0];
Type *t = isType(o);
StructDeclaration *sd;
if (!t)
{
e->error("type expected as second argument of __traits %s instead of %s", e->ident->toChars(), o->toChars());
goto Lfalse;
}
Type *tb = t->baseElemOf();
if (tb->ty == Tstruct
&& ((sd = (StructDeclaration *)(((TypeStruct *)tb)->sym)) != NULL))
{
if (sd->isPOD())
goto Ltrue;
else
goto Lfalse;
}
goto Ltrue;
}
else if (e->ident == Id::isNested)
{
if (dim != 1)
goto Ldimerror;
RootObject *o = (*e->args)[0];
Dsymbol *s = getDsymbol(o);
AggregateDeclaration *a;
FuncDeclaration *f;
if (!s) { }
else if ((a = s->isAggregateDeclaration()) != NULL)
{
if (a->isNested())
goto Ltrue;
else
goto Lfalse;
}
else if ((f = s->isFuncDeclaration()) != NULL)
{
if (f->isNested())
goto Ltrue;
else
goto Lfalse;
}
e->error("aggregate or function expected instead of '%s'", o->toChars());
goto Lfalse;
}
//.........这里部分代码省略.........
示例10: obj_write_deferred
void obj_write_deferred(Library *library)
{
for (size_t i = 0; i < obj_symbols_towrite.dim; i++)
{
Dsymbol *s = obj_symbols_towrite[i];
Module *m = s->getModule();
char *mname;
if (m)
{
mname = m->srcfile->toChars();
lastmname = mname;
}
else
{
//mname = s->ident->toChars();
mname = lastmname;
assert(mname);
}
obj_start(mname);
static int count;
count++; // sequence for generating names
/* Create a module that's a doppelganger of m, with just
* enough to be able to create the moduleinfo.
*/
OutBuffer idbuf;
idbuf.printf("%s.%d", m ? m->ident->toChars() : mname, count);
char *idstr = idbuf.peekString();
if (!m)
{
// it doesn't make sense to make up a module if we don't know where to put the symbol
// so output it into it's own object file without ModuleInfo
objmod->initfile(idstr, NULL, mname);
toObjFile(s, false);
objmod->termfile();
}
else
{
idbuf.data = NULL;
Identifier *id = Identifier::create(idstr, TOKidentifier);
Module *md = Module::create(mname, id, 0, 0);
md->members = Dsymbols_create();
md->members->push(s); // its only 'member' is s
md->doppelganger = 1; // identify this module as doppelganger
md->md = m->md;
md->aimports.push(m); // it only 'imports' m
md->massert = m->massert;
md->munittest = m->munittest;
md->marray = m->marray;
genObjFile(md, false);
}
/* Set object file name to be source name with sequence number,
* as mangled symbol names get way too long.
*/
const char *fname = FileName::removeExt(mname);
OutBuffer namebuf;
unsigned hash = 0;
for (char *p = s->toChars(); *p; p++)
hash += *p;
namebuf.printf("%s_%x_%x.%s", fname, count, hash, global.obj_ext);
FileName::free((char *)fname);
fname = namebuf.extractString();
//printf("writing '%s'\n", fname);
File *objfile = File::create(fname);
obj_end(library, objfile);
}
obj_symbols_towrite.dim = 0;
}
示例11: semantic
void Import::semantic(Scope *sc)
{
//printf("Import::semantic('%s')\n", toChars());
// Load if not already done so
if (!mod)
{ load(sc);
if (mod)
mod->importAll(0);
}
if (mod)
{
#if 0
if (mod->loc.linnum != 0)
{ /* If the line number is not 0, then this is not
* a 'root' module, i.e. it was not specified on the command line.
*/
mod->importedFrom = sc->module->importedFrom;
assert(mod->importedFrom);
}
#endif
// Modules need a list of each imported module
//printf("%s imports %s\n", sc->module->toChars(), mod->toChars());
sc->module->aimports.push(mod);
if (!isstatic && !aliasId && !names.dim)
{
if (sc->explicitProtection)
protection = sc->protection;
for (Scope *scd = sc; scd; scd = scd->enclosing)
{
if (scd->scopesym)
{
scd->scopesym->importScope(mod, protection);
break;
}
}
}
mod->semantic();
if (mod->needmoduleinfo)
{ //printf("module4 %s because of %s\n", sc->module->toChars(), mod->toChars());
sc->module->needmoduleinfo = 1;
}
sc = sc->push(mod);
/* BUG: Protection checks can't be enabled yet. The issue is
* that Dsymbol::search errors before overload resolution.
*/
#if 0
sc->protection = protection;
#else
sc->protection = PROTpublic;
#endif
for (size_t i = 0; i < aliasdecls.dim; i++)
{ Dsymbol *s = aliasdecls[i];
//printf("\tImport alias semantic('%s')\n", s->toChars());
if (mod->search(loc, names[i], 0))
s->semantic(sc);
else
{
s = mod->search_correct(names[i]);
if (s)
mod->error(loc, "import '%s' not found, did you mean '%s %s'?", names[i]->toChars(), s->kind(), s->toChars());
else
mod->error(loc, "import '%s' not found", names[i]->toChars());
}
}
sc = sc->pop();
}
if (global.params.moduleDeps != NULL &&
// object self-imports itself, so skip that (Bugzilla 7547)
!(id == Id::object && sc->module->ident == Id::object))
{
/* The grammar of the file is:
* ImportDeclaration
* ::= BasicImportDeclaration [ " : " ImportBindList ] [ " -> "
* ModuleAliasIdentifier ] "\n"
*
* BasicImportDeclaration
* ::= ModuleFullyQualifiedName " (" FilePath ") : " Protection
* " [ " static" ] : " ModuleFullyQualifiedName " (" FilePath ")"
*
* FilePath
* - any string with '(', ')' and '\' escaped with the '\' character
*/
OutBuffer *ob = global.params.moduleDeps;
ob->writestring(sc->module->toPrettyChars());
ob->writestring(" (");
escapePath(ob, sc->module->srcfile->toChars());
ob->writestring(") : ");
// use protection instead of sc->protection because it couldn't be
//.........这里部分代码省略.........
示例12: if
Initializer *StructInitializer::semantic(Scope *sc, Type *t, int needInterpret)
{
int errors = 0;
//printf("StructInitializer::semantic(t = %s) %s\n", t->toChars(), toChars());
vars.setDim(field.dim);
t = t->toBasetype();
if (t->ty == Tstruct)
{
unsigned fieldi = 0;
TypeStruct *ts = (TypeStruct *)t;
ad = ts->sym;
if (ad->ctor)
error(loc, "%s %s has constructors, cannot use { initializers }, use %s( initializers ) instead",
ad->kind(), ad->toChars(), ad->toChars());
StructDeclaration *sd = ad->isStructDeclaration();
assert(sd);
sd->size(loc);
if (sd->sizeok != SIZEOKdone)
{
error(loc, "struct %s is forward referenced", sd->toChars());
errors = 1;
goto Lerror;
}
size_t nfields = sd->fields.dim;
if (sd->isnested)
nfields--;
for (size_t i = 0; i < field.dim; i++)
{
Identifier *id = field[i];
Initializer *val = value[i];
Dsymbol *s;
VarDeclaration *v;
if (id == NULL)
{
if (fieldi >= nfields)
{ error(loc, "too many initializers for %s", ad->toChars());
errors = 1;
field.remove(i);
i--;
continue;
}
else
{
s = ad->fields[fieldi];
}
}
else
{
//s = ad->symtab->lookup(id);
s = ad->search(loc, id, 0);
if (!s)
{
s = ad->search_correct(id);
if (s)
error(loc, "'%s' is not a member of '%s', did you mean '%s %s'?",
id->toChars(), t->toChars(), s->kind(), s->toChars());
else
error(loc, "'%s' is not a member of '%s'", id->toChars(), t->toChars());
errors = 1;
continue;
}
s = s->toAlias();
// Find out which field index it is
for (fieldi = 0; 1; fieldi++)
{
if (fieldi >= nfields)
{
error(loc, "%s.%s is not a per-instance initializable field",
t->toChars(), s->toChars());
errors = 1;
break;
}
if (s == ad->fields[fieldi])
break;
}
}
if (s && (v = s->isVarDeclaration()) != NULL)
{
val = val->semantic(sc, v->type, needInterpret);
value[i] = val;
vars[i] = v;
}
else
{ error(loc, "%s is not a field of %s", id ? id->toChars() : s->toChars(), ad->toChars());
errors = 1;
}
fieldi++;
}
}
else if (t->ty == Tdelegate && value.dim == 0)
{ /* Rewrite as empty delegate literal { }
*/
Parameters *arguments = new Parameters;
Type *tf = new TypeFunction(arguments, NULL, 0, LINKd);
FuncLiteralDeclaration *fd = new FuncLiteralDeclaration(loc, 0, tf, TOKdelegate, NULL);
fd->fbody = new CompoundStatement(loc, new Statements());
//.........这里部分代码省略.........
示例13: println
DValue *DtoNestedVariable(Loc &loc, Type *astype, VarDeclaration *vd,
bool byref) {
IF_LOG Logger::println("DtoNestedVariable for %s @ %s", vd->toChars(),
loc.toChars());
LOG_SCOPE;
////////////////////////////////////
// Locate context value
Dsymbol *vdparent = vd->toParent2();
assert(vdparent);
IrFunction *irfunc = gIR->func();
// Check whether we can access the needed frame
FuncDeclaration *fd = irfunc->decl;
while (fd && fd != vdparent) {
fd = getParentFunc(fd);
}
if (!fd) {
error(loc, "function `%s` cannot access frame of function `%s`",
irfunc->decl->toPrettyChars(), vdparent->toPrettyChars());
return new DLValue(astype, llvm::UndefValue::get(DtoPtrToType(astype)));
}
// is the nested variable in this scope?
if (vdparent == irfunc->decl) {
return makeVarDValue(astype, vd);
}
// get the nested context
LLValue *ctx = nullptr;
bool skipDIDeclaration = false;
auto currentCtx = gIR->funcGen().nestedVar;
if (currentCtx) {
Logger::println("Using own nested context of current function");
ctx = currentCtx;
} else if (irfunc->decl->isMember2()) {
Logger::println(
"Current function is member of nested class, loading vthis");
AggregateDeclaration *cd = irfunc->decl->isMember2();
LLValue *val = irfunc->thisArg;
if (cd->isClassDeclaration()) {
val = DtoLoad(val);
}
ctx = DtoLoad(DtoGEPi(val, 0, getVthisIdx(cd), ".vthis"));
skipDIDeclaration = true;
} else {
Logger::println("Regular nested function, loading context arg");
ctx = DtoLoad(irfunc->nestArg);
}
assert(ctx);
IF_LOG { Logger::cout() << "Context: " << *ctx << '\n'; }
DtoCreateNestedContextType(vdparent->isFuncDeclaration());
assert(isIrLocalCreated(vd));
////////////////////////////////////
// Extract variable from nested context
const auto frameType = LLPointerType::getUnqual(irfunc->frameType);
IF_LOG { Logger::cout() << "casting to: " << *irfunc->frameType << '\n'; }
LLValue *val = DtoBitCast(ctx, frameType);
IrLocal *const irLocal = getIrLocal(vd);
const auto vardepth = irLocal->nestedDepth;
const auto funcdepth = irfunc->depth;
IF_LOG {
Logger::cout() << "Variable: " << vd->toChars() << '\n';
Logger::cout() << "Variable depth: " << vardepth << '\n';
Logger::cout() << "Function: " << irfunc->decl->toChars() << '\n';
Logger::cout() << "Function depth: " << funcdepth << '\n';
}
if (vardepth == funcdepth) {
// This is not always handled above because functions without
// variables accessed by nested functions don't create new frames.
IF_LOG Logger::println("Same depth");
} else {
// Load frame pointer and index that...
IF_LOG Logger::println("Lower depth");
val = DtoGEPi(val, 0, vardepth);
IF_LOG Logger::cout() << "Frame index: " << *val << '\n';
val = DtoAlignedLoad(
val, (std::string(".frame.") + vdparent->toChars()).c_str());
IF_LOG Logger::cout() << "Frame: " << *val << '\n';
}
const auto idx = irLocal->nestedIndex;
assert(idx != -1 && "Nested context not yet resolved for variable.");
LLSmallVector<int64_t, 2> dwarfAddrOps;
LLValue *gep = DtoGEPi(val, 0, idx, vd->toChars());
val = gep;
IF_LOG {
//.........这里部分代码省略.........
示例14: DtoNestedVariable
DValue* DtoNestedVariable(Loc loc, Type* astype, VarDeclaration* vd, bool byref)
{
Logger::println("DtoNestedVariable for %s @ %s", vd->toChars(), loc.toChars());
LOG_SCOPE;
////////////////////////////////////
// Locate context value
Dsymbol* vdparent = vd->toParent2();
assert(vdparent);
IrFunction* irfunc = gIR->func();
// Check whether we can access the needed frame
FuncDeclaration *fd = irfunc->decl;
while (fd != vdparent) {
if (fd->isStatic()) {
error(loc, "function %s cannot access frame of function %s", irfunc->decl->toPrettyChars(), vdparent->toPrettyChars());
return new DVarValue(astype, vd, llvm::UndefValue::get(getPtrToType(DtoType(astype))));
}
fd = getParentFunc(fd, false);
assert(fd);
}
// is the nested variable in this scope?
if (vdparent == irfunc->decl)
{
LLValue* val = vd->ir.getIrValue();
return new DVarValue(astype, vd, val);
}
LLValue *dwarfValue = 0;
std::vector<LLValue*> dwarfAddr;
LLType *int64Ty = LLType::getInt64Ty(gIR->context());
// get the nested context
LLValue* ctx = 0;
if (irfunc->decl->isMember2())
{
#if DMDV2
AggregateDeclaration* cd = irfunc->decl->isMember2();
LLValue* val = irfunc->thisArg;
if (cd->isClassDeclaration())
val = DtoLoad(val);
#else
ClassDeclaration* cd = irfunc->decl->isMember2()->isClassDeclaration();
LLValue* val = DtoLoad(irfunc->thisArg);
#endif
ctx = DtoLoad(DtoGEPi(val, 0,cd->vthis->ir.irField->index, ".vthis"));
}
else if (irfunc->nestedVar) {
ctx = irfunc->nestedVar;
dwarfValue = ctx;
} else {
ctx = DtoLoad(irfunc->nestArg);
dwarfValue = irfunc->nestArg;
if (global.params.symdebug)
dwarfOpDeref(dwarfAddr);
}
assert(ctx);
DtoCreateNestedContextType(vdparent->isFuncDeclaration());
assert(vd->ir.irLocal);
////////////////////////////////////
// Extract variable from nested context
if (nestedCtx == NCArray) {
LLValue* val = DtoBitCast(ctx, getPtrToType(getVoidPtrType()));
val = DtoGEPi1(val, vd->ir.irLocal->nestedIndex);
val = DtoAlignedLoad(val);
assert(vd->ir.irLocal->value);
val = DtoBitCast(val, vd->ir.irLocal->value->getType(), vd->toChars());
return new DVarValue(astype, vd, val);
}
else if (nestedCtx == NCHybrid) {
LLValue* val = DtoBitCast(ctx, LLPointerType::getUnqual(irfunc->frameType));
Logger::cout() << "Context: " << *val << '\n';
Logger::cout() << "of type: " << *val->getType() << '\n';
unsigned vardepth = vd->ir.irLocal->nestedDepth;
unsigned funcdepth = irfunc->depth;
Logger::cout() << "Variable: " << vd->toChars() << '\n';
Logger::cout() << "Variable depth: " << vardepth << '\n';
Logger::cout() << "Function: " << irfunc->decl->toChars() << '\n';
Logger::cout() << "Function depth: " << funcdepth << '\n';
if (vardepth == funcdepth) {
// This is not always handled above because functions without
// variables accessed by nested functions don't create new frames.
Logger::println("Same depth");
} else {
// Load frame pointer and index that...
if (dwarfValue && global.params.symdebug) {
dwarfOpOffset(dwarfAddr, val, vd->ir.irLocal->nestedDepth);
dwarfOpDeref(dwarfAddr);
}
Logger::println("Lower depth");
val = DtoGEPi(val, 0, vd->ir.irLocal->nestedDepth);
//.........这里部分代码省略.........
示例15: DtoNestedVariable
DValue* DtoNestedVariable(Loc& loc, Type* astype, VarDeclaration* vd, bool byref)
{
IF_LOG Logger::println("DtoNestedVariable for %s @ %s", vd->toChars(), loc.toChars());
LOG_SCOPE;
////////////////////////////////////
// Locate context value
Dsymbol* vdparent = vd->toParent2();
assert(vdparent);
IrFunction* irfunc = gIR->func();
// Check whether we can access the needed frame
FuncDeclaration *fd = irfunc->decl;
while (fd != vdparent) {
if (fd->isStatic()) {
error(loc, "function %s cannot access frame of function %s", irfunc->decl->toPrettyChars(), vdparent->toPrettyChars());
return new DVarValue(astype, vd, llvm::UndefValue::get(getPtrToType(DtoType(astype))));
}
fd = getParentFunc(fd, false);
assert(fd);
}
// is the nested variable in this scope?
if (vdparent == irfunc->decl)
{
LLValue* val = vd->ir.getIrValue();
return new DVarValue(astype, vd, val);
}
LLValue *dwarfValue = 0;
std::vector<LLValue*> dwarfAddr;
// get the nested context
LLValue* ctx = 0;
if (irfunc->nestedVar) {
// If this function has its own nested context struct, always load it.
ctx = irfunc->nestedVar;
dwarfValue = ctx;
} else if (irfunc->decl->isMember2()) {
// If this is a member function of a nested class without its own
// context, load the vthis member.
AggregateDeclaration* cd = irfunc->decl->isMember2();
LLValue* val = irfunc->thisArg;
if (cd->isClassDeclaration())
val = DtoLoad(val);
ctx = DtoLoad(DtoGEPi(val, 0, cd->vthis->ir.irField->index, ".vthis"));
} else {
// Otherwise, this is a simple nested function, load from the context
// argument.
ctx = DtoLoad(irfunc->nestArg);
dwarfValue = irfunc->nestArg;
if (global.params.symdebug)
gIR->DBuilder.OpDeref(dwarfAddr);
}
assert(ctx);
DtoCreateNestedContextType(vdparent->isFuncDeclaration());
assert(vd->ir.irLocal);
////////////////////////////////////
// Extract variable from nested context
LLValue* val = DtoBitCast(ctx, LLPointerType::getUnqual(irfunc->frameType));
IF_LOG {
Logger::cout() << "Context: " << *val << '\n';
Logger::cout() << "of type: " << *irfunc->frameType << '\n';
}
unsigned vardepth = vd->ir.irLocal->nestedDepth;
unsigned funcdepth = irfunc->depth;
IF_LOG {
Logger::cout() << "Variable: " << vd->toChars() << '\n';
Logger::cout() << "Variable depth: " << vardepth << '\n';
Logger::cout() << "Function: " << irfunc->decl->toChars() << '\n';
Logger::cout() << "Function depth: " << funcdepth << '\n';
}
if (vardepth == funcdepth) {
// This is not always handled above because functions without
// variables accessed by nested functions don't create new frames.
IF_LOG Logger::println("Same depth");
} else {
// Load frame pointer and index that...
if (dwarfValue && global.params.symdebug) {
gIR->DBuilder.OpOffset(dwarfAddr, val, vd->ir.irLocal->nestedDepth);
gIR->DBuilder.OpDeref(dwarfAddr);
}
IF_LOG Logger::println("Lower depth");
val = DtoGEPi(val, 0, vd->ir.irLocal->nestedDepth);
IF_LOG Logger::cout() << "Frame index: " << *val << '\n';
val = DtoAlignedLoad(val, (std::string(".frame.") + vdparent->toChars()).c_str());
IF_LOG Logger::cout() << "Frame: " << *val << '\n';
}
int idx = vd->ir.irLocal->nestedIndex;
assert(idx != -1 && "Nested context not yet resolved for variable.");
//.........这里部分代码省略.........