Beispiel #1
0
TypePtr FunctionScope::setParamType(AnalysisResultPtr ar, int index,
                                    TypePtr type) {
  ASSERT(index >= 0 && index < (int)m_paramTypes.size());
  TypePtr paramType = m_paramTypes[index];

  if (!paramType) paramType = NEW_TYPE(Some);
  type = Type::Coerce(ar, paramType, type);
  if (type && !Type::SameType(paramType, type)) {
    ar->incNewlyInferred();
    if (!ar->isFirstPass()) {
      Logger::Verbose("Corrected type of parameter %d of %s: %s -> %s",
                      index, m_name.c_str(),
                      paramType->toString().c_str(), type->toString().c_str());
    }
  }
  m_paramTypes[index] = type;
  return type;
}
Beispiel #2
0
TypePtr SymbolTable::setType(AnalysisResultPtr ar, const std::string &name,
                             TypePtr type, bool coerced) {
  TypePtr oldType = getType(name, true);
  if (!oldType) oldType = NEW_TYPE(Some);

  if (m_declarations.find(name) == m_declarations.end()) {
    m_symbols.push_back(name);
    m_declarations[name] = ConstructPtr();
  }
  if (type) {
    TypePtr ret = coerceTo(ar, coerced? m_coerced : m_rtypes, name, type);
    TypePtr newType = getType(name, true);
    if (!newType) newType = NEW_TYPE(Some);
    if (!Type::SameType(oldType, newType)) {
      ar->incNewlyInferred();
    }
    return newType;
  }
  return type;
}
Beispiel #3
0
void FunctionScope::setReturnType(AnalysisResultPtr ar, TypePtr type) {
  // no change can be made to virtual function's prototype
  if (m_overriding) return;

  if (m_returnType) {
    type = Type::Coerce(ar, m_returnType, type);
    if (type && !Type::SameType(m_returnType, type)) {
      ar->incNewlyInferred();
      if (!ar->isFirstPass()) {
        Logger::Verbose("Corrected function return type %s -> %s",
                        m_returnType->toString().c_str(),
                        type->toString().c_str());
      }
    }
  }
  if (!type->getName().empty()) {
    FileScopePtr fs = getFileScope();
    if (fs) fs->addClassDependency(ar, type->getName());
  }
  m_returnType = type;
}