Replace vera++ with clang-format (#4518)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu
This commit is contained in:
@@ -17,30 +17,33 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
||||
#include <winbase.h>
|
||||
#include <winnt.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#if defined (__GNUC__) || defined (__clang__)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#include <sys/time.h>
|
||||
#endif /* __GNUC__ || __clang__ */
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
static const LONGLONG UnixEpochInTicks = 116444736000000000; /* difference between 1970 and 1601 */
|
||||
static const LONGLONG TicksPerMs = 10000; /* 1 tick is 100 nanoseconds */
|
||||
|
||||
/* https://support.microsoft.com/en-us/help/167296/how-to-convert-a-unix-time-t-to-a-win32-filetime-or-systemtime */
|
||||
static void UnixTimeMsToFileTime (double t, LPFILETIME pft)
|
||||
static void
|
||||
UnixTimeMsToFileTime (double t, LPFILETIME pft)
|
||||
{
|
||||
LONGLONG ll = (LONGLONG) t * TicksPerMs + UnixEpochInTicks;
|
||||
pft->dwLowDateTime = (DWORD) ll;
|
||||
pft->dwHighDateTime = (DWORD) (ll >> 32);
|
||||
} /* UnixTimeMsToFileTime */
|
||||
|
||||
static double FileTimeToUnixTimeMs (FILETIME ft)
|
||||
static double
|
||||
FileTimeToUnixTimeMs (FILETIME ft)
|
||||
{
|
||||
ULARGE_INTEGER date;
|
||||
date.HighPart = ft.dwHighDateTime;
|
||||
@@ -56,10 +59,11 @@ static double FileTimeToUnixTimeMs (FILETIME ft)
|
||||
* @return offset between UTC and local time at the given unix timestamp, if
|
||||
* available. Otherwise, returns 0, assuming UTC time.
|
||||
*/
|
||||
double jerry_port_get_local_time_zone_adjustment (double unix_ms, /**< ms since unix epoch */
|
||||
bool is_utc) /**< is the time above in UTC? */
|
||||
double
|
||||
jerry_port_get_local_time_zone_adjustment (double unix_ms, /**< ms since unix epoch */
|
||||
bool is_utc) /**< is the time above in UTC? */
|
||||
{
|
||||
#if defined (HAVE_TM_GMTOFF)
|
||||
#if defined(HAVE_TM_GMTOFF)
|
||||
struct tm tm;
|
||||
time_t now = (time_t) (unix_ms / 1000);
|
||||
localtime_r (&now, &tm);
|
||||
@@ -71,7 +75,7 @@ double jerry_port_get_local_time_zone_adjustment (double unix_ms, /**< ms since
|
||||
}
|
||||
|
||||
return ((double) tm.tm_gmtoff) * 1000;
|
||||
#elif defined (_WIN32)
|
||||
#elif defined(_WIN32)
|
||||
FILETIME fileTime, localFileTime;
|
||||
SYSTEMTIME systemTime, localSystemTime;
|
||||
ULARGE_INTEGER time, localTime;
|
||||
@@ -95,7 +99,7 @@ double jerry_port_get_local_time_zone_adjustment (double unix_ms, /**< ms since
|
||||
return (double) (((LONGLONG) localTime.QuadPart - (LONGLONG) time.QuadPart) / TicksPerMs);
|
||||
}
|
||||
return 0.0;
|
||||
#elif defined (__GNUC__) || defined (__clang__)
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
time_t now_time = (time_t) (unix_ms / 1000);
|
||||
double tza_s = 0.0;
|
||||
|
||||
@@ -138,13 +142,14 @@ double jerry_port_get_local_time_zone_adjustment (double unix_ms, /**< ms since
|
||||
* executed successfully,
|
||||
* 0 - otherwise.
|
||||
*/
|
||||
double jerry_port_get_current_time (void)
|
||||
double
|
||||
jerry_port_get_current_time (void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FILETIME ft;
|
||||
GetSystemTimeAsFileTime (&ft);
|
||||
return FileTimeToUnixTimeMs (ft);
|
||||
#elif defined (__GNUC__) || defined (__clang__)
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
struct timeval tv;
|
||||
|
||||
if (gettimeofday (&tv, NULL) == 0)
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if !defined (_XOPEN_SOURCE) || _XOPEN_SOURCE < 500
|
||||
#if !defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 500
|
||||
#undef _XOPEN_SOURCE
|
||||
/* Required macro for sleep functions (nanosleep or usleep) */
|
||||
#define _XOPEN_SOURCE 500
|
||||
#endif
|
||||
#endif /* !(defined(_XOPEN_SOURCE) || _XOPEN_SOURCE < 500) */
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@@ -25,14 +25,15 @@
|
||||
#include <unistd.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
/**
|
||||
* Default implementation of jerry_port_sleep. Uses 'usleep' if available on the
|
||||
* system, does nothing otherwise.
|
||||
*/
|
||||
void jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
|
||||
void
|
||||
jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep (sleep_time);
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
/**
|
||||
* Pointer to the current context.
|
||||
|
||||
@@ -15,17 +15,17 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
/**
|
||||
* Default implementation of jerry_port_fatal. Calls 'abort' if exit code is
|
||||
* non-zero, 'exit' otherwise.
|
||||
*/
|
||||
void jerry_port_fatal (jerry_fatal_code_t code) /**< cause of error */
|
||||
void
|
||||
jerry_port_fatal (jerry_fatal_code_t code) /**< cause of error */
|
||||
{
|
||||
if (code != 0
|
||||
&& code != ERR_OUT_OF_MEMORY)
|
||||
if (code != 0 && code != ERR_OUT_OF_MEMORY)
|
||||
{
|
||||
abort ();
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-debugger.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
/**
|
||||
* Actual log level
|
||||
@@ -57,13 +57,13 @@ jerry_port_default_set_log_level (jerry_log_level_t level) /**< log level */
|
||||
void
|
||||
jerry_port_log (jerry_log_level_t level, /**< message log level */
|
||||
const char *format, /**< format string */
|
||||
...) /**< parameters */
|
||||
...) /**< parameters */
|
||||
{
|
||||
if (level <= jerry_port_default_log_level)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
#if defined(JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
int length = vsnprintf (NULL, 0, format, args);
|
||||
va_end (args);
|
||||
va_start (args, format);
|
||||
@@ -80,7 +80,7 @@ jerry_port_log (jerry_log_level_t level, /**< message log level */
|
||||
}
|
||||
} /* jerry_port_log */
|
||||
|
||||
#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
#if defined(JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
|
||||
#define DEBUG_BUFFER_SIZE (256)
|
||||
static char debug_buffer[DEBUG_BUFFER_SIZE];
|
||||
@@ -97,7 +97,7 @@ jerry_port_print_char (char c) /**< the character to print */
|
||||
{
|
||||
putchar (c);
|
||||
|
||||
#if defined (JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
#if defined(JERRY_DEBUGGER) && (JERRY_DEBUGGER == 1)
|
||||
debug_buffer[debug_buffer_index++] = c;
|
||||
|
||||
if ((debug_buffer_index == DEBUG_BUFFER_SIZE) || (c == '\n'))
|
||||
|
||||
@@ -17,14 +17,15 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jerryscript-port-default.h"
|
||||
#include "jerryscript-port.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
#define S_ISDIR(mode) (((mode) &S_IFMT) == S_IFDIR)
|
||||
#endif /* !defined(S_ISDIR) */
|
||||
|
||||
/**
|
||||
* Determines the size of the given file.
|
||||
@@ -112,7 +113,7 @@ jerry_port_get_directory_end (const jerry_char_t *path_p) /**< path */
|
||||
|
||||
while (end_p > path_p)
|
||||
{
|
||||
#if defined (_WIN32)
|
||||
#if defined(_WIN32)
|
||||
if (end_p[-1] == '/' || end_p[-1] == '\\')
|
||||
{
|
||||
return (size_t) (end_p - path_p);
|
||||
@@ -170,7 +171,7 @@ jerry_port_normalize_path (const jerry_char_t *in_path_p, /**< path to the refer
|
||||
path_p[in_path_length] = '\0';
|
||||
}
|
||||
|
||||
#if defined (_WIN32)
|
||||
#if defined(_WIN32)
|
||||
char full_path[_MAX_PATH];
|
||||
|
||||
if (_fullpath (full_path, path_p, _MAX_PATH) != NULL)
|
||||
@@ -188,7 +189,7 @@ jerry_port_normalize_path (const jerry_char_t *in_path_p, /**< path to the refer
|
||||
|
||||
memcpy (path_p, full_path, full_path_len + 1);
|
||||
}
|
||||
#elif defined (__unix__) || defined (__APPLE__)
|
||||
#elif defined(__unix__) || defined(__APPLE__)
|
||||
char *norm_p = realpath (path_p, NULL);
|
||||
|
||||
if (norm_p != NULL)
|
||||
@@ -216,8 +217,7 @@ typedef struct jerry_port_module_t
|
||||
/**
|
||||
* Native info descriptor for modules.
|
||||
*/
|
||||
static const jerry_object_native_info_t jerry_port_module_native_info =
|
||||
{
|
||||
static const jerry_object_native_info_t jerry_port_module_native_info = {
|
||||
.free_cb = NULL,
|
||||
};
|
||||
|
||||
@@ -296,12 +296,10 @@ jerry_port_module_manager_deinit (void *user_data_p) /**< context pointer to dei
|
||||
/**
|
||||
* Declare the context data manager for modules.
|
||||
*/
|
||||
static const jerry_context_data_manager_t jerry_port_module_manager =
|
||||
{
|
||||
.init_cb = jerry_port_module_manager_init,
|
||||
.deinit_cb = jerry_port_module_manager_deinit,
|
||||
.bytes_needed = sizeof (jerry_port_module_manager_t)
|
||||
};
|
||||
static const jerry_context_data_manager_t jerry_port_module_manager = { .init_cb = jerry_port_module_manager_init,
|
||||
.deinit_cb = jerry_port_module_manager_deinit,
|
||||
.bytes_needed =
|
||||
sizeof (jerry_port_module_manager_t) };
|
||||
|
||||
/**
|
||||
* Default module resolver.
|
||||
@@ -346,8 +344,7 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier
|
||||
|
||||
while (module_p != NULL)
|
||||
{
|
||||
if (module_p->realm == realm
|
||||
&& strcmp ((const char *) module_p->path_p, (const char *) path_p) == 0)
|
||||
if (module_p->realm == realm && strcmp ((const char *) module_p->path_p, (const char *) path_p) == 0)
|
||||
{
|
||||
free (path_p);
|
||||
free (in_path_p);
|
||||
@@ -375,9 +372,7 @@ jerry_port_module_resolve (const jerry_value_t specifier, /**< module specifier
|
||||
parse_options.options = JERRY_PARSE_MODULE | JERRY_PARSE_HAS_RESOURCE;
|
||||
parse_options.resource_name = jerry_create_string_sz ((const jerry_char_t *) in_path_p, in_path_length);
|
||||
|
||||
jerry_value_t ret_value = jerry_parse (source_p,
|
||||
source_size,
|
||||
&parse_options);
|
||||
jerry_value_t ret_value = jerry_parse (source_p, source_size, &parse_options);
|
||||
jerry_release_value (parse_options.resource_name);
|
||||
|
||||
jerry_port_release_source (source_p);
|
||||
@@ -411,6 +406,5 @@ void
|
||||
jerry_port_module_release (const jerry_value_t realm) /**< if this argument is object, release only those modules,
|
||||
* which realm value is equal to this argument. */
|
||||
{
|
||||
jerry_port_module_free ((jerry_port_module_manager_t *) jerry_get_context_data (&jerry_port_module_manager),
|
||||
realm);
|
||||
jerry_port_module_free ((jerry_port_module_manager_t *) jerry_get_context_data (&jerry_port_module_manager), realm);
|
||||
} /* jerry_port_module_release */
|
||||
|
||||
@@ -18,13 +18,10 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "jerryscript.h"
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_BEGIN
|
||||
|
||||
/** \addtogroup jerry_port_default Default Jerry engine port API
|
||||
* These functions are only available if the default port of Jerry is used.
|
||||
@@ -40,7 +37,6 @@ void jerry_port_default_set_current_context (jerry_context_t *context_p);
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
JERRY_C_API_END
|
||||
|
||||
#endif /* !JERRYSCRIPT_PORT_DEFAULT_H */
|
||||
|
||||
Reference in New Issue
Block a user