Beispiel #1
0
ASTNode* Intersect::staticResolution(StaticContext *context)
{
  XPath2MemoryManager *mm = context->getMemoryManager();

  if(!sortAdded_) {
    sortAdded_ = true;
    // Wrap ourselves in a document order sort
    ASTNode *result = new (mm) XQDocumentOrder(this, mm);
    result->setLocationInfo(this);
    return result->staticResolution(context);
  }

  for(VectorOfASTNodes::iterator i = _args.begin(); i != _args.end(); ++i) {
    SequenceType *seqType = new (mm) SequenceType(new (mm) SequenceType::ItemType(SequenceType::ItemType::TEST_NODE),
                                                  SequenceType::STAR);
    seqType->setLocationInfo(this);

    *i = new (mm) XQTreatAs(*i, seqType, mm);
    (*i)->setLocationInfo(this);

    *i = (*i)->staticResolution(context);
  }

  return this;
}
Beispiel #2
0
XERCES_CPP_NAMESPACE_USE
#endif

FTSelection *FTDistance::staticResolution(StaticContext *context)
{
    XPath2MemoryManager *mm = context->getMemoryManager();

    SequenceType *seqType = new (mm) SequenceType(SchemaSymbols::fgURI_SCHEMAFORSCHEMA,
            SchemaSymbols::fgDT_INTEGER,
            SequenceType::EXACTLY_ONE, mm);
    seqType->setLocationInfo(this);

    arg_ = arg_->staticResolution(context);

    range_.arg1 = new (mm) XQAtomize(range_.arg1, mm);
    range_.arg1->setLocationInfo(this);
    range_.arg1 = new (mm) XQTreatAs(range_.arg1, seqType, mm);
    range_.arg1->setLocationInfo(this);
    range_.arg1 = range_.arg1->staticResolution(context);

    if(range_.arg2 != NULL) {
        range_.arg2 = new (mm) XQAtomize(range_.arg2, mm);
        range_.arg2->setLocationInfo(this);
        range_.arg2 = new (mm) XQTreatAs(range_.arg2, seqType, mm);
        range_.arg2->setLocationInfo(this);
        range_.arg2 = range_.arg2->staticResolution(context);
    }

    return this;
}
Beispiel #3
0
ASTNode *UTransform::staticResolution(StaticContext* context)
{
    XPath2MemoryManager *mm = context->getMemoryManager();

    VectorOfCopyBinding::iterator end = bindings_->end();
    for(VectorOfCopyBinding::iterator it0 = bindings_->begin(); it0 != end; ++it0) {
        // Work out the uri and localname of the variable binding
        const XMLCh* prefix=XPath2NSUtils::getPrefix((*it0)->qname_, mm);
        if(prefix && *prefix)
            (*it0)->uri_ = context->getUriBoundToPrefix(prefix, this);
        (*it0)->name_ = XPath2NSUtils::getLocalName((*it0)->qname_);

        SequenceType *copyType = new (mm) SequenceType(new (mm) SequenceType::ItemType(SequenceType::ItemType::TEST_NODE),
                SequenceType::EXACTLY_ONE);
        copyType->setLocationInfo(this);

        // call static resolution on the value
        (*it0)->expr_ = new (mm) XQCopyOf((*it0)->expr_, /*copyNamespaces*/true, mm);
        (*it0)->expr_->setLocationInfo(this);
        (*it0)->expr_ = new (mm) XQTreatAs((*it0)->expr_, copyType, mm, err_XUTY0013);
        (*it0)->expr_->setLocationInfo(this);
        (*it0)->expr_ = (*it0)->expr_->staticResolution(context);
    }

    // Call staticResolution on the modify expression
    modify_ = modify_->staticResolution(context);

    // Call staticResolution on the return expression
    return_ = return_->staticResolution(context);

    valMode_ = context->getRevalidationMode();

    return this;
}
Beispiel #4
0
ASTNode* FunctionZeroOrOne::staticResolution(StaticContext *context)
{
  XPath2MemoryManager *mm = context->getMemoryManager();

  SequenceType *seqType = new (mm) SequenceType(new (mm) SequenceType::ItemType(SequenceType::ItemType::TEST_ANYTHING),
                                                SequenceType::QUESTION_MARK);
  seqType->setLocationInfo(this);

  ASTNode *result = new (mm) XQTreatAs(_args.front(), seqType, mm, err_FORG0003);
  result->setLocationInfo(this);
  return result->staticResolution(context);
}
Beispiel #5
0
ASTNode *UDelete::staticResolution(StaticContext *context)
{
  XPath2MemoryManager *mm = context->getMemoryManager();

  SequenceType *seqType = new (mm) SequenceType(new (mm) SequenceType::ItemType(SequenceType::ItemType::TEST_NODE),
                                                SequenceType::STAR);
  seqType->setLocationInfo(this);

  expr_ = new (mm) XQTreatAs(expr_, seqType, mm, err_XUTY0007);
  expr_->setLocationInfo(this);

  expr_ = expr_->staticResolution(context);
  return this;
}
Beispiel #6
0
ASTNode* XQNameExpression::staticResolution(StaticContext *context)
{
    XPath2MemoryManager *mm = context->getMemoryManager();

    expr_ = new (mm) XQAtomize(expr_, mm);
    expr_->setLocationInfo(this);
    SequenceType *seqType = new (mm) SequenceType(new (mm) SequenceType::ItemType(SequenceType::ItemType::TEST_ANYTHING),
            SequenceType::EXACTLY_ONE);
    seqType->setLocationInfo(this);
    expr_ = new (mm) XQTreatAs(expr_, seqType, mm);
    expr_->setLocationInfo(this);
    expr_ = expr_->staticResolution(context);

    return this;
}
Beispiel #7
0
ASTNode *XQFunctionDeref::staticResolution(StaticContext *context)
{
  XPath2MemoryManager *mm = context->getMemoryManager();

  SequenceType *seqType = new (mm) SequenceType(new (mm) SequenceType::ItemType(SequenceType::ItemType::TEST_FUNCTION),
                                                SequenceType::EXACTLY_ONE);
  seqType->setLocationInfo(this);

  expr_ = new (mm) XQTreatAs(expr_, seqType, mm);
  expr_->setLocationInfo(this);
  expr_ = expr_->staticResolution(context);

  if(args_) {
    for(VectorOfASTNodes::iterator i = args_->begin(); i != args_->end(); ++i) {
      *i = (*i)->staticResolution(context);
    }
  }

  return this;
}
ASTNode* ArithmeticOperator::staticResolution(StaticContext *context)
{
  XPath2MemoryManager *mm = context->getMemoryManager();

  for(VectorOfASTNodes::iterator i = _args.begin(); i != _args.end(); ++i) {
    // An arithmetic expression is evaluated by applying the following rules, in order,
    // until an error is raised or a value is computed:

    // 1. Atomization is applied to each operand.

    *i = new (mm) XQAtomize(*i, mm);
    (*i)->setLocationInfo(this);

    // 2. If either operand is an empty sequence, the result of the operation is an empty sequence.
    // 3. If either operand is now a sequence of length greater than one, then:
    //      * If XPath 1.0 compatibility mode is true, any items after the first item in the sequence are discarded.
    //        Otherwise, a type error is raised.

    if(!context->getXPath1CompatibilityMode()) {
      SequenceType *seqType = new (mm) SequenceType(new (mm) SequenceType::ItemType(SequenceType::ItemType::TEST_ANYTHING),
                                                    SequenceType::QUESTION_MARK);
      seqType->setLocationInfo(*i);

      *i = new (mm) XQTreatAs(*i, seqType, mm);
      (*i)->setLocationInfo(this);
    }

    // 4. If either operand is now of type xdt:untypedAtomic, it is cast to the default type for the given operator.
    //    If the cast fails, a type error is raised.

    *i = new (mm) XQPromoteUntyped(*i, SchemaSymbols::fgURI_SCHEMAFORSCHEMA,
                                   SchemaSymbols::fgDT_DOUBLE, mm);
    (*i)->setLocationInfo(this);

    *i = (*i)->staticResolution(context);
  }

  return this;
}
Beispiel #9
0
ASTNode *FunctionRefImpl::createInstance(const XMLCh *uri, const XMLCh *name, unsigned int numArgs,
                                         StaticContext *context, const LocationInfo *location,
                                         FunctionSignature *&signature)
{
  XPath2MemoryManager *mm = context->getMemoryManager();

  VectorOfASTNodes newArgs = VectorOfASTNodes(XQillaAllocator<ASTNode*>(mm));
  for(unsigned int i = 0; i < numArgs; ++i) {
    newArgs.push_back(0); // Dummy argument
  }

  ASTNode *result = context->lookUpFunction(uri, name, newArgs, location);
  if(!result) return 0;

  switch(result->getType()) {
  case ASTNode::FUNCTION:
  case ASTNode::USER_FUNCTION: {
    XQFunction *function = (XQFunction*)result;
    function->parseSignature(context);
    signature = new (mm) FunctionSignature(function->getSignature(), mm);

    if(signature->argSpecs) {
      // Fill in the arguments with XQVariable objects
      ArgumentSpecs::const_iterator argsIt = signature->argSpecs->begin();
      VectorOfASTNodes &args = const_cast<VectorOfASTNodes&>(function->getArguments());
      for(VectorOfASTNodes::iterator i = args.begin(); i != args.end(); ++i, ++argsIt) {
        (*i) = new (mm) XQVariable((*argsIt)->getURI(), (*argsIt)->getName(), mm);
        (*i)->setLocationInfo(location);
      }
    }

    break;
  }
  case ASTNode::CAST_AS: {
    XQCastAs *cast = (XQCastAs*)result;

    // Fill in the argument with an XQVariable object
    XQVariable *var = new (mm) XQVariable(0, constructorArgName, mm);
    var->setLocationInfo(location);
    cast->setExpression(var);

    // Create a signature for the constructor function
    SequenceType *argType = new (mm) SequenceType(SchemaSymbols::fgURI_SCHEMAFORSCHEMA,
                                                  AnyAtomicType::fgDT_ANYATOMICTYPE,
                                                  SequenceType::QUESTION_MARK, mm);
    argType->setLocationInfo(location);

    ArgumentSpec *arg = new (mm) ArgumentSpec(constructorArgName, argType, mm);
    arg->setLocationInfo(location);

    ArgumentSpecs *args = new (mm) ArgumentSpecs(XQillaAllocator<ArgumentSpec*>(mm));
    args->push_back(arg);

    signature = new (mm) FunctionSignature(args, cast->getSequenceType(), mm);
    signature->staticResolution(context);
    break;
  }
  default:
    assert(false);
    break;
  }

  return result;
}