diff options
Diffstat (limited to 'src')
37 files changed, 190 insertions, 202 deletions
diff --git a/src/apply-names.cc b/src/apply-names.cc index d8c9680d..76662fee 100644 --- a/src/apply-names.cc +++ b/src/apply-names.cc @@ -57,10 +57,10 @@ static WabtLabel* find_label_by_var(Context* ctx, WabtVar* var) { if (wabt_string_slices_are_equal(label, &var->name)) return label; } - return NULL; + return nullptr; } else { if (var->index < 0 || (size_t)var->index >= ctx->labels.size) - return NULL; + return nullptr; return ctx->labels.data[ctx->labels.size - 1 - var->index]; } } @@ -78,7 +78,7 @@ static void use_name_for_var(WabtStringSlice* name, WabtVar* var) { static WabtResult use_name_for_func_type_var(WabtModule* module, WabtVar* var) { WabtFuncType* func_type = wabt_get_func_type_by_var(module, var); - if (func_type == NULL) + if (!func_type) return WABT_ERROR; use_name_for_var(&func_type->name, var); return WABT_OK; @@ -86,7 +86,7 @@ static WabtResult use_name_for_func_type_var(WabtModule* module, WabtVar* var) { static WabtResult use_name_for_func_var(WabtModule* module, WabtVar* var) { WabtFunc* func = wabt_get_func_by_var(module, var); - if (func == NULL) + if (!func) return WABT_ERROR; use_name_for_var(&func->name, var); return WABT_OK; @@ -94,7 +94,7 @@ static WabtResult use_name_for_func_var(WabtModule* module, WabtVar* var) { static WabtResult use_name_for_global_var(WabtModule* module, WabtVar* var) { WabtGlobal* global = wabt_get_global_by_var(module, var); - if (global == NULL) + if (!global) return WABT_ERROR; use_name_for_var(&global->name, var); return WABT_OK; @@ -102,7 +102,7 @@ static WabtResult use_name_for_global_var(WabtModule* module, WabtVar* var) { static WabtResult use_name_for_table_var(WabtModule* module, WabtVar* var) { WabtTable* table = wabt_get_table_by_var(module, var); - if (table == NULL) + if (!table) return WABT_ERROR; use_name_for_var(&table->name, var); return WABT_OK; @@ -110,7 +110,7 @@ static WabtResult use_name_for_table_var(WabtModule* module, WabtVar* var) { static WabtResult use_name_for_memory_var(WabtModule* module, WabtVar* var) { WabtMemory* memory = wabt_get_memory_by_var(module, var); - if (memory == NULL) + if (!memory) return WABT_ERROR; use_name_for_var(&memory->name, var); return WABT_OK; @@ -145,7 +145,7 @@ static WabtResult use_name_for_param_and_local_var(Context* ctx, if (name->start) { var->type = WABT_VAR_TYPE_NAME; var->name = wabt_dup_string_slice(*name); - return var->name.start != NULL ? WABT_OK : WABT_ERROR; + return var->name.start ? WABT_OK : WABT_ERROR; } return WABT_OK; } @@ -277,7 +277,7 @@ static WabtResult visit_func(Context* ctx, &func->local_types, &func->local_bindings, &ctx->local_index_to_name); CHECK_RESULT(wabt_visit_func(func, &ctx->visitor)); - ctx->current_func = NULL; + ctx->current_func = nullptr; return WABT_OK; } diff --git a/src/ast-lexer.cc b/src/ast-lexer.cc index 07f3c425..07fef8ee 100644 --- a/src/ast-lexer.cc +++ b/src/ast-lexer.cc @@ -114,7 +114,7 @@ static WabtResult fill(WabtLocation* loc, /* TODO(binji): could just alloc instead, because we know we'll need to * memmove below */ char* new_buffer = (char*)wabt_realloc(lexer->buffer, new_buffer_size); - if (new_buffer == NULL) { + if (!new_buffer) { wabt_ast_parser_error(loc, lexer, parser, "unable to reallocate lexer buffer."); return WABT_ERROR; @@ -480,7 +480,7 @@ WabtAstLexer* wabt_new_ast_file_lexer(const char* filename) { lexer->source.file = fopen(filename, "rb"); if (!lexer->source.file) { wabt_destroy_ast_lexer(lexer); - return NULL; + return nullptr; } return lexer; } diff --git a/src/ast-parser-lexer-shared.cc b/src/ast-parser-lexer-shared.cc index 8e5ef684..b7e7ffa9 100644 --- a/src/ast-parser-lexer-shared.cc +++ b/src/ast-parser-lexer-shared.cc @@ -47,7 +47,7 @@ void wabt_ast_format_error(WabtSourceErrorHandler* error_handler, len = wabt_vsnprintf(buffer, len + 1, format, args_copy); } - char* source_line = NULL; + char* source_line = nullptr; size_t source_line_length = 0; int source_line_column_offset = 0; size_t source_line_max_length = error_handler->source_line_max_length; diff --git a/src/ast-parser.y b/src/ast-parser.y index 16315080..abc2c640 100644 --- a/src/ast-parser.y +++ b/src/ast-parser.y @@ -61,7 +61,7 @@ (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \ (Current).last_column = YYRHSLOC(Rhs, N).last_column; \ } else { \ - (Current).filename = NULL; \ + (Current).filename = nullptr; \ (Current).line = YYRHSLOC(Rhs, 0).line; \ (Current).first_column = (Current).last_column = \ YYRHSLOC(Rhs, 0).last_column; \ @@ -305,20 +305,20 @@ non_empty_text_list : TEXT { WabtTextListNode* node = new_text_list_node(); DUPTEXT(node->text, $1); - node->next = NULL; + node->next = nullptr; $$.first = $$.last = node; } | non_empty_text_list TEXT { $$ = $1; WabtTextListNode* node = new_text_list_node(); DUPTEXT(node->text, $2); - node->next = NULL; + node->next = nullptr; $$.last->next = node; $$.last = node; } ; text_list : - /* empty */ { $$.first = $$.last = NULL; } + /* empty */ { $$.first = $$.last = nullptr; } | non_empty_text_list ; @@ -326,7 +326,7 @@ quoted_text : TEXT { WabtTextListNode node; node.text = $1; - node.next = NULL; + node.next = nullptr; WabtTextList text_list; text_list.first = &node; text_list.last = &node; @@ -747,7 +747,7 @@ func_body : $$ = new_func_field(); $$->type = WABT_FUNC_FIELD_TYPE_EXPRS; $$->first_expr = $1.first; - $$->next = NULL; + $$->next = nullptr; } | LPAR LOCAL value_type_list RPAR func_body { $$ = new_func_field(); @@ -1460,7 +1460,7 @@ script : size_t i; for (i = 0; i < $$.commands.size; ++i) { WabtCommand* command = &$$.commands.data[i]; - WabtVar* module_var = NULL; + WabtVar* module_var = nullptr; switch (command->type) { case WABT_COMMAND_TYPE_MODULE: { last_module_index = i; diff --git a/src/ast-writer.cc b/src/ast-writer.cc index 58f220f4..3acc26ae 100644 --- a/src/ast-writer.cc +++ b/src/ast-writer.cc @@ -83,22 +83,22 @@ static void write_indent(Context* ctx) { static size_t s_indent_len = sizeof(s_indent) - 1; size_t indent = ctx->indent; while (indent > s_indent_len) { - wabt_write_data(&ctx->stream, s_indent, s_indent_len, NULL); + wabt_write_data(&ctx->stream, s_indent, s_indent_len, nullptr); indent -= s_indent_len; } if (indent > 0) { - wabt_write_data(&ctx->stream, s_indent, indent, NULL); + wabt_write_data(&ctx->stream, s_indent, indent, nullptr); } } static void write_next_char(Context* ctx) { switch (ctx->next_char) { case NEXT_CHAR_SPACE: - wabt_write_data(&ctx->stream, " ", 1, NULL); + wabt_write_data(&ctx->stream, " ", 1, nullptr); break; case NEXT_CHAR_NEWLINE: case NEXT_CHAR_FORCE_NEWLINE: - wabt_write_data(&ctx->stream, "\n", 1, NULL); + wabt_write_data(&ctx->stream, "\n", 1, nullptr); write_indent(ctx); break; @@ -113,7 +113,7 @@ static void write_data_with_next_char(Context* ctx, const void* src, size_t size) { write_next_char(ctx); - wabt_write_data(&ctx->stream, src, size, NULL); + wabt_write_data(&ctx->stream, src, size, nullptr); } static void WABT_PRINTF_FORMAT(2, 3) @@ -125,7 +125,7 @@ static void WABT_PRINTF_FORMAT(2, 3) } static void write_putc(Context* ctx, char c) { - wabt_write_data(&ctx->stream, &c, 1, NULL); + wabt_write_data(&ctx->stream, &c, 1, nullptr); } static void write_puts(Context* ctx, const char* s, NextChar next_char) { @@ -189,7 +189,7 @@ static bool write_string_slice_opt(Context* ctx, NextChar next_char) { if (str->start) write_string_slice(ctx, str, next_char); - return str->start != NULL; + return !!str->start; } static void write_string_slice_or_index(Context* ctx, @@ -250,7 +250,7 @@ static void write_br_var(Context* ctx, const WabtVar* var, NextChar next_char) { static void write_type(Context* ctx, WabtType type, NextChar next_char) { const char* type_name = wabt_get_type_name(type); - assert(type_name != NULL); + assert(type_name); write_puts(ctx, type_name, next_char); } @@ -284,7 +284,7 @@ static void write_begin_block(Context* ctx, write_puts_space(ctx, text); bool has_label = write_string_slice_opt(ctx, &block->label, NEXT_CHAR_SPACE); - write_types(ctx, &block->sig, NULL); + write_types(ctx, &block->sig, nullptr); if (!has_label) writef(ctx, " ;; label = @%d", ctx->depth); write_newline(ctx, FORCE_NEWLINE); @@ -538,7 +538,7 @@ static void write_type_bindings(Context* ctx, } const WabtStringSlice* name = &ctx->index_to_name.data[i]; - bool has_name = name->start != NULL; + bool has_name = !!name->start; if (has_name) write_string_slice(ctx, name, NEXT_CHAR_SPACE); write_type(ctx, types->data[i], NEXT_CHAR_SPACE); @@ -704,7 +704,7 @@ static void write_start_function(Context* ctx, const WabtVar* start) { static void write_module(Context* ctx, const WabtModule* module) { write_open_newline(ctx, "module"); const WabtModuleField* field; - for (field = module->first_field; field != NULL; field = field->next) { + for (field = module->first_field; field; field = field->next) { switch (field->type) { case WABT_MODULE_FIELD_TYPE_FUNC: write_func(ctx, module, &field->func); @@ -747,7 +747,7 @@ WabtResult wabt_write_ast(WabtWriter* writer, const WabtModule* module) { Context ctx; WABT_ZERO_MEMORY(ctx); ctx.result = WABT_OK; - wabt_init_stream(&ctx.stream, writer, NULL); + wabt_init_stream(&ctx.stream, writer, nullptr); write_module(&ctx, module); /* the memory for the actual string slice is shared with the module, so we * only need to free the vector */ @@ -29,7 +29,7 @@ WabtExportPtr wabt_get_export_by_name(const WabtModule* module, const WabtStringSlice* name) { int index = wabt_find_binding_index_by_name(&module->export_bindings, name); if (index == -1) - return NULL; + return nullptr; return module->exports.data[index]; } @@ -78,7 +78,7 @@ int wabt_get_module_index_by_var(const WabtScript* script, const WabtVar* var) { WabtFuncPtr wabt_get_func_by_var(const WabtModule* module, const WabtVar* var) { int index = wabt_get_index_from_var(&module->func_bindings, var); if (index < 0 || (size_t)index >= module->funcs.size) - return NULL; + return nullptr; return module->funcs.data[index]; } @@ -86,7 +86,7 @@ WabtGlobalPtr wabt_get_global_by_var(const WabtModule* module, const WabtVar* var) { int index = wabt_get_index_from_var(&module->global_bindings, var); if (index < 0 || (size_t)index >= module->globals.size) - return NULL; + return nullptr; return module->globals.data[index]; } @@ -94,7 +94,7 @@ WabtTablePtr wabt_get_table_by_var(const WabtModule* module, const WabtVar* var) { int index = wabt_get_index_from_var(&module->table_bindings, var); if (index < 0 || (size_t)index >= module->tables.size) - return NULL; + return nullptr; return module->tables.data[index]; } @@ -102,7 +102,7 @@ WabtMemoryPtr wabt_get_memory_by_var(const WabtModule* module, const WabtVar* var) { int index = wabt_get_index_from_var(&module->memory_bindings, var); if (index < 0 || (size_t)index >= module->memories.size) - return NULL; + return nullptr; return module->memories.data[index]; } @@ -110,7 +110,7 @@ WabtFuncTypePtr wabt_get_func_type_by_var(const WabtModule* module, const WabtVar* var) { int index = wabt_get_index_from_var(&module->func_type_bindings, var); if (index < 0 || (size_t)index >= module->func_types.size) - return NULL; + return nullptr; return module->func_types.data[index]; } @@ -139,14 +139,14 @@ WabtModule* wabt_get_first_module(const WabtScript* script) { if (command->type == WABT_COMMAND_TYPE_MODULE) return &command->module; } - return NULL; + return nullptr; } WabtModule* wabt_get_module_by_var(const WabtScript* script, const WabtVar* var) { int index = wabt_get_index_from_var(&script->module_bindings, var); if (index < 0 || (size_t)index >= script->commands.size) - return NULL; + return nullptr; WabtCommand* command = &script->commands.data[index]; assert(command->type == WABT_COMMAND_TYPE_MODULE); return &command->module; @@ -184,7 +184,7 @@ void wabt_find_duplicate_bindings(const WabtBindingHash* bindings, continue; /* only follow the chain if this is the first entry in the chain */ - if (entry->prev != NULL) + if (entry->prev) continue; WabtBindingHashEntry* a = entry; @@ -457,7 +457,7 @@ void wabt_destroy_module(WabtModule* module) { wabt_destroy_string_slice(&module->name); WabtModuleField* field = module->first_field; - while (field != NULL) { + while (field) { WabtModuleField* next_field = field->next; destroy_module_field(field); wabt_free(field); @@ -585,7 +585,7 @@ static WABT_INLINE const WabtLocation* wabt_get_raw_module_location( case WABT_RAW_MODULE_TYPE_TEXT: return &raw->text->loc; default: assert(0); - return NULL; + return nullptr; } } diff --git a/src/binary-reader-ast.cc b/src/binary-reader-ast.cc index 89ede529..3552c998 100644 --- a/src/binary-reader-ast.cc +++ b/src/binary-reader-ast.cc @@ -63,7 +63,7 @@ static void push_label(Context* ctx, LabelNode label; label.label_type = label_type; label.first = first; - label.last = NULL; + label.last = nullptr; ctx->max_depth++; wabt_append_label_node_value(&ctx->label_stack, &label); } @@ -388,7 +388,7 @@ static WabtResult begin_global_init_expr(uint32_t index, void* user_data) { static WabtResult end_global_init_expr(uint32_t index, void* user_data) { Context* ctx = (Context*)user_data; - ctx->current_init_expr = NULL; + ctx->current_init_expr = nullptr; return WABT_OK; } @@ -598,7 +598,7 @@ static WabtResult on_else_expr(void* user_data) { label->label_type = WABT_LABEL_TYPE_ELSE; label->first = &parent_label->last->if_.false_; - label->last = NULL; + label->last = nullptr; return WABT_OK; } @@ -773,7 +773,7 @@ static WabtResult on_unreachable_expr(void* user_data) { static WabtResult end_function_body(uint32_t index, void* user_data) { Context* ctx = (Context*)user_data; CHECK_RESULT(pop_label(ctx)); - ctx->current_func = NULL; + ctx->current_func = nullptr; return WABT_OK; } @@ -815,7 +815,7 @@ static WabtResult begin_elem_segment_init_expr(uint32_t index, static WabtResult end_elem_segment_init_expr(uint32_t index, void* user_data) { Context* ctx = (Context*)user_data; - ctx->current_init_expr = NULL; + ctx->current_init_expr = nullptr; return WABT_OK; } @@ -879,7 +879,7 @@ static WabtResult begin_data_segment_init_expr(uint32_t index, static WabtResult end_data_segment_init_expr(uint32_t index, void* user_data) { Context* ctx = (Context*)user_data; - ctx->current_init_expr = NULL; + ctx->current_init_expr = nullptr; return WABT_OK; } diff --git a/src/binary-reader-interpreter.cc b/src/binary-reader-interpreter.cc index b325e1f3..ceff1454 100644 --- a/src/binary-reader-interpreter.cc +++ b/src/binary-reader-interpreter.cc @@ -1044,7 +1044,7 @@ static WabtResult end_function_body(uint32_t index, void* user_data) { CHECK_RESULT(emit_drop_keep(ctx, drop_count, keep_count)); CHECK_RESULT(emit_opcode(ctx, WABT_OPCODE_RETURN)); pop_label(ctx); - ctx->current_func = NULL; + ctx->current_func = nullptr; return WABT_OK; } @@ -1578,7 +1578,7 @@ WabtResult wabt_read_binary_interpreter(WabtInterpreterEnvironment* env, *out_module = module; } else { wabt_reset_interpreter_environment_to_mark(env, mark); - *out_module = NULL; + *out_module = nullptr; } destroy_context(&ctx); return result; diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index 18173e81..50eb9df5 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -99,7 +99,8 @@ static WabtResult begin_section(WabtBinaryReaderContext* ctx, if (section_match) { printf("\nContents of section %s:\n", name); wabt_write_memory_dump(context->out_stream, context->data + ctx->offset, - size, ctx->offset, WABT_PRINT_CHARS, NULL, NULL); + size, ctx->offset, WABT_PRINT_CHARS, nullptr, + nullptr); } break; case WABT_DUMP_DISASSEMBLE: @@ -259,7 +260,7 @@ static void log_opcode(Context* ctx, static WabtResult on_opcode_bare(WabtBinaryReaderContext* ctx) { Context* context = (Context*)ctx->user_data; - log_opcode(context, ctx->data, 0, NULL); + log_opcode(context, ctx->data, 0, nullptr); return WABT_OK; } @@ -315,7 +316,7 @@ WabtResult on_br_table_expr(WabtBinaryReaderContext* ctx, Context* context = (Context*)ctx->user_data; size_t immediate_len = ctx->offset - context->current_opcode_offset; /* TODO(sbc): Print targets */ - log_opcode(context, ctx->data, immediate_len, NULL); + log_opcode(context, ctx->data, immediate_len, nullptr); return WABT_OK; } @@ -323,7 +324,7 @@ static WabtResult on_end_expr(void* user_data) { Context* context = (Context*)user_data; context->indent_level--; assert(context->indent_level >= 0); - log_opcode(context, NULL, 0, NULL); + log_opcode(context, nullptr, 0, nullptr); return WABT_OK; } @@ -354,7 +355,7 @@ static WabtResult on_opcode_block_sig(WabtBinaryReaderContext* ctx, if (num_types) log_opcode(context, ctx->data, 1, "%s", wabt_type_name(*sig_types)); else - log_opcode(context, ctx->data, 1, NULL); + log_opcode(context, ctx->data, 1, nullptr); context->indent_level++; return WABT_OK; } @@ -653,7 +654,7 @@ static WabtResult on_data_segment_data(uint32_t index, Context* ctx = (Context*)user_data; if (should_print_details(ctx)) { wabt_write_memory_dump(ctx->out_stream, src_data, size, 0, WABT_PRINT_CHARS, - " - ", NULL); + " - ", nullptr); } return WABT_OK; } diff --git a/src/binary-reader.cc b/src/binary-reader.cc index 704886ad..8485d0d5 100644 --- a/src/binary-reader.cc +++ b/src/binary-reader.cc @@ -448,11 +448,11 @@ static void write_indent(LoggingContext* ctx) { static size_t s_indent_len = sizeof(s_indent) - 1; size_t indent = ctx->indent; while (indent > s_indent_len) { - wabt_write_data(ctx->stream, s_indent, s_indent_len, NULL); + wabt_write_data(ctx->stream, s_indent, s_indent_len, nullptr); indent -= s_indent_len; } if (indent > 0) { - wabt_write_data(ctx->stream, s_indent, indent, NULL); + wabt_write_data(ctx->stream, s_indent, indent, nullptr); } } diff --git a/src/binary-reader.h b/src/binary-reader.h index 6e4b929f..dab830d5 100644 --- a/src/binary-reader.h +++ b/src/binary-reader.h @@ -24,7 +24,7 @@ #include "common.h" #define WABT_READ_BINARY_OPTIONS_DEFAULT \ - { NULL, false } + { nullptr, false } typedef struct WabtReadBinaryOptions { struct WabtStream* log_stream; diff --git a/src/binary-writer-spec.cc b/src/binary-writer-spec.cc index 5dd3e2fe..19e61c62 100644 --- a/src/binary-writer-spec.cc +++ b/src/binary-writer-spec.cc @@ -52,16 +52,16 @@ static WabtStringSlice strip_extension(const char* s) { * s = "foo.wasm" => "foo" * s = "foo.bar" => "foo.bar" */ - if (s == NULL) { + if (!s) { WabtStringSlice result; - result.start = NULL; + result.start = nullptr; result.length = 0; return result; } size_t slen = strlen(s); const char* ext_start = strrchr(s, '.'); - if (ext_start == NULL) + if (!ext_start) ext_start = s + slen; WabtStringSlice result; @@ -85,7 +85,7 @@ static WabtStringSlice get_basename(const char* s) { size_t slen = strlen(s); const char* start = s; const char* last_slash = strrchr(s, '/'); - if (last_slash != NULL) + if (last_slash) start = last_slash + 1; WabtStringSlice result; @@ -132,25 +132,27 @@ static void write_escaped_string_slice(Context* ctx, WabtStringSlice ss) { } static void write_command_type(Context* ctx, const WabtCommand* command) { - static const char* s_command_names[] = { - "module", - "action", - "register", - "assert_malformed", - "assert_invalid", - NULL, /* ASSERT_INVALID_NON_BINARY, this command will never be written */ - "assert_unlinkable", - "assert_uninstantiable", - "assert_return", - "assert_return_nan", - "assert_trap", - "assert_exhaustion", - }; + static const char* s_command_names[] = + { + "module", + "action", + "register", + "assert_malformed", + "assert_invalid", + nullptr, /* ASSERT_INVALID_NON_BINARY, this command will never be + written */ + "assert_unlinkable", + "assert_uninstantiable", + "assert_return", + "assert_return_nan", + "assert_trap", + "assert_exhaustion", + }; WABT_STATIC_ASSERT(WABT_ARRAY_SIZE(s_command_names) == WABT_NUM_COMMAND_TYPES); write_key(ctx, "type"); - assert(s_command_names[command->type] != NULL); + assert(s_command_names[command->type]); write_string(ctx, s_command_names[command->type]); } @@ -315,7 +317,7 @@ static void write_raw_module(Context* ctx, WabtFileStream stream; WabtResult result = wabt_init_file_writer(&stream.writer, filename); if (WABT_SUCCEEDED(result)) { - wabt_init_stream(&stream.base, &stream.writer.base, NULL); + wabt_init_stream(&stream.base, &stream.writer.base, nullptr); wabt_write_data(&stream.base, raw_module->binary.data, raw_module->binary.size, ""); wabt_close_file_writer(&stream.writer); @@ -485,11 +487,11 @@ WabtResult wabt_write_binary_spec_script( ctx.module_filename_noext = strip_extension( ctx.spec_options->json_filename ? ctx.spec_options->json_filename : source_filename); - ctx.write_modules = ctx.spec_options->json_filename != NULL; + ctx.write_modules = !!ctx.spec_options->json_filename; WabtResult result = wabt_init_mem_writer(&ctx.json_writer); if (WABT_SUCCEEDED(result)) { - wabt_init_stream(&ctx.json_stream, &ctx.json_writer.base, NULL); + wabt_init_stream(&ctx.json_stream, &ctx.json_writer.base, nullptr); write_commands(&ctx, script); if (ctx.spec_options->json_filename) { wabt_write_output_buffer_to_file(&ctx.json_writer.buf, diff --git a/src/binary-writer-spec.h b/src/binary-writer-spec.h index cb4d3d23..bf470ca0 100644 --- a/src/binary-writer-spec.h +++ b/src/binary-writer-spec.h @@ -24,7 +24,7 @@ struct WabtWriter; #define WABT_WRITE_BINARY_SPEC_OPTIONS_DEFAULT \ - { NULL, WABT_WRITE_BINARY_OPTIONS_DEFAULT } + { nullptr, WABT_WRITE_BINARY_OPTIONS_DEFAULT } typedef struct WabtWriteBinarySpecOptions { const char* json_filename; diff --git a/src/binary-writer.cc b/src/binary-writer.cc index 0c94b079..e2ffa641 100644 --- a/src/binary-writer.cc +++ b/src/binary-writer.cc @@ -542,7 +542,7 @@ static void write_init_expr(Context* ctx, const WabtModule* module, const WabtExpr* expr) { if (expr) - write_expr_list(ctx, module, NULL, expr); + write_expr_list(ctx, module, nullptr, expr); wabt_write_opcode(&ctx->stream, WABT_OPCODE_END); } diff --git a/src/binary-writer.h b/src/binary-writer.h index 8d1d4b2f..a5f3b94c 100644 --- a/src/binary-writer.h +++ b/src/binary-writer.h @@ -26,7 +26,7 @@ struct WabtWriter; struct WabtStream; #define WABT_WRITE_BINARY_OPTIONS_DEFAULT \ - { NULL, true, false, false } + { nullptr, true, false, false } typedef struct WabtWriteBinaryOptions { struct WabtStream* log_stream; diff --git a/src/binding-hash.cc b/src/binding-hash.cc index 59249571..a7230e93 100644 --- a/src/binding-hash.cc +++ b/src/binding-hash.cc @@ -48,7 +48,7 @@ static WabtBindingHashEntry* hash_new_entry(WabtBindingHash* hash, WabtBindingHashEntry* free_entry = hash->free_head; hash->free_head = free_entry->next; if (free_entry->next) - free_entry->next->prev = NULL; + free_entry->next->prev = nullptr; /* our main position is already claimed. Check to see if the entry in that * position is in its main position */ @@ -68,7 +68,7 @@ static WabtBindingHashEntry* hash_new_entry(WabtBindingHash* hash, other_entry->next = free_entry; *free_entry = *entry; - entry->next = NULL; + entry->next = nullptr; } } else { /* remove from the free list */ @@ -78,12 +78,12 @@ static WabtBindingHashEntry* hash_new_entry(WabtBindingHash* hash, entry->prev->next = entry->next; else hash->free_head = entry->next; - entry->next = NULL; + entry->next = nullptr; } WABT_ZERO_MEMORY(entry->binding); entry->binding.name = *name; - entry->prev = NULL; + entry->prev = nullptr; /* entry->next is set above */ return entry; } @@ -105,7 +105,7 @@ static void hash_resize(WabtBindingHash* hash, size_t desired_capacity) { entry->next = new_hash.free_head; new_hash.free_head = entry; } - new_hash.free_head->prev = NULL; + new_hash.free_head->prev = nullptr; /* copy from the old hash to the new hash */ for (i = 0; i < hash->entries.capacity; ++i) { diff --git a/src/common.cc b/src/common.cc index 7d9a688a..cdc40376 100644 --- a/src/common.cc +++ b/src/common.cc @@ -100,7 +100,7 @@ WabtStringSlice wabt_string_slice_from_cstr(const char* string) { bool wabt_string_slice_is_empty(const WabtStringSlice* str) { assert(str); - return str->start == NULL || str->length == 0; + return !str->start || str->length == 0; } bool wabt_string_slices_are_equal(const WabtStringSlice* a, diff --git a/src/common.h b/src/common.h index 88808ec4..0b303e20 100644 --- a/src/common.h +++ b/src/common.h @@ -115,7 +115,7 @@ typedef struct WabtSourceErrorHandler { #define WABT_SOURCE_ERROR_HANDLER_DEFAULT \ { \ wabt_default_source_error_callback, WABT_SOURCE_LINE_MAX_LENGTH_DEFAULT, \ - NULL \ + nullptr \ } typedef void (*WabtBinaryErrorCallback)(uint32_t offset, @@ -128,7 +128,7 @@ typedef struct WabtBinaryErrorHandler { } WabtBinaryErrorHandler; #define WABT_BINARY_ERROR_HANDLER_DEFAULT \ - { wabt_default_binary_error_callback, NULL } + { wabt_default_binary_error_callback, nullptr } /* This data structure is not required; it is just used by the default error * handler callbacks. */ @@ -536,7 +536,7 @@ static WABT_INLINE const char* wabt_get_type_name(WabtType type) { case WABT_TYPE_FUNC: return "func"; case WABT_TYPE_VOID: return "void"; case WABT_TYPE_ANY: return "any"; - default: return NULL; + default: return nullptr; } } diff --git a/src/interpreter.cc b/src/interpreter.cc index 1630c34a..d539bff3 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -210,7 +210,7 @@ WabtInterpreterExport* wabt_get_interpreter_export_by_name( int field_index = wabt_find_binding_index_by_name(&module->export_bindings, name); if (field_index < 0) - return NULL; + return nullptr; assert((size_t)field_index < module->exports.size); return &module->exports.data[field_index]; } @@ -1031,7 +1031,7 @@ WabtInterpreterResult wabt_run_interpreter(WabtInterpreterThread* thread, UINT32_MAX); uint32_t new_byte_size = new_page_size * WABT_PAGE_SIZE; void* new_data = wabt_realloc(memory->data, new_byte_size); - PUSH_NEG_1_AND_BREAK_IF(new_data == NULL); + PUSH_NEG_1_AND_BREAK_IF(!new_data); memset((void*)((intptr_t)new_data + old_byte_size), 0, new_byte_size - old_byte_size); memory->data = new_data; diff --git a/src/option-parser.cc b/src/option-parser.cc index 98ccb59a..2afe1d59 100644 --- a/src/option-parser.cc +++ b/src/option-parser.cc @@ -97,7 +97,7 @@ void wabt_parse_options(WabtOptionParser* parser, } WabtOption* best_option = &parser->options[best_index]; - const char* option_argument = NULL; + const char* option_argument = nullptr; if (best_option->has_argument) { if (arg[best_length] == '=') { option_argument = &arg[best_length + 1]; @@ -126,7 +126,7 @@ void wabt_parse_options(WabtOptionParser* parser, for (j = 0; j < parser->num_options; ++j) { WabtOption* option = &parser->options[j]; if (option->short_name && arg[k] == option->short_name) { - const char* option_argument = NULL; + const char* option_argument = nullptr; if (option->has_argument) { /* a short option with a required argument cannot be followed * by other short options */ @@ -177,10 +177,10 @@ void wabt_print_help(WabtOptionParser* parser, const char* program_name) { int length; if (option->long_name) { if (option->metavar) { - length = - wabt_snprintf(NULL, 0, "%s=%s", option->long_name, option->metavar); + length = wabt_snprintf(nullptr, 0, "%s=%s", option->long_name, + option->metavar); } else { - length = wabt_snprintf(NULL, 0, "%s", option->long_name); + length = wabt_snprintf(nullptr, 0, "%s", option->long_name); } } else { continue; diff --git a/src/prebuilt/ast-lexer-gen.cc b/src/prebuilt/ast-lexer-gen.cc index 047f34d7..e90a39ae 100644 --- a/src/prebuilt/ast-lexer-gen.cc +++ b/src/prebuilt/ast-lexer-gen.cc @@ -116,7 +116,7 @@ static WabtResult fill(WabtLocation* loc, /* TODO(binji): could just alloc instead, because we know we'll need to * memmove below */ char* new_buffer = (char*)wabt_realloc(lexer->buffer, new_buffer_size); - if (new_buffer == NULL) { + if (new_buffer == nullptr) { wabt_ast_parser_error(loc, lexer, parser, "unable to reallocate lexer buffer."); return WABT_ERROR; @@ -6683,7 +6683,7 @@ WabtAstLexer* wabt_new_ast_file_lexer(const char* filename) { lexer->source.file = fopen(filename, "rb"); if (!lexer->source.file) { wabt_destroy_ast_lexer(lexer); - return NULL; + return nullptr; } return lexer; } diff --git a/src/prebuilt/ast-parser-gen.cc b/src/prebuilt/ast-parser-gen.cc index f8544a3c..9843231c 100644 --- a/src/prebuilt/ast-parser-gen.cc +++ b/src/prebuilt/ast-parser-gen.cc @@ -118,7 +118,7 @@ (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \ (Current).last_column = YYRHSLOC(Rhs, N).last_column; \ } else { \ - (Current).filename = NULL; \ + (Current).filename = nullptr; \ (Current).line = YYRHSLOC(Rhs, 0).line; \ (Current).first_column = (Current).last_column = \ YYRHSLOC(Rhs, 0).last_column; \ @@ -2279,7 +2279,7 @@ yyreduce: { WabtTextListNode* node = new_text_list_node(); DUPTEXT(node->text, (yyvsp[0].text)); - node->next = NULL; + node->next = nullptr; (yyval.text_list).first = (yyval.text_list).last = node; } #line 2286 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ @@ -2291,7 +2291,7 @@ yyreduce: (yyval.text_list) = (yyvsp[-1].text_list); WabtTextListNode* node = new_text_list_node(); DUPTEXT(node->text, (yyvsp[0].text)); - node->next = NULL; + node->next = nullptr; (yyval.text_list).last->next = node; (yyval.text_list).last = node; } @@ -2300,7 +2300,7 @@ yyreduce: case 4: #line 321 "src/ast-parser.y" /* yacc.c:1646 */ - { (yyval.text_list).first = (yyval.text_list).last = NULL; } + { (yyval.text_list).first = (yyval.text_list).last = nullptr; } #line 2305 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; @@ -2309,7 +2309,7 @@ yyreduce: { WabtTextListNode node; node.text = (yyvsp[0].text); - node.next = NULL; + node.next = nullptr; WabtTextList text_list; text_list.first = &node; text_list.last = &node; @@ -3054,7 +3054,7 @@ yyreduce: (yyval.func_fields) = new_func_field(); (yyval.func_fields)->type = WABT_FUNC_FIELD_TYPE_EXPRS; (yyval.func_fields)->first_expr = (yyvsp[0].expr_list).first; - (yyval.func_fields)->next = NULL; + (yyval.func_fields)->next = nullptr; } #line 3060 "src/prebuilt/ast-parser-gen.cc" /* yacc.c:1646 */ break; @@ -4053,7 +4053,7 @@ yyreduce: size_t i; for (i = 0; i < (yyval.script).commands.size; ++i) { WabtCommand* command = &(yyval.script).commands.data[i]; - WabtVar* module_var = NULL; + WabtVar* module_var = nullptr; switch (command->type) { case WABT_COMMAND_TYPE_MODULE: { last_module_index = i; diff --git a/src/resolve-names.cc b/src/resolve-names.cc index a3d36f11..e2f28aca 100644 --- a/src/resolve-names.cc +++ b/src/resolve-names.cc @@ -266,7 +266,7 @@ static void visit_func(Context* ctx, WabtFunc* func) { check_duplicate_bindings(ctx, &func->local_bindings, "local"); wabt_visit_func(func, &ctx->visitor); - ctx->current_func = NULL; + ctx->current_func = nullptr; } static void visit_export(Context* ctx, WabtExport* export_) { @@ -331,7 +331,7 @@ static void visit_module(Context* ctx, WabtModule* module) { visit_data_segment(ctx, module->data_segments.data[i]); if (module->start) resolve_func_var(ctx, module->start); - ctx->current_module = NULL; + ctx->current_module = nullptr; } static void visit_raw_module(Context* ctx, WabtRawModule* raw_module) { @@ -450,7 +450,7 @@ WabtResult wabt_resolve_names_module(WabtAstLexer* lexer, WabtModule* module, WabtSourceErrorHandler* error_handler) { Context ctx; - init_context(&ctx, lexer, NULL, error_handler); + init_context(&ctx, lexer, nullptr, error_handler); visit_module(&ctx, module); wabt_destroy_label_ptr_vector(&ctx.labels); return ctx.result; diff --git a/src/stream.cc b/src/stream.cc index 9ec9e2a5..14a2c284 100644 --- a/src/stream.cc +++ b/src/stream.cc @@ -36,7 +36,7 @@ void wabt_init_stream(WabtStream* stream, void wabt_init_file_stream_from_existing(WabtFileStream* stream, FILE* file) { wabt_init_file_writer_existing(&stream->writer, file); - wabt_init_stream(&stream->base, &stream->writer.base, NULL); + wabt_init_stream(&stream->base, &stream->writer.base, nullptr); } WabtStream* wabt_init_stdout_stream(void) { @@ -59,7 +59,7 @@ void wabt_write_data_at(WabtStream* stream, return; if (stream->log_stream) { wabt_write_memory_dump(stream->log_stream, src, size, offset, print_chars, - NULL, desc); + nullptr, desc); } if (stream->writer->write_data) { stream->result = stream->writer->write_data(offset, src, size, @@ -95,7 +95,7 @@ void wabt_move_data(WabtStream* stream, void wabt_writef(WabtStream* stream, const char* format, ...) { WABT_SNPRINTF_ALLOCA(buffer, length, format); - wabt_write_data(stream, buffer, length, NULL); + wabt_write_data(stream, buffer, length, nullptr); } void wabt_write_u8(WabtStream* stream, uint32_t value, const char* desc) { diff --git a/src/stream.h b/src/stream.h index 11e51407..f34eb2da 100644 --- a/src/stream.h +++ b/src/stream.h @@ -26,7 +26,7 @@ typedef struct WabtStream { WabtWriter* writer; size_t offset; WabtResult result; - /* if non-NULL, log all writes to this stream */ + /* if non-null, log all writes to this stream */ struct WabtStream* log_stream; } WabtStream; @@ -53,7 +53,7 @@ WabtStream* wabt_init_stderr_stream(void); /* helper functions for writing to a WabtStream. the |desc| parameter is * optional, and will be appended to the log stream if |stream.log_stream| is - * non-NULL. */ + * non-null. */ void wabt_write_data_at(WabtStream*, size_t offset, const void* src, @@ -77,7 +77,7 @@ void wabt_write_u32(WabtStream*, uint32_t value, const char* desc); void wabt_write_u64(WabtStream*, uint64_t value, const char* desc); static WABT_INLINE void wabt_write_char(WabtStream* stream, char c) { - wabt_write_u8(stream, c, NULL); + wabt_write_u8(stream, c, nullptr); } /* dump memory as text, similar to the xxd format */ @@ -93,7 +93,7 @@ static WABT_INLINE void wabt_write_output_buffer_memory_dump( WabtStream* stream, struct WabtOutputBuffer* buf) { wabt_write_memory_dump(stream, buf->start, buf->size, 0, - WABT_DONT_PRINT_CHARS, NULL, NULL); + WABT_DONT_PRINT_CHARS, nullptr, nullptr); } WABT_EXTERN_C_END diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc index 76fd901f..5cbf7572 100644 --- a/src/tools/wasm-interp.cc +++ b/src/tools/wasm-interp.cc @@ -91,17 +91,17 @@ static const char s_description[] = " $ wasm-interp test.wasm -V 100 --run-all-exports\n"; static WabtOption s_options[] = { - {FLAG_VERBOSE, 'v', "verbose", NULL, NOPE, + {FLAG_VERBOSE, 'v', "verbose", nullptr, NOPE, "use multiple times for more info"}, - {FLAG_HELP, 'h', "help", NULL, NOPE, "print this help message"}, + {FLAG_HELP, 'h', "help", nullptr, NOPE, "print this help message"}, {FLAG_VALUE_STACK_SIZE, 'V', "value-stack-size", "SIZE", YEP, "size in elements of the value stack"}, {FLAG_CALL_STACK_SIZE, 'C', "call-stack-size", "SIZE", YEP, "size in frames of the call stack"}, - {FLAG_TRACE, 't', "trace", NULL, NOPE, "trace execution"}, - {FLAG_SPEC, 0, "spec", NULL, NOPE, + {FLAG_TRACE, 't', "trace", nullptr, NOPE, "trace execution"}, + {FLAG_SPEC, 0, "spec", nullptr, NOPE, "run spec tests (input file should be .json)"}, - {FLAG_RUN_ALL_EXPORTS, 0, "run-all-exports", NULL, NOPE, + {FLAG_RUN_ALL_EXPORTS, 0, "run-all-exports", nullptr, NOPE, "run all the exported functions, in order. useful for testing"}, }; WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options)); @@ -113,7 +113,7 @@ static void on_option(struct WabtOptionParser* parser, case FLAG_VERBOSE: s_verbose++; wabt_init_file_writer_existing(&s_log_stream_writer, stdout); - wabt_init_stream(&s_log_stream, &s_log_stream_writer.base, NULL); + wabt_init_stream(&s_log_stream, &s_log_stream_writer.base, nullptr); s_read_binary_options.log_stream = &s_log_stream; break; @@ -183,7 +183,7 @@ static WabtStringSlice get_dirname(const char* s) { * s = "foo.bar", => "" */ const char* last_slash = strrchr(s, '/'); - if (last_slash == NULL) + if (last_slash == nullptr) last_slash = s; WabtStringSlice result; @@ -457,7 +457,7 @@ static WabtResult read_module(const char* module_filename, void* data; size_t size; - *out_module = NULL; + *out_module = nullptr; result = wabt_read_file(module_filename, &data, &size); if (WABT_SUCCEEDED(result)) { @@ -612,7 +612,7 @@ static void init_environment(WabtInterpreterEnvironment* env) { static WabtResult read_and_run_module(const char* module_filename) { WabtResult result; WabtInterpreterEnvironment env; - WabtInterpreterModule* module = NULL; + WabtInterpreterModule* module = nullptr; WabtInterpreterThread thread; init_environment(&env); diff --git a/src/tools/wasm-link.cc b/src/tools/wasm-link.cc index 7487bc15..75a6b224 100644 --- a/src/tools/wasm-link.cc +++ b/src/tools/wasm-link.cc @@ -38,12 +38,12 @@ static const char s_description[] = " $ wasm-link m1.wasm m2.wasm -o out.wasm\n"; static WabtOption s_options[] = { - {FLAG_VERBOSE, 'v', "verbose", NULL, NOPE, + {FLAG_VERBOSE, 'v', "verbose", nullptr, NOPE, "use multiple times for more info"}, {FLAG_OUTPUT, 'o', "output", "FILE", YEP, "output wasm binary file"}, - {FLAG_RELOCATABLE, 'r', "relocatable", NULL, NOPE, + {FLAG_RELOCATABLE, 'r', "relocatable", nullptr, NOPE, "output a relocatable object file"}, - {FLAG_HELP, 'h', "help", NULL, NOPE, "print this help message"}, + {FLAG_HELP, 'h', "help", nullptr, NOPE, "print this help message"}, }; WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options)); @@ -70,7 +70,7 @@ static void on_option(struct WabtOptionParser* parser, case FLAG_VERBOSE: s_verbose++; wabt_init_file_writer_existing(&s_log_stream_writer, stdout); - wabt_init_stream(&s_log_stream, &s_log_stream_writer.base, NULL); + wabt_init_stream(&s_log_stream, &s_log_stream_writer.base, nullptr); break; case FLAG_OUTPUT: @@ -785,7 +785,7 @@ static WabtResult perform_link(Context* ctx) { if (WABT_FAILED(wabt_init_mem_writer(&writer))) WABT_FATAL("unable to open memory writer for writing\n"); - WabtStream* log_stream = NULL; + WabtStream* log_stream = nullptr; if (s_verbose) log_stream = &s_log_stream; diff --git a/src/tools/wasm2wast.cc b/src/tools/wasm2wast.cc index 4f701638..e55a923b 100644 --- a/src/tools/wasm2wast.cc +++ b/src/tools/wasm2wast.cc @@ -34,7 +34,7 @@ static int s_verbose; static const char* s_infile; static const char* s_outfile; -static WabtReadBinaryOptions s_read_binary_options = {NULL, true}; +static WabtReadBinaryOptions s_read_binary_options = {nullptr, true}; static bool s_generate_names; static WabtBinaryErrorHandler s_error_handler = @@ -67,14 +67,14 @@ static const char s_description[] = " $ wasm2wast test.wasm --no-debug-names -o test.wast\n"; static WabtOption s_options[] = { - {FLAG_VERBOSE, 'v', "verbose", NULL, NOPE, + {FLAG_VERBOSE, 'v', "verbose", nullptr, NOPE, "use multiple times for more info"}, - {FLAG_HELP, 'h', "help", NULL, NOPE, "print this help message"}, + {FLAG_HELP, 'h', "help", nullptr, NOPE, "print this help message"}, {FLAG_OUTPUT, 'o', "output", "FILENAME", YEP, "output file for the generated wast file, by default use stdout"}, - {FLAG_NO_DEBUG_NAMES, 0, "no-debug-names", NULL, NOPE, + {FLAG_NO_DEBUG_NAMES, 0, "no-debug-names", nullptr, NOPE, "Ignore debug names in the binary file"}, - {FLAG_GENERATE_NAMES, 0, "generate-names", NULL, NOPE, + {FLAG_GENERATE_NAMES, 0, "generate-names", nullptr, NOPE, "Give auto-generated names to non-named functions, types, etc."}, }; WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options)); @@ -86,7 +86,7 @@ static void on_option(struct WabtOptionParser* parser, case FLAG_VERBOSE: s_verbose++; wabt_init_file_writer_existing(&s_log_stream_writer, stdout); - wabt_init_stream(&s_log_stream, &s_log_stream_writer.base, NULL); + wabt_init_stream(&s_log_stream, &s_log_stream_writer.base, nullptr); s_read_binary_options.log_stream = &s_log_stream; break; diff --git a/src/tools/wasmdump.cc b/src/tools/wasmdump.cc index fdde4681..2fb58980 100644 --- a/src/tools/wasmdump.cc +++ b/src/tools/wasmdump.cc @@ -49,16 +49,17 @@ static const char s_description[] = " $ wasmdump test.wasm\n"; static WabtOption s_options[] = { - {FLAG_HEADERS, 'h', "headers", NULL, NOPE, "print headers"}, - {FLAG_SECTION, 'j', "section", NULL, YEP, "select just one section"}, - {FLAG_RAW, 's', "full-contents", NULL, NOPE, "print raw section contents"}, - {FLAG_DISASSEMBLE, 'd', "disassemble", NULL, NOPE, + {FLAG_HEADERS, 'h', "headers", nullptr, NOPE, "print headers"}, + {FLAG_SECTION, 'j', "section", nullptr, YEP, "select just one section"}, + {FLAG_RAW, 's', "full-contents", nullptr, NOPE, + "print raw section contents"}, + {FLAG_DISASSEMBLE, 'd', "disassemble", nullptr, NOPE, "disassemble function bodies"}, - {FLAG_DEBUG, '\0', "debug", NULL, NOPE, "disassemble function bodies"}, - {FLAG_DETAILS, 'x', "details", NULL, NOPE, "Show section details"}, - {FLAG_RELOCS, 'r', "reloc", NULL, NOPE, + {FLAG_DEBUG, '\0', "debug", nullptr, NOPE, "disassemble function bodies"}, + {FLAG_DETAILS, 'x', "details", nullptr, NOPE, "Show section details"}, + {FLAG_RELOCS, 'r', "reloc", nullptr, NOPE, "show relocations inline with disassembly"}, - {FLAG_HELP, 'h', "help", NULL, NOPE, "print this help message"}, + {FLAG_HELP, 'h', "help", nullptr, NOPE, "print this help message"}, }; WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options)); diff --git a/src/tools/wasmopcodecnt.cc b/src/tools/wasmopcodecnt.cc index 91cca58a..e415106f 100644 --- a/src/tools/wasmopcodecnt.cc +++ b/src/tools/wasmopcodecnt.cc @@ -64,32 +64,15 @@ static const char s_description[] = " $ wasmopcodecnt test.wasm -o test.dist\n"; static WabtOption s_options[] = { - {FLAG_VERBOSE, - 'v', - "verbose", - NULL, - NOPE, + {FLAG_VERBOSE, 'v', "verbose", nullptr, NOPE, "use multiple times for more info"}, - {FLAG_HELP, 'h', "help", NULL, NOPE, "print this help message"}, - {FLAG_OUTPUT, - 'o', - "output", - "FILENAME", - YEP, + {FLAG_HELP, 'h', "help", nullptr, NOPE, "print this help message"}, + {FLAG_OUTPUT, 'o', "output", "FILENAME", YEP, "output file for the opcode counts, by default use stdout"}, - {FLAG_CUTOFF, - 'c', - "cutoff", - "N", - YEP, + {FLAG_CUTOFF, 'c', "cutoff", "N", YEP, "cutoff for reporting counts less than N"}, - {FLAG_SEPARATOR, - 's', - "separator", - "SEPARATOR", - YEP, - "Separator text between element and count when reporting counts"} -}; + {FLAG_SEPARATOR, 's', "separator", "SEPARATOR", YEP, + "Separator text between element and count when reporting counts"}}; WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options)); @@ -100,7 +83,7 @@ static void on_option(struct WabtOptionParser* parser, case FLAG_VERBOSE: s_verbose++; wabt_init_file_writer_existing(&s_log_stream_writer, stdout); - wabt_init_stream(&s_log_stream, &s_log_stream_writer.base, NULL); + wabt_init_stream(&s_log_stream, &s_log_stream_writer.base, nullptr); s_read_binary_options.log_stream = &s_log_stream; break; @@ -375,7 +358,7 @@ int main(int argc, char** argv) { if (WABT_SUCCEEDED(result)) { display_sorted_int_counter_vector( out, "Opcode counts:", &opcnt_data.opcode_vec, opcode_counter_gt, - display_opcode_name, NULL); + display_opcode_name, nullptr); display_sorted_int_counter_vector( out, "\ni32.const:", &opcnt_data.i32_const_vec, int_counter_gt, display_intmax, wabt_get_opcode_name(WABT_OPCODE_I32_CONST)); diff --git a/src/tools/wast-desugar.cc b/src/tools/wast-desugar.cc index d3e9d931..494938f0 100644 --- a/src/tools/wast-desugar.cc +++ b/src/tools/wast-desugar.cc @@ -61,11 +61,11 @@ static const char s_description[] = " $ wast-desugar --generate-names test.wast\n"; static WabtOption s_options[] = { - {FLAG_HELP, 'h', "help", NULL, WABT_OPTION_NO_ARGUMENT, + {FLAG_HELP, 'h', "help", nullptr, WABT_OPTION_NO_ARGUMENT, "print this help message"}, {FLAG_OUTPUT, 'o', "output", "FILE", WABT_OPTION_HAS_ARGUMENT, "output file for the formatted file"}, - {FLAG_GENERATE_NAMES, 0, "generate-names", NULL, WABT_OPTION_NO_ARGUMENT, + {FLAG_GENERATE_NAMES, 0, "generate-names", nullptr, WABT_OPTION_NO_ARGUMENT, "Give auto-generated names to non-named functions, types, etc."}, }; WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options)); diff --git a/src/tools/wast2wasm.cc b/src/tools/wast2wasm.cc index a5e3d3b8..e1655d42 100644 --- a/src/tools/wast2wasm.cc +++ b/src/tools/wast2wasm.cc @@ -86,22 +86,22 @@ static const char s_description[] = " $ wast2wasm spec-test.wast --spec -o spec-test.json\n"; static WabtOption s_options[] = { - {FLAG_VERBOSE, 'v', "verbose", NULL, NOPE, + {FLAG_VERBOSE, 'v', "verbose", nullptr, NOPE, "use multiple times for more info"}, - {FLAG_HELP, 'h', "help", NULL, NOPE, "print this help message"}, - {FLAG_DUMP_MODULE, 'd', "dump-module", NULL, NOPE, + {FLAG_HELP, 'h', "help", nullptr, NOPE, "print this help message"}, + {FLAG_DUMP_MODULE, 'd', "dump-module", nullptr, NOPE, "print a hexdump of the module to stdout"}, {FLAG_OUTPUT, 'o', "output", "FILE", YEP, "output wasm binary file"}, - {FLAG_RELOCATABLE, 'r', NULL, NULL, NOPE, + {FLAG_RELOCATABLE, 'r', nullptr, nullptr, NOPE, "create a relocatable wasm binary (suitable for linking with wasm-link)"}, - {FLAG_SPEC, 0, "spec", NULL, NOPE, + {FLAG_SPEC, 0, "spec", nullptr, NOPE, "parse a file with multiple modules and assertions, like the spec " "tests"}, - {FLAG_NO_CANONICALIZE_LEB128S, 0, "no-canonicalize-leb128s", NULL, NOPE, + {FLAG_NO_CANONICALIZE_LEB128S, 0, "no-canonicalize-leb128s", nullptr, NOPE, "Write all LEB128 sizes as 5-bytes instead of their minimal size"}, - {FLAG_DEBUG_NAMES, 0, "debug-names", NULL, NOPE, + {FLAG_DEBUG_NAMES, 0, "debug-names", nullptr, NOPE, "Write debug names to the generated binary file"}, - {FLAG_NO_CHECK, 0, "no-check", NULL, NOPE, + {FLAG_NO_CHECK, 0, "no-check", nullptr, NOPE, "Don't check for invalid modules"}, }; WABT_STATIC_ASSERT(NUM_FLAGS == WABT_ARRAY_SIZE(s_options)); diff --git a/src/type-checker.cc b/src/type-checker.cc index 63c0c2ad..488ff9be 100644 --- a/src/type-checker.cc +++ b/src/type-checker.cc @@ -42,7 +42,7 @@ WabtResult wabt_typechecker_get_label(WabtTypeChecker* tc, assert(tc->label_stack.size > 0); print_error(tc, "invalid depth: %" PRIzd " (max %" PRIzd ")", depth, tc->label_stack.size - 1); - *out_label = NULL; + *out_label = nullptr; return WABT_ERROR; } *out_label = &tc->label_stack.data[tc->label_stack.size - depth - 1]; diff --git a/src/validator.cc b/src/validator.cc index 8e3d5d97..d7bbdaf7 100644 --- a/src/validator.cc +++ b/src/validator.cc @@ -130,7 +130,7 @@ static WabtResult check_global_var(Context* ctx, static WabtType get_global_var_type_or_any(Context* ctx, const WabtVar* var) { const WabtGlobal* global; - if (WABT_SUCCEEDED(check_global_var(ctx, var, &global, NULL))) + if (WABT_SUCCEEDED(check_global_var(ctx, var, &global, nullptr))) return global->type; return WABT_TYPE_ANY; } @@ -544,7 +544,7 @@ static void check_func(Context* ctx, &func->decl.sig.result_types); check_expr_list(ctx, loc, func->first_expr); wabt_typechecker_end_function(&ctx->typechecker); - ctx->current_func = NULL; + ctx->current_func = nullptr; } static void print_const_expr_error(Context* ctx, @@ -563,7 +563,7 @@ static void check_const_init_expr(Context* ctx, const char* desc) { WabtType type = WABT_TYPE_VOID; if (expr) { - if (expr->next != NULL) { + if (expr->next) { print_const_expr_error(ctx, loc, desc); return; } @@ -574,7 +574,7 @@ static void check_const_init_expr(Context* ctx, break; case WABT_EXPR_TYPE_GET_GLOBAL: { - const WabtGlobal* ref_global = NULL; + const WabtGlobal* ref_global = nullptr; int ref_global_index; if (WABT_FAILED(check_global_var(ctx, &expr->get_global.var, &ref_global, &ref_global_index))) { @@ -664,7 +664,7 @@ static void check_elem_segments(Context* ctx, const WabtModule* module) { size_t i; for (i = 0; i < elem_segment->vars.size; ++i) { if (!WABT_SUCCEEDED( - check_func_var(ctx, &elem_segment->vars.data[i], NULL))) + check_func_var(ctx, &elem_segment->vars.data[i], nullptr))) continue; } @@ -704,7 +704,7 @@ static void check_import(Context* ctx, switch (import->kind) { case WABT_EXTERNAL_KIND_FUNC: if (wabt_decl_has_func_type(&import->func.decl)) - check_func_type_var(ctx, &import->func.decl.type_var, NULL); + check_func_type_var(ctx, &import->func.decl.type_var, nullptr); break; case WABT_EXTERNAL_KIND_TABLE: check_table(ctx, loc, &import->table); @@ -730,17 +730,18 @@ static void check_import(Context* ctx, static void check_export(Context* ctx, const WabtExport* export_) { switch (export_->kind) { case WABT_EXTERNAL_KIND_FUNC: - check_func_var(ctx, &export_->var, NULL); + check_func_var(ctx, &export_->var, nullptr); break; case WABT_EXTERNAL_KIND_TABLE: - check_table_var(ctx, &export_->var, NULL); + check_table_var(ctx, &export_->var, nullptr); break; case WABT_EXTERNAL_KIND_MEMORY: - check_memory_var(ctx, &export_->var, NULL); + check_memory_var(ctx, &export_->var, nullptr); break; case WABT_EXTERNAL_KIND_GLOBAL: { const WabtGlobal* global; - if (WABT_SUCCEEDED(check_global_var(ctx, &export_->var, &global, NULL))) { + if (WABT_SUCCEEDED( + check_global_var(ctx, &export_->var, &global, nullptr))) { if (global->mutable_) { print_error(ctx, &export_->var.loc, "mutable globals cannot be exported"); @@ -782,7 +783,7 @@ static void check_module(Context* ctx, const WabtModule* module) { ctx->num_imported_globals = 0; WabtModuleField* field; - for (field = module->first_field; field != NULL; field = field->next) { + for (field = module->first_field; field; field = field->next) { switch (field->type) { case WABT_MODULE_FIELD_TYPE_FUNC: check_func(ctx, &field->loc, &field->func); @@ -827,7 +828,7 @@ static void check_module(Context* ctx, const WabtModule* module) { print_error(ctx, &field->loc, "only one start function allowed"); } - const WabtFunc* start_func = NULL; + const WabtFunc* start_func = nullptr; check_func_var(ctx, &field->start, &start_func); if (start_func) { if (wabt_get_num_params(start_func) != 0) { @@ -851,7 +852,7 @@ static void check_module(Context* ctx, const WabtModule* module) { } /* returns the result type of the invoked function, checked by the caller; - * returning NULL means that another error occured first, so the result type + * returning nullptr means that another error occured first, so the result type * should be ignored. */ static const WabtTypeVector* check_invoke(Context* ctx, const WabtAction* action) { @@ -860,7 +861,7 @@ static const WabtTypeVector* check_invoke(Context* ctx, wabt_get_module_by_var(ctx->script, &action->module_var); if (!module) { print_error(ctx, &action->loc, "unknown module"); - return NULL; + return nullptr; } WabtExport* export_ = wabt_get_export_by_name(module, &invoke->name); @@ -868,13 +869,13 @@ static const WabtTypeVector* check_invoke(Context* ctx, print_error(ctx, &action->loc, "unknown function export \"" PRIstringslice "\"", WABT_PRINTF_STRING_SLICE_ARG(invoke->name)); - return NULL; + return nullptr; } WabtFunc* func = wabt_get_func_by_var(module, &export_->var); if (!func) { /* this error will have already been reported, just skip it */ - return NULL; + return nullptr; } size_t actual_args = invoke->args.size; @@ -884,7 +885,7 @@ static const WabtTypeVector* check_invoke(Context* ctx, ", expected %" PRIzd, actual_args > expected_args ? "many" : "few", actual_args, expected_args); - return NULL; + return nullptr; } size_t i; for (i = 0; i < actual_args; ++i) { diff --git a/src/vector.h b/src/vector.h index 500ebb96..bb578abe 100644 --- a/src/vector.h +++ b/src/vector.h @@ -64,7 +64,7 @@ \ void wabt_destroy_##name##_vector(type##Vector* vec) { \ wabt_free(vec->data); \ - vec->data = NULL; \ + vec->data = nullptr; \ vec->size = 0; \ vec->capacity = 0; \ } \ diff --git a/src/writer.cc b/src/writer.cc index e50999eb..a44af47e 100644 --- a/src/writer.cc +++ b/src/writer.cc @@ -158,7 +158,7 @@ WabtResult wabt_init_mem_writer_existing(WabtMemoryWriter* writer, void wabt_steal_mem_writer_output_buffer(WabtMemoryWriter* writer, WabtOutputBuffer* out_buf) { *out_buf= writer->buf; - writer->buf.start = NULL; + writer->buf.start = nullptr; writer->buf.size = 0; writer->buf.capacity = 0; } |