/******************************************************************************* "this" is the signature of the function object. "s" is the signature of the declaration appearing in the lib module. ********************************************************************************/ bool signature::subtype( const TypeManager* tm, const function* func, const signature& s, const QueryLoc& loc) const { if (paramCount() != s.paramCount()) return false; if (!theQName->equals(s.theQName.getp())) return false; if (theNonOptimizedReturnType.getp() != NULL && s.theNonOptimizedReturnType.getp() != NULL && !TypeOps::is_subtype(tm, *theNonOptimizedReturnType.getp(), *s.theNonOptimizedReturnType.getp(), loc)) { return false; } assert (s.theTypes.size() == theTypes.size() || theIsVariadic); for (csize i = 0; i < theTypes.size(); ++i) { xqtref_t builtinParamType = theTypes[i]; if (func == BUILTIN_FUNC(FN_ZORBA_XML_PARSE_2)) { if (i == 2) { store::Item_t typeName; GENV_ITEMFACTORY->createQName(typeName, static_context::ZORBA_XML_FN_OPTIONS_NS, "", "options"), builtinParamType = tm-> create_node_type(store::StoreConsts::elementNode, typeName, NULL, SequenceType::QUANT_QUESTION, false, false); } } if (!TypeOps::is_subtype(tm, *builtinParamType, // subtype *s.theTypes[i].getp(), // supertype loc)) { return false; } } return true; }
function* fn_sum::specialize( static_context* sctx, const std::vector<xqtref_t>& argTypes) const { RootTypeManager& rtm = GENV_TYPESYSTEM; TypeManager* tm = sctx->get_typemanager(); xqtref_t argType = argTypes[0]; if (TypeOps::is_subtype(tm, *argType, *rtm.UNTYPED_ATOMIC_TYPE_STAR)) { return (getArity() == 1 ? BUILTIN_FUNC(OP_SUM_DOUBLE_1) : BUILTIN_FUNC(OP_SUM_DOUBLE_2)); } else if (TypeOps::is_subtype(tm, *argType, *rtm.DOUBLE_TYPE_STAR)) { return (getArity() == 1 ? BUILTIN_FUNC(OP_SUM_DOUBLE_1) : BUILTIN_FUNC(OP_SUM_DOUBLE_2)); } else if (TypeOps::is_subtype(tm, *argType, *rtm.FLOAT_TYPE_STAR)) { return (getArity() == 1 ? BUILTIN_FUNC(OP_SUM_FLOAT_1) : BUILTIN_FUNC(OP_SUM_FLOAT_2)); } else if (TypeOps::is_subtype(tm, *argType, *rtm.INTEGER_TYPE_STAR)) { return (getArity() == 1 ? BUILTIN_FUNC(OP_SUM_INTEGER_1) : BUILTIN_FUNC(OP_SUM_INTEGER_2)); } else if (TypeOps::is_subtype(tm, *argType, *rtm.DECIMAL_TYPE_STAR)) { return (getArity() == 1 ? BUILTIN_FUNC(OP_SUM_DECIMAL_1) : BUILTIN_FUNC(OP_SUM_DECIMAL_2)); } else { return NULL; } }
flwor_wincond::flwor_wincond( CompilerCB* ccb, static_context* sctx, bool isOnly, const vars& in_vars, const vars& out_vars, expr* cond) : theIsOnly(isOnly), theInputVars(in_vars), theOutputVars(out_vars), theCondExpr(cond), theCCB(ccb) { expr::checkSimpleExpr(theCondExpr); if (sctx != NULL) { TypeManager* tm = sctx->get_typemanager(); xqtref_t condType = theCondExpr->get_return_type(); if (!TypeOps::is_equal(tm, *condType, *GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE, theCondExpr->get_loc())) { theCondExpr = theCCB->theEM-> create_fo_expr(theCondExpr->get_sctx(), theCondExpr->get_udf(), theCondExpr->get_loc(), BUILTIN_FUNC(FN_BOOLEAN_1), theCondExpr); } } }
function* toValueComp(static_context* sctx) const { return BUILTIN_FUNC(OP_VALUE_GREATER_2); }
function* toValueComp(static_context* sctx) const { return BUILTIN_FUNC(OP_VALUE_LESS_EQUAL_2); }
/******************************************************************************* Let f be "this" function, F be the fo expr representing a call to f, and E be the arg of F. This method is used to optimize the exression F(E) by replacing f with another op_node_sort_distinct function g, such that the action set of g is a subset of the action set of f, or by completely eliminating F, if no op_node_sort_distinct action is needed on E. The optimization is based on : (a) The PRODUCES_SORTED_NODES and PRODUCES_DISTINCT_NODES annotations of E, (b) The IGNORES_SORTED_NODES and IGNORES_DUP_NODES annotations of F, and (c) The "noa" param. The "self" param is the fo expr F, and the "child" param is the E expr. ********************************************************************************/ function* op_node_sort_distinct_base::optimize(const expr* self, expr* child) const { TypeManager* tm = self->get_sctx()->get_typemanager(); #if 0 cout << "optimize: self " << self << " child " << child << " self_ignores_sorted " << (self != NULL && self->ignoresSortedNodes()) << " child_prod_sorted " << (child != NULL && child->producesSortedNodes()) << endl; #endif // Get the acction set of "this" function const bool* myActions = this->action(); // Check if the NOA action is really required. bool noa = myActions[NOA]; if (noa) { xqtref_t inputType = child->get_return_type(); if (TypeOps::is_subtype(tm, *inputType, *GENV_TYPESYSTEM.ANY_SIMPLE_TYPE)) { // No action is required at all in this case, because the result is sure // to consist of atomic values only, and this is an allowed result given // that the NOA action is in "this" action set. return NULL; } else if (TypeOps::is_subtype(tm, *inputType, *GENV_TYPESYSTEM.ANY_NODE_TYPE_STAR)) { noa = false; } } // See if duplicate node elimination is really required bool distinct = myActions[DISTINCT]; if (distinct) { if (self != NULL && self->ignoresDuplicateNodes()) distinct = false; if (child != NULL && child->producesDistinctNodes()) distinct = false; } bool sort = (myActions[SORT_ASC] || myActions[SORT_DESC]); if (sort) { if (self != NULL && self->ignoresSortedNodes()) sort = false; if (child != NULL && child->producesSortedNodes() && myActions[SORT_ASC]) sort = false; } if (!sort) { if (distinct && noa) { return BUILTIN_FUNC(OP_DISTINCT_NODES_OR_ATOMICS_1); } else if (distinct) { return (getKind() == FunctionConsts::OP_CHECK_DISTINCT_NODES_1 ? BUILTIN_FUNC(OP_CHECK_DISTINCT_NODES_1) : BUILTIN_FUNC(OP_DISTINCT_NODES_1)); } else if (noa) { return BUILTIN_FUNC(OP_EITHER_NODES_OR_ATOMICS_1); } else { return NULL; } } else if (distinct && noa) { return (myActions[SORT_ASC] ? BUILTIN_FUNC(OP_SORT_DISTINCT_NODES_ASC_OR_ATOMICS_1) : BUILTIN_FUNC(OP_SORT_DISTINCT_NODES_DESC_OR_ATOMICS_1)); } else if (distinct) { return (myActions[SORT_ASC] ? BUILTIN_FUNC(OP_SORT_DISTINCT_NODES_ASC_1) : BUILTIN_FUNC(OP_SORT_DISTINCT_NODES_DESC_1)); } else if (noa) { return (myActions[SORT_ASC] ? BUILTIN_FUNC(OP_SORT_NODES_ASC_OR_ATOMICS_1) : BUILTIN_FUNC(OP_SORT_NODES_DESC_OR_ATOMICS_1)); } else { return (myActions[SORT_ASC] ? BUILTIN_FUNC(OP_SORT_NODES_ASC_1) : BUILTIN_FUNC(OP_SORT_NODES_DESC_1)); } }