From: Jean Privat Date: Fri, 22 Apr 2022 17:04:57 +0000 (-0400) Subject: Merge: doc: fixed some typos and other misc. corrections X-Git-Url: http://nitlanguage.org?hp=c1bfc9f2a7e8d49bdc3644ee233d9d03e299a542 Merge: doc: fixed some typos and other misc. corrections This PR is fairly basic and only contains the following changes: - Corrected various sentence structures, typos and text formatting across several markdown pages (language doc, README, etc.) Note: There are a few sections I would rewrite differently to sound more professional/neutral and to include more details about how the language behaves in certain cases, but I felt like it was outside of this PR's scope. Pull-Request: #2833 Reviewed-by: Jean Privat --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d4e5928..398ed14 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,7 @@ services: variables: NEO4J_AUTH: none + POSTGRES_HOST_AUTH_METHOD: trust cache: paths: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8850808..5292526 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,5 +18,5 @@ We are always open for suggestions or any other kind of contribution. If you do not want to submit code for some reason, you are always welcome to ask questions about the language or related topics via the issue system. You may also proof-read and correct documentation if you are willing! -All the documents on this repository are written in English, however most of our contributors are not native anglophones. +All the documents in this repository are written in English. However, most of our contributors are not native anglophones. Therefore we encourage people, especially those coming of an english-speaking culture to read the documentation available and submit patches to correct bad formulations, typos or related mistakes on our part through the usual system. diff --git a/README.md b/README.md index e499bbb..ddd682a 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Important files and directories: * lib/ Nit standard library * LICENCE License of the software * Makefile Bootstrap the Nit tools - * misc/ Some additional files for commons text editors and tools + * misc/ Some additional files for common text editors and tools * NOTICE.md List of the authors * README This file * share/ Common resources used by tools diff --git a/contrib/pep8analysis/src/parser/lexer.nit b/contrib/pep8analysis/src/parser/lexer.nit index c663dcd..f985cf7 100644 --- a/contrib/pep8analysis/src/parser/lexer.nit +++ b/contrib/pep8analysis/src/parser/lexer.nit @@ -255,7 +255,7 @@ redef class AError init init_error(message: String, loc: Location) do - init(loc) + self.location = loc self.message = message end end diff --git a/doc/manual/basic_type.md b/doc/manual/basic_type.md index a94912f..e1d050d 100644 --- a/doc/manual/basic_type.md +++ b/doc/manual/basic_type.md @@ -35,8 +35,8 @@ the `to_f` and `to_i` methods. Literal strings are enclosed within quotes (`"`). To insert a value inside a literal string, include the values inside braces (`{}`). -Braces has to be escaped. -`+` is the concatenation operator but is less efficient than the brace form. +Braces have to be escaped. +`+` is the concatenation operator, but is less efficient than the brace form. ~~~ var j = 5 @@ -52,7 +52,7 @@ print "hel\"lo\nwo\{rld" ~~~ Multi-line strings are enclosed with triple quotes (`"""`). -Values are inserted with a triple braces (`{{{value}}}`). +Values are inserted with triple braces (`{{{value}}}`). The multi-line form thus allows verbatim new-lines, quotes and braces ~~~ @@ -65,8 +65,8 @@ but {{{ 1+2 }}} is rendered as 3 All objects have a `to_s` method that converts the object to a String. `print` is a top-level method that takes any number of arguments and -prints to the standard output. `print` always add a newline, another -top-level method, `printn`, does not add the newline. +prints them to the standard output. `print` always adds a newline to the output, another +top-level method, `printn`, does not add a newline. ~~~ var x: String @@ -84,7 +84,7 @@ Common comparison operators are available: `==` and `!=` on all objects; `<`, `>`, `<=`, `>=` and `<=>` on `Comparable` objects (which include `Int`, `String` and others). -- `==`, `<`, `>`, `<=`, `>=` and `<=>` are standard Nit operators (so they are redefinable). +- `==`, `<`, `>`, `<=`, `>=` and `<=>` are standard Nit operators thus are redefinable. - `and`, `or` and `not` are not standard Nit operators: they are not redefinable, also they are lazy and have adaptive typing flow @@ -93,7 +93,7 @@ Common comparison operators are available: `==` and `!=` on all objects; - `==` is not for reference equality but for value equality (like `equals` in Java). There is a special reference equality operator, `is`, but it cannot be redefined and its usage is not recommended. - Note also that while `==` is redefinable, it has a special adaptive + Note that while `==` is redefinable, it has a special adaptive typing flow effect when used with `null`. - `!=` is not a standard Nit operator. In fact `x != y` is diff --git a/doc/manual/class.md b/doc/manual/class.md index b778c43..615907d 100644 --- a/doc/manual/class.md +++ b/doc/manual/class.md @@ -12,7 +12,7 @@ Here are the differences: - enums (e.g. `Int` or `Bool`) can only specialize interfaces, cannot have attributes, cannot have constructors, have proper instances but they are not instantiated by the programmer—it means no `new Int`. Note that at this point there is no user-defined enums. -All kinds of classes must have a name, can have some superclasses and can have some definitions of properties. Properties are methods, attributes, constructors and virtual types. All kinds of classes can also be generic. When we talk about “classes” in general, it means all these four kinds. We say “concrete classes” to designate only the classes declared with the `class` keyword alone. +All kinds of classes must have a name, can have some superclasses and can have some definitions of properties. Properties are methods, attributes, constructors and virtual types. All kinds of classes can also be generic. When documentation refers to “classes” , it generally refers to all four kinds. The term “concrete classes” is used to designate the classes declared with the `class` keyword alone. ## Class Specialization @@ -32,7 +32,7 @@ There is no repeated inheritance nor private inheritance. The specialization bet - adding new superclasses. -Note that the kind or the visibility of a class cannot be changed by a refinement. Therefore, it is allowed to just write `redef class X` whatever is the kind or the visibility of `X`. +Note that the kind or the visibility of a class cannot be changed by a refinement. Therefore, it is allowed to just write `redef class X` regardless of the kind or the visibility of `X`. In programs, the real instantiated classes are always the combination of all their refinements. diff --git a/doc/manual/constructor.md b/doc/manual/constructor.md index 38a32c3..77a1283 100644 --- a/doc/manual/constructor.md +++ b/doc/manual/constructor.md @@ -12,7 +12,7 @@ Their objective is double : Classes in OO models are often a simple aggregates of attributes and methods. -By default, the `new` construction require a value for each attribute defined in a class without a default value. +By default, the `new` construction requires a value for each attribute defined in a class without a default value. ~~~ class Product @@ -68,7 +68,7 @@ assert op.price.is_approx(159.50, 0.001) ## Uncollected attributes -There is three cases for an attributes to not be collected in the `new`. +There are three cases for which an attribute is not collected in a `new` construction. * Attributes with a default value * Attributes with the annotation `noinit` @@ -104,8 +104,8 @@ Therefore, `total_price` cannot be initialised with a default value, because at ## Generalized initializers -Initializers are methods that are automatically invoked by the new. -In fact, by default, the setter of an attribute is used as a initializer. +Initializers are methods that are automatically invoked by `new`. +In fact, by default, the setter of an attribute is used as an initializer. `autoinit` is used to register a method as a setter. @@ -124,8 +124,8 @@ var fp = new FooProduct("ABC", "Bla bla", 15.96, 1, 3) assert fp.z == 13 ~~~ -Generalized setters are a powerful tool but often needed in only rare specific cases. -In most case, there is no reason that an argument of a `new` construction is not stored in the object as a real attribute. +Generalized setters are a powerful tool, but only needed in rare specific cases. +In most cases, there is no reason for an argument of a `new` construction to not be stored in the object as a real attribute. ## Inheritance @@ -213,7 +213,7 @@ They should not be used since they will be removed in a near future. ## `new` factories -`new` factories permit to completely shortcut the class instantiation mechanim. +`new` factories allow to completely shortcut the class instantiation mechanism. It could be used to provide `new` syntax on non-concrete class (mainly `extern class`). `new` factories behave like a top-level function that return the result of the construction. diff --git a/doc/manual/method.md b/doc/manual/method.md index ded7093..979d104 100644 --- a/doc/manual/method.md +++ b/doc/manual/method.md @@ -81,10 +81,10 @@ Concrete classes may have abstract methods. It is up to a refinement to provide `super` calls the “previous” definition of the method. It is used in a redefinition of a method in a subclass or in a refinement, It can be used with or without arguments; in the latter case, the original arguments are implicitly used. -The `super` of Nit behave more like the `call-next-method` of CLOS that the `super` of Java or Smalltalk. It permits the traversal of complex class hierarchies and refinement. Basically, `super` is polymorphic: the method called by `super` is not only determined by the class of -definition of the method but also by the dynamic type of `self`. +The `super` of Nit behaves more like the `call-next-method` of CLOS than the `super` of Java or Smalltalk. It permits the traversal of complex class hierarchies and refinement. Basically, `super` is polymorphic: the method called by `super` is not only determined by the class of +definition of the method, but also by the dynamic type of `self`. -The principle it to produce a strict order of the redefinitions of a method (the linearization). Each call to `super` call the next method definition in the linearization. From a technical point of view, the linearization algorithm used is based on C3. It ensures that: +The principle is to produce a strict order of the redefinitions of a method (the linearization). Each call to `super` call the next method definition in the linearization. From a technical point of view, the linearization algorithm used is based on C3. It ensures that: - A definition comes after its redefinition. @@ -134,7 +134,7 @@ Operators and setters are methods that require a special syntax for their defini - bracket operator: `[]`. Its definition requires one parameter or more and a return value. Its invocation is done with `x[y, z]` where `x` is the receiver, `y` the first argument and `z` the second argument. -- setters: `something=` where `something` can be any valid method identifier. Their definitions require one parameter or more and no return value. If there is only one parameter, the invocation is done with `x.something = y` where `x` is the receiver and y the argument. If there is more that one parameter, the invocation is done with `x.something(y, z) = t` where `x` is the receiver, `y` the first argument, `z` the second argument and `t` the last argument. +- setters: `something=` where `something` can be any valid method identifier. Their definitions require one parameter or more and no return value. If there is only one parameter, the invocation is done with `x.something = y` where `x` is the receiver and `y` the argument. If there is more that one parameter, the invocation is done with `x.something(y, z) = t` where `x` is the receiver, `y` the first argument, `z` the second argument and `t` the last argument. - bracket setter: `[]=`. Its definition requires two parameters or more and no return value. Its invocation is done with `x[y, z] = t` where `x` is the receiver, `y` the first argument, `z` the second argument and `t` the last argument. diff --git a/doc/manual/module.md b/doc/manual/module.md index 9fcd7e9..5657b7c 100644 --- a/doc/manual/module.md +++ b/doc/manual/module.md @@ -1,6 +1,6 @@ # Modules -`module` declares the name of a module. While optional it is recommended to use it, at least for documentation purpose. The basename of the source file must match the name declared with `module`. The extension of the source file must be `nit`. +`module` declares the name of a module. While optional, it is recommended to use it, at least for documentation purposes. The basename of the source file must match the name declared with `module`. The extension of the source file must be `nit`. A module is made of, in order: @@ -18,7 +18,7 @@ A module is made of, in order: - `private import` indicates a private importation. Importers of a given module will not automatically import its privately imported modules. An analogy is using `#include` in a body file (`.c`) in C/C++. -- `intrude import` indicates an intrusive importation. `intrude` `import` bypasses the `private` visibility and gives to the importer module a full access on the imported module. Such an import may only be considered when modules are strongly bounded and developed together. The closest, but insufficient, analogy is something like including a body file in a body file in C/C++. +- `intrude import` indicates an intrusive importation. `intrude` `import` bypasses the `private` visibility and gives to the importer module full access on the imported module. Such an import may only be considered when modules are strongly bounded and developed together. The closest, but insufficient, analogy is something like including a body file in a body file in C/C++. ## Visibility diff --git a/doc/manual/nitreference.tex b/doc/manual/nitreference.tex index 432dba9..0bfdddd 100644 --- a/doc/manual/nitreference.tex +++ b/doc/manual/nitreference.tex @@ -65,7 +65,7 @@ \noindent\textbf{A Concise Reference of the Nit Language} -This document attempts to be as short as possible while covering all features of the language in deepth. +This document attempts to be as short as possible while covering all features of the language in depth. It is not a real manual to learn the language since concepts are covered when required. %Forward and backward references about concepts are written like this~\goto{redef} which means Section~\ref*{redef}. %An index\goto{index} also lists concepts and keywords for an improved navigation. diff --git a/doc/manual/structure.md b/doc/manual/structure.md index b3a319d..0cbbc22 100644 --- a/doc/manual/structure.md +++ b/doc/manual/structure.md @@ -16,7 +16,7 @@ program. Nit heavily refers to the control flow in its specification: - Adaptive typing. -Some structures alter the control flow but are not described in this +Some structures alter the control flow, but are not described in this section: `and`, `or`, `not`, `or else` and `return`. Note that the control flow is determined only from the position, the @@ -118,11 +118,11 @@ loop end ~~~ -Note that `loop` is different from `while true` because the control flow does not consider the values of expression. +Note that `loop` is different from `while true` because the control flow does not consider the values of expressions. ## do -Single `do` are used to create scope for variables or to be attached with labeled breaks. +Single `do` are used to create scoped variables or to be attached with labeled breaks. ~~~ do diff --git a/doc/manual/variable.md b/doc/manual/variable.md index 906714e..f5e527e 100644 --- a/doc/manual/variable.md +++ b/doc/manual/variable.md @@ -1,6 +1,6 @@ # Local Variables and Static Typing -`var` declares local variables. In fact there is no global variable in Nit, so in this document *variable* always refers to a local variable. A variable is visible up to the end of the current +`var` declares local variables. In fact, there is no global variable in Nit, so in this document *variable* always refers to a local variable. A variable is visible up to the end of the current control structure. Two variables with the same name cannot coexist: no nesting nor masking. Variables are bound to values. A variable cannot be used unless it has a value in all control flow paths (à la Java). @@ -54,7 +54,7 @@ print d + 1 ## Variable Upper Bound -An optional type information can be added to a variable declaration. This type is used as an upper bound of the type of the variable. When a initial value is given in a variable declaration without a specific type information, the static type of the initial value is used as an upper bound. If no type and no initial value are given, the upper bound is set to `nullable Object`. +An optional type information can be added to a variable declaration. This type is used as an upper bound of the type of the variable. When an initial value is given in a variable declaration without a specific type information, the static type of the initial value is used as an upper bound. If no type and no initial value are given, the upper bound is set to `nullable Object`. ~~~nitish var e: Int # Upper bound is Int @@ -130,7 +130,7 @@ end print max # outputs 11 ~~~ -Note that type adaptation occurs only in an `isa` if the target type is more specific that the current type. +Note that type adaptation occurs only in an `isa` if the target type is more specific than the current type. ~~~ var col: Collection[Int] = [1, 2, 3] diff --git a/lib/bucketed_game/bucketed_game.nit b/lib/bucketed_game/bucketed_game.nit index 213d875..58569ace 100644 --- a/lib/bucketed_game/bucketed_game.nit +++ b/lib/bucketed_game/bucketed_game.nit @@ -171,9 +171,12 @@ class GameTurn[G: Game] var game: G # Create a new game turn for `game`. - init (game: G) is old_style_init do - super(game.tick) - self.game = game + init(game: G) + is + is_old_style_init + do + _tick = game.tick + _game = game end # Insert the Bucketable event `e` to be executed at next tick. diff --git a/lib/core/collection/sorter.nit b/lib/core/collection/sorter.nit index 9157995..7476b6f 100644 --- a/lib/core/collection/sorter.nit +++ b/lib/core/collection/sorter.nit @@ -106,7 +106,14 @@ interface Comparator # var a = [5, 2, 3, 1, 4] # default_comparator.quick_sort(a, 0, a.length - 1) # assert a == [1, 2, 3, 4, 5] + # var a2 = new Array[Int] + # default_comparator.quick_sort(a2, 0, a2.length - 1) + # assert a2 == new Array[Int] + # var a3 = [1] + # default_comparator.quick_sort(a3, 0, a3.length - 1) + # assert a3 == [1] fun quick_sort(array: Array[COMPARED], from: Int, to: Int) do + if from >= to then return var pivot = array[from] var i = from var j = to diff --git a/src/astbuilder.nit b/src/astbuilder.nit index 681c4bf..0b911c6 100644 --- a/src/astbuilder.nit +++ b/src/astbuilder.nit @@ -20,6 +20,7 @@ intrude import literal intrude import parser intrude import semantize::scope intrude import modelbuilder_base +intrude import modelize_property # General factory to build semantic nodes in the AST of expressions class ASTBuilder @@ -165,13 +166,48 @@ class ASTBuilder return new ANotExpr.make(expr) end + # Make a new attribute + fun make_attribute(name: String, + n_type: nullable AType, + n_visibility: nullable AVisibility, + initial_value: nullable AExpr, + n_block: nullable AExpr, + m_attributedef: nullable MAttributeDef, + m_setterdef: nullable MMethodDef, + m_getterdef: nullable MMethodDef): AAttrPropdef + do + return new AAttrPropdef.make(name, n_type, n_visibility, initial_value, n_block, m_attributedef, m_setterdef, m_getterdef) + end + + # Make a new class (AStdClassdef) + fun make_class(mclassdef: nullable MClassDef, + n_visibility: nullable AVisibility, + n_formaldefs : Collection[AFormaldef], + n_extern_code_block : nullable AExternCodeBlock, + n_propdefs : Collection[APropdef], + n_classkind: nullable AClasskind): AStdClassdef + do + return new AStdClassdef.make(mclassdef, n_visibility, n_formaldefs, n_extern_code_block, n_propdefs, n_classkind) + end + + fun make_var(variable: Variable, mtype: MType): AVarExpr + do + return new AVarExpr.make(variable, mtype) + end + + # Make a call assignment i.e `a = 10` + fun make_call_assign(recv: AExpr, callsite: CallSite, n_args: nullable Collection[AExpr], n_value: AExpr): ACallAssignExpr + do + return new ACallAssignExpr.make(recv, callsite, n_args, n_value) + end + # Build a callsite to call the `mproperty` in the current method `caller_method`. # `is_self_call` indicate if the method caller is a property of `self` - fun create_callsite(modelbuilder: ModelBuilder, caller_method : AMethPropdef, mproperty: MMethod, is_self_call: Bool): CallSite + fun create_callsite(modelbuilder: ModelBuilder, caller_property: APropdef, mproperty: MMethod, is_self_call: Bool): CallSite do # FIXME It's not the better solution to call `TypeVisitor` here to build a model entity, but some make need to have a callsite - var type_visitor = new TypeVisitor(modelbuilder, caller_method.mpropdef.as(not null)) - var callsite = type_visitor.build_callsite_by_property(caller_method, mproperty.intro_mclassdef.bound_mtype, mproperty, is_self_call) + var type_visitor = new TypeVisitor(modelbuilder, caller_property.mpropdef.as(not null)) + var callsite = type_visitor.build_callsite_by_property(caller_property, mproperty.intro_mclassdef.bound_mtype, mproperty, is_self_call) assert callsite != null return callsite end @@ -262,6 +298,68 @@ class APlaceholderExpr end end +redef class ACallAssignExpr + private init make(recv: AExpr, callsite: CallSite, args: nullable Collection[AExpr], n_value: AExpr) + do + _callsite = callsite + _mtype = callsite.recv + _is_typed = true + var n_args = new AListExprs + if args != null then + n_args.n_exprs.add_all(args) + end + var n_qid = new AQid + n_qid.n_id = new TId + n_qid.n_id.text = callsite.mproperty.name + init_acallassignexpr(recv, n_qid, n_args, new TAssign, n_value) + end +end + +redef class AStdClassdef + private init make(mclassdef: nullable MClassDef, + n_visibility: nullable AVisibility, + n_formaldefs : Collection[Object], + n_extern_code_block : nullable AExternCodeBlock, + n_propdefs : Collection[Object], + n_classkind: nullable AClasskind) + do + if n_visibility == null then n_visibility = new APublicVisibility + if n_classkind == null then n_classkind = new AConcreteClasskind.init_aconcreteclasskind(new TKwclass) + var n_qid = new AQclassid.init_aqclassid(null, new TClassid) + init_astdclassdef(null, null, n_visibility, n_classkind, n_qid, null, n_formaldefs, null, n_extern_code_block, n_propdefs, new TKwend) + _mclassdef = mclassdef + _mclass = mclassdef.mclass + end +end + +redef class AAttrPropdef + + # Create a new `AAttrPropdef` + # Note: By default if the `AVisibility` is not given the visibility is set to public + private init make(name: String, + n_type: nullable AType, + n_visibility: nullable AVisibility, + initial_value: nullable AExpr, + n_block: nullable AExpr, + m_attributedef: nullable MAttributeDef, + m_setterdef: nullable MMethodDef, + m_getterdef: nullable MMethodDef) + do + # Set the model type + if n_type != null then mtype = n_type.mtype + # Define the visibility default is public + if n_visibility == null then n_visibility = new APublicVisibility + init_aattrpropdef(null, null, n_visibility, new TKwvar, new TId, n_type, null, initial_value, null, null , n_block, null) + # Set the name of the attribute + _n_id2.text = name + _mpropdef = m_attributedef + _mreadpropdef = m_getterdef + _mwritepropdef = m_setterdef + if initial_value != null or n_block != null then has_value = true + if m_attributedef != null then self.location = m_attributedef.location + end +end + redef class ANotExpr private init make(expr: AExpr) do @@ -318,6 +416,18 @@ redef class AMethPropdef if n_visibility == null then n_visibility = new APublicVisibility self.init_amethpropdef(null,tk_redef,n_visibility,new TKwmeth,null,null,null,n_methid,n_signature,n_annotations,n_extern_calls,n_extern_code_block,new TKwdo,n_block,new TKwend) self.mpropdef = mmethoddef + if mpropdef != null then self.location = mmethoddef.location + end + + # Execute all method verification scope flow and typing. + # It also execute an ast validation to define all parents and all locations + fun do_all(toolcontext: ToolContext) + do + self.validate + # FIXME: The `do_` usage it is maybe to much (verification...). Solution: Cut the `do_` methods into simpler parts + self.do_scope(toolcontext) + self.do_flow(toolcontext) + self.do_typing(toolcontext.modelbuilder) end end @@ -538,13 +648,6 @@ redef class ACallExpr end end -redef class AAsCastExpr - private init make(n_expr: AExpr, n_type: AType) - do - init_aascastexpr(n_expr, new TKwas , null , n_type, null) - end -end - redef class AAsNotnullExpr private init make(n_expr: AExpr, t: nullable MType) do @@ -642,6 +745,20 @@ redef class AVarAssignExpr end redef class ASignature + + init make_from_msignature(msignature: MSignature) + do + var nparams = new Array[AParam] + for mparam in msignature.mparameters do + var variable = new Variable(mparam.name) + variable.declared_type = mparam.mtype + n_params.add(new AParam.make(variable, new AType.make(mparam.mtype))) + end + var return_type = null + if msignature.return_mtype != null then return_type = new AType.make(msignature.return_mtype) + init_asignature(null, nparams, null, return_type) + end + redef fun clone: SELF do var ntype = n_type @@ -655,6 +772,7 @@ redef class AParam private init make(v: nullable Variable, t: nullable AType) do _n_id = new TId + if v != null then _n_id.text = v.name _variable = v _n_type = t end @@ -667,6 +785,17 @@ redef class AParam end end +redef class AFormaldef + + private init make(mparameter: MParameterType, t: AType) + do + _n_id = new TClassid + _n_id.text = mparameter.name + _n_type = t + _mtype = mparameter + end +end + redef class ABlockExpr private init make(t: nullable MType) do @@ -827,3 +956,214 @@ redef class AAnnotation _n_args = n_args end end + +redef class MEntity + # Build a ANode from `self` + # + # Allows the creation of an AST node from a model entity. + fun create_ast_representation(astbuilder: nullable ASTBuilder): ANode is abstract +end + +redef class MPropDef + redef fun create_ast_representation(astbuilder: nullable ASTBuilder): APropdef is abstract +end + +redef class MClassDef + redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AStdClassdef do + if astbuilder == null then astbuilder = new ASTBuilder(mmodule) + var n_propdefs = new Array[APropdef] + for mpropdef in self.mpropdefs do + n_propdefs.add(mpropdef.create_ast_representation(astbuilder)) + end + var n_formaldefs = new Array[AFormaldef] + for mparameter in self.mclass.mparameters do n_formaldefs.add(mparameter.create_ast_representation(astbuilder)) + + return astbuilder.make_class(self, visibility.create_ast_representation(astbuilder), n_formaldefs, null, n_propdefs, null) + end +end + +redef class MAttributeDef + redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AAttrPropdef do + if astbuilder == null then astbuilder = new ASTBuilder(mclassdef.mmodule) + var ntype = null + if self.static_mtype != null then ntype = static_mtype.create_ast_representation(astbuilder) + return astbuilder.make_attribute("_" + self.name, ntype, self.visibility.create_ast_representation(astbuilder), null, null, self, null, null) + end +end + +redef class MMethodDef + redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AMethPropdef do + if astbuilder == null then astbuilder = new ASTBuilder(mclassdef.mmodule) + var tk_redef = null + if self.mproperty.intro != self then tk_redef = new TKwredef + var n_signature = if self.msignature == null then new ASignature else self.msignature.create_ast_representation(astbuilder) + return astbuilder.make_method(visibility.create_ast_representation(astbuilder), tk_redef, self, n_signature) + end +end + +redef class MVisibility + fun create_ast_representation(astbuilder: nullable ASTBuilder): AVisibility do + if self.to_s == "public" then + return new APublicVisibility + else if self.to_s == "private" then + return new APrivateVisibility + else if self.to_s == "protected" then + return new AProtectedVisibility + else + return new AIntrudeVisibility + end + end +end + +redef class MSignature + redef fun create_ast_representation(astbuilder: nullable ASTBuilder): ASignature do + var nparams = new Array[AParam] + for mparam in mparameters do nparams.add(mparam.create_ast_representation(astbuilder)) + var return_type = null + if self.return_mtype != null then return_type = self.return_mtype.create_ast_representation(astbuilder) + return new ASignature.init_asignature(null, nparams, null, return_type) + end +end + +redef class MParameter + redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AParam do + var variable = new Variable(self.name) + variable.declared_type = self.mtype + return new AParam.make(variable, self.mtype.create_ast_representation(astbuilder)) + end +end + +redef class MParameterType + redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AFormaldef do + var n_type = super + return new AFormaldef.make(self, n_type) + end +end + +redef class MType + redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AType do + return new AType.make(self) + end +end + +redef class ModelBuilder + # Try to get MMethod property if exist in the given mclassdef. return new `MMethod` if not exist. + private fun get_mmethod(name: String, mclassdef: MClassDef, visibility: nullable MVisibility): MMethod do + visibility = visibility or else public_visibility + var mproperty = try_get_mproperty_by_name(null, mclassdef, name).as(nullable MMethod) + if mproperty == null then mproperty = new MMethod(mclassdef, name, mclassdef.location, visibility) + return mproperty + end + + # Creation of a new method (AST and model representation) with the given name. + # See `create_method_from_property` for more information. + fun create_method_from_name(name: String, mclassdef: MClassDef, is_abstract: Bool, msignature: nullable MSignature, visibility: nullable MVisibility): AMethPropdef do + var mproperty = get_mmethod(name, mclassdef, visibility) + return create_method_from_property(mproperty, mclassdef, is_abstract, msignature) + end + + # Creation of a new method (AST and model representation) with the given MMethod. + # Take care, if `is_abstract == false` the AMethPropdef returned has an empty body (potential error if the given signature has an return type). + fun create_method_from_property(mproperty: MMethod, mclassdef: MClassDef, is_abstract: Bool, msignature: nullable MSignature): AMethPropdef do + var m_def = new MMethodDef(mclassdef, mproperty, mclassdef.location) + + if msignature == null then msignature = new MSignature(new Array[MParameter]) + + m_def.msignature = msignature + m_def.is_abstract = true + var n_def = m_def.create_ast_representation + # Association new npropdef to mpropdef + unsafe_add_mpropdef2npropdef(m_def,n_def) + + if not is_abstract then + n_def.mpropdef.is_abstract = false + n_def.n_block = new ABlockExpr.make + end + + return n_def + end + + # Creation of a new attribute (AST and model representation) with the given name. + # See `create_attribute_from_property` for more information. + fun create_attribute_from_name(name: String, mclassdef: MClassDef, mtype: MType, visibility: nullable MVisibility): AAttrPropdef do + if visibility == null then visibility = public_visibility + var mattribute = try_get_mproperty_by_name(null, mclassdef, name) + if mattribute == null then mattribute = new MAttribute(mclassdef, name, mclassdef.location, visibility) + return create_attribute_from_property(mattribute.as(MAttribute), mclassdef, mtype) + end + + # Creation of a new attribute (AST and model representation) with the given MAttribute. + # See `create_attribute_from_propdef` for more information. + fun create_attribute_from_property(mattribute: MAttribute, mclassdef: MClassDef, mtype: MType): AAttrPropdef do + var attribut_def = new MAttributeDef(mclassdef, mattribute, mclassdef.location) + attribut_def.static_mtype = mtype + return create_attribute_from_propdef(attribut_def) + end + + # Creation of a new attribute (AST representation) with the given MAttributeDef. + fun create_attribute_from_propdef(mattribut_def: MAttributeDef): AAttrPropdef + is + expect(mclassdef2node(mattribut_def.mclassdef) != null) + do + var n_attribute = mattribut_def.create_ast_representation + + var nclass = mclassdef2node(mattribut_def.mclassdef) + + n_attribute.location = mattribut_def.location + n_attribute.validate + + nclass.n_propdefs.unsafe_add_all([n_attribute]) + nclass.validate + + n_attribute.build_read_property(self, mattribut_def.mclassdef) + n_attribute.build_read_signature + + mpropdef2npropdef[mattribut_def] = n_attribute + return n_attribute + end + + # Creation of a new class (AST and model representation) with the given name. + # `visibility` : Define the visibility of the method. If it's `null` the default is `public_visibility` + # See `create_class_from_mclass` for more information. + fun create_class_from_name(name: String, super_type: Array[MClassType], mmodule: MModule, visibility: nullable MVisibility): AStdClassdef do + if visibility == null then visibility = public_visibility + var mclass = try_get_mclass_by_name(null, mmodule, name) + if mclass == null then mclass = new MClass(mmodule, name, mmodule.location, new Array[String], concrete_kind, visibility) + return create_class_from_mclass(mclass, super_type, mmodule) + end + + # Creation of a new class (AST and model representation) with the given MClass. + # This method creates a new concrete class definition `MClassDef`, and adds it to the class hierarchy. + # See `create_class_from_mclassdef` for more information. + fun create_class_from_mclass(mclass: MClass, super_type: Array[MClassType], mmodule: MModule): AStdClassdef do + var mclassdef = new MClassDef(mmodule, mclass.mclass_type, mmodule.location) + mclassdef.set_supertypes(super_type) + mclassdef.add_in_hierarchy + + return create_class_from_mclassdef(mclassdef, mmodule) + end + + # Creation of a new class (AST representation) with the given MClassDef. + # Note all the properties of our MClassDef will also generate an AST representation. + # Make an error if the attribute already has a representation in the modelbuilder. + # This method also create the default constructor. + fun create_class_from_mclassdef(mclassdef: MClassDef, mmodule: MModule): AStdClassdef do + var n_classdef = mclassdef.create_ast_representation + n_classdef.location = mclassdef.location + n_classdef.validate + + for n_propdef in n_classdef.n_propdefs do + var mpropdef = n_propdef.mpropdef + assert mpropdef != null + + var p_npropdef = mpropdef2node(mpropdef) + if p_npropdef != null then error(null, "The property `{mpropdef.name}` already has a representation in the AST.") + unsafe_add_mpropdef2npropdef(mpropdef, n_propdef) + end + + process_default_constructors(n_classdef) + unsafe_add_mclassdef2nclassdef(mclassdef, n_classdef) + + return n_classdef + end +end diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 57e738f..e10be39 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -26,6 +26,7 @@ import mixin import counter import pkgconfig private import explain_assert_api +import contracts # Add compiling options redef class ToolContext @@ -1353,29 +1354,6 @@ abstract class AbstractCompilerVisitor fun compile_callsite(callsite: CallSite, arguments: Array[RuntimeVariable]): nullable RuntimeVariable do if callsite.is_broken then return null - var initializers = callsite.mpropdef.initializers - if not initializers.is_empty then - var recv = arguments.first - - var i = 1 - for p in initializers do - if p isa MMethod then - var args = [recv] - for x in p.intro.msignature.mparameters do - args.add arguments[i] - i += 1 - end - self.send(p, args) - else if p isa MAttribute then - self.write_attribute(p, recv, arguments[i]) - i += 1 - else abort - end - assert i == arguments.length - - return self.send(callsite.mproperty, [recv]) - end - return self.send(callsite.mproperty, arguments) end @@ -1412,7 +1390,7 @@ abstract class AbstractCompilerVisitor # of runtime variables to use in the call. fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: RuntimeVariable, args: SequenceRead[AExpr]): Array[RuntimeVariable] do - var msignature = mpropdef.new_msignature or else mpropdef.msignature.as(not null) + var msignature = mpropdef.msignature.as(not null) var res = new Array[RuntimeVariable] res.add(recv) @@ -3710,6 +3688,31 @@ redef class AClassdef v.supercall(mpropdef, arguments.first.mtype.as(MClassType), arguments) end return + else if mclassdef.default_init == mpropdef then + var recv = arguments.first + var initializers = mpropdef.initializers + var no_init = false + if not initializers.is_empty and not mpropdef.is_old_style_init then + var i = 1 + for p in initializers do + if p isa MMethod then + var args = [recv] + for x in p.intro.msignature.mparameters do + args.add arguments[i] + i += 1 + end + v.send(p, args) + if p.intro.is_calling_init then no_init = true + else if p isa MAttribute then + v.write_attribute(p, recv, arguments[i]) + i += 1 + else abort + end + assert i == arguments.length + + end + if not no_init then v.send(mclass.the_root_init_mmethod.as(not null), [recv]) + return else abort end diff --git a/src/compiler/global_compiler.nit b/src/compiler/global_compiler.nit index ac5a2a1..737ec48 100644 --- a/src/compiler/global_compiler.nit +++ b/src/compiler/global_compiler.nit @@ -30,7 +30,7 @@ redef class ToolContext # option --global var opt_global = new OptionBool("Use global compilation", "--global") - var global_compiler_phase = new GlobalCompilerPhase(self, null) + var global_compiler_phase = new GlobalCompilerPhase(self, [contracts_phase]) redef init do super diff --git a/src/compiler/java_compiler.nit b/src/compiler/java_compiler.nit index 60aea2b..7b83104 100644 --- a/src/compiler/java_compiler.nit +++ b/src/compiler/java_compiler.nit @@ -497,7 +497,7 @@ class JavaCompilerVisitor # This method is used to manage varargs in signatures and returns the real array # of runtime variables to use in the call. fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: RuntimeVariable, args: SequenceRead[AExpr]): Array[RuntimeVariable] do - var msignature = mpropdef.new_msignature or else mpropdef.msignature.as(not null) + var msignature = mpropdef.msignature.as(not null) var res = new Array[RuntimeVariable] res.add(recv) diff --git a/src/compiler/separate_compiler.nit b/src/compiler/separate_compiler.nit index 4716dae..38bc466 100644 --- a/src/compiler/separate_compiler.nit +++ b/src/compiler/separate_compiler.nit @@ -97,7 +97,7 @@ redef class ToolContext end end - var separate_compiler_phase = new SeparateCompilerPhase(self, null) + var separate_compiler_phase = new SeparateCompilerPhase(self, [contracts_phase]) end class SeparateCompilerPhase @@ -825,23 +825,14 @@ class SeparateCompiler v.add_decl("\};") end - # Globally compile the table of the class mclass - # In a link-time optimisation compiler, tables are globally computed - # In a true separate compiler (a with dynamic loading) you cannot do this unfortnally - fun compile_class_to_c(mclass: MClass) + protected fun compile_class_vft(ccinfo: ClassCompilationInfo, v: SeparateCompilerVisitor) do - if mclass.is_broken then return - - var mtype = mclass.intro.bound_mtype - var c_name = mclass.c_name - - var v = new_visitor - + var mclass = ccinfo.mclass + var mtype = ccinfo.mtype var rta = runtime_type_analysis - var is_dead = rta != null and not rta.live_classes.has(mclass) - # While the class may be dead, some part of separately compiled code may use symbols associated to the class, so - # in order to compile and link correctly the C code, these symbols should be declared and defined. - var need_corpse = is_dead and mtype.is_c_primitive or mclass.kind == extern_kind or mclass.kind == enum_kind + var c_name = ccinfo.mclass.c_name + var is_dead = ccinfo.is_dead + var need_corpse = ccinfo.need_corpse v.add_decl("/* runtime class {c_name}: {mclass.full_name} (dead={is_dead}; need_corpse={need_corpse})*/") @@ -873,11 +864,24 @@ class SeparateCompiler v.add_decl("\}") v.add_decl("\};") end + end + + # Given a `MClass`, if it's a universal class and if it needs to be handle + # specifically by the compiler, this function will compile it and return + # true. Otherwise, no C code will be written in the visitor and the value + # false will be returned. + fun compile_class_if_universal(ccinfo: ClassCompilationInfo, v: SeparateCompilerVisitor): Bool + do + var mclass = ccinfo.mclass + var mtype = ccinfo.mtype + var c_name = ccinfo.mclass.c_name + var is_dead = ccinfo.is_dead + var need_corpse = ccinfo.need_corpse if mtype.is_c_primitive or mtype.mclass.name == "Pointer" then # Is a primitive type or the Pointer class, not any other extern class - if mtype.is_tagged then return + if mtype.is_tagged then return true #Build instance struct self.header.add_decl("struct instance_{c_name} \{") @@ -887,7 +891,7 @@ class SeparateCompiler self.header.add_decl("\};") # Pointer is needed by extern types, live or not - if is_dead and mtype.mclass.name != "Pointer" then return + if is_dead and mtype.mclass.name != "Pointer" then return true #Build BOX self.provide_declaration("BOX_{c_name}", "val* BOX_{c_name}({mtype.ctype_extern});") @@ -905,7 +909,7 @@ class SeparateCompiler v.add("\}") # A Pointer class also need its constructor - if mtype.mclass.name != "Pointer" then return + if mtype.mclass.name != "Pointer" then return true v = new_visitor self.provide_declaration("NEW_{c_name}", "{mtype.ctype} NEW_{c_name}(const struct type* type);") @@ -926,7 +930,7 @@ class SeparateCompiler v.add("return {res};") end v.add("\}") - return + return true else if mclass.name == "NativeArray" then #Build instance struct self.header.add_decl("struct instance_{c_name} \{") @@ -953,7 +957,7 @@ class SeparateCompiler v.add("{res}->length = length;") v.add("return (val*){res};") v.add("\}") - return + return true else if mclass.name == "RoutineRef" then self.header.add_decl("struct instance_{c_name} \{") self.header.add_decl("const struct type *type;") @@ -976,7 +980,7 @@ class SeparateCompiler v.add("{res}->method = method;") v.add("return (val*){res};") v.add("\}") - return + return true else if mtype.mclass.kind == extern_kind and mtype.mclass.name != "CString" then # Is an extern class (other than Pointer and CString) # Pointer is caught in a previous `if`, and CString is internal @@ -1001,8 +1005,17 @@ class SeparateCompiler v.add("return {res};") end v.add("\}") - return + return true end + return false + end + + protected fun compile_default_new(ccinfo: ClassCompilationInfo, v: SeparateCompilerVisitor) + do + var mclass = ccinfo.mclass + var mtype = ccinfo.mtype + var c_name = ccinfo.mclass.c_name + var is_dead = ccinfo.is_dead #Build NEW self.provide_declaration("NEW_{c_name}", "{mtype.ctype} NEW_{c_name}(const struct type* type);") @@ -1036,6 +1049,35 @@ class SeparateCompiler v.add("return {res};") end v.add("\}") + + end + + protected fun build_class_compilation_info(mclass: MClass): ClassCompilationInfo + do + var mtype = mclass.intro.bound_mtype + var rta = runtime_type_analysis + var is_dead = rta != null and not rta.live_classes.has(mclass) + + # While the class may be dead, some part of separately compiled code may use symbols associated to the class, so + # in order to compile and link correctly the C code, these symbols should be declared and defined. + var need_corpse = is_dead and mtype.is_c_primitive or mclass.kind == extern_kind or mclass.kind == enum_kind + + var compilation_info = new ClassCompilationInfo(mclass, is_dead, need_corpse) + return compilation_info + end + + # Globally compile the table of the class mclass + # In a link-time optimisation compiler, tables are globally computed + # In a true separate compiler (a with dynamic loading) you cannot do this unfortnally + fun compile_class_to_c(mclass: MClass) + do + var v = new_visitor + var class_info = build_class_compilation_info(mclass) + compile_class_vft(class_info, v) + var is_already_managed = compile_class_if_universal(class_info, v) + if not is_already_managed then + compile_default_new(class_info, v) + end end # Compile structures used to map tagged primitive values to their classes and types. @@ -2551,6 +2593,34 @@ class SeparateRuntimeFunction end end +# Encapsulates every information needed to compile a class. +# +# The compilation of a class is done by several methods, two of those are +# mandatory : +# - compile_class_to_c : starts the compilation process +# - compile_class_vft : generate the virtual function table +# And one of them is optional : +# - compile_class_if_universal : compiles the rest of the class if its a universal +# type. Universal type are handle in a case-basis, this is why they need special treatment. +# Generally, universal class will have special structure and a custom allocator. +# +# Throughout each step of the class compilation process, some information must be share. +# This class encapsulates the compilation process state. +# (except vft), eg +class ClassCompilationInfo + var mclass: MClass # class to compile + var is_dead: Bool + var need_corpse: Bool + + # Shortcut to access the class's bound type. + var mtype: MClassType is noinit + + init + do + mtype = mclass.intro.bound_mtype + end +end + class SeparateThunkFunction super ThunkFunction super SeparateRuntimeFunction diff --git a/src/compiler/separate_erasure_compiler.nit b/src/compiler/separate_erasure_compiler.nit index 8e0a0b2..813e7fb 100644 --- a/src/compiler/separate_erasure_compiler.nit +++ b/src/compiler/separate_erasure_compiler.nit @@ -46,7 +46,7 @@ redef class ToolContext end end - var erasure_compiler_phase = new ErasureCompilerPhase(self, null) + var erasure_compiler_phase = new ErasureCompilerPhase(self, [contracts_phase]) end class ErasureCompilerPhase @@ -194,74 +194,12 @@ class SeparateErasureCompiler self.header.add_decl("typedef struct instance \{ const struct class *class; nitattribute_t attrs[1]; \} val; /* general C type representing a Nit instance. */") end - redef fun compile_class_to_c(mclass: MClass) + redef fun compile_class_if_universal(ccinfo, v) do - var mtype = mclass.intro.bound_mtype + var mclass = ccinfo.mclass + var mtype = ccinfo.mtype var c_name = mclass.c_name - - var class_table = self.class_tables[mclass] - var v = self.new_visitor - - var rta = runtime_type_analysis - var is_dead = false # mclass.kind == abstract_kind or mclass.kind == interface_kind - if not is_dead and rta != null and not rta.live_classes.has(mclass) and not mtype.is_c_primitive and mclass.name != "NativeArray" then - is_dead = true - end - - v.add_decl("/* runtime class {c_name} */") - - self.provide_declaration("class_{c_name}", "extern const struct class class_{c_name};") - v.add_decl("extern const struct type_table type_table_{c_name};") - - # Build class vft - v.add_decl("const struct class class_{c_name} = \{") - v.add_decl("{class_ids[mclass]},") - v.add_decl("\"{mclass.name}\", /* class_name_string */") - v.add_decl("{self.box_kind_of(mclass)}, /* box_kind */") - v.add_decl("{class_colors[mclass]},") - if not is_dead then - if build_class_vts_table(mclass) then - v.require_declaration("vts_table_{c_name}") - v.add_decl("&vts_table_{c_name},") - else - v.add_decl("NULL,") - end - v.add_decl("&type_table_{c_name},") - v.add_decl("\{") - var vft = self.method_tables.get_or_null(mclass) - if vft != null then for i in [0 .. vft.length[ do - var mpropdef = vft[i] - if mpropdef == null then - v.add_decl("NULL, /* empty */") - else - assert mpropdef isa MMethodDef - if rta != null and not rta.live_methoddefs.has(mpropdef) then - v.add_decl("NULL, /* DEAD {mclass.intro_mmodule}:{mclass}:{mpropdef} */") - continue - end - var rf = mpropdef.virtual_runtime_function - v.require_declaration(rf.c_name) - v.add_decl("(nitmethod_t){rf.c_name}, /* pointer to {mpropdef.full_name} */") - end - end - v.add_decl("\}") - end - v.add_decl("\};") - - # Build class type table - - v.add_decl("const struct type_table type_table_{c_name} = \{") - v.add_decl("{class_table.length},") - v.add_decl("\{") - for msuper in class_table do - if msuper == null then - v.add_decl("-1, /* empty */") - else - v.add_decl("{self.class_ids[msuper]}, /* {msuper} */") - end - end - v.add_decl("\}") - v.add_decl("\};") + var is_dead = ccinfo.is_dead if mtype.is_c_primitive or mtype.mclass.name == "Pointer" then #Build instance struct @@ -281,7 +219,7 @@ class SeparateErasureCompiler v.add("return (val*)res;") v.add("\}") - if mtype.mclass.name != "Pointer" then return + if mtype.mclass.name != "Pointer" then return true v = new_visitor self.provide_declaration("NEW_{c_name}", "{mtype.ctype} NEW_{c_name}();") @@ -299,7 +237,7 @@ class SeparateErasureCompiler v.add("return {res};") end v.add("\}") - return + return true else if mclass.name == "NativeArray" then #Build instance struct self.header.add_decl("struct instance_{c_name} \{") @@ -321,7 +259,7 @@ class SeparateErasureCompiler v.add("{res}->length = length;") v.add("return (val*){res};") v.add("\}") - return + return true else if mclass.name == "RoutineRef" then self.header.add_decl("struct instance_{c_name} \{") self.header.add_decl("const struct class *class;") @@ -341,7 +279,7 @@ class SeparateErasureCompiler v.add("{res}->method = method;") v.add("return (val*){res};") v.add("\}") - return + return true else if mtype.mclass.kind == extern_kind and mtype.mclass.name != "CString" then var pointer_type = mainmodule.pointer_type @@ -361,8 +299,84 @@ class SeparateErasureCompiler v.add("return {res};") end v.add("\}") - return + return true end + return false + end + + redef fun compile_class_vft(ccinfo, v) + do + var mclass = ccinfo.mclass + var mtype = ccinfo.mtype + var c_name = mclass.c_name + var is_dead = ccinfo.is_dead + var rta = runtime_type_analysis + + # Build class vft + self.provide_declaration("class_{c_name}", "extern const struct class class_{c_name};") + + v.add_decl("const struct class class_{c_name} = \{") + v.add_decl("{class_ids[mclass]},") + v.add_decl("\"{mclass.name}\", /* class_name_string */") + v.add_decl("{self.box_kind_of(mclass)}, /* box_kind */") + v.add_decl("{class_colors[mclass]},") + if not is_dead then + if build_class_vts_table(mclass) then + v.require_declaration("vts_table_{c_name}") + v.add_decl("&vts_table_{c_name},") + else + v.add_decl("NULL,") + end + v.add_decl("&type_table_{c_name},") + v.add_decl("\{") + var vft = self.method_tables.get_or_null(mclass) + if vft != null then for i in [0 .. vft.length[ do + var mpropdef = vft[i] + if mpropdef == null then + v.add_decl("NULL, /* empty */") + else + assert mpropdef isa MMethodDef + if rta != null and not rta.live_methoddefs.has(mpropdef) then + v.add_decl("NULL, /* DEAD {mclass.intro_mmodule}:{mclass}:{mpropdef} */") + continue + end + var rf = mpropdef.virtual_runtime_function + v.require_declaration(rf.c_name) + v.add_decl("(nitmethod_t){rf.c_name}, /* pointer to {mpropdef.full_name} */") + end + end + v.add_decl("\}") + end + v.add_decl("\};") + end + + protected fun compile_class_type_table(ccinfo: ClassCompilationInfo, v: SeparateCompilerVisitor) + do + var mclass = ccinfo.mclass + var c_name = mclass.c_name + var class_table = self.class_tables[mclass] + + # Build class type table + v.add_decl("const struct type_table type_table_{c_name} = \{") + v.add_decl("{class_table.length},") + v.add_decl("\{") + for msuper in class_table do + if msuper == null then + v.add_decl("-1, /* empty */") + else + v.add_decl("{self.class_ids[msuper]}, /* {msuper} */") + end + end + v.add_decl("\}") + v.add_decl("\};") + end + + redef fun compile_default_new(ccinfo, v) + do + var mclass = ccinfo.mclass + var mtype = ccinfo.mtype + var c_name = mclass.c_name + var is_dead = ccinfo.is_dead #Build NEW self.provide_declaration("NEW_{c_name}", "{mtype.ctype} NEW_{c_name}(void);") @@ -391,6 +405,33 @@ class SeparateErasureCompiler v.add("\}") end + redef fun build_class_compilation_info(mclass) + do + var ccinfo = super + var mtype = ccinfo.mtype + var rta = runtime_type_analysis + var is_dead = false # mclass.kind == abstract_kind or mclass.kind == interface_kind + if not is_dead and rta != null and not rta.live_classes.has(mclass) and not mtype.is_c_primitive and mclass.name != "NativeArray" then + is_dead = true + end + ccinfo.is_dead = is_dead + return ccinfo + end + + redef fun compile_class_to_c(mclass: MClass) + do + var ccinfo = build_class_compilation_info(mclass) + var v = new_visitor + v.add_decl("/* runtime class {mclass.c_name} */") + self.provide_declaration("class_{mclass.c_name}", "extern const struct class class_{mclass.c_name};") + v.add_decl("extern const struct type_table type_table_{mclass.c_name};") + self.compile_class_vft(ccinfo, v) + self.compile_class_type_table(ccinfo, v) + if not self.compile_class_if_universal(ccinfo, v) then + self.compile_default_new(ccinfo, v) + end + end + private fun build_class_vts_table(mclass: MClass): Bool do if self.vt_tables[mclass].is_empty then return false diff --git a/src/contracts.nit b/src/contracts.nit index e2bad53..f732065 100644 --- a/src/contracts.nit +++ b/src/contracts.nit @@ -18,10 +18,11 @@ # FIXME Split the module in three parts: extension of the modele, building phase and the "re-driving" module contracts -import astbuilder import parse_annotations import phase import semantize +intrude import model_contract +intrude import astbuilder intrude import modelize_property intrude import scope intrude import typing @@ -34,41 +35,45 @@ end private class ContractsPhase super Phase - # The entry point of the contract phase - # In reality, the contract phase is executed on each module - # FIXME: Actually all method is checked to add method if any contract is inherited redef fun process_nmodule(nmodule)do # Check if the contracts are disabled if toolcontext.opt_no_contract.value then return nmodule.do_contracts(self.toolcontext) end + + redef fun process_mainmodule(mainmodule: MModule, given_mmodules: SequenceRead[MModule]) do + # Visit all loaded modules `toolcontext.nmodules` to do contract weaving + for nmodule in toolcontext.modelbuilder.nmodules do + nmodule.do_weaving_contracts(self.toolcontext) + end + end end redef class AModule - # Compile all contracts - # - # The implementation of the contracts is done in two visits. - # - # - First step, the visitor analyzes and constructs the contracts - # for each class (invariant) and method (expect, ensure). - # - # - Second step the visitor analyzes each `ASendExpr` to see - # if the callsite calls a method with a contract. If this is - # the case the callsite is replaced by another callsite to the contract method. + + # Entry point to generate the entire contract infrastructure. + # Once this method is called we must call the `do_weaving_contracts` method (see it for more information). fun do_contracts(toolcontext: ToolContext) do + var ast_builder = new ASTBuilder(mmodule.as(not null)) # - var contract_visitor = new ContractsVisitor(toolcontext, toolcontext.modelbuilder.identified_modules.first, self, new ASTBuilder(mmodule.as(not null))) + var contract_visitor = new ContractsVisitor(toolcontext, toolcontext.modelbuilder.identified_modules.first, self, ast_builder) contract_visitor.enter_visit(self) - # - var callsite_visitor = new CallSiteVisitor(toolcontext) + end + + # Entry point to execute the weaving in order to redirect the calls to the contract sides if it's needed. + fun do_weaving_contracts(toolcontext: ToolContext) + do + var ast_builder = new ASTBuilder(mmodule.as(not null)) + var callsite_visitor = new CallSiteVisitor(toolcontext, ast_builder) callsite_visitor.enter_visit(self) end end -# This visitor checks the `AMethPropdef` and the `AClassDef` to check if they have a contract annotation or it's a redefinition with a inheritance contract +# Visitor to build all contracts. private class ContractsVisitor super Visitor + # Instance of the toolcontext var toolcontext: ToolContext # The main module @@ -90,6 +95,8 @@ private class ContractsVisitor var current_location: Location is noinit # Is the contrat is an introduction or not? + # This attribute has the same value as the `is_intro` of the propdef attached to the contract. + # Note : For MClassDef `is_intro_contract == false`. This is due to the fact that a method for checking invariants is systematically added to the root object class. var is_intro_contract: Bool is noinit # Actual visited class @@ -98,6 +105,11 @@ private class ContractsVisitor # is `no_contract` annotation was found var find_no_contract = false + # The reference to the `in_contract` attribute. + # This attribute is used to disable contract verification when you are already in a contract verification. + # Keep the `in_contract` attribute to avoid searching at each contrat + var in_contract_attribute: nullable MAttribute = null + redef fun visit(node) do node.create_contracts(self) @@ -114,64 +126,106 @@ private class ContractsVisitor end # Define the new contract take in consideration that an old contract exist or not - private fun build_contract(n_annotation: AAnnotation, mcontract: MContract, mclassdef: MClassDef): MMethodDef + private fun build_contract(n_annotations: Array[AAnnotation], mcontract: MContract, mclassdef: MClassDef) do - self.current_location = n_annotation.location + var n_conditions = new Array[AExpr] # Retrieving the expression provided in the annotation - var n_condition = n_annotation.construct_condition(self) - var m_contractdef: AMethPropdef + for n_annotation in n_annotations do n_conditions.add n_annotation.construct_condition(self) if is_intro_contract then # Create new contract method - m_contractdef = mcontract.create_intro_contract(self, n_condition, mclassdef) + mcontract.create_intro_contract(self, n_conditions, mclassdef) else # Create a redef of contract to take in consideration the new condition - m_contractdef = mcontract.create_subcontract(self, n_condition, mclassdef) + mcontract.create_subcontract(self, n_conditions, mclassdef) end - var contract_propdef = m_contractdef.mpropdef - # The contract has a null mpropdef, this should never happen - assert contract_propdef != null - return contract_propdef end - # Verification if the construction of the contract is necessary. - # Three cases are checked for `expect`: - # - # - Is the `--full-contract` option it's use? - # - Is the method is in the main package - # - Is the method is in a direct imported package. - # - fun check_usage_expect(actual_mmodule: MModule): Bool + # Inject the incontract attribute (`_in_contract_`) in the `Sys` class + # This attribute allows to check if the contract need to be executed + private fun inject_incontract_in_sys do - var main_package = mainmodule.mpackage - var actual_package = actual_mmodule.mpackage - if main_package != null and actual_package != null then - var condition_direct_arc = toolcontext.modelbuilder.model.mpackage_importation_graph.has_arc(main_package, actual_package) - return toolcontext.opt_full_contract.value or condition_direct_arc or main_package == actual_package + # If the `in_contract_attribute` already know just return + if in_contract_attribute != null then return + + var sys_class = toolcontext.modelbuilder.get_mclass_by_name(visited_module, mainmodule, "Sys") + + # Try to get the `in_contract` property, if it has already defined in a previously visited module. + var in_contract_property = toolcontext.modelbuilder.try_get_mproperty_by_name(visited_module, sys_class.intro, "__in_contract_") + if in_contract_property != null then + self.in_contract_attribute = in_contract_property.as(MAttribute) + return end - return false + + var bool_false = new AFalseExpr.make(mainmodule.bool_type) + var n_in_contract_attribute = toolcontext.modelbuilder.create_attribute_from_name("__in_contract_", sys_class.intro, mainmodule.bool_type, public_visibility).create_setter(toolcontext.modelbuilder, true).define_default(bool_false) + + in_contract_attribute = n_in_contract_attribute.mpropdef.mproperty end - # Verification if the construction of the contract is necessary. - # Two cases are checked for `ensure`: + # Return the `_in_contract_` attribute. + # If the attribute `_in_contract_` does not exist it's injected with `inject_incontract_in_sys` + private fun get_incontract: MAttribute + do + if self.in_contract_attribute == null then inject_incontract_in_sys + return in_contract_attribute.as(not null) + end + + # Return an `AIfExpr` with the contract encapsulated by an `if` to check if it's already in a contract verification. + # + # Example: + # ~~~nitish + # class A + # fun bar([...]) is except([...]) + # + # fun _contract_bar([...]) + # do + # if not sys._in_contract_ then + # sys._in_contract_ = true + # _bar_expect([...]) + # sys._in_contract_ = false + # end + # bar([...]) + # end # - # - Is the `--full-contract` option it's use? - # - Is the method is in the main package + # fun _bar_expect([...]) + # end + # ~~~~ # - fun check_usage_ensure(actual_mmodule: MModule): Bool + private fun encapsulated_contract_call(visited_method: AMethPropdef, call_to_contracts: Array[ACallExpr]): AIfExpr do - return toolcontext.opt_full_contract.value or mainmodule.mpackage == actual_mmodule.mpackage - end + var sys_property = toolcontext.modelbuilder.model.get_mproperties_by_name("sys").first.as(MMethod) + var callsite_sys = ast_builder.create_callsite(toolcontext.modelbuilder, visited_method, sys_property, true) + + var incontract_attribute = get_incontract + + var callsite_get_incontract = ast_builder.create_callsite(toolcontext.modelbuilder, visited_method, incontract_attribute.getter.as(MMethod), false) + var callsite_set_incontract = ast_builder.create_callsite(toolcontext.modelbuilder, visited_method, incontract_attribute.setter.as(MMethod), false) + + var n_condition = ast_builder.make_not(ast_builder.make_call(ast_builder.make_call(new ASelfExpr, callsite_sys, null), callsite_get_incontract, null)) + + var n_if = ast_builder.make_if(n_condition, null) + var if_then_block = n_if.n_then.as(ABlockExpr) + + if_then_block.add(ast_builder.make_call(ast_builder.make_call(new ASelfExpr, callsite_sys, null), callsite_set_incontract, [new ATrueExpr.make(mainmodule.bool_type)])) + if_then_block.add_all(call_to_contracts) + if_then_block.add(ast_builder.make_call(ast_builder.make_call(new ASelfExpr, callsite_sys, null), callsite_set_incontract, [new AFalseExpr.make(mainmodule.bool_type)])) + + return n_if + end end # This visitor checks the `callsite` to see if the target `mpropdef` has a contract. private class CallSiteVisitor super Visitor + # Instance of the toolcontext var toolcontext: ToolContext + var ast_builder: ASTBuilder + # Actual visited method - var visited_method: APropdef is noinit + var visited_propdef: APropdef is noinit redef fun visit(node) do @@ -179,22 +233,18 @@ private class CallSiteVisitor node.visit_all(self) end - # Check if the callsite calls a method with a contract. - # If it's the case the callsite is replaced by another callsite to the contract method. - private fun drive_method_contract(callsite: CallSite): CallSite + # Check if the callsite is bound on a property with a contract. + # If the property is linked to a contract a new callsite will be created towards the correct facet, + # in the other case the returned callsite wall be the same as the given `callsite` + private fun drive_callsite_to_contract(callsite: CallSite): CallSite do - if callsite.mproperty.mcontract_facet != null then - var contract_facet = callsite.mproperty.mcontract_facet - var visited_mpropdef = visited_method.mpropdef - assert contract_facet != null and visited_mpropdef != null + var contract_facet = callsite.mproperty.mcontract_facet + var visited_mpropdef = visited_propdef.mpropdef - var type_visitor = new TypeVisitor(toolcontext.modelbuilder, visited_mpropdef) - var drived_callsite = type_visitor.build_callsite_by_property(visited_method, callsite.recv, contract_facet, callsite.recv_is_self) - # This never happen this check is here for debug - assert drived_callsite != null - return drived_callsite - end - return callsite + if visited_mpropdef isa MContract or visited_mpropdef isa MFacet then return callsite + if visited_mpropdef == null or contract_facet == null then return callsite + + return ast_builder.create_callsite(toolcontext.modelbuilder, visited_propdef, contract_facet, callsite.recv_is_self) end end @@ -205,46 +255,48 @@ end redef class AAnnotation - # Returns the conditions of annotation parameters in the form of and expr - # exemple: - # the contract ensure(true, i == 10, f >= 1.0) - # return this condition (true and i == 10 and f >= 1.0) + # Returns the conditions of annotation parameters. If there are several parameters, the result is an `AAndExpr` + # Example: + # the contract `ensure(true, i == 10, f >= 1.0)` + # return this condition `(true and i == 10 and f >= 1.0)` private fun construct_condition(v : ContractsVisitor): AExpr do var n_condition = n_args.first n_args.remove_at(0) for n_arg in n_args do n_condition = v.ast_builder.make_and(n_condition, n_arg) + n_condition.location = self.location return n_condition end end -# The root of all contracts -# -# The objective of this class is to provide the set -# of services must be implemented or provided by a contract -abstract class MContract - super MMethod +redef class MContract - # Define the name of the contract - fun contract_name: String is abstract + # Should contract be called? + # return `true` if the contract needs to be called. + private fun is_called(v: ContractsVisitor, mpropdef: MPropDef): Bool + do + return v.toolcontext.opt_full_contract.value + end # Method use to diplay warning when the contract is not present at the introduction - private fun no_intro_contract(v: ContractsVisitor, a: AAnnotation)do end + private fun no_intro_contract(v: ContractsVisitor, a: Array[AAnnotation])do end # Creating specific inheritance block contract - private fun create_nblock(v: ContractsVisitor, n_condition: AExpr, args: Array[AExpr]): ABlockExpr is abstract + # + # `super_args` : Correspond to the `super` call arguments + private fun create_inherit_nblock(v: ContractsVisitor, n_conditions: Array[AExpr], super_args: Array[AExpr]): ABlockExpr is abstract - # Method to adapt the `n_mpropdef.n_block` to the contract - private fun adapt_block_to_contract(v: ContractsVisitor, n_mpropdef: AMethPropdef) is abstract + # Method to adapt the given `n_mpropdef.n_block` to the contract + private fun adapt_method_to_contract(v: ContractsVisitor, mfacet: MFacet, n_mpropdef: AMethPropdef) is abstract - # Adapt the msignature specifically for the contract method - private fun adapt_specific_msignature(m_signature: MSignature): MSignature do return m_signature.adapt_to_condition + # Create and return an adapted `MSignature` specifically for the contract in fonction of the given `m_signature` + private fun adapt_specific_msignature(m_signature: MSignature): MSignature do return m_signature.adapt_to_contract - # Adapt the nsignature specifically for the contract method - private fun adapt_specific_nsignature(n_signature: ASignature): ASignature do return n_signature.adapt_to_condition(null) + # Create and return an adapted `ASignature` specifically for the contract in fonction of the given `n_signature` + private fun adapt_specific_nsignature(n_signature: ASignature): ASignature do return n_signature.adapt_to_contract # Adapt the `m_signature` to the contract - # If it is not null call the specific adapt `m_signature` for the contract + # If `m_signature == null` return a new `MSignature` else it calls a specific adapt method see `adapt_specific_msignature` private fun adapt_msignature(m_signature: nullable MSignature): MSignature do if m_signature == null then return new MSignature(new Array[MParameter]) @@ -252,74 +304,89 @@ abstract class MContract end # Adapt the `n_signature` to the contract - # If it is not null call the specific adapt `n_signature` for the contract + # If `n_signature == null` return a new `ASignature` else it calls a specific adapt method see `adapt_specific_nsignature` private fun adapt_nsignature(n_signature: nullable ASignature): ASignature do if n_signature == null then return new ASignature return adapt_specific_nsignature(n_signature) end - # Create a new empty contract - private fun create_empty_contract(v: ContractsVisitor, mclassdef: MClassDef, msignature: nullable MSignature, n_signature: ASignature) - do - var n_contract_def = intro_mclassdef.mclass.create_empty_method(v, self, mclassdef, msignature, n_signature) - n_contract_def.do_all(v.toolcontext) - end - # Create the initial contract (intro) # All contracts have the same implementation for the introduction. # + # Example: + # ~~~nitish # fun contrat([...]) # do # assert contract_condition # end + # ~~~ # - private fun create_intro_contract(v: ContractsVisitor, n_condition: nullable AExpr, mclassdef: MClassDef): AMethPropdef + private fun create_intro_contract(v: ContractsVisitor, n_conditions: Array[AExpr], mclassdef: MClassDef) do var n_block = v.ast_builder.make_block - if n_condition != null then + for n_condition in n_conditions do # Create a new tid to set the name of the assert for more explicit error - var tid = new TId.init_tk(self.location) - tid.text = "{self.contract_name}" - n_block.add v.ast_builder.make_assert(tid, n_condition, null) + var tid = new TId.init_tk(n_condition.location) + tid.text = "{n_condition.location.text}" + var n_assert = v.ast_builder.make_assert(tid, n_condition, null) + # Define the assert location to reference the annoation + n_assert.location = n_condition.location + n_block.add n_assert end - return make_contract(v, n_block, mclassdef) + make_contract(v, n_block, mclassdef) end - # Create a contract with old (super) and the new conditions - private fun create_subcontract(v: ContractsVisitor, ncondition: nullable AExpr, mclassdef: MClassDef): AMethPropdef + # Create a contract to check the old (super call) and the new conditions + # + # Example: + # ~~~nitish + # fun contrat([...]) + # do + # super # Call the old contracts + # assert new_condition + # end + # ~~~ + # + private fun create_subcontract(v: ContractsVisitor, n_conditions: Array[AExpr], mclassdef: MClassDef) do var args = v.n_signature.make_parameter_read(v.ast_builder) var n_block = v.ast_builder.make_block - if ncondition != null then n_block = self.create_nblock(v, ncondition, args) - return make_contract(v, n_block, mclassdef) + n_block = self.create_inherit_nblock(v, n_conditions, args) + make_contract(v, n_block, mclassdef) end - # Build a method with a specific block `n_block` in a specified `mclassdef` - private fun make_contract(v: ContractsVisitor, n_block: AExpr, mclassdef: MClassDef): AMethPropdef + # Build a new contract method with a specific block `n_block` in a specified `mclassdef` + private fun make_contract(v: ContractsVisitor, n_block: AExpr, mclassdef: MClassDef) do - var n_contractdef = intro_mclassdef.mclass.create_empty_method(v, self, mclassdef, v.m_signature, v.n_signature) + var n_contractdef = v.toolcontext.modelbuilder.create_method_from_property(self, mclassdef, false, v.m_signature) + # Set the signature to keep the same variable + n_contractdef.n_signature = v.n_signature n_contractdef.n_block = n_block # Define the location of the new method for corresponding of the annotation location n_contractdef.location = v.current_location n_contractdef.do_all(v.toolcontext) - return n_contractdef end end -# A expect (precondition) contract representation -# This method check if the requirements of the called method is true. -class MExpect - super MContract +redef class MExpect - # Define the name of the contract - redef fun contract_name: String do return "expect" + redef fun is_called(v: ContractsVisitor, mpropdef: MPropDef): Bool + do + var main_package = v.mainmodule.mpackage + var actual_package = mpropdef.mclassdef.mmodule.mpackage + if main_package != null and actual_package != null then + var condition_direct_arc = v.toolcontext.modelbuilder.model.mpackage_importation_graph.has_arc(main_package, actual_package) + return super or main_package == actual_package or condition_direct_arc + end + return false + end # Display warning if no contract is defined at introduction `expect`, # because if no contract is defined at the introduction the added # contracts will not cause any error even if they are not satisfied. # - # exemple + # Example: # ~~~nitish # class A # fun bar [...] @@ -333,91 +400,95 @@ class MExpect # redef fun bar is expect(contract_condition) # redef fun _bar_expect([...]) # do - # if not (contract_condition) then super + # if (contract_condition) then return + # super # end # end # ~~~~ # - redef fun no_intro_contract(v: ContractsVisitor, a: AAnnotation) + redef fun no_intro_contract(v: ContractsVisitor, a: Array[AAnnotation]) do - v.toolcontext.warning(a.location,"","Useless contract: No contract defined at the introduction of the method") + v.toolcontext.warning(a.first.location,"useless_contract","Useless contract: No contract defined at the introduction of the method") end - redef fun create_nblock(v: ContractsVisitor, n_condition: AExpr, args: Array[AExpr]): ABlockExpr + redef fun create_inherit_nblock(v: ContractsVisitor, n_conditions: Array[AExpr], super_args: Array[AExpr]): ABlockExpr do - # Creating the if expression with the new condition - var if_block = v.ast_builder.make_if(n_condition, n_condition.mtype) - # Creating and adding return expr to the then case - if_block.n_then = v.ast_builder.make_return(null) - # Creating the super call to the contract and adding this to else case - if_block.n_else = v.ast_builder.make_super_call(args,null) var n_block = v.ast_builder.make_block - n_block.add if_block + for n_condition in n_conditions do + # Creating the if expression with the new condition + var if_block = v.ast_builder.make_if(n_condition, n_condition.mtype) + # Creating and adding return expr to the then case + if_block.n_then = v.ast_builder.make_return + if_block.location = n_condition.location + n_block.add if_block + end + n_block.add v.ast_builder.make_super_call(super_args) return n_block end - redef fun adapt_block_to_contract(v: ContractsVisitor, n_mpropdef: AMethPropdef) + redef fun adapt_method_to_contract(v: ContractsVisitor, mfacet: MFacet, n_mpropdef: AMethPropdef) do var callsite = v.ast_builder.create_callsite(v.toolcontext.modelbuilder, n_mpropdef, self, true) - var n_self = new ASelfExpr var args = n_mpropdef.n_signature.make_parameter_read(v.ast_builder) - var n_callexpect = v.ast_builder.make_call(n_self,callsite,args) + var n_callexpect = v.ast_builder.make_call(new ASelfExpr, callsite,args) # Creation of the new instruction block with the call to expect condition var actual_expr = n_mpropdef.n_block var new_block = new ABlockExpr - new_block.n_expr.push n_callexpect + new_block.n_expr.push v.encapsulated_contract_call(n_mpropdef, [n_callexpect]) if actual_expr isa ABlockExpr then new_block.n_expr.add_all(actual_expr.n_expr) else if actual_expr != null then new_block.n_expr.push(actual_expr) end n_mpropdef.n_block = new_block + mfacet.has_applied_expect = true end end -# The root of all contracts where the call is after the execution of the original method (`invariant` and `ensure`). -abstract class BottomMContract - super MContract +redef class BottomMContract - redef fun create_nblock(v: ContractsVisitor, n_condition: AExpr, args: Array[AExpr]): ABlockExpr + redef fun is_called(v: ContractsVisitor, mpropdef: MPropDef): Bool + do + return super or v.mainmodule.mpackage == mpropdef.mclassdef.mmodule.mpackage + end + + redef fun create_inherit_nblock(v: ContractsVisitor, n_conditions: Array[AExpr], super_args: Array[AExpr]): ABlockExpr do - var tid = new TId.init_tk(v.current_location) - tid.text = "{contract_name}" - # Creating the assert expression with the new condition - var assert_block = v.ast_builder.make_assert(tid,n_condition,null) - # Creating the super call to the contract - var super_call = v.ast_builder.make_super_call(args,null) # Define contract block var n_block = v.ast_builder.make_block - # Adding the expressions to the block + + var super_call = v.ast_builder.make_super_call(super_args) + n_block.add super_call - n_block.add assert_block + for n_condition in n_conditions do + var tid = new TId.init_tk(n_condition.location) + tid.text = "{n_condition.location.text}" + # Creating the assert expression with the new condition + var n_assert = v.ast_builder.make_assert(tid, n_condition) + n_assert.location = n_condition.location + n_block.add n_assert + end return n_block end - # Inject the result variable in the `n_block` of the given `n_mpropdef`. + # Inject the `result` variable into the `n_block` of the given n_mpropdef`. + # + # The purpose of the variable is to capture return values to use it in contracts. private fun inject_result(v: ContractsVisitor, n_mpropdef: AMethPropdef, ret_type: MType): Variable + is + expect(n_mpropdef.n_signature.n_type != null) do var actual_block = n_mpropdef.n_block # never happen. If it's the case the problem is in the contract facet building assert actual_block isa ABlockExpr - var return_var: nullable Variable = null - var return_expr = actual_block.n_expr.last.as(AReturnExpr) var returned_expr = return_expr.n_expr # The return node has no returned expression assert returned_expr != null - # Check if the result variable already exit - if returned_expr isa AVarExpr then - if returned_expr.variable.name == "result" then - return_var = returned_expr.variable - end - end - - return_var = new Variable("result") + var return_var = new Variable("result") # Creating a new variable to keep the old return of the method var assign_result = v.ast_builder.make_var_assign(return_var, returned_expr) # Remove the actual return @@ -435,13 +506,7 @@ abstract class BottomMContract end end -# A ensure (postcondition) representation -# This method check if the called method respects the expectations of the caller. -class MEnsure - super BottomMContract - - # Define the name of the contract - redef fun contract_name: String do return "ensure" +redef class MEnsure redef fun adapt_specific_msignature(m_signature: MSignature): MSignature do @@ -453,14 +518,12 @@ class MEnsure return n_signature.adapt_to_ensurecondition end - redef fun adapt_block_to_contract(v: ContractsVisitor, n_mpropdef: AMethPropdef) + redef fun adapt_method_to_contract(v: ContractsVisitor, mfacet: MFacet, n_mpropdef: AMethPropdef) do var callsite = v.ast_builder.create_callsite(v.toolcontext.modelbuilder, n_mpropdef, self, true) var n_self = new ASelfExpr # argument to call the contract method var args = n_mpropdef.n_signature.make_parameter_read(v.ast_builder) - # Inject the variable result - # The cast is always safe because the online adapted method is the contract facet var actual_block = n_mpropdef.n_block # never happen. If it's the case the problem is in the contract facet building @@ -468,164 +531,120 @@ class MEnsure var ret_type = n_mpropdef.mpropdef.mproperty.intro.msignature.return_mtype if ret_type != null then + # Inject the variable result var result_var = inject_result(v, n_mpropdef, ret_type) # Expr to read the result variable var read_result = v.ast_builder.make_var_read(result_var, ret_type) var return_expr = actual_block.n_expr.pop # Adding the read return to argument args.add(read_result) - var n_callcontract = v.ast_builder.make_call(n_self,callsite,args) - actual_block.add_all([n_callcontract,return_expr]) + var n_call_contract = v.ast_builder.make_call(n_self, callsite, args) + actual_block.add_all([v.encapsulated_contract_call(n_mpropdef, [n_call_contract]), return_expr]) else # build the call to the contract method - var n_callcontract = v.ast_builder.make_call(n_self,callsite,args) - actual_block.add n_callcontract + var n_call_contract = v.ast_builder.make_call(n_self, callsite, args) + actual_block.add v.encapsulated_contract_call(n_mpropdef, [n_call_contract]) end - end -end - -redef class MClass - - # This method create an abstract method representation with this MMethodDef an this AMethoddef - private fun create_abstract_method(v: ContractsVisitor, mproperty: MMethod, mclassdef: MClassDef, msignature: nullable MSignature, n_signature: ASignature): AMethPropdef - do - # new methoddef definition - var m_def = new MMethodDef(mclassdef, mproperty, v.current_location) - # set the signature - if msignature != null then m_def.msignature = msignature.clone - # set the abstract flag - m_def.is_abstract = true - # Build the new node method - var n_def = v.ast_builder.make_method(null,null,m_def,n_signature,null,null,null,null) - # Define the location of the new method for corresponding of the actual method - n_def.location = v.current_location - # Association new npropdef to mpropdef - v.toolcontext.modelbuilder.unsafe_add_mpropdef2npropdef(m_def,n_def) - return n_def - end - - # Create method with an empty block - # the `mproperty` i.e the global property definition. The mclassdef to set where the method is declared and it's model `msignature` and ast `n_signature` signature - private fun create_empty_method(v: ContractsVisitor, mproperty: MMethod, mclassdef: MClassDef, msignature: nullable MSignature, n_signature: ASignature): AMethPropdef - do - var n_def = create_abstract_method(v, mproperty, mclassdef, msignature, n_signature) - n_def.mpropdef.is_abstract = false - n_def.n_block = v.ast_builder.make_block - return n_def + n_mpropdef.do_all(v.toolcontext) + mfacet.has_applied_ensure = true end end redef class MMethod - # The contract facet of the method - # it's representing the method with contract - # This method call the contract and the method - var mcontract_facet: nullable MMethod = null - - # The expected contract method - var mexpect: nullable MExpect = null - - # The ensure contract method - var mensure: nullable MEnsure = null - - # Check if the MMethod has no ensure contract - # if this is the case returns false and built it - # else return true - private fun check_exist_ensure: Bool - do - if self.mensure != null then return true - # build a new `MEnsure` contract - self.mensure = new MEnsure(intro_mclassdef, "_ensure_{name}", intro_mclassdef.location, public_visibility) - return false - end - - # Check if the MMethod has no expect contract - # if this is the case returns false and built it - # else return true - private fun check_exist_expect: Bool - do - if self.mexpect != null then return true - # build a new `MExpect` contract - self.mexpect = new MExpect(intro_mclassdef, "_expect_{name}", intro_mclassdef.location, public_visibility) - return false - end - - # Check if the MMethod has an contract facet - # If the method has no contract facet she create it - private fun check_exist_contract_facet(mpropdef : MMethodDef): Bool - do - if self.mcontract_facet != null then return true - # build a new `MMethod` contract - self.mcontract_facet = new MMethod(intro_mclassdef, "_contract_{name}", intro_mclassdef.location, public_visibility) - return false - end -end - -redef class MMethodDef - - # Verification of the contract facet - # Check if a contract facet already exists to use it again or if it is necessary to create it. - private fun check_contract_facet(v: ContractsVisitor, n_signature: ASignature, classdef: MClassDef, mcontract: MContract, exist_contract: Bool) - do - var exist_contract_facet = mproperty.check_exist_contract_facet(self) - if exist_contract_facet and exist_contract then return - - var contract_facet: AMethPropdef + # Define contract facet for MMethod in the given mclassdef. The facet represents the entry point with contracts (expect, ensure) of the method. + # If a contract is given adapt the contract facet. + # + # `classdef`: Indicates the class where we want to introduce our facet + # `exist_contract`: Indicates if it is necessary to define a new facet for the contract. If `exist_contract_facet and exist_contract` it's not necessary to add a facet. + # + # Exemple: + # ~~~nitish + # from: + # classe A + # i :Int + # fun add_one is ensure(old(i) + 1 == i) + # end + # to: + # classe A + # fun add_one is ensure(old(i) + 1 == i) + # + # # The contract facet + # fun contract_add_one do + # add_one + # ensure_add_one(old_add_one) + # end + # end + # ~~ + private fun define_contract_facet(v: ContractsVisitor, classdef: MClassDef, mcontract: nullable MContract) + do + var exist_contract_facet = has_contract_facet + var contract_facet = build_contract_facet + # Do nothing the contract and the contract facet already exist + if mcontract != null and mcontract.is_already_applied(contract_facet) then return + + var n_contract_facet: AMethPropdef if not exist_contract_facet then # If has no contract facet in intro just create it - if classdef != mproperty.intro_mclassdef then create_contract_facet(v, mproperty.intro_mclassdef, n_signature) - # If has no contract facet just create it - contract_facet = create_contract_facet(v, classdef, n_signature) + if classdef != intro_mclassdef then + var n_intro_face = create_facet(v, intro_mclassdef, contract_facet, self) + n_intro_face.location = self.intro.location + n_intro_face.do_all(v.toolcontext) + end + n_contract_facet = create_facet(v, classdef, contract_facet, self) else # Check if the contract facet already exist in this context (in this classdef) - if classdef.mpropdefs_by_property.has_key(mproperty.mcontract_facet) then - # get the define - contract_facet = v.toolcontext.modelbuilder.mpropdef2node(classdef.mpropdefs_by_property[mproperty.mcontract_facet]).as(AMethPropdef) + if classdef.mpropdefs_by_property.has_key(contract_facet) then + # get the definition + n_contract_facet = v.toolcontext.modelbuilder.mpropdef2node(classdef.mpropdefs_by_property[contract_facet]).as(AMethPropdef) else # create a new contract facet definition - contract_facet = create_contract_facet(v, classdef, n_signature) + n_contract_facet = create_facet(v, classdef, contract_facet, self) var block = v.ast_builder.make_block # super call to the contract facet - var n_super_call = v.ast_builder.make_super_call(n_signature.make_parameter_read(v.ast_builder), null) + var args = n_contract_facet.n_signature.make_parameter_read(v.ast_builder) + var n_super_call = v.ast_builder.make_super_call(args) # verification for add a return or not - if contract_facet.mpropdef.msignature.return_mtype != null then + if self.intro.msignature.return_mtype != null then block.add(v.ast_builder.make_return(n_super_call)) else block.add(n_super_call) end - contract_facet.n_block = block + n_contract_facet.n_block = block end end - contract_facet.adapt_block_to_contract(v, mcontract, contract_facet) - contract_facet.location = v.current_location - contract_facet.do_all(v.toolcontext) - end + if mcontract != null then mcontract.adapt_method_to_contract(v, contract_facet, n_contract_facet) - # Method to create a contract facet of the method - private fun create_contract_facet(v: ContractsVisitor, classdef: MClassDef, n_signature: ASignature): AMethPropdef - do - var contract_facet = mproperty.mcontract_facet - assert contract_facet != null - # Defines the contract phase is an init or not - # it is necessary to use the contracts on constructor - contract_facet.is_init = self.mproperty.is_init - - # check if the method has an `msignature` to copy it. - var m_signature: nullable MSignature = null - if mproperty.intro.msignature != null then m_signature = mproperty.intro.msignature.clone + n_contract_facet.location = v.current_location + n_contract_facet.do_all(v.toolcontext) + end - var n_contractdef = classdef.mclass.create_empty_method(v, contract_facet, classdef, m_signature, n_signature) + # Method to create a facet of the method. + # See `define_contract_facet` for more information about two types of facets. + # + # `called` : is the property to call in this facet. + private fun create_facet(v: ContractsVisitor, classdef: MClassDef, facet: MFacet, called: MMethod): AMethPropdef + is + expect( called.is_same_instance(self) or called.is_same_instance(self.mcontract_facet) ) + do + # Defines the contract facet is an init or not + # it is necessary to use the contracts with in a constructor + facet.is_init = is_init + var n_contractdef = v.toolcontext.modelbuilder.create_method_from_property(facet, classdef, false, self.intro.msignature) # FIXME set the location because the callsite creation need the node location n_contractdef.location = v.current_location n_contractdef.validate var block = v.ast_builder.make_block - var n_self = new ASelfExpr - var args = n_contractdef.n_signature.make_parameter_read(v.ast_builder) - var callsite = v.ast_builder.create_callsite(v.toolcontext.modelbuilder, n_contractdef, mproperty, true) - var n_call = v.ast_builder.make_call(n_self, callsite, args) - if m_signature.return_mtype == null then + # Arguments to call the `called` property + var args: Array[AExpr] + args = n_contractdef.n_signature.make_parameter_read(v.ast_builder) + + var callsite = v.ast_builder.create_callsite(v.toolcontext.modelbuilder, n_contractdef, called, true) + var n_call = v.ast_builder.make_call(new ASelfExpr, callsite, args) + + if self.intro.msignature.return_mtype == null then block.add(n_call) else block.add(v.ast_builder.make_return(n_call)) @@ -635,150 +654,138 @@ redef class MMethodDef n_contractdef.do_all(v.toolcontext) return n_contractdef end +end + +redef class MMethodDef # Entry point to build contract (define the contract facet and define the contract method verification) - private fun construct_contract(v: ContractsVisitor, n_signature: ASignature, n_annotation: AAnnotation, mcontract: MContract, exist_contract: Bool) + private fun construct_contract(v: ContractsVisitor, n_signature: ASignature, n_annotations: Array[AAnnotation], mcontract: MContract, exist_contract: Bool) do - if check_same_contract(v, n_annotation, mcontract) then return - if not exist_contract and not is_intro then no_intro_contract(v, n_signature, mcontract, n_annotation) v.define_signature(mcontract, n_signature, mproperty.intro.msignature) - - var conditiondef = v.build_contract(n_annotation, mcontract, mclassdef) - check_contract_facet(v, n_signature.clone, mclassdef, mcontract, exist_contract) - has_contract = true + if not exist_contract and not is_intro then no_intro_contract(v, mcontract, n_annotations) + v.build_contract(n_annotations, mcontract, mclassdef) + # Check if the contract must be called to know if it's needed to construct the facet + if mcontract.is_called(v, self) then mproperty.define_contract_facet(v, mclassdef, mcontract) end # Create a contract on the introduction classdef of the property. # Display an warning message if necessary - private fun no_intro_contract(v: ContractsVisitor, n_signature: ASignature, mcontract: MContract, n_annotation: AAnnotation) + private fun no_intro_contract(v: ContractsVisitor, mcontract: MContract, n_annotations: Array[AAnnotation]) do - mcontract.create_empty_contract(v, mcontract.intro_mclassdef, mcontract.adapt_msignature(self.mproperty.intro.msignature), mcontract.adapt_nsignature(n_signature)) - mcontract.no_intro_contract(v, n_annotation) - mproperty.intro.has_contract = true + v.toolcontext.modelbuilder.create_method_from_property(mcontract, mcontract.intro_mclassdef, false, v.m_signature) + mcontract.no_intro_contract(v, n_annotations) end - # Is the contract already defined in the context - # - # Exemple : - # fun foo is expect([...]), expect([...]) - # - # Here `check_same_contract` display an error when the second expect is processed - private fun check_same_contract(v: ContractsVisitor, n_annotation: AAnnotation ,mcontract: MContract): Bool + # Apply the `no_contract` annotation to the contract. This method removes the inheritance by adding an empty contract method. + # Display a warning if the annotation is not needed + private fun no_contract_apply(v: ContractsVisitor, n_signature: ASignature) do - if self.mclassdef.mpropdefs_by_property.has_key(mcontract) then - v.toolcontext.error(n_annotation.location, "The method already has a defined `{mcontract.contract_name}` contract at line {self.mclassdef.mpropdefs_by_property[mcontract].location.line_start}") - return true + var mensure = mproperty.mensure + var mexpect = mproperty.mexpect + if mensure == null and mexpect == null then + v.toolcontext.warning(location, "useless_nocontract", "Useless `no_contract`, no contract was declared for `{name}`. Remove the `no_contract`") + end + if mensure != null then + # Add an empty ensure method to replace the actual definition + v.toolcontext.modelbuilder.create_method_from_property(mensure, mclassdef, false, mensure.intro.msignature) + end + if mexpect != null then + # Add an empty expect method to replace the actual definition + v.toolcontext.modelbuilder.create_method_from_property(mexpect, mclassdef, false, mexpect.intro.msignature) end - return false end end -redef class MPropDef - # flag to indicate is the `MPropDef` has a contract - var has_contract = false -end - redef class APropdef redef fun check_callsite(v) do - v.visited_method = self + v.visited_propdef = self end end redef class AMethPropdef - # Execute all method verification scope flow and typing. - # It also execute an ast validation to define all parents and all locations - private fun do_all(toolcontext: ToolContext) - do - self.validate - # FIXME: The `do_` usage it is maybe to much (verification...). Solution: Cut the `do_` methods into simpler parts - self.do_scope(toolcontext) - self.do_flow(toolcontext) - self.do_typing(toolcontext.modelbuilder) - end - # Entry point to create a contract (verification of inheritance, or new contract). redef fun create_contracts(v) do v.ast_builder.check_mmodule(mpropdef.mclassdef.mmodule) - v.current_location = self.location v.is_intro_contract = mpropdef.is_intro + check_annotation(v) + if not mpropdef.is_intro then check_redef(v) + end - if n_annotations != null then - for n_annotation in n_annotations.n_items do - check_annotation(v,n_annotation) - end + # Verification of the annotation to know if it is a contract annotation. + # If this is the case, we built the appropriate contract. + private fun check_annotation(v: ContractsVisitor) + do + var annotations_expect = get_annotations("expect") + var annotations_ensure = get_annotations("ensure") + var annotation_no_contract = get_annotations("no_contract") + + if (not annotations_expect.is_empty or not annotations_ensure.is_empty) and not annotation_no_contract.is_empty then + v.toolcontext.error(location, "The new contract definition is not correct when using `no_contract`. Remove the contract definition or the `no_contract`") + return end - if not mpropdef.is_intro and not v.find_no_contract then - self.check_redef(v) + var nsignature = n_signature or else new ASignature + + if not annotation_no_contract.is_empty then + mpropdef.no_contract_apply(v, nsignature.clone) + return end - # reset the flag - v.find_no_contract = false - end + if not annotations_expect.is_empty then + var exist_contract = mpropdef.mproperty.has_expect + mpropdef.construct_contract(v, nsignature.clone, annotations_expect, mpropdef.mproperty.build_expect, exist_contract) + end - # Verification of the annotation to know if it is a contract annotation. - # If this is the case, we built the appropriate contract. - private fun check_annotation(v: ContractsVisitor, n_annotation: AAnnotation) - do - if n_annotation.name == "expect" then - if not v.check_usage_expect(mpropdef.mclassdef.mmodule) then return - var exist_contract = mpropdef.mproperty.check_exist_expect - mpropdef.construct_contract(v, self.n_signature.as(not null), n_annotation, mpropdef.mproperty.mexpect.as(not null), exist_contract) - else if n_annotation.name == "ensure" then - if not v.check_usage_ensure(mpropdef.mclassdef.mmodule) then return - var exist_contract = mpropdef.mproperty.check_exist_ensure - mpropdef.construct_contract(v, self.n_signature.as(not null), n_annotation, mpropdef.mproperty.mensure.as(not null), exist_contract) - else if n_annotation.name == "no_contract" then - # no_contract found set the flag to true - v.find_no_contract = true + if not annotations_ensure.is_empty then + var exist_contract = mpropdef.mproperty.has_ensure + mpropdef.construct_contract(v, nsignature.clone, annotations_ensure, mpropdef.mproperty.build_ensure, exist_contract) end end # Verification if the method have an inherited contract to apply it. private fun check_redef(v: ContractsVisitor) do - # Check if the method has an attached contract - if not mpropdef.has_contract then - if mpropdef.mproperty.intro.has_contract then - mpropdef.has_contract = true - end - end - end + var mexpect = mpropdef.mproperty.mexpect + var mensure = mpropdef.mproperty.mensure + var mcontract_facet = mpropdef.mproperty.mcontract_facet - # Adapt the block to use the contracts - private fun adapt_block_to_contract(v: ContractsVisitor, contract: MContract, n_mpropdef: AMethPropdef) - do - contract.adapt_block_to_contract(v, n_mpropdef) - mpropdef.has_contract = true - n_mpropdef.do_all(v.toolcontext) + if mexpect != null then + if mcontract_facet != null and mcontract_facet.has_applied_expect then return + if mexpect.is_called(v, mpropdef.as(not null)) then mpropdef.mproperty.define_contract_facet(v, mpropdef.mclassdef, mexpect) + end + if mensure != null then + if mcontract_facet != null and mcontract_facet.has_applied_ensure then return + if mensure.is_called(v, mpropdef.as(not null)) then mpropdef.mproperty.define_contract_facet(v, mpropdef.mclassdef, mensure) + end end end redef class MSignature - # Adapt signature for a expect condition - # Removed the return type is it not necessary - private fun adapt_to_condition: MSignature do return new MSignature(mparameters.to_a, null) + # Adapt signature for an contract + # + # The returned `MSignature` is the copy of `self` without return type. + private fun adapt_to_contract: MSignature do return new MSignature(mparameters.to_a, null) - # Adapt signature for a ensure condition + # Adapt signature for a ensure contract # - # Create new parameter with the return type + # The returned `MSignature` is the copy of `self` without return type. + # The return type is replaced by a new parameter `result` private fun adapt_to_ensurecondition: MSignature do var rtype = return_mtype - var msignature = adapt_to_condition + var msignature = adapt_to_contract if rtype != null then msignature.mparameters.add(new MParameter("result", rtype, false)) end return msignature end - # Adapt signature for a expect condition - # Removed the return type is it not necessary + # The returned `MSignature` is the exact copy of `self`. private fun clone: MSignature do return new MSignature(mparameters.to_a, return_mtype) end @@ -798,26 +805,26 @@ redef class ASignature return args end - # Return a copy of self adapted for the expect condition - # npropdef it is use to define the parent of the parameters - private fun adapt_to_condition(return_type: nullable AType): ASignature + # Create a new ASignature adapted for contract + # + # The returned `ASignature` is the copy of `self` without return type. + private fun adapt_to_contract: ASignature do var adapt_nsignature = self.clone - adapt_nsignature.n_type = return_type + if adapt_nsignature.n_type != null then adapt_nsignature.n_type.detach return adapt_nsignature end - # Return a copy of self adapted for postcondition on npropdef + # Create a new ASignature adapted for ensure + # + # The returned `ASignature` is the copy of `self` without return type. + # The return type is replaced by a new parameter `result` private fun adapt_to_ensurecondition: ASignature do - var nsignature = adapt_to_condition(null) + var nsignature = adapt_to_contract if ret_type != null then - var n_id = new TId - n_id.text = "result" - var new_param = new AParam - new_param.n_id = n_id - new_param.variable = new Variable(n_id.text) - new_param.variable.declared_type = ret_type - nsignature.n_params.add new_param + var variable = new Variable("result") + variable.declared_type = ret_type + nsignature.n_params.add new AParam.make(variable, ret_type.create_ast_representation) end return nsignature end @@ -828,7 +835,9 @@ redef class ASendExpr do var actual_callsite = callsite if actual_callsite != null then - callsite = v.drive_method_contract(actual_callsite) + callsite = v.drive_callsite_to_contract(actual_callsite) + # Set the signature mapping with the old value, this avoids having to re-check the callsite. + callsite.signaturemap = actual_callsite.signaturemap end end end @@ -838,7 +847,9 @@ redef class ANewExpr do var actual_callsite = callsite if actual_callsite != null then - callsite = v.drive_method_contract(actual_callsite) + callsite = v.drive_callsite_to_contract(actual_callsite) + # Set the signature mapping with the old value, this avoids having to re-check the callsite + callsite.signaturemap = actual_callsite.signaturemap end end end diff --git a/src/doc/commands/tests/test_commands_http.nit b/src/doc/commands/tests/test_commands_http.nit index 57f5dd6..1f51238 100644 --- a/src/doc/commands/tests/test_commands_http.nit +++ b/src/doc/commands/tests/test_commands_http.nit @@ -205,7 +205,7 @@ class TestCommandsHttp var cmd = new CmdFeatures(test_model) var res = cmd.http_init(req) assert res isa CmdSuccess - assert cmd.results.as(not null).length == 3 + assert cmd.results.as(not null).length == 4 end # CmdLinearization @@ -215,7 +215,7 @@ class TestCommandsHttp var cmd = new CmdLinearization(test_model, test_main) var res = cmd.http_init(req) assert res isa CmdSuccess - assert cmd.results.as(not null).length == 10 + assert cmd.results.as(not null).length == 9 end fun test_cmd_http_lin_no_lin is test do diff --git a/src/doc/commands/tests/test_commands_model.nit b/src/doc/commands/tests/test_commands_model.nit index 4847987..0ee6952 100644 --- a/src/doc/commands/tests/test_commands_model.nit +++ b/src/doc/commands/tests/test_commands_model.nit @@ -181,7 +181,7 @@ class TestCommandsModel var cmd = new CmdFeatures(test_model, mentity_name = "test_prog::Career") var res = cmd.init_command assert res isa CmdSuccess - assert cmd.results.as(not null).length == 10 + assert cmd.results.as(not null).length == 11 end fun test_cmd_features_with_filter_attribute is test do @@ -189,7 +189,7 @@ class TestCommandsModel var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::Career") var res = cmd.init_command assert res isa CmdSuccess - assert cmd.results.as(not null).length == 7 + assert cmd.results.as(not null).length == 8 end fun test_cmd_features_with_filter_public is test do @@ -197,7 +197,7 @@ class TestCommandsModel var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::Career") var res = cmd.init_command assert res isa CmdSuccess - assert cmd.results.as(not null).length == 4 + assert cmd.results.as(not null).length == 5 end fun test_cmd_features_with_filter_match is test do @@ -214,7 +214,7 @@ class TestCommandsModel var cmd = new CmdFeatures(test_model, filter, mentity_name = "test_prog::TestGame") var res = cmd.init_command assert res isa CmdSuccess - assert cmd.results.as(not null).length == 3 + assert cmd.results.as(not null).length == 4 end fun test_cmd_features_no_features is test do @@ -229,7 +229,7 @@ class TestCommandsModel var cmd = new CmdLinearization(test_model, test_main, mentity_name = "init") var res = cmd.init_command assert res isa CmdSuccess - assert cmd.results.as(not null).length == 10 + assert cmd.results.as(not null).length == 9 end fun test_cmd_lin_no_lin is test do diff --git a/src/doc/commands/tests/test_commands_parser.nit b/src/doc/commands/tests/test_commands_parser.nit index 41cc36b..f5d6699 100644 --- a/src/doc/commands/tests/test_commands_parser.nit +++ b/src/doc/commands/tests/test_commands_parser.nit @@ -239,7 +239,7 @@ class TestCommandsParser var cmd = parser.parse("defs: test_prog::TestGame | inherited: TestGame") assert cmd isa CmdFeatures assert parser.error == null - assert cmd.results.as(not null).length == 3 + assert cmd.results.as(not null).length == 4 end # CmdLinearization diff --git a/src/doc/templates/html_model.nit b/src/doc/templates/html_model.nit index 1b86587..90cd190 100644 --- a/src/doc/templates/html_model.nit +++ b/src/doc/templates/html_model.nit @@ -251,10 +251,6 @@ end redef class MMethodDef redef fun html_signature(short) do - var new_msignature = self.new_msignature - if mproperty.is_root_init and new_msignature != null then - return new_msignature.html_signature(short) - end var msignature = self.msignature if msignature == null then return new Template return msignature.html_signature(short) diff --git a/src/doc/templates/term_model.nit b/src/doc/templates/term_model.nit index 55351fb..b33ce7f 100644 --- a/src/doc/templates/term_model.nit +++ b/src/doc/templates/term_model.nit @@ -199,9 +199,6 @@ end redef class MMethodDef redef fun cs_signature(no_color) do - if mproperty.is_root_init then - return new_msignature.as(not null).cs_signature(no_color) - end return msignature.as(not null).cs_signature(no_color) end end diff --git a/src/doc/templates/tests/test_html_commands.sav/test_cmd_call.res b/src/doc/templates/tests/test_html_commands.sav/test_cmd_call.res index 6663e41..ab2acab 100644 --- a/src/doc/templates/tests/test_html_commands.sav/test_cmd_call.res +++ b/src/doc/templates/tests/test_html_commands.sav/test_cmd_call.res @@ -1 +1 @@ - + diff --git a/src/doc/templates/tests/test_html_commands.sav/test_cmd_features.res b/src/doc/templates/tests/test_html_commands.sav/test_cmd_features.res index 8904ee1..2f71284 100644 --- a/src/doc/templates/tests/test_html_commands.sav/test_cmd_features.res +++ b/src/doc/templates/tests/test_html_commands.sav/test_cmd_features.res @@ -1 +1 @@ - + diff --git a/src/doc/templates/tests/test_html_commands.sav/test_cmd_lin.res b/src/doc/templates/tests/test_html_commands.sav/test_cmd_lin.res index 3ae2de3..c7f7cf4 100644 --- a/src/doc/templates/tests/test_html_commands.sav/test_cmd_lin.res +++ b/src/doc/templates/tests/test_html_commands.sav/test_cmd_lin.res @@ -1 +1 @@ - + diff --git a/src/doc/templates/tests/test_json_commands.sav/test_cmd_call.res b/src/doc/templates/tests/test_json_commands.sav/test_cmd_call.res index 0b60952..087789a 100644 --- a/src/doc/templates/tests/test_json_commands.sav/test_cmd_call.res +++ b/src/doc/templates/tests/test_json_commands.sav/test_cmd_call.res @@ -1,6 +1,6 @@ { "results": [{ - "name": "init", + "name": "defaultinit", "namespace": [{ "name": "test_prog", "synopsis": "Test program for model tools." @@ -8,18 +8,48 @@ "name": "Character", "synopsis": "Characters can be played by both the human or the machine." }, "$", { - "name": "Object", - "synopsis": "Root of everything." - }, "::", { - "name": "init" + "name": "defaultinit" }], "class_name": "MMethodDef", - "full_name": "test_prog$Character$Object::init", + "full_name": "test_prog$Character$defaultinit", "visibility": "public", - "modifiers": ["redef", "init"], + "modifiers": ["init"], + "is_intro": true, "msignature": { - "arity": 0, - "mparameters": [], + "arity": 4, + "mparameters": [{ + "is_vararg": false, + "name": "race", + "mtype": { + "name": "Race", + "synopsis": "Race determines basic characteristics and what the character will be able to do in life.", + "html_synopsis": "Race determines basic characteristics and what the character will be able to do in life." + } + }, { + "is_vararg": false, + "name": "name", + "mtype": { + "name": "String", + "synopsis": "Strings (there is no chars...).", + "html_synopsis": "Strings (there is no chars...)." + } + }, { + "is_vararg": false, + "name": "age", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "sex", + "mtype": { + "name": "Bool", + "synopsis": "Booleans, `true` or `false`.", + "html_synopsis": "Booleans, true or false." + } + }], "return_mtype": null } }, { diff --git a/src/doc/templates/tests/test_json_commands.sav/test_cmd_features.res b/src/doc/templates/tests/test_json_commands.sav/test_cmd_features.res index 88019d8..e07fe59 100644 --- a/src/doc/templates/tests/test_json_commands.sav/test_cmd_features.res +++ b/src/doc/templates/tests/test_json_commands.sav/test_cmd_features.res @@ -69,6 +69,51 @@ "html_synopsis": "Some services about Integers." } }, { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Career", + "synopsis": "A `Career` gives a characteristic bonus or malus to the character." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Career::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "strength_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "endurance_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "intelligence_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } + }, { "name": "endurance_bonus", "namespace": [{ "name": "test_prog", diff --git a/src/doc/templates/tests/test_json_commands.sav/test_cmd_lin.res b/src/doc/templates/tests/test_json_commands.sav/test_cmd_lin.res index c7ddd5a..957889a 100644 --- a/src/doc/templates/tests/test_json_commands.sav/test_cmd_lin.res +++ b/src/doc/templates/tests/test_json_commands.sav/test_cmd_lin.res @@ -187,29 +187,6 @@ "name": "test_prog", "synopsis": "Test program for model tools." }, "$", { - "name": "Character", - "synopsis": "Characters can be played by both the human or the machine." - }, "$", { - "name": "Object", - "synopsis": "Root of everything." - }, "::", { - "name": "init" - }], - "class_name": "MMethodDef", - "full_name": "test_prog$Character$Object::init", - "visibility": "public", - "modifiers": ["redef", "init"], - "msignature": { - "arity": 0, - "mparameters": [], - "return_mtype": null - } - }, { - "name": "init", - "namespace": [{ - "name": "test_prog", - "synopsis": "Test program for model tools." - }, "$", { "name": "Dwarf", "synopsis": "Dwarves make strong warriors." }, "$", { diff --git a/src/doc/templates/tests/test_json_model.sav/test_propdefs_to_full_json.res b/src/doc/templates/tests/test_json_model.sav/test_propdefs_to_full_json.res index 802b1ec..126aca2 100644 --- a/src/doc/templates/tests/test_json_model.sav/test_propdefs_to_full_json.res +++ b/src/doc/templates/tests/test_json_model.sav/test_propdefs_to_full_json.res @@ -312,23 +312,21 @@ } } { - "name": "init", + "name": "defaultinit", "namespace": [{ "name": "test_prog", "synopsis": "Test program for model tools." }, "$", { - "name": "Character", - "synopsis": "Characters can be played by both the human or the machine." - }, "$", { "name": "Object", "synopsis": "Root of everything." - }, "::", { - "name": "init" + }, "$", { + "name": "defaultinit" }], "class_name": "MMethodDef", - "full_name": "test_prog$Character$Object::init", + "full_name": "test_prog$Object$defaultinit", "visibility": "public", - "modifiers": ["redef", "init"], + "modifiers": ["init"], + "is_intro": true, "msignature": { "arity": 0, "mparameters": [], @@ -558,6 +556,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Int", + "synopsis": "Some services about Integers." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Int$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "+", "namespace": [{ "name": "test_prog", @@ -728,6 +748,94 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Float", + "synopsis": "Some services about Floats." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Float$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Bool", + "synopsis": "Booleans, `true` or `false`." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Bool$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "String", + "synopsis": "Strings (there is no chars...)." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$String$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "List", + "synopsis": "List of things." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$List$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "main", "namespace": [{ "name": "test_prog", @@ -774,6 +882,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Sys", + "synopsis": "Sys" + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Sys$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "_strength_bonus", "namespace": [{ "name": "test_prog", @@ -1008,6 +1138,190 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Career", + "synopsis": "A `Career` gives a characteristic bonus or malus to the character." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Career$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "strength_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "endurance_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "intelligence_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Warrior", + "synopsis": "Warriors are good for fighting." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Warrior$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "strength_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "endurance_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "intelligence_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Magician", + "synopsis": "Magicians know magic and how to use it." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Magician$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "strength_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "endurance_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "intelligence_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Alcoholic", + "synopsis": "Alcoholics are good to nothing escept taking punches." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Alcoholic$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "strength_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "endurance_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "intelligence_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ "name": "_base_strength", "synopsis": "Used to represents how strong the race is.", "namespace": [{ @@ -1207,57 +1521,241 @@ } } { - "name": "base_intelligence", - "synopsis": "Is this race smart?", + "name": "base_intelligence", + "synopsis": "Is this race smart?", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Race", + "synopsis": "Race determines basic characteristics and what the character will be able to do in life." + }, "$", { + "name": "base_intelligence", + "synopsis": "Is this race smart?" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Race$base_intelligence", + "visibility": "public", + "html_synopsis": "Is this race smart?", + "modifiers": ["fun"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + } +} +{ + "name": "base_intelligence=", + "synopsis": "Is this race smart?", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Race", + "synopsis": "Race determines basic characteristics and what the character will be able to do in life." + }, "$", { + "name": "base_intelligence=", + "synopsis": "Is this race smart?" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Race$base_intelligence=", + "visibility": "protected", + "html_synopsis": "Is this race smart?", + "modifiers": ["protected", "fun"], + "is_intro": true, + "msignature": { + "arity": 1, + "mparameters": [{ + "is_vararg": false, + "name": "base_intelligence", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Race", + "synopsis": "Race determines basic characteristics and what the character will be able to do in life." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Race$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "base_strength", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_endurance", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_intelligence", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Human", + "synopsis": "Humans are able to do everithing." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Human$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "base_strength", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_endurance", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_intelligence", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", "namespace": [{ "name": "test_prog", "synopsis": "Test program for model tools." }, "$", { - "name": "Race", - "synopsis": "Race determines basic characteristics and what the character will be able to do in life." + "name": "Dwarf", + "synopsis": "Dwarves make strong warriors." }, "$", { - "name": "base_intelligence", - "synopsis": "Is this race smart?" + "name": "defaultinit" }], "class_name": "MMethodDef", - "full_name": "test_prog$Race$base_intelligence", + "full_name": "test_prog$Dwarf$defaultinit", "visibility": "public", - "html_synopsis": "Is this race smart?", - "modifiers": ["fun"], + "modifiers": ["init"], "is_intro": true, "msignature": { - "arity": 0, - "mparameters": [], - "return_mtype": { - "name": "Int", - "synopsis": "Some services about Integers.", - "html_synopsis": "Some services about Integers." - } + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "base_strength", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_endurance", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_intelligence", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null } } { - "name": "base_intelligence=", - "synopsis": "Is this race smart?", + "name": "defaultinit", "namespace": [{ "name": "test_prog", "synopsis": "Test program for model tools." }, "$", { - "name": "Race", - "synopsis": "Race determines basic characteristics and what the character will be able to do in life." + "name": "Elf", + "synopsis": "Elves make good magicians." }, "$", { - "name": "base_intelligence=", - "synopsis": "Is this race smart?" + "name": "defaultinit" }], "class_name": "MMethodDef", - "full_name": "test_prog$Race$base_intelligence=", - "visibility": "protected", - "html_synopsis": "Is this race smart?", - "modifiers": ["protected", "fun"], + "full_name": "test_prog$Elf$defaultinit", + "visibility": "public", + "modifiers": ["init"], "is_intro": true, "msignature": { - "arity": 1, + "arity": 3, "mparameters": [{ "is_vararg": false, + "name": "base_strength", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_endurance", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, "name": "base_intelligence", "mtype": { "name": "Int", @@ -1902,6 +2400,60 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Character", + "synopsis": "Characters can be played by both the human or the machine." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Character$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 4, + "mparameters": [{ + "is_vararg": false, + "name": "race", + "mtype": { + "name": "Race", + "synopsis": "Race determines basic characteristics and what the character will be able to do in life.", + "html_synopsis": "Race determines basic characteristics and what the character will be able to do in life." + } + }, { + "is_vararg": false, + "name": "name", + "mtype": { + "name": "String", + "synopsis": "Strings (there is no chars...).", + "html_synopsis": "Strings (there is no chars...)." + } + }, { + "is_vararg": false, + "name": "age", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "sex", + "mtype": { + "name": "Bool", + "synopsis": "Booleans, `true` or `false`.", + "html_synopsis": "Booleans, true or false." + } + }], + "return_mtype": null + } +} +{ "name": "dps", "synopsis": "Damage per second inflicted by this weapon.", "namespace": [{ @@ -1965,6 +2517,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Weapon", + "synopsis": "Something that can be used to attack someone and inflict damage." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Weapon$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "hit_points", "namespace": [{ "name": "test_prog", @@ -2181,6 +2755,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Combatable", + "synopsis": "Something that can be combatted, it can `attack` and `defend`." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Combatable$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "player_characters", "synopsis": "Characters played by human players.", "namespace": [{ @@ -2487,6 +3083,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Game", + "synopsis": "This is the interface you have to implement to use ure gaming platform." + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Game$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "_player_characters", "namespace": [{ "name": "test_prog", @@ -2591,6 +3209,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "MyGame", + "synopsis": "This is an example of how to implement the Game interface" + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$MyGame$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "start", "namespace": [{ "name": "test_prog", @@ -2612,6 +3252,27 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "Starter" + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$Starter$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "_player_characters", "namespace": [{ "name": "test_prog", @@ -2662,6 +3323,27 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "TestGame" + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$TestGame$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "test_game", "namespace": [{ "name": "test_prog", @@ -2682,3 +3364,24 @@ "return_mtype": null } } +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "$", { + "name": "GameTest" + }, "$", { + "name": "defaultinit" + }], + "class_name": "MMethodDef", + "full_name": "test_prog$GameTest$defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_intro": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} diff --git a/src/doc/templates/tests/test_json_model.sav/test_props_to_full_json.res b/src/doc/templates/tests/test_json_model.sav/test_props_to_full_json.res index 09644aa..4b49e79 100644 --- a/src/doc/templates/tests/test_json_model.sav/test_props_to_full_json.res +++ b/src/doc/templates/tests/test_json_model.sav/test_props_to_full_json.res @@ -117,6 +117,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Object", + "synopsis": "Root of everything." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Object::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "unary -", "namespace": [{ "name": "test_prog", @@ -332,6 +354,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Int", + "synopsis": "Some services about Integers." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Int::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "+", "namespace": [{ "name": "test_prog", @@ -497,6 +541,94 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Float", + "synopsis": "Some services about Floats." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Float::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Bool", + "synopsis": "Booleans, `true` or `false`." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Bool::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "String", + "synopsis": "Strings (there is no chars...)." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::String::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "List", + "synopsis": "List of things." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::List::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "main", "namespace": [{ "name": "test_prog", @@ -518,6 +650,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Sys", + "synopsis": "Sys" + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Sys::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "_strength_bonus", "namespace": [{ "name": "test_prog", @@ -752,6 +906,190 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Career", + "synopsis": "A `Career` gives a characteristic bonus or malus to the character." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Career::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "strength_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "endurance_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "intelligence_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Warrior", + "synopsis": "Warriors are good for fighting." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Warrior::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "strength_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "endurance_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "intelligence_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Magician", + "synopsis": "Magicians know magic and how to use it." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Magician::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "strength_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "endurance_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "intelligence_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Alcoholic", + "synopsis": "Alcoholics are good to nothing escept taking punches." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Alcoholic::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "strength_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "endurance_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "intelligence_bonus", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ "name": "_base_strength", "synopsis": "Used to represents how strong the race is.", "namespace": [{ @@ -953,55 +1291,239 @@ } } { - "name": "base_intelligence", - "synopsis": "Is this race smart?", + "name": "base_intelligence", + "synopsis": "Is this race smart?", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Race", + "synopsis": "Race determines basic characteristics and what the character will be able to do in life." + }, "::", { + "name": "base_intelligence", + "synopsis": "Is this race smart?" + }], + "class_name": "MMethod", + "full_name": "test_prog::Race::base_intelligence", + "visibility": "public", + "html_synopsis": "Is this race smart?", + "modifiers": ["fun"], + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + } +} +{ + "name": "base_intelligence=", + "synopsis": "Is this race smart?", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Race", + "synopsis": "Race determines basic characteristics and what the character will be able to do in life." + }, "::", { + "name": "base_intelligence=", + "synopsis": "Is this race smart?" + }], + "class_name": "MMethod", + "full_name": "test_prog::Race::base_intelligence=", + "visibility": "protected", + "html_synopsis": "Is this race smart?", + "modifiers": ["protected", "fun"], + "msignature": { + "arity": 1, + "mparameters": [{ + "is_vararg": false, + "name": "base_intelligence", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Race", + "synopsis": "Race determines basic characteristics and what the character will be able to do in life." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Race::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "base_strength", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_endurance", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_intelligence", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Human", + "synopsis": "Humans are able to do everithing." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Human::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "base_strength", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_endurance", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_intelligence", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null + } +} +{ + "name": "defaultinit", "namespace": [{ "name": "test_prog", "synopsis": "Test program for model tools." }, "::", { - "name": "Race", - "synopsis": "Race determines basic characteristics and what the character will be able to do in life." + "name": "Dwarf", + "synopsis": "Dwarves make strong warriors." }, "::", { - "name": "base_intelligence", - "synopsis": "Is this race smart?" + "name": "defaultinit" }], "class_name": "MMethod", - "full_name": "test_prog::Race::base_intelligence", + "full_name": "test_prog::Dwarf::defaultinit", "visibility": "public", - "html_synopsis": "Is this race smart?", - "modifiers": ["fun"], + "modifiers": ["init"], + "is_init": true, "msignature": { - "arity": 0, - "mparameters": [], - "return_mtype": { - "name": "Int", - "synopsis": "Some services about Integers.", - "html_synopsis": "Some services about Integers." - } + "arity": 3, + "mparameters": [{ + "is_vararg": false, + "name": "base_strength", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_endurance", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_intelligence", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }], + "return_mtype": null } } { - "name": "base_intelligence=", - "synopsis": "Is this race smart?", + "name": "defaultinit", "namespace": [{ "name": "test_prog", "synopsis": "Test program for model tools." }, "::", { - "name": "Race", - "synopsis": "Race determines basic characteristics and what the character will be able to do in life." + "name": "Elf", + "synopsis": "Elves make good magicians." }, "::", { - "name": "base_intelligence=", - "synopsis": "Is this race smart?" + "name": "defaultinit" }], "class_name": "MMethod", - "full_name": "test_prog::Race::base_intelligence=", - "visibility": "protected", - "html_synopsis": "Is this race smart?", - "modifiers": ["protected", "fun"], + "full_name": "test_prog::Elf::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, "msignature": { - "arity": 1, + "arity": 3, "mparameters": [{ "is_vararg": false, + "name": "base_strength", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "base_endurance", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, "name": "base_intelligence", "mtype": { "name": "Int", @@ -1641,6 +2163,60 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Character", + "synopsis": "Characters can be played by both the human or the machine." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Character::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 4, + "mparameters": [{ + "is_vararg": false, + "name": "race", + "mtype": { + "name": "Race", + "synopsis": "Race determines basic characteristics and what the character will be able to do in life.", + "html_synopsis": "Race determines basic characteristics and what the character will be able to do in life." + } + }, { + "is_vararg": false, + "name": "name", + "mtype": { + "name": "String", + "synopsis": "Strings (there is no chars...).", + "html_synopsis": "Strings (there is no chars...)." + } + }, { + "is_vararg": false, + "name": "age", + "mtype": { + "name": "Int", + "synopsis": "Some services about Integers.", + "html_synopsis": "Some services about Integers." + } + }, { + "is_vararg": false, + "name": "sex", + "mtype": { + "name": "Bool", + "synopsis": "Booleans, `true` or `false`.", + "html_synopsis": "Booleans, true or false." + } + }], + "return_mtype": null + } +} +{ "name": "dps", "synopsis": "Damage per second inflicted by this weapon.", "namespace": [{ @@ -1669,6 +2245,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Weapon", + "synopsis": "Something that can be used to attack someone and inflict damage." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Weapon::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "hit_points", "namespace": [{ "name": "test_prog", @@ -1846,6 +2444,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Combatable", + "synopsis": "Something that can be combatted, it can `attack` and `defend`." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Combatable::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "player_characters", "synopsis": "Characters played by human players.", "namespace": [{ @@ -1974,6 +2594,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Game", + "synopsis": "This is the interface you have to implement to use ure gaming platform." + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Game::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "_player_characters", "namespace": [{ "name": "test_prog", @@ -2078,6 +2720,28 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "MyGame", + "synopsis": "This is an example of how to implement the Game interface" + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::MyGame::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "start", "namespace": [{ "name": "test_prog", @@ -2098,6 +2762,27 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "Starter" + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::Starter::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "_player_characters", "namespace": [{ "name": "test_prog", @@ -2148,6 +2833,27 @@ } } { + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "TestGame" + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::TestGame::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} +{ "name": "test_game", "namespace": [{ "name": "test_prog", @@ -2167,3 +2873,24 @@ "return_mtype": null } } +{ + "name": "defaultinit", + "namespace": [{ + "name": "test_prog", + "synopsis": "Test program for model tools." + }, "::", { + "name": "GameTest" + }, "::", { + "name": "defaultinit" + }], + "class_name": "MMethod", + "full_name": "test_prog::GameTest::defaultinit", + "visibility": "public", + "modifiers": ["init"], + "is_init": true, + "msignature": { + "arity": 0, + "mparameters": [], + "return_mtype": null + } +} diff --git a/src/doc/templates/tests/test_md_commands.sav/test_cmd_call.res b/src/doc/templates/tests/test_md_commands.sav/test_cmd_call.res index 3ed3eb0..91c5ae8 100644 --- a/src/doc/templates/tests/test_md_commands.sav/test_cmd_call.res +++ b/src/doc/templates/tests/test_md_commands.sav/test_cmd_call.res @@ -1,2 +1,2 @@ -* `character$Character$init` +* `character$Character$defaultinit` * `character$Character$total_strengh` - The actual strength of the character. diff --git a/src/doc/templates/tests/test_md_commands.sav/test_cmd_features.res b/src/doc/templates/tests/test_md_commands.sav/test_cmd_features.res index cfabfc6..9d0a142 100644 --- a/src/doc/templates/tests/test_md_commands.sav/test_cmd_features.res +++ b/src/doc/templates/tests/test_md_commands.sav/test_cmd_features.res @@ -1,6 +1,7 @@ * `_endurance_bonus` * `_intelligence_bonus` * `_strength_bonus` +* `defaultinit` * `endurance_bonus` * `endurance_bonus=` * `careers$Career$init` diff --git a/src/doc/templates/tests/test_md_commands.sav/test_cmd_lin.res b/src/doc/templates/tests/test_md_commands.sav/test_cmd_lin.res index 4f36fb0..c7b37e8 100644 --- a/src/doc/templates/tests/test_md_commands.sav/test_cmd_lin.res +++ b/src/doc/templates/tests/test_md_commands.sav/test_cmd_lin.res @@ -6,5 +6,4 @@ * `careers$Warrior$init` * `careers$Magician$init` * `careers$Alcoholic$init` -* `character$Character$init` * `races$Dwarf$init` diff --git a/src/doc/term/tests/test_term.sav/test_call.res b/src/doc/term/tests/test_term.sav/test_call.res index ac3c732..0947bc2 100644 --- a/src/doc/term/tests/test_term.sav/test_call.res +++ b/src/doc/term/tests/test_term.sav/test_call.res @@ -1,7 +1,7 @@ Methods calling `test_prog::Career::endurance_bonus`: - * test_prog$Character$Object::init - redef init init(race: Race, name: String, age: Int, sex: Bool) + + test_prog$Character$defaultinit + init defaultinit(race: Race, name: String, age: Int, sex: Bool) test_location + test_prog$Character$total_endurance diff --git a/src/doc/term/tests/test_term.sav/test_lin.res b/src/doc/term/tests/test_term.sav/test_lin.res index 23e94dc..532b2e3 100644 --- a/src/doc/term/tests/test_term.sav/test_lin.res +++ b/src/doc/term/tests/test_term.sav/test_lin.res @@ -5,6 +5,6 @@ Linearization for `test_prog::Object::init`: test_location * test_prog$Race$Object::init - redef init init(base_strength: Int, base_endurance: Int, base_intelligence: Int) + redef init init test_location diff --git a/src/doc/term/tests/test_term.sav/test_term_catalog_stats.res b/src/doc/term/tests/test_term.sav/test_term_catalog_stats.res index c8a157d..47521e8 100644 --- a/src/doc/term/tests/test_term.sav/test_term_catalog_stats.res +++ b/src/doc/term/tests/test_term.sav/test_term_catalog_stats.res @@ -1,7 +1,7 @@ Catalog statistics: * 2 packages * 11 modules - * 79 methods + * 101 methods * 26 classes * 509 lines of code * 6 contributors diff --git a/src/frontend/serialization_model_phase.nit b/src/frontend/serialization_model_phase.nit index 7e9a506..a44833d 100644 --- a/src/frontend/serialization_model_phase.nit +++ b/src/frontend/serialization_model_phase.nit @@ -267,8 +267,6 @@ redef init from_deserializer(v) do abort""" end redef class AAttrPropdef - private fun name: String do return n_id2.text - # Name of this attribute in the serialized format private var serialize_name: String = name is lazy end diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index 7557da7..527f16e 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -490,7 +490,7 @@ class NaiveInterpreter # Return `null` if one of the evaluation of the arguments return null. fun varargize(mpropdef: MMethodDef, map: nullable SignatureMap, recv: Instance, args: SequenceRead[AExpr]): nullable Array[Instance] do - var msignature = mpropdef.new_msignature or else mpropdef.msignature.as(not null) + var msignature = mpropdef.msignature.as(not null) var res = new Array[Instance] res.add(recv) @@ -615,28 +615,6 @@ class NaiveInterpreter fun callsite(callsite: nullable CallSite, arguments: Array[Instance]): nullable Instance do if callsite == null then return null - var initializers = callsite.mpropdef.initializers - if not initializers.is_empty then - var recv = arguments.first - var i = 1 - for p in initializers do - if p isa MMethod then - var args = [recv] - for x in p.intro.msignature.mparameters do - args.add arguments[i] - i += 1 - end - self.send(p, args) - else if p isa MAttribute then - assert recv isa MutableInstance - write_attribute(p, recv, arguments[i]) - i += 1 - else abort - end - assert i == arguments.length - - return send(callsite.mproperty, [recv]) - end return send(callsite.mproperty, arguments) end @@ -1657,6 +1635,31 @@ redef class AClassdef v.call(superpd, arguments) end return null + else if mclassdef.default_init == mpropdef then + var recv = arguments.first + var initializers = mpropdef.initializers + var no_init = false + if not initializers.is_empty and not mpropdef.is_old_style_init then + var i = 1 + for p in initializers do + if p isa MMethod then + var args = [recv] + for x in p.intro.msignature.mparameters do + args.add arguments[i] + i += 1 + end + v.send(p, args) + if p.intro.is_calling_init then no_init = true + else if p isa MAttribute then + assert recv isa MutableInstance + v.write_attribute(p, recv, arguments[i]) + i += 1 + else abort + end + assert i == arguments.length + end + if not no_init then v.send(mclass.the_root_init_mmethod.as(not null), [recv]) + return null else abort end diff --git a/src/metrics/ast_metrics.nit b/src/metrics/ast_metrics.nit index d34899e..e5f1e10 100644 --- a/src/metrics/ast_metrics.nit +++ b/src/metrics/ast_metrics.nit @@ -49,7 +49,6 @@ private class AstMetricsVisitor super Visitor var phase: AstMetricsPhase - init(phase: AstMetricsPhase) do self.phase = phase redef fun visit(n) do diff --git a/src/metrics/mclassdef_collect.nit b/src/metrics/mclassdef_collect.nit index 98a4412..2c8f1c5 100644 --- a/src/metrics/mclassdef_collect.nit +++ b/src/metrics/mclassdef_collect.nit @@ -16,7 +16,7 @@ module mclassdef_collect # We usualy need specific phases -# NOTE: `frontend` is sufficent in most case (it is often too much) +# NOTE: `frontend` is sufficent in most cases (it is often too much) import frontend import model_collect diff --git a/src/metrics/method_analyze_metrics.nit b/src/metrics/method_analyze_metrics.nit index bb0612f..95b4ca0 100644 --- a/src/metrics/method_analyze_metrics.nit +++ b/src/metrics/method_analyze_metrics.nit @@ -16,7 +16,7 @@ module method_analyze_metrics # We usualy need specific phases -# NOTE: `frontend` is sufficent in most case (it is often too much) +# NOTE: `frontend` is sufficent in most cases (it is often too much) import nitsmell_toolcontext import mclassdef_collect diff --git a/src/metrics/static_types_metrics.nit b/src/metrics/static_types_metrics.nit index 45c429b..4dd38d0 100644 --- a/src/metrics/static_types_metrics.nit +++ b/src/metrics/static_types_metrics.nit @@ -41,14 +41,6 @@ private class ATypeCounterVisitor var typecount: Counter[MType] - # Get a new visitor on a classef to add type count in `typecount`. - init(modelbuilder: ModelBuilder, nclassdef: AClassdef, typecount: Counter[MType]) - do - self.modelbuilder = modelbuilder - self.nclassdef = nclassdef - self.typecount = typecount - end - redef fun visit(n) do if n isa AAnnotation then return diff --git a/src/model/model.nit b/src/model/model.nit index e3fa3fd..e22ae84 100644 --- a/src/model/model.nit +++ b/src/model/model.nit @@ -778,9 +778,44 @@ class MClassDef # All property introductions and redefinitions in `self` (not inheritance). var mpropdefs = new Array[MPropDef] + # The special default_init constructor + var default_init: nullable MMethodDef = null is writable + # All property introductions and redefinitions (not inheritance) in `self` by its associated property. var mpropdefs_by_property = new HashMap[MProperty, MPropDef] + # Return the direct parent mtype of `self` + # Exemple + # ~~~nitish + # module 1 + # + # class A + # class B + # super A + # + # module 2 + # + # redef class A + # class C + # super B + # + # mclassdef_C.get_direct_supermtype == [B] + # ~~~~ + fun get_direct_supermtype: Collection[MClassType] + do + # Get the potentiel direct parents + var parents = in_hierarchy.direct_greaters + # Stock the potentiel direct parents + var res = supertypes + for parent in parents do + # remove all super parents of the potentiel direct parents + res.remove_all(parent.supertypes) + # if the length of the potentiel direct parent equal 1 break + if res.length == 1 then break + end + return res + end + redef fun mdoc_or_fallback do return mdoc or else mclass.mdoc_or_fallback end @@ -2622,19 +2657,21 @@ class MMethodDef # The signature attached to the property definition var msignature: nullable MSignature = null is writable - # The signature attached to the `new` call on a root-init - # This is a concatenation of the signatures of the initializers - # - # REQUIRE `mproperty.is_root_init == (new_msignature != null)` - var new_msignature: nullable MSignature = null is writable - # List of initialisers to call in root-inits # # They could be setters or attributes - # - # REQUIRE `mproperty.is_root_init == (new_msignature != null)` var initializers = new Array[MProperty] + # Does the method take the responsibility to call `init`? + # + # If the method is used as an initializer, then + # using this information prevents to call `init` twice. + var is_calling_init = false is writable + + # Does the method is a old_style_init? + # + var is_old_style_init = false is writable + # Is the method definition abstract? var is_abstract: Bool = false is writable diff --git a/src/model/model_contract.nit b/src/model/model_contract.nit new file mode 100644 index 0000000..2e13a45 --- /dev/null +++ b/src/model/model_contract.nit @@ -0,0 +1,120 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# The abstract concept of a contract in the model +module model_contract + +import model +import scope + +# The root of all contracts +abstract class MContract + super MMethod + + # Is the contract is it already applied on the given `mfacet` + fun is_already_applied(mfacet: MFacet): Bool is abstract +end + +# An expect (precondition) contract representation +class MExpect + super MContract + + redef fun is_already_applied(mfacet: MFacet): Bool do return mfacet.has_applied_expect +end + +# The root of all contracts where the call is after the execution of the original method (`invariant` and `ensure`). +abstract class BottomMContract + super MContract +end + +# A ensure (postcondition) representation +class MEnsure + super BottomMContract + + redef fun is_already_applied(mfacet: MFacet): Bool do return mfacet.has_applied_ensure +end + +# A facet contract representation +# This class is created to keep the information of which method is a contract facet +class MFacet + super MMethod + + # Is there an `expect` contract applied? + var has_applied_expect: Bool = false + + # Is there an `ensure` contract applied? + var has_applied_ensure: Bool = false +end + +redef class MMethod + + # The contract facet of the method + # is representing the method with a contract + # This method calls contracts (expect, ensure) and the method + var mcontract_facet: nullable MFacet = null + + # The `MExpect` contract if any + var mexpect: nullable MExpect = null + + # The `MEnsure` contract if any + var mensure: nullable MEnsure = null + + # Build `mensure` if is not exist and return it + private fun build_ensure: MEnsure + do + var m_mensure = self.mensure + # build a new `MEnsure` contract + if m_mensure == null then m_mensure = new MEnsure(intro_mclassdef, "_ensure_{name}", intro_mclassdef.location, public_visibility) + self.mensure = m_mensure + return m_mensure + end + + # Is there an ensure contract? + fun has_ensure: Bool + do + return self.mensure != null + end + + # Build `mexpect` if is not exist and return it + private fun build_expect: MExpect + do + var m_mexpect = self.mexpect + # build a new `MExpect` contract + if m_mexpect == null then m_mexpect = new MExpect(intro_mclassdef, "_expect_{name}", intro_mclassdef.location, public_visibility) + self.mexpect = m_mexpect + return m_mexpect + end + + # Is there an expect contract? + fun has_expect: Bool + do + return self.mexpect != null + end + + # Build `mcontract_facet` if is not exist and return it + private fun build_contract_facet: MFacet + do + var m_mcontract_facet = self.mcontract_facet + # build a new `MFacet` contract + if m_mcontract_facet == null then m_mcontract_facet = new MFacet(intro_mclassdef, "_contract_{name}", intro_mclassdef.location, public_visibility) + self.mcontract_facet = m_mcontract_facet + return m_mcontract_facet + end + + # Is there an contract facet? + fun has_contract_facet: Bool + do + return self.mcontract_facet != null + end +end diff --git a/src/modelbuilder_base.nit b/src/modelbuilder_base.nit index 0db4b4b..0d75563 100644 --- a/src/modelbuilder_base.nit +++ b/src/modelbuilder_base.nit @@ -60,7 +60,7 @@ class ModelBuilder # If no such a class exists, then null is returned. # If more than one class exists, then an error on `anode` is displayed and null is returned. # FIXME: add a way to handle class name conflict - fun try_get_mclass_by_name(anode: ANode, mmodule: MModule, name: String): nullable MClass + fun try_get_mclass_by_name(anode: nullable ANode, mmodule: MModule, name: String): nullable MClass do var classes = model.get_mclasses_by_name(name) if classes == null then @@ -112,7 +112,7 @@ class ModelBuilder end # Like `try_get_mclass_by_name` but display an error message when the class is not found - fun get_mclass_by_name(node: ANode, mmodule: MModule, name: String): nullable MClass + fun get_mclass_by_name(node: nullable ANode, mmodule: MModule, name: String): nullable MClass do var mclass = try_get_mclass_by_name(node, mmodule, name) if mclass == null then @@ -127,7 +127,7 @@ class ModelBuilder # If no such a property exists, then null is returned. # If more than one property exists, then an error on `anode` is displayed and null is returned. # FIXME: add a way to handle property name conflict - fun try_get_mproperty_by_name2(anode: ANode, mmodule: MModule, mtype: MType, name: String): nullable MProperty + fun try_get_mproperty_by_name2(anode: nullable ANode, mmodule: MModule, mtype: MType, name: String): nullable MProperty do var props = self.model.get_mproperties_by_name(name) if props == null then @@ -209,7 +209,7 @@ class ModelBuilder # Alias for try_get_mproperty_by_name2(anode, mclassdef.mmodule, mclassdef.mtype, name) - fun try_get_mproperty_by_name(anode: ANode, mclassdef: MClassDef, name: String): nullable MProperty + fun try_get_mproperty_by_name(anode: nullable ANode, mclassdef: MClassDef, name: String): nullable MProperty do return try_get_mproperty_by_name2(anode, mclassdef.mmodule, mclassdef.bound_mtype, name) end diff --git a/src/modelize/modelize_property.nit b/src/modelize/modelize_property.nit index 35e210e..6f7f209 100644 --- a/src/modelize/modelize_property.nit +++ b/src/modelize/modelize_property.nit @@ -53,6 +53,17 @@ redef class ModelBuilder mpropdef2npropdef[mpropdef] = npropdef end + # Associate a `nclassdef` with its `mclassdef` + # + # Be careful, this method is unsafe, no checking is done when it's used. + # The safe way to add mclass it's to use the `build_property` + # + # See `mclassdef2nclassdef` + fun unsafe_add_mclassdef2nclassdef(mclassdef: MClassDef, nclassdef: AClassdef) + do + mclassdef2nclassdef[mclassdef] = nclassdef + end + # Retrieve the associated AST node of a mpropertydef. # This method is used to associate model entity with syntactic entities. # @@ -66,10 +77,9 @@ redef class ModelBuilder toolcontext.run_phases_on_npropdef(res) return res end - if mpropdef isa MMethodDef and mpropdef.mproperty.is_root_init then - res = mclassdef2nclassdef.get_or_null(mpropdef.mclassdef) - if res != null then return res - end + # Fall back to the class node if any. + res = mclassdef2nclassdef.get_or_null(mpropdef.mclassdef) + if res != null then return res return null end @@ -150,7 +160,11 @@ redef class ModelBuilder var mclassdef = nclassdef.mclassdef.as(not null) # Are we a refinement - if not mclassdef.is_intro then return + if not mclassdef.is_intro then + # Set the default_init of the mclassdef with the intro default_init + mclassdef.default_init = mclassdef.mclass.intro.default_init + return + end # Look for the init in Object, or create it if mclassdef.mclass.name == "Object" and the_root_init_mmethod == null then @@ -161,11 +175,9 @@ redef class ModelBuilder var mparameters = new Array[MParameter] var msignature = new MSignature(mparameters, null) mpropdef.msignature = msignature - mpropdef.new_msignature = msignature mprop.is_init = true self.toolcontext.info("{mclassdef} gets a free empty constructor {mpropdef}{msignature}", 3) the_root_init_mmethod = mprop - return end # Is there already a constructor defined? @@ -176,13 +188,15 @@ redef class ModelBuilder if mpropdef.mproperty.is_root_init then assert defined_init == null defined_init = mpropdef - else if mpropdef.mproperty.name == "init" then - # An explicit old-style init named "init", so return + else if mpropdef.name == "defaultinit" then return end end - if not nclassdef isa AStdClassdef then return + if mclassdef.default_init != null then return + + # If the class is not AStdClassdef or it's an enum just return. No defaultinit is need. + if not nclassdef isa AStdClassdef or nclassdef.n_classkind isa AEnumClasskind then return # Collect undefined attributes var mparameters = new Array[MParameter] @@ -194,7 +208,6 @@ redef class ModelBuilder if mpropdef == null then return # Skip broken method var sig = mpropdef.msignature if sig == null then continue # Skip broken method - mparameters.add_all sig.mparameters initializers.add(mpropdef.mproperty) mpropdef.mproperty.is_autoinit = true @@ -238,10 +251,13 @@ redef class ModelBuilder if the_root_init_mmethod == null then return # Look for most-specific new-stype init definitions - var spropdefs = the_root_init_mmethod.lookup_super_definitions(mclassdef.mmodule, mclassdef.bound_mtype) - if spropdefs.is_empty then - toolcontext.error(nclassdef.location, "Error: `{mclassdef}` does not specialize `{the_root_init_mmethod.intro_mclassdef}`. Possible duplication of the root class `Object`?") - return + var spropdefs = new ArraySet[MMethodDef] + + for x in mclassdef.get_direct_supermtype do + var y = x.mclass.intro.default_init + if y == null then continue + if y.is_broken or y.msignature == null then return + spropdefs.add y end # Look at the autoinit class-annotation @@ -295,13 +311,29 @@ redef class ModelBuilder abort end end - else + else if spropdefs.not_empty then + # Search for inherited manual defaultinit + var manual = null + for s in spropdefs do + if mpropdef2npropdef.has_key(s) then + self.toolcontext.info("{mclassdef} inherits a manual defaultinit {s}", 3) + manual = s + end + end # Search the longest-one and checks for conflict var longest = spropdefs.first if spropdefs.length > 1 then # part 1. find the longest list for spd in spropdefs do if spd.initializers.length > longest.initializers.length then longest = spd + + if spd != manual and manual != null then + self.toolcontext.info("{mclassdef} conflict between manual defaultinit {manual} and automatic defaultinit {spd}.", 3) + end + end + # conflict with manual autoinit? + if longest != manual and manual != null then + self.error(nclassdef, "Error: conflict between manual defaultinit {manual} and automatic defaultinit {longest}.") end # part 2. compare # Check for conflict in the order of initializers @@ -334,41 +366,26 @@ redef class ModelBuilder mparameters.clear initializers.clear else - # Can we just inherit? - if spropdefs.length == 1 and mparameters.is_empty and defined_init == null then - self.toolcontext.info("{mclassdef} inherits the basic constructor {longest}", 3) - mclassdef.mclass.root_init = longest - return - end - # Combine the inherited list to what is collected if longest.initializers.length > 0 then - mparameters.prepend longest.new_msignature.mparameters + mparameters.prepend longest.msignature.mparameters initializers.prepend longest.initializers end end end - # If we already have a basic init definition, then setup its initializers - if defined_init != null then - defined_init.initializers.add_all(initializers) + # Create a specific new autoinit constructor + do + var mprop = new MMethod(mclassdef, "defaultinit", nclassdef.location, public_visibility) + mprop.is_init = true + var mpropdef = new MMethodDef(mclassdef, mprop, nclassdef.location) + mpropdef.initializers.add_all(initializers) var msignature = new MSignature(mparameters, null) - defined_init.new_msignature = msignature - self.toolcontext.info("{mclassdef} extends its basic constructor signature to {defined_init}{msignature}", 3) - mclassdef.mclass.root_init = defined_init - return + mpropdef.msignature = msignature + mclassdef.default_init = mpropdef + self.toolcontext.info("{mclassdef} gets a free auto constructor `{mpropdef}{msignature}`. {spropdefs}", 3) + mclassdef.mclass.the_root_init_mmethod = the_root_init_mmethod end - - # Else create the local implicit basic init definition - var mprop = the_root_init_mmethod - var mpropdef = new MMethodDef(mclassdef, mprop, nclassdef.location) - mpropdef.has_supercall = true - mpropdef.initializers.add_all(initializers) - var msignature = new MSignature(mparameters, null) - mpropdef.new_msignature = msignature - mpropdef.msignature = new MSignature(new Array[MParameter], null) # always an empty real signature - self.toolcontext.info("{mclassdef} gets a free constructor for attributes {mpropdef}{msignature}", 3) - mclassdef.mclass.root_init = mpropdef end # Check the visibility of `mtype` as an element of the signature of `mpropdef`. @@ -504,11 +521,9 @@ end redef class MClass # The base init of the class. - # Used to get the common new_msignature and initializers # - # TODO: Where to put this information is not clear because unlike other - # informations, the initialisers are stable in a same class. - var root_init: nullable MMethodDef = null + # TODO: merge with `root_init` and `ModelBuilder::the_root_init_mmethod` if possible + var the_root_init_mmethod: nullable MMethod = null end redef class MClassDef @@ -785,10 +800,16 @@ redef class AMethPropdef var name: String var amethodid = self.n_methid var name_node: ANode + var is_old_style_init = false if amethodid == null then if n_kwinit != null then name = "init" name_node = n_kwinit + var old_style_annot = get_single_annotation("old_style_init", modelbuilder) + if old_style_annot != null or self.n_signature.n_params.not_empty then + name = "defaultinit" + if old_style_annot != null then is_old_style_init = true + end else if n_kwnew != null then name = "new" name_node = n_kwnew @@ -822,7 +843,7 @@ redef class AMethPropdef var look_like_a_root_init = look_like_a_root_init(modelbuilder, mclassdef) var mprop: nullable MMethod = null - if not is_init or n_kwredef != null then mprop = modelbuilder.try_get_mproperty_by_name(name_node, mclassdef, name).as(nullable MMethod) + if not is_init or n_kwredef != null or look_like_a_root_init then mprop = modelbuilder.try_get_mproperty_by_name(name_node, mclassdef, name).as(nullable MMethod) if mprop == null and look_like_a_root_init then mprop = modelbuilder.the_root_init_mmethod var nb = n_block @@ -867,6 +888,15 @@ redef class AMethPropdef mclassdef.mprop2npropdef[mprop] = self var mpropdef = new MMethodDef(mclassdef, mprop, self.location) + if mpropdef.name == "defaultinit" and mclassdef.is_intro then + assert mclassdef.default_init == null + mpropdef.is_old_style_init = is_old_style_init + mclassdef.default_init = mpropdef + # Set the initializers with the mproperty. + # This point is need when a super class define this own default_init and inherited class use the default_init generated automaticlely. + mpropdef.initializers.add mprop + mpropdef.is_calling_init = true + end set_doc(mpropdef, modelbuilder) @@ -888,16 +918,6 @@ redef class AMethPropdef var mmodule = mclassdef.mmodule var nsig = self.n_signature - if mproperty.is_root_init and not mclassdef.is_intro then - var root_init = mclassdef.mclass.root_init - if root_init != null then - # Inherit the initializers by refinement - mpropdef.new_msignature = root_init.new_msignature - assert mpropdef.initializers.is_empty - mpropdef.initializers.add_all root_init.initializers - end - end - var accept_special_last_parameter = self.n_methid == null or self.n_methid.accept_special_last_parameter var return_is_mandatory = self.n_methid != null and self.n_methid.return_is_mandatory @@ -1172,6 +1192,10 @@ redef class AAttrPropdef # Could be through `n_expr`, `n_block` or `is_lazy` var has_value = false + # The name of the attribute + # Note: The name of the attribute is in reality the name of the mreadpropdef + var name: String = n_id2.text is lazy + # The guard associated to a lazy attribute. # Because some engines does not have a working `isset`, # this additional attribute is used to guard the lazy initialization. @@ -1186,48 +1210,14 @@ redef class AAttrPropdef redef fun build_property(modelbuilder, mclassdef) do var mclass = mclassdef.mclass - var nid2 = n_id2 - var name = nid2.text var atabstract = self.get_single_annotation("abstract", modelbuilder) - if atabstract == null then - if not mclass.kind.need_init then - modelbuilder.error(self, "Error: attempt to define attribute `{name}` in the {mclass.kind} `{mclass}`.") - end - var mprop = new MAttribute(mclassdef, "_" + name, self.location, private_visibility) - var mpropdef = new MAttributeDef(mclassdef, mprop, self.location) - self.mpropdef = mpropdef - modelbuilder.mpropdef2npropdef[mpropdef] = self - end - - var readname = name - var mreadprop = modelbuilder.try_get_mproperty_by_name(nid2, mclassdef, readname).as(nullable MMethod) - if mreadprop == null then - var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility) - mreadprop = new MMethod(mclassdef, readname, self.location, mvisibility) - if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mreadprop) then - mreadprop.is_broken = true - return - end - else - if mreadprop.is_broken then return - if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, true, mreadprop) then return - check_redef_property_visibility(modelbuilder, self.n_visibility, mreadprop) - end - mclassdef.mprop2npropdef[mreadprop] = self + if atabstract == null then build_attribute_property(modelbuilder, mclassdef) - var attr_mpropdef = mpropdef - if attr_mpropdef != null then - mreadprop.getter_for = attr_mpropdef.mproperty - attr_mpropdef.mproperty.getter = mreadprop - end + # Construction of the read property. If it's not correctly built just return. + if not build_read_property(modelbuilder, mclassdef) then return - var mreadpropdef = new MMethodDef(mclassdef, mreadprop, self.location) - self.mreadpropdef = mreadpropdef - modelbuilder.mpropdef2npropdef[mreadpropdef] = self - set_doc(mreadpropdef, modelbuilder) - if mpropdef != null then mpropdef.mdoc = mreadpropdef.mdoc if atabstract != null then mreadpropdef.is_abstract = true has_value = n_expr != null or n_block != null @@ -1250,29 +1240,8 @@ redef class AAttrPropdef end end - var atlazy = self.get_single_annotation("lazy", modelbuilder) - var atlateinit = self.get_single_annotation("lateinit", modelbuilder) - if atlazy != null or atlateinit != null then - if atlazy != null and atlateinit != null then - modelbuilder.error(atlazy, "Error: `lazy` incompatible with `lateinit`.") - return - end - if not has_value then - if atlazy != null then - modelbuilder.error(atlazy, "Error: `lazy` attributes need a value.") - else if atlateinit != null then - modelbuilder.error(atlateinit, "Error: `lateinit` attributes need a value.") - end - has_value = true - return - end - is_lazy = true - var mlazyprop = new MAttribute(mclassdef, "lazy _" + name, self.location, none_visibility) - mlazyprop.is_fictive = true - var mlazypropdef = new MAttributeDef(mclassdef, mlazyprop, self.location) - mlazypropdef.is_fictive = true - self.mlazypropdef = mlazypropdef - end + # Construction of the read property. If it's not correctly built just return. + if not build_lazy_property(modelbuilder, mclassdef) then return var atoptional = self.get_single_annotation("optional", modelbuilder) if atoptional != null then @@ -1295,6 +1264,88 @@ redef class AAttrPropdef modelbuilder.advice(self, "attr-in-refinement", "Warning: attributes in refinement need a value or `noautoinit`.") end + # Construction of the read property. If it's not correctly built just return. + if not build_write_property(modelbuilder, mclassdef, false) then return + + if atabstract != null then mwritepropdef.is_abstract = true + + var atautoinit = self.get_single_annotation("autoinit", modelbuilder) + if atautoinit != null then + if has_value then + modelbuilder.error(atautoinit, "Error: `autoinit` attributes cannot have an initial value.") + else if not mwritepropdef.is_intro then + modelbuilder.error(atautoinit, "Error: `autoinit` attributes cannot be set on redefinitions.") + else if not mclassdef.is_intro then + modelbuilder.error(atautoinit, "Error: `autoinit` attributes cannot be used in class refinements.") + else if atabstract == null then + modelbuilder.warning(atautoinit, "useless-autoinit", "Warning: superfluous `autoinit` on attribute.") + end + else if atabstract != null then + # By default, abstract attribute are not autoinit + noinit = true + end + end + + # Build the attribute property + fun build_attribute_property(modelbuilder: ModelBuilder, mclassdef: MClassDef) + do + var mclass = mclassdef.mclass + var attribute_name = "_" + name + + if not mclass.kind.need_init then + modelbuilder.error(self, "Error: attempt to define attribute `{name}` in the {mclass.kind} `{mclass}`.") + end + var mprop = new MAttribute(mclassdef, "_" + name, self.location, private_visibility) + var mpropdef = new MAttributeDef(mclassdef, mprop, self.location) + self.mpropdef = mpropdef + modelbuilder.mpropdef2npropdef[mpropdef] = self + end + + # Build the read method property to get the value of the attribute + # Return `true` if the property was correctly created else return `false`. + # Warning the signature of the property is not set. This step is done by `build_signature`. + fun build_read_property(modelbuilder: ModelBuilder, mclassdef: MClassDef): Bool + do + var mclass = mclassdef.mclass + + var readname = name + var mreadprop = modelbuilder.try_get_mproperty_by_name(self, mclassdef, readname).as(nullable MMethod) + if mreadprop == null then + var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility) + mreadprop = new MMethod(mclassdef, readname, self.location, mvisibility) + if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mreadprop) then + mreadprop.is_broken = true + return false + end + else + if mreadprop.is_broken then return false + if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, true, mreadprop) then return false + check_redef_property_visibility(modelbuilder, self.n_visibility, mreadprop) + end + mclassdef.mprop2npropdef[mreadprop] = self + + var attr_mpropdef = mpropdef + if attr_mpropdef != null then + mreadprop.getter_for = attr_mpropdef.mproperty + attr_mpropdef.mproperty.getter = mreadprop + end + + var mreadpropdef = new MMethodDef(mclassdef, mreadprop, self.location) + self.mreadpropdef = mreadpropdef + modelbuilder.mpropdef2npropdef[mreadpropdef] = self + set_doc(mreadpropdef, modelbuilder) + if mpropdef != null then mpropdef.mdoc = mreadpropdef.mdoc + + return true + end + + # Build the write method property to set the attribute value + # Return `true` if the property was correctly created else return `false`. + # Warning the signature of the property is not set. + fun build_write_property(modelbuilder: ModelBuilder, mclassdef: MClassDef, is_same_visibility: Bool): Bool + do + var mclass = mclassdef.mclass + var writename = name + "=" var atwritable = self.get_single_annotation("writable", modelbuilder) if atwritable != null then @@ -1302,7 +1353,7 @@ redef class AAttrPropdef writename = atwritable.arg_as_id(modelbuilder) or else writename end end - var mwriteprop = modelbuilder.try_get_mproperty_by_name(nid2, mclassdef, writename).as(nullable MMethod) + var mwriteprop = modelbuilder.try_get_mproperty_by_name(self, mclassdef, writename).as(nullable MMethod) var nwkwredef: nullable Token = null if atwritable != null then nwkwredef = atwritable.n_kwredef if mwriteprop == null then @@ -1310,25 +1361,26 @@ redef class AAttrPropdef if atwritable != null then mvisibility = new_property_visibility(modelbuilder, mclassdef, atwritable.n_visibility) else - mvisibility = mreadprop.visibility + mvisibility = mreadpropdef.mproperty.visibility # By default, use protected visibility at most - if mvisibility > protected_visibility then mvisibility = protected_visibility + if mvisibility > protected_visibility and not is_same_visibility then mvisibility = protected_visibility end mwriteprop = new MMethod(mclassdef, writename, self.location, mvisibility) if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef, false, mwriteprop) then mwriteprop.is_broken = true - return + return false end - mwriteprop.deprecation = mreadprop.deprecation + mwriteprop.deprecation = mreadpropdef.mproperty.deprecation else - if mwriteprop.is_broken then return - if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef or else n_kwredef, true, mwriteprop) then return + if mwriteprop.is_broken then return false + if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef or else n_kwredef, true, mwriteprop) then return false if atwritable != null then check_redef_property_visibility(modelbuilder, atwritable.n_visibility, mwriteprop) end end mclassdef.mprop2npropdef[mwriteprop] = self + var attr_mpropdef = mpropdef if attr_mpropdef != null then mwriteprop.setter_for = attr_mpropdef.mproperty attr_mpropdef.mproperty.setter = mwriteprop @@ -1338,23 +1390,35 @@ redef class AAttrPropdef self.mwritepropdef = mwritepropdef modelbuilder.mpropdef2npropdef[mwritepropdef] = self mwritepropdef.mdoc = mreadpropdef.mdoc - if atabstract != null then mwritepropdef.is_abstract = true - var atautoinit = self.get_single_annotation("autoinit", modelbuilder) - if atautoinit != null then - if has_value then - modelbuilder.error(atautoinit, "Error: `autoinit` attributes cannot have an initial value.") - else if not mwritepropdef.is_intro then - modelbuilder.error(atautoinit, "Error: `autoinit` attributes cannot be set on redefinitions.") - else if not mclassdef.is_intro then - modelbuilder.error(atautoinit, "Error: `autoinit` attributes cannot be used in class refinements.") - else if atabstract == null then - modelbuilder.warning(atautoinit, "useless-autoinit", "Warning: superfluous `autoinit` on attribute.") + return true + end + + # Build the lazy attribute property + # Return `true` if the property was correctly created else return `false`. + fun build_lazy_property(modelbuilder: ModelBuilder, mclassdef: MClassDef): Bool + do + var mclass = mclassdef.mclass + + var atlazy = self.get_single_annotation("lazy", modelbuilder) + var atlateinit = self.get_single_annotation("lateinit", modelbuilder) + if atlazy != null or atlateinit != null then + if atlazy != null and atlateinit != null then + modelbuilder.error(atlazy, "Error: `lazy` incompatible with `lateinit`.") + return false end - else if atabstract != null then - # By default, abstract attribute are not autoinit - noinit = true + if not has_value then + if atlazy != null then + modelbuilder.error(atlazy, "Error: `lazy` attributes need a value.") + else if atlateinit != null then + modelbuilder.error(atlateinit, "Error: `lateinit` attributes need a value.") + end + has_value = true + return false + end + create_lazy end + return true end redef fun build_signature(modelbuilder) @@ -1412,23 +1476,9 @@ redef class AAttrPropdef mpropdef.static_mtype = mtype end - do - var msignature = new MSignature(new Array[MParameter], mtype) - mreadpropdef.msignature = msignature - end + build_read_signature - var mwritepropdef = self.mwritepropdef - if mwritepropdef != null then - var mwritetype = mtype - if is_optional then - mwritetype = mwritetype.as_nullable - end - var name: String - name = n_id2.text - var mparameter = new MParameter(name, mwritetype, false) - var msignature = new MSignature([mparameter], null) - mwritepropdef.msignature = msignature - end + if self.mwritepropdef != null then build_write_signature var mlazypropdef = self.mlazypropdef if mlazypropdef != null then @@ -1437,6 +1487,91 @@ redef class AAttrPropdef check_repeated_types(modelbuilder) end + # Build the read method signature + # `except`: mreadpropdef != null + # `expect`: mtype != null + fun build_read_signature + is + expect(mreadpropdef != null and mtype != null) + do + var msignature = new MSignature(new Array[MParameter], mtype) + mreadpropdef.msignature = msignature + end + + # Build the write method signature + # `except`: mwritepropdef != null + # `expect`: mtype != null + fun build_write_signature + is + expect(mwritepropdef != null and mtype != null) + do + var mwritetype = mtype.as(not null) + if is_optional then + mwritetype = mwritetype.as_nullable + end + var mparameter = new MParameter(name, mwritetype, false) + var msignature = new MSignature([mparameter], null) + mwritepropdef.msignature = msignature + end + + # Create a new setter for the attribute. + # + # `modelbuilder`: It's used to link the new `mwritepropdef` and `self` + # `visibility`: Is the setter has the same visibilty of the `mreadpropdef`. + # If `not is_same_visibility and mreadpropdef.mproperty.visibility > protected_visibility` the `mwritepropdef` visibility will be set to protected. + fun create_setter(modelbuilder: ModelBuilder, is_same_visibility: nullable Bool): AAttrPropdef + is + expect(mreadpropdef != null) # Use to define the visibility, the mclassdef and the doc of the `mwritepropdef` + do + if mwritepropdef != null then return self # Self already has a `mwritepropdef` + var same_visibility = false + if is_same_visibility != null then same_visibility = is_same_visibility + + self.build_write_property(modelbuilder, mreadpropdef.mclassdef, same_visibility) + self.build_write_signature + return self + end + + # Set the default `self` value + # + # `expr`: Represents the default value of the attribute. If `expr isa ABlockExpr` `self.n_block` will be set. + fun define_default(expr: AExpr): AAttrPropdef + do + self.has_value = true + if expr isa ABlockExpr then + self.n_block = expr + else + self.n_expr = expr + end + return self + end + + # Set `self` as optional + fun define_as_optional: AAttrPropdef + is + expect(has_value) + do + is_optional = true + return self + end + + # Create the lazy attribute. + # + # see `mlazypropdef` for more information about this property. + fun create_lazy: AAttrPropdef + is + expect(has_value and mpropdef != null) # The only way to get a null `mpropdef` is when the attribute is defined as `abstract`. But if the attribute has a value, it cannot be abstract. + do + if self.mlazypropdef != null then return self # Self already has a `mlazypropdef` + is_lazy = true + var mlazyprop = new MAttribute(mpropdef.mclassdef, "lazy _" + name, self.location, none_visibility) + mlazyprop.is_fictive = true + var mlazypropdef = new MAttributeDef(mpropdef.mclassdef, mlazyprop, self.location) + mlazypropdef.is_fictive = true + self.mlazypropdef = mlazypropdef + return self + end + # Detect the static type from the value assigned to the attribute `self` # # Return the static type if it can be safely inferred. diff --git a/src/neo.nit b/src/neo.nit index 3af570a..be92ab6 100644 --- a/src/neo.nit +++ b/src/neo.nit @@ -305,8 +305,8 @@ class NeoModel # Collect all nodes from the current `model`. private fun collect_model_nodes(model: Model): Collection[NeoNode] do for mpackage in model.mpackages do - to_node(mpackage) - for mgroup in mpackage.mgroups do to_node(mgroup) + mpackage.to_node(nodes, model_name) + for mgroup in mpackage.mgroups do mgroup.to_node(nodes, model_name) end return nodes.values end @@ -328,22 +328,6 @@ class NeoModel # Nodes associated with MEntities. private var nodes = new HashMap[MEntity, NeoNode] - # Get the `NeoNode` associated with `mentity`. - # `mentities` are stored locally to avoid duplication. - fun to_node(mentity: MEntity): NeoNode do - if nodes.has_key(mentity) then return nodes[mentity] - if mentity isa MPackage then return mpackage_node(mentity) - if mentity isa MGroup then return mgroup_node(mentity) - if mentity isa MModule then return mmodule_node(mentity) - if mentity isa MClass then return mclass_node(mentity) - if mentity isa MClassDef then return mclassdef_node(mentity) - if mentity isa MProperty then return mproperty_node(mentity) - if mentity isa MPropDef then return mpropdef_node(mentity) - if mentity isa MType then return mtype_node(mentity) - if mentity isa MParameter then return mparameter_node(mentity) - abort - end - # Get the `MEntity` associated with `node`. fun to_mentity(model: Model, node: NeoNode): MEntity do if node.labels.has("MPackage") then return to_mpackage(model, node) @@ -358,36 +342,6 @@ class NeoModel abort end - # Make a new `NeoNode` based on `mentity`. - private fun make_node(mentity: MEntity): NeoNode do - var node = new NeoNode - nodes[mentity] = node - node.labels.add "MEntity" - node.labels.add model_name - node["name"] = mentity.name - if not mentity isa MSignature then - #FIXME: MSignature is a MEntity, but has no model :/ - node["location"] = mentity.location.to_s - end - var mdoc = mentity.mdoc - if mdoc != null then - node["mdoc"] = new JsonArray.from(mdoc.content) - node["mdoc_location"] = mdoc.location.to_s - end - return node - end - - # Build a `NeoNode` representing `mpackage`. - private fun mpackage_node(mpackage: MPackage): NeoNode do - var node = make_node(mpackage) - node.labels.add "MPackage" - var root = mpackage.root - if root != null then - node.out_edges.add(new NeoEdge(node, "ROOT", to_node(root))) - end - return node - end - # Build a new `MPackage` from a `node`. # # REQUIRE `node.labels.has("MPackage")` @@ -404,24 +358,6 @@ class NeoModel return mpackage end - # Build a `NeoNode` representing `mgroup`. - private fun mgroup_node(mgroup: MGroup): NeoNode do - var node = make_node(mgroup) - node.labels.add "MGroup" - var parent = mgroup.parent - node.out_edges.add(new NeoEdge(node, "PROJECT", to_node(mgroup.mpackage))) - if parent != null then - node.out_edges.add(new NeoEdge(node, "PARENT", to_node(parent))) - end - for mmodule in mgroup.mmodules do - node.out_edges.add(new NeoEdge(node, "DECLARES", to_node(mmodule))) - end - for subgroup in mgroup.in_nesting.direct_smallers do - node.in_edges.add(new NeoEdge(node, "NESTS", to_node(subgroup))) - end - return node - end - # Build a new `MGroup` from a `node`. # # REQUIRE `node.labels.has("MGroup")` @@ -443,22 +379,6 @@ class NeoModel return mgroup end - # Build a `NeoNode` representing `mmodule`. - private fun mmodule_node(mmodule: MModule): NeoNode do - var node = make_node(mmodule) - node.labels.add "MModule" - for parent in mmodule.in_importation.direct_greaters do - node.out_edges.add(new NeoEdge(node, "IMPORTS", to_node(parent))) - end - for mclass in mmodule.intro_mclasses do - node.out_edges.add(new NeoEdge(node, "INTRODUCES", to_node(mclass))) - end - for mclassdef in mmodule.mclassdefs do - node.out_edges.add(new NeoEdge(node, "DEFINES", to_node(mclassdef))) - end - return node - end - # Build a new `MModule` from a `node`. # # REQUIRE `node.labels.has("MModule")` @@ -485,21 +405,6 @@ class NeoModel return mmodule end - # Build a `NeoNode` representing `mclass`. - private fun mclass_node(mclass: MClass): NeoNode do - var node = make_node(mclass) - node.labels.add "MClass" - node["kind"] = mclass.kind.to_s - node["visibility"] = mclass.visibility.to_s - if not mclass.mparameters.is_empty then - var parameter_names = new Array[String] - for p in mclass.mparameters do parameter_names.add(p.name) - node["parameter_names"] = new JsonArray.from(parameter_names) - end - node.out_edges.add(new NeoEdge(node, "CLASSTYPE", to_node(mclass.mclass_type))) - return node - end - # Build a new `MClass` from a `node`. # # REQUIRE `node.labels.has("MClass")` @@ -525,24 +430,6 @@ class NeoModel return mclass end - # Build a `NeoNode` representing `mclassdef`. - private fun mclassdef_node(mclassdef: MClassDef): NeoNode do - var node = make_node(mclassdef) - node.labels.add "MClassDef" - node.out_edges.add(new NeoEdge(node, "BOUNDTYPE", to_node(mclassdef.bound_mtype))) - node.out_edges.add(new NeoEdge(node, "MCLASS", to_node(mclassdef.mclass))) - for mproperty in mclassdef.intro_mproperties do - node.out_edges.add(new NeoEdge(node, "INTRODUCES", to_node(mproperty))) - end - for mpropdef in mclassdef.mpropdefs do - node.out_edges.add(new NeoEdge(node, "DECLARES", to_node(mpropdef))) - end - for sup in mclassdef.supertypes do - node.out_edges.add(new NeoEdge(node, "INHERITS", to_node(sup))) - end - return node - end - # Build a new `MClassDef` from a `node`. # # REQUIRE `node.labels.has("MClassDef")` @@ -566,26 +453,6 @@ class NeoModel return mclassdef end - # Build a `NeoNode` representing `mproperty`. - private fun mproperty_node(mproperty: MProperty): NeoNode do - var node = make_node(mproperty) - node.labels.add "MProperty" - node["visibility"] = mproperty.visibility.to_s - if mproperty isa MMethod then - node.labels.add "MMethod" - node["is_init"] = mproperty.is_init - else if mproperty isa MAttribute then - node.labels.add "MAttribute" - else if mproperty isa MVirtualTypeProp then - node.labels.add "MVirtualTypeProp" - else if mproperty isa MInnerClass then - node.labels.add "MInnerClass" - node.out_edges.add(new NeoEdge(node, "NESTS", to_node(mproperty.inner))) - end - node.out_edges.add(new NeoEdge(node, "INTRO_CLASSDEF", to_node(mproperty.intro_mclassdef))) - return node - end - # Build a new `MProperty` from a `node`. # # REQUIRE `node.labels.has("MProperty")` @@ -619,39 +486,6 @@ class NeoModel return mprop end - # Build a `NeoNode` representing `mpropdef`. - private fun mpropdef_node(mpropdef: MPropDef): NeoNode do - var node = make_node(mpropdef) - node.labels.add "MPropDef" - node.out_edges.add(new NeoEdge(node, "DEFINES", to_node(mpropdef.mproperty))) - if mpropdef isa MMethodDef then - node.labels.add "MMethodDef" - node["is_abstract"] = mpropdef.is_abstract - node["is_intern"] = mpropdef.is_intern - node["is_extern"] = mpropdef.is_extern - var msignature = mpropdef.msignature - if msignature != null then - node.out_edges.add(new NeoEdge(node, "SIGNATURE", to_node(msignature))) - end - else if mpropdef isa MAttributeDef then - node.labels.add "MAttributeDef" - var static_mtype = mpropdef.static_mtype - if static_mtype != null then - node.out_edges.add(new NeoEdge(node, "TYPE", to_node(static_mtype))) - end - else if mpropdef isa MVirtualTypeDef then - node.labels.add "MVirtualTypeDef" - var bound = mpropdef.bound - if bound != null then - node.out_edges.add(new NeoEdge(node, "BOUND", to_node(bound))) - end - else if mpropdef isa MInnerClassDef then - node.labels.add "MInnerClassDef" - node.out_edges.add(new NeoEdge(node, "NESTS", to_node(mpropdef.inner))) - end - return node - end - # Build a new `MPropDef` from a `node`. # # REQUIRE `node.labels.has("MPropDef")` @@ -695,74 +529,6 @@ class NeoModel return mpropdef end - # Build a `NeoNode` representing `mtype`. - private fun mtype_node(mtype: MType): NeoNode do - var node = make_node(mtype) - node.labels.add "MType" - if mtype isa MClassType then - node.labels.add "MClassType" - node.out_edges.add(new NeoEdge(node, "CLASS", to_node(mtype.mclass))) - for arg in mtype.arguments do - node.out_edges.add(new NeoEdge(node, "ARGUMENT", to_node(arg))) - end - if mtype isa MGenericType then - node.labels.add "MGenericType" - end - else if mtype isa MVirtualType then - node.labels.add "MVirtualType" - node.out_edges.add(new NeoEdge(node, "PROPERTY", to_node(mtype.mproperty))) - else if mtype isa MParameterType then - node.labels.add "MParameterType" - node["rank"] = mtype.rank - node.out_edges.add(new NeoEdge(node, "CLASS", to_node(mtype.mclass))) - else if mtype isa MNullableType then - node.labels.add "MNullableType" - node.out_edges.add(new NeoEdge(node, "TYPE", to_node(mtype.mtype))) - else if mtype isa MSignature then - node.labels.add "MSignature" - var names = new JsonArray - var rank = 0 - for mparameter in mtype.mparameters do - names.add mparameter.name - var pnode = mparameter_node(mparameter) - pnode["rank"] = rank - node.out_edges.add(new NeoEdge(node, "PARAMETER", pnode)) - rank += 1 - end - if not names.is_empty then node["parameter_names"] = names - var return_mtype = mtype.return_mtype - if return_mtype != null then - node.out_edges.add(new NeoEdge(node, "RETURNTYPE", to_node(return_mtype))) - end - else if mtype isa MRawType then - node.labels.add "MRawType" - var text = new JsonArray - var rank = 0 - for part in mtype.parts do - text.add part.text - if part.target != null then - var pnode = mtypepart_node(part) - pnode["rank"] = rank - node.out_edges.add(new NeoEdge(node, "LINK", pnode)) - end - rank += 1 - end - if not text.is_empty then node["text"] = text - end - return node - end - - # Build a `NeoNode` representing `mtypepart`. - private fun mtypepart_node(mtypepart: MTypePart): NeoNode do - var node = make_node(mtypepart) - node.labels.add "MTypePart" - if mtypepart.target != null then - var target_node = to_node(mtypepart.target.as(not null)) - node.out_edges.add(new NeoEdge(node, "TARGET", target_node)) - end - return node - end - # Build a new `MType` from a `node`. # # REQUIRE `node.labels.has("MType")` @@ -845,16 +611,6 @@ class NeoModel abort end - # Build a `NeoNode` representing `mparameter`. - private fun mparameter_node(mparameter: MParameter): NeoNode do - var node = make_node(mparameter) - node.labels.add "MParameter" - node["name"] = mparameter.name - node["is_vararg"] = mparameter.is_vararg - node.out_edges.add(new NeoEdge(node, "TYPE", to_node(mparameter.mtype))) - return node - end - # Build a new `MParameter` from `node`. # # REQUIRE `node.labels.has("MParameter")` @@ -925,3 +681,334 @@ class NeoModel end end end + +redef class MPackage + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + var root = root + if root != null then + node.out_edges.add(new NeoEdge(node, "ROOT", root.to_node(nodes, model_name))) + end + return node + end +end + +redef class MGroup + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + var parent = parent + node.out_edges.add(new NeoEdge(node, "PROJECT", mpackage.to_node(nodes, model_name))) + if parent != null then + node.out_edges.add(new NeoEdge(node, "PARENT", parent.to_node(nodes, model_name))) + end + for mmodule in mmodules do + node.out_edges.add(new NeoEdge(node, "DECLARES", mmodule.to_node(nodes, model_name))) + end + for subgroup in in_nesting.direct_smallers do + node.in_edges.add(new NeoEdge(node, "NESTS", subgroup.to_node(nodes, model_name))) + end + return node + end +end + +redef class MModule + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + for parent in in_importation.direct_greaters do + node.out_edges.add(new NeoEdge(node, "IMPORTS", parent.to_node(nodes, model_name))) + end + for mclass in intro_mclasses do + node.out_edges.add(new NeoEdge(node, "INTRODUCES", mclass.to_node(nodes, model_name))) + end + for mclassdef in mclassdefs do + node.out_edges.add(new NeoEdge(node, "DEFINES", mclassdef.to_node(nodes, model_name))) + end + return node + end +end + +redef class MClass + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node["kind"] = kind.to_s + node["visibility"] = visibility.to_s + if not mparameters.is_empty then + var parameter_names = new Array[String] + for p in mparameters do parameter_names.add(p.name) + node["parameter_names"] = new JsonArray.from(parameter_names) + end + node.out_edges.add(new NeoEdge(node, "CLASSTYPE", mclass_type.to_node(nodes, model_name))) + return node + end +end + +redef class MClassDef + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node.out_edges.add(new NeoEdge(node, "BOUNDTYPE", bound_mtype.to_node(nodes, model_name))) + node.out_edges.add(new NeoEdge(node, "MCLASS", mclass.to_node(nodes, model_name))) + for mproperty in intro_mproperties do + node.out_edges.add(new NeoEdge(node, "INTRODUCES", mproperty.to_node(nodes, model_name))) + end + for mpropdef in mpropdefs do + node.out_edges.add(new NeoEdge(node, "DECLARES", mpropdef.to_node(nodes, model_name))) + end + for sup in supertypes do + node.out_edges.add(new NeoEdge(node, "INHERITS", sup.to_node(nodes, model_name))) + end + return node + end +end + +redef class MProperty + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = make_node(nodes, model_name) + node.labels.add "MProperty" + node["visibility"] = visibility.to_s + node.out_edges.add(new NeoEdge(node, "INTRO_CLASSDEF", intro_mclassdef.to_node(nodes, model_name))) + node.labels.add self.class_name + return node + end +end + +redef class MMethod + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node["is_init"] = is_init + return node + end +end + +redef class MInnerClass + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node.out_edges.add(new NeoEdge(node, "NESTS", inner.to_node(nodes, model_name))) + return node + end +end + +redef class MPropDef + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = make_node(nodes, model_name) + node.labels.add "MPropDef" + node.out_edges.add(new NeoEdge(node, "DEFINES", mproperty.to_node(nodes, model_name))) + node.labels.add self.class_name + return node + end +end + +redef class MMethodDef + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node["is_abstract"] = is_abstract + node["is_intern"] = is_intern + node["is_extern"] = is_extern + var msignature = msignature + if msignature != null then + node.out_edges.add(new NeoEdge(node, "SIGNATURE", msignature.to_node(nodes, model_name))) + end + return node + end +end + +redef class MAttributeDef + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + var static_mtype = static_mtype + if static_mtype != null then + node.out_edges.add(new NeoEdge(node, "TYPE", static_mtype.to_node(nodes, model_name))) + end + return node + end +end + +redef class MVirtualTypeDef + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + var bound = bound + if bound != null then + node.out_edges.add(new NeoEdge(node, "BOUND", bound.to_node(nodes, model_name))) + end + return node + end +end + +redef class MInnerClassDef + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node.out_edges.add(new NeoEdge(node, "NESTS", inner.to_node(nodes, model_name))) + return node + end +end + +redef class MTypePart + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + if self.target != null then + var target_node = self.target.as(not null).to_node(nodes, model_name) + node.out_edges.add(new NeoEdge(node, "TARGET", target_node)) + end + return node + end +end + +redef class MParameter + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node["name"] = self.name + node["is_vararg"] = self.is_vararg + node.out_edges.add(new NeoEdge(node, "TYPE", self.mtype.to_node(nodes, model_name))) + return node + end +end + +redef class MClassType + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node.labels.add "MClassType" + node.out_edges.add(new NeoEdge(node, "CLASS", mclass.to_node(nodes, model_name))) + for arg in arguments do + node.out_edges.add(new NeoEdge(node, "ARGUMENT", arg.to_node(nodes, model_name))) + end + return node + end +end + + +redef class MGenericType + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node.labels.add "MGenericType" + return node + end +end + +redef class MVirtualType + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node.labels.add "MVirtualType" + node.out_edges.add(new NeoEdge(node, "PROPERTY", mproperty.to_node(nodes, model_name))) + return node + end +end + +redef class MParameterType + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node.labels.add "MParameterType" + node["rank"] = rank + node.out_edges.add(new NeoEdge(node, "CLASS", mclass.to_node(nodes, model_name))) + return node + end +end + +redef class MNullableType + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node.labels.add "MNullableType" + node.out_edges.add(new NeoEdge(node, "TYPE", mtype.to_node(nodes, model_name))) + return node + end +end + +redef class MSignature + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node.labels.add "MSignature" + var names = new JsonArray + var rank = 0 + for mparameter in mparameters do + names.add mparameter.name + var pnode = mparameter.to_node(nodes, model_name) + pnode["rank"] = rank + node.out_edges.add(new NeoEdge(node, "PARAMETER", pnode)) + rank += 1 + end + if not names.is_empty then node["parameter_names"] = names + var return_mtype = return_mtype + if return_mtype != null then + node.out_edges.add(new NeoEdge(node, "RETURNTYPE", return_mtype.to_node(nodes, model_name))) + end + return node + end +end + +redef class MRawType + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = super + node.labels.add "MRawType" + var text = new JsonArray + var rank = 0 + for part in self.parts do + text.add part.text + if part.target != null then + var pnode = part.to_node(nodes, model_name) + pnode["rank"] = rank + node.out_edges.add(new NeoEdge(node, "LINK", pnode)) + end + rank += 1 + end + if not text.is_empty then node["text"] = text + return node + end +end + +redef class MType + redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = make_node(nodes, model_name) + node.labels.add "MType" + return node + end +end + +redef class MEntity + # Build a `NeoNode` representing `self`. + private fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + if nodes.has_key(self) then return nodes[self] + var node = make_node(nodes, model_name) + node.labels.add self.class_name + return node + end + + # Make a new `NeoNode` based on `mentity`. + private fun make_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do + var node = new NeoNode + nodes[self] = node + node.labels.add "MEntity" + if model_name != null then node.labels.add model_name + node["name"] = self.name + if not self isa MSignature then + #FIXME: MSignature is a MEntity, but has no model :/ + node["location"] = self.location.to_s + end + var mdoc = self.mdoc + if mdoc != null then + node["mdoc"] = new JsonArray.from(mdoc.content) + node["mdoc_location"] = mdoc.location.to_s + end + return node + end +end diff --git a/src/nit.nit b/src/nit.nit index be6c665..6441b1a 100644 --- a/src/nit.nit +++ b/src/nit.nit @@ -75,6 +75,7 @@ else end modelbuilder.run_phases +toolcontext.run_global_phases(modelbuilder.parsed_modules) if toolcontext.opt_only_metamodel.value then toolcontext.quit diff --git a/src/nitni/nitni_callbacks.nit b/src/nitni/nitni_callbacks.nit index 6d05196..c9725d0 100644 --- a/src/nitni/nitni_callbacks.nit +++ b/src/nitni/nitni_callbacks.nit @@ -219,7 +219,7 @@ class MExplicitCall var cname if mproperty.is_init then - if mproperty.name == "init" or mproperty.name == "new" then + if mproperty.name == "init" or mproperty.name == "new" or mproperty.name == "defaultinit" then cname = "new_{recv_mtype.mangled_cname}" else cname = "new_{recv_mtype.mangled_cname}_{mproperty.short_cname}" @@ -350,7 +350,7 @@ redef class AInitPropExternCall mmodule, mtype, meth_name ) if meth == null then - meth_name = "init" + meth_name = "defaultinit" meth = toolcontext.modelbuilder.try_get_mproperty_by_name2( self, mmodule, mtype, meth_name ) end diff --git a/src/nitni/nitni_utilities.nit b/src/nitni/nitni_utilities.nit index 910877b..b1b5917 100644 --- a/src/nitni/nitni_utilities.nit +++ b/src/nitni/nitni_utilities.nit @@ -28,7 +28,7 @@ redef class MMethod do var cname if self.is_init then - if self.name == "init" or self.name == "new" then + if self.name == "init" or self.name == "new" or self.name == "defaultinit" then cname = "new_{recv_mtype.mangled_cname}" else cname = "new_{recv_mtype.mangled_cname}_{self.short_cname}" diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index 5b8d41b..404ebce 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -245,7 +245,6 @@ class RapidTypeAnalysis v.add_monomorphic_send(vararg, self.modelbuilder.force_get_primitive_method(node, "with_native", vararg.mclass, self.mainmodule)) end - # TODO? new_msignature var sig = msignature var osig = mmeth.intro.msignature.as(not null) for i in [0..sig.arity[ do @@ -261,9 +260,15 @@ class RapidTypeAnalysis if npropdef isa AClassdef then if mmethoddef.mproperty.is_root_init then + # Final init call if not mmethoddef.is_intro then self.add_super_send(v.receiver, mmethoddef) end + else if mmethoddef.mclassdef.default_init == mmethoddef then + # default_init call + for i in mmethoddef.initializers do + if i isa MMethod then self.add_send(v.receiver, i) + end else npropdef.debug "cannot RTA {mmethoddef}" abort @@ -382,7 +387,6 @@ class RapidTypeAnalysis v.enter_visit(npropdef.n_block) end end - end fun add_cast(mtype: MType) diff --git a/src/semantize/auto_super_init.nit b/src/semantize/auto_super_init.nit index 55263bd..0be7107 100644 --- a/src/semantize/auto_super_init.nit +++ b/src/semantize/auto_super_init.nit @@ -104,14 +104,9 @@ redef class AMethPropdef var auto_super_inits = new Array[CallSite] # The look for new-style super constructors (called from a old style constructor) - var the_root_init_mmethod = modelbuilder.the_root_init_mmethod - if the_root_init_mmethod != null and auto_super_inits.is_empty then - var candidatedefs = the_root_init_mmethod.lookup_definitions(mmodule, anchor) - if candidatedefs.is_empty then - # skip broken - is_broken = true - return - end + var candidatedefs = get_super_candidatedefs(modelbuilder) + + if not candidatedefs.is_empty and auto_super_inits.is_empty then var candidatedef = candidatedefs.first if candidatedefs.length > 1 then @@ -121,18 +116,34 @@ redef class AMethPropdef return end - var msignature = candidatedef.new_msignature or else candidatedef.msignature + var msignature = candidatedef.msignature msignature = msignature.resolve_for(recvtype, anchor, mmodule, true) - if msignature.arity > 0 then + if msignature.arity > mpropdef.msignature.arity then modelbuilder.error(self, "Error: cannot do an implicit constructor call to `{candidatedef}{msignature}`. Expected at least `{msignature.arity}` arguments.") is_broken = true return end - var callsite = new CallSite(hot_location, recvtype, mmodule, anchor, true, the_root_init_mmethod, candidatedef, msignature, false) + if candidatedef.mproperty != mpropdef.mproperty then + var i = 0 + for candidat_mparameter in msignature.mparameters do + var actual_mparameter = mpropdef.msignature.mparameters[i] + if not candidat_mparameter.mtype.is_subtype(mmodule, anchor, actual_mparameter.mtype) then + modelbuilder.error(self, "Type Error: expected argument #{i} of type `{candidat_mparameter.mtype}`, got implicit argument `{candidat_mparameter.name}` of type `{actual_mparameter.mtype}`. Signature is {msignature}") + return + end + i += 1 + end + end + + var callsite = new CallSite(hot_location, recvtype, mmodule, anchor, true, candidatedef.mproperty, candidatedef, msignature, false) auto_super_inits.add(callsite) - modelbuilder.toolcontext.info("Auto-super init for {mpropdef} to {the_root_init_mmethod.full_name}", 4) + modelbuilder.toolcontext.info("Auto-super init for {mpropdef} to {candidatedef.full_name}", 4) + else if candidatedefs.is_empty then + # skip broken + is_broken = true + return end if auto_super_inits.is_empty then modelbuilder.error(self, "Error: no constructors to call implicitly in `{mpropdef}`. Call one explicitly.") @@ -142,6 +153,34 @@ redef class AMethPropdef self.auto_super_inits = auto_super_inits end + # This method returns the list of possible candidates for the current definition. + # + # Warning this method supports super call from old_style_init to default_inits without signature verification!!! + private fun get_super_candidatedefs(modelbuilder: ModelBuilder): Array[MMethodDef] + do + var candidatedefs = new Array[MMethodDef] + + var mclassdef = self.parent.as(AClassdef).mclassdef + if mclassdef == null or mclassdef.is_broken then return candidatedefs # skip error + var mpropdef = self.mpropdef + if mpropdef == null or mpropdef.is_broken then return candidatedefs # skip error + var mmodule = mpropdef.mclassdef.mmodule + var anchor = mclassdef.bound_mtype + var mproperty = mpropdef.mproperty + + # The look for new-style super constructors (called from a old style constructor) + var the_root_init_mmethod = modelbuilder.the_root_init_mmethod + + if mpropdef.is_old_style_init then + var superprop: nullable MMethodDef = null + for mclass in mclassdef.mclass.in_hierarchy(mmodule).direct_greaters do + candidatedefs.add(mclass.intro.default_init.as(not null)) + end + else + candidatedefs = the_root_init_mmethod.lookup_definitions(mmodule, anchor) + end + return candidatedefs + end end redef class ANode diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index b9acd5e..98aba77 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -76,6 +76,12 @@ private class TypeVisitor end end + # Display a warning on `node` if `not mpropdef.is_fictive` + fun display_warning(node: ANode, tag: String, message: String) + do + if not mpropdef.is_fictive then self.modelbuilder.warning(node, tag, message) + end + fun anchor_to(mtype: MType): MType do return mtype.anchor_to(mmodule, anchor) @@ -190,9 +196,9 @@ private class TypeVisitor if sup == null then return null # Forward error if sup == sub then - self.modelbuilder.warning(node, "useless-type-test", "Warning: expression is already a `{sup}`.") + display_warning(node, "useless-type-test", "Warning: expression is already a `{sup}`.") else if self.is_subtype(sub, sup) then - self.modelbuilder.warning(node, "useless-type-test", "Warning: expression is already a `{sup}` since it is a `{sub}`.") + display_warning(node, "useless-type-test", "Warning: expression is already a `{sup}` since it is a `{sub}`.") end return sup end @@ -215,16 +221,16 @@ private class TypeVisitor fun check_can_be_null(anode: ANode, mtype: MType): Bool do if mtype isa MNullType then - modelbuilder.warning(anode, "useless-null-test", "Warning: expression is always `null`.") + display_warning(anode, "useless-null-test", "Warning: expression is always `null`.") return true end if can_be_null(mtype) then return true if mtype isa MFormalType then var res = anchor_to(mtype) - modelbuilder.warning(anode, "useless-null-test", "Warning: expression is not null, since it is a `{mtype}: {res}`.") + display_warning(anode, "useless-null-test", "Warning: expression is not null, since it is a `{mtype}: {res}`.") else - modelbuilder.warning(anode, "useless-null-test", "Warning: expression is not null, since it is a `{mtype}`.") + display_warning(anode, "useless-null-test", "Warning: expression is not null, since it is a `{mtype}`.") end return false end @@ -315,13 +321,22 @@ private class TypeVisitor var mproperty = self.try_get_mproperty_by_name2(node, unsafe_type, name) if name == "new" and mproperty == null then - name = "init" + name = "defaultinit" mproperty = self.try_get_mproperty_by_name2(node, unsafe_type, name) + if mproperty == null then + name = "init" + mproperty = self.try_get_mproperty_by_name2(node, unsafe_type, name) + end end if mproperty == null then if recv_is_self then - self.modelbuilder.error(node, "Error: method or variable `{name}` unknown in `{recvtype}`.") + # FIXME This test was added to display a more explicit error when a potential duplication of root object class. + if name == "init" then + self.modelbuilder.error(node, "Possible duplication of the root class `Object`") + else + self.modelbuilder.error(node, "Error: method or variable `{name}` unknown in `{recvtype}`.") + end else if recvtype.need_anchor then self.modelbuilder.error(node, "Error: method `{name}` does not exists in `{recvtype}: {unsafe_type}`.") else @@ -370,9 +385,9 @@ private class TypeVisitor if info != null and self.mpropdef.mproperty.deprecation == null then var mdoc = info.mdoc if mdoc != null then - self.modelbuilder.warning(node, "deprecated-method", "Deprecation Warning: method `{mproperty.name}` is deprecated: {mdoc.content.first}") + display_warning(node, "deprecated-method", "Deprecation Warning: method `{mproperty.name}` is deprecated: {mdoc.content.first}") else - self.modelbuilder.warning(node, "deprecated-method", "Deprecation Warning: method `{mproperty.name}` is deprecated.") + display_warning(node, "deprecated-method", "Deprecation Warning: method `{mproperty.name}` is deprecated.") end end @@ -385,7 +400,7 @@ private class TypeVisitor else if propdefs.length == 1 then mpropdef = propdefs.first else - self.modelbuilder.warning(node, "property-conflict", "Warning: conflicting property definitions for property `{mproperty.name}` in `{unsafe_type}`: {propdefs.join(" ")}") + display_warning(node, "property-conflict", "Warning: conflicting property definitions for property `{mproperty.name}` in `{unsafe_type}`: {propdefs.join(" ")}") mpropdef = mproperty.intro end @@ -395,7 +410,7 @@ private class TypeVisitor # The `build_callsite_by_propdef` builds the callsite directly with the `mprodef` passed in argument. fun build_callsite_by_propdef(node: ANode, recvtype: MType, mpropdef: MMethodDef, recv_is_self: Bool): nullable CallSite do - var msignature = mpropdef.new_msignature or else mpropdef.msignature + var msignature = mpropdef.msignature if msignature == null then return null # skip error msignature = resolve_for(msignature, recvtype, recv_is_self).as(MSignature) @@ -1023,6 +1038,18 @@ redef class AExpr end return res end + + # Type the expression as if located in `visited_mpropdef` + # `TypeVisitor` and `PostTypingVisitor` will be used to do the typing, see them for more information. + # + # `visited_mpropdef`: Correspond to the evaluation context in which the expression is located. + fun do_typing(modelbuilder: ModelBuilder, visited_mpropdef: MPropDef) + do + var type_visitor = new TypeVisitor(modelbuilder, visited_mpropdef) + type_visitor.visit_stmt(self) + var post_visitor = new PostTypingVisitor(type_visitor) + post_visitor.enter_visit(self) + end end redef class ABlockExpr @@ -1730,7 +1757,7 @@ redef class AArrayExpr end if useless then assert ntype != null - v.modelbuilder.warning(ntype, "useless-type", "Warning: useless type declaration `{mtype}` in literal Array since it can be inferred from the elements type.") + v.display_warning(ntype, "useless-type", "Warning: useless type declaration `{mtype}` in literal Array since it can be inferred from the elements type.") end self.element_mtype = mtype @@ -1774,7 +1801,7 @@ redef class ARangeExpr # get the constructor var callsite if self isa ACrangeExpr then - callsite = v.build_callsite_by_name(self, mtype, "init", false) + callsite = v.build_callsite_by_name(self, mtype, "defaultinit", false) else if self isa AOrangeExpr then callsite = v.build_callsite_by_name(self, mtype, "without_last", false) else @@ -1984,9 +2011,7 @@ redef class ASendExpr var args = compute_raw_arguments - if not self isa ACallrefExpr then - callsite.check_signature(v, node, args) - end + if not self isa ACallrefExpr then callsite.check_signature(v, node, args) if callsite.mproperty.is_init then var vmpropdef = v.mpropdef @@ -2055,7 +2080,7 @@ redef class AEqFormExpr if mtype == null or mtype2 == null then return if mtype == v.type_bool(self) and (n_expr2 isa AFalseExpr or n_expr2 isa ATrueExpr) then - v.modelbuilder.warning(self, "useless-truism", "Warning: useless comparison to a Bool literal.") + v.display_warning(self, "useless-truism", "Warning: useless comparison to a Bool literal.") end if not mtype2 isa MNullType then return @@ -2156,7 +2181,7 @@ redef class ABraReassignExpr end redef class AInitExpr - redef fun property_name do return "init" + redef fun property_name do if n_args.n_exprs.is_empty then return "init" else return "defaultinit" redef fun property_node do return n_kwinit redef fun compute_raw_arguments do return n_args.to_a end @@ -2325,7 +2350,7 @@ redef class ASuperExpr return end - var msignature = superprop.new_msignature or else superprop.msignature.as(not null) + var msignature = superprop.msignature.as(not null) msignature = v.resolve_for(msignature, recvtype, true).as(MSignature) var callsite = new CallSite(hot_location, recvtype, v.mmodule, v.anchor, true, superprop.mproperty, superprop, msignature, false) @@ -2572,7 +2597,7 @@ redef class ASafeExpr self.mtype = mtype.as_notnull if not v.can_be_null(mtype) then - v.modelbuilder.warning(self, "useless-safe", "Warning: useless safe operator `?` on non-nullable value.") + v.display_warning(self, "useless-safe", "Warning: useless safe operator `?` on non-nullable value.") return end end @@ -2600,7 +2625,7 @@ redef class ADebugTypeExpr var mtype = v.resolve_mtype(ntype) if mtype != null and mtype != expr then var umtype = v.anchor_to(mtype) - v.modelbuilder.warning(self, "debug", "Found type {expr} (-> {unsafe}), expected {mtype} (-> {umtype})") + v.display_warning(self, "debug", "Found type {expr} (-> {unsafe}), expected {mtype} (-> {umtype})") end self.is_typed = true end diff --git a/src/test_test_phase.nit b/src/test_test_phase.nit index cd300d4..11b1451 100644 --- a/src/test_test_phase.nit +++ b/src/test_test_phase.nit @@ -21,7 +21,7 @@ module test_test_phase import test_phase # We usualy need specific phases -# NOTE: `frontend` is sufficient in most case (it is often too much) +# NOTE: `frontend` is sufficient in most cases (it is often too much) import frontend # The body of the specific work. diff --git a/src/vm/vm_optimizations.nit b/src/vm/vm_optimizations.nit index 514d3d1..3fe9672 100644 --- a/src/vm/vm_optimizations.nit +++ b/src/vm/vm_optimizations.nit @@ -24,28 +24,7 @@ redef class VirtualMachine # Add optimization of the method dispatch redef fun callsite(callsite: nullable CallSite, arguments: Array[Instance]): nullable Instance do - var initializers = callsite.mpropdef.initializers - if initializers.is_empty then return send_optimize(callsite.as(not null), arguments) - - var recv = arguments.first - var i = 1 - for p in initializers do - if p isa MMethod then - var args = [recv] - for x in p.intro.msignature.mparameters do - args.add arguments[i] - i += 1 - end - self.send(p, args) - else if p isa MAttribute then - assert recv isa MutableInstance - write_attribute(p, recv, arguments[i]) - i += 1 - else abort - end - assert i == arguments.length - - return send_optimize(callsite.as(not null), [recv]) + return send_optimize(callsite.as(not null), arguments) end # Try to have the most efficient implementation of the method dispatch diff --git a/tests/base_attr_nullable.nit b/tests/base_attr_nullable.nit index ae29324..112f86b 100644 --- a/tests/base_attr_nullable.nit +++ b/tests/base_attr_nullable.nit @@ -26,7 +26,6 @@ end class Integer var val: Int - init(val: Int) do _val = val fun output do _val.output end diff --git a/tests/base_init_super_call2.nit b/tests/base_init_super_call2.nit index be64735..0f2988b 100644 --- a/tests/base_init_super_call2.nit +++ b/tests/base_init_super_call2.nit @@ -40,7 +40,10 @@ end class C1 super A - init(j: Int) do + init(j: Int) + is + old_style_init + do super j.output end @@ -48,7 +51,10 @@ end class D1 super A - init(j: Int) do + init(j: Int) + is + old_style_init + do super j.output end @@ -56,7 +62,10 @@ end class E1 super A - init(j: Bool) do + init(j: Bool) + is + old_style_init + do super(8)#alt4#super j.output end @@ -64,7 +73,10 @@ end class C2 super A - init(j: Int) do + init(j: Int) + is + old_style_init + do super(j) j.output end @@ -72,7 +84,10 @@ end class D2 super A - init(j: Int) do + init(j: Int) + is + old_style_init + do super(j) j.output end @@ -80,7 +95,10 @@ end class E2 super A - init(j: Bool) do + init(j: Bool) + is + old_style_init + do super(11)#alt5#super(j) j.output end @@ -88,7 +106,10 @@ end class C3 super A - init(j: Int) do + init(j: Int) + is + old_style_init + do super(j)#alt6# j.output end @@ -96,7 +117,10 @@ end class D3 super A - init(j: Int) do + init(j: Int) + is + old_style_init + do super(j)#alt6# j.output end @@ -104,7 +128,10 @@ end class E3 super A - init(j: Bool) do + init(j: Bool) + is + old_style_init + do super(14)#alt6# j.output end @@ -112,7 +139,10 @@ end class F1 super A - init(j: Int, k: Bool) do + init(j: Int, k: Bool) + is + old_style_init + do super j.output end @@ -120,7 +150,10 @@ end class F2 super A - init(j: Int, k: Bool) do + init(j: Int, k: Bool) + is + old_style_init + do super(j)#alt6# j.output end diff --git a/tests/base_simple3.nit b/tests/base_simple3.nit index 8bb2bc8..6515ef7 100644 --- a/tests/base_simple3.nit +++ b/tests/base_simple3.nit @@ -33,11 +33,7 @@ end class B var val: Int - init(v: Int) - do - 7.output - self.val = v - end + init do 7.output fun run do val.output end diff --git a/tests/contracts_null_parameter.nit b/tests/contracts_null_parameter.nit new file mode 100644 index 0000000..da7c073 --- /dev/null +++ b/tests/contracts_null_parameter.nit @@ -0,0 +1,31 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + + var null_attribut: nullable Int + + fun set_null_attribut(i: nullable Int) + is + ensure(null_attribut == i) + do + null_attribut = i + end +end + + +var a = new A +a.set_null_attribut +a.set_null_attribut(10) +a.set_null_attribut diff --git a/tests/error_defs_init.nit b/tests/error_defs_init.nit index adff5f2..710fe07 100644 --- a/tests/error_defs_init.nit +++ b/tests/error_defs_init.nit @@ -16,18 +16,18 @@ import kernel class A #1alt1#init do abort - #1alt2#init(a: Int) do abort + #1alt2#init(a: Int) is old_style_init do abort #1alt3#new do abort #1alt4#new(c: Int) do abort - #1alt5#init foo(a: Int) do abort + #1alt5#init foo(a: Int) is old_style_init do abort #1alt6#new foo(c: Int) do abort #1alt7#fun foo do end #alt1#init do abort - #alt2#init(b: Float) do abort + #alt2#init(b: Float)is old_style_init do abort #alt3#new do abort #alt4#new(d: Float) do abort - #alt5#init foo(a: Float) do abort + #alt5#init foo(a: Float)is old_style_init do abort #alt6#new foo(c: Float) do abort #alt7#fun foo do end end diff --git a/tests/sav/base_arg_default_autoinit_alt1.res b/tests/sav/base_arg_default_autoinit_alt1.res index d6c4929..df31aac 100644 --- a/tests/sav/base_arg_default_autoinit_alt1.res +++ b/tests/sav/base_arg_default_autoinit_alt1.res @@ -1,9 +1,9 @@ -alt/base_arg_default_autoinit_alt1.nit:59,5--7: Error: expected at least 1 argument(s) for `init(mandatory: Int, optional: nullable Int)`; got 0. See introduction at `core::Object::init`. -alt/base_arg_default_autoinit_alt1.nit:68,5--7: Error: expected 2 argument(s) for `init(mandatory: Int, optional: nullable Int)`; got 3. See introduction at `core::Object::init`. -alt/base_arg_default_autoinit_alt1.nit:71,5--7: Error: expected 4 argument(s) for `init(mandatory: Int, optional, optional_b: nullable Int, mandatory_b: Int)`; got 1. See introduction at `core::Object::init`. -alt/base_arg_default_autoinit_alt1.nit:74,5--7: Error: expected 4 argument(s) for `init(mandatory: Int, optional, optional_b: nullable Int, mandatory_b: Int)`; got 2. See introduction at `core::Object::init`. -alt/base_arg_default_autoinit_alt1.nit:77,5--7: Error: expected 4 argument(s) for `init(mandatory: Int, optional, optional_b: nullable Int, mandatory_b: Int)`; got 3. See introduction at `core::Object::init`. -alt/base_arg_default_autoinit_alt1.nit:83,5--7: Error: expected 4 argument(s) for `init(mandatory: Int, optional, optional_b: nullable Int, mandatory_b: Int)`; got 5. See introduction at `core::Object::init`. -alt/base_arg_default_autoinit_alt1.nit:86,5--7: Error: expected 3 argument(s) for `init(optional_b: nullable Int, mandatory_b, mandatory: Int)`; got 1. See introduction at `core::Object::init`. -alt/base_arg_default_autoinit_alt1.nit:89,5--7: Error: expected 3 argument(s) for `init(optional_b: nullable Int, mandatory_b, mandatory: Int)`; got 2. See introduction at `core::Object::init`. -alt/base_arg_default_autoinit_alt1.nit:95,5--7: Error: expected 3 argument(s) for `init(optional_b: nullable Int, mandatory_b, mandatory: Int)`; got 4. See introduction at `core::Object::init`. +alt/base_arg_default_autoinit_alt1.nit:59,5--7: Error: expected at least 1 argument(s) for `defaultinit(mandatory: Int, optional: nullable Int)`; got 0. See introduction at `base_arg_default_autoinit_alt1::A::defaultinit`. +alt/base_arg_default_autoinit_alt1.nit:68,5--7: Error: expected 2 argument(s) for `defaultinit(mandatory: Int, optional: nullable Int)`; got 3. See introduction at `base_arg_default_autoinit_alt1::A::defaultinit`. +alt/base_arg_default_autoinit_alt1.nit:71,5--7: Error: expected 4 argument(s) for `defaultinit(mandatory: Int, optional, optional_b: nullable Int, mandatory_b: Int)`; got 1. See introduction at `base_arg_default_autoinit_alt1::B::defaultinit`. +alt/base_arg_default_autoinit_alt1.nit:74,5--7: Error: expected 4 argument(s) for `defaultinit(mandatory: Int, optional, optional_b: nullable Int, mandatory_b: Int)`; got 2. See introduction at `base_arg_default_autoinit_alt1::B::defaultinit`. +alt/base_arg_default_autoinit_alt1.nit:77,5--7: Error: expected 4 argument(s) for `defaultinit(mandatory: Int, optional, optional_b: nullable Int, mandatory_b: Int)`; got 3. See introduction at `base_arg_default_autoinit_alt1::B::defaultinit`. +alt/base_arg_default_autoinit_alt1.nit:83,5--7: Error: expected 4 argument(s) for `defaultinit(mandatory: Int, optional, optional_b: nullable Int, mandatory_b: Int)`; got 5. See introduction at `base_arg_default_autoinit_alt1::B::defaultinit`. +alt/base_arg_default_autoinit_alt1.nit:86,5--7: Error: expected 3 argument(s) for `defaultinit(optional_b: nullable Int, mandatory_b, mandatory: Int)`; got 1. See introduction at `base_arg_default_autoinit_alt1::C::defaultinit`. +alt/base_arg_default_autoinit_alt1.nit:89,5--7: Error: expected 3 argument(s) for `defaultinit(optional_b: nullable Int, mandatory_b, mandatory: Int)`; got 2. See introduction at `base_arg_default_autoinit_alt1::C::defaultinit`. +alt/base_arg_default_autoinit_alt1.nit:95,5--7: Error: expected 3 argument(s) for `defaultinit(optional_b: nullable Int, mandatory_b, mandatory: Int)`; got 4. See introduction at `base_arg_default_autoinit_alt1::C::defaultinit`. diff --git a/tests/sav/base_attr_annot_1alt1.res b/tests/sav/base_attr_annot_1alt1.res index 9caee3f..55e832d 100644 --- a/tests/sav/base_attr_annot_1alt1.res +++ b/tests/sav/base_attr_annot_1alt1.res @@ -1 +1 @@ -alt/base_attr_annot_1alt1.nit:33,9--11: Error: expected 0 argument(s) for `init`; got 1. See introduction at `core::Object::init`. +alt/base_attr_annot_1alt1.nit:33,9--11: Error: expected 0 argument(s) for `defaultinit`; got 1. See introduction at `base_attr_annot_1alt1::B::defaultinit`. diff --git a/tests/sav/base_attr_annot_alt1.res b/tests/sav/base_attr_annot_alt1.res index ea3b78f..7b33360 100644 --- a/tests/sav/base_attr_annot_alt1.res +++ b/tests/sav/base_attr_annot_alt1.res @@ -1 +1 @@ -alt/base_attr_annot_alt1.nit:33,9--11: Error: expected 1 argument(s) for `init(a: Object)`; got 0. See introduction at `core::Object::init`. +alt/base_attr_annot_alt1.nit:33,9--11: Error: expected 1 argument(s) for `defaultinit(a: Object)`; got 0. See introduction at `base_attr_annot_alt1::B::defaultinit`. diff --git a/tests/sav/base_attr_nullable_alt1.res b/tests/sav/base_attr_nullable_alt1.res index c7cab54..60c2eaf 100644 --- a/tests/sav/base_attr_nullable_alt1.res +++ b/tests/sav/base_attr_nullable_alt1.res @@ -1 +1 @@ -Runtime error: Uninitialized attribute _a1 (alt/base_attr_nullable_alt1.nit:38) +Runtime error: Uninitialized attribute _a1 (alt/base_attr_nullable_alt1.nit:37) diff --git a/tests/sav/base_attr_nullable_alt2.res b/tests/sav/base_attr_nullable_alt2.res index d238261..46a38b1 100644 --- a/tests/sav/base_attr_nullable_alt2.res +++ b/tests/sav/base_attr_nullable_alt2.res @@ -1,2 +1,2 @@ -Runtime error: Uninitialized attribute _a2 (alt/base_attr_nullable_alt2.nit:39) +Runtime error: Uninitialized attribute _a2 (alt/base_attr_nullable_alt2.nit:38) 1 diff --git a/tests/sav/base_attr_nullable_alt3.res b/tests/sav/base_attr_nullable_alt3.res index b6f38c8..a725723 100644 --- a/tests/sav/base_attr_nullable_alt3.res +++ b/tests/sav/base_attr_nullable_alt3.res @@ -1 +1 @@ -Runtime error: Uninitialized attribute _a1 (alt/base_attr_nullable_alt3.nit:64) +Runtime error: Uninitialized attribute _a1 (alt/base_attr_nullable_alt3.nit:63) diff --git a/tests/sav/base_attr_nullable_alt4.res b/tests/sav/base_attr_nullable_alt4.res index 1a98ce8..7ab0b21 100644 --- a/tests/sav/base_attr_nullable_alt4.res +++ b/tests/sav/base_attr_nullable_alt4.res @@ -1,2 +1,2 @@ -Runtime error: Uninitialized attribute _a2 (alt/base_attr_nullable_alt4.nit:45) +Runtime error: Uninitialized attribute _a2 (alt/base_attr_nullable_alt4.nit:44) 10 diff --git a/tests/sav/base_attr_nullable_alt5.res b/tests/sav/base_attr_nullable_alt5.res index 891e424..eadaa67 100644 --- a/tests/sav/base_attr_nullable_alt5.res +++ b/tests/sav/base_attr_nullable_alt5.res @@ -1,3 +1,3 @@ -Runtime error: Uninitialized attribute _a3 (alt/base_attr_nullable_alt5.nit:66) +Runtime error: Uninitialized attribute _a3 (alt/base_attr_nullable_alt5.nit:65) 10 20 diff --git a/tests/sav/base_init_basic_alt3.res b/tests/sav/base_init_basic_alt3.res index 84d579c..971fe14 100644 --- a/tests/sav/base_init_basic_alt3.res +++ b/tests/sav/base_init_basic_alt3.res @@ -1,2 +1,2 @@ -alt/base_init_basic_alt3.nit:47,7: Error: cannot generate automatic init for class F. Conflict in the order in inherited initializers base_init_basic_alt3$E$init(c=, e=) and base_init_basic_alt3$D$init(c=, b=). Use `autoinit` to order initializers. eg `autoinit c=, b=, e=` -alt/base_init_basic_alt3.nit:54,7: Error: cannot generate automatic init for class G. Conflict in the order in inherited initializers base_init_basic_alt3$E$init(c=, e=) and base_init_basic_alt3$D$init(c=, b=). Use `autoinit` to order initializers. eg `autoinit c=, b=, e=, g=` +alt/base_init_basic_alt3.nit:47,7: Error: cannot generate automatic init for class F. Conflict in the order in inherited initializers base_init_basic_alt3$E$defaultinit(c=, e=) and base_init_basic_alt3$D$defaultinit(c=, b=). Use `autoinit` to order initializers. eg `autoinit c=, b=, e=` +alt/base_init_basic_alt3.nit:54,7: Error: cannot generate automatic init for class G. Conflict in the order in inherited initializers base_init_basic_alt3$E$defaultinit(c=, e=) and base_init_basic_alt3$D$defaultinit(c=, b=). Use `autoinit` to order initializers. eg `autoinit c=, b=, e=, g=` diff --git a/tests/sav/base_init_basic_alt5.res b/tests/sav/base_init_basic_alt5.res index 82ddfc6..565d4e7 100644 --- a/tests/sav/base_init_basic_alt5.res +++ b/tests/sav/base_init_basic_alt5.res @@ -1 +1 @@ -alt/base_init_basic_alt5.nit:79,9--11: Error: expected 2 argument(s) for `init(c, b: Int)`; got 1. See introduction at `core::Object::init`. +alt/base_init_basic_alt5.nit:79,9--11: Error: expected 2 argument(s) for `defaultinit(c, b: Int)`; got 1. See introduction at `base_init_basic_alt5::D::defaultinit`. diff --git a/tests/sav/base_init_combine_alt1.res b/tests/sav/base_init_combine_alt1.res index b079cab..d9b9b04 100644 --- a/tests/sav/base_init_combine_alt1.res +++ b/tests/sav/base_init_combine_alt1.res @@ -1 +1 @@ -alt/base_init_combine_alt1.nit:59,9--11: Error: expected 2 argument(s) for `init(i, z: Int)`; got 1. See introduction at `core::Object::init`. +alt/base_init_combine_alt1.nit:59,9--11: Error: expected 2 argument(s) for `defaultinit(i, z: Int)`; got 1. See introduction at `base_init_combine_alt1::F::defaultinit`. diff --git a/tests/sav/base_init_noinit_alt4.res b/tests/sav/base_init_noinit_alt4.res index 7282bf5..5d7df60 100644 --- a/tests/sav/base_init_noinit_alt4.res +++ b/tests/sav/base_init_noinit_alt4.res @@ -1 +1 @@ -alt/base_init_noinit_alt4.nit:30,3--5: Error: expected 0 argument(s) for `init`; got 1. See introduction at `core::Object::init`. +alt/base_init_noinit_alt4.nit:30,3--5: Error: expected 0 argument(s) for `defaultinit`; got 1. See introduction at `base_init_noinit_alt4::A::defaultinit`. diff --git a/tests/sav/base_init_super_call2_alt3.res b/tests/sav/base_init_super_call2_alt3.res index d75b874..9245c89 100644 --- a/tests/sav/base_init_super_call2_alt3.res +++ b/tests/sav/base_init_super_call2_alt3.res @@ -1 +1 @@ -alt/base_init_super_call2_alt3.nit:38,2--5: Error: cannot do an implicit constructor call to `base_init_super_call2_alt3$A$init(i: Int)`. Expected at least `1` arguments. +alt/base_init_super_call2_alt3.nit:38,2--5: Error: cannot do an implicit constructor call to `base_init_super_call2_alt3$A$defaultinit(i: Int)`. Expected at least `1` arguments. diff --git a/tests/sav/base_init_super_call2_alt4.res b/tests/sav/base_init_super_call2_alt4.res index 823de40..eeb33c5 100644 --- a/tests/sav/base_init_super_call2_alt4.res +++ b/tests/sav/base_init_super_call2_alt4.res @@ -1 +1 @@ -alt/base_init_super_call2_alt4.nit:60,3--7: Type Error: expected argument #0 of type `Int`, got implicit argument `j` of type `Bool`. Signature is (i: Int) +alt/base_init_super_call2_alt4.nit:69,3--7: Type Error: expected argument #0 of type `Int`, got implicit argument `j` of type `Bool`. Signature is (i: Int) diff --git a/tests/sav/base_init_super_call2_alt5.res b/tests/sav/base_init_super_call2_alt5.res index b6e45c9..7fd2621 100644 --- a/tests/sav/base_init_super_call2_alt5.res +++ b/tests/sav/base_init_super_call2_alt5.res @@ -1 +1 @@ -alt/base_init_super_call2_alt5.nit:84,9: Type Error: expected `Int`, got `Bool`. +alt/base_init_super_call2_alt5.nit:102,9: Type Error: expected `Int`, got `Bool`. diff --git a/tests/sav/base_init_super_call2_alt6.res b/tests/sav/base_init_super_call2_alt6.res index a920abb..0d1abc9 100644 --- a/tests/sav/base_init_super_call2_alt6.res +++ b/tests/sav/base_init_super_call2_alt6.res @@ -1,4 +1 @@ -alt/base_init_super_call2_alt6.nit:91,2--5: Error: cannot do an implicit constructor call to `base_init_super_call2_alt6$A$init(i: Int)`. Expected at least `1` arguments. -alt/base_init_super_call2_alt6.nit:99,2--5: Error: cannot do an implicit constructor call to `base_init_super_call2_alt6$A$init(i: Int)`. Expected at least `1` arguments. -alt/base_init_super_call2_alt6.nit:107,2--5: Error: cannot do an implicit constructor call to `base_init_super_call2_alt6$A$init(i: Int)`. Expected at least `1` arguments. -alt/base_init_super_call2_alt6.nit:123,2--5: Error: cannot do an implicit constructor call to `base_init_super_call2_alt6$A$init(i: Int)`. Expected at least `1` arguments. +alt/base_init_super_call2_alt6.nit:131,2--5: Type Error: expected argument #0 of type `Int`, got implicit argument `i` of type `Bool`. Signature is (i: Int) diff --git a/tests/sav/base_init_super_call_alt3.res b/tests/sav/base_init_super_call_alt3.res index 138108b..4adff4b 100644 --- a/tests/sav/base_init_super_call_alt3.res +++ b/tests/sav/base_init_super_call_alt3.res @@ -1,23 +1 @@ -1 -2 -3 -4 -6 -6 -7 -7 -8 -true -9 -9 -10 -10 -11 -true -12 -13 -14 -true -15 -15 -16 +alt/base_init_super_call_alt3.nit:38,2--5: Error: cannot do an implicit constructor call to `base_init_super_call_alt3$A$defaultinit(i: Int)`. Expected at least `1` arguments. diff --git a/tests/sav/base_new_alt8.res b/tests/sav/base_new_alt8.res index 880abb6..a0517ba 100644 --- a/tests/sav/base_new_alt8.res +++ b/tests/sav/base_new_alt8.res @@ -1 +1,2 @@ +alt/base_new_alt8.nit:91,2--4: Error: ambiguous property name `defaultinit` for `Int`; conflict between core::Numeric::defaultinit and core::Discrete::defaultinit. alt/base_new_alt8.nit:91,2--8: Type Error: cannot instantiate enum `Int`. diff --git a/tests/sav/base_vararg_mult_alt1.res b/tests/sav/base_vararg_mult_alt1.res index 8189994..b9c7f9d 100644 --- a/tests/sav/base_vararg_mult_alt1.res +++ b/tests/sav/base_vararg_mult_alt1.res @@ -1,3 +1,3 @@ -alt/base_vararg_mult_alt1.nit:40,5--7: Error: expected at least 1 argument(s) for `init(ints: Int...)`; got 0. See introduction at `core::Object::init`. -alt/base_vararg_mult_alt1.nit:47,5--7: Error: expected 2 argument(s) for `init(ints: Int..., objs: Object...)`; got 3. See introduction at `core::Object::init`. +alt/base_vararg_mult_alt1.nit:40,5--7: Error: expected at least 1 argument(s) for `defaultinit(ints: Int...)`; got 0. See introduction at `base_vararg_mult_alt1::A::defaultinit`. +alt/base_vararg_mult_alt1.nit:47,5--7: Error: expected 2 argument(s) for `defaultinit(ints: Int..., objs: Object...)`; got 3. See introduction at `base_vararg_mult_alt1::B::defaultinit`. alt/base_vararg_mult_alt1.nit:48,11--18: Type Error: expected `Int`, got `Array[Int]`. Is an ellipsis `...` missing on the argument? diff --git a/tests/sav/contracts.res b/tests/sav/contracts.res index fe6b723..c9b0553 100644 --- a/tests/sav/contracts.res +++ b/tests/sav/contracts.res @@ -1 +1 @@ -Runtime error: Assert 'expect' failed (contracts.nit:31) +Runtime error: Assert 'expect(not bool)' failed (contracts.nit:31) diff --git a/tests/sav/contracts_abstract.res b/tests/sav/contracts_abstract.res index 5f6178c..738f3f0 100644 --- a/tests/sav/contracts_abstract.res +++ b/tests/sav/contracts_abstract.res @@ -1 +1 @@ -Runtime error: Assert 'ensure' failed (contracts_abstract.nit:26) +Runtime error: Assert 'ensure(y <= 10.0, y == 42.0)' failed (contracts_abstract.nit:26) diff --git a/tests/sav/contracts_add.res b/tests/sav/contracts_add.res index a353fc9..6d21df2 100644 --- a/tests/sav/contracts_add.res +++ b/tests/sav/contracts_add.res @@ -1,2 +1,2 @@ contracts_add.nit:46,3--16: Useless contract: No contract defined at the introduction of the method -Runtime error: Assert 'ensure' failed (contracts_add.nit:39) +Runtime error: Assert 'ensure(x == 0)' failed (contracts_add.nit:39) diff --git a/tests/sav/contracts_constructor.res b/tests/sav/contracts_constructor.res index f0801df..94dfe03 100644 --- a/tests/sav/contracts_constructor.res +++ b/tests/sav/contracts_constructor.res @@ -1 +1 @@ -Runtime error: Assert 'expect' failed (contracts_constructor.nit:20) +Runtime error: Assert 'expect(test > 10)' failed (contracts_constructor.nit:20) diff --git a/tests/sav/contracts_ensures.res b/tests/sav/contracts_ensures.res index 5e3bffa..34f0938 100644 --- a/tests/sav/contracts_ensures.res +++ b/tests/sav/contracts_ensures.res @@ -1 +1 @@ -Runtime error: Assert 'ensure' failed (contracts_ensures.nit:29) +Runtime error: Assert 'ensure(not bool)' failed (contracts_ensures.nit:29) diff --git a/tests/sav/contracts_ensures_1.res b/tests/sav/contracts_ensures_1.res index c947107..698c7dc 100644 --- a/tests/sav/contracts_ensures_1.res +++ b/tests/sav/contracts_ensures_1.res @@ -1,3 +1,3 @@ -Runtime error: Assert 'ensure' failed (contracts_ensures_1.nit:20) +Runtime error: Assert 'ensure(x > 0)' failed (contracts_ensures_1.nit:20) Good Fail diff --git a/tests/sav/contracts_ensures_2.res b/tests/sav/contracts_ensures_2.res index 982613a..213d864 100644 --- a/tests/sav/contracts_ensures_2.res +++ b/tests/sav/contracts_ensures_2.res @@ -1,4 +1,4 @@ -Runtime error: Assert 'ensure' failed (contracts_ensures_2.nit:31) +Runtime error: Assert 'ensure(y == 1.2)' failed (contracts_ensures_2.nit:31) Good Good Good diff --git a/tests/sav/contracts_ensures_3.res b/tests/sav/contracts_ensures_3.res index 11ebcc5..06c56eb 100644 --- a/tests/sav/contracts_ensures_3.res +++ b/tests/sav/contracts_ensures_3.res @@ -1 +1 @@ -Runtime error: Assert 'ensure' failed (contracts_ensures_3.nit:20) +Runtime error: Assert 'ensure(result > 0)' failed (contracts_ensures_3.nit:20) diff --git a/tests/sav/contracts_ensures_4.res b/tests/sav/contracts_ensures_4.res index e602695..6c8805e 100644 --- a/tests/sav/contracts_ensures_4.res +++ b/tests/sav/contracts_ensures_4.res @@ -1 +1 @@ -Runtime error: Assert 'ensure' failed (contracts_ensures_4.nit:31) +Runtime error: Assert 'ensure(not result)' failed (contracts_ensures_4.nit:31) diff --git a/tests/sav/contracts_ensures_sequence.res b/tests/sav/contracts_ensures_sequence.res index 3cdcc71..b62c05a 100644 --- a/tests/sav/contracts_ensures_sequence.res +++ b/tests/sav/contracts_ensures_sequence.res @@ -1 +1 @@ -Runtime error: Assert 'ensure' failed (contracts_ensures_sequence.nit:18) +Runtime error: Assert 'ensure(x > 2)' failed (contracts_ensures_sequence.nit:18) diff --git a/tests/sav/contracts_error.res b/tests/sav/contracts_error.res index 45e60a6..3847129 100644 --- a/tests/sav/contracts_error.res +++ b/tests/sav/contracts_error.res @@ -1,2 +1,2 @@ -contracts_error.nit:23,10--22: Error: expected an expression. -contracts_error.nit:24,10--22: Error: expected an expression. +contracts_error.nit:23,3--23: Error: expected an expression. +contracts_error.nit:24,3--23: Error: expected an expression. diff --git a/tests/sav/contracts_expects_1.res b/tests/sav/contracts_expects_1.res index c265d14..555a497 100644 --- a/tests/sav/contracts_expects_1.res +++ b/tests/sav/contracts_expects_1.res @@ -1 +1 @@ -Runtime error: Assert 'expect' failed (contracts_expects_1.nit:20) +Runtime error: Assert 'expect(x > 0)' failed (contracts_expects_1.nit:20) diff --git a/tests/sav/contracts_generic_type.res b/tests/sav/contracts_generic_type.res index 9c7f782..6d36851 100644 --- a/tests/sav/contracts_generic_type.res +++ b/tests/sav/contracts_generic_type.res @@ -1 +1 @@ -Runtime error: Assert 'expect' failed (contracts_generic_type.nit:33) +Runtime error: Assert 'expect(x.length != 0)' failed (contracts_generic_type.nit:33) diff --git a/tests/sav/contracts_inheritance.res b/tests/sav/contracts_inheritance.res index 0abeba3..5736913 100644 --- a/tests/sav/contracts_inheritance.res +++ b/tests/sav/contracts_inheritance.res @@ -1,5 +1,5 @@ contracts_inheritance.nit:58,6--9: Warning: conflicting property definitions for property `toto` in `MySubArray`: contracts_inheritance$MyArrayInt$toto contracts_inheritance$MyArrayInt2$toto -Runtime error: Assert 'ensure' failed (contracts_inheritance.nit:32) +Runtime error: Assert 'ensure(e == 12)' failed (contracts_inheritance.nit:32) toto MyArrayInt2 toto MyArrayInt toto ArrayInt diff --git a/tests/sav/contracts_same_contract.res b/tests/sav/contracts_same_contract.res index 54afbe1..e69de29 100644 --- a/tests/sav/contracts_same_contract.res +++ b/tests/sav/contracts_same_contract.res @@ -1 +0,0 @@ -contracts_same_contract.nit:22,3--17: The method already has a defined `expect` contract at line 21 diff --git a/tests/sav/contracts_static.res b/tests/sav/contracts_static.res index 95b94d6..445cb2e 100644 --- a/tests/sav/contracts_static.res +++ b/tests/sav/contracts_static.res @@ -1,2 +1,2 @@ -Runtime error: Assert 'ensure' failed (contracts_static.nit:29) +Runtime error: Assert 'ensure(x > 10)' failed (contracts_static.nit:29) Error diff --git a/tests/sav/contracts_virtual_type.res b/tests/sav/contracts_virtual_type.res index 616e1d0..ada2d2b 100644 --- a/tests/sav/contracts_virtual_type.res +++ b/tests/sav/contracts_virtual_type.res @@ -1 +1 @@ -Runtime error: Assert 'expect' failed (contracts_virtual_type.nit:23) +Runtime error: Assert 'expect(x == 1)' failed (contracts_virtual_type.nit:23) diff --git a/tests/sav/error_class_glob.res b/tests/sav/error_class_glob.res index 0a541aa..5c09788 100644 --- a/tests/sav/error_class_glob.res +++ b/tests/sav/error_class_glob.res @@ -1,13 +1,2 @@ -../lib/core/kernel.nit:32,1--225,3: Error: `kernel$Object` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:227,1--300,3: Error: `kernel$Sys` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:313,1--371,3: Error: `kernel$Comparable` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:373,1--410,3: Error: `kernel$Discrete` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:412,1--429,3: Error: `kernel$Cloneable` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:431,1--486,3: Error: `kernel$Numeric` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:492,1--515,3: Error: `kernel$Bool` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:517,1--599,3: Error: `kernel$Float` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:601,1--700,3: Error: `kernel$Byte` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:702,1--886,3: Error: `kernel$Int` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:888,1--1067,3: Error: `kernel$Char` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:1069,1--1086,3: Error: `kernel$Pointer` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:1088,1--1097,3: Error: `kernel$Task` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? +../lib/core/collection/hash_collection.nit:275,3--6: Possible duplication of the root class `Object` +../lib/core/collection/hash_collection.nit:473,3--6: Possible duplication of the root class `Object` diff --git a/tests/sav/error_defs_init_1alt1_alt2.res b/tests/sav/error_defs_init_1alt1_alt2.res index 85a7e8e..e69de29 100644 --- a/tests/sav/error_defs_init_1alt1_alt2.res +++ b/tests/sav/error_defs_init_1alt1_alt2.res @@ -1 +0,0 @@ -alt/error_defs_init_1alt1_alt2.nit:27,2--5: Error: a property `init` is already defined in class `A` at line 18. diff --git a/tests/sav/error_defs_init_1alt2_alt1.res b/tests/sav/error_defs_init_1alt2_alt1.res index d0f5aa7..e69de29 100644 --- a/tests/sav/error_defs_init_1alt2_alt1.res +++ b/tests/sav/error_defs_init_1alt2_alt1.res @@ -1 +0,0 @@ -alt/error_defs_init_1alt2_alt1.nit:26,2--5: Error: a property `init` is already defined in class `A` at line 18. diff --git a/tests/sav/error_defs_init_1alt2_alt2.res b/tests/sav/error_defs_init_1alt2_alt2.res index c9e3a71..b0df7ca 100644 --- a/tests/sav/error_defs_init_1alt2_alt2.res +++ b/tests/sav/error_defs_init_1alt2_alt2.res @@ -1 +1 @@ -alt/error_defs_init_1alt2_alt2.nit:27,2--5: Error: a property `init` is already defined in class `A` at line 18. +alt/error_defs_init_1alt2_alt2.nit:27,2--5: Error: a property `defaultinit` is already defined in class `A` at line 18. diff --git a/tests/sav/error_init_auto.res b/tests/sav/error_init_auto.res index a466472..b4fea22 100644 --- a/tests/sav/error_init_auto.res +++ b/tests/sav/error_init_auto.res @@ -1,4 +1,4 @@ -error_init_auto.nit:34,5--7: Error: expected 1 argument(s) for `init(x: Int)`; got 0. See introduction at `core::Object::init`. -error_init_auto.nit:36,5--7: Error: expected 1 argument(s) for `init(x: Int)`; got 2. See introduction at `core::Object::init`. -error_init_auto.nit:37,5--7: Error: expected 1 argument(s) for `init(x: Int)`; got 3. See introduction at `core::Object::init`. +error_init_auto.nit:34,5--7: Error: expected 1 argument(s) for `defaultinit(x: Int)`; got 0. See introduction at `error_init_auto::A::defaultinit`. +error_init_auto.nit:36,5--7: Error: expected 1 argument(s) for `defaultinit(x: Int)`; got 2. See introduction at `error_init_auto::A::defaultinit`. +error_init_auto.nit:37,5--7: Error: expected 1 argument(s) for `defaultinit(x: Int)`; got 3. See introduction at `error_init_auto::A::defaultinit`. error_init_auto.nit:38,11--13: Error: method `foo` does not exists in `A`. diff --git a/tests/sav/error_init_auto_alt1.res b/tests/sav/error_init_auto_alt1.res index 3356259..390923a 100644 --- a/tests/sav/error_init_auto_alt1.res +++ b/tests/sav/error_init_auto_alt1.res @@ -1,4 +1,4 @@ -alt/error_init_auto_alt1.nit:35,5--7: Error: expected 0 argument(s) for `init`; got 1. See introduction at `core::Object::init`. -alt/error_init_auto_alt1.nit:36,5--7: Error: expected 0 argument(s) for `init`; got 2. See introduction at `core::Object::init`. -alt/error_init_auto_alt1.nit:37,5--7: Error: expected 0 argument(s) for `init`; got 3. See introduction at `core::Object::init`. +alt/error_init_auto_alt1.nit:35,5--7: Error: expected 0 argument(s) for `defaultinit`; got 1. See introduction at `error_init_auto_alt1::A::defaultinit`. +alt/error_init_auto_alt1.nit:36,5--7: Error: expected 0 argument(s) for `defaultinit`; got 2. See introduction at `error_init_auto_alt1::A::defaultinit`. +alt/error_init_auto_alt1.nit:37,5--7: Error: expected 0 argument(s) for `defaultinit`; got 3. See introduction at `error_init_auto_alt1::A::defaultinit`. alt/error_init_auto_alt1.nit:38,11--13: Error: method `foo` does not exists in `A`. diff --git a/tests/sav/error_init_auto_alt2.res b/tests/sav/error_init_auto_alt2.res index 16c9ed4..d43fffd 100644 --- a/tests/sav/error_init_auto_alt2.res +++ b/tests/sav/error_init_auto_alt2.res @@ -1,4 +1,4 @@ -alt/error_init_auto_alt2.nit:34,5--7: Error: expected 2 argument(s) for `init(x, y: Int)`; got 0. See introduction at `core::Object::init`. -alt/error_init_auto_alt2.nit:35,5--7: Error: expected 2 argument(s) for `init(x, y: Int)`; got 1. See introduction at `core::Object::init`. -alt/error_init_auto_alt2.nit:37,5--7: Error: expected 2 argument(s) for `init(x, y: Int)`; got 3. See introduction at `core::Object::init`. +alt/error_init_auto_alt2.nit:34,5--7: Error: expected 2 argument(s) for `defaultinit(x, y: Int)`; got 0. See introduction at `error_init_auto_alt2::A::defaultinit`. +alt/error_init_auto_alt2.nit:35,5--7: Error: expected 2 argument(s) for `defaultinit(x, y: Int)`; got 1. See introduction at `error_init_auto_alt2::A::defaultinit`. +alt/error_init_auto_alt2.nit:37,5--7: Error: expected 2 argument(s) for `defaultinit(x, y: Int)`; got 3. See introduction at `error_init_auto_alt2::A::defaultinit`. alt/error_init_auto_alt2.nit:38,11--13: Error: method `foo` does not exists in `A`. diff --git a/tests/sav/error_init_auto_alt3.res b/tests/sav/error_init_auto_alt3.res index 61e44f6..8a30015 100644 --- a/tests/sav/error_init_auto_alt3.res +++ b/tests/sav/error_init_auto_alt3.res @@ -1,4 +1,4 @@ -alt/error_init_auto_alt3.nit:34,5--7: Error: expected 1 argument(s) for `init(xx: Int)`; got 0. See introduction at `error_init_auto_alt3::A::init`. -alt/error_init_auto_alt3.nit:36,5--7: Error: expected 1 argument(s) for `init(xx: Int)`; got 2. See introduction at `error_init_auto_alt3::A::init`. -alt/error_init_auto_alt3.nit:37,5--7: Error: expected 1 argument(s) for `init(xx: Int)`; got 3. See introduction at `error_init_auto_alt3::A::init`. +alt/error_init_auto_alt3.nit:34,5--7: Error: expected 1 argument(s) for `defaultinit(xx: Int)`; got 0. See introduction at `error_init_auto_alt3::A::defaultinit`. +alt/error_init_auto_alt3.nit:36,5--7: Error: expected 1 argument(s) for `defaultinit(xx: Int)`; got 2. See introduction at `error_init_auto_alt3::A::defaultinit`. +alt/error_init_auto_alt3.nit:37,5--7: Error: expected 1 argument(s) for `defaultinit(xx: Int)`; got 3. See introduction at `error_init_auto_alt3::A::defaultinit`. alt/error_init_auto_alt3.nit:38,11--13: Error: method `foo` does not exists in `A`. diff --git a/tests/sav/error_init_auto_alt4.res b/tests/sav/error_init_auto_alt4.res index 1e2a53a..8d39276 100644 --- a/tests/sav/error_init_auto_alt4.res +++ b/tests/sav/error_init_auto_alt4.res @@ -1,3 +1,3 @@ -alt/error_init_auto_alt4.nit:34,5--7: Error: expected 1 argument(s) for `init(x: Int)`; got 0. See introduction at `core::Object::init`. -alt/error_init_auto_alt4.nit:36,5--7: Error: expected 1 argument(s) for `init(x: Int)`; got 2. See introduction at `core::Object::init`. -alt/error_init_auto_alt4.nit:37,5--7: Error: expected 1 argument(s) for `init(x: Int)`; got 3. See introduction at `core::Object::init`. +alt/error_init_auto_alt4.nit:34,5--7: Error: expected 1 argument(s) for `defaultinit(x: Int)`; got 0. See introduction at `error_init_auto_alt4::A::defaultinit`. +alt/error_init_auto_alt4.nit:36,5--7: Error: expected 1 argument(s) for `defaultinit(x: Int)`; got 2. See introduction at `error_init_auto_alt4::A::defaultinit`. +alt/error_init_auto_alt4.nit:37,5--7: Error: expected 1 argument(s) for `defaultinit(x: Int)`; got 3. See introduction at `error_init_auto_alt4::A::defaultinit`. diff --git a/tests/sav/nit_args9.res b/tests/sav/nit_args9.res index 1a3a40c..4181eb7 100644 --- a/tests/sav/nit_args9.res +++ b/tests/sav/nit_args9.res @@ -16,6 +16,7 @@ test_keep_going.nit:44,18--21: Error: method `fail` does not exists in `Sys`. var a = new Sys.fail ^ +Errors: 6. Warnings: 0. 1 2 3 diff --git a/tests/sav/nitcatalog_args1.res b/tests/sav/nitcatalog_args1.res index 040f43c..6cca568 100644 --- a/tests/sav/nitcatalog_args1.res +++ b/tests/sav/nitcatalog_args1.res @@ -84,7 +84,7 @@

Quality

Tags

@@ -95,7 +95,7 @@ none

Contributors

diff --git a/tests/sav/nitdoc_args1.res b/tests/sav/nitdoc_args1.res index a7326d6..7fd3669 100644 --- a/tests/sav/nitdoc_args1.res +++ b/tests/sav/nitdoc_args1.res @@ -1,13 +1,13 @@ Parsing code... Generating documentation pages... Documentation produced in `out/nitdoc_args1.write` -Generated 22/22 pages +Generated 27/27 pages PageHome: 1 PageMPackage: 2 PageMGroup: 2 PageMModule: 2 PageMClass: 5 - PageMProperty: 10 + PageMProperty: 15 PagePerson: 0 PageTag: 0 class_module_95d0_58d_58dInt.html @@ -25,15 +25,20 @@ module_module_95d0_58d_58dmodule_95d0.html module_module_95d1_58d_58dmodule_95d1.html package_module_95d0.html package_module_95d1.html +property_module_95d0_58d_58dInt_58d_58ddefaultinit.html +property_module_95d0_58d_58dObject_58d_58ddefaultinit.html property_module_95d0_58d_58dObject_58d_58dinit.html property_module_95d0_58d_58dObject_58d_58doutput.html property_module_95d0_58d_58dObject_58d_58dprint.html +property_module_95d0_58d_58dSys_58d_58ddefaultinit.html property_module_95d0_58d_58dSys_58d_58dmain.html property_module_95d1_58d_58dA_58d_58da1.html property_module_95d1_58d_58dA_58d_58da12.html property_module_95d1_58d_58dA_58d_58da123.html property_module_95d1_58d_58dA_58d_58da13.html +property_module_95d1_58d_58dA_58d_58ddefaultinit.html property_module_95d1_58d_58dB_58d_58dall2.html property_module_95d1_58d_58dB_58d_58dall25.html +property_module_95d1_58d_58dB_58d_58ddefaultinit.html quicksearch-list.js vendors/ diff --git a/tests/sav/nitdoc_args2.res b/tests/sav/nitdoc_args2.res index 268190c..6d7fcc3 100644 --- a/tests/sav/nitdoc_args2.res +++ b/tests/sav/nitdoc_args2.res @@ -1,13 +1,13 @@ Parsing code... Generating documentation pages... Documentation produced in `out/nitdoc_args2.write` -Generated 28/28 pages +Generated 31/31 pages PageHome: 1 PageMPackage: 1 PageMGroup: 1 PageMModule: 1 PageMClass: 7 - PageMProperty: 17 + PageMProperty: 20 PagePerson: 0 PageTag: 0 class_base_attr_nullable_58d_58dBar.html @@ -26,19 +26,22 @@ module_base_attr_nullable_58d_58dbase_attr_nullable.html package_base_attr_nullable.html property_base_attr_nullable_58d_58dBar_58d_58da3.html property_base_attr_nullable_58d_58dBar_58d_58da3_61d.html +property_base_attr_nullable_58d_58dBar_58d_58ddefaultinit.html property_base_attr_nullable_58d_58dFoo_58d_58da1.html property_base_attr_nullable_58d_58dFoo_58d_58da1_61d.html property_base_attr_nullable_58d_58dFoo_58d_58da2.html property_base_attr_nullable_58d_58dFoo_58d_58da2_61d.html +property_base_attr_nullable_58d_58dFoo_58d_58ddefaultinit.html property_base_attr_nullable_58d_58dFoo_58d_58dnop.html property_base_attr_nullable_58d_58dFoo_58d_58drun.html property_base_attr_nullable_58d_58dFoo_58d_58drun_other.html property_base_attr_nullable_58d_58dInt_58d_58d_43d.html property_base_attr_nullable_58d_58dInt_58d_58doutput.html -property_base_attr_nullable_58d_58dInteger_58d_58dinit.html +property_base_attr_nullable_58d_58dInteger_58d_58ddefaultinit.html property_base_attr_nullable_58d_58dInteger_58d_58doutput.html property_base_attr_nullable_58d_58dInteger_58d_58dval.html property_base_attr_nullable_58d_58dInteger_58d_58dval_61d.html +property_base_attr_nullable_58d_58dObject_58d_58ddefaultinit.html property_base_attr_nullable_58d_58dObject_58d_58dinit.html property_base_attr_nullable_58d_58dSys_58d_58dmain.html quicksearch-list.js diff --git a/tests/sav/nitdoc_args3.res b/tests/sav/nitdoc_args3.res index 105d27c..c61e127 100644 --- a/tests/sav/nitdoc_args3.res +++ b/tests/sav/nitdoc_args3.res @@ -1,13 +1,13 @@ Parsing code... Generating documentation pages... Documentation produced in `out/nitdoc_args3.write` -Generated 28/28 pages +Generated 31/31 pages PageHome: 1 PageMPackage: 1 PageMGroup: 1 PageMModule: 1 PageMClass: 7 - PageMProperty: 17 + PageMProperty: 20 PagePerson: 0 PageTag: 0 class_base_attr_nullable_58d_58dBar.html @@ -26,19 +26,22 @@ module_base_attr_nullable_58d_58dbase_attr_nullable.html package_base_attr_nullable.html property_base_attr_nullable_58d_58dBar_58d_58da3.html property_base_attr_nullable_58d_58dBar_58d_58da3_61d.html +property_base_attr_nullable_58d_58dBar_58d_58ddefaultinit.html property_base_attr_nullable_58d_58dFoo_58d_58da1.html property_base_attr_nullable_58d_58dFoo_58d_58da1_61d.html property_base_attr_nullable_58d_58dFoo_58d_58da2.html property_base_attr_nullable_58d_58dFoo_58d_58da2_61d.html +property_base_attr_nullable_58d_58dFoo_58d_58ddefaultinit.html property_base_attr_nullable_58d_58dFoo_58d_58dnop.html property_base_attr_nullable_58d_58dFoo_58d_58drun.html property_base_attr_nullable_58d_58dFoo_58d_58drun_other.html property_base_attr_nullable_58d_58dInt_58d_58d_43d.html property_base_attr_nullable_58d_58dInt_58d_58doutput.html -property_base_attr_nullable_58d_58dInteger_58d_58dinit.html +property_base_attr_nullable_58d_58dInteger_58d_58ddefaultinit.html property_base_attr_nullable_58d_58dInteger_58d_58doutput.html property_base_attr_nullable_58d_58dInteger_58d_58dval.html property_base_attr_nullable_58d_58dInteger_58d_58dval_61d.html +property_base_attr_nullable_58d_58dObject_58d_58ddefaultinit.html property_base_attr_nullable_58d_58dObject_58d_58dinit.html property_base_attr_nullable_58d_58dSys_58d_58dmain.html quicksearch-list.js diff --git a/tests/sav/nitdoc_args4.res b/tests/sav/nitdoc_args4.res index 3be4a55..dfe20dd 100644 --- a/tests/sav/nitdoc_args4.res +++ b/tests/sav/nitdoc_args4.res @@ -1,11 +1,11 @@ Parsing code... Generating documentation pages... -Generated 111/111 pages +Generated 134/134 pages PageHome: 1 PageMPackage: 2 PageMGroup: 7 PageMModule: 10 PageMClass: 22 - PageMProperty: 61 + PageMProperty: 84 PagePerson: 6 PageTag: 2 diff --git a/tests/sav/nitlight_args1.res b/tests/sav/nitlight_args1.res index e7f3ab8..feb5de0 100644 --- a/tests/sav/nitlight_args1.res +++ b/tests/sav/nitlight_args1.res @@ -33,35 +33,31 @@ class B var val: Int - init(v: Int) - do - 7.output - self.val = v - end - fun run do val.output -end - -class C - var val1: Int - var val2: Int = 10 -end + init do 7.output + fun run do val.output +end + +class C + var val1: Int + var val2: Int = 10 +end + +fun foo do 2.output +fun bar(i: Int) do i.output +fun baz: Int do return 4 -fun foo do 2.output -fun bar(i: Int) do i.output -fun baz: Int do return 4 - -1.output -foo -bar(3) -baz.output - -var a = new A -a.run - -var b = new B(8) -b.run - -var c = new C(9) -c.val1.output -c.val2.output +1.output +foo +bar(3) +baz.output + +var a = new A +a.run + +var b = new B(8) +b.run + +var c = new C(9) +c.val1.output +c.val2.output \ No newline at end of file diff --git a/tests/sav/nitlight_args2.res b/tests/sav/nitlight_args2.res index 204c980..a4316b9 100644 --- a/tests/sav/nitlight_args2.res +++ b/tests/sav/nitlight_args2.res @@ -73,37 +73,33 @@ class B var val: Int - init(v: Int) - do - 7.output - self.val = v - end - fun run do val.output -end - -class C - var val1: Int - var val2: Int = 10 -end + init do 7.output + fun run do val.output +end + +class C + var val1: Int + var val2: Int = 10 +end + +fun foo do 2.output +fun bar(i: Int) do i.output +fun baz: Int do return 4 -fun foo do 2.output -fun bar(i: Int) do i.output -fun baz: Int do return 4 - -1.output -foo -bar(3) -baz.output - -var a = new A -a.run - -var b = new B(8) -b.run - -var c = new C(9) -c.val1.output -c.val2.output +1.output +foo +bar(3) +baz.output + +var a = new A +a.run + +var b = new B(8) +b.run + +var c = new C(9) +c.val1.output +c.val2.output \ No newline at end of file diff --git a/tests/sav/nitlight_args3.res b/tests/sav/nitlight_args3.res index f1c2d87..af3ce32 100644 --- a/tests/sav/nitlight_args3.res +++ b/tests/sav/nitlight_args3.res @@ -1,10 +1,10 @@ - 7.output - self.val = v - end - fun run do val.output -end - -class C - var val1: Int - var val2: Int = 10 - \ No newline at end of file +end + +class C + var val1: Int + var val2: Int = 10 +end + +fun foo do 2.output +fun bar(i: Int) do i.output + \ No newline at end of file diff --git a/tests/sav/nitlight_args4.res b/tests/sav/nitlight_args4.res index 8bb2bc8..6515ef7 100644 --- a/tests/sav/nitlight_args4.res +++ b/tests/sav/nitlight_args4.res @@ -33,11 +33,7 @@ end class B var val: Int - init(v: Int) - do - 7.output - self.val = v - end + init do 7.output fun run do val.output end diff --git a/tests/sav/nitlight_args5.res b/tests/sav/nitlight_args5.res index 90f6ed3..7b59e9a 100644 --- a/tests/sav/nitlight_args5.res +++ b/tests/sav/nitlight_args5.res @@ -73,37 +73,33 @@ class B var val: Int - init(v: Int) - do - 7.output - self.val = v - end - fun run do val.output -end - -class C - var val1: Int - var val2: Int = 10 -end + init do 7.output + fun run do val.output +end + +class C + var val1: Int + var val2: Int = 10 +end + +fun foo do 2.output +fun bar(i: Int) do i.output +fun baz: Int do return 4 -fun foo do 2.output -fun bar(i: Int) do i.output -fun baz: Int do return 4 - -1.output -foo -bar(3) -baz.output - -var a = new A -a.run - -var b = new B(8) -b.run - -var c = new C(9) -c.val1.output -c.val2.output +1.output +foo +bar(3) +baz.output + +var a = new A +a.run + +var b = new B(8) +b.run + +var c = new C(9) +c.val1.output +c.val2.output \ No newline at end of file diff --git a/tests/sav/nitmetrics_args1.res b/tests/sav/nitmetrics_args1.res index 139d036..29e31bd 100644 --- a/tests/sav/nitmetrics_args1.res +++ b/tests/sav/nitmetrics_args1.res @@ -1,74 +1,73 @@ *** METRICS *** --- AST Metrics --- ## All nodes of the AST - population: 52 + population: 49 minimum value: 1 - maximum value: 40 - total value: 304 - average value: 5.84 + maximum value: 37 + total value: 286 + average value: 5.83 distribution: - <=1: sub-population=16 (30.76%); cumulated value=16 (5.26%) - <=2: sub-population=5 (9.61%); cumulated value=10 (3.28%) - <=4: sub-population=9 (17.30%); cumulated value=28 (9.21%) - <=8: sub-population=12 (23.07%); cumulated value=76 (25.00%) - <=16: sub-population=5 (9.61%); cumulated value=59 (19.40%) - <=32: sub-population=4 (7.69%); cumulated value=75 (24.67%) - <=64: sub-population=1 (1.92%); cumulated value=40 (13.15%) + <=1: sub-population=15 (30.61%); cumulated value=15 (5.24%) + <=2: sub-population=3 (6.12%); cumulated value=6 (2.09%) + <=4: sub-population=12 (24.48%); cumulated value=40 (13.98%) + <=8: sub-population=10 (20.40%); cumulated value=67 (23.42%) + <=16: sub-population=4 (8.16%); cumulated value=48 (16.78%) + <=32: sub-population=4 (8.16%); cumulated value=73 (25.52%) + <=64: sub-population=1 (2.04%); cumulated value=37 (12.93%) list: - TId: 40 (13.15%) - APublicVisibility: 19 (6.25%) - AListExprs: 19 (6.25%) - AQid: 19 (6.25%) - ACallExpr: 18 (5.92%) - TClassid: 15 (4.93%) - AQclassid: 15 (4.93%) - TInteger: 10 (3.28%) - AIntegerExpr: 10 (3.28%) - AType: 9 (2.96%) + TId: 37 (12.93%) + APublicVisibility: 19 (6.64%) + ACallExpr: 18 (6.29%) + AQid: 18 (6.29%) + AListExprs: 18 (6.29%) + AQclassid: 14 (4.89%) + TClassid: 14 (4.89%) + TInteger: 10 (3.49%) + AIntegerExpr: 10 (3.49%) + ASignature: 8 (2.79%) ... - AAnnotation: 1 (0.32%) - AAnnotations: 1 (0.32%) - AReturnExpr: 1 (0.32%) - TKwreturn: 1 (0.32%) - AInterfaceClasskind: 1 (0.32%) - TKwinterface: 1 (0.32%) - ANoImport: 1 (0.32%) - AMainMethPropdef: 1 (0.32%) - AMainClassdef: 1 (0.32%) - TKwimport: 1 (0.32%) + TKwreturn: 1 (0.34%) + AAnnotation: 1 (0.34%) + AParam: 1 (0.34%) + AMainMethPropdef: 1 (0.34%) + AInterfaceClasskind: 1 (0.34%) + TKwinterface: 1 (0.34%) + ANoImport: 1 (0.34%) + ABlockExpr: 1 (0.34%) + AMainClassdef: 1 (0.34%) + TKwimport: 1 (0.34%) ## All identifiers of the AST - population: 20 + population: 19 minimum value: 1 maximum value: 11 - total value: 55 - average value: 2.75 + total value: 51 + average value: 2.68 distribution: - <=1: sub-population=3 (15.00%); cumulated value=3 (5.45%) - <=2: sub-population=12 (60.00%); cumulated value=24 (43.63%) - <=4: sub-population=3 (15.00%); cumulated value=10 (18.18%) - <=8: sub-population=1 (5.00%); cumulated value=7 (12.72%) - <=16: sub-population=1 (5.00%); cumulated value=11 (20.00%) + <=1: sub-population=3 (15.78%); cumulated value=3 (5.88%) + <=2: sub-population=12 (63.15%); cumulated value=24 (47.05%) + <=4: sub-population=2 (10.52%); cumulated value=7 (13.72%) + <=8: sub-population=1 (5.26%); cumulated value=6 (11.76%) + <=16: sub-population=1 (5.26%); cumulated value=11 (21.56%) list: - output: 11 (20.00%) - Int: 7 (12.72%) - run: 4 (7.27%) - c: 3 (5.45%) - val: 3 (5.45%) - i: 2 (3.63%) - bar: 2 (3.63%) - foo: 2 (3.63%) - val2: 2 (3.63%) - val1: 2 (3.63%) - C: 2 (3.63%) - v: 2 (3.63%) - baz: 2 (3.63%) - a: 2 (3.63%) - A: 2 (3.63%) - B: 2 (3.63%) - b: 2 (3.63%) - intern: 1 (1.81%) - Object: 1 (1.81%) - Bool: 1 (1.81%) + output: 11 (21.56%) + Int: 6 (11.76%) + run: 4 (7.84%) + c: 3 (5.88%) + baz: 2 (3.92%) + i: 2 (3.92%) + bar: 2 (3.92%) + val2: 2 (3.92%) + val1: 2 (3.92%) + C: 2 (3.92%) + val: 2 (3.92%) + B: 2 (3.92%) + a: 2 (3.92%) + A: 2 (3.92%) + foo: 2 (3.92%) + b: 2 (3.92%) + intern: 1 (1.96%) + Object: 1 (1.96%) + Bool: 1 (1.96%) --- Detection of variance constraints on formal parameter types --- -- Generic classes -- list: @@ -221,41 +220,41 @@ Number of refined classes: 0 (0.00%) Average number of class refinments by classes: 0.00 Average number of class refinments by refined classes: na -Number of properties: 18 - Number of MAttribute: 3 (16.66%) - Number of MMethod: 15 (83.33%) +Number of properties: 21 + Number of MAttribute: 3 (14.28%) + Number of MMethod: 18 (85.71%) -Number of property definitions: 20 -Number of redefined properties: 1 (5.55%) -Average number of property redefinitions by property: 0.11 +Number of property definitions: 23 +Number of redefined properties: 1 (4.76%) +Average number of property redefinitions by property: 0.09 Average number of property redefinitions by redefined property: 2.00 --- Explicit vs. Implicit Self --- -Total number of self: 5 -Total number of implicit self: 4 (80.00%) +Total number of self: 4 +Total number of implicit self: 4 (100.00%) --- Construction of tables --- Number of runtime classes: 6 (excluding interfaces and abstract classes) Average number of composing class definition by runtime class: 2.00 -Total size of tables (classes and instances): 23 (not including stuff like info for subtyping or call-next-method) -Average size of table by runtime class: 3.83 -Values never redefined: 17 (73.91%) +Total size of tables (classes and instances): 31 (not including stuff like info for subtyping or call-next-method) +Average size of table by runtime class: 5.16 +Values never redefined: 25 (80.64%) generating package_hierarchy.dot generating module_hierarchy.dot --- Metrics of the explitic static types --- -Total number of explicit static types: 9 +Total number of explicit static types: 8 Statistics of type usage: population: 4 minimum value: 1 - maximum value: 6 - total value: 9 - average value: 2.25 + maximum value: 5 + total value: 8 + average value: 2.00 distribution: - <=1: sub-population=3 (75.00%); cumulated value=3 (33.33%) - <=8: sub-population=1 (25.00%); cumulated value=6 (66.66%) + <=1: sub-population=3 (75.00%); cumulated value=3 (37.50%) + <=8: sub-population=1 (25.00%); cumulated value=5 (62.50%) list: - Int: 6 (66.66%) - C: 1 (11.11%) - B: 1 (11.11%) - A: 1 (11.11%) + Int: 5 (62.50%) + C: 1 (12.50%) + B: 1 (12.50%) + A: 1 (12.50%) # MClasses metrics @@ -292,11 +291,11 @@ Statistics of type usage: std: 0.926 sum: 6 cnbp: number of accessible properties (inherited + local) - avg: 3.0 - max: C (7) - min: Object (1) - std: 2.36 - sum: 24 + avg: 4.0 + max: C (9) + min: Object (2) + std: 2.591 + sum: 33 cnba: number of accessible attributes (inherited + local) avg: 0.0 max: C (2) @@ -304,17 +303,17 @@ Statistics of type usage: std: 0.845 sum: 3 cnbi: number of accessible constructors (inherited + local) - avg: 1.0 - max: B (2) - min: Object (1) - std: 0.378 - sum: 8 + avg: 2.0 + max: A (3) + min: Object (2) + std: 0.655 + sum: 17 cnbm: number of accessible methods (inherited + local) - avg: 3.0 - max: B (5) - min: Object (1) - std: 1.773 - sum: 21 + avg: 4.0 + max: C (7) + min: Object (2) + std: 1.927 + sum: 30 cnbv: number of accessible virtual types (inherited + local) avg: 0.0 max: Object (0) @@ -322,11 +321,11 @@ Statistics of type usage: std: 0.0 sum: 0 cnbip: number of introduced properties - avg: 2.0 - max: C (6) + avg: 3.0 + max: C (7) min: Bool (0) std: 2.268 - sum: 18 + sum: 21 cnbrp: number of redefined properties avg: 0.0 max: A (1) @@ -334,11 +333,11 @@ Statistics of type usage: std: 0.535 sum: 2 cnbhp: number of inherited properties - avg: 0.0 - max: Bool (1) + avg: 1.0 + max: Bool (2) min: Object (0) - std: 0.926 - sum: 6 + std: 1.0 + sum: 12 ## global metrics cnoa: number of ancestor classes @@ -372,11 +371,11 @@ Statistics of type usage: std: 0.926 sum: 6 cnbp: number of accessible properties (inherited + local) - avg: 3.0 - max: C (7) - min: Object (1) - std: 2.36 - sum: 24 + avg: 4.0 + max: C (9) + min: Object (2) + std: 2.591 + sum: 33 cnba: number of accessible attributes (inherited + local) avg: 0.0 max: C (2) @@ -384,17 +383,17 @@ Statistics of type usage: std: 0.845 sum: 3 cnbi: number of accessible constructors (inherited + local) - avg: 1.0 - max: B (2) - min: Object (1) - std: 0.378 - sum: 8 + avg: 2.0 + max: A (3) + min: Object (2) + std: 0.655 + sum: 17 cnbm: number of accessible methods (inherited + local) - avg: 3.0 - max: B (5) - min: Object (1) - std: 1.773 - sum: 21 + avg: 4.0 + max: C (7) + min: Object (2) + std: 1.927 + sum: 30 cnbv: number of accessible virtual types (inherited + local) avg: 0.0 max: Object (0) @@ -402,11 +401,11 @@ Statistics of type usage: std: 0.0 sum: 0 cnbip: number of introduced properties - avg: 2.0 - max: C (6) + avg: 3.0 + max: C (7) min: Bool (0) std: 2.268 - sum: 18 + sum: 21 cnbrp: number of redefined properties avg: 0.0 max: A (1) @@ -414,11 +413,11 @@ Statistics of type usage: std: 0.535 sum: 2 cnbhp: number of inherited properties - avg: 0.0 - max: Bool (1) + avg: 1.0 + max: Bool (2) min: Object (0) - std: 0.926 - sum: 6 + std: 1.0 + sum: 12 # MModules metrics @@ -738,27 +737,27 @@ Warning: no source file for `base_simple3` sum: 0.143 # Mendel metrics - large mclasses (threshold: 3.915) + large mclasses (threshold: 4.915) + B: 5 C: 5 - B: 4 - Sys: 4 - budding mclasses (threshold: 5.033) - blooming mclasses (threshold: 21.874) - C: 25.0 + budding mclasses (threshold: 3.231) + C: 3.5 + blooming mclasses (threshold: 15.285) + C: 17.5 --- Detection of the usage of covariance static type conformance --- -- Total -- - Kinds of the subtype - list: - primitive type: 6 (100.00%) - total: 6 + primitive type: 5 (100.00%) + total: 5 - Variance - list: - monomorph: 6 (100.00%) - total: 6 + monomorph: 5 (100.00%) + total: 5 - Classes of the subtype - list: - Int: 6 (100.00%) - total: 6 + Int: 5 (100.00%) + total: 5 -- On covariance only -- - Specific covariance case explanations - list: @@ -815,7 +814,7 @@ Warning: no source file for `base_simple3` cnbna: number of accessible nullable attributes (inherited + local) -- nothing sum: 0 --- Sends on Nullable Receiver --- -Total number of sends: 19 +Total number of sends: 18 Number of sends on a unsafe nullable receiver: 0 (0.00%) Number of sends on a safe nullable receiver: 0 (0.00%) Number of buggy sends (cannot determine the type of the receiver): 0 (0.00%) @@ -848,17 +847,17 @@ Number of buggy sends (cannot determine the type of the receiver): 0 (0.00%) std: 0.0 sum: 17 mnlm: number of live methods in a mmodule - avg: 14.0 - max: base_simple3 (14) - min: base_simple3 (14) - std: 0.0 - sum: 14 - mnlmd: number of live method definitions in a mmodule avg: 16.0 max: base_simple3 (16) min: base_simple3 (16) std: 0.0 sum: 16 + mnlmd: number of live method definitions in a mmodule + avg: 18.0 + max: base_simple3 (18) + min: base_simple3 (18) + std: 0.0 + sum: 18 mnldd: number of dead method definitions in a mmodule avg: 0.0 max: base_simple3 (0) @@ -901,49 +900,49 @@ Number of buggy sends (cannot determine the type of the receiver): 0 (0.00%) sum: 0 ## Callsites -* 23 live callsites +* 21 live callsites MMethodDef locally designated (by number of CallSites) - population: 14 + population: 12 minimum value: 1 maximum value: 10 - total value: 23 - average value: 1.64 + total value: 21 + average value: 1.75 distribution: - <=1: sub-population=13 (92.85%); cumulated value=13 (56.52%) - <=16: sub-population=1 (7.14%); cumulated value=10 (43.47%) + <=1: sub-population=11 (91.66%); cumulated value=11 (52.38%) + <=16: sub-population=1 (8.33%); cumulated value=10 (47.61%) list: - base_simple3$Int$output: 10 (43.47%) - base_simple3$B$val: 1 (4.34%) - base_simple3$B$val=: 1 (4.34%) - base_simple3$Object$init: 1 (4.34%) - base_simple3$C$val2: 1 (4.34%) + base_simple3$Int$output: 10 (47.61%) + base_simple3$B$val: 1 (4.76%) + base_simple3$C$val2: 1 (4.76%) + base_simple3$C$val1: 1 (4.76%) + base_simple3$B$run: 1 (4.76%) ... - base_simple3$A$init: 1 (4.34%) - base_simple3$Sys$baz: 1 (4.34%) - base_simple3$Sys$bar: 1 (4.34%) - base_simple3$Sys$foo: 1 (4.34%) - base_simple3$C$init: 1 (4.34%) + base_simple3$A$defaultinit: 1 (4.76%) + base_simple3$Sys$baz: 1 (4.76%) + base_simple3$Sys$bar: 1 (4.76%) + base_simple3$Sys$foo: 1 (4.76%) + base_simple3$C$defaultinit: 1 (4.76%) MMethodDef possibly invoked at runtime (by number of CallSites) - population: 14 + population: 12 minimum value: 1 maximum value: 10 - total value: 23 - average value: 1.64 + total value: 21 + average value: 1.75 distribution: - <=1: sub-population=13 (92.85%); cumulated value=13 (56.52%) - <=16: sub-population=1 (7.14%); cumulated value=10 (43.47%) + <=1: sub-population=11 (91.66%); cumulated value=11 (52.38%) + <=16: sub-population=1 (8.33%); cumulated value=10 (47.61%) list: - base_simple3$Int$output: 10 (43.47%) - base_simple3$B$val: 1 (4.34%) - base_simple3$B$val=: 1 (4.34%) - base_simple3$Object$init: 1 (4.34%) - base_simple3$C$val2: 1 (4.34%) + base_simple3$Int$output: 10 (47.61%) + base_simple3$B$val: 1 (4.76%) + base_simple3$C$val2: 1 (4.76%) + base_simple3$C$val1: 1 (4.76%) + base_simple3$B$run: 1 (4.76%) ... - base_simple3$A$init: 1 (4.34%) - base_simple3$Sys$baz: 1 (4.34%) - base_simple3$Sys$bar: 1 (4.34%) - base_simple3$Sys$foo: 1 (4.34%) - base_simple3$C$init: 1 (4.34%) + base_simple3$A$defaultinit: 1 (4.76%) + base_simple3$Sys$baz: 1 (4.76%) + base_simple3$Sys$bar: 1 (4.76%) + base_simple3$Sys$foo: 1 (4.76%) + base_simple3$C$defaultinit: 1 (4.76%) class_hierarchy.dot classdef_hierarchy.dot inheritance/ diff --git a/tests/sav/nitsmells_args1.res b/tests/sav/nitsmells_args1.res index 6bf7b3d..251dd03 100644 --- a/tests/sav/nitsmells_args1.res +++ b/tests/sav/nitsmells_args1.res @@ -7,7 +7,7 @@ Long method: Average 1 lines -total_strengh has 2 lines -total_endurance has 2 lines -total_intelligence has 2 lines -Large class: 6 attributes and 18 methods (4.673A 6.923M Average) +Large class: 6 attributes and 18 methods (4.673A 6.858M Average) -------------------- Full name: test_prog$GameTest Location: test_prog/tests/test_game.nit:25,1--33,3 Feature envy: diff --git a/tests/sav/nitsmells_args3.res b/tests/sav/nitsmells_args3.res index 0ef08f3..972ccf1 100644 --- a/tests/sav/nitsmells_args3.res +++ b/tests/sav/nitsmells_args3.res @@ -2,4 +2,4 @@ --- Code Smells Metrics --- -------------------- Full name: TestNitsmells$LargeClass Location: TestNitsmells/LargeClass/largeclass.nit:20,1--55,3 -Large class: 18 attributes and 48 methods (17.515A 30.464M Average) +Large class: 18 attributes and 49 methods (17.515A 24.215M Average) diff --git a/tests/sav/nituml_args1.res b/tests/sav/nituml_args1.res index ecae7b8..8c7ce7d 100644 --- a/tests/sav/nituml_args1.res +++ b/tests/sav/nituml_args1.res @@ -13,10 +13,10 @@ digraph G { subgraph clusterbase_prot_sig2 { label = "base_prot_sig2" base_prot_sig2C [ - label = "{C|- _vpriA: nullable A\l- _vpriA2: A\l|- priA(a: A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l+ init()\l}"color="#58B26A" + label = "{C|- _vpriA: nullable A\l- _vpriA2: A\l|- priA(a: A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l+ init()\l+ defaultinit()\l}"color="#58B26A" ] base_prot_sig2D [ - label = "{D|- _vpubA: nullable A\l- _vpriA: nullable A\l- _vpubA2: A\l- _vpriA2: A\l|- pubA(a: A)\l- priA(a: A)\l- vpubA(): nullable A\l- vpubA=(vpubA: nullable A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l- vpubA2(): A\l- vpubA2=(vpubA2: A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l+ init()\l}"color="#58B26A" + label = "{D|- _vpubA: nullable A\l- _vpriA: nullable A\l- _vpubA2: A\l- _vpriA2: A\l|- pubA(a: A)\l- priA(a: A)\l- vpubA(): nullable A\l- vpubA=(vpubA: nullable A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l- vpubA2(): A\l- vpubA2=(vpubA2: A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l+ init()\l+ defaultinit()\l}"color="#58B26A" ] } } diff --git a/tests/sav/nituml_args2.res b/tests/sav/nituml_args2.res index 5a9488d..8fbab9b 100644 --- a/tests/sav/nituml_args2.res +++ b/tests/sav/nituml_args2.res @@ -13,7 +13,7 @@ digraph G { subgraph clusterbase_prot_sig2 { label = "base_prot_sig2" base_prot_sig2C [ - label = "{C||+ init()\l}"color="#58B26A" + label = "{C||+ init()\l+ defaultinit()\l}"color="#58B26A" ] } } diff --git a/tests/sav/nituml_args3.res b/tests/sav/nituml_args3.res index a5a027f..e30a297 100644 --- a/tests/sav/nituml_args3.res +++ b/tests/sav/nituml_args3.res @@ -12,31 +12,31 @@ digraph G { fontsize = 8 ] Object [ - label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ sys(): Sys\l+ init()\l}" + label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ sys(): Sys\l+ init()\l+ defaultinit()\l}" ] Sys [ - label = "{Sys||+ main()\l+ run()\l+ errno(): Int\l+ exit(exit_value: Int)\l+ is_windows(): Bool\l}" + label = "{Sys||+ main()\l+ run()\l+ errno(): Int\l+ exit(exit_value: Int)\l+ is_windows(): Bool\l+ defaultinit()\l}" ] Object -> Sys [dir=back arrowtail=open style=dashed]; Comparable [ - label = "{interface\nComparable||+ \<(other: OTHER): Bool\l+ \<=(other: OTHER): Bool\l+ \>=(other: OTHER): Bool\l+ \>(other: OTHER): Bool\l+ \<=\>(other: OTHER): Int\l+ is_between(c: OTHER, d: OTHER): Bool\l+ max(other: OTHER): OTHER\l+ min(c: OTHER): OTHER\l}" + label = "{interface\nComparable||+ \<(other: OTHER): Bool\l+ \<=(other: OTHER): Bool\l+ \>=(other: OTHER): Bool\l+ \>(other: OTHER): Bool\l+ \<=\>(other: OTHER): Int\l+ is_between(c: OTHER, d: OTHER): Bool\l+ max(other: OTHER): OTHER\l+ min(c: OTHER): OTHER\l+ defaultinit()\l}" ] Object -> Comparable [dir=back arrowtail=open style=dashed]; Discrete [ - label = "{interface\nDiscrete||+ successor(i: Int): OTHER\l+ predecessor(i: Int): OTHER\l+ distance(d: OTHER): Int\l}" + label = "{interface\nDiscrete||+ successor(i: Int): OTHER\l+ predecessor(i: Int): OTHER\l+ distance(d: OTHER): Int\l+ defaultinit()\l}" ] Comparable -> Discrete [dir=back arrowtail=open style=dashed]; Cloneable [ - label = "{interface\nCloneable||+ clone(): SELF\l}" + label = "{interface\nCloneable||+ clone(): SELF\l+ defaultinit()\l}" ] Object -> Cloneable [dir=back arrowtail=open style=dashed]; Numeric [ - label = "{interface\nNumeric||+ +(i: OTHER): OTHER\l+ -(i: OTHER): OTHER\l+ unary -(): OTHER\l+ *(i: OTHER): OTHER\l+ /(i: OTHER): OTHER\l+ to_i(): Int\l+ to_f(): Float\l+ to_b(): Byte\l+ is_zero(): Bool\l+ zero(): OTHER\l+ value_of(val: Numeric): OTHER\l}" + label = "{interface\nNumeric||+ +(i: OTHER): OTHER\l+ -(i: OTHER): OTHER\l+ unary -(): OTHER\l+ *(i: OTHER): OTHER\l+ /(i: OTHER): OTHER\l+ to_i(): Int\l+ to_f(): Float\l+ to_b(): Byte\l+ is_zero(): Bool\l+ zero(): OTHER\l+ value_of(val: Numeric): OTHER\l+ defaultinit()\l}" ] Comparable -> Numeric [dir=back arrowtail=open style=dashed]; @@ -68,32 +68,32 @@ Char [ Discrete -> Char [dir=back arrowtail=open style=dashed]; Pointer [ - label = "{Pointer||+ nul(): Pointer\l+ address_is_null(): Bool\l+ free()\l- native_equals(o: Pointer): Bool\l}" + label = "{Pointer||+ nul(): Pointer\l+ address_is_null(): Bool\l+ free()\l- native_equals(o: Pointer): Bool\l+ defaultinit()\l}" ] Object -> Pointer [dir=back arrowtail=open style=dashed]; Task [ - label = "{interface\nTask||+ main()\l}" + label = "{interface\nTask||+ main()\l+ defaultinit()\l}" ] Object -> Task [dir=back arrowtail=open style=dashed]; A [ - label = "{A|- _vpubA: nullable A\l- _vproA: nullable A\l- _vpriA: nullable A\l- _vpubA2: A\l- _vproA2: A\l- _vpriA2: A\l- _vpriB: nullable B\l- _vpriB2: B\l|+ pubA(a: A)\l# proA(a: A)\l- priA(a: A)\l+ pubA2(): A\l# proA2(): A\l- priA2(): A\l+ vpubA(): nullable A\l+ vpubA=(vpubA: nullable A)\l# vproA(): nullable A\l# vproA=(vproA: nullable A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l+ vpubA2(): A\l+ vpubA2=(vpubA2: A)\l# vproA2(): A\l# vproA2=(vproA2: A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l- priB(a: B)\l- priB2(): B\l- vpriB(): nullable B\l- vpriB=(vpriB: nullable B)\l- vpriB2(): B\l- vpriB2=(vpriB2: B)\l}" + label = "{A|- _vpubA: nullable A\l- _vproA: nullable A\l- _vpriA: nullable A\l- _vpubA2: A\l- _vproA2: A\l- _vpriA2: A\l- _vpriB: nullable B\l- _vpriB2: B\l|+ pubA(a: A)\l# proA(a: A)\l- priA(a: A)\l+ pubA2(): A\l# proA2(): A\l- priA2(): A\l+ vpubA(): nullable A\l+ vpubA=(vpubA: nullable A)\l# vproA(): nullable A\l# vproA=(vproA: nullable A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l+ vpubA2(): A\l+ vpubA2=(vpubA2: A)\l# vproA2(): A\l# vproA2=(vproA2: A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l- priB(a: B)\l- priB2(): B\l- vpriB(): nullable B\l- vpriB=(vpriB: nullable B)\l- vpriB2(): B\l- vpriB2=(vpriB2: B)\l+ defaultinit()\l}" ] Object -> A [dir=back arrowtail=open style=dashed]; B [ - label = "{B|- _vpubA: nullable A\l- _vpriA: nullable A\l- _vpubA2: A\l- _vpriA2: A\l- _vpubB: nullable B\l- _vpriB: nullable B\l- _vpubB2: B\l- _vpriB2: B\l|- pubA(a: A)\l- priA(a: A)\l- vpubA(): nullable A\l- vpubA=(vpubA: nullable A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l- vpubA2(): A\l- vpubA2=(vpubA2: A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l- pubB(a: B)\l- priB(a: B)\l- vpubB(): nullable B\l- vpubB=(vpubB: nullable B)\l- vpriB(): nullable B\l- vpriB=(vpriB: nullable B)\l- vpubB2(): B\l- vpubB2=(vpubB2: B)\l- vpriB2(): B\l- vpriB2=(vpriB2: B)\l}" + label = "{B|- _vpubA: nullable A\l- _vpriA: nullable A\l- _vpubA2: A\l- _vpriA2: A\l- _vpubB: nullable B\l- _vpriB: nullable B\l- _vpubB2: B\l- _vpriB2: B\l|- pubA(a: A)\l- priA(a: A)\l- vpubA(): nullable A\l- vpubA=(vpubA: nullable A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l- vpubA2(): A\l- vpubA2=(vpubA2: A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l- pubB(a: B)\l- priB(a: B)\l- vpubB(): nullable B\l- vpubB=(vpubB: nullable B)\l- vpriB(): nullable B\l- vpriB=(vpriB: nullable B)\l- vpubB2(): B\l- vpubB2=(vpubB2: B)\l- vpriB2(): B\l- vpriB2=(vpriB2: B)\l+ defaultinit()\l}" ] Object -> B [dir=back arrowtail=open style=dashed]; C [ - label = "{C|- _vpriA: nullable A\l- _vpriA2: A\l|- priA(a: A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l}" + label = "{C|- _vpriA: nullable A\l- _vpriA2: A\l|- priA(a: A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l+ defaultinit()\l}" ] Object -> C [dir=back arrowtail=open style=dashed]; D [ - label = "{D|- _vpubA: nullable A\l- _vpriA: nullable A\l- _vpubA2: A\l- _vpriA2: A\l|- pubA(a: A)\l- priA(a: A)\l- vpubA(): nullable A\l- vpubA=(vpubA: nullable A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l- vpubA2(): A\l- vpubA2=(vpubA2: A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l}" + label = "{D|- _vpubA: nullable A\l- _vpriA: nullable A\l- _vpubA2: A\l- _vpriA2: A\l|- pubA(a: A)\l- priA(a: A)\l- vpubA(): nullable A\l- vpubA=(vpubA: nullable A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l- vpubA2(): A\l- vpubA2=(vpubA2: A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l+ defaultinit()\l}" ] Object -> D [dir=back arrowtail=open style=dashed]; diff --git a/tests/sav/nituml_args4.res b/tests/sav/nituml_args4.res index f03123a..3248f5a 100644 --- a/tests/sav/nituml_args4.res +++ b/tests/sav/nituml_args4.res @@ -12,31 +12,31 @@ digraph G { fontsize = 8 ] Object [ - label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ sys(): Sys\l+ init()\l}" + label = "{interface\nObject||+ object_id(): Int\l+ is_same_type(other: Object): Bool\l+ is_same_instance(other: nullable Object): Bool\l+ ==(other: nullable Object): Bool\l+ !=(other: nullable Object): Bool\l+ output()\l+ output_class_name()\l+ hash(): Int\l+ sys(): Sys\l+ init()\l+ defaultinit()\l}" ] Sys [ - label = "{Sys||+ main()\l+ run()\l+ errno(): Int\l+ exit(exit_value: Int)\l+ is_windows(): Bool\l}" + label = "{Sys||+ main()\l+ run()\l+ errno(): Int\l+ exit(exit_value: Int)\l+ is_windows(): Bool\l+ defaultinit()\l}" ] Object -> Sys [dir=back arrowtail=open style=dashed]; Comparable [ - label = "{interface\nComparable||+ \<(other: OTHER): Bool\l+ \<=(other: OTHER): Bool\l+ \>=(other: OTHER): Bool\l+ \>(other: OTHER): Bool\l+ \<=\>(other: OTHER): Int\l+ is_between(c: OTHER, d: OTHER): Bool\l+ max(other: OTHER): OTHER\l+ min(c: OTHER): OTHER\l}" + label = "{interface\nComparable||+ \<(other: OTHER): Bool\l+ \<=(other: OTHER): Bool\l+ \>=(other: OTHER): Bool\l+ \>(other: OTHER): Bool\l+ \<=\>(other: OTHER): Int\l+ is_between(c: OTHER, d: OTHER): Bool\l+ max(other: OTHER): OTHER\l+ min(c: OTHER): OTHER\l+ defaultinit()\l}" ] Object -> Comparable [dir=back arrowtail=open style=dashed]; Discrete [ - label = "{interface\nDiscrete||+ successor(i: Int): OTHER\l+ predecessor(i: Int): OTHER\l+ distance(d: OTHER): Int\l}" + label = "{interface\nDiscrete||+ successor(i: Int): OTHER\l+ predecessor(i: Int): OTHER\l+ distance(d: OTHER): Int\l+ defaultinit()\l}" ] Comparable -> Discrete [dir=back arrowtail=open style=dashed]; Cloneable [ - label = "{interface\nCloneable||+ clone(): SELF\l}" + label = "{interface\nCloneable||+ clone(): SELF\l+ defaultinit()\l}" ] Object -> Cloneable [dir=back arrowtail=open style=dashed]; Numeric [ - label = "{interface\nNumeric||+ +(i: OTHER): OTHER\l+ -(i: OTHER): OTHER\l+ unary -(): OTHER\l+ *(i: OTHER): OTHER\l+ /(i: OTHER): OTHER\l+ to_i(): Int\l+ to_f(): Float\l+ to_b(): Byte\l+ is_zero(): Bool\l+ zero(): OTHER\l+ value_of(val: Numeric): OTHER\l}" + label = "{interface\nNumeric||+ +(i: OTHER): OTHER\l+ -(i: OTHER): OTHER\l+ unary -(): OTHER\l+ *(i: OTHER): OTHER\l+ /(i: OTHER): OTHER\l+ to_i(): Int\l+ to_f(): Float\l+ to_b(): Byte\l+ is_zero(): Bool\l+ zero(): OTHER\l+ value_of(val: Numeric): OTHER\l+ defaultinit()\l}" ] Comparable -> Numeric [dir=back arrowtail=open style=dashed]; @@ -68,22 +68,22 @@ Char [ Discrete -> Char [dir=back arrowtail=open style=dashed]; Pointer [ - label = "{Pointer||+ nul(): Pointer\l+ address_is_null(): Bool\l+ free()\l}" + label = "{Pointer||+ nul(): Pointer\l+ address_is_null(): Bool\l+ free()\l+ defaultinit()\l}" ] Object -> Pointer [dir=back arrowtail=open style=dashed]; Task [ - label = "{interface\nTask||+ main()\l}" + label = "{interface\nTask||+ main()\l+ defaultinit()\l}" ] Object -> Task [dir=back arrowtail=open style=dashed]; A [ - label = "{A||+ pubA(a: A)\l# proA(a: A)\l+ pubA2(): A\l# proA2(): A\l+ vpubA(): nullable A\l+ vpubA=(vpubA: nullable A)\l# vproA(): nullable A\l# vproA=(vproA: nullable A)\l+ vpubA2(): A\l+ vpubA2=(vpubA2: A)\l# vproA2(): A\l# vproA2=(vproA2: A)\l}" + label = "{A||+ pubA(a: A)\l# proA(a: A)\l+ pubA2(): A\l# proA2(): A\l+ vpubA(): nullable A\l+ vpubA=(vpubA: nullable A)\l# vproA(): nullable A\l# vproA=(vproA: nullable A)\l+ vpubA2(): A\l+ vpubA2=(vpubA2: A)\l# vproA2(): A\l# vproA2=(vproA2: A)\l+ defaultinit()\l}" ] Object -> A [dir=back arrowtail=open style=dashed]; C [ - label = "{C||}" + label = "{C||+ defaultinit()\l}" ] Object -> C [dir=back arrowtail=open style=dashed]; diff --git a/tests/sav/nitx_args2.res b/tests/sav/nitx_args2.res index 48c2f5f..36bf720 100644 --- a/tests/sav/nitx_args2.res +++ b/tests/sav/nitx_args2.res @@ -5,5 +5,5 @@ Documentation for `base_simple3::Sys::foo`: + base_simple3::Sys::foo fun foo - base_simple3.nit:49,1--19 + base_simple3.nit:45,1--19 diff --git a/tests/sav/nitx_args3.res b/tests/sav/nitx_args3.res index e191640..8c12ac9 100644 --- a/tests/sav/nitx_args3.res +++ b/tests/sav/nitx_args3.res @@ -7,7 +7,7 @@ Features for `base_simple3::base_simple3`: + base_simple3$B class B - base_simple3.nit:34,1--42,3 + base_simple3.nit:34,1--38,3 + base_simple3$Bool enum Bool @@ -15,7 +15,7 @@ Features for `base_simple3::base_simple3`: + base_simple3$C class C - base_simple3.nit:44,1--47,3 + base_simple3.nit:40,1--43,3 + base_simple3$Int enum Int @@ -27,5 +27,5 @@ Features for `base_simple3::base_simple3`: + base_simple3$Sys class Sys - base_simple3.nit:49,1--19 + base_simple3.nit:45,1--19 diff --git a/tests/sav/test_highlight_args1.res b/tests/sav/test_highlight_args1.res index c9cc4e2..43b741f 100644 --- a/tests/sav/test_highlight_args1.res +++ b/tests/sav/test_highlight_args1.res @@ -53,48 +53,44 @@
	var val: Int

base_simple3$B$val=

	var val: Int
-

base_simple3$B$init

-
	init(v: Int)
-	do
-		7.output
-		self.val = v
-	end
+

base_simple3$B$Object::init

+
	init do 7.output

base_simple3$B$run

-
	fun run do val.output
+
	fun run do val.output

base_simple3$C$_val1

-
	var val1: Int
+
	var val1: Int

base_simple3$C$val1

-
	var val1: Int
+
	var val1: Int

base_simple3$C$val1=

-
	var val1: Int
+
	var val1: Int

base_simple3$C$_val2

-
	var val2: Int = 10
+
	var val2: Int = 10

base_simple3$C$val2

-
	var val2: Int = 10
+
	var val2: Int = 10

base_simple3$C$val2=

-
	var val2: Int = 10
+
	var val2: Int = 10

base_simple3$Sys$foo

-
fun foo do 2.output
+
fun foo do 2.output

base_simple3$Sys$bar

-
fun bar(i: Int) do i.output
+
fun bar(i: Int) do i.output

base_simple3$Sys$baz

-
fun baz: Int do return 4
+
fun baz: Int do return 4

base_simple3$Sys$main

-
1.output
-foo
-bar(3)
-baz.output
-
-var a = new A
-a.run
-
-var b = new B(8)
-b.run
-
-var c = new C(9)
-c.val1.output
-c.val2.output
-

AST node: AModule at base_simple3.nit:17,1--66,13

+
1.output
+foo
+bar(3)
+baz.output
+
+var a = new A
+a.run
+
+var b = new B(8)
+b.run
+
+var c = new C(9)
+c.val1.output
+c.val2.output
+

AST node: AModule at base_simple3.nit:17,1--62,13

import end
 
 interface Object
@@ -114,37 +110,33 @@
 
 class B
 	var val: Int
-	init(v: Int)
-	do
-		7.output
-		self.val = v
-	end
-	fun run do val.output
-end
-
-class C
-	var val1: Int
-	var val2: Int = 10
-end
+	init do 7.output
+	fun run do val.output
+end
+
+class C
+	var val1: Int
+	var val2: Int = 10
+end
+
+fun foo do 2.output
+fun bar(i: Int) do i.output
+fun baz: Int do return 4
 
-fun foo do 2.output
-fun bar(i: Int) do i.output
-fun baz: Int do return 4
-
-1.output
-foo
-bar(3)
-baz.output
-
-var a = new A
-a.run
-
-var b = new B(8)
-b.run
-
-var c = new C(9)
-c.val1.output
-c.val2.output
+1.output +foo +bar(3) +baz.output + +var a = new A +a.run + +var b = new B(8) +b.run + +var c = new C(9) +c.val1.output +c.val2.output

AST node: ANoImport at base_simple3.nit:17,1--10

import end

AST node: APublicVisibility at base_simple3.nit:17,1

@@ -184,4 +176,35 @@
 is

AST node: AAnnotation at base_simple3.nit:26,16--21

 intern
-

AST node: AIdAtid at bas***TRUNCATED*** +

AST node: AIdAtid at base_simple3.nit:26,16--21

+
 intern
+

AST node: AConcreteClasskind at base_simple3.nit:29,1--5

+
class
+

AST node: TKwclass at base_simple3.nit:29,1--5

+
class
+

AST node: TKwinit at base_simple3.nit:30,2--5

+
	init
+

AST node: TKwdo at base_simple3.nit:30,7--8

+
 do
+

AST node: ACallExpr at base_simple3.nit:30,10--17

+
 5.output
+

AST node: AIntegerExpr at base_simple3.nit:30,10

+
 5
+

AST node: TInteger at base_simple3.nit:30,10

+
 5
+

AST node: AQid at base_simple3.nit:30,12--17

+
output
+

AST node: AListExprs at base_simple3.nit:30,17

+
+

AST node: AAttrPropdef at base_simple3.nit:35,2--13

+
	var val: Int
+

AST node: TKwvar at base_simple3.nit:35,2--4

+
	var
+

AST node: AType at base_simple3.nit:35,11--13

+
 Int
+

AST node: AImplicitSelfExpr at base_simple3.nit:37,13

+
+

AST node: TAssign at base_simple3.nit:42,16

+
 =
+

AST node: ATopClassdef at base_simple3.nit:45,1--19

+
fun foo do 2.