Exemple #1
0
static node_t *tag_decl(void)
{
    int t = token->id;
    const char *id = NULL;
    node_t *sym = NULL;
    struct source src = source;
    int follow[] = {INT, CONST, STATIC, IF, 0};

    expect(t);
    if (token->id == ID) {
        id = token->name;
        expect(ID);
    }
    if (token->id == '{') {
        expect('{');
        sym = tag_type(t, id, src);
        if (t == ENUM)
            ids(sym);
        else
            fields(sym);
        match('}', follow);
        SYM_DEFINED(sym) = true;
    } else if (id) {
        sym = lookup(id, tags);
        if (sym) {
            if (is_current_scope(sym) && TYPE_OP(SYM_TYPE(sym)) != t)
                errorf(src,
                       "use of '%s' with tag type that does not match "
                       "previous declaration '%s' at %s:%u:%u",
                       id2s(t), type2s(SYM_TYPE(sym)),
                       AST_SRC(sym).file,
                       AST_SRC(sym).line,
                       AST_SRC(sym).column);
        } else {
            sym = tag_type(t, id, src);
        }
    } else {
        error("expected identifier or '{'");
        sym = tag_type(t, NULL, src);
    }

    return SYM_TYPE(sym);
}
Exemple #2
0
static int _llp_out_message(llp_mes* lms)
{
	unsigned int inx =0;
	size_t i=0;
	check_null(lms, LP_FAIL);
	llp_out_open(&lms->sio);			// open out buff
//	sl_W32(lms->d_mes->message_id);		// if write id?
	
	for(i=0; i<lms->field_lens; i++)
	{
		switch(tag_type(lms->d_mes->message_tfl[i].tag))
		{
		case LLPT_INTEGER:
			{
				for(inx=0; inx<lms->field_al[i].lens; inx++)
				{
					llp_value* lv = lib_array_inx(&lms->field_al[i], inx);
					sl_Wtag(&lms->sio, o_num, i);
					sl_Winteger(&lms->sio, lv->lp_integer);
				}
			}
			break;
		case LLPT_REAL:
			{
				for(inx=0; inx<lms->field_al[i].lens; inx++)
				{
					llp_value* lv = lib_array_inx(&lms->field_al[i], inx);
					sl_Wtag(&lms->sio, o_num, i);
					sl_Wreal(&lms->sio, lv->lp_real);
				}
			}
			break;
		case LLPT_STRING:
			{
				for(inx=0; inx<lms->field_al[i].lens; inx++)
				{
					llp_value* lv = lib_array_inx(&lms->field_al[i], inx);
					sl_Wtag(&lms->sio, o_str, i);
					sl_Wstring(&lms->sio, lv->lp_str);
				}
			}
			break;
		case LLPT_BYTES:
			{
				for(inx=0; inx<lms->field_al[i].lens; inx++)
				{
					llp_value* lv = lib_array_inx(&lms->field_al[i], inx);
					sl_Wtag(&lms->sio, o_bytes, i);
					sl_Wbytes(&lms->sio, lv->lp_bytes);
				}
			}
			break;
		case LLPT_MESSAGE:
			{
				for(inx=0; inx<lms->field_al[i].lens; inx++)
				{
					llp_value* lv = lib_array_inx(&lms->field_al[i], inx);
					sl_Wtag(&lms->sio, o_mes, i);
					check_fail(_llp_out_message(lv->lp_mes), LP_FAIL);
					sl_Wmessage(&lms->sio, lv->lp_mes);
					llp_out_close(&lv->lp_mes->sio);			// close the message slice
				}
			}
			break;
		default:
			return LP_FAIL;
		}
	}
	return LP_TRUE;
}
Exemple #3
0
LLP_API int llp_in_message(slice* in, llp_mes* lms)
{
	size_t Ri = 0;
	byte   tt = 0;
	llp_uint32 Rtag =0;
	check_null(lms, LP_FAIL);
	check_null(in, LP_FAIL);
	check_null(in->sp, LP_FAIL);

	while(sl_is_end(in)==0)
	{
		check_fail(sl_R32(in, &Rtag), LP_FAIL);		// read tag
		
		if( (Ri=Rtag_id(Rtag))>=lms->field_lens )		// check ID is true
			return LP_FAIL;
		
		// check tag type is true
		switch(tt=(byte)tag_type(lms->d_mes->message_tfl[Ri].tag))
		{
		case LLPT_INTEGER:
			{
				llp_integer temp=0;
				if(Rtag_type(Rtag)!= o_num)
					return LP_FAIL;
				check_fail(sl_Rinteger(in, &temp), LP_FAIL);
				check_fail(_llp_Wmes(lms, Ri, tt, (void*)(&temp)), LP_FAIL);
			}
			break;
		case LLPT_REAL:
			{
				llp_real temp = 0.0;
				if(Rtag_type(Rtag)!= o_num)
					return LP_FAIL;
				check_fail(sl_Rreal(in, &temp), LP_FAIL);
				check_fail(_llp_Wmes(lms, Ri, tt, (void*)(&temp)), LP_FAIL);
			}
			break;
		case  LLPT_STRING:
			{
				char* temp = NULL;
				if(Rtag_type(Rtag)!= o_str)
					return LP_FAIL;
				check_fail(sl_Rstring(in, &temp), LP_FAIL);
				check_fail(_llp_Wmes(lms, Ri, tt, (void*)(temp)), LP_FAIL);
			}
			break;
		case LLPT_BYTES:
			{
				slice temp = {0};
				if(Rtag_type(Rtag)!= o_bytes)
					return LP_FAIL;
				check_fail(sl_Rbytes(in, &temp), LP_FAIL);
				check_fail(_llp_Wmes(lms, Ri, tt, (void*)(&temp)), LP_FAIL);
			}
			break;
		case LLPT_MESSAGE:
			{
				slice st = {0};
				llp_mes* temp = NULL;
				if(Rtag_type(Rtag)!= o_mes)
					return LP_FAIL;
				check_fail(sl_R32(in, (llp_uint32*)(&st.sp_size)), LP_FAIL);		// read message lens
				st.sp = in->sp;
				st.b_sp = st.sp;
				check_fail(_llp_Wmes(lms, Ri, tt, (void*)(&temp)), LP_FAIL);
				check_fail(llp_in_message(&st, temp), LP_FAIL);
				in->sp += st.sp_size;
			}
			break;
		default:
			return LP_FAIL;
		}
	}

	return LP_TRUE;
}
Exemple #4
0
 shape_kind() : Shape(N) { this->m_all_kinds = (const size_t*)get_kinds<Shape>(original2remapped<Shape>(tag_type(N))); }