Style fixes in libruntime.

This commit is contained in:
Ruben Ayrapetyan
2014-08-12 14:16:05 +04:00
parent aa43e06366
commit b4a29f754a
11 changed files with 830 additions and 673 deletions
+26
View File
@@ -37,45 +37,71 @@ jerry_exit( jerry_status_t code) /**< status code */
switch (code) switch (code)
{ {
case ERR_OK: case ERR_OK:
{
JERRY_UNREACHABLE(); JERRY_UNREACHABLE();
break; break;
}
case ERR_IO: case ERR_IO:
{
__printf ("ERR_IO\n"); __printf ("ERR_IO\n");
break; break;
}
case ERR_BUFFER_SIZE: case ERR_BUFFER_SIZE:
{
__printf ("ERR_BUFFER_SIZE\n"); __printf ("ERR_BUFFER_SIZE\n");
break; break;
}
case ERR_SEVERAL_FILES: case ERR_SEVERAL_FILES:
{
__printf ("ERR_SEVERAL_FILES\n"); __printf ("ERR_SEVERAL_FILES\n");
break; break;
}
case ERR_NO_FILES: case ERR_NO_FILES:
{
__printf ("ERR_NO_FILES\n"); __printf ("ERR_NO_FILES\n");
break; break;
}
case ERR_NON_CHAR: case ERR_NON_CHAR:
{
__printf ("ERR_NON_CHAR\n"); __printf ("ERR_NON_CHAR\n");
break; break;
}
case ERR_UNCLOSED: case ERR_UNCLOSED:
{
__printf ("ERR_UNCLOSED\n"); __printf ("ERR_UNCLOSED\n");
break; break;
}
case ERR_INT_LITERAL: case ERR_INT_LITERAL:
{
__printf ("ERR_INT_LITERAL\n"); __printf ("ERR_INT_LITERAL\n");
break; break;
}
case ERR_STRING: case ERR_STRING:
{
__printf ("ERR_STRING\n"); __printf ("ERR_STRING\n");
break; break;
}
case ERR_PARSER: case ERR_PARSER:
{
__printf ("ERR_PARSER\n"); __printf ("ERR_PARSER\n");
break; break;
}
case ERR_MEMORY: case ERR_MEMORY:
{
__printf ("ERR_MEMORY\n"); __printf ("ERR_MEMORY\n");
break; break;
}
case ERR_SYSCALL: case ERR_SYSCALL:
{
JERRY_UNREACHABLE(); JERRY_UNREACHABLE();
break; break;
}
case ERR_GENERAL: case ERR_GENERAL:
{
__printf ("ERR_GENERAL\n"); __printf ("ERR_GENERAL\n");
break; break;
} }
}
/* The failed assertion is 'Return code is zero' */ /* The failed assertion is 'Return code is zero' */
jerry_assert_fail ("Return code is zero", __FILE__, __LINE__); jerry_assert_fail ("Return code is zero", __FILE__, __LINE__);
+71 -1
View File
@@ -208,42 +208,60 @@ libc_printf_write_d_i( _FILE *stream, /**< stream pointer */
switch (length) switch (length)
{ {
case LIBC_PRINTF_ARG_LENGTH_TYPE_NONE: case LIBC_PRINTF_ARG_LENGTH_TYPE_NONE:
{
value = (uintmax_t)va_arg (*args_list_p, int); value = (uintmax_t)va_arg (*args_list_p, int);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_HH: case LIBC_PRINTF_ARG_LENGTH_TYPE_HH:
{
value = (uintmax_t)va_arg (*args_list_p, int); /* char is promoted to int */ value = (uintmax_t)va_arg (*args_list_p, int); /* char is promoted to int */
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_H: case LIBC_PRINTF_ARG_LENGTH_TYPE_H:
{
value = (uintmax_t)va_arg (*args_list_p, int); /* short int is promoted to int */ value = (uintmax_t)va_arg (*args_list_p, int); /* short int is promoted to int */
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_L: case LIBC_PRINTF_ARG_LENGTH_TYPE_L:
{
value = (uintmax_t)va_arg (*args_list_p, long int); value = (uintmax_t)va_arg (*args_list_p, long int);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_LL: case LIBC_PRINTF_ARG_LENGTH_TYPE_LL:
{
value = (uintmax_t)va_arg (*args_list_p, long long int); value = (uintmax_t)va_arg (*args_list_p, long long int);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_J: case LIBC_PRINTF_ARG_LENGTH_TYPE_J:
{
value = (uintmax_t)va_arg (*args_list_p, intmax_t); value = (uintmax_t)va_arg (*args_list_p, intmax_t);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_Z: case LIBC_PRINTF_ARG_LENGTH_TYPE_Z:
{
is_signed = false; is_signed = false;
value = (uintmax_t)va_arg (*args_list_p, size_t); value = (uintmax_t)va_arg (*args_list_p, size_t);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_T: case LIBC_PRINTF_ARG_LENGTH_TYPE_T:
{
is_signed = false; is_signed = false;
value = (uintmax_t)va_arg (*args_list_p, ptrdiff_t); value = (uintmax_t)va_arg (*args_list_p, ptrdiff_t);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL: case LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL:
{
JERRY_UNREACHABLE(); JERRY_UNREACHABLE();
} }
}
if (is_signed) if (is_signed)
{ {
@@ -309,40 +327,58 @@ libc_printf_write_u_o_x_X( _FILE *stream, /**< stream pointer */
switch (length) switch (length)
{ {
case LIBC_PRINTF_ARG_LENGTH_TYPE_NONE: case LIBC_PRINTF_ARG_LENGTH_TYPE_NONE:
{
value = (uintmax_t)va_arg (*args_list_p, unsigned int); value = (uintmax_t)va_arg (*args_list_p, unsigned int);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_HH: case LIBC_PRINTF_ARG_LENGTH_TYPE_HH:
{
value = (uintmax_t)va_arg (*args_list_p, unsigned int); /* char is promoted to int */ value = (uintmax_t)va_arg (*args_list_p, unsigned int); /* char is promoted to int */
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_H: case LIBC_PRINTF_ARG_LENGTH_TYPE_H:
{
value = (uintmax_t)va_arg (*args_list_p, unsigned int); /* short int is promoted to int */ value = (uintmax_t)va_arg (*args_list_p, unsigned int); /* short int is promoted to int */
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_L: case LIBC_PRINTF_ARG_LENGTH_TYPE_L:
{
value = (uintmax_t)va_arg (*args_list_p, unsigned long int); value = (uintmax_t)va_arg (*args_list_p, unsigned long int);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_LL: case LIBC_PRINTF_ARG_LENGTH_TYPE_LL:
{
value = (uintmax_t)va_arg (*args_list_p, unsigned long long int); value = (uintmax_t)va_arg (*args_list_p, unsigned long long int);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_J: case LIBC_PRINTF_ARG_LENGTH_TYPE_J:
{
value = (uintmax_t)va_arg (*args_list_p, uintmax_t); value = (uintmax_t)va_arg (*args_list_p, uintmax_t);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_Z: case LIBC_PRINTF_ARG_LENGTH_TYPE_Z:
{
value = (uintmax_t)va_arg (*args_list_p, size_t); value = (uintmax_t)va_arg (*args_list_p, size_t);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_T: case LIBC_PRINTF_ARG_LENGTH_TYPE_T:
{
value = (uintmax_t)va_arg (*args_list_p, ptrdiff_t); value = (uintmax_t)va_arg (*args_list_p, ptrdiff_t);
break; break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL: case LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL:
{
JERRY_UNREACHABLE(); JERRY_UNREACHABLE();
} }
}
if (flags & LIBC_PRINTF_ARG_FLAG_SHARP) if (flags & LIBC_PRINTF_ARG_FLAG_SHARP)
{ {
@@ -371,28 +407,38 @@ libc_printf_write_u_o_x_X( _FILE *stream, /**< stream pointer */
switch (specifier) switch (specifier)
{ {
case 'u': case 'u':
{
alphabet = "0123456789"; alphabet = "0123456789";
radix = 10; radix = 10;
break; break;
}
case 'o': case 'o':
{
alphabet = "01234567"; alphabet = "01234567";
radix = 8; radix = 8;
break; break;
}
case 'x': case 'x':
{
alphabet = "0123456789abcdef"; alphabet = "0123456789abcdef";
radix = 16; radix = 16;
break; break;
}
case 'X': case 'X':
{
alphabet = "0123456789ABCDEF"; alphabet = "0123456789ABCDEF";
radix = 16; radix = 16;
break; break;
}
default: default:
{
JERRY_UNREACHABLE(); JERRY_UNREACHABLE();
} }
}
char str_buffer[ 32 ]; char str_buffer[ 32 ];
const char *string_p = libc_printf_uint_to_string (value, const char *string_p = libc_printf_uint_to_string (value,
@@ -508,6 +554,7 @@ __vfprintf( _FILE *stream, /**< stream pointer */
switch (*format_iter_p) switch (*format_iter_p)
{ {
case 'h': case 'h':
{
format_iter_p++; format_iter_p++;
if (*format_iter_p == 'h') if (*format_iter_p == 'h')
{ {
@@ -520,8 +567,10 @@ __vfprintf( _FILE *stream, /**< stream pointer */
length = LIBC_PRINTF_ARG_LENGTH_TYPE_H; length = LIBC_PRINTF_ARG_LENGTH_TYPE_H;
} }
break; break;
}
case 'l': case 'l':
{
format_iter_p++; format_iter_p++;
if (*format_iter_p == 'l') if (*format_iter_p == 'l')
{ {
@@ -534,41 +583,54 @@ __vfprintf( _FILE *stream, /**< stream pointer */
length = LIBC_PRINTF_ARG_LENGTH_TYPE_L; length = LIBC_PRINTF_ARG_LENGTH_TYPE_L;
} }
break; break;
}
case 'j': case 'j':
{
format_iter_p++; format_iter_p++;
length = LIBC_PRINTF_ARG_LENGTH_TYPE_J; length = LIBC_PRINTF_ARG_LENGTH_TYPE_J;
break; break;
}
case 'z': case 'z':
{
format_iter_p++; format_iter_p++;
length = LIBC_PRINTF_ARG_LENGTH_TYPE_Z; length = LIBC_PRINTF_ARG_LENGTH_TYPE_Z;
break; break;
}
case 't': case 't':
{
format_iter_p++; format_iter_p++;
length = LIBC_PRINTF_ARG_LENGTH_TYPE_T; length = LIBC_PRINTF_ARG_LENGTH_TYPE_T;
break; break;
}
case 'L': case 'L':
{
format_iter_p++; format_iter_p++;
length = LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL; length = LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL;
break; break;
} }
}
switch (*format_iter_p) switch (*format_iter_p)
{ {
case 'd': case 'd':
case 'i': case 'i':
{
libc_printf_write_d_i (stream, &args_copy, flags, length, width); libc_printf_write_d_i (stream, &args_copy, flags, length, width);
break; break;
}
case 'u': case 'u':
case 'o': case 'o':
case 'x': case 'x':
case 'X': case 'X':
{
libc_printf_write_u_o_x_X(stream, *format_iter_p, &args_copy, flags, length, width); libc_printf_write_u_o_x_X(stream, *format_iter_p, &args_copy, flags, length, width);
break; break;
}
case 'f': case 'f':
case 'F': case 'F':
@@ -578,10 +640,13 @@ __vfprintf( _FILE *stream, /**< stream pointer */
case 'G': case 'G':
case 'a': case 'a':
case 'A': case 'A':
{
JERRY_UNIMPLEMENTED(); JERRY_UNIMPLEMENTED();
break; break;
}
case 'c': case 'c':
{
if (length & LIBC_PRINTF_ARG_LENGTH_TYPE_L) if (length & LIBC_PRINTF_ARG_LENGTH_TYPE_L)
{ {
JERRY_UNIMPLEMENTED(); JERRY_UNIMPLEMENTED();
@@ -601,8 +666,10 @@ __vfprintf( _FILE *stream, /**< stream pointer */
flags & LIBC_PRINTF_ARG_FLAG_ZERO_PADDING); flags & LIBC_PRINTF_ARG_FLAG_ZERO_PADDING);
} }
break; break;
}
case 's': case 's':
{
if (length & LIBC_PRINTF_ARG_LENGTH_TYPE_L) if (length & LIBC_PRINTF_ARG_LENGTH_TYPE_L)
{ {
JERRY_UNIMPLEMENTED(); JERRY_UNIMPLEMENTED();
@@ -618,6 +685,7 @@ __vfprintf( _FILE *stream, /**< stream pointer */
flags & LIBC_PRINTF_ARG_FLAG_ZERO_PADDING); flags & LIBC_PRINTF_ARG_FLAG_ZERO_PADDING);
} }
break; break;
}
case 'p': case 'p':
{ {
@@ -639,14 +707,16 @@ __vfprintf( _FILE *stream, /**< stream pointer */
LIBC_PRINTF_ARG_LENGTH_TYPE_Z, LIBC_PRINTF_ARG_LENGTH_TYPE_Z,
width); width);
} }
}
break; break;
}
case 'n': case 'n':
{
JERRY_UNIMPLEMENTED(); JERRY_UNIMPLEMENTED();
break; break;
} }
} }
}
format_iter_p++; format_iter_p++;
} }
+35 -2
View File
@@ -124,7 +124,8 @@ __memcmp(const void *s1, /**< first area */
if (area1_p[ index ] < area2_p[ index ]) if (area1_p[ index ] < area2_p[ index ])
{ {
return -1; return -1;
} else if ( area1_p[ index ] > area2_p[ index ] ) }
else if (area1_p[ index ] > area2_p[ index ])
{ {
return 1; return 1;
} }
@@ -171,7 +172,8 @@ __memmove(void *s1, /**< destination */
{ {
dest_p[ index ] = src_p[ index ]; dest_p[ index ] = src_p[ index ];
} }
} else if ( dest_p > src_p ) }
else if (dest_p > src_p)
{ /* from end to begin */ { /* from end to begin */
for (size_t index = 1; index <= n; index++) for (size_t index = 1; index <= n; index++)
{ {
@@ -191,23 +193,35 @@ __strcmp (const char *s1, const char *s2)
if (s1 == NULL) if (s1 == NULL)
{ {
if (s2 != NULL) if (s2 != NULL)
{
return -1; return -1;
}
else else
{
return 0; return 0;
} }
}
if (s2 == NULL) if (s2 == NULL)
{
return 1; return 1;
}
for (i = 0; s1[i]; i++) for (i = 0; s1[i]; i++)
{ {
if (s1[i] > s2[i]) if (s1[i] > s2[i])
{
return 1; return 1;
}
else if (s1[i] < s2[i]) else if (s1[i] < s2[i])
{
return -1; return -1;
} }
}
if (s2[i]) if (s2[i])
{
return -1; return -1;
}
return 0; return 0;
} }
@@ -222,20 +236,30 @@ __strncmp (const char *s1, const char *s2, size_t n)
if (s1 == NULL) if (s1 == NULL)
{ {
if (s2 != NULL) if (s2 != NULL)
{
return -1; return -1;
}
else else
{
return 0; return 0;
} }
}
if (s2 == NULL) if (s2 == NULL)
{
return 1; return 1;
}
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
if (s1[i] > s2[i]) if (s1[i] > s2[i])
{
return 1; return 1;
}
else if (s1[i] < s2[i]) else if (s1[i] < s2[i])
{
return -1; return -1;
} }
}
return 0; return 0;
} }
@@ -252,8 +276,10 @@ __strncpy(char *dest, const char *src, size_t n)
{ {
dest[i] = src[i]; dest[i] = src[i];
if (src[i] == '\0') if (src[i] == '\0')
{
break; break;
} }
}
return dest; return dest;
} }
@@ -274,7 +300,10 @@ __strlen (const char *s)
{ {
size_t i; size_t i;
for (i = 0; s[i]; i++) for (i = 0; s[i]; i++)
{
; ;
}
return i; return i;
} }
@@ -291,11 +320,15 @@ __isspace (int c)
case '\r': case '\r':
case '\t': case '\t':
case '\v': case '\v':
{
return 1; return 1;
}
default: default:
{
return 0; return 0;
} }
} }
}
/** Checks for an uppercase letter. */ /** Checks for an uppercase letter. */
int int
+37 -9
View File
@@ -146,11 +146,11 @@ _FILE*
__fopen (const char *path, /**< file path */ __fopen (const char *path, /**< file path */
const char *mode) /**< file open mode */ const char *mode) /**< file open mode */
{ {
bool may_read = false, bool may_read = false;
may_write = false, bool may_write = false;
truncate = false, bool truncate = false;
create_if_not_exist = false, bool create_if_not_exist = false;
position_at_end = false; bool position_at_end = false;
JERRY_ASSERT(path != NULL && mode != NULL); JERRY_ASSERT(path != NULL && mode != NULL);
JERRY_ASSERT(mode[1] == '+' || mode[1] == '\0'); JERRY_ASSERT(mode[1] == '+' || mode[1] == '\0');
@@ -158,16 +158,21 @@ __fopen(const char *path, /**< file path */
switch (mode[0]) switch (mode[0])
{ {
case 'r': case 'r':
{
may_read = true; may_read = true;
may_write = (mode[1] == '+'); may_write = (mode[1] == '+');
break; break;
}
case 'w': case 'w':
{
may_write = true; may_write = true;
truncate = true; truncate = true;
create_if_not_exist = true; create_if_not_exist = true;
may_read = (mode[1] == '+'); may_read = (mode[1] == '+');
break; break;
}
case 'a': case 'a':
{
may_write = true; may_write = true;
position_at_end = true; position_at_end = true;
create_if_not_exist = true; create_if_not_exist = true;
@@ -176,9 +181,12 @@ __fopen(const char *path, /**< file path */
JERRY_UNIMPLEMENTED(); JERRY_UNIMPLEMENTED();
} }
break; break;
}
default: default:
{
JERRY_UNREACHABLE(); JERRY_UNREACHABLE();
} }
}
int flags = 0; int flags = 0;
int access = S_IRUSR | S_IWUSR; int access = S_IRUSR | S_IWUSR;
@@ -254,15 +262,21 @@ __fseek(_FILE * fp, /**< stream pointer */
switch (whence) switch (whence)
{ {
case __SEEK_SET: case __SEEK_SET:
{
whence_real = SEEK_SET; whence_real = SEEK_SET;
break; break;
}
case __SEEK_CUR: case __SEEK_CUR:
{
whence_real = SEEK_CUR; whence_real = SEEK_CUR;
break; break;
}
case __SEEK_END: case __SEEK_END:
{
whence_real = SEEK_END; whence_real = SEEK_END;
break; break;
} }
}
syscall_3 (__NR_lseek, (long int)fp, offset, whence_real); syscall_3 (__NR_lseek, (long int)fp, offset, whence_real);
@@ -296,10 +310,14 @@ __fread(void *ptr, /**< address of buffer to read to */
do do
{ {
ret = syscall_3( __NR_read, (long int)stream, (long int) ((uint8_t*)ptr + bytes_read), (long int) (size * nmemb - bytes_read)); ret = syscall_3 (__NR_read,
(long int) stream,
(long int) ((uint8_t*) ptr + bytes_read),
(long int) (size * nmemb - bytes_read));
bytes_read += (size_t)ret; bytes_read += (size_t)ret;
} while (bytes_read != size * nmemb && ret != 0); }
while (bytes_read != size * nmemb && ret != 0);
return bytes_read; return bytes_read;
} /* __fread */ } /* __fread */
@@ -319,10 +337,14 @@ __fwrite(const void *ptr, /**< data to write */
do do
{ {
long int ret = syscall_3( __NR_write, (long int)stream, (long int) ((uint8_t*)ptr + bytes_written), (long int) (size * nmemb - bytes_written)); long int ret = syscall_3 (__NR_write,
(long int) stream,
(long int) ((uint8_t*) ptr + bytes_written),
(long int) (size * nmemb - bytes_written));
bytes_written += (size_t)ret; bytes_written += (size_t)ret;
} while (bytes_written != size * nmemb); }
while (bytes_written != size * nmemb);
return bytes_written; return bytes_written;
} /* __fwrite */ } /* __fwrite */
@@ -396,15 +418,21 @@ __fseek(_FILE * fp, /**< stream pointer */
switch (whence) switch (whence)
{ {
case __SEEK_SET: case __SEEK_SET:
{
whence_real = SEEK_SET; whence_real = SEEK_SET;
break; break;
}
case __SEEK_CUR: case __SEEK_CUR:
{
whence_real = SEEK_CUR; whence_real = SEEK_CUR;
break; break;
}
case __SEEK_END: case __SEEK_END:
{
whence_real = SEEK_END; whence_real = SEEK_END;
break; break;
} }
}
return fseek (fp, offset, whence_real); return fseek (fp, offset, whence_real);
} /* __fseek */ } /* __fseek */