/** * Visits the given ASTNode as a function. For this node only the * traversal is preorder. */ void L3FormulaFormatter_visitFunction ( const ASTNode_t *parent, const ASTNode_t *node, StringBuffer_t *sb, const L3ParserSettings_t *settings ) { unsigned int numChildren = ASTNode_getNumChildren(node); unsigned int n; L3FormulaFormatter_format(sb, node, settings); StringBuffer_appendChar(sb, '('); if (numChildren > 0) { L3FormulaFormatter_visit( node, ASTNode_getChild(node, 0), sb, settings); } for (n = 1; n < numChildren; n++) { StringBuffer_appendChar(sb, ','); StringBuffer_appendChar(sb, ' '); L3FormulaFormatter_visit( node, ASTNode_getChild(node, n), sb, settings); } StringBuffer_appendChar(sb, ')'); }
/** * Visits the given ASTNode and continues the inorder traversal. */ void L3FormulaFormatter_visitOther ( const ASTNode_t *parent, const ASTNode_t *node, StringBuffer_t *sb, const L3ParserSettings_t *settings ) { unsigned int numChildren = ASTNode_getNumChildren(node); unsigned int group = L3FormulaFormatter_isGrouped(parent, node, settings); unsigned int n; if (group) { StringBuffer_appendChar(sb, '('); } if (numChildren == 0) { L3FormulaFormatter_format(sb, node, settings); } else if (numChildren == 1) { //I believe this would only be called for invalid ASTNode setups, // but this could in theory occur. This is the safest // behavior I can think of. L3FormulaFormatter_format(sb, node, settings); StringBuffer_appendChar(sb, '('); L3FormulaFormatter_visit( node, ASTNode_getChild(node, 0), sb, settings); StringBuffer_appendChar(sb, ')'); } else { L3FormulaFormatter_visit( node, ASTNode_getChild(node, 0), sb, settings); for (n = 1; n < numChildren; n++) { L3FormulaFormatter_format(sb, node, settings); L3FormulaFormatter_visit( node, ASTNode_getChild(node, n), sb, settings); } } if (group) { StringBuffer_appendChar(sb, ')'); } }
END_TEST START_TEST (test_L3FormulaFormatter_accessWithNULL) { // ensure we survive NULL arguments L3FormulaFormatter_format(NULL, NULL, NULL); L3FormulaFormatter_formatFunction(NULL, NULL, NULL); L3FormulaFormatter_formatOperator(NULL, NULL); L3FormulaFormatter_visit(NULL, NULL, NULL, NULL); L3FormulaFormatter_visitFunction(NULL, NULL, NULL, NULL); L3FormulaFormatter_visitLog10(NULL, NULL, NULL, NULL); L3FormulaFormatter_visitOther(NULL, NULL, NULL, NULL); L3FormulaFormatter_visitSqrt(NULL, NULL, NULL, NULL); L3FormulaFormatter_visitUMinus(NULL, NULL, NULL, NULL); fail_unless( L3FormulaFormatter_isFunction(NULL, NULL) == 0 ); fail_unless( L3FormulaFormatter_isGrouped(NULL, NULL, NULL) == 0 ); fail_unless( SBML_formulaToL3String(NULL) == NULL ); }