Esempio n. 1
0
DynamicArray::DynamicArray(TypeSystem& typesys, DataType& elemType)
    : BaseType(make_name(typesys, elemType), typesys.word_size() * 2)
    , elemType_(&elemType)
    , wordSize_(typesys.word_size())
{
    typesys.manage(this);
}
Esempio n. 2
0
void registerFunction(const string& name, RetT(*f)(ArgT0, ArgT1))
{
    TypeSystem* ts = TypeSystem::instance();
    IType *retT = CType2ScriptType<RetT>::get(ts);
    vector<IType*> argT = {CType2ScriptType<ArgT0>::get(ts), CType2ScriptType<ArgT1>::get(ts)};
    IType *ftype = ts->getFunc(retT, argT);
    SymbolTableManager::instance()->global()->addSymbol(name, ftype);
    CodeManager::instance()->registerFunction(name, FunctionPtr(new CFunction2<RetT, ArgT0, ArgT1>(f)));
}
Esempio n. 3
0
void registerVarLengFunction(const string& name, CVarlengFunction::FuncT f)
{
    TypeSystem* ts = TypeSystem::instance();
    IType *retT = CType2ScriptType<int>::get(ts);
    vector<IType*> argT = {CType2ScriptType<const char*>::get(ts)};
    IType *ftype = ts->getFunc(retT, argT);
    dynamic_cast<FunctionType*>(ftype)->isVarLengOfArg = true;
    SymbolTableManager::instance()->global()->addSymbol(name, ftype);
    CodeManager::instance()->registerFunction(name, FunctionPtr(new CVarlengFunction(f)));
}
Esempio n. 4
0
  TyErrorId typeSystemInit(TypeSystem const & crTypeSystem) {
    cout << "SofaExampleAnnotator::typeSystemInit()" << endl;

    // get Type and Feature objects for use in process()
    annot  = crTypeSystem.getType("uima.tcas.Annotation");
    cross  = crTypeSystem.getType("sofa.test.CrossAnnotation");
    other = cross.getFeatureByBaseName("otherAnnotation");
    if (!(annot.isValid() && cross.isValid() && other.isValid())) {
      cout << "SofaExampleAnnotator::typeSystemInit() - Error getting Type or Feature objects" << endl;
      return (TyErrorId)UIMA_ERR_RESMGR_INVALID_RESOURCE;
    }
    return(TyErrorId)UIMA_ERR_NONE;
  }
Esempio n. 5
0
// === EDIT ===
// Edit type
void MainWindow::editType(){
    QVector<int> ids = utilities::getSelectedTableViewIds(ui->typesTable);

    // No rows or more than 1
    if (ids.size() != 1) {
        return;
    }

    // An empty person
    TypeSystem ts;
    // Set person ID to the ID of the row
    ts.setId(ids[0]);

    // Get the person info by ID
    if(!servicesLayer.getTypeSystem(ts, 1, error)){
        checkError();
        return;
    }

    // Edit dialog
    EditTypeSystemDialog editDialog;
    // Forward person to edit dialog
    editDialog.setName(ts.getName());
    // Set the fields
    editDialog.setFields();
    // Set title
    editDialog.setTitle("Edit Type");

    // If saved
    if (editDialog.exec()) {

        ts.setName(editDialog.getName());

        // If error, show error, else update table
        if (!servicesLayer.editTypeSystem(ts, 1, error)) {
            checkError();
            return;
        }
        else{
            checkTypeSearch();
            displayMachinesTable();
            displayConnectionsTable();
        }

        // Set status bar message
        ui->statusBar->showMessage(ts.getName() + " edited", constants::STATUSBAR_MESSAGE_TIME);

        // Disable Person edit and delete buttons
        disableEditDeleteTypeButtons();
    }
}
Esempio n. 6
0
/**
 * Derive the name of the array type from the elements' type
 */
static RefPtr<SharedString>
make_name(TypeSystem& typesys, DataType& elemType)
{
    ostringstream buf;

    buf << elemType.name()->c_str() << "[]";
    return typesys.get_string(buf.str().c_str(), buf.str().length());
}
Esempio n. 7
0
RetT callFromC(IFunction *func, RuntimeEnv* env)
{
    TypeSystem* ts = TypeSystem::instance();
    IType *retT = CType2ScriptType<RetT>::get(ts);
    vector<IType*> argT = {};
    IType *ftype = ts->getFunc(retT, argT);

    int retSize = retT->getSize();
    int retArgSize = retSize;
    env->pushValue(RetT());

    env->pushFrame(retArgSize);
    func->call(env);
    env->popFrame(retSize);

    RetT r;
    env->popValue(r);
    return r;
}
Esempio n. 8
0
bool RemoveInterfacePass::is_leaf(const TypeSystem& type_system,
                                  const DexType* intf) {
  auto intf_children = type_system.get_interface_children(intf);
  size_t num_removed = 0;
  for (const auto child : intf_children) {
    if (m_removed_interfaces.count(child) > 0) {
      ++num_removed;
    }
  }
  return num_removed == intf_children.size();
}
		/*!
		* Initializes the typesystem types and features
		*/
		TyErrorId AnnotatorPerformanceAnnotation::initializeTypeSystem(TypeSystem const& crTypeSystem)
		{
			tAnnotatorPerformanceAnnotation = crTypeSystem.getType("org.gramlab.kwaga.unitex_uima.general.tcas.AnnotatorPerformanceAnnotation");
			if (!tAnnotatorPerformanceAnnotation.isValid())
				return (TyErrorId) UIMA_ERR_RESMGR_INVALID_RESOURCE;

			fComponentName = tAnnotatorPerformanceAnnotation.getFeatureByBaseName("componentName");
			fElapsedTime = tAnnotatorPerformanceAnnotation.getFeatureByBaseName("elapsedTime");

			return (TyErrorId) UIMA_ERR_NONE;
		}
		/*!
		 * Initializes the typesystem types and features
		 */
		TyErrorId SentenceAnnotation::initializeTypeSystem(TypeSystem const& crTypeSystem)
		{
			if (ContextAreaAnnotation::initializeTypeSystem(crTypeSystem) != UIMA_ERR_NONE)
				return (TyErrorId) UIMA_ERR_RESMGR_INVALID_RESOURCE;

			tSentenceAnnotation = crTypeSystem.getType("org.gramlab.kwaga.unitex_uima.unitex.tcas.SentenceAnnotation");
			if (!tSentenceAnnotation.isValid())
				return (TyErrorId) UIMA_ERR_RESMGR_INVALID_RESOURCE;

			fParagraph = tSentenceAnnotation.getFeatureByBaseName("paragraph");

			return (TyErrorId) UIMA_ERR_NONE;
		}
Esempio n. 11
0
TypeSet RemoveInterfacePass::remove_leaf_interfaces(
    const Scope& scope,
    const DexType* root,
    const TypeSet& interfaces,
    const TypeSystem& type_system) {
  TypeSet leaf_interfaces;
  for (const auto intf : interfaces) {
    if (is_leaf(type_system, intf)) {
      leaf_interfaces.insert(intf);
    }
  }

  std::unordered_map<DexMethod*, DexMethod*> intf_meth_to_dispatch;
  for (const auto intf : leaf_interfaces) {
    TRACE(RM_INTF, 5, "Found leaf interface %s\n", SHOW(intf));
    auto implementors = type_system.get_implementors(intf);
    auto intf_methods = type_class(intf)->get_vmethods();
    for (const auto meth : intf_methods) {
      TRACE(RM_INTF, 5, "Finding virt scope for %s\n", SHOW(meth));
      auto intf_scope = type_system.find_interface_scope(meth);
      MethodOrderedSet found_targets =
          find_dispatch_targets(type_system, intf_scope, implementors);
      std::vector<DexMethod*> dispatch_targets(found_targets.begin(),
                                               found_targets.end());
      auto replacement_type = get_replacement_type(type_system, intf, root);
      auto dispatch =
          generate_dispatch(replacement_type, dispatch_targets, meth,
                            m_keep_debug_info, m_interface_dispatch_anno);
      m_dispatch_stats[dispatch_targets.size()]++;
      intf_meth_to_dispatch[meth] = dispatch;
    }
  }
  update_interface_calls(scope, intf_meth_to_dispatch);
  remove_inheritance(scope, type_system, leaf_interfaces);
  m_num_interface_removed += leaf_interfaces.size();
  return leaf_interfaces;
}
Esempio n. 12
0
void RemoveInterfacePass::remove_inheritance(const Scope& scope,
                                             const TypeSystem& type_system,
                                             const TypeSet& interfaces) {
  for (const auto intf : interfaces) {
    always_assert(is_leaf(type_system, intf));
    auto impls = type_system.get_implementors(intf);
    for (const auto impl : impls) {
      TRACE(RM_INTF, 5, "Remove inheritance for %s on %s\n", SHOW(intf),
            SHOW(impl));
      auto new_impl_list = get_new_impl_list(impl, intf);
      type_class(impl)->set_interfaces(new_impl_list);
    }
    type_class(intf)->set_interfaces(DexTypeList::make_type_list({}));
  }
}
Esempio n. 13
0
void RemoveInterfacePass::remove_interfaces_for_root(
    const Scope& scope,
    const DexStoresVector& stores,
    const DexType* root,
    const TypeSystem& type_system) {
  TRACE(RM_INTF, 5, "Processing root %s\n", SHOW(root));
  TypeSet interfaces;
  type_system.get_all_interface_children(root, interfaces);
  include_parent_interfaces(root, interfaces);

  m_total_num_interface += interfaces.size();
  m_num_interface_excluded += exclude_unremovables(
      scope, stores, type_system, m_skip_multiple_targets_roots,
      m_include_primary_dex, interfaces);

  TRACE(RM_INTF, 5, "removable interfaces %ld\n", interfaces.size());
  TypeSet removed =
      remove_leaf_interfaces(scope, root, interfaces, type_system);

  while (removed.size() > 0) {
    for (const auto intf : removed) {
      interfaces.erase(intf);
      m_removed_interfaces.insert(intf);
    }
    TRACE(RM_INTF, 5, "non-leaf removable interfaces %ld\n", interfaces.size());
    removed = remove_leaf_interfaces(scope, root, interfaces, type_system);
  }

  // Update type reference to removed interfaces all at once.
  remove_interface_references(scope, type_system, root, m_removed_interfaces);

  if (traceEnabled(RM_INTF, 9)) {
    TypeSystem updated_ts(scope);
    for (const auto intf : interfaces) {
      TRACE(RM_INTF, 9, "unremoved interface %s\n", SHOW(intf));
      TypeSet children;
      updated_ts.get_all_interface_children(intf, children);
      for (const auto cintf : children) {
        TRACE(RM_INTF, 9, "  child %s\n", SHOW(cintf));
      }
    }
  }
}
Esempio n. 14
0
// ==== DELETE ====
// Delete type
void MainWindow::deleteType(){
    QVector<int> ids = utilities::getSelectedTableViewIds(ui->typesTable);

    // No rows
    if (ids.isEmpty()) {
        return;
    }

    int numRows = ids.size();
    QString deleteConfirmMessage = "";
    QString statusBarMessage = "";

    // Get all the machines that are about to be deleted
    QVector<TypeSystem> typesToBeDeleted;
    for(int i = 0; i < numRows;i++){
        // An empty machine
        TypeSystem ts;
        // Set machine ID to the ID of the row
        ts.setId(ids[i]);

        // Get the machine info by ID
        if(!servicesLayer.getTypeSystem(ts, 1, error)){
            checkError();
            return;
        }

        // Add to vector
        typesToBeDeleted.push_back(ts);
    }

    // Single row
    if(numRows == 1){
        deleteConfirmMessage = "Are you sure you want to delete " + typesToBeDeleted[0].getName() + "?";
        statusBarMessage = typesToBeDeleted[0].getName() + " deleted";
    }
    // Rows less than 11
    else if(numRows > 1 && numRows < 11){

        deleteConfirmMessage = "Are you sure you want to delete:\n";

        // Loop over names
        for(int i = 0; i < numRows;i++){
            deleteConfirmMessage += typesToBeDeleted[i].getName() + "\n";
        }

        statusBarMessage = QString::number(numRows) + " entries deleted";
    }
    // More than 10
    else{
        deleteConfirmMessage = "Are you sure you want to delete these " + QString::number(numRows) + " entries?";
        statusBarMessage = QString::number(numRows) + " entries deleted";
    }

    // Confirmation window
    int ans = QMessageBox::question(this, "Confirmation", deleteConfirmMessage, QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
    // Check answer
    if (ans == QMessageBox::Yes) {
        // Delete
        if(!servicesLayer.deleteTypeSystem(typesToBeDeleted, 1, error)){
            checkError();
            return;
        }

        // Disable Person edit and delete buttons
        disableEditDeleteTypeButtons();

        // Status bar update
        ui->statusBar->showMessage(statusBarMessage, constants::STATUSBAR_MESSAGE_TIME);

        // Re-display
        checkTypeSearch();
        displayMachinesTable();
        displayConnectionsTable();
    }
}
Esempio n. 15
0
 TyErrorId typeSystemInit(TypeSystem const & crTypeSystem) {
   cout << "SofaDataAnnotator: typeSystemInit()" << endl;
   annot  = crTypeSystem.getType("uima.tcas.Annotation");
   return(TyErrorId)UIMA_ERR_NONE;
 }
 /*static*/
 void
 CapabilityContainer::initTypeOrFeatures(
   TyMapLang2TypeOrFeatures & rMap, // output argument
   Capability::TyVecCapabilityTofs const & vecTofs,
   Capability::TyVecCapabilityLanguages const & vecLangs,
   TypeSystem const & typeSystem) {
   const int BUF_SIZE = 0x100;
   char  cBuf[BUF_SIZE];
   Capability::TyVecCapabilityLanguages::const_iterator itLang;
   for (itLang = vecLangs.begin(); itLang != vecLangs.end(); ++itLang) {
     // convert unicode lang string to single-byte lang string
     assert((*itLang).length() < BUF_SIZE);
     // Note: this conversion can be used only for invariant characters
     u_UCharsToChars((*itLang).getBuffer(), cBuf, (*itLang).length());
     // zero terminate single-byte buffer
     cBuf[(*itLang).length()] = '\0';
     // Special workaround code for the new way to specify the unspecified language
     if (strcasecmp(cBuf, "x-unspecified") == 0) {
       strcpy(cBuf, Language::UNSPECIFIED);
     }
     // create a language object based on single-byte lang string
     Language lang(cBuf);
     if (!lang.isValid()) {
       /* taph 06.02.2003: once we have more detailed information about
       the origin of the error we need to replace "unknown configuration file"
       with the filename of the XML file (and maybe line number?) */
       UIMA_EXC_THROW_NEW(uima::CapabilityException,          // exc-type
                          UIMA_ERR_ENGINE_LANGUAGE_INVALID,   // error code
                          ErrorMessage(UIMA_MSG_ID_EXC_INVALID_LANGUAGE, cBuf), // error message
                          ErrorMessage(UIMA_MSG_ID_EXCON_CHECKING_CAPABILITY_SPEC,"unknown configuration file"),  // error context message
                          ErrorInfo::recoverable);
     }
     // create a new empty vector in the map for this lang
     TySetTypeOrFeatures & setTofs = rMap[lang];
     // now fill the vector with tof objects created from tof strings
     Capability::TyVecCapabilityTofs::const_iterator itTof;
     for (itTof = vecTofs.begin(); itTof != vecTofs.end(); ++itTof) {
       TypeOrFeature tof;
       // the tof string may be a type...
       Type t = typeSystem.getType(*itTof);
       if (t.isValid()) {
         tof = TypeOrFeature(t);
       } else {
         // or the tof string may be a feature
         Feature f = typeSystem.getFeatureByFullName(*itTof);
         if (f.isValid()) {
           tof = TypeOrFeature(f);
         } else {
           /* taph 06.02.2003: once we have more detailed information about
           the origin of the error we need to replace "unknown configuration file"
           with the filename of the XML file (and maybe line number?) */
           if (tof.isType()) {
             UIMA_EXC_THROW_NEW(uima::CapabilityException,        // exc-type
                                UIMA_ERR_INVALID_FSTYPE_OBJECT,   // error code
                                ErrorMessage(UIMA_MSG_ID_EXC_UNKNOWN_TYPE_NAME, *itTof), // error message
                                ErrorMessage(UIMA_MSG_ID_EXCON_CHECKING_CAPABILITY_SPEC, "unknown configuration file"),  // error context message
                                ErrorInfo::recoverable);
           } else {
             UIMA_EXC_THROW_NEW(uima::CapabilityException,        // exc-type
                                UIMA_ERR_INVALID_FSFEATURE_OBJECT,// error code
                                ErrorMessage(UIMA_MSG_ID_EXC_UNKNOWN_FEATURE_NAME, *itTof), // error message
                                ErrorMessage(UIMA_MSG_ID_EXCON_CHECKING_CAPABILITY_SPEC, "unknown configuration file"),  // error context message
                                ErrorInfo::recoverable);
           }
         }
       }
       assert(tof.isValid());
       setTofs.insert(tof);
     } // for all tof strings
   } // for all lang strings
 }