本文整理汇总了C++中VarDeclaration::enclosesLifetimeOf方法的典型用法代码示例。如果您正苦于以下问题:C++ VarDeclaration::enclosesLifetimeOf方法的具体用法?C++ VarDeclaration::enclosesLifetimeOf怎么用?C++ VarDeclaration::enclosesLifetimeOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VarDeclaration
的用法示例。
在下文中一共展示了VarDeclaration::enclosesLifetimeOf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkAssignEscape
/****************************************
* Given an AssignExp, determine if the lvalue will cause
* the contents of the rvalue to escape.
* Print error messages when these are detected.
* Infer 'scope' for the lvalue where possible, in order
* to eliminate the error.
* Params:
* sc = used to determine current function and module
* ae = AssignExp to check for any pointers to the stack
* gag = do not print error messages
* Returns:
* true if pointers to the stack can escape via assignment
*/
bool checkAssignEscape(Scope *sc, Expression *e, bool gag)
{
//printf("checkAssignEscape(e: %s)\n", e->toChars());
if (e->op != TOKassign && e->op != TOKblit && e->op != TOKconstruct)
return false;
AssignExp *ae = (AssignExp *)e;
Expression *e1 = ae->e1;
Expression *e2 = ae->e2;
//printf("type = %s, %d\n", e1->type->toChars(), e1->type->hasPointers());
if (!e1->type->hasPointers())
return false;
if (e1->op == TOKslice)
return false;
EscapeByResults er;
escapeByValue(e2, &er);
if (!er.byref.dim && !er.byvalue.dim && !er.byfunc.dim && !er.byexp.dim)
return false;
VarDeclaration *va = NULL;
while (e1->op == TOKdotvar)
e1 = ((DotVarExp *)e1)->e1;
if (e1->op == TOKvar)
va = ((VarExp *)e1)->var->isVarDeclaration();
else if (e1->op == TOKthis)
va = ((ThisExp *)e1)->var->isVarDeclaration();
else if (e1->op == TOKindex)
{
IndexExp *ie = (IndexExp *)e1;
if (ie->e1->op == TOKvar && ie->e1->type->toBasetype()->ty == Tsarray)
va = ((VarExp *)ie->e1)->var->isVarDeclaration();
}
// Try to infer 'scope' for va if in a function not marked @system
bool inferScope = false;
if (va && sc->func && sc->func->type && sc->func->type->ty == Tfunction)
inferScope = ((TypeFunction *)sc->func->type)->trust != TRUSTsystem;
bool result = false;
for (size_t i = 0; i < er.byvalue.dim; i++)
{
VarDeclaration *v = er.byvalue[i];
//printf("byvalue: %s\n", v->toChars());
if (v->isDataseg())
continue;
Dsymbol *p = v->toParent2();
if (!(va && va->isScope()))
v->storage_class &= ~STCmaybescope;
if (v->isScope())
{
if (va && va->isScope() && va->storage_class & STCreturn && !(v->storage_class & STCreturn) &&
sc->func->setUnsafe())
{
if (!gag)
error(ae->loc, "scope variable %s assigned to return scope %s", v->toChars(), va->toChars());
result = true;
continue;
}
// If va's lifetime encloses v's, then error
if (va &&
((va->enclosesLifetimeOf(v) && !(v->storage_class & STCparameter)) ||
// va is class reference
(ae->e1->op == TOKdotvar && va->type->toBasetype()->ty == Tclass && (va->enclosesLifetimeOf(v) || !va->isScope())) ||
va->storage_class & STCref) &&
sc->func->setUnsafe())
{
if (!gag)
error(ae->loc, "scope variable %s assigned to %s with longer lifetime", v->toChars(), va->toChars());
result = true;
continue;
}
if (va && !va->isDataseg() && !va->doNotInferScope)
{
if (!va->isScope() && inferScope)
{ //printf("inferring scope for %s\n", va->toChars());
va->storage_class |= STCscope | STCscopeinferred;
va->storage_class |= v->storage_class & STCreturn;
//.........这里部分代码省略.........