syntax: syntax tree is trashed once no more needed
authorJean Privat <jean@pryen.org>
Sun, 26 Jul 2009 02:32:05 +0000 (22:32 -0400)
committerJean Privat <jean@pryen.org>
Mon, 27 Jul 2009 07:36:20 +0000 (03:36 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/nitdoc.nit
src/syntax/syntax.nit
src/syntax/syntax_base.nit

index 31276ed..b407967 100644 (file)
@@ -247,6 +247,7 @@ special AbstractCompiler
 
        init
        do
+               keep_ast = true
                super("nitdoc")
                option_context.add_option(opt_dir)
        end
index 68a1ebb..8a8f18e 100644 (file)
@@ -76,6 +76,13 @@ redef class MMSrcModule
 
                generate_icode(tc)
                tc.check_errors
+
+               if not tc.keep_ast then clear_ast
        end
 end
 
+redef class ToolContext
+       # Should the AST be preserved in source modules after syntax processing?
+       # Default is false.
+       readable writable var _keep_ast: Bool = false
+end
index b34d364..172092a 100644 (file)
@@ -24,8 +24,13 @@ import mmloader
 class MMSrcModule
 special MMModule
        # A source module can locate AST nodes of related MM entities
+       # Once a source module AST is no more needed, _nodes is set to null
+       # See ToolContext::keep_ast property in syntax.nit for details
        var _nodes: nullable HashMap[Object, nullable PNode] = new HashMap[Object, nullable PNode]
 
+       # Release the AST
+       fun clear_ast do _nodes = null
+
        # The related AST node
        fun node: AModule do return nodes(self).as(AModule)