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