From a9260e4d0a05b1cb1e772ace9d458d673c5faf64 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Mon, 18 Jan 2010 13:13:21 -0500 Subject: [PATCH] syntax: fix code using superstrings with nullables Signed-off-by: Jean Privat --- lib/opts.nit | 5 ++--- src/compiling/compiling.nit | 21 +++++++++++---------- src/metamodel/static_type.nit | 5 ++--- src/mmloader.nit | 5 +++-- src/nitdoc.nit | 1 + src/syntax/icode_generation.nit | 4 ++-- src/syntax/mmbuilder.nit | 2 +- src/syntax/syntax_base.nit | 3 ++- src/syntax/typing.nit | 9 ++++----- 9 files changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/opts.nit b/lib/opts.nit index 2850507..fd4a8a1 100644 --- a/lib/opts.nit +++ b/lib/opts.nit @@ -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 diff --git a/src/compiling/compiling.nit b/src/compiling/compiling.nit index 5b3fd7f..f052c04 100644 --- a/src/compiling/compiling.nit +++ b/src/compiling/compiling.nit @@ -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 ") 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 diff --git a/src/metamodel/static_type.nit b/src/metamodel/static_type.nit index 3c34a9b..063559e 100644 --- a/src/metamodel/static_type.nit +++ b/src/metamodel/static_type.nit @@ -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 diff --git a/src/mmloader.nit b/src/mmloader.nit index 04c3a98..4dfc361 100644 --- a/src/mmloader.nit +++ b/src/mmloader.nit @@ -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 diff --git a/src/nitdoc.nit b/src/nitdoc.nit index 7d4358d..4582f8e 100644 --- a/src/nitdoc.nit +++ b/src/nitdoc.nit @@ -187,6 +187,7 @@ special AbstractCompiler add("Overview  Index  With Frames\n") add("") add("Visibility: ") + var module = module if (not inside_mode and not intrude_mode) or module == null then add("Public  ") else diff --git a/src/syntax/icode_generation.nit b/src/syntax/icode_generation.nit index 15255a7..d021373 100644 --- a/src/syntax/icode_generation.nit +++ b/src/syntax/icode_generation.nit @@ -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) diff --git a/src/syntax/mmbuilder.nit b/src/syntax/mmbuilder.nit index 3b7951f..5d3efc1 100644 --- a/src/syntax/mmbuilder.nit +++ b/src/syntax/mmbuilder.nit @@ -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 diff --git a/src/syntax/syntax_base.nit b/src/syntax/syntax_base.nit index 512ccf4..f4060f1 100644 --- a/src/syntax/syntax_base.nit +++ b/src/syntax/syntax_base.nit @@ -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 diff --git a/src/syntax/typing.nit b/src/syntax/typing.nit index a1e8b64..fea49b7 100644 --- a/src/syntax/typing.nit +++ b/src/syntax/typing.nit @@ -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) -- 1.7.9.5