nullable: type, compile and test 'isset _attr'
[nit.git] / src / compiling / compiling_methods.nit
index 61f3267..3f79777 100644 (file)
@@ -455,6 +455,12 @@ end
 
 redef class MMAttribute
        # Compile a read acces on selffor a given reciever.
+       meth compile_isset(v: CompilerVisitor, n: PNode, recv: String): String
+       do
+               return "TAG_Bool({global.attr_access}({recv})!=NIT_NULL) /* isset {local_class}::{name}*/"
+       end
+
+       # Compile a read acces on selffor a given reciever.
        meth compile_read_access(v: CompilerVisitor, n: PNode, recv: String): String
        do
                var res = "{global.attr_access}({recv}) /*{local_class}::{name}*/"
@@ -1501,6 +1507,14 @@ redef class AAttrReassignExpr
        end
 end
 
+redef class AIssetAttrExpr
+       redef meth compile_expr(v)
+       do
+               var e = v.compile_expr(n_expr)
+               return prop.compile_isset(v, n_id, e)
+       end
+end
+
 redef class AAbsAbsSendExpr
        # Compile each argument and add them to the array
        meth compile_arguments_in(v: CompilerVisitor, cargs: Array[String])