// // This is the safe way to change the operator on an aggregate, as it // does lots of error checking and fixing. Especially for establishing // a function call's operation on it's set of parameters. Sequences // of instructions are also aggregates, but they just direnctly set // their operator to EOpSequence. // // Returns an aggregate node, which could be the one passed in if // it was already an aggregate but no operator was set. // TIntermAggregate *TIntermediate::setAggregateOperator( TIntermNode *node, TOperator op, const TSourceLoc &line) { TIntermAggregate *aggNode; // // Make sure we have an aggregate. If not turn it into one. // if (node) { aggNode = node->getAsAggregate(); if (aggNode == NULL || aggNode->getOp() != EOpNull) { // // Make an aggregate containing this node. // aggNode = new TIntermAggregate(); aggNode->getSequence()->push_back(node); } } else { aggNode = new TIntermAggregate(); } // // Set the operator. // aggNode->setOp(op); aggNode->setLine(line); return aggNode; }
// If the input node is nullptr, return nullptr. // If the input node is a sequence (block) node, return it. // If the input node is not a sequence node, put it inside a sequence node and return that. TIntermAggregate *TIntermediate::ensureSequence(TIntermNode *node) { if (node == nullptr) return nullptr; TIntermAggregate *aggNode = node->getAsAggregate(); if (aggNode != nullptr && aggNode->getOp() == EOpSequence) return aggNode; aggNode = makeAggregate(node, node->getLine()); aggNode->setOp(EOpSequence); return aggNode; }
// // This is to be executed once the final root is put on top by the parsing // process. // bool TIntermediate::postProcess(TIntermNode *root) { if (root == NULL) return true; // // First, finish off the top level sequence, if any // TIntermAggregate *aggRoot = root->getAsAggregate(); if (aggRoot && aggRoot->getOp() == EOpNull) aggRoot->setOp(EOpSequence); return true; }
// // This is to be executed once the final root is put on top by the parsing // process. // TIntermAggregate *TIntermediate::postProcess(TIntermNode *root) { if (root == nullptr) return nullptr; // // Finish off the top level sequence, if any // TIntermAggregate *aggRoot = root->getAsAggregate(); if (aggRoot != nullptr && aggRoot->getOp() == EOpNull) { aggRoot->setOp(EOpSequence); } else if (aggRoot == nullptr || aggRoot->getOp() != EOpSequence) { aggRoot = new TIntermAggregate(EOpSequence); aggRoot->setLine(root->getLine()); aggRoot->getSequence()->push_back(root); } return aggRoot; }