compiler/resolution/lifetime.cpp
/* Consider two variables/arguments a and b.
   Is the lifetime of a strictly within the lifetime for b?
      - e.g. if a is declared in a block nested inside the lifetime of b
 */
Consider two variables/arguments a and b.
Is the lifetime of a strictly within the lifetime for b.
Consider two variables / arguments a and b . Is the lifetime of a strictly within the lifetime for b .
static bool isLifetimeShorter(Lifetime a, Lifetime b) {
  if (a.unknown) 
    return false;
  else if (b.unknown) 
    return true;
  if (a.infinite) 
    return false;
  else if (b.infinite) 
    return true;
  if (a.returnScope && !b.returnScope) 
    return false;
  else if (!a.returnScope && b.returnScope) 
    return true;
  else if (a.fromSymbolScope == b.fromSymbolScope)
    return false;
  else {
    Symbol* aSym = a.fromSymbolScope;
    Symbol* bSym = b.fromSymbolScope;
    BlockStmt* aBlock = getDefBlock(aSym);
    BlockStmt* bBlock = getDefBlock(bSym);
    if (aBlock == bBlock) {
      return false;
    } else {
      return isBlockWithinBlock(aBlock, bBlock);
    }
  }
  return false;
}
static bool isLifetimeShorter ( Lifetime a , Lifetime b ) { if ( a . unknown ) return false ; else if ( b . unknown ) return true ; if ( a . infinite ) return false ; else if ( b . infinite ) return true ; if ( a . returnScope && ! b . returnScope ) return false ; else if ( ! a . returnScope && b . returnScope ) return true ; else if ( a . fromSymbolScope == b . fromSymbolScope ) return false ; else { Symbol * aSym = a . fromSymbolScope ; Symbol * bSym = b . fromSymbolScope ; BlockStmt * aBlock = getDefBlock ( aSym ) ; BlockStmt * bBlock = getDefBlock ( bSym ) ; if ( aBlock == bBlock ) { return false ; } else { return isBlockWithinBlock ( aBlock , bBlock ) ; } } return false ; }
Consider two variables/arguments a and b.
Consider two variables / arguments a and b .
// a unknown, b unknown or not // a not unknown, b unknown // a infinite, b infinite or not // a not infinite, b infinite // a return scope, b not // a not return scope, b is // TODO: check the order of the declarations