Ejemplo n.º 1
0
static error_code_t on_document_end(generator_t *super, const YYLTYPE *yylloc, const char *file_name)
{
	TLIBC_UNUSED(file_name);
	TLIBC_UNUSED(yylloc);

	generator_printline(super, 0, "");

	generator_close(super);
	return E_TD_NOERROR;
}
Ejemplo n.º 2
0
tlibc_error_code_t tlibc_csv_read_vector_element_end(tlibc_abstract_reader_t *super, const char* var_name, uint32_t index)
{
	tlibc_csv_reader_t *self = TLIBC_CONTAINER_OF(super, tlibc_csv_reader_t, super);
	TLIBC_UNUSED(var_name);
	TLIBC_UNUSED(index);
	if(self->field_end == NULL)
	{
		self->field = NULL;
	}
	else
	{
		self->field = self->field_end + 1;
	}
	return E_TLIBC_NOERROR;
}
Ejemplo n.º 3
0
tlibc_error_code_t tlibc_csv_read_vector_element_begin(tlibc_abstract_reader_t *super, const char* var_name, uint32_t index)
{
	tlibc_error_code_t ret = E_TLIBC_NOERROR;
	tlibc_csv_reader_t *self = TLIBC_CONTAINER_OF(super, tlibc_csv_reader_t, super);
	TLIBC_UNUSED(var_name);
	if(self->field == NULL)
	{
		ret = E_TLIBC_NOT_FOUND;
		goto done;
	}
	if(*self->field == '\0')
	{
		goto done;
	}

	self->field_end = self->field;
	while((*self->field_end != ';') && (*self->field_end != 0))
	{
		++self->field_end;
	}

	if(*self->field_end == ';')
	{
		*self->field_end = 0;
	}
	else
	{
		self->field_end = NULL;
	}
	
done:
	return ret;
}
Ejemplo n.º 4
0
static error_code_t on_document_begin(generator_t *super, const YYLTYPE *yylloc, const char *file_name)
{
	char header[MAX_PACKAGE_NAME_LENGTH];	
	TLIBC_UNUSED(yylloc);

	generator_open(super, file_name, GENERATOR_READER_C_SUFFIX);

	generator_printline(super, 0, "/**");
    generator_printline(super, 0, " * Autogenerated by %s Compiler (%s)", PROJECT_NAME, VERSION);
    generator_printline(super, 0, " *");
    generator_printline(super, 0, " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING");
    generator_printline(super, 0, " *  @generated");
    generator_printline(super, 0, " */");
	generator_printline(super, 0, "");

	
	//包含header的头文件
	strncpy_notdir(header, file_name, MAX_PACKAGE_NAME_LENGTH - 1);
	generator_replace_extension(header, MAX_PACKAGE_NAME_LENGTH, GENERATOR_READER_H_SUFFIX);
	generator_printline(super, 0, "#include \"%s\"", header);

	generator_printline(super, 0, "#include <stdint.h>");
	generator_printline(super, 0, "#include <string.h>");

	generator_printline(super, 0, "");
	generator_printline(super, 0, "");
	return E_TD_NOERROR;
}
Ejemplo n.º 5
0
tlibc_error_code_t tlibc_csv_read_enum_begin(tlibc_abstract_reader_t *super, const char *enum_name)
{
	tlibc_csv_reader_t *self = TLIBC_CONTAINER_OF(super, tlibc_csv_reader_t, super);
	TLIBC_UNUSED(enum_name);

	self->read_enum_name_once = true;
	return E_TLIBC_NOERROR;
}
Ejemplo n.º 6
0
tlibc_error_code_t tlibc_csv_read_field_begin(tlibc_abstract_reader_t *super, const char *var_name)
{
	tlibc_csv_reader_t *self = TLIBC_CONTAINER_OF(super, tlibc_csv_reader_t, super);
	int32_t index;

	if(self->pre_read_uint32)
	{   
		return E_TLIBC_NOERROR;
	}   
	TLIBC_UNUSED(var_name);
	index = get_field_index(self, self->col);
	if((index < 0) || (index >= TLIBC_CSV_FIELD_NUM))
	{
		return E_TLIBC_NOT_FOUND;
	}
	self->field = self->cur_line_fields[index];

	return E_TLIBC_NOERROR;
}
Ejemplo n.º 7
0
tlibc_error_code_t tlibc_binary_write_string(tlibc_abstract_writer_t *super, const char* str, uint32_t str_length)
{
    tlibc_binary_writer_t *self = TLIBC_CONTAINER_OF(super, tlibc_binary_writer_t, super);
    uint32_t str_len = 0;
    tlibc_error_code_t ret= E_TLIBC_NOERROR;
    TLIBC_UNUSED(str_length);

    for(; self->offset < self->size; )
    {
        char c = (self->addr[self->offset++] = str[str_len++]);

        if(c == 0)
        {
            goto done;
        }
    }

    ret = E_TLIBC_OUT_OF_MEMORY;
done:
    return ret;
}
Ejemplo n.º 8
0
static error_code_t on_definition(generator_t *super, const YYLTYPE *yylloc, const syn_definition_t *definition)
{
	generator_reader_c_t *self = TLIBC_CONTAINER_OF(super, generator_reader_c_t, super);
	TLIBC_UNUSED(yylloc);
	switch(definition->type)
	{
		case E_DT_IMPORT:
			return _on_import(self, &definition->definition.de_import);				
		case E_DT_CONST:
			return E_TD_NOERROR;
		case E_DT_ENUM:
			return _on_enum(self, &definition->definition.de_enum);
		case E_DT_STRUCT:
			return _on_struct(self, &definition->definition.de_struct);
		case E_DT_UNION:
			return _on_union(self, &definition->definition.de_union);
		case E_DT_TYPEDEF:
			return E_TD_NOERROR;
		case E_DT_UNIX_COMMENT:
			return E_TD_NOERROR;
		default:
			return E_TD_ERROR;
	}
}