# HG changeset patch # User Paul Boddie # Date 1484865190 -3600 # Node ID faa1569c867fcfe20f6aaeaa56bd88fbc8a9f719 # Parent 7153e60d49b99d0ce128edfdc4f1493173231152 Enabled all compiler warnings, fixed attribute initialiser warnings along with various control-flow and variable warnings. diff -r 7153e60d49b9 -r faa1569c867f generator.py --- a/generator.py Thu Jan 19 19:23:39 2017 +0100 +++ b/generator.py Thu Jan 19 23:33:10 2017 +0100 @@ -535,7 +535,7 @@ # Define a macro for the constant. attr_name = encode_path(const_path) - print >>f_decls, "#define %s ((__attr) {&%s, &%s})" % (attr_name, structure_name, structure_name) + print >>f_decls, "#define %s ((__attr) {.context=&%s, .value=&%s})" % (attr_name, structure_name, structure_name) def make_parameter_table(self, f_decls, f_defs, parameters): @@ -851,7 +851,7 @@ # Handle gaps in the structure. if attrname is None: - structure.append("{0, 0}") + structure.append("__NULL") # Handle non-constant and constant members. @@ -884,7 +884,7 @@ else: attr = encode_function_pointer(attr) - structure.append("{%s, .fn=%s}" % (bound_attr and ".b=&%s" % bound_attr or "0", attr)) + structure.append("{.b=%s, .fn=%s}" % (bound_attr and "&%s" % bound_attr or "0", attr)) continue # Special argument specification member. @@ -937,7 +937,7 @@ # Special class relationship attributes. elif is_type_attribute(attrname): - structure.append("{0, &%s}" % encode_path(decode_type_attribute(attrname))) + structure.append("{.context=0, .value=&%s}" % encode_path(decode_type_attribute(attrname))) continue # All other kinds of members. @@ -976,19 +976,19 @@ if kind == "" and origin == self.none_type: attr_path = encode_predefined_reference(self.none_value) - return "{&%s, &%s} /* %s */" % (attr_path, attr_path, name) + return "{.context=&%s, .value=&%s} /* %s */" % (attr_path, attr_path, name) # Predefined constant members. if (path, name) in self.predefined_constant_members: attr_path = encode_predefined_reference("%s.%s" % (path, name)) - return "{&%s, &%s} /* %s */" % (attr_path, attr_path, name) + return "{.context=&%s, .value=&%s} /* %s */" % (attr_path, attr_path, name) # General undetermined members. if kind in ("", ""): attr_path = encode_predefined_reference(self.none_value) - return "{&%s, &%s} /* %s */" % (attr_path, attr_path, name) + return "{.context=&%s, .value=&%s} /* %s */" % (attr_path, attr_path, name) # Set the context depending on the kind of attribute. # For methods: {&, &} @@ -1002,7 +1002,7 @@ context = "&%s" % encode_path(origin) else: context = "0" - return "{%s, &%s}" % (context, encode_path(origin)) + return "{.context=%s, .value=&%s}" % (context, encode_path(origin)) def append_defaults(self, path, structure): @@ -1111,21 +1111,22 @@ %s();""" % function_name print >>f_code, """\ - return 0; } __Catch(__tmp_exc) { - if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {0, &__builtins___exception_system_SystemExit}))) + if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {.context=0, .value=&__builtins___exception_system_SystemExit}))) return __load_via_object( __load_via_object(__tmp_exc.arg.value, %s).value, %s).intvalue; fprintf(stderr, "Program terminated due to exception: %%s.\\n", __load_via_object( - %s((__attr[]) {{0, 0}, __tmp_exc.arg}).value, + %s((__attr[]) {__NULL, __tmp_exc.arg}).value, %s).strvalue); return 1; } + + return 0; } """ % ( encode_symbol("pos", "value"), diff -r 7153e60d49b9 -r faa1569c867f templates/Makefile --- a/templates/Makefile Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/Makefile Thu Jan 19 23:33:10 2017 +0100 @@ -1,6 +1,6 @@ SRC = exceptions.c main.c $(wildcard native/*.c) ops.c progops.c progtypes.c $(wildcard src/*.c) OBJ = $(SRC:.c=.o) -CFLAGS = -I. -finput-charset=UTF-8 +CFLAGS = -Wall -I. -finput-charset=UTF-8 LDFLAGS = -lm -lgc ifdef ARCH diff -r 7153e60d49b9 -r faa1569c867f templates/Makefile-debug --- a/templates/Makefile-debug Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/Makefile-debug Thu Jan 19 23:33:10 2017 +0100 @@ -1,6 +1,6 @@ SRC = exceptions.c main.c $(wildcard native/*.c) ops.c progops.c progtypes.c $(wildcard src/*.c) OBJ = $(SRC:.c=.o) -CFLAGS = -I. -finput-charset=UTF-8 -g +CFLAGS = -Wall -I. -finput-charset=UTF-8 -g LDFLAGS = -lm -lgc ifdef ARCH diff -r 7153e60d49b9 -r faa1569c867f templates/native/common.c --- a/templates/native/common.c Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/native/common.c Thu Jan 19 23:33:10 2017 +0100 @@ -40,7 +40,7 @@ __attr attr = __new(&__InstanceTable___builtins___str_string, &__builtins___str_string, sizeof(__obj___builtins___str_string)); attr.value->attrs[__pos___data__].size = size; attr.value->attrs[__pos___data__].strvalue = s; - attr.value->attrs[__pos___key__] = (__attr) {0, 0}; + attr.value->attrs[__pos___key__] = __NULL; return attr; } diff -r 7153e60d49b9 -r faa1569c867f templates/native/iconv.c --- a/templates/native/iconv.c Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/native/iconv.c Thu Jan 19 23:33:10 2017 +0100 @@ -33,7 +33,7 @@ static void __raise_incomplete_sequence_error(__attr value, __attr arg) { #ifdef __HAVE_posix_iconv_IncompleteSequenceError - __attr args[3] = {{0, 0}, value, arg}; + __attr args[3] = {__NULL, value, arg}; __attr exc = __new_posix_iconv_IncompleteSequenceError(args); __Raise(exc); #endif /* __HAVE_posix_iconv_IncompleteSequenceError */ @@ -42,7 +42,7 @@ static void __raise_invalid_sequence_error(__attr value, __attr arg) { #ifdef __HAVE_posix_iconv_InvalidSequenceError - __attr args[3] = {{0, 0}, value, arg}; + __attr args[3] = {__NULL, value, arg}; __attr exc = __new_posix_iconv_InvalidSequenceError(args); __Raise(exc); #endif /* __HAVE_posix_iconv_InvalidSequenceError */ @@ -117,6 +117,10 @@ else __raise_os_error(__new_int(errno), __builtins___none_None); + + /* Should never be reached: included to satisfy the compiler. */ + + return __builtins___none_None; } __attr __fn_native_iconv_iconv_close(__attr __args[]) diff -r 7153e60d49b9 -r faa1569c867f templates/native/io.c --- a/templates/native/io.c Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/native/io.c Thu Jan 19 23:33:10 2017 +0100 @@ -84,6 +84,10 @@ attr.datavalue = (void *) f; return attr; } + + /* Should never be reached: included to satisfy the compiler. */ + + return __builtins___none_None; } __attr __fn_native_io_fdopen(__attr __args[]) @@ -113,6 +117,10 @@ attr.datavalue = (void *) f; return attr; } + + /* Should never be reached: included to satisfy the compiler. */ + + return __builtins___none_None; } __attr __fn_native_io_fread(__attr __args[]) @@ -134,7 +142,7 @@ { if (feof(f) && (have_read == 0)) __raise_eof_error(); - else if (error = ferror(f)) + else if ((error = ferror(f))) __raise_io_error(__new_int(error)); } @@ -162,7 +170,7 @@ { if (feof(f)) __raise_eof_error(); - else if (error = ferror(f)) + else if ((error = ferror(f))) __raise_io_error(__new_int(error)); } diff -r 7153e60d49b9 -r faa1569c867f templates/native/limits.c --- a/templates/native/limits.c Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/native/limits.c Thu Jan 19 23:33:10 2017 +0100 @@ -30,15 +30,11 @@ __attr __fn_native_limits_get_maxint(__attr __args[]) { - __attr * const status = &__args[1]; - return __new_int(INT_MAX); } __attr __fn_native_limits_get_minint(__attr __args[]) { - __attr * const status = &__args[1]; - return __new_int(INT_MIN); } diff -r 7153e60d49b9 -r faa1569c867f templates/native/list.c --- a/templates/native/list.c Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/native/list.c Thu Jan 19 23:33:10 2017 +0100 @@ -32,7 +32,7 @@ __attr * const size = &__args[1]; /* size.__data__ interpreted as int */ unsigned int n = __load_via_object(size->value, __pos___data__).intvalue; - __attr attr = {0, .seqvalue=__new_fragment(n)}; + __attr attr = {{0}, .seqvalue=__new_fragment(n)}; /* Return the __data__ attribute. */ return attr; @@ -61,7 +61,7 @@ /* Replace the __data__ attribute if appropriate. */ if (newdata != data) - __store_via_object(self->value, __pos___data__, ((__attr) {0, .seqvalue=newdata})); + __store_via_object(self->value, __pos___data__, ((__attr) {{0}, .seqvalue=newdata})); return __builtins___none_None; } @@ -92,7 +92,7 @@ /* Replace the __data__ attribute if appropriate. */ if (newdata != data) - __store_via_object(self->value, __pos___data__, ((__attr) {0, .seqvalue=newdata})); + __store_via_object(self->value, __pos___data__, ((__attr) {{0}, .seqvalue=newdata})); return __builtins___none_None; } diff -r 7153e60d49b9 -r faa1569c867f templates/native/str.c --- a/templates/native/str.c Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/native/str.c Thu Jan 19 23:33:10 2017 +0100 @@ -84,8 +84,6 @@ __attr __fn_native_str_str_len(__attr __args[]) { __attr * const _data = &__args[1]; - /* _data interpreted as string */ - char *s = _data->strvalue; /* Return the new integer. */ return __new_int(_data->size); @@ -94,8 +92,6 @@ __attr __fn_native_str_str_nonempty(__attr __args[]) { __attr * const _data = &__args[1]; - /* _data interpreted as string */ - char *s = _data->strvalue; return _data->size ? __builtins___boolean_True : __builtins___boolean_False; } diff -r 7153e60d49b9 -r faa1569c867f templates/native/system.c --- a/templates/native/system.c Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/native/system.c Thu Jan 19 23:33:10 2017 +0100 @@ -37,16 +37,12 @@ __attr __fn_native_system_get_argv(__attr __args[]) { - __attr * const status = &__args[1]; - /* NOTE: To be written. */ return __builtins___none_None; } __attr __fn_native_system_get_path(__attr __args[]) { - __attr * const status = &__args[1]; - /* NOTE: To be written. */ return __builtins___none_None; } diff -r 7153e60d49b9 -r faa1569c867f templates/ops.c --- a/templates/ops.c Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/ops.c Thu Jan 19 23:33:10 2017 +0100 @@ -200,10 +200,12 @@ attribute. */ if (__is_instance(context)) + { if (__test_common_instance(context, __TYPEPOS(attr.context), __TYPECODE(attr.context))) return __replace_context(context, attr); else __raise_type_error(); + } /* Test for access to a type class attribute using a type instance. */ @@ -232,7 +234,7 @@ __attr __update_context(__ref context, __attr attr) { - __attr out = {context, .fn=attr.fn}; + __attr out = {.context=context, .fn=attr.fn}; return out; } diff -r 7153e60d49b9 -r faa1569c867f templates/progops.c --- a/templates/progops.c Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/progops.c Thu Jan 19 23:33:10 2017 +0100 @@ -30,8 +30,8 @@ __attr __new(const __table * table, __ref cls, size_t size) { __ref obj = (__ref) __ALLOCATE(1, size); - __attr self = {obj, obj}; - __attr tmp = {0, cls}; + __attr self = {.context=obj, .value=obj}; + __attr tmp = {.context=0, .value=cls}; obj->table = table; __store_via_object(obj, __pos___class__, tmp); return self; @@ -57,7 +57,7 @@ /* Calculate the size of the fragment. */ __fragment *data = __new_fragment(number); - __attr attr = {0, .seqvalue=data}; + __attr attr = {{0}, .seqvalue=data}; unsigned int i, j; /* Copy the given number of values, starting from the second element. */ @@ -106,7 +106,7 @@ void __raise_io_error(__attr value) { #ifdef __HAVE___builtins___exception_io_IOError - __attr args[2] = {{0, 0}, value}; + __attr args[2] = {__NULL, value}; __attr exc = __new___builtins___exception_io_IOError(args); __Raise(exc); #endif /* __HAVE___builtins___exception_io_IOError */ @@ -122,7 +122,7 @@ void __raise_os_error(__attr value, __attr arg) { #ifdef __HAVE___builtins___exception_system_OSError - __attr args[3] = {{0, 0}, value, arg}; + __attr args[3] = {__NULL, value, arg}; __attr exc = __new___builtins___exception_system_OSError(args); __Raise(exc); #endif /* __HAVE___builtins___exception_system_OSError */ @@ -272,7 +272,7 @@ int __BOOL(__attr attr) { - __attr args[2] = {{0, 0}, attr}; + __attr args[2] = {__NULL, attr}; /* Invoke the bool function with the object and test against True. */ diff -r 7153e60d49b9 -r faa1569c867f templates/progops.h --- a/templates/progops.h Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/progops.h Thu Jan 19 23:33:10 2017 +0100 @@ -19,7 +19,6 @@ #ifndef __PROGOPS_H__ #define __PROGOPS_H__ -#include #include "types.h" /* Generic instantiation operations, defining common members. */ @@ -76,6 +75,6 @@ /* Convenience definitions. */ -#define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance((__attr[]) {{0, 0}, __ATTR, __TYPE})) +#define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance((__attr[]) {__NULL, __ATTR, __TYPE})) #endif /* __PROGOPS_H__ */ diff -r 7153e60d49b9 -r faa1569c867f templates/types.h --- a/templates/types.h Thu Jan 19 19:23:39 2017 +0100 +++ b/templates/types.h Thu Jan 19 23:33:10 2017 +0100 @@ -106,9 +106,9 @@ #define __INSTANCEPOS 0 -/* Special null value. */ +/* Special null values. */ -#define __NULL ((__attr) {0, 0}) +#define __NULL ((__attr) {{0}, {0}}) /* Function pointer type. */ diff -r 7153e60d49b9 -r faa1569c867f translator.py --- a/translator.py Thu Jan 19 19:23:39 2017 +0100 +++ b/translator.py Thu Jan 19 23:33:10 2017 +0100 @@ -133,7 +133,7 @@ elif static_name: parent = ref.parent() context = ref.has_kind("") and encode_path(parent) or None - return "((__attr) {%s, &%s})" % (context and "&%s" % context or "0", static_name) + return "((__attr) {.context=%s, .value=&%s})" % (context and "&%s" % context or "0", static_name) # Qualified names must be converted into parent-relative accesses. @@ -805,7 +805,7 @@ if not ref.static(): self.process_assignment_for_object( - n.name, make_expression("((__attr) {0, &%s})" % + n.name, make_expression("((__attr) {.context=0, .value=&%s})" % encode_path(class_name))) self.enter_namespace(n.name) @@ -984,7 +984,7 @@ context = self.is_method(objpath) self.process_assignment_for_object(original_name, - make_expression("((__attr) {%s, &%s})" % ( + make_expression("((__attr) {.context=%s, .value=&%s})" % ( context and "&%s" % encode_path(context) or "0", encode_path(objpath)))) @@ -1148,7 +1148,7 @@ if context_required: args = ["__CONTEXT_AS_VALUE(__tmp_targets[%d])" % self.function_target] else: - args = ["(__attr) {0, 0}"] + args = ["__NULL"] args += [None] * (not parameters and len(n.args) or parameters and len(parameters) or 0) kwcodes = [] @@ -1306,13 +1306,13 @@ # Without defaults, produce an attribute referring to the function. if not defaults: - return make_expression("((__attr) {0, &%s})" % encode_path(function_name)) + return make_expression("((__attr) {.context=0, .value=&%s})" % encode_path(function_name)) # With defaults, copy the function structure and set the defaults on the # copy. else: - return make_expression("(__tmp_value = __COPY(&%s, sizeof(%s)), %s, (__attr) {0, __tmp_value})" % ( + return make_expression("(__tmp_value = __COPY(&%s, sizeof(%s)), %s, (__attr) {.context=0, .value=__tmp_value})" % ( encode_path(function_name), encode_symbol("obj", function_name), ", ".join(defaults)))