Methods without PNodes.
authorJean Privat <jean@pryen.org>
Sat, 27 Dec 2008 14:56:33 +0000 (09:56 -0500)
committerJean Privat <jean@pryen.org>
Sat, 27 Dec 2008 14:56:33 +0000 (09:56 -0500)
Unlike explicit methods, implicit methods are not associated with a PNode.
These changes bring up the infrastructure for such inplicit methods.

src/compiling/compiling_methods.nit
src/nitdoc.nit
src/syntax/mmbuilder.nit
src/syntax/syntax_base.nit

index 3706c57..ea4414f 100644 (file)
@@ -208,12 +208,13 @@ redef class MMMethod
        meth compile_call(v: CompilerVisitor, cargs: Array[String]): String
        do
                var i = self
-               assert i isa MMSrcMethod
-               if i.node isa AInternMethPropdef or 
-                       (i.local_class.name == (once "Array".to_symbol) and name == (once "[]".to_symbol))
-               then
-                       var e = i.do_compile_inside(v, cargs)
-                       return e
+               if i isa MMSrcMethod then
+                       if i isa MMMethSrcMethod and i.node isa AInternMethPropdef or 
+                               (i.local_class.name == (once "Array".to_symbol) and name == (once "[]".to_symbol))
+                       then
+                               var e = i.do_compile_inside(v, cargs)
+                               return e
+                       end
                end
                var ee = once "==".to_symbol
                var ne = once "!=".to_symbol
@@ -326,7 +327,10 @@ redef class MMSrcMethod
                var ctx_old = v.ctx
                v.ctx = new CContext
 
-               v.add_decl("struct trace_t trace = \{NULL, NULL, {node.line_number}, LOCATE_{cname}};")
+               var ln = 0
+               var s = self
+               if s.node != null then ln = s.node.line_number
+               v.add_decl("struct trace_t trace = \{NULL, NULL, {ln}, LOCATE_{cname}};")
                v.add_instr("trace.prev = tracehead; tracehead = &trace;")
                v.add_instr("trace.file = LOCATE_{module.name};")
                var s = do_compile_inside(v, args)
index 46cd1ed..9f55979 100644 (file)
@@ -488,7 +488,7 @@ special MMEntity
        redef meth doc
        do
                var n = node
-               if not node isa PPropdef then
+               if n == null or not node isa PPropdef then
                        return null
                end
                assert n isa PPropdef
index 129b50f..3a16ada 100644 (file)
@@ -234,9 +234,8 @@ redef class MMSrcLocalClass
                end
 
                if prop.global == null then
-                       #print "{prop.full_name} is an introduction"
                        prop.new_global
-                       prop.global.is_init = prop.node isa AConcreteInitPropdef
+                       prop.global.is_init = prop.is_init
                end
        end
 end
index deefdad..7d22308 100644 (file)
@@ -102,11 +102,13 @@ end
 redef class MMLocalProperty
        # The attached node (if any)
        meth node: PNode do return null
+
+       # Is the concrete method defined as init
+       meth is_init: Bool do return false
 end
 
 # Concrete NIT source attribute
 class MMSrcAttribute
-special MMLocalProperty
 special MMAttribute
        redef readable attr _node: AAttrPropdef
        init(name: Symbol, cla: MMLocalClass, n: AAttrPropdef)
@@ -118,7 +120,6 @@ end
 
 # Concrete NIT source method
 class MMSrcMethod
-special MMLocalProperty
 special MMMethod
 end
 
@@ -126,33 +127,35 @@ end
 class MMAttrImplementationMethod
 special MMSrcMethod
        redef readable attr _node: AAttrPropdef
+       init(name: Symbol, cla: MMLocalClass, n: AAttrPropdef)
+       do
+               super(name, cla)
+               _node = n
+       end
 end
 
 # Concrete NIT source method for an automatic read accesor
 class MMReadImplementationMethod
 special MMAttrImplementationMethod
-
        init(name: Symbol, cla: MMLocalClass, n: AAttrPropdef)
        do
-               super(name, cla)
-               _node = n
+               super(name, cla, n)
        end
 end
 
 # Concrete NIT source method for an automatic write accesor
 class MMWriteImplementationMethod
 special MMAttrImplementationMethod
-
        init(name: Symbol, cla: MMLocalClass, n: AAttrPropdef)
        do
-               super(name, cla)
-               _node = n
+               super(name, cla, n)
        end
 end
 
 # Concrete NIT source method for an explicit method
 class MMMethSrcMethod
 special MMSrcMethod
+       redef meth is_init do return _node isa AConcreteInitPropdef
        redef readable attr _node: AMethPropdef
        init(name: Symbol, cla: MMLocalClass, n: AMethPropdef)
        do
@@ -276,13 +279,20 @@ special Visitor
        # Display an error for a given syntax node
        meth error(n: PNode, s: String)
        do
-               _tc.error("{n.locate}: {s}")
+               _tc.error("{locate(n)}: {s}")
        end
 
        # Display a warning for a given syntax node
        meth warning(n: PNode, s: String)
        do
-               _tc.warning("{n.locate}: {s}")
+               _tc.warning("{locate(n)}: {s}")
+       end
+
+       #
+       meth locate(n: PNode): String
+       do
+               if n != null then return n.locate
+               return _module.filename
        end
 
        # Check conformity and display error