Пример #1
0
short BiArithCount::codeGen(Generator * generator)
{
  Attributes ** attr;
  ExpGenerator * eg = generator->getExpGenerator();
  
  if (eg->genItemExpr(this, &attr, (1+getArity()), -1) == 1)
    return 0;

  // if temp space is needed for this operation, set it.
  if (attr[0]->isComplexType())
    {
      eg->addTempsLength(((ComplexType *)attr[0])->setTempSpaceInfo(getOperatorType(),
#pragma nowarn(1506)   // warning elimination 
								    eg->getTempsLength()));
#pragma warn(1506)  // warning elimination 
    }
			      
  ex_arith_count_clause * arith_clause =
    new(generator->getSpace()) 
    ex_arith_count_clause(getOperatorType(), 
			  attr, 
			  generator->getSpace());
  
  generator->getExpGenerator()->linkClause(this, arith_clause);

  return 0;
}
short UnArith::codeGen(Generator * generator)
{
  Attributes ** attr;
  ExpGenerator * eg = generator->getExpGenerator();
  
  if (eg->genItemExpr(this, &attr, (1+getArity()), -1) == 1)
    return 0;


  ex_arith_clause * arith_clause = 
    new(generator->getSpace()) 
    ex_arith_clause(getOperatorType(), attr, generator->getSpace(),
                    0, FALSE);
  
  generator->getExpGenerator()->linkClause(this, arith_clause);

  return 0;
}
// ItmBlockFunction::codeGen
//
// The Block function executes the code represented by both its children and
// then returns the result of the right child (child(1)).
//
short ItmBlockFunction::codeGen(Generator * generator) {
  // Get local handles...
  //
  Attributes **attr;
  Space* space = generator->getSpace();
  CollHeap *heap = generator->wHeap();
  ExpGenerator *exp = generator->getExpGenerator();

  // If this Block has already been codeGenned, then bug out...
  // Otherwise, allocate space for the result if necessary and set
  // attr[0] to point to the result attribute data. Also, mark this
  // node as codeGenned.
  //
  if (exp->genItemExpr(this, &attr, 2, 0) == 1)
    return 0;

  // CodeGen the left child.
  //
  child(0)->codeGen(generator);

  // CodeGen the right child.
  //
  child(1)->codeGen(generator);

  // The result of the Block is the result of the right child. Set
  // the src attribute for the convert (added below) to be the right child
  // The dst attribute has already been set in genItemExpr().
  //
  attr[1] = generator->getMapInfo
    (child(1)->castToItemExpr()->getValueId())->getAttr();

  // Allocate a convert clause to move the result from child(1) to the
  // result of this node. This move is necessary so that future
  // side-effects of the result of child(1) -- if it is a local variable,
  // for instance -- will not change the result of the Block.
  //
  ex_conv_clause * convClause =
    new(generator->getSpace()) ex_conv_clause
    (getOperatorType(), attr, space);
  generator->getExpGenerator()->linkClause(this, convClause);

  return 0;
}
Пример #4
0
short BiArith::codeGen(Generator * generator)
{
  Attributes ** attr;
  ExpGenerator * eg = generator->getExpGenerator();
  
  if (eg->genItemExpr(this, &attr, (1+getArity()), -1) == 1)
    return 0;

  // if temp space is needed for this operation, set it.
  if (attr[0]->isComplexType())
    {
      eg->addTempsLength(((ComplexType *)attr[0])->setTempSpaceInfo(getOperatorType(),
#pragma nowarn(1506)   // warning elimination 
								    eg->getTempsLength()));
#pragma warn(1506)  // warning elimination 
    }
			      
  attr[0]->resetlastdaymonthflag();
  attr[0]->resetlastdayonerrflag();

// Check to see which type of rounding is needed for add_months, date_add
// functions.  Set flags here for use in executor datetime.cpp.
  if (isStandardNormalization())
     attr[0]->setlastdayonerrflag();
  if (isKeepLastDay())
     attr[0]->setlastdaymonthflag();

  ex_arith_clause * arith_clause =
    new(generator->getSpace()) 
    ex_arith_clause(getOperatorType(), attr, generator->getSpace(),
		    (short)getRoundingMode(),
		    getDivToDownscale());

  generator->getExpGenerator()->linkClause(this, arith_clause);

  return 0;
}
// ItmDoWhileFunction::codeGen
//
// The DoWhile function executes the code represented by child(0) until 
// the condition represented by child(1) becomes false. The result of 
// the DoWhile is the final value of child(0).
//
// The looping is accomplished by inserting a NOOP/BRANCH pair. The NOOP
// is inserted before generating the code for either child and serves as a 
// branch target. The BRANCH is inserted after generating the code for
// both children and is targeted at the NOOP clause based on the result of
// child(1). Between the NOOP and the BRANCH the body of the loop (child(0)) 
// and the termination condition (child(1)) are repeatedly evaluated. After
// the branch the final result of the loop body is assigned as the result
// of the DoWhile.
//
short ItmDoWhileFunction::codeGen(Generator * generator) {
  // Get local handles...
  //
  Attributes **attr;
  Space* space = generator->getSpace();
  CollHeap *wHeap = generator->wHeap();
  ExpGenerator *exp = generator->getExpGenerator();

  // If this DoWhile has already been codeGenned, then bug out...
  // Otherwise, allocate space for the result if necessary and set
  // attr[0] to point to the result attribute data. Also, mark this
  // node as codeGenned.
  //
  if (exp->genItemExpr(this, &attr, 2, 0) == 1)
    return 0;

  // Insert the NOOP clause to use as the branch target for the
  // start of the loop body.
  //
  ex_clause * branchTarget = new(space) ex_noop_clause();
  exp->linkClause(this, branchTarget);

  // CodeGen the body of the loop.
  //
  child(0)->codeGen(generator);

  // The result of the DoWhile is the result of the body of the loop. Set
  // the src attribute for the convert (added below) to be the body of
  // the while loop. The dst attribute has already been set in genItemExpr().
  //
  attr[1] = generator->getMapInfo
    (child(0)->castToItemExpr()->getValueId())->getAttr();

  // CodeGen the loop termination condition.
  //
  child(1)->codeGen(generator);

  // Construct a BRANCH clause to loop back and repeat the expression
  // and condition if the condition evaluates to TRUE.
  //
  Attributes ** branchAttrs = new(wHeap) Attributes*[2];
  Attributes *boolAttr = generator->getMapInfo
    (child(1)->castToItemExpr()->getValueId())->getAttr();
  branchAttrs[0] = boolAttr->newCopy(wHeap);
  branchAttrs[1] = boolAttr->newCopy(wHeap);
  //  branchAttrs[0]->copyLocationAttrs(boolAttr);
  //  branchAttrs[1]->copyLocationAttrs(boolAttr);

  branchAttrs[0]->resetShowplan();
  ex_branch_clause * branchClause
    = new(space) ex_branch_clause(ITM_OR, branchAttrs, space);
  branchClause->set_branch_clause(branchTarget);

  // Insert the branch clause into the expression.
  //
  exp->linkClause(this, branchClause);

  // Allocate a convert clause to move the result from child(0) to the
  // result of this node. This move is necessary so that future
  // side-effects of the result of child(0) -- if it is a local variable,
  // for instance -- will not change the result of the DoWhile.
  //
  ex_conv_clause * convClause =
    new(generator->getSpace()) ex_conv_clause
    (getOperatorType(), attr, space);
  exp->linkClause(this, convClause);

  return 0;
}