Ejemplo n.º 1
0
static bool test_traversal_cb(
    const struct RFstring *name,
    const struct ast_node *desc,
    struct type *t,
    struct test_traversal_cb_ctx *ctx)
{
    ck_assert_msg(
        rf_string_equal(&ctx->names[ctx->idx], name),
        "Ast type traversal index %u expected name "RF_STR_PF_FMT" but got "
        RF_STR_PF_FMT".",
        ctx->idx,
        RF_STR_PF_ARG(&ctx->names[ctx->idx]),
        RF_STR_PF_ARG(name)
    );
    ck_assert_msg(
        type_compare(ctx->types[ctx->idx], t, TYPECMP_IDENTICAL),
        "Ast type traversal index %u expected type "RF_STR_PF_FMT" but got "
        RF_STR_PF_FMT".",
        ctx->idx,
        RF_STR_PF_ARG(type_str(ctx->types[ctx->idx], TSTR_DEFAULT)),
        RF_STR_PF_ARG(type_str(t, TSTR_DEFAULT))
    );
    ++ctx->idx;
    return true;
}
Ejemplo n.º 2
0
} END_TEST

START_TEST (test_type_to_str) {

    struct type *t_u32 = testsupport_analyzer_type_create_simple_elementary(ELEMENTARY_TYPE_UINT_32);
    struct type *t_f64 = testsupport_analyzer_type_create_simple_elementary(ELEMENTARY_TYPE_FLOAT_64);
    struct type *t_string = testsupport_analyzer_type_create_simple_elementary(ELEMENTARY_TYPE_STRING);
    struct type *t_prod_1 = testsupport_analyzer_type_create_operator(TYPEOP_PRODUCT,
                                                                     t_u32,
                                                                     t_f64);
    struct type *t_sum_1 = testsupport_analyzer_type_create_operator(TYPEOP_SUM,
                                                                     t_f64,
                                                                     t_string);
    static const struct RFstring id_person =  RF_STRING_STATIC_INIT("person");
    struct type *t_defined_1 = testsupport_analyzer_type_create_defined(&id_person,
                                                                        t_sum_1);

    struct RFstring *ts;
    RFS_PUSH();
    ck_assert((ts = type_str(t_u32, TSTR_DEFAULT)));
    ck_assert_rf_str_eq_cstr(ts, "u32");
    ck_assert((ts = type_str(t_prod_1, TSTR_DEFAULT)));
    ck_assert_rf_str_eq_cstr(ts, "u32,f64");
    ck_assert((ts = type_str(t_defined_1, TSTR_DEFAULT)));
    ck_assert_rf_str_eq_cstr(ts, "person");
    RFS_POP();
} END_TEST
Ejemplo n.º 3
0
void display_functions (HashTable *func_tbl) {
    
    Bucket *p;
    function_entry *fe;
    int i;
    
    p = func_tbl->pListHead;
    while (p != NULL) {
        fe = p->pData;
        
        st_output_debug_string("\t%s %s %s (", acc_type_str(fe->fn_flags), type_str(&fe->return_type),
                               fe->function_name);
        
        for (i = 0; i < fe->num_args; i++) {
            if (i == fe->num_args - 1) {
                st_output_debug_string("%s: %s", fe->args_info[i].name, type_str(&fe->args_info[i].arg_type));
                break;
            }
            st_output_debug_string("%s : %s, ", fe->args_info[i].name, type_str(&fe->args_info[i].arg_type));
        }
        
        st_output_debug_string(")");
        st_output_debug_string(" { ");
        display_variables(fe->local_vars);
        st_output_debug_string(" }\n\n");
        p = p->pListNext;
    }
        
}
Ejemplo n.º 4
0
// Debugging function, to make sure the rule tables are being generated properly
void dump_rules( int level, rule_t *rules ){
	if ( rules ){
		int i;
		for ( i = 0; i < level; i++ )
			printf( "    " );
		
		printf( "%s -> %s\n", type_str( rules->type ), type_str( rules->ret ));
		dump_rules( level+1, rules->down );
		dump_rules( level, rules->next );
	}
}
Ejemplo n.º 5
0
void ResourceManager::load(StringId64 type, StringId64 name)
{
	ResourcePair id = { type, name };
	ResourceEntry& entry = sort_map::get(_rm, id, ResourceEntry::NOT_FOUND);

	if (entry == ResourceEntry::NOT_FOUND)
	{
		TempAllocator64 ta;
		DynamicString type_str(ta);
		DynamicString name_str(ta);
		type.to_string(type_str);
		name.to_string(name_str);

		CE_ASSERT(_loader->can_load(type, name)
			, "Can't load resource #ID(%s-%s)"
			, type_str.c_str()
			, name_str.c_str()
			);
		CE_UNUSED(type_str);
		CE_UNUSED(name_str);

		ResourceRequest rr;
		rr.type = type;
		rr.name = name;
		rr.load_function = sort_map::get(_type_data, type, ResourceTypeData()).load;
		rr.allocator = &_resource_heap;
		rr.data = NULL;

		_loader->add_request(rr);
		return;
	}

	entry.references++;
}
Ejemplo n.º 6
0
const void* ResourceManager::get(StringId64 type, StringId64 name)
{
	const ResourcePair id = { type, name };
	TempAllocator128 ta;
	DynamicString type_str(ta);
	DynamicString name_str(ta);
	type.to_string(type_str);
	name.to_string(name_str);

	CE_ASSERT(can_get(type, name)
		, "Resource not loaded #ID(%s-%s)"
		, type_str.c_str()
		, name_str.c_str()
		);
	CE_UNUSED(type_str);
	CE_UNUSED(name_str);

	if (_autoload && !sort_map::has(_rm, id))
	{
		load(type, name);
		flush();
	}

	const ResourceEntry& entry = sort_map::get(_rm, id, ResourceEntry::NOT_FOUND);
	return entry.data;
}
Ejemplo n.º 7
0
static unsigned int
type_bitwidth(ir_unit_t *iu, int index)
{
  ir_type_t *it = type_get(iu, index);
  switch(it->it_code) {
  case IR_TYPE_VOID:
    return 0;
  case IR_TYPE_INT1:
    return 1;
  case IR_TYPE_INT8:
    return 8;
  case IR_TYPE_INT16:
    return 16;
  case IR_TYPE_INT32:
    return 32;
  case IR_TYPE_INT64:
    return 64;
  case IR_TYPE_INTx:
    return it->it_bits;

  default:
    parser_error(iu, "Unable to compute bitwidth of type %s\n",
                 type_str(iu, it));
  }
}
Ejemplo n.º 8
0
Object * s_exp(void) {
  Object *cell = _nil;
  switch(token_type()) {
    case T_NUMBER:
      cell = number(atoi(token.token));
      match(T_NUMBER);
      break;
    case T_SYMBOL:
      cell = symbol(token.token);
      match(T_SYMBOL);
      break;
    case T_LEFTPAREN:
      match(T_LEFTPAREN);
      cell = s_exp_list();
      match(T_RIGHTPAREN);
      break;
    case T_END:
      break;
    default:
      printf("%s:%d error, did not expect type %d %s\n",
          __FILE__, __LINE__, token_type(), type_str(token_type()));
      exit(-1);
  }
  return cell;
}
Ejemplo n.º 9
0
void display_variables(HashTable *vars) {

    Bucket *p;
    variable *var;
    
    p = vars->pListHead;
    while (p != NULL) {
        var = p->pData;
        p = p->pListNext;
        if (!p) {
            st_output_debug_string("%s: %s;", var->name, type_str(&var->variable_type));
            break;
        }
        st_output_debug_string("%s : %s, ", var->name, type_str(&var->variable_type));
    }
    
}
Ejemplo n.º 10
0
void match(int type) {
  if (type != token_type()) {
    printf("Error - expected %d %s , got '%s'\n",
        type, type_str(type), token.token);
    printf("Line %d, word %d\n", token.line, token.word);
    exit(-1);
  }
  scanner();
}
Ejemplo n.º 11
0
void sip_trans::dump() const
{
    DBG("type=%s (0x%x); msg=%p; to_tag=%.*s;"
	" reply_status=%i; state=%s (%i); retr_buf=%p; timers [%s,%s,%s]\n",
	type_str(),type,msg,to_tag.len,to_tag.s,
	reply_status,state_str(),state,retr_buf,
	timers[0]==NULL?"none":timer_name(timers[0]->type),
	timers[1]==NULL?"none":timer_name(timers[1]->type),
	timers[2]==NULL?"none":timer_name(timers[2]->type));
}
Ejemplo n.º 12
0
Archivo: TS.c Proyecto: Hamza5/CLOG
void afficher(){
    liste *v;
    v=tete;
	printf("+--------+--------------------+----------+-------+\n");
	printf("|%-8s|%-20s|%-10s|%-7s|\n","Nom","Type","Nature","Taille");
	printf("+--------+--------------------+----------+-------+\n");
	while(v!=NULL){
        printf("|%-8s|%-20s|%-10s|%7d|\n", v->elm.nom, type_str(v->elm.type), nature_str(v->elm.nature), v->elm.taille);
		printf("+--------+--------------------+----------+-------+\n");
        v=v->svt;
    }
}
Ejemplo n.º 13
0
void Iss2::DataRequest::print( std::ostream &o ) const
{
    o << "<DataReq"
      << " mode " << mode_str(mode)
      << (valid ? "   valid" : " invalid")
      << " type " << type_str(type);
    if ( type == XTN_READ || type == XTN_WRITE )
        //o << " (" << xtn_str((enum ExternalAccessType)addr) << ")";
        o << " (" << xtn_str((enum ExternalAccessType)(addr/4)) << ")";
    else
        o << " @ " << std::hex << std::showbase << addr;
    o << " wdata " << std::hex << std::showbase << wdata
      << " be " << std::hex << (int)be
      << ">";
}
Ejemplo n.º 14
0
ChatType PurpleLine::get_chat_type(const char *type_ptr) {
    if (!type_ptr)
        return ChatType::ANY; // Invalid

    std::string type_str(type_ptr);

    if (type_str == chat_type_to_string[ChatType::GROUP])
        return ChatType::GROUP;
    else if (type_str == chat_type_to_string[ChatType::ROOM])
        return ChatType::ROOM;
    else if (type_str == chat_type_to_string[ChatType::GROUP_INVITE])
        return ChatType::GROUP_INVITE;

    return ChatType::ANY; // Invalid
}
Ejemplo n.º 15
0
dnsbl_log(const DNSBL_WORK *dlw,
	  const DNSBL_HGROUP *hg,
	  DNSBL_HIT hit,
	  const char *pat, ...)
{
	char type_buf[1+sizeof(hg->btype_buf)+LITZ(" whitelist")];
	const char *type;
	char gbuf[8];
	const char *gnum;
	char msg[256];
	va_list args;

	va_start(args, pat);
	vsnprintf(msg, sizeof(msg), pat, args);
	va_end(args);

	if (hit) {
		type_buf[0] = ' ';
		type_str(&type_buf[1], sizeof(type_buf)-1, dlw, hit);
		type = type_buf;
	} else {
		type = "";
	}
	if (!have_dnsbl_groups) {
		gnum = "";
	} else if (!hg) {
		gnum = "*";
	} else {
		snprintf(gbuf, sizeof(gbuf), "%d",
			 (int)(hg - dlw->hgroups)+1);
		gnum = gbuf;
	}

	if (helper.debug) {
		if (dcc_no_syslog)
			thr_trace_msg(dlw->log_ctxt, "DNSBL%s%s%s %s",
				      gnum, helper_str, type, msg);
		else
			thr_trace_msg(dlw->log_ctxt, "%s DNSBL%s%s%s %s",
				      dlw->id,
				      gnum, helper_str, type, msg);
	} else {
		thr_log_print(dlw->log_ctxt, 1, "DNSBL%s%s%s %s\n",
			      helper_str, gnum, type, msg);
	}
}
Ejemplo n.º 16
0
void display_globals() {
    
    HashTable *glb_tbl = CG(global_var_table);
    variable *var;
    Bucket *p;
    
    p = glb_tbl->pListHead;
    
    st_output_debug_string("Global Variables:\n\n");
    while (p != NULL) {
        var = p->pData;
        st_output_debug_string("%s: %s;\n", var->name, type_str(&var->variable_type));
    }
    
    st_output_debug_string("\n\n");

}
Ejemplo n.º 17
0
static unsigned int
type_sizeof(ir_unit_t *iu, int index)
{
  ir_type_t *it = type_get(iu, index);
  switch(it->it_code) {
  case IR_TYPE_VOID:
    return 0;
  case IR_TYPE_INT1:
  case IR_TYPE_INT8:
    return 1;
  case IR_TYPE_INT16:
    return 2;
  case IR_TYPE_INT32:
  case IR_TYPE_FLOAT:
    return 4;
  case IR_TYPE_INT64:
  case IR_TYPE_DOUBLE:
    return 8;

  case IR_TYPE_INTx:
    if(it->it_bits <= 32)
      return 4;
    if(it->it_bits <= 64) {
      return 8;
    }
    goto bad;

  case IR_TYPE_POINTER:
    return 4;
  case IR_TYPE_STRUCT:
    return it->it_struct.size;

  case IR_TYPE_ARRAY:

    return type_sizeof(iu, it->it_array.element_type) *
      it->it_array.num_elements;

  default:
  bad:
    parser_error(iu, "Unable to compute size of type %s\n",
                 type_str(iu, it));
  }
}
Ejemplo n.º 18
0
void InterfaceSim::on_add_receiver(const char *type)
{
    SimulationType t = str_type(type);
    if (t == ST_UNKNOWN) return;

    lo_address a = lo_message_get_source(m_msg);
    if (!a) return;

    char *url = lo_address_get_url(a);
    if (!url) return;

    // Physics can change object positions in any of the other
    // simulations
    if (t & ST_HAPTICS || t & ST_VISUAL)
        sendtotype(ST_PHYSICS, 0, "/world/add_receiver_url",
                   "ss", type, url);

    // Haptics can add force to objects in the physics simulation.
    if (t & ST_PHYSICS || t & ST_VISUAL)
        sendtotype(ST_HAPTICS, 0, "/world/add_receiver_url",
                   "ss", type, url);

    // Visual can send a message to haptics due to keyboard
    // shortcuts. (e.g. reset_workspace.)
    if (t & ST_HAPTICS)
        sendtotype(ST_VISUAL, 0, "/world/add_receiver_url",
                   "ss", type, url);

    // Interface can modify anything in any other simulation.
    add_receiver(0, url, t, false);

#ifdef DEBUG
    printf("[%s] add_receiver(): %s, source = %s\n", type_str(), type, url);
#endif
    free(url);
}
Ejemplo n.º 19
0
std::string gen_vardef_array(ParseNode * pn, ParseNode * spec_typename, ParseNode * slice, VariableDescAttr * vardescattr) {
	// ARRAY
	/* in cpp code, definition of an array is inherit attribute(继承属性) grammar */
	string arr_decl = "";
#define USE_LOOP
	// pn is flattened
	for (int i = 0; i < pn->child.size(); i++)
	{
		// for each variable in flatterned paramtable
		int sliceid = 0;
		sprintf(codegen_buf, "for1array<%s>", spec_typename->fs.CurrentTerm.what.c_str());
		sprintf(codegen_buf, gen_vardef_typestr(vardescattr).c_str(), string(codegen_buf).c_str());
		string type_str(codegen_buf);
		sprintf(codegen_buf, gen_vardef_typestr(vardescattr).c_str(), spec_typename->fs.CurrentTerm.what.c_str());
		string elem_type_str(codegen_buf); // `T`
										   // init high dimension array
										   /* though using for-loop to init a high-dimension array is verbose comparing to using constructors, 
										   i use this form because it is more clear and it can remind users of the cost of using a high dimension array */
		vector<string> this_major; /* if you want to set value of a(i0)(i1)(i2) then this_major is a(i0)(i1) */
		this_major.push_back(pn->child[i]/* NT_VARIABLEINITIAL/NT_KEYVALUE */->child[0]->fs.CurrentTerm.what /* array name */);
		for (int i = 1; i < slice->child.size(); i++)
		{
			sprintf(codegen_buf, "%s(i%d)", this_major.back().c_str(), i - 1);
			this_major.push_back(string(codegen_buf));
		}
		for (sliceid = slice->child.size() - 2; sliceid >= 0; sliceid--)
		{
			string prev_type_str = type_str;
			sprintf(codegen_buf, "for1array< %s >", type_str.c_str());
			type_str = string(codegen_buf);
			sprintf(codegen_buf, "for(int i%d = %s; i%d < %s; i%d++){\n\t%s(i%d) = %s(%s, %s + 1);\n%s\n}\n" /* NOTE fortran is [lower_bound, upper_bound] cpp is [lower_bound, upper_bound) */
				, sliceid, slice->child[sliceid]->child[0]->fs.CurrentTerm.what.c_str(), sliceid, slice->child[sliceid]->child[1]->fs.CurrentTerm.what.c_str(), sliceid
				, this_major[sliceid].c_str(), sliceid, prev_type_str.c_str(), slice->child[sliceid + 1]->child[0]->fs.CurrentTerm.what.c_str(), slice->child[sliceid + 1]->child[1]->fs.CurrentTerm.what.c_str()
				, sliceid + 1 == slice->child.size() - 1 ? "" : tabber(slice->child[sliceid + 1]->fs.CurrentTerm.what).c_str());
			prev_type_str = type_str;
			slice->child[sliceid]->fs.CurrentTerm.what = string(codegen_buf);
		}
		// use it in fucntion_decl
		//string var_pattern = gen_vardef_pattern(vardescattr, false);

		// no desc if var_def is not in paramtable
		sprintf(codegen_buf, "%s %s(%s, %s + 1);\n", type_str.c_str(), pn->child[i]->child[0]->fs.CurrentTerm.what.c_str() /* array name */
			, slice->child[0]->child[0]->fs.CurrentTerm.what.c_str(), slice->child[0]->child[1]->fs.CurrentTerm.what.c_str() /* slice from to */);
		arr_decl += codegen_buf;
		/* set initial value from array_builder */
		if (pn->child[i]->child[1]->fs.CurrentTerm.token == TokenMeta::NT_ARRAYBUILDER)
		{
			for (int abid = 0; abid < pn->child[i]->child[1]->child.size(); abid++)
			{
				ParseNode * array_builder = pn->child[i]->child[1]->child[abid];
				if (array_builder->fs.CurrentTerm.token == TokenMeta::NT_ARRAYBUILDER_VALUE) {
					std::string vec_size = "{", vec_lb = "{";
					for (int sliceid = 0; sliceid < slice->child.size(); sliceid++)
					{
						if (sliceid != 0) {
							vec_lb += ",";
							vec_size += ",";
						}
						vec_lb += slice->child[sliceid]->child[0]->fs.CurrentTerm.what;
						int lb, ub;
						sscanf(slice->child[sliceid]->child[0]->fs.CurrentTerm.what.c_str(), "%d", &lb);
						sscanf(slice->child[sliceid]->child[1]->fs.CurrentTerm.what.c_str(), "%d", &ub);
						sprintf(codegen_buf, "%d", ub - lb + 1);
						vec_size += codegen_buf;
					}
					vec_size += "}", vec_lb += "}";
					sprintf(codegen_buf, array_builder->fs.CurrentTerm.what.c_str() /*  "init_for1array(%%s, %%s, %%s, %s)\n" from gen_arraybuilder */
						, pn->child[i]->child[0]->fs.CurrentTerm.what.c_str() /* variable name */
						, vec_lb.c_str()
						, vec_size.c_str()
						, elem_type_str.c_str());
				}
				else if (array_builder->fs.CurrentTerm.token == TokenMeta::NT_ARRAYBUILDER_EXP) {
					string formatter = (array_builder->fs.CurrentTerm.what + ";\n");
					sprintf(codegen_buf, formatter.c_str(), pn->child[i]->child[0]->fs.CurrentTerm.what.c_str());
				}
				else {
					sprintf(codegen_buf, "");
				}
			}
		}
		else {
			sprintf(codegen_buf, "");
		}
		arr_decl += codegen_buf;
	}
	return arr_decl;
}
Ejemplo n.º 20
0
void display_properties(HashTable *pps) {
    
    Bucket *p;
    property_info *prop;
    
    p = pps->pListHead;
    st_output_debug_string("  Properties:\n");
    while (p != NULL) {
        prop = p->pData;
        st_output_debug_string("\t%s %s: %s;\n", acc_type_str(prop->flags), prop->name, type_str(&prop->type));
        p = p->pListNext;
    }
    
}
Ejemplo n.º 21
0
 Expr& operator()(Expr& e)
 {
   std::cout << type_str(e) << '\n';
   lingo_unimplemented();
 }