Exemplo n.º 1
0
short Assign::codeGen(Generator * generator)
{
  Attributes ** attr;

  // If this Assign has already been codeGenned, then bug out early.
  //
  MapInfo * assignMapInfo = generator->getMapInfoAsIs(getValueId());
  if (assignMapInfo && assignMapInfo->isCodeGenerated())
    return 0;

  // If the left child (lvalue) is already in the map table, then
  // add the Assign value Id to the map table with the same attributes
  // as the let child. Mark the Assign node as codeGenned. Also, allocate
  // space for the attributes.
  //
  MapInfo *leftChildMapInfo = generator->getMapInfoAsIs
    (child(0)->castToItemExpr()->getValueId());
  if (leftChildMapInfo)
    {
      if (! assignMapInfo)
	assignMapInfo = 
	  generator->addMapInfoToThis(generator->getLastMapTable(), 
				      getValueId(), 
				      leftChildMapInfo->getAttr());
      assignMapInfo->codeGenerated();
      attr = new(generator->wHeap()) Attributes*[2];

      // Set the result attribute
      //
      attr[0] = assignMapInfo->getAttr();
    }
  // Otherwise, go ahead and generate the Assign attributes (which also
  // allocates space for the Assign result). Add the left child to the
  // map table with the same attributes as the Assign node.
  //
  else
    {
      generator->getExpGenerator()->genItemExpr(this, &attr, 2, 0);
      generator->addMapInfoToThis(generator->getLastMapTable(), 
				  child(0)->castToItemExpr()->getValueId(),
				  attr[0]);
    }

  attr[0]->resetShowplan();

  // Now, generate code for the right child (rvalue).
  //
  generator->getExpGenerator()->setClauseLinked(FALSE);
  child(1)->codeGen(generator);
  attr[1] = generator->getAttr(child(1));
  generator->getExpGenerator()->setClauseLinked(FALSE);

  ex_conv_clause * conv_clause =
    new(generator->getSpace()) ex_conv_clause
    (getOperatorType(), attr, generator->getSpace());
  generator->getExpGenerator()->linkClause(this, conv_clause);

  return 0;
}
// A transformation method for protecting sequence functions from not
// being evaluated due to short-circuit evaluation. This is the base
// class implementation which simply recurses on the children unless
// they have already been code-generated.
//
void ItemExpr::protectiveSequenceFunctionTransformation(Generator *generator)
{
  for(Int32 i=0; i<getArity(); i++)
    {
      MapInfo *mapInfo = generator->getMapInfoAsIs(child(i));
      if(!mapInfo || !mapInfo->isCodeGenerated())
	child(i)->protectiveSequenceFunctionTransformation(generator);
    }
}
Exemplo n.º 3
0
short Aggregate::codeGen(Generator * generator)
{
  Attributes ** attr;

  // If this Aggr has already been codeGenned, then bug out early.
  //
  MapInfo * aggrMapInfo = generator->getMapInfoAsIs(getValueId());
  if (aggrMapInfo && aggrMapInfo->isCodeGenerated())
    return 0;

  if (getOperatorType() != ITM_ONE_ROW)
  {
    if (generator->getExpGenerator()->genItemExpr(this, &attr, (1+getArity()), -1) == 1)
      return 0;
  }

  ex_clause * clause = 0;
  
  switch (getOperatorType())
    {
    case ITM_ONE_ROW:
      {
        Int32 degree = 0;
        findnumleaves(this, degree); // degree has number of leaves in the tree

        if (generator->getExpGenerator()->genItemExpr(this, &attr, (1+degree),
                                                               -1) == 1)
          return 0;

	clause =
	  new(generator->getSpace()) ex_aggr_one_row_clause(getOperatorType(),
							    (short)(1+degree), 
							    attr,
							    generator->getSpace());
      }
      break;

    case ITM_ANY_TRUE_MAX:
      {
	clause =
	  new(generator->getSpace()) ex_aggr_any_true_max_clause(getOperatorType(),
								 (short)(1+getArity()), 
								 attr, generator->getSpace());
      }
      break;
      
    default:
      break;
      
    }

  GenAssert(clause, "Aggregate::codeGen -- missing clause!");
  generator->getExpGenerator()->linkClause(this, clause);  

  return 0;
}
Exemplo n.º 4
0
void
markGeneratedEntries(Generator *generator, ItemExpr *item, ValueIdSet &marks)
{
  if(item) {
    MapInfo *mapInfo =
      generator->getMapInfoAsIs(item->getValueId());
    
    if(mapInfo && mapInfo->isCodeGenerated())
      marks += item->getValueId();

    for(Int32 i = 0; i < item->getArity(); i++) {
      markGeneratedEntries(generator,item->child(i), marks);
    }
  }
}
// ItmPersistentExpressionVar::codeGen
//
// Adds the persistent variable to the expression generator.
//
short ItmPersistentExpressionVar::codeGen(Generator * generator) {

  // If the variable has already been codeGenned, bug out...
  //
  MapInfo * mi = generator->getMapInfoAsIs(getValueId());
  if (mi && mi->isCodeGenerated()) return 0;

  // Otherwise, generate the code and add it to the map table.
  //
  generator->getExpGenerator()->addPersistent(getValueId(), 
					      generator->getMapTable());

  // Add the initial value to the persistent list in the ExpGenerator.
  //
  generator->getExpGenerator()->linkPersistent(this);

  // ok...
  //
  return 0;
}