예제 #1
0
void ArithmeticOperator::calculateStaticTypeForNumerics(const StaticType &arg0, const StaticType &arg1)
{
  // Deal with numerics and numeric type promotion
  if(arg0.containsType(StaticType::DECIMAL_TYPE)) {
    if(arg1.containsType(StaticType::DECIMAL_TYPE)) {
      _src.getStaticType() |= StaticType::DECIMAL_TYPE;
    }
    if(arg1.containsType(StaticType::FLOAT_TYPE)) {
      _src.getStaticType() |= StaticType::FLOAT_TYPE;
    }
    // untypedAtomic will be promoted to xs:double
    if(arg1.containsType(StaticType::DOUBLE_TYPE|StaticType::UNTYPED_ATOMIC_TYPE)) {
      _src.getStaticType() |= StaticType::DOUBLE_TYPE;
    }
  }
  if(arg0.containsType(StaticType::FLOAT_TYPE)) {
    if(arg1.containsType(StaticType::DECIMAL_TYPE|StaticType::FLOAT_TYPE)) {
      _src.getStaticType() |= StaticType::FLOAT_TYPE;
    }
    // untypedAtomic will be promoted to xs:double
    if(arg1.containsType(StaticType::DOUBLE_TYPE|StaticType::UNTYPED_ATOMIC_TYPE)) {
      _src.getStaticType() |= StaticType::DOUBLE_TYPE;
    }
  }
  // untypedAtomic will be promoted to xs:double
  if(arg0.containsType(StaticType::DOUBLE_TYPE|StaticType::UNTYPED_ATOMIC_TYPE)) {
    if(arg1.containsType(StaticType::DECIMAL_TYPE|StaticType::FLOAT_TYPE|StaticType::DOUBLE_TYPE|StaticType::UNTYPED_ATOMIC_TYPE)) {
      _src.getStaticType() |= StaticType::DOUBLE_TYPE;
    }
  }
}
예제 #2
0
void SequenceType::getStaticType(StaticType &st, const StaticContext *context,
                                 bool &isExact, const LocationInfo *location) const
{
  if(m_pItemType == 0) {
    st = StaticType();
    isExact = true;
  }
  else {
    m_pItemType->getStaticType(st, context, isExact, location);

    switch(m_nOccurrence) {
    case EXACTLY_ONE: break;
    case STAR: st.multiply(0, StaticType::UNLIMITED); break;
    case PLUS: st.multiply(1, StaticType::UNLIMITED); break;
    case QUESTION_MARK: st.multiply(0, 1); break;
    }
  }
}
예제 #3
0
static StaticType generalCompTypeConversion(const StaticType &arg0_type, const StaticType &arg1_type)
{
	StaticType result = arg0_type;

	StaticType target = arg1_type;
	if(target.getMax() != 0)
		target.setCardinality(1, 1);
	target.substitute(StaticType::NUMERIC_TYPE, StaticType::DOUBLE_TYPE);
	target.substitute(StaticType::UNTYPED_ATOMIC_TYPE, StaticType::STRING_TYPE);

	result.substitute(StaticType::UNTYPED_ATOMIC_TYPE, target);
	return result;
}
예제 #4
0
static XmlValue::Type staticTypeToValueType(const StaticType &sType)
{
	if(sType.isType(StaticType::NODE_TYPE)) return XmlValue::NODE;
	if(sType.isType(StaticType::ANY_SIMPLE_TYPE)) return XmlValue::ANY_SIMPLE_TYPE;
	if(sType.isType(StaticType::ANY_URI_TYPE)) return XmlValue::ANY_URI;
	if(sType.isType(StaticType::BASE_64_BINARY_TYPE)) return XmlValue::BASE_64_BINARY;
	if(sType.isType(StaticType::BOOLEAN_TYPE)) return XmlValue::BOOLEAN;
	if(sType.isType(StaticType::DATE_TYPE)) return XmlValue::DATE;
	if(sType.isType(StaticType::DATE_TIME_TYPE)) return XmlValue::DATE_TIME;
	if(sType.isType(StaticType::DAY_TIME_DURATION_TYPE)) return XmlValue::DAY_TIME_DURATION;
	if(sType.isType(StaticType::DECIMAL_TYPE)) return XmlValue::DECIMAL;
	if(sType.isType(StaticType::DOUBLE_TYPE)) return XmlValue::DOUBLE;
	if(sType.isType(StaticType::DURATION_TYPE)) return XmlValue::DURATION;
	if(sType.isType(StaticType::FLOAT_TYPE)) return XmlValue::FLOAT;
	if(sType.isType(StaticType::G_DAY_TYPE)) return XmlValue::G_DAY;
	if(sType.isType(StaticType::G_MONTH_TYPE)) return XmlValue::G_MONTH;
	if(sType.isType(StaticType::G_MONTH_DAY_TYPE)) return XmlValue::G_MONTH_DAY;
	if(sType.isType(StaticType::G_YEAR_TYPE)) return XmlValue::G_YEAR;
	if(sType.isType(StaticType::G_YEAR_MONTH_TYPE)) return XmlValue::G_YEAR_MONTH;
	if(sType.isType(StaticType::HEX_BINARY_TYPE)) return XmlValue::HEX_BINARY;
	if(sType.isType(StaticType::NOTATION_TYPE)) return XmlValue::NOTATION;
	if(sType.isType(StaticType::QNAME_TYPE)) return XmlValue::QNAME;
	if(sType.isType(StaticType::STRING_TYPE)) return XmlValue::STRING;
	if(sType.isType(StaticType::TIME_TYPE)) return XmlValue::TIME;
	if(sType.isType(StaticType::UNTYPED_ATOMIC_TYPE)) return XmlValue::UNTYPED_ATOMIC;
	if(sType.isType(StaticType::YEAR_MONTH_DURATION_TYPE)) return XmlValue::YEAR_MONTH_DURATION;
	return XmlValue::NONE;
}
예제 #5
0
static StaticType valueCompTypeConversion(const StaticType &arg0_type)
{
	StaticType result = arg0_type;
	result.substitute(StaticType::UNTYPED_ATOMIC_TYPE, StaticType::STRING_TYPE);
	return result;
}
예제 #6
0
void XQUserFunction::staticTyping(StaticContext *context, StaticTyper *styper)
{
  // Nothing more to do for external functions
  if(body_ == NULL) return;

  if(signature_->updating == FunctionSignature::OP_TRUE && signature_->returnType != NULL) {
    XQThrow(StaticErrorException, X("XQUserFunction::staticTyping"),
            X("It is a static error for an updating function to declare a return type [err:XUST0028]"));
  }

  // Find user defined functions and templates that are referenced in our body,
  // and try to call staticTyping() on them before us.
  if(context) staticTypeFunctionCalls(body_, context, styper);

  bool ciTypeSet = false;
  StaticType ciType = StaticType();
  if(pattern_ != NULL) {
    VectorOfASTNodes::iterator patIt = pattern_->begin();
    for(; patIt != pattern_->end(); ++patIt) {
      (*patIt) = (*patIt)->staticTyping(context, styper);
      if(!ciTypeSet) {
        ciTypeSet = true;
        ciType = (*patIt)->getStaticAnalysis().getStaticType();
      }
      else ciType |= (*patIt)->getStaticAnalysis().getStaticType();
    }
    if(ciTypeSet) {
      ciType.setCardinality(1, 1);
    }
  }
  if(isTemplate_ && name_ != 0) {
    // Named template
    ciTypeSet = true;
    ciType = StaticType::ITEM_TYPE;
  }

  // define the new variables in a new scope and assign them the proper values
  if(context) {
    VariableTypeStore *varStore = context->getVariableTypeStore();

    if(isGlobal_) varStore->addLocalScope();
    else varStore->addLogicalBlockScope();

    // Declare the parameters
    if(signature_->argSpecs) {
      ArgumentSpecs::iterator it;
      for(it = signature_->argSpecs->begin(); it != signature_->argSpecs->end (); ++it) {
        varStore->declareVar((*it)->getURI(), (*it)->getName(), (*it)->getStaticAnalysis());
      }
    }
  }

  {
    // Declare the context item
    AutoContextItemTypeReset contextTypeReset(context, ciType);
    body_ = body_->staticTyping(context, styper);
  }

  if(context)
    context->getVariableTypeStore()->removeScope();

  if(signature_->updating == FunctionSignature::OP_TRUE) {
    if(!body_->getStaticAnalysis().isUpdating() && !body_->getStaticAnalysis().isPossiblyUpdating())
      XQThrow(StaticErrorException, X("XQUserFunction::staticTyping"),
              X("It is a static error for the body expression of a user defined updating function "
                "not to be an updating expression [err:XUST0002]"));
  }
  else {
    if(body_->getStaticAnalysis().isUpdating()) {
      if(isTemplate_) {
        XQThrow(StaticErrorException, X("XQUserFunction::staticTyping"),
                X("It is a static error for the body expression of a template "
                  "to be an updating expression [err:XUST0001]"));
      } else {
        XQThrow(StaticErrorException, X("XQUserFunction::staticTyping"),
                X("It is a static error for the body expression of a user defined function "
                  "to be an updating expression [err:XUST0001]"));
      }
    }
  }

  // Remove the parameter variables from the stored StaticAnalysis
  src_.clear();
  src_.copy(body_->getStaticAnalysis());
  if(signature_->argSpecs) {
    for(ArgumentSpecs::iterator it = signature_->argSpecs->begin(); it != signature_->argSpecs->end (); ++it) {
      if(!src_.removeVariable((*it)->getURI(), (*it)->getName())) {
        // The parameter isn't used, so set it to null, so that we don't bother to evaluate it
        (*it)->setNotUsed();
      }
    }
  }

  // Run staticTyping on the template instances
  if(templateInstance_ != 0 && context) {
    StaticAnalysis templateVarSrc(context->getMemoryManager());
    templateVarSrc.getStaticType() = StaticType::ITEM_TYPE;

    VariableTypeStore *varStore = context->getVariableTypeStore();
    varStore->addLogicalBlockScope();

    if(signature_->argSpecs != 0) {
      ArgumentSpecs::const_iterator argIt;
      for(argIt = signature_->argSpecs->begin(); argIt != signature_->argSpecs->end(); ++argIt) {
        varStore->declareVar((*argIt)->getURI(), (*argIt)->getName(), templateVarSrc);
      }
    }

    // Turn off warnings here, since they are largely irrelevent to the user
    AutoMessageListenerReset reset(context);

    templateInstance_ = templateInstance_->staticTyping(context, styper);

    varStore->removeScope();
  }
}