示例#1
0
文件: type.c 项目: qznc/libfirm
void ir_init_type(ir_prog *irp)
{
	/* construct none and unknown type. */
	irp->none_type = new_type(tpop_none, mode_BAD, NULL);
	set_type_size_bytes(irp->none_type, 0);
	set_type_state (irp->none_type, layout_fixed);

	irp->code_type = new_type(tpop_code, mode_ANY, NULL);
	set_type_state(irp->code_type, layout_fixed);

	irp->unknown_type = new_type(tpop_unknown, mode_ANY, NULL);
	set_type_size_bytes(irp->unknown_type, 0);
	set_type_state (irp->unknown_type, layout_fixed);
}
Type Nanox::compute_replacement_type_for_vla(Type type, 
        ObjectList<Source>::iterator dim_names_begin,
        ObjectList<Source>::iterator dim_names_end)
{
    Type new_type(NULL);
    if (type.is_array())
    {
        new_type = compute_replacement_type_for_vla(type.array_element(), dim_names_begin + 1, dim_names_end);

        if (dim_names_begin == dim_names_end)
        {
            internal_error("Invalid dimension list", 0);
        }

        new_type = new_type.get_array_to(*dim_names_begin);
    }
    else if (type.is_pointer())
    {
        new_type = compute_replacement_type_for_vla(type.points_to(), dim_names_begin, dim_names_end);
        new_type = new_type.get_pointer_to();
    }
    else
    {
        new_type = type;
    }

    return new_type;
}
示例#3
0
文件: event.c 项目: xaradevil/tcvp
extern int
reg_event(char *name, tcvp_alloc_event_t af, tcvp_serialize_event_t sf,
          tcvp_deserialize_event_t df, char *fmt)
{
    tcvp_event_type_t *e;

    if(!af) {
        af = evt_alloc;
        if(!sf)
            sf = evt_serialize;
        if(!df)
            df = evt_deserialize;
    }

    if(!tchash_find(event_types, name, -1, &e)) {
        if(e->alloc)
            return -1;
        e->alloc = af;
        e->serialize = sf;
        e->deserialize = df;
        e->format = fmt;
        return e->num;
    }

    e = new_type(name, af, sf, df, fmt);

    return e->num;
}
示例#4
0
static symbol_t *
find_tag (ty_meta_e meta, symbol_t *tag, type_t *type)
{
	const char *tag_name;
	symbol_t   *sym;

	if (tag) {
		tag_name = va ("tag %s", tag->name);
	} else {
		const char *path = GETSTR (pr.source_file);
		const char *file = strrchr (path, '/');
		if (!file++)
			file = path;
		tag_name = va ("tag .%s.%d", file, pr.source_line);
	}
	sym = symtab_lookup (current_symtab, tag_name);
	if (sym) {
		if (sym->table == current_symtab && sym->type->meta != meta)
			error (0, "%s defined as wrong kind of tag", tag->name);
		if (sym->type->meta == meta)
			return sym;
	}
	sym = new_symbol (tag_name);
	if (!type)
		type = new_type ();
	if (!type->name)
		type->name = sym->name;
	sym->type = type;
	sym->type->type = ev_invalid;
	sym->type->meta = meta;
	sym->sy_type = sy_type;
	return sym;
}
示例#5
0
void c_typecheck_baset::typecheck_c_enum_tag_type(c_enum_tag_typet &type)
{
  // It's just a tag.

  if(type.find(ID_tag).is_nil())
  {
    error().source_location=type.source_location();
    error() << "anonymous enum tag without members" << eom;
    throw 0;
  }

  source_locationt source_location=type.source_location();

  irept &tag=type.add(ID_tag);
  irep_idt base_name=tag.get(ID_C_base_name);
  irep_idt identifier=tag.get(ID_identifier);

  // is it in the symbol table?
  symbol_tablet::symbolst::const_iterator s_it=
    symbol_table.symbols.find(identifier);

  if(s_it!=symbol_table.symbols.end())
  {
    // Yes.
    const symbolt &symbol=s_it->second;

    if(symbol.type.id()!=ID_c_enum &&
       symbol.type.id()!=ID_incomplete_c_enum)
    {
      error().source_location=source_location;
      error() << "use of tag that does not match previous declaration" << eom;
      throw 0;
    }
  }
  else
  {
    // no, add it as an incomplete c_enum
    typet new_type(ID_incomplete_c_enum);
    new_type.subtype()=signed_int_type(); // default
    new_type.add(ID_tag)=tag;

    symbolt enum_tag_symbol;

    enum_tag_symbol.is_type=true;
    enum_tag_symbol.type=new_type;
    enum_tag_symbol.location=source_location;
    enum_tag_symbol.is_file_local=true;
    enum_tag_symbol.base_name=base_name;
    enum_tag_symbol.name=identifier;

    symbolt *new_symbol;
    move_symbol(enum_tag_symbol, new_symbol);
  }

  // Clean up resulting type
  type.remove(ID_tag);
  type.set_identifier(identifier);
}
示例#6
0
文件: identity.c 项目: bearlang/cub
expression *new_identity_node(expression *left, expression *right) {
    expression *identity = xmalloc(sizeof(*identity));
    identity->operation.type = O_IDENTITY;
    identity->type = new_type(T_BOOL);
    identity->value = left;
    left->next = right;
    identity->next = NULL;
    identity->line = left->line;
    identity->offset = left->offset;
    return identity;
}
   void KernelHandle::insertOrRefreshNeighborSwarm(unsigned int robot_id, std::vector<unsigned int> swarm_list)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
       VoidAllocator alloc_inst (segment.get_segment_manager());
   
       std::pair<shm_neighbor_swarm_type*, std::size_t> neighbor_swarm = segment.find<shm_neighbor_swarm_type>("shm_neighbor_swarm_"); 
       if(neighbor_swarm.first==0)
       {
           return;
       }
 
       shm_neighbor_swarm_type *ns_pointer=neighbor_swarm.first;
       shm_neighbor_swarm_type::iterator ns_it;
       ns_it=ns_pointer->find(robot_id);
   
       if(ns_it!=ns_pointer->end())
       {
           named_kernel_mtx.lock();
           ns_it->second.clearSwarmIDVector();
           
           for(int i=0;i<swarm_list.size();i++)
           {
               ns_it->second.addSwarmID(swarm_list[i]);
           }
           ns_it->second.setAge(0);  //age置为0
           
           named_kernel_mtx.unlock();
       }
       else
       {
           NeighborSwarm new_neighbor_swarm(alloc_inst, 0);
           
           for(int i=0;i<swarm_list.size();i++)
           {
               new_neighbor_swarm.addSwarmID(swarm_list[i]);
           }
           
           NeighborSwarmType new_type(robot_id, new_neighbor_swarm);
           
           named_kernel_mtx.lock();
           ns_pointer->insert(new_type);
           named_kernel_mtx.unlock();
           return;
       }
   }
示例#8
0
文件: generate.c 项目: bearlang/cub
static size_t get_return_struct(code_system *system, type *return_type) {
  if (is_void(return_type)) {
    return 0;
  }

  size_t count = system->struct_count;
  code_struct *return_struct;

  for (size_t i = 0; i < count; i++) {
    return_struct = get_code_struct(system, i);
    if (return_struct->field_count != 1) {
      continue;
    }

    code_field *first_field = &return_struct->fields[0];
    type *first = first_field->field_type;

    if (first->type != T_BLOCKREF || !first->blocktype ||
        !first->blocktype->next || first->blocktype->next->next) {
      continue;
    }

    type *second = first->blocktype->next->argument_type;
    first = first->blocktype->argument_type;

    if (first->type == T_OBJECT && first->struct_index == i &&
        equivalent_type(return_type, second)) {
      return i;
    }
  }

  return_struct = add_struct(system);
  return_struct->field_count = 1;
  return_struct->fields = xmalloc(sizeof(code_field));
  return_struct->fields[0].field_type = new_type(T_BLOCKREF);

  argument *blocktype = xmalloc(sizeof(*blocktype));
  blocktype->symbol_name = NULL;
  blocktype->argument_type = get_object_type(count);
  return_struct->fields[0].field_type->blocktype = blocktype;

  blocktype->next = xmalloc(sizeof(argument));
  blocktype = blocktype->next;
  blocktype->symbol_name = NULL;
  blocktype->argument_type = copy_type(return_type);
  blocktype->next = NULL;

  return count;
}
示例#9
0
文件: event.c 项目: xaradevil/tcvp
extern int
get_event(char *name)
{
    tcvp_event_type_t *e;

    if(tchash_find(event_types, name, -1, &e))
        e = new_type(name, NULL, NULL, NULL, NULL);
    if(!e->alloc) {
        char *m = malloc(strlen(name) + sizeof("tcvp/events/") + 1);
        sprintf(m, "tcvp/events/%s", name);
        tc2_request(TC2_LOAD_MODULE, 1, m, NULL);
        free(m);
    }

    return e->num;
}
   void KernelHandle::insertOrUpdateNeighbor(unsigned int robot_id, float distance, float azimuth, float elevation, float x, float y, float z)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
   
       VoidAllocator alloc_inst (segment.get_segment_manager());
   
       std::pair<shm_neighbors_type*, std::size_t> neighbors = segment.find<shm_neighbors_type>("shm_neighbors_"); 
       if(neighbors.first==0)
       {
           return;
       }
 
       shm_neighbors_type *n_pointer=neighbors.first;
       shm_neighbors_type::iterator n_it;
       n_it=n_pointer->find(robot_id);
   
       if(n_it!=n_pointer->end())
       {
           NeighborLocation new_neighbor_location(distance, azimuth, elevation, x, y, z);
           
           named_kernel_mtx.lock();
           n_it->second = new_neighbor_location;
           named_kernel_mtx.unlock();   
       }
       else
       {
           NeighborLocation new_neighbor_location(distance, azimuth, elevation, x, y, z);
           NeighborLocationType new_type(robot_id, new_neighbor_location);    
           
           named_kernel_mtx.lock();
           n_pointer->insert(new_type);
           named_kernel_mtx.unlock();
       }
   }
   void KernelHandle::insertOrUpdateSwarm(unsigned int swarm_id, bool value)
   {
       std::string robot_id_string=boost::lexical_cast<std::string>(KernelInitializer::unique_robot_id_);
       std::string shm_object_name="KernelData"+robot_id_string;
       std::string mutex_name="named_kernel_mtx"+robot_id_string;
       boost::interprocess::named_mutex named_kernel_mtx(boost::interprocess::open_or_create, mutex_name.data()); 
       boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create ,shm_object_name.data(), 102400);
   
       VoidAllocator alloc_inst (segment.get_segment_manager());
   
       std::pair<shm_swarms_type*, std::size_t> swarms = segment.find<shm_swarms_type>("shm_swarms_"); 
       if(swarms.first==0)
       {
           return;
       }
 
       shm_swarms_type *s_pointer=swarms.first;
       shm_swarms_type::iterator s_it;
       s_it=s_pointer->find(swarm_id);
   
       if(s_it!=s_pointer->end())
       {
           named_kernel_mtx.lock();
           s_it->second = value;
           named_kernel_mtx.unlock();
           return;    
       }
       else
       {
           SwarmsType new_type(swarm_id, value);
           
           named_kernel_mtx.lock();
           s_pointer->insert(new_type);
           named_kernel_mtx.unlock();
           return;
       }
   }
示例#12
0
文件: router.cpp 项目: fritzo/pomagma
Router::Router(const Signature& signature,
               const std::unordered_map<std::string, float>& language)
    : m_carrier(*signature.carrier()),
      m_language(language),
      m_value_index(signature.carrier()->item_count()) {
    POMAGMA_INFO("Building router indices");

    for (auto pair : signature.nullary_functions()) {
        const auto& name = pair.first;
        const auto& fun = *pair.second;
        if (m_language.find(name) != m_language.end()) {
            const TypeId type = new_type(NULLARY, name);
            if (Ob val = fun.find()) {
                m_segments.push_back(Segment(type, val));
            }
        }
    }

    for (auto pair : signature.injective_functions()) {
        const auto& name = pair.first;
        const auto& fun = *pair.second;
        if (m_language.find(name) != m_language.end()) {
            const TypeId type = new_type(UNARY, name);
            for (auto iter = fun.iter(); iter.ok(); iter.next()) {
                Ob arg = *iter;
                Ob val = fun.find(arg);
                m_segments.push_back(Segment(type, val, arg));
            }
        }
    }

    for (auto pair : signature.binary_functions()) {
        const auto& name = pair.first;
        const auto& fun = *pair.second;
        if (m_language.find(name) != m_language.end()) {
            const TypeId type = new_type(BINARY, name);
            for (auto iter = m_carrier.iter(); iter.ok(); iter.next()) {
                Ob lhs = *iter;
                for (auto iter = fun.iter_lhs(lhs); iter.ok(); iter.next()) {
                    Ob rhs = *iter;
                    Ob val = fun.find(lhs, rhs);
                    m_segments.push_back(Segment(type, val, lhs, rhs));
                }
            }
        }
    }

    for (auto pair : signature.symmetric_functions()) {
        const auto& name = pair.first;
        const auto& fun = *pair.second;
        if (m_language.find(name) != m_language.end()) {
            const TypeId type = new_type(BINARY, name);
            for (auto iter = m_carrier.iter(); iter.ok(); iter.next()) {
                Ob lhs = *iter;
                for (auto iter = fun.iter_lhs(lhs); iter.ok(); iter.next()) {
                    Ob rhs = *iter;
                    Ob val = fun.find(lhs, rhs);
                    m_segments.push_back(Segment(type, val, lhs, rhs));
                }
            }
        }
    }

    std::sort(m_segments.begin(), m_segments.end());

    // assume all values are reached by at least one segment
    m_value_index.resize(1 + m_carrier.item_count(), 0);
    for (size_t i = 0; i < m_segments.size(); ++i) {
        m_value_index[m_segments[i].val] = i;
    }
}
示例#13
0
文件: etch_type.c 项目: OBIGOGIT/etch
/**
 * new__static_type() 
 * create a type object whose destructor will have no effect.
 */
etch_type* new_static_type(const wchar_t* name)
{
    etch_type* newtype = new_type(name);
    set_etchobj_static_all(newtype);
    return newtype;
} 
void cpp_typecheckt::typecheck_compound_type(
  struct_union_typet &type)
{
  // first save qualifiers
  c_qualifierst qualifiers(type);

  // now clear them from the type
  type.remove(ID_C_constant);
  type.remove(ID_C_volatile);
  type.remove(ID_C_restricted);

  // get the tag name
  bool anonymous=type.find(ID_tag).is_nil();
  irep_idt base_name;
  cpp_scopet *dest_scope=NULL;
  bool has_body=type.find(ID_body).is_not_nil();
  bool tag_only_declaration=type.get_bool(ID_C_tag_only_declaration);

  if(anonymous)
  {
    base_name="#anon_"+type.id_string()+i2string(anon_counter++);
    type.set("#is_anonymous", true);
    // anonymous structs always go into the current scope
    dest_scope=&cpp_scopes.current_scope();
  }
  else
  {
    const cpp_namet &cpp_name=
      to_cpp_name(type.find(ID_tag));

    // scope given?
    if(cpp_name.is_simple_name())
    {
      base_name=cpp_name.get_base_name();
      dest_scope=&tag_scope(base_name, has_body, tag_only_declaration);
    }
    else
    {
      cpp_save_scopet cpp_save_scope(cpp_scopes);
      cpp_typecheck_resolvet cpp_typecheck_resolve(*this);
      cpp_template_args_non_tct t_args;
      dest_scope=&cpp_typecheck_resolve.resolve_scope(cpp_name, base_name, t_args);
    }
  }

  const irep_idt symbol_name=
    language_prefix+
    dest_scope->prefix+
    "tag."+id2string(base_name);

  // check if we have it already

  contextt::symbolst::iterator previous_symbol=
    context.symbols.find(symbol_name);

  if(previous_symbol!=context.symbols.end())
  {
    // we do!

    symbolt &symbol=previous_symbol->second;

    if(has_body)
    {
      if(symbol.type.id()=="incomplete_"+type.id_string())
      {
        // a previously incomplete struct/union becomes complete
        symbol.type.swap(type);
        typecheck_compound_body(symbol);
      }
      else
      {
        err_location(type.location());
        str << "error: struct symbol `" << base_name
            << "' declared previously" << std::endl;
        str << "location of previous definition: "
            << symbol.location;
        throw 0;
      }
    }
  }
  else
  {
    // produce new symbol
    symbolt symbol;

    symbol.name=symbol_name;
    symbol.base_name=base_name;
    symbol.value.make_nil();
    symbol.location=type.location();
    symbol.mode=ID_cpp;
    symbol.module=module;
    symbol.type.swap(type);
    symbol.is_type=true;
    symbol.is_macro=false;
    symbol.pretty_name=cpp_scopes.current_scope().prefix+id2string(symbol.base_name);
    symbol.type.set(ID_tag, symbol.pretty_name);

    // move early, must be visible before doing body
    symbolt *new_symbol;
 
    if(context.move(symbol, new_symbol))
      throw "cpp_typecheckt::typecheck_compound_type: context.move() failed";

    // put into dest_scope
    cpp_idt &id=cpp_scopes.put_into_scope(*new_symbol, *dest_scope);

    id.id_class=cpp_idt::CLASS;
    id.is_scope=true;
    id.prefix=cpp_scopes.current_scope().prefix+
              id2string(new_symbol->base_name)+"::";
    id.class_identifier=new_symbol->name;
    id.id_class=cpp_idt::CLASS;

    if(has_body)
      typecheck_compound_body(*new_symbol);
    else
    {
      typet new_type("incomplete_"+new_symbol->type.id_string());
      new_type.set(ID_tag, new_symbol->base_name);
      new_symbol->type.swap(new_type);
    }
  }

  // create type symbol
  typet symbol_type(ID_symbol);
  symbol_type.set(ID_identifier, symbol_name);
  qualifiers.write(symbol_type);
  type.swap(symbol_type);
}