void ASTUnaryFunctionNode::write(XMLOutputStream& stream) const { if (&stream == NULL) return; stream.startElement("apply"); //const char * name = ASTBase::getNameFromType(type); ASTBase::writeStartEndElement(stream); /* write the one child * note we expect to have one child but cannot guarantee it */ unsigned int numChildren = getNumChildren(); /* HACK TO REPLICATE OLD AST */ /* for log 10 write out the logbase explicilty * for sqrt write out the degree explicilty * NOTE the qualifier node will add the necessary integers */ if (numChildren == 1) { if (isLog10() == true) { ASTQualifierNode * logbase = new ASTQualifierNode(AST_QUALIFIER_LOGBASE); logbase->write(stream); delete logbase; } else if (isSqrt() == true) { ASTQualifierNode * degree = new ASTQualifierNode(AST_QUALIFIER_DEGREE); degree->write(stream); delete degree; } ASTFunctionBase::getChild(0)->write(stream); } else { for (unsigned int n = 0; n < numChildren; n++) { ASTFunctionBase::getChild(n)->write(stream); } } stream.endElement("apply"); }
void ASTLambdaFunctionNode::write(XMLOutputStream& stream) const { ASTBase::writeStartElement(stream); /* HACK TO REPLICATE OLD AST */ /* all but the last child will be wrapped as bvars * even if they are technically not */ unsigned int numChildren = ASTFunctionBase::getNumChildren(); for (unsigned int i = 0; i < numChildren; i++) { if (i < numChildren-1 && ASTFunctionBase::getChild(i)->getType() != AST_QUALIFIER_BVAR) { ASTQualifierNode * bvar = new ASTQualifierNode(AST_QUALIFIER_BVAR); bvar->addChild(ASTFunctionBase::getChild(i)->deepCopy()); bvar->write(stream); delete bvar; } else { ASTFunctionBase::getChild(i)->write(stream); } } stream.endElement("lambda"); }
void ASTNaryFunctionNode::write(XMLOutputStream& stream) const { int type = getType(); unsigned int numChildren = getNumChildren(); if (numChildren <= 2 && (type == AST_PLUS || type == AST_TIMES)) { writeNodeOfType(stream, type); } else if (type == AST_UNKNOWN && numChildren == 0) { // we have an empty apply tag stream.startEndElement("apply"); } else { stream.startElement("apply"); //const char * name = ASTBase::getNameFromType(type); ASTBase::writeStartEndElement(stream); /* write children */ /* HACK TO REPLICATE OLD AST */ /* for log/root with two or more children assume first is logbase/degree * and last is the value operated on * * however if the node is read in with a logbase and then more than * further children it uses the first as the value operated on */ if (type == AST_FUNCTION_ROOT) { if (numChildren > 1) { if (ASTFunctionBase::getChild(0)->getType() != AST_QUALIFIER_DEGREE) { ASTQualifierNode * logbase = new ASTQualifierNode(AST_QUALIFIER_DEGREE); logbase->addChild(ASTFunctionBase::getChild(0)->deepCopy()); logbase->write(stream); delete logbase; ASTFunctionBase::getChild(numChildren-1)->write(stream); } else { /* if there is only 1 child that is logbase we dont write either */ ASTFunctionBase::getChild(0)->write(stream); ASTFunctionBase::getChild(numChildren-1)->write(stream); } } else { ASTFunctionBase::getChild(0)->write(stream); } } else { for (unsigned int i = 0; i < ASTFunctionBase::getNumChildren(); i++) { ASTFunctionBase::getChild(i)->write(stream); } } stream.endElement("apply"); } }
void ASTBinaryFunctionNode::write(XMLOutputStream& stream) const { if (&stream == NULL) return; int type = getType(); stream.startElement("apply"); //const char * name = ASTBase::getNameFromType(type); ASTBase::writeStartEndElement(stream); /* HACK TO REPLICATE OLD AST */ /* for divide/power(operator) only write the first and last child * any other write all children */ /* write the two children * note we expect to have two children but cannot guarantee it */ unsigned int numChildren = getNumChildren(); if (type == AST_DIVIDE || type == AST_POWER) { if (numChildren > 0) { ASTFunctionBase::getChild(0)->write(stream); } if (numChildren > 1) { ASTFunctionBase::getChild(numChildren - 1)->write(stream); } } /* HACK TO REPLICATE OLD AST */ /* for log/root with two or more children assume first is logbase/degree * and last is the value operated on * * however if the node is read in with a logbase and then more than * further children it uses the first as the value operated on */ else if (type == AST_FUNCTION_LOG) { if (numChildren > 1) { if (ASTFunctionBase::getChild(0)->getType() != AST_QUALIFIER_LOGBASE) { ASTQualifierNode * logbase = new ASTQualifierNode(AST_QUALIFIER_LOGBASE); logbase->addChild(ASTFunctionBase::getChild(0)->deepCopy()); logbase->write(stream); delete logbase; ASTFunctionBase::getChild(numChildren-1)->write(stream); } else { /* if there is only 1 child that is logbase we dont write either */ ASTFunctionBase::getChild(0)->write(stream); ASTFunctionBase::getChild(numChildren-1)->write(stream); } } } else { for (unsigned int n = 0; n < numChildren; n++) { ASTFunctionBase::getChild(n)->write(stream); } } stream.endElement("apply"); }