syntax: fix code using superstrings with nullables
authorJean Privat <jean@pryen.org>
Mon, 18 Jan 2010 18:13:21 +0000 (13:13 -0500)
committerJean Privat <jean@pryen.org>
Mon, 18 Jan 2010 18:13:21 +0000 (13:13 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/opts.nit
src/compiling/compiling.nit
src/metamodel/static_type.nit
src/mmloader.nit
src/nitdoc.nit
src/syntax/icode_generation.nit
src/syntax/mmbuilder.nit
src/syntax/syntax_base.nit
src/syntax/typing.nit

index 2850507..fd4a8a1 100644 (file)
@@ -69,9 +69,8 @@ class Option
 
        fun pretty_default: String
        do
-               if default_value != null then
-                       return " ({default_value})"
-               end
+               var dv = default_value
+               if dv != null then return " ({dv})"
                return ""
        end
 
index 5b3fd7f..f052c04 100644 (file)
@@ -49,7 +49,8 @@ redef class Program
        # Then execute the build.sh
        fun compile_prog_to_c
        do
-               tc.compdir.mkdir
+               var compdir = tc.compdir.as(not null)
+               compdir.mkdir
 
                var files = new Array[String]
                var includes = new ArraySet[String]
@@ -58,7 +59,7 @@ redef class Program
                files.add("$CLIBDIR/gc_static_objects_list.c")
                tc.info("Generating C code",1)
                for m in module.mhe.greaters_and_self do
-                       files.add("{tc.compdir}/{m.name}.{get_file_ending}.c")
+                       files.add("{compdir}/{m.name}.{get_file_ending}.c")
                        tc.info("Generating C code for module: {m.name}",2)
                        m.compile_separate_module(self)
                        var native_name = m.location.file.strip_extension(".nit")
@@ -70,10 +71,10 @@ redef class Program
                end
 
                tc.info("Generating main, tables and makefile ...",1)
-               files.add("{tc.compdir}/{module.name}._tables.c")
+               files.add("{compdir}/{module.name}._tables.c")
                compile_main
 
-               var fn = "{tc.compdir}/{module.name}._build.sh"
+               var fn = "{compdir}/{module.name}._build.sh"
                var f = new OFStream.open(fn)
                var verbose = ""
 
@@ -84,10 +85,10 @@ redef class Program
 
                f.write("#!/bin/sh\n")
                f.write("# This shell script is generated by NIT to compile the program {module.name}.\n")
-               f.write("CLIBDIR=\"{tc.clibdir}\"\n")
-               f.write("{tc.bindir}/gccx {verbose} -d {tc.compdir} -I $CLIBDIR {includes.join(" ")}")
+               f.write("CLIBDIR=\"{tc.clibdir.as(not null)}\"\n")
+               f.write("{tc.bindir.as(not null)}/gccx {verbose} -d {compdir} -I $CLIBDIR {includes.join(" ")}")
                if tc.output_file != null then 
-                       f.write(" -o {tc.output_file}")
+                       f.write(" -o {tc.output_file.as(not null)}")
                else if tc.ext_prefix.is_empty then
                        f.write(" -o {module.name}")
                else
@@ -114,7 +115,7 @@ redef class Program
                v.add_decl("#include <nit_common.h>")
                compile_tables_to_c(v)
                compile_main_part(v)
-               var f = new OFStream.open("{tc.compdir}/{module.name}._tables.c")
+               var f = new OFStream.open("{tc.compdir.as(not null)}/{module.name}._tables.c")
                f.write("/* This C file is generated by NIT to compile program {module.name}. */\n")
                for m in module.mhe.greaters_and_self do
                        f.write("#include \"{m.name}.{get_file_ending}.h\"\n")
@@ -136,7 +137,7 @@ redef class MMModule
                if native_name.file_exists then v.add_decl("#include <{native_name.basename("")}>")
                declare_class_tables_to_c(v)
                compile_mod_to_c(v)
-               var f = new OFStream.open("{tc.compdir}/{name}.{program.get_file_ending}.h")
+               var f = new OFStream.open("{tc.compdir.as(not null)}/{name}.{program.get_file_ending}.h")
                f.write("/* This C header file is generated by NIT to compile modules and programs that requires {name}. */\n")
                f.write("#ifndef {name}{program.get_file_ending}\n")
                f.write("#define {name}{program.get_file_ending}\n")
@@ -147,7 +148,7 @@ redef class MMModule
                f.write("#endif\n")
                f.close
 
-               f = new OFStream.open("{tc.compdir}/{name}.{program.get_file_ending}.c")
+               f = new OFStream.open("{tc.compdir.as(not null)}/{name}.{program.get_file_ending}.c")
                f.write("/* This C file is generated by NIT to compile module {name}. */\n")
                f.write("#include \"{name}.{program.get_file_ending}.h\"\n")
                for s in v.ctx.instrs do
index 3c34a9b..063559e 100644 (file)
@@ -144,9 +144,8 @@ class MMSignature
                        end
                        s.append("({a.join(",")})")
                end
-               if _return_type != null then
-                       s.append(": {_return_type}")
-               end
+               var rt = _return_type
+               if rt != null then s.append(": {rt}")
                return s.to_s
        end
 
index 04c3a98..4dfc361 100644 (file)
@@ -38,10 +38,11 @@ special Comparable
        end
 
        redef fun to_s: String do
-               if location == null then
+               var l = location
+               if l == null then
                        return text
                else
-                       return "{location}: {text}"
+                       return "{l}: {text}"
                end
        end
 end
index 7d4358d..4582f8e 100644 (file)
@@ -187,6 +187,7 @@ special AbstractCompiler
                add("<a href=\"overview.html\"><b>Overview</b></a>&nbsp; <a href=\"index-1.html\"><b>Index</b></a>&nbsp; <a href=\"index.html\" target=\"_top\"><b>With Frames</b></a>\n")
                add("</td></tr></table>")
                add("Visibility: ")
+               var module = module
                if (not inside_mode and not intrude_mode) or module == null then
                        add("<b>Public</b>&nbsp; ")
                else
index 15255a7..d021373 100644 (file)
@@ -1034,8 +1034,8 @@ redef class AStringFormExpr
                var ionce = new IOnce
                var reg = v.expr(ionce, stype)
                v.seq = ionce.body
-               var ns = v.expr(new INative("BOX_NativeString(\"{_cstring}\")", null), v.visitor.type_nativestring)
-               var ni = v.expr(new INative("TAG_Int({_cstring_length})", null), v.visitor.type_int)
+               var ns = v.expr(new INative("BOX_NativeString(\"{_cstring.as(not null)}\")", null), v.visitor.type_nativestring)
+               var ni = v.expr(new INative("TAG_Int({_cstring_length.as(not null)})", null), v.visitor.type_int)
                var prop = v.visitor.get_method(stype, once "with_native".to_symbol)
                var e = v.expr(new INew(stype, prop, [ns, ni]), stype)
                v.add_assignment(reg, e)
index 3b7951f..5d3efc1 100644 (file)
@@ -960,7 +960,7 @@ redef class AAttrPropdef
                        var t0 = n_type.get_stype(v)
                        if t0 != null then t = t0 else return
                else
-                       v.error(self, "Not yet implemented: Attribute definition {_prop.local_class}::{_prop} requires an explicit type.")
+                       v.error(self, "Not yet implemented: Attribute definition {prop.local_class}::{prop} requires an explicit type.")
                        return
                end
 
index 512ccf4..f4060f1 100644 (file)
@@ -477,8 +477,9 @@ special Visitor
                                node = n
                        end
                end
+               assert stype != null
                for n in nodes do
-                       if not n.stype < stype.as(not null) then
+                       if not n.stype < stype then
                                if node == null then
                                        error(n, "Type error: no most general type. Got {n.stype} and {stype}.")
                                else
index a1e8b64..fea49b7 100644 (file)
@@ -118,14 +118,14 @@ special AbsSyntaxVisitor
                else if candidates.length > 0 then
                        var a = new Array[String]
                        for p in candidates do
-                               a.add("{p.full_name}{p.signature}")
+                               a.add("{p.full_name}{p.signature.as(not null)}")
                        end
                        v.error(n, "Error: Conflicting default constructor to call for {c}: {a.join(", ")}.")
                        return null
                else if false_candidates.length > 0 then
                        var a = new Array[String]
                        for p in false_candidates do
-                               a.add("{p.full_name}{p.signature}")
+                               a.add("{p.full_name}{p.signature.as(not null)}")
                        end
                        v.error(n, "Error: there is no available compatible constrctor in {c}. Discarded candidates are {a.join(", ")}.")
                        return null
@@ -1338,12 +1338,11 @@ redef class ASuperInitCall
                else if cla == prev_class then
                        v.error(self, "Error: Only one super constructor invocation of class {cla} is allowed.")
                else
-                       var last_is_found = prev_class == null
                        for c in order do
                                if c == prev_class then
-                                       last_is_found = true
+                                       prev_class = null
                                else if c == cla then
-                                       if not last_is_found then
+                                       if prev_class != null then
                                                v.error(self, "Error: Constructor of {c} must be invoked before constructor of {prev_class}")
                                        end
                                        esic.add(property)