Exemple #1
0
void XQGlobalVariable::staticTyping(StaticContext* context, StaticTyper *styper)
{
  VariableTypeStore* varStore = context->getVariableTypeStore();

  if(m_Value != NULL) {
    XQUserFunction::staticTypeFunctionCalls(m_Value, context, styper);

    m_Value = m_Value->staticTyping(context, styper);
    _src.copy(m_Value->getStaticAnalysis());

    if(m_Value->getStaticAnalysis().isUpdating()) {
      XQThrow(StaticErrorException,X("XQGlobalVariable::staticTyping"),
              X("It is a static error for the initializing expression of a global variable "
                "to be an updating expression [err:XUST0001]"));
    }
  }

  if(m_Value == 0 || !required_) {
    if(m_Type != 0) {
      bool isPrimitive;
      m_Type->getStaticType(_src.getStaticType(), context, isPrimitive, m_Type);
    }
    else {
      _src.getStaticType() = StaticType(StaticType::ITEM_TYPE, 0, StaticType::UNLIMITED);
    }
  }

  varStore->declareGlobalVar(m_szURI, m_szLocalName, _src);
}
Exemple #2
0
void XQQuery::staticTyping(StaticTyper *styper)
{
  StaticContext *context = m_context;

  StaticTyper defaultTyper;
  if(styper == 0) styper = &defaultTyper;

  VariableTypeStore* varStore = context->getVariableTypeStore();

  // Static type the imported modules (again)
  ImportedModules::const_iterator modIt;
  for(modIt = m_importedModules.begin(); modIt != m_importedModules.end(); ++modIt) {
    (*modIt)->staticTyping(styper);
  }  

  // Define types for the imported variables
  for(modIt = m_importedModules.begin(); modIt != m_importedModules.end(); ++modIt) {
    for(GlobalVariables::const_iterator varIt = (*modIt)->m_userDefVars.begin();
        varIt != (*modIt)->m_userDefVars.end(); ++varIt) {
      varStore->declareGlobalVar((*varIt)->getVariableURI(), (*varIt)->getVariableLocalName(),
                                 (*varIt)->getStaticAnalysis());
    }
  }

  // Run staticTyping on the global variables
  if(!m_userDefVars.empty()) {
    // declare all the global variables with a special StaticAnalysis, in order to recognize 'variable is defined
    // later' errors instead of more generic 'variable not found'. In order to catch references to not yet defined
    // variables (but when no recursion happens) we also create a scope where we undefine the rest of the variables (once
    // we enter in a function call, the scope will disappear and the forward references to the global variables will
    // appear).
    StaticAnalysis forwardRef(context->getMemoryManager());
    forwardRef.setProperties(StaticAnalysis::FORWARDREF);

    StaticAnalysis undefinedVar(context->getMemoryManager());
    undefinedVar.setProperties(StaticAnalysis::UNDEFINEDVAR);

    GlobalVariables::iterator itVar, itVar2;
    for(itVar = m_userDefVars.begin(); itVar != m_userDefVars.end(); ++itVar) {
      varStore->declareGlobalVar((*itVar)->getVariableURI(), (*itVar)->getVariableLocalName(),
                                 forwardRef);
    }

    for(itVar = m_userDefVars.begin(); itVar != m_userDefVars.end(); ++itVar) {
      varStore->addLogicalBlockScope();
      for(itVar2 = itVar; itVar2 != m_userDefVars.end(); ++itVar2) {
        varStore->declareVar((*itVar2)->getVariableURI(), (*itVar2)->getVariableLocalName(),
                             undefinedVar);
      }
      (*itVar)->staticTyping(context, styper);
      varStore->removeScope();
    }
  }

  // Run staticTyping on the user defined functions,
  // which calculates a better type for them
  UserFunctions::iterator i, j;
  for(i = m_userDefFns.begin(); i != m_userDefFns.end(); ++i) {
    for(j = m_userDefFns.begin(); j != m_userDefFns.end(); ++j) {
      (*j)->resetStaticTypingOnce();
    }

    (*i)->staticTypingOnce(context, styper);
  }

  // Run staticTyping on the query body
  if(m_query) m_query = m_query->staticTyping(context, styper);
}
Exemple #3
0
void XQQuery::staticTyping(StaticTyper *styper)
{
  StaticTyper defaultTyper;
  if(styper == 0) styper = &defaultTyper;

  // Static type the imported modules (again)
  ImportedModules::const_iterator modIt;
  if(m_moduleCacheOwned) {
    for(modIt = m_moduleCache->ordered_.begin(); modIt != m_moduleCache->ordered_.end(); ++modIt) {
      (*modIt)->staticTyping(styper);
    }
  }

  // Define types for the imported variables
  VariableTypeStore* varStore = m_context->getVariableTypeStore();
  GlobalVariables::const_iterator varIt;
  for(modIt = m_importedModules.begin(); modIt != m_importedModules.end(); ++modIt) {
    XQQuery *module = *modIt;
    for(; module; module = module->getNext()) {
      for(varIt = module->m_userDefVars.begin(); varIt != module->m_userDefVars.end(); ++varIt) {
        varStore->declareGlobalVar((*varIt)->getVariableURI(), (*varIt)->getVariableLocalName(),
                                   (*varIt)->getStaticAnalysis(), *varIt);
      }
    }
  }

  // Set up a default type for the global variables
  for(varIt = m_userDefVars.begin(); varIt != m_userDefVars.end(); ++varIt) {
    (*varIt)->resetStaticTypingOnce();
    varStore->declareGlobalVar((*varIt)->getVariableURI(), (*varIt)->getVariableLocalName(),
                               (*varIt)->getStaticAnalysis(), *varIt);
  }

  UserFunctions::const_iterator i, j;
  {
    GlobalVariables globalsOrder(XQillaAllocator<XQGlobalVariable*>(m_context->getMemoryManager()));
    AutoReset<GlobalVariables*> autoReset(styper->getGlobalsOrder());
    styper->getGlobalsOrder() = &globalsOrder;

    // Run staticTyping on the global variables
    for(varIt = m_userDefVars.begin(); varIt != m_userDefVars.end(); ++varIt) {
      for(j = m_userDefFns.begin(); j != m_userDefFns.end(); ++j) {
        (*j)->resetStaticTypingOnce();
      }

      (*varIt)->staticTypingOnce(m_context, styper);
    }

    // XQuery 1.1 reorders the global variables to enable forward references
    if(m_version3)
      m_userDefVars = globalsOrder;
  }

  // Run staticTyping on the user defined functions,
  // which calculates a better type for them
  for(i = m_userDefFns.begin(); i != m_userDefFns.end(); ++i) {
    for(j = m_userDefFns.begin(); j != m_userDefFns.end(); ++j) {
      (*j)->resetStaticTypingOnce();
    }

    (*i)->staticTypingOnce(m_context, styper);
  }

  // Run staticTyping on the query body
  if(m_query) m_query = m_query->staticTyping(m_context, styper);
}