Esempio n. 1
0
void component_spec_iterate(nesc_declaration c,
			    void (*iterator)(data_declaration fndecl,
					     void *data),
			    void *data,
			    bool interfaces, bool otherdecls)
{
  const char *ifname;
  void *ifentry;
  env_scanner scanifs;

  env_scan(c->env->id_env, &scanifs);
  while (env_next(&scanifs, &ifname, &ifentry))
    {
      data_declaration idecl = ifentry;

      if (!otherdecls && !(idecl->kind == decl_interface_ref ||
			    idecl->kind == decl_function))
	continue;

      if (idecl->kind != decl_interface_ref || interfaces)
	iterator(idecl, data);

      if (idecl->kind == decl_interface_ref)
	{
	  env_scanner scanfns;
	  const char *fnname;
	  void *fnentry;

	  interface_scan(idecl, &scanfns);
	  while (env_next(&scanfns, &fnname, &fnentry))
	    iterator(fnentry, data);
	}
    }
}
Esempio n. 2
0
int match_function_component(bool eqconnection,
			     struct endp f, struct endp c, endp amatch)
{
  const char *ifname;
  void *ifentry;
  int matched = 0;
  env_scanner scanifs;
  bool want_defined;

  assert(f.function && !c.interface && !c.function);

  want_defined = f.function->defined ^ !eqconnection;

  component_scan(c.component, &scanifs);
  while (env_next(&scanifs, &ifname, &ifentry))
    {
      data_declaration idecl = ifentry;

      c.function = c.interface = NULL;
      if (idecl->kind == decl_interface_ref)
	{
	  c.interface = idecl;
	  matched += match_function_interface(want_defined ^ idecl->required,
					      f, c, amatch);
	}
      else
	{
	  c.function = idecl;
	  if (c.function->defined == want_defined)
	    matched += match_endpoints(&f, &c, amatch);
	}
    }
  return matched;
}
Esempio n. 3
0
int match_interface_component(bool eqconnection,
			      struct endp i, struct endp c, endp amatch)
{
  const char *ifname;
  void *ifentry;
  int matched = 0;
  env_scanner scanifs;
  bool want_required;

  assert(i.interface && !c.interface);

  want_required = i.interface->required ^ !eqconnection;

  component_scan(c.component, &scanifs);
  while (env_next(&scanifs, &ifname, &ifentry))
    {
      data_declaration idecl = ifentry;

      if (idecl->kind == decl_interface_ref)
	{
	  c.interface = idecl;
	  if (c.interface->required == want_required)
	    matched += match_endpoints(&i, &c, amatch);
	}
    }
  return matched;
}
Esempio n. 4
0
int match_function_interface(bool eqconnection,
			     struct endp f, struct endp i, endp amatch)
{
#ifdef NO_FUNCTION_INTERFACE_MATCHING
  return 0;
#else
  env_scanner scanfns;
  const char *fnname;
  void *fnentry;
  int matched = 0;
  bool want_defined;

  assert(f.function && !i.function);

  want_defined = f.function->defined ^ !eqconnection;

  /* Check all functions */
  interface_scan(i.interface, &scanfns);
  while (env_next(&scanfns, &fnname, &fnentry))
    {
      i.function = fnentry;
      if (i.function->defined == want_defined)
	matched += match_endpoints(&f, &i, amatch); 
    }

  return matched;
#endif
}
Esempio n. 5
0
void connect_interface(location l, cgraph cg, cgraph userg,
		       struct endp from, struct endp to,
		       bool reverse)
{
  env_scanner scanfns;
  const char *fnname;
  void *fnentry;

  if (to.interface->required ^ reverse)
    connect_userg(l, userg, to, from);
  else
    connect_userg(l, userg, from, to);

  assert(!from.function && !to.function
	 /*&& from.interface->itype == to.interface->itype*/);

  /* All functions */
  interface_scan(to.interface, &scanfns);
  while (env_next(&scanfns, &fnname, &fnentry))
    {
      data_declaration fndecl = fnentry;

      assert(fndecl->kind == decl_function);
      to.function = fndecl;
      from.function = env_lookup(from.interface->functions->id_env, fndecl->name, TRUE);
      if (fndecl->defined ^ reverse)
	connect_cg(cg, from, to);
      else
	connect_cg(cg, to, from);
    }
}
Esempio n. 6
0
void copy_interface_functions(region r, nesc_declaration container,
			      data_declaration iref, environment fns)
{
  environment icopy = new_environment(r, NULL, TRUE, FALSE);
  env_scanner scanif;
  const char *fnname;
  void *fnentry;

  env_scan(fns->id_env, &scanif);
  while (env_next(&scanif, &fnname, &fnentry))
    {
      data_declaration fndecl = fnentry, fncopy;

      /* Strings acquire a magic_string decl which we don't care about
	 legal example: 
	  command int (*init())[sizeof "aa"];
      */
      if (fndecl->kind == decl_magic_string)
	continue;

      fncopy = declare(icopy, fndecl, FALSE);
      fncopy->fn_uses = NULL;
      fncopy->nuses = NULL;
      fncopy->instanceof = fndecl;
      fncopy->container = container;
      fncopy->interface = iref;
      /* required events and provided commands are defined */
      fncopy->defined = (fncopy->ftype == function_command) ^ iref->required;
    }

  iref->functions = icopy;
}
Esempio n. 7
0
const char* env_get(const char* key)
{
	char *ptr = current_env->data;
	struct env_element e;
	do {
		e = env_next(&ptr);
		if (e.key && (strcmp(key, e.key)==0)) 
			return e.value;
	} while (e.key);
	return NULL;
}
Esempio n. 8
0
int env_delete(const char* key)
{

	char *ptr = current_env->data;
	struct env_element e;
	do {
		e = env_next(&ptr);
		if (e.key && (strcmp(e.key, key)==0)) {  
			char* to = e.key;
			e = env_next(&ptr);				
			char* from = e.key;
			if (!from)
				from = &current_env->data[current_env->occupied]; 
			int delta = (from - to); 
			while (*from != 0xff) 
				*to++ = *from++;
			*to = 0xff;
			current_env->occupied-=delta;
			return 0;
		}
	} while (e.key);	
	return 0;
}
Esempio n. 9
0
void env_dump(void)
{
	char *ptr = current_env->data;
	struct env_element e;
	console_printf("=== Current environment ===\n");
	do {
		e = env_next(&ptr);
		if (e.key) 
			console_printf("%-10s  %s\n", e.key, e.value);
	} while (e.key);
	console_printf("=== %d/%d bytes used ===\n", 
		       current_env->occupied, 
		       current_env_size);
}
Esempio n. 10
0
void set_interface_functions_gparms(environment fns, typelist gparms)
{
  env_scanner scanif;
  const char *fnname;
  void *fnentry;

  env_scan(fns->id_env, &scanif);
  while (env_next(&scanif, &fnname, &fnentry))
    {
      data_declaration fndecl = fnentry;

      /* Push generic args onto fn type and decl */
      fndecl->gparms = gparms;
      fndecl->type = make_generic_type(fndecl->type, gparms);
    }
}