Пример #1
0
string make_entity_name(void *stack_ptr, const string &type, char prefix) {
    string name = Introspection::get_variable_name(stack_ptr, type);

    if (name.empty()) {
        return unique_name(prefix);
    } else {
        // Halide names may not contain '.'
        for (size_t i = 0; i < name.size(); i++) {
            if (name[i] == '.') {
                name[i] = ':';
            }
        }
        return unique_name(name);
    }
}
Пример #2
0
void Function::define(const vector<string> &args, Expr value) {
    assert(value.defined() && "Undefined expression in right-hand-side of function definition\n");

    // Make sure all the vars in the value are either args or are
    // attached to some parameter
    CheckVars check;
    check.pure_args = args;
    value.accept(&check);

    assert(!check.reduction_domain.defined() && "Reduction domain referenced in pure function definition");

    if (!contents.defined()) {
        contents = new FunctionContents;
        contents.ptr->name = unique_name('f');
    }

    assert(!contents.ptr->value.defined() && "Function is already defined");
    contents.ptr->value = value;
    contents.ptr->args = args;
        
    for (size_t i = 0; i < args.size(); i++) {
        Schedule::Dim d = {args[i], For::Serial};
        contents.ptr->schedule.dims.push_back(d);
    }        
}
Пример #3
0
void Term__unique_name(VM* vm)
{
    Term* t = as_term_ref(vm->input(0));
    if (t == NULL)
        return vm->throw_str("NULL term");
    set_value(vm->output(), unique_name(t));
}
Пример #4
0
void
fork_to_background (void)
{
  pid_t pid;
  /* Whether we arrange our own version of opt.lfilename here.  */
  int changedp = 0;

  if (!opt.lfilename)
    {
      opt.lfilename = unique_name (DEFAULT_LOGFILE);
      changedp = 1;
    }
  pid = fork ();
  if (pid < 0)
    {
      /* parent, error */
      perror ("fork");
      exit (1);
    }
  else if (pid != 0)
    {
      /* parent, no error */
      printf (_("Continuing in background.\n"));
      if (changedp)
	printf (_("Output will be written to `%s'.\n"), opt.lfilename);
      exit (0);
    }
  /* child: keep running */
}
Пример #5
0
ACE_RW_Process_Mutex::ACE_RW_Process_Mutex (const ACE_TCHAR *name,
                                            int flags,
                                            mode_t mode )
  : lock_ (name ? name : unique_name (), flags, mode)
{
// ACE_TRACE ("ACE_RW_Process_Mutex::ACE_RW_Process_Mutex");
}
Пример #6
0
void branch_update_state_type(Branch* branch)
{
    if (branch_state_type_is_out_of_date(branch)) {

        // TODO: Handle the case where the stateType should go from non-NULL to NULL

        // Recreate the state type
        Type* type = create_compound_type();

        // TODO: give this new type a nice name

        for (int i=0; i < branch->length(); i++) {
            Term* term = branch->get(i);
            if (term == NULL)
                continue;

            if (term->function != FUNCS.unpack_state || FUNCS.unpack_state == NULL)
                continue;

            Term* identifyingTerm = term->input(1);

            compound_type_append_field(type, declared_type(term), unique_name(identifyingTerm));
        }

        branch->stateType = type;

        // Might need to update any existing pack_state calls.
        branch_update_existing_pack_state_calls(branch);
    }
}
Пример #7
0
void Macros::instance_process_locs(const string & name)
{
    // if not locdefs - error
    Macdef & m = *macdef_instance;
    auto i = m.locdefs.find(name);
    const Nodes & usage = m.iduse[name];

    if (usage.empty())
        throw Err(LNFUN);

    if (i == m.locdefs.end())
        throw Err("Undeclared '" + name + "' in macro definition", m.tok(), usage[0]->tok());

    string newname = name + "@" + unique_name();

    // change name in def
    Idn * idn = get<Idn>(LNFUN, i->second);
    idn->s = newname;

    for (auto j : usage)
    {
        Idn * idn = get<Idn>(LNFUN, j);
        idn->s = newname;
    }
}
Пример #8
0
void get_relative_name_as_list(Term* term, Block* relativeTo, Value* nameOutput)
{
    set_list(nameOutput, 0);

    // Walk upwards and build the name, stop when we reach relativeTo.
    // The output list will be reversed but we'll fix that.

    while (true) {
        set_value(list_append(nameOutput), unique_name(term));

        if (term->owningBlock == relativeTo) {
            break;
        }

        term = parent_term(term);

        // If term is null, then it wasn't really a child of relativeTo
        if (term == NULL) {
            set_null(nameOutput);
            return;
        }
    }

    // Fix output list
    list_reverse(nameOutput);
}
Пример #9
0
Parameter::Parameter(Type t, bool is_buffer, int d) :
    contents(new ParameterContents(t, is_buffer, d, unique_name('p'), false, true)) {
    internal_assert(is_buffer || d == 0) << "Scalar parameters should be zero-dimensional";
    // Note that is_registered is always true here; this is just using a parallel code structure for clarity.
    if (contents.defined() && contents.ptr->is_registered) {
        ObjectInstanceRegistry::register_instance(this, 0, ObjectInstanceRegistry::FilterParam, this, NULL);
    }
}
Пример #10
0
static void init(bNodeTree *UNUSED(ntree), bNode *node)
{
    TexNodeOutput *tno = MEM_callocN(sizeof(TexNodeOutput), "TEX_output");
    node->storage = tno;

    strcpy(tno->name, "Default");
    unique_name(node);
    assign_index(node);
}
Пример #11
0
char *buffer_name(char *fn)
{
	static char name[256];
	int i;

	char *p = strrchr(fn, '/');
	if (p != NULL) p++;
	if (p == NULL || *p == '\0') p = fn;
	if (unique_name(p)) {
		strcpy(name, p);
		return name;
	}
	for (i = 2; i < 100; i++) {
		sprintf(name, "%s<%d>", p, i);
		if (unique_name(name))
			return name;
	}
	return name;	/* unlikely and no problem */
}
void Connection::remove_match( const char* rule )
{
	Error e;
	
	dbus_bus_remove_match(_connection, rule, e);

	cbus_dbg("%s: removed match rule %s", unique_name(), rule);

	if(e) throw e;
}
Пример #13
0
void migrate_state_list(Value* list, Block* oldBlock, Block* newBlock, Migration* migration)
{
    if (is_null(list))
        return;
    if (newBlock == NULL) {
        set_null(list);
        return;
    }

    Value oldList;
    move(list, &oldList);
    touch(&oldList);
    set_list(list, newBlock->length());

    // Copy state values with matching names.
    for (int i=0; i < list_length(&oldList); i++) {
        Value* oldValue = list_get(&oldList, i);
        if (is_null(oldValue))
            continue;

        Term* oldTerm = oldBlock->get(i);
        Term* newTerm = find_from_unique_name(newBlock, unique_name(oldTerm));

#if 0
        printf("looking at unique name = %s for term %d, newTerm = %p\n",
            as_cstring(unique_name(oldTerm)), oldTerm->id, newTerm);
#endif

        if (newTerm != NULL) {
            Value* newSlot = list_get(list, newTerm->index);
            move(oldValue, newSlot);

#if 0
            printf("migrating state value, term name = %s\n", as_cstring(unique_name(oldTerm)));
#endif
        }
    }

    migrate_value(list, migration);
}
Пример #14
0
/*
 * Create a new variable V and add V=e to the cxt.
 */
static expr_t context_update(context_t cxt, expr_t e)
{
    if (expr_gettype(e) == EXPRTYPE_VAR)
        panic("unexpected CSE var type");
    expr_t v;
    if (cseinfo_search(cxt->cseinfo, e, &v))
        return v;
    char *name = unique_name("F", &cxt->varid);
    var_t v0 = make_var(name);
    v = expr_var(v0);
    cxt->cseinfo = cseinfo_destructive_insert(cxt->cseinfo, e, v);
    return v;
}
Пример #15
0
// Unpack a state value. Input 1 is the "identifying term" which is used as a key.
void unpack_state(caStack* stack)
{
    caValue* container = circa_input(stack, 0);
    Term* identifyingTerm = (Term*) circa_caller_input_term(stack, 1);

    caValue* element = get_field(container, unique_name(identifyingTerm));

    if (element == NULL) {
        set_null(circa_output(stack, 0));
    } else {
        copy(element, circa_output(stack, 0));
    }
}
Пример #16
0
    BufferContents(Type t, int x_size, int y_size, int z_size, int w_size,
                   uint8_t* data, const std::string &n) :
        type(t), allocation(NULL), name(n.empty() ? unique_name('b') : n) {
        user_assert(t.lanes() == 1) << "Can't create of a buffer of a vector type";
        buf.elem_size = t.bytes();
        uint64_t size = 1;
        if (x_size) {
            size *= x_size;
            check_buffer_size(size, name);
        }
        if (y_size) {
            size *= y_size;
            check_buffer_size(size, name);
        }
        if (z_size) {
            size *= z_size;
            check_buffer_size(size, name);
        }
        if (w_size) {
            size *= w_size;
            check_buffer_size(size, name);
        }
        size *= buf.elem_size;
        check_buffer_size(size, name);

        if (!data) {
            size = size + 32;
            check_buffer_size(size, name);
            allocation = (uint8_t *)calloc(1, (size_t)size);
            user_assert(allocation) << "Out of memory allocating buffer " << name << " of size " << size << "\n";
            buf.host = allocation;
            while ((size_t)(buf.host) & 0x1f) buf.host++;
        } else {
            buf.host = data;
        }
        buf.dev = 0;
        buf.host_dirty = false;
        buf.dev_dirty = false;
        buf.extent[0] = x_size;
        buf.extent[1] = y_size;
        buf.extent[2] = z_size;
        buf.extent[3] = w_size;
        buf.stride[0] = 1;
        buf.stride[1] = x_size;
        buf.stride[2] = x_size*y_size;
        buf.stride[3] = x_size*y_size*z_size;
        buf.min[0] = 0;
        buf.min[1] = 0;
        buf.min[2] = 0;
        buf.min[3] = 0;
    }
Пример #17
0
Term* find_from_unique_name(Block* block, Value* name)
{
    // O(n) search; this should be made more efficient.

    for (int i=0; i < block->length(); i++) {
        Term* term = block->get(i);
        if (term == NULL)
            continue;
        if (string_equals(unique_name(term), name)) {
            return term;
        }
    }
    return NULL;
}
Пример #18
0
int unique_name(push_from_the_east)(int obstacles[9], int ball_direction)
{
int i;
switch(ball_direction)
	{
	case N: return(NE);
	case NE: return(NE);
	case NW: return(N);
	case W: return(W);
	case E: return(unique_name(random_heading)());
	case S: return(SE);
	case SE: return(SE);
	case SW: return(S);
	default: return(N);
	}
}
Пример #19
0
const std::string& SymbolNameSet::symbol_name(const TreePtr<ModuleGlobal>& global) {
  std::string& name = m_symbol_names[global];
  if (!name.empty())
    return name;
  
  if (!global->symbol_name.empty()) {
    PSI_ASSERT(global->linkage != link_local);
    name = global->symbol_name;
  } else {
    std::ostringstream ss;
    ss << "_Y0";
    SymbolLocationWriter lw(ss);
    lw.write(global->location().logical, true, '\0', '\0');
    name = ss.str();
    if (global->linkage == link_local)
      name = unique_name(name);
  }
  return name;
}
Пример #20
0
void
fork_to_background (void)
{
    /* Whether we arrange our own version of opt.lfilename here.  */
    int changedp = 0;

    if (!opt.lfilename)
    {
        opt.lfilename = unique_name (DEFAULT_LOGFILE);
        changedp = 1;
    }
    printf (_("Continuing in background.\n"));
    if (changedp)
        printf (_("Output will be written to `%s'.\n"), opt.lfilename);

    ws_hangup ();
    if (!windows_nt_p)
        FreeConsole ();
}
Пример #21
0
void pack_any_open_state_vars(Branch* branch)
{
    for (int i=0; i < branch->length(); i++) {
        Term* term = branch->get(i);
        if (term == NULL)
            continue;
        if (term->function == FUNCS.declared_state) {
            Term* result = branch->get(term->name);

            // If this result already has a pack_state() term then leave it alone.
            if (find_user_with_function(result, FUNCS.pack_state) != NULL)
                continue;

            Term* pack = apply(branch, FUNCS.pack_state, TermList(
                find_open_state_result(branch, branch->length()), result, term));
            pack->setStringProp("field", unique_name(term));
            branch->move(pack, result->index + 1);
        }
    }
}
Пример #22
0
void
fork_to_background (void)
{
    /* Whether we arrange our own version of opt.lfilename here.  */
    int changedp = 0;

    //z l 表示日志文件,filename 表示文件名称
    if (!opt.lfilename)
    {
        //z 根据文件前缀生成一个文件名,前缀+数字(数字增大,直到找到一个不存在的文件为止)
        opt.lfilename = unique_name (DEFAULT_LOGFILE);
        changedp = 1;
    }
    printf (_("Continuing in background.\n"));
    //z 成功生成日志记录文件,输出信息
    if (changedp)
        printf (_("Output will be written to `%s'.\n"), opt.lfilename);

    ws_hangup ();
    if (!windows_nt_p)
        FreeConsole ();
}
Пример #23
0
InputParameters &
InputParameterWarehouse::addInputParameters(const std::string & name, InputParameters parameters, THREAD_ID tid /* =0 */)
{
  // Error if the name contains "::"
  if (name.find("::") != std::string::npos)
    mooseError("The object name may not contain '::' in the name: " << name);

  // Create the actual InputParameters object that will be reference by the objects
  MooseSharedPointer<InputParameters> ptr(new InputParameters(parameters));

  // Set the name parameter to the object being created
  ptr->set<std::string>("_object_name") = name;

  // The object name defined by the base class name, this method of storing is used for
  // determining the uniqueness of the name
  MooseObjectName unique_name(ptr->get<std::string>("_moose_base"), name);

  // Check that the Parameters do not already exist
  if (_input_parameters[tid].find(unique_name) != _input_parameters[tid].end())
    mooseError("A '" << unique_name.tag() << "' object already exists with the name '" << unique_name.name() << "'.\n");

  // Store the parameters according to the base name
  _input_parameters[tid].insert(std::pair<MooseObjectName, MooseSharedPointer<InputParameters> >(unique_name, ptr));

  // Store the object according to the control tags
  if (ptr->isParamValid("control_tags"))
  {
    std::vector<std::string> tags = ptr->get<std::vector<std::string> >("control_tags");
    for (std::vector<std::string>::const_iterator it = tags.begin(); it != tags.end(); ++it)
      _input_parameters[tid].insert(std::pair<MooseObjectName, MooseSharedPointer<InputParameters> >(MooseObjectName(*it, name),  ptr));
  }

  // Set the name and tid parameters
  ptr->addPrivateParam<THREAD_ID>("_tid", tid);
  ptr->allowCopy(false);  // no more copies allowed

  // Return a reference to the InputParameters object
  return *ptr;
}
Пример #24
0
LOCAL LONG ins_tree(LONG stree, WORD sobj, WORD kind, WORD dobj, WORD dx, WORD dy)
{
	LONG	dtree;
	BYTE	name[9];

	dtree = copy_tree(stree, sobj, TRUE);
	unique_name(&name[0], "TREE%hd", LWGET(RSH_NTREE(head)) + 1);
	if (new_index( (BYTE *) dtree, kind, &name[0]) == NIL)
	{
		hndl_alert(1, string_addr(STNFULL));
		return (-1L);
	}
	else
	{
		add_trindex(dtree);
		dobj = mov_tree(LWGET(RSH_NTREE(head)), dobj, dx, dy);
		select_tree(ad_view, trunpan_f(dobj));
		name_tree(dobj);
		dselct_tree(ad_view, trunpan_f(dobj));
		return (dtree);
	}
}
Пример #25
0
static inline
struct qp_source *
make_source(const char *filename, int value_type)
{
  qp_app_check();
  ASSERT(filename && filename[0]);
  struct qp_source *source;
  source = (struct qp_source *)
    qp_malloc(sizeof(struct qp_source));
  source->name = unique_name(filename);
  source->num_values = 0;
  source->value_type = (value_type)?value_type:QP_TYPE_DOUBLE;
  source->num_channels = 0;
  source->labels = NULL;
  source->num_labels = 0;
  /* NULL terminated array on channels */
  source->channels = qp_malloc(sizeof(struct qp_channel *));
  *(source->channels) = NULL;
  qp_sllist_append(app->sources, source);

  return source;
}
Пример #26
0
/// Modify transformation
inode* modify_transformation(idocument& Document, inode& Object, iplugin_factory* Modifier)
{
	return_val_if_fail(Modifier, 0);

	// Get the upstream and downstream properties ...
	imatrix_sink* const downstream_sink = dynamic_cast<imatrix_sink*>(&Object);
	return_val_if_fail(downstream_sink, 0);

	iproperty& downstream_input = downstream_sink->matrix_sink_input();

	iproperty* const upstream_output = Document.pipeline().dependency(downstream_input);

	inode* modifier = 0;

	// This block is recorded for undo purposes ...
	{
		record_state_change_set changeset(Document, string_cast(boost::format(_("Add Modifier %1%")) % Modifier->name()), K3D_CHANGE_SET_CONTEXT);

		// Create our modifier object ...
		modifier = plugin::create<inode>(*Modifier, Document, unique_name(Document.nodes(), Modifier->name()));
		return_val_if_fail(modifier, 0);

		// Get its input and output properties ...
		imatrix_sink* const modifier_sink = dynamic_cast<imatrix_sink*>(modifier);
		return_val_if_fail(modifier_sink, 0);
		imatrix_source* const modifier_source = dynamic_cast<imatrix_source*>(modifier);
		return_val_if_fail(modifier_source, 0);

		// Insert the modifier into the DAG ...
		ipipeline::dependencies_t dependencies;
		if(upstream_output)
			dependencies.insert(std::make_pair(&modifier_sink->matrix_sink_input(), upstream_output));
		dependencies.insert(std::make_pair(&downstream_input, &modifier_source->matrix_source_output()));
		Document.pipeline().set_dependencies(dependencies);
	}

	return modifier;
}
Пример #27
0
void EdbusConnection::setup_filter(void) {
	E_ASSERT(dc != NULL);
	E_ASSERT(dc->conn != NULL);

	DBusError err;
	dbus_error_init(&err);

	/* if we didn't registered any signal match, match everything */
	if(dc->signal_matches == 0) {
		dbus_bus_add_match(dc->conn, "type='signal'", &err);

		if(dbus_error_is_set(&err)) {
			E_WARNING(E_STRLOC ": Signal match failed: %s, %s\n", err.name, err.message);
			dbus_error_free(&err);
			return;
		}
	}

	/* if we didn't registered any method match, match everything */
	if(dc->method_matches == 0) {
		const char* name = unique_name();
		if(name) {
			char buff[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
			snprintf(buff, sizeof(buff), "destination='%s'", name);

			dbus_bus_add_match(dc->conn, buff, &err);

			if(dbus_error_is_set(&err)) {
				E_WARNING(E_STRLOC ": Destination match failed: %s, %s\n", err.name, err.message);
				dbus_error_free(&err);
				return;
			}
		} else
			E_WARNING(E_STRLOC ": Unable to get unique name\n");
	}

	dbus_connection_add_filter(dc->conn, edbus_signal_filter, dc, 0);
}
void Connection::request_name( const char* name, int flags )
{
	Error e;

	cbus_dbg("%s: registering bus name %s", unique_name(), name);

#ifdef DBUS_LEGACY
	dbus_bus_acquire_service(_connection, name, flags, e);
#else
	dbus_bus_request_name(_connection, name, flags, e);	//we deliberalely don't check return value
#endif

	if(e)	throw e;

//	this->remove_match("destination");

	if(name)
	{
		this->_service_name = name;
		std::string match = "destination='" + _service_name + "'";
		this->add_match(match.c_str());
	}
}
Пример #29
0
char *xfer_okay(void)
{
	static char new_pathname[PATHLEN];
	char *p;

	strcpy(new_pathname, download);
	p = new_pathname + ((int) strlen(new_pathname));	/* start of fname */
	if (single_file[0]) {
		strcat(new_pathname, single_file);	/* add override fname */
		single_done = true;
	} else {
		strcat(new_pathname, xfer_real);	/* add real fname */
		unique_name(new_pathname);	/* make it unique */
	}
	rename(xfer_pathname, new_pathname);	/* rename temp to real */
	if (!nostamp && xfer_ftime)
		setstamp(new_pathname, xfer_ftime);	/* set timestamp */

	if (xfer_logged)	/* delete from bad-xfer log */
		xfer_del();

	return (strcmp(p, xfer_real) ? p : NULL);	/* dup rename? */
}
Пример #30
0
void EdbusConnection::add_method_match(const char* path, const char* interface, const char* name) {
	if(!dc || !dc->conn)
		return;

	const char* u = unique_name();
	if(!u)
		return;

	DBusError err;
	dbus_error_init(&err);

	char buff[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
	snprintf(buff, sizeof(buff), "destination='%s',path='%s',interface='%s',member='%s'", u, path, interface, name);

	dbus_bus_add_match(dc->conn, buff, &err);

	if(dbus_error_is_set(&err)) {
		E_WARNING(E_STRLOC ": Adding method match failed: %s, %s\n", err.name, err.message);
		dbus_error_free(&err);
		return;
	}

	dc->method_matches++;
}