nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: compiler: introduce and use `MType::is_c_primitive`
[nit.git]
/
src
/
compiler
/
abstract_compiler.nit
diff --git
a/src/compiler/abstract_compiler.nit
b/src/compiler/abstract_compiler.nit
index
5800bad
..
c3952e3
100644
(file)
--- a/
src/compiler/abstract_compiler.nit
+++ b/
src/compiler/abstract_compiler.nit
@@
-1399,7
+1399,7
@@
abstract class AbstractCompilerVisitor
var recv
var ctype = mtype.ctype
assert mtype.mclass.name != "NativeArray"
var recv
var ctype = mtype.ctype
assert mtype.mclass.name != "NativeArray"
- if ctype == "val*" then
+ if not mtype.is_c_primitive then
recv = init_instance(mtype)
else if ctype == "char*" then
recv = new_expr("NULL/*special!*/", mtype)
recv = init_instance(mtype)
else if ctype == "char*" then
recv = new_expr("NULL/*special!*/", mtype)
@@
-1785,12
+1785,16
@@
redef class MType
# Short name of the `ctype` to use in unions
fun ctypename: String do return "val"
# Short name of the `ctype` to use in unions
fun ctypename: String do return "val"
+
+ # Is the associated C type a primitive one?
+ #
+ # ENSURE `result == (ctype != "val*")`
+ fun is_c_primitive: Bool do return false
end
redef class MClassType
end
redef class MClassType
- redef fun ctype: String
- do
+ redef var ctype is lazy do
if mclass.name == "Int" then
return "long"
else if mclass.name == "Bool" then
if mclass.name == "Int" then
return "long"
else if mclass.name == "Bool" then
@@
-1808,6
+1812,8
@@
redef class MClassType
end
end
end
end
+ redef var is_c_primitive is lazy do return ctype != "val*"
+
redef fun ctype_extern: String
do
if mclass.kind == extern_kind then
redef fun ctype_extern: String
do
if mclass.kind == extern_kind then
@@
-2297,7
+2303,7
@@
redef class AAttrPropdef
if is_lazy then
var set
var ret = self.mpropdef.static_mtype
if is_lazy then
var set
var ret = self.mpropdef.static_mtype
- var useiset = ret.ctype == "val*" and not ret isa MNullableType
+ var useiset = not ret.is_c_primitive and not ret isa MNullableType
var guard = self.mlazypropdef.mproperty
if useiset then
set = v.isset_attribute(self.mpropdef.mproperty, recv)
var guard = self.mlazypropdef.mproperty
if useiset then
set = v.isset_attribute(self.mpropdef.mproperty, recv)
@@
-2325,7
+2331,7
@@
redef class AAttrPropdef
v.write_attribute(self.mpropdef.mproperty, arguments.first, arguments[1])
if is_lazy then
var ret = self.mpropdef.static_mtype
v.write_attribute(self.mpropdef.mproperty, arguments.first, arguments[1])
if is_lazy then
var ret = self.mpropdef.static_mtype
- var useiset = ret.ctype == "val*" and not ret isa MNullableType
+ var useiset = not ret.is_c_primitive and not ret isa MNullableType
if not useiset then
v.write_attribute(self.mlazypropdef.mproperty, arguments.first, v.bool_instance(true))
end
if not useiset then
v.write_attribute(self.mlazypropdef.mproperty, arguments.first, v.bool_instance(true))
end
@@
-2834,7
+2840,7
@@
redef class AAsNotnullExpr
var i = v.expr(self.n_expr, null)
if v.compiler.modelbuilder.toolcontext.opt_no_check_assert.value then return i
var i = v.expr(self.n_expr, null)
if v.compiler.modelbuilder.toolcontext.opt_no_check_assert.value then return i
- if i.mtype.ctype != "val*" then return i
+ if i.mtype.is_c_primitive then return i
v.add("if (unlikely({i} == NULL)) \{")
v.add_abort("Cast failed")
v.add("if (unlikely({i} == NULL)) \{")
v.add_abort("Cast failed")