Example #1
0
//
// For "if" test nodes.  There are three children; a condition,
// a true path, and a false path.  The two paths are in the
// nodePair.
//
// Returns the selection node created.
//
TIntermNode *TIntermediate::addSelection(
    TIntermTyped *cond, TIntermNodePair nodePair, const TSourceLoc &line)
{
    //
    // For compile time constant selections, prune the code and
    // test now.
    //

    if (cond->getAsTyped() && cond->getAsTyped()->getAsConstantUnion())
    {
        if (cond->getAsConstantUnion()->getBConst(0) == true)
        {
            return nodePair.node1 ? setAggregateOperator(
                nodePair.node1, EOpSequence, nodePair.node1->getLine()) : NULL;
        }
        else
        {
            return nodePair.node2 ? setAggregateOperator(
                nodePair.node2, EOpSequence, nodePair.node2->getLine()) : NULL;
        }
    }

    TIntermSelection *node = new TIntermSelection(
        cond, nodePair.node1, nodePair.node2);
    node->setLine(line);

    return node;
}
Example #2
0
// For "if" test nodes.  There are three children; a condition,
// a true path, and a false path.  The two paths are in the
// nodePair.
//
// Returns the node created.
TIntermNode *TIntermediate::addIfElse(TIntermTyped *cond,
                                      TIntermNodePair nodePair,
                                      const TSourceLoc &line)
{
    // For compile time constant conditions, prune the code now.

    if (cond->getAsConstantUnion())
    {
        if (cond->getAsConstantUnion()->getBConst(0) == true)
        {
            return nodePair.node1 ? setAggregateOperator(nodePair.node1, EOpSequence,
                                                         nodePair.node1->getLine())
                                  : nullptr;
        }
        else
        {
            return nodePair.node2 ? setAggregateOperator(nodePair.node2, EOpSequence,
                                                         nodePair.node2->getLine())
                                  : nullptr;
        }
    }

    TIntermIfElse *node =
        new TIntermIfElse(cond, ensureSequence(nodePair.node1), ensureSequence(nodePair.node2));
    node->setLine(line);

    return node;
}