9d1297bbca4f499a2f324d45507c1b74cee4ed20
[nit.git] / src / loader.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2012 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Loading of Nit source files
18 module loader
19
20 import modelbuilder_base
21
22 redef class ToolContext
23 # Option --path
24 var opt_path = new OptionArray("Set include path for loaders (may be used more than once)", "-I", "--path")
25
26 # Option --only-metamodel
27 var opt_only_metamodel = new OptionBool("Stop after meta-model processing", "--only-metamodel")
28
29 # Option --only-parse
30 var opt_only_parse = new OptionBool("Only proceed to parse step of loaders", "--only-parse")
31
32 redef init
33 do
34 super
35 option_context.add_option(opt_path, opt_only_parse, opt_only_metamodel)
36 end
37 end
38
39 redef class ModelBuilder
40 redef init
41 do
42 super
43
44 # Setup the paths value
45 paths.append(toolcontext.opt_path.value)
46
47 var path_env = "NIT_PATH".environ
48 if not path_env.is_empty then
49 paths.append(path_env.split_with(':'))
50 end
51
52 var nit_dir = toolcontext.nit_dir
53 var libname = "{nit_dir}/lib"
54 if libname.file_exists then paths.add(libname)
55 end
56
57 # Load a bunch of modules.
58 # `modules` can contains filenames or module names.
59 # Imported modules are automatically loaded and modelized.
60 # The result is the corresponding model elements.
61 # Errors and warnings are printed with the toolcontext.
62 #
63 # Note: class and property model elements are not analysed.
64 fun parse(modules: Sequence[String]): Array[MModule]
65 do
66 var time0 = get_time
67 # Parse and recursively load
68 self.toolcontext.info("*** PARSE ***", 1)
69 var mmodules = new ArraySet[MModule]
70 for a in modules do
71 var nmodule = self.load_module(a)
72 if nmodule == null then continue # Skip error
73 # Load imported module
74 build_module_importation(nmodule)
75
76 mmodules.add(nmodule.mmodule.as(not null))
77 end
78 var time1 = get_time
79 self.toolcontext.info("*** END PARSE: {time1-time0} ***", 2)
80
81 self.toolcontext.check_errors
82
83 if toolcontext.opt_only_parse.value then
84 self.toolcontext.info("*** ONLY PARSE...", 1)
85 exit(0)
86 end
87
88 return mmodules.to_a
89 end
90
91 # Load recursively all modules of the group `mgroup`.
92 # See `parse` for details.
93 fun parse_group(mgroup: MGroup): Array[MModule]
94 do
95 var res = new Array[MModule]
96 visit_group(mgroup)
97 for mg in mgroup.in_nesting.smallers do
98 for mp in mg.module_paths do
99 var nmodule = self.load_module(mp.filepath)
100 if nmodule == null then continue # Skip error
101 # Load imported module
102 build_module_importation(nmodule)
103
104 res.add(nmodule.mmodule.as(not null))
105 end
106 end
107 return res
108 end
109
110 # Load a bunch of modules and groups.
111 #
112 # Each name can be:
113 #
114 # * a path to a module, a group or a directory of projects.
115 # * a short name of a module or a group that are looked in the `paths` (-I)
116 #
117 # Then, for each entry, if it is:
118 #
119 # * a module, then is it parser and returned.
120 # * a group then recursively all its modules are parsed.
121 # * a directory of projects then all the modules of all projects are parsed.
122 # * else an error is displayed.
123 #
124 # See `parse` for details.
125 fun parse_full(names: Sequence[String]): Array[MModule]
126 do
127 var time0 = get_time
128 # Parse and recursively load
129 self.toolcontext.info("*** PARSE ***", 1)
130 var mmodules = new ArraySet[MModule]
131 for a in names do
132 # Case of a group
133 var mgroup = self.get_mgroup(a)
134 if mgroup != null then
135 mmodules.add_all parse_group(mgroup)
136 continue
137 end
138
139 # Case of a directory that is not a group
140 var stat = a.to_path.stat
141 if stat != null and stat.is_dir then
142 self.toolcontext.info("look in directory {a}", 2)
143 var fs = a.files
144 # Try each entry as a group or a module
145 for f in fs do
146 var af = a/f
147 mgroup = get_mgroup(af)
148 if mgroup != null then
149 mmodules.add_all parse_group(mgroup)
150 continue
151 end
152 var mp = identify_file(af)
153 if mp != null then
154 var nmodule = self.load_module(af)
155 if nmodule == null then continue # Skip error
156 build_module_importation(nmodule)
157 mmodules.add(nmodule.mmodule.as(not null))
158 else
159 self.toolcontext.info("ignore file {af}", 2)
160 end
161 end
162 continue
163 end
164
165 var nmodule = self.load_module(a)
166 if nmodule == null then continue # Skip error
167 # Load imported module
168 build_module_importation(nmodule)
169
170 mmodules.add(nmodule.mmodule.as(not null))
171 end
172 var time1 = get_time
173 self.toolcontext.info("*** END PARSE: {time1-time0} ***", 2)
174
175 self.toolcontext.check_errors
176
177 if toolcontext.opt_only_parse.value then
178 self.toolcontext.info("*** ONLY PARSE...", 1)
179 exit(0)
180 end
181
182 return mmodules.to_a
183 end
184
185 # The list of directories to search for top level modules
186 # The list is initially set with:
187 #
188 # * the toolcontext --path option
189 # * the NIT_PATH environment variable
190 # * `toolcontext.nit_dir`
191 # Path can be added (or removed) by the client
192 var paths = new Array[String]
193
194 # Like (and used by) `get_mmodule_by_name` but just return the ModulePath
195 fun search_mmodule_by_name(anode: nullable ANode, mgroup: nullable MGroup, name: String): nullable ModulePath
196 do
197 # First, look in groups
198 var c = mgroup
199 while c != null do
200 var dirname = c.filepath
201 if dirname == null then break # virtual group
202 if dirname.has_suffix(".nit") then break # singleton project
203
204 # Second, try the directory to find a file
205 var try_file = dirname + "/" + name + ".nit"
206 if try_file.file_exists then
207 var res = self.identify_file(try_file.simplify_path)
208 assert res != null
209 return res
210 end
211
212 # Third, try if the requested module is itself a group
213 try_file = dirname + "/" + name + "/" + name + ".nit"
214 if try_file.file_exists then
215 var res = self.identify_file(try_file.simplify_path)
216 assert res != null
217 return res
218 end
219
220 c = c.parent
221 end
222
223 # Look at some known directories
224 var lookpaths = self.paths
225
226 # Look in the directory of the group project also (even if not explicitly in the path)
227 if mgroup != null then
228 # path of the root group
229 var dirname = mgroup.mproject.root.filepath
230 if dirname != null then
231 dirname = dirname.join_path("..").simplify_path
232 if not lookpaths.has(dirname) and dirname.file_exists then
233 lookpaths = lookpaths.to_a
234 lookpaths.add(dirname)
235 end
236 end
237 end
238
239 var candidate = search_module_in_paths(anode.hot_location, name, lookpaths)
240
241 if candidate == null then
242 if mgroup != null then
243 error(anode, "Error: cannot find module {name} from {mgroup.name}. tried {lookpaths.join(", ")}")
244 else
245 error(anode, "Error: cannot find module {name}. tried {lookpaths.join(", ")}")
246 end
247 return null
248 end
249 return candidate
250 end
251
252 # Get a module by its short name; if required, the module is loaded, parsed and its hierarchies computed.
253 # If `mgroup` is set, then the module search starts from it up to the top level (see `paths`);
254 # if `mgroup` is null then the module is searched in the top level only.
255 # If no module exists or there is a name conflict, then an error on `anode` is displayed and null is returned.
256 fun get_mmodule_by_name(anode: nullable ANode, mgroup: nullable MGroup, name: String): nullable MModule
257 do
258 var path = search_mmodule_by_name(anode, mgroup, name)
259 if path == null then return null # Forward error
260 var res = self.load_module(path.filepath)
261 if res == null then return null # Forward error
262 # Load imported module
263 build_module_importation(res)
264 return res.mmodule.as(not null)
265 end
266
267 # Search a module `name` from path `lookpaths`.
268 # If found, the path of the file is returned
269 private fun search_module_in_paths(location: nullable Location, name: String, lookpaths: Collection[String]): nullable ModulePath
270 do
271 var candidate: nullable String = null
272 for dirname in lookpaths do
273 var try_file = (dirname + "/" + name + ".nit").simplify_path
274 if try_file.file_exists then
275 if candidate == null then
276 candidate = try_file
277 else if candidate != try_file then
278 # try to disambiguate conflicting modules
279 var abs_candidate = module_absolute_path(candidate)
280 var abs_try_file = module_absolute_path(try_file)
281 if abs_candidate != abs_try_file then
282 toolcontext.error(location, "Error: conflicting module file for {name}: {candidate} {try_file}")
283 end
284 end
285 end
286 try_file = (dirname + "/" + name + "/" + name + ".nit").simplify_path
287 if try_file.file_exists then
288 if candidate == null then
289 candidate = try_file
290 else if candidate != try_file then
291 # try to disambiguate conflicting modules
292 var abs_candidate = module_absolute_path(candidate)
293 var abs_try_file = module_absolute_path(try_file)
294 if abs_candidate != abs_try_file then
295 toolcontext.error(location, "Error: conflicting module file for {name}: {candidate} {try_file}")
296 end
297 end
298 end
299 end
300 if candidate == null then return null
301 return identify_file(candidate)
302 end
303
304 # Cache for `identify_file` by realpath
305 private var identified_files_by_path = new HashMap[String, nullable ModulePath]
306
307 # All the currently identified modules.
308 # See `identify_file`.
309 var identified_files = new Array[ModulePath]
310
311 # Identify a source file
312 # Load the associated project and groups if required
313 #
314 # Silently return `null` if `path` is not a valid module path.
315 fun identify_file(path: String): nullable ModulePath
316 do
317 # special case for not a nit file
318 if path.file_extension != "nit" then
319 # search dirless files in known -I paths
320 if path.dirname == "" then
321 var res = search_module_in_paths(null, path, self.paths)
322 if res != null then return res
323 end
324
325 # Found nothing? maybe it is a group...
326 var candidate = null
327 if path.file_exists then
328 var mgroup = get_mgroup(path)
329 if mgroup != null then
330 var owner_path = mgroup.filepath.join_path(mgroup.name + ".nit")
331 if owner_path.file_exists then candidate = owner_path
332 end
333 end
334
335 if candidate == null then
336 return null
337 end
338 path = candidate
339 end
340
341 # Fast track, the path is already known
342 var pn = path.basename(".nit")
343 var rp = module_absolute_path(path)
344 if identified_files_by_path.has_key(rp) then return identified_files_by_path[rp]
345
346 # Search for a group
347 var mgrouppath = path.join_path("..").simplify_path
348 var mgroup = get_mgroup(mgrouppath)
349
350 if mgroup == null then
351 # singleton project
352 var mproject = new MProject(pn, model)
353 mgroup = new MGroup(pn, mproject, null) # same name for the root group
354 mgroup.filepath = path
355 mproject.root = mgroup
356 toolcontext.info("found project `{pn}` at {path}", 2)
357 end
358
359 var res = new ModulePath(pn, path, mgroup)
360 mgroup.module_paths.add(res)
361
362 identified_files_by_path[rp] = res
363 identified_files.add(res)
364 return res
365 end
366
367 # Groups by path
368 private var mgroups = new HashMap[String, nullable MGroup]
369
370 # Return the mgroup associated to a directory path.
371 # If the directory is not a group null is returned.
372 #
373 # Note: `paths` is also used to look for mgroups
374 fun get_mgroup(dirpath: String): nullable MGroup
375 do
376 if not dirpath.file_exists then do
377 for p in paths do
378 var try = p / dirpath
379 if try.file_exists then
380 dirpath = try
381 break label
382 end
383 end
384 return null
385 end label
386
387 var rdp = module_absolute_path(dirpath)
388 if mgroups.has_key(rdp) then
389 return mgroups[rdp]
390 end
391
392 # Hack, a group is determined by one of the following:
393 # * the presence of a honomymous nit file
394 # * the fact that the directory is named `src`
395 # * the fact that there is a sub-directory named `src`
396 var pn = rdp.basename(".nit")
397 var mp = dirpath.join_path(pn + ".nit").simplify_path
398
399 # dirpath2 is the root directory
400 # dirpath is the src subdirectory directory, if any, else it is the same that dirpath2
401 var dirpath2 = dirpath
402 if not mp.file_exists then
403 if pn == "src" then
404 # With a src directory, the group name is the name of the parent directory
405 dirpath2 = rdp.dirname
406 pn = dirpath2.basename("")
407 else
408 # Check a `src` subdirectory
409 dirpath = dirpath2 / "src"
410 if not dirpath.file_exists then
411 # All rules failed, so return null
412 return null
413 end
414 end
415 end
416
417 # check parent directory
418 var parentpath = dirpath2.join_path("..").simplify_path
419 var parent = get_mgroup(parentpath)
420
421 var mgroup
422 if parent == null then
423 # no parent, thus new project
424 var mproject = new MProject(pn, model)
425 mgroup = new MGroup(pn, mproject, null) # same name for the root group
426 mproject.root = mgroup
427 toolcontext.info("found project `{mproject}` at {dirpath}", 2)
428 else
429 mgroup = new MGroup(pn, parent.mproject, parent)
430 toolcontext.info("found sub group `{mgroup.full_name}` at {dirpath}", 2)
431 end
432
433 # search documentation
434 # in src first so the documentation of the project code can be distinct for the documentation of the project usage
435 var readme = dirpath.join_path("README.md")
436 if not readme.file_exists then readme = dirpath.join_path("README")
437 if not readme.file_exists then readme = dirpath2.join_path("README.md")
438 if not readme.file_exists then readme = dirpath2.join_path("README")
439 if readme.file_exists then
440 var mdoc = load_markdown(readme)
441 mgroup.mdoc = mdoc
442 mdoc.original_mentity = mgroup
443 end
444
445 mgroup.filepath = dirpath
446 mgroups[module_absolute_path(dirpath)] = mgroup
447 mgroups[module_absolute_path(dirpath2)] = mgroup
448 return mgroup
449 end
450
451 # Load a markdown file as a documentation object
452 fun load_markdown(filepath: String): MDoc
453 do
454 var mdoc = new MDoc(new Location(new SourceFile.from_string(filepath, ""),0,0,0,0))
455 var s = new FileReader.open(filepath)
456 while not s.eof do
457 mdoc.content.add(s.read_line)
458 end
459 return mdoc
460 end
461
462 # Force the identification of all ModulePath of the group and sub-groups.
463 fun visit_group(mgroup: MGroup) do
464 var p = mgroup.filepath
465 for f in p.files do
466 var fp = p/f
467 var g = get_mgroup(fp)
468 if g != null then visit_group(g)
469 identify_file(fp)
470 end
471 end
472
473 # Transform relative paths (starting with '../') into absolute paths
474 private fun module_absolute_path(path: String): String do
475 return getcwd.join_path(path).simplify_path
476 end
477
478 # Try to load a module AST using a path.
479 # Display an error if there is a problem (IO / lexer / parser) and return null
480 fun load_module_ast(filename: String): nullable AModule
481 do
482 if filename.file_extension != "nit" then
483 self.toolcontext.error(null, "Error: file {filename} is not a valid nit module.")
484 return null
485 end
486 if not filename.file_exists then
487 self.toolcontext.error(null, "Error: file {filename} not found.")
488 return null
489 end
490
491 self.toolcontext.info("load module {filename}", 2)
492
493 # Load the file
494 var file = new FileReader.open(filename)
495 var lexer = new Lexer(new SourceFile(filename, file))
496 var parser = new Parser(lexer)
497 var tree = parser.parse
498 file.close
499
500 # Handle lexer and parser error
501 var nmodule = tree.n_base
502 if nmodule == null then
503 var neof = tree.n_eof
504 assert neof isa AError
505 error(neof, neof.message)
506 return null
507 end
508
509 return nmodule
510 end
511
512 # Remove Nit source files from a list of arguments.
513 #
514 # Items of `args` that can be loaded as a nit file will be removed from `args` and returned.
515 fun filter_nit_source(args: Array[String]): Array[String]
516 do
517 var keep = new Array[String]
518 var res = new Array[String]
519 for a in args do
520 var l = identify_file(a)
521 if l == null then
522 keep.add a
523 else
524 res.add a
525 end
526 end
527 args.clear
528 args.add_all(keep)
529 return res
530 end
531
532 # Try to load a module using a path.
533 # Display an error if there is a problem (IO / lexer / parser) and return null.
534 # Note: usually, you do not need this method, use `get_mmodule_by_name` instead.
535 #
536 # The MModule is created however, the importation is not performed,
537 # therefore you should call `build_module_importation`.
538 fun load_module(filename: String): nullable AModule
539 do
540 # Look for the module
541 var file = identify_file(filename)
542 if file == null then
543 if filename.file_exists then
544 toolcontext.error(null, "Error: `{filename}` is not a Nit source file.")
545 else
546 toolcontext.error(null, "Error: cannot find module `{filename}`.")
547 end
548 return null
549 end
550
551 # Already known and loaded? then return it
552 var mmodule = file.mmodule
553 if mmodule != null then
554 return mmodule2nmodule[mmodule]
555 end
556
557 # Load it manually
558 var nmodule = load_module_ast(file.filepath)
559 if nmodule == null then return null # forward error
560
561 # build the mmodule and load imported modules
562 mmodule = build_a_mmodule(file.mgroup, file.name, nmodule)
563
564 if mmodule == null then return null # forward error
565
566 # Update the file information
567 file.mmodule = mmodule
568
569 return nmodule
570 end
571
572 # Injection of a new module without source.
573 # Used by the interpreter.
574 fun load_rt_module(parent: nullable MModule, nmodule: AModule, mod_name: String): nullable AModule
575 do
576 # Create the module
577
578 var mgroup = null
579 if parent != null then mgroup = parent.mgroup
580 var mmodule = new MModule(model, mgroup, mod_name, nmodule.location)
581 nmodule.mmodule = mmodule
582 nmodules.add(nmodule)
583 self.mmodule2nmodule[mmodule] = nmodule
584
585 if parent!= null then
586 var imported_modules = new Array[MModule]
587 imported_modules.add(parent)
588 mmodule.set_visibility_for(parent, intrude_visibility)
589 mmodule.set_imported_mmodules(imported_modules)
590 else
591 build_module_importation(nmodule)
592 end
593
594 return nmodule
595 end
596
597 # Visit the AST and create the `MModule` object
598 private fun build_a_mmodule(mgroup: nullable MGroup, mod_name: String, nmodule: AModule): nullable MModule
599 do
600 # Check the module name
601 var decl = nmodule.n_moduledecl
602 if decl != null then
603 var decl_name = decl.n_name.n_id.text
604 if decl_name != mod_name then
605 error(decl.n_name, "Error: module name missmatch; declared {decl_name} file named {mod_name}")
606 end
607 end
608
609 # Check for conflicting module names in the project
610 if mgroup != null then
611 var others = model.get_mmodules_by_name(mod_name)
612 if others != null then for other in others do
613 if other.mgroup!= null and other.mgroup.mproject == mgroup.mproject then
614 var node: ANode
615 if decl == null then node = nmodule else node = decl.n_name
616 error(node, "Error: A module named `{other.full_name}` already exists at {other.location}")
617 break
618 end
619 end
620 end
621
622 # Create the module
623 var mmodule = new MModule(model, mgroup, mod_name, nmodule.location)
624 nmodule.mmodule = mmodule
625 nmodules.add(nmodule)
626 self.mmodule2nmodule[mmodule] = nmodule
627
628 var source = nmodule.location.file
629 if source != null then
630 assert source.mmodule == null
631 source.mmodule = mmodule
632 end
633
634 if decl != null then
635 # Extract documentation
636 var ndoc = decl.n_doc
637 if ndoc != null then
638 var mdoc = ndoc.to_mdoc
639 mmodule.mdoc = mdoc
640 mdoc.original_mentity = mmodule
641 else
642 advice(decl, "missing-doc", "Documentation warning: Undocumented module `{mmodule}`")
643 end
644 # Is the module a test suite?
645 mmodule.is_test_suite = not decl.get_annotations("test_suite").is_empty
646 end
647
648 return mmodule
649 end
650
651 # Analyze the module importation and fill the module_importation_hierarchy
652 #
653 # Unless you used `load_module`, the importation is already done and this method does a no-op.
654 fun build_module_importation(nmodule: AModule)
655 do
656 if nmodule.is_importation_done then return
657 nmodule.is_importation_done = true
658 var mmodule = nmodule.mmodule.as(not null)
659 var stdimport = true
660 var imported_modules = new Array[MModule]
661 for aimport in nmodule.n_imports do
662 stdimport = false
663 if not aimport isa AStdImport then
664 continue
665 end
666 var mgroup = mmodule.mgroup
667 if aimport.n_name.n_quad != null then mgroup = null # Start from top level
668 for grp in aimport.n_name.n_path do
669 var path = search_mmodule_by_name(grp, mgroup, grp.text)
670 if path == null then return # Skip error
671 mgroup = path.mgroup
672 end
673 var mod_name = aimport.n_name.n_id.text
674 var sup = self.get_mmodule_by_name(aimport.n_name, mgroup, mod_name)
675 if sup == null then continue # Skip error
676 aimport.mmodule = sup
677 imported_modules.add(sup)
678 var mvisibility = aimport.n_visibility.mvisibility
679 if mvisibility == protected_visibility then
680 error(aimport.n_visibility, "Error: only properties can be protected.")
681 return
682 end
683 if sup == mmodule then
684 error(aimport.n_name, "Error: Dependency loop in module {mmodule}.")
685 end
686 if sup.in_importation < mmodule then
687 error(aimport.n_name, "Error: Dependency loop between modules {mmodule} and {sup}.")
688 return
689 end
690 mmodule.set_visibility_for(sup, mvisibility)
691 end
692 if stdimport then
693 var mod_name = "standard"
694 var sup = self.get_mmodule_by_name(nmodule, null, mod_name)
695 if sup != null then # Skip error
696 imported_modules.add(sup)
697 mmodule.set_visibility_for(sup, public_visibility)
698 end
699 end
700 self.toolcontext.info("{mmodule} imports {imported_modules.join(", ")}", 3)
701 mmodule.set_imported_mmodules(imported_modules)
702
703 # Force standard to be public if imported
704 for sup in mmodule.in_importation.greaters do
705 if sup.name == "standard" then
706 mmodule.set_visibility_for(sup, public_visibility)
707 end
708 end
709
710 # TODO: Correctly check for useless importation
711 # It is even doable?
712 var directs = mmodule.in_importation.direct_greaters
713 for nim in nmodule.n_imports do
714 if not nim isa AStdImport then continue
715 var im = nim.mmodule
716 if im == null then continue
717 if directs.has(im) then continue
718 # This generates so much noise that it is simpler to just comment it
719 #warning(nim, "Warning: possible useless importation of {im}")
720 end
721 end
722
723 # All the loaded modules
724 var nmodules = new Array[AModule]
725
726 # Register the nmodule associated to each mmodule
727 #
728 # Public clients need to use `mmodule2node` to access stuff.
729 private var mmodule2nmodule = new HashMap[MModule, AModule]
730
731 # Retrieve the associated AST node of a mmodule.
732 # This method is used to associate model entity with syntactic entities.
733 #
734 # If the module is not associated with a node, returns null.
735 fun mmodule2node(mmodule: MModule): nullable AModule
736 do
737 return mmodule2nmodule.get_or_null(mmodule)
738 end
739 end
740
741 # File-system location of a module (file) that is identified but not always loaded.
742 class ModulePath
743 # The name of the module
744 # (it's the basename of the filepath)
745 var name: String
746
747 # The human path of the module
748 var filepath: String
749
750 # The group (and the project) of the possible module
751 var mgroup: MGroup
752
753 # The loaded module (if any)
754 var mmodule: nullable MModule = null
755
756 redef fun to_s do return filepath
757 end
758
759 redef class MGroup
760 # Modules paths associated with the group
761 var module_paths = new Array[ModulePath]
762
763 # Is the group interesting for a final user?
764 #
765 # Groups are mandatory in the model but for simple projects they are not
766 # always interesting.
767 #
768 # A interesting group has, at least, one of the following true:
769 #
770 # * it has 2 modules or more
771 # * it has a subgroup
772 # * it has a documentation
773 fun is_interesting: Bool
774 do
775 return module_paths.length > 1 or mmodules.length > 1 or not in_nesting.direct_smallers.is_empty or mdoc != null
776 end
777
778 end
779
780 redef class SourceFile
781 # Associated mmodule, once created
782 var mmodule: nullable MModule = null
783 end
784
785 redef class AStdImport
786 # The imported module once determined
787 var mmodule: nullable MModule = null
788 end
789
790 redef class AModule
791 # The associated MModule once build by a `ModelBuilder`
792 var mmodule: nullable MModule
793 # Flag that indicate if the importation is already completed
794 var is_importation_done: Bool = false
795 end