Replace `ensures` by `ensure` and `expects` `expect`
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
40 files changed:
# The implementation of the contracts is done in two visits.
#
# - First step, the visitor analyzes and constructs the 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 (expects, ensures).
+ # 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
#
# - Second step the visitor analyzes each `ASendExpr` to see
# if the callsite calls a method with a contract. If this is
end
# Verification if the construction of the contract is necessary.
end
# Verification if the construction of the contract is necessary.
- # Three cases are checked for `expects`:
+ # 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.
#
#
# - 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_expects(actual_mmodule: MModule): Bool
+ fun check_usage_expect(actual_mmodule: MModule): Bool
do
var main_package = mainmodule.mpackage
var actual_package = actual_mmodule.mpackage
do
var main_package = mainmodule.mpackage
var actual_package = actual_mmodule.mpackage
end
# Verification if the construction of the contract is necessary.
end
# Verification if the construction of the contract is necessary.
- # Two cases are checked for `ensures`:
+ # Two cases are checked for `ensure`:
#
# - Is the `--full-contract` option it's use?
# - Is the method is in the main package
#
#
# - Is the `--full-contract` option it's use?
# - Is the method is in the main package
#
- fun check_usage_ensures(actual_mmodule: MModule): Bool
+ fun check_usage_ensure(actual_mmodule: MModule): Bool
do
return toolcontext.opt_full_contract.value or mainmodule.mpackage == actual_mmodule.mpackage
end
do
return toolcontext.opt_full_contract.value or mainmodule.mpackage == actual_mmodule.mpackage
end
# Returns the conditions of annotation parameters in the form of and expr
# exemple:
# Returns the conditions of annotation parameters in the form of and expr
# exemple:
- # the contract ensures(true, i == 10, f >= 1.0)
+ # 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
# return this condition (true and i == 10 and f >= 1.0)
private fun construct_condition(v : ContractsVisitor): AExpr
do
super MContract
# Define the name of the contract
super MContract
# Define the name of the contract
- redef fun contract_name: String do return "expects"
+ redef fun contract_name: String do return "expect"
# Display warning if no contract is defined at introduction `expect`,
# because if no contract is defined at the introduction the added
# Display warning if no contract is defined at introduction `expect`,
# because if no contract is defined at the introduction the added
# ~~~nitish
# class A
# fun bar [...]
# ~~~nitish
# class A
# fun bar [...]
- # fun _bar_expects([...])
+ # fun _bar_expect([...])
# do
# [empty contract]
# end
# end
#
# redef class A
# do
# [empty contract]
# end
# end
#
# redef class A
- # redef fun bar is expects(contract_condition)
- # redef fun _bar_expects([...])
+ # redef fun bar is expect(contract_condition)
+ # redef fun _bar_expect([...])
# do
# if not (contract_condition) then super
# end
# do
# if not (contract_condition) then super
# end
-# The root of all contracts where the call is after the execution of the original method (`invariants` and `ensures`).
+# The root of all contracts where the call is after the execution of the original method (`invariant` and `ensure`).
abstract class BottomMContract
super MContract
abstract class BottomMContract
super MContract
super BottomMContract
# Define the name of the contract
super BottomMContract
# Define the name of the contract
- redef fun contract_name: String do return "ensures"
+ redef fun contract_name: String do return "ensure"
redef fun adapt_specific_msignature(m_signature: MSignature): MSignature
do
redef fun adapt_specific_msignature(m_signature: MSignature): MSignature
do
do
if self.mensure != null then return true
# build a new `MEnsure` contract
do
if self.mensure != null then return true
# build a new `MEnsure` contract
- self.mensure = new MEnsure(intro_mclassdef, "_ensures_{name}", intro_mclassdef.location, public_visibility)
+ self.mensure = new MEnsure(intro_mclassdef, "_ensure_{name}", intro_mclassdef.location, public_visibility)
do
if self.mexpect != null then return true
# build a new `MExpect` contract
do
if self.mexpect != null then return true
# build a new `MExpect` contract
- self.mexpect = new MExpect(intro_mclassdef, "_expects_{name}", intro_mclassdef.location, public_visibility)
+ self.mexpect = new MExpect(intro_mclassdef, "_expect_{name}", intro_mclassdef.location, public_visibility)
# Is the contract already defined in the context
#
# Exemple :
# Is the contract already defined in the context
#
# Exemple :
- # fun foo is expects([...]), expects([...])
+ # fun foo is expect([...]), expect([...])
- # Here `check_same_contract` display an error when the second expects is processed
+ # 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
do
if self.mclassdef.mpropdefs_by_property.has_key(mcontract) then
private fun check_same_contract(v: ContractsVisitor, n_annotation: AAnnotation ,mcontract: MContract): Bool
do
if self.mclassdef.mpropdefs_by_property.has_key(mcontract) then
# If this is the case, we built the appropriate contract.
private fun check_annotation(v: ContractsVisitor, n_annotation: AAnnotation)
do
# If this is the case, we built the appropriate contract.
private fun check_annotation(v: ContractsVisitor, n_annotation: AAnnotation)
do
- if n_annotation.name == "expects" then
- if not v.check_usage_expects(mpropdef.mclassdef.mmodule) then return
+ 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)
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 == "ensures" then
- if not v.check_usage_ensures(mpropdef.mclassdef.mmodule) then return
+ 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
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
class MyClass
fun foo(x: Int)
is
class MyClass
fun foo(x: Int)
is
- expects(x == 1)
- ensures(x > 0)
+ expect(x == 1)
+ ensure(x > 0)
class MyClass2
fun foo(bool: Bool)
is
class MyClass2
fun foo(bool: Bool)
is
- expects(not bool)
- ensures(not bool)
+ expect(not bool)
+ ensure(not bool)
do
if bool then print "Error"
end
do
if bool then print "Error"
end
# Verification if it's possible to define a contract in different context (abstract class, interface and class) and it's possible to inherit it.
class MyClass
# Verification if it's possible to define a contract in different context (abstract class, interface and class) and it's possible to inherit it.
class MyClass
- fun foo(x: Int, y: Float)is abstract, expects(x != 10)
+ fun foo(x: Int, y: Float)is abstract, expect(x != 10)
end
abstract class AbstractClass
end
abstract class AbstractClass
- fun bar(x: Int, y: Float)is abstract, expects(x >= 1), ensures(y == 10.0)
+ fun bar(x: Int, y: Float)is abstract, expect(x >= 1), ensure(y == 10.0)
- fun baz(x: Int, y: Float)is abstract, ensures(y <= 10.0, y == 42.0)
+ fun baz(x: Int, y: Float)is abstract, ensure(y <= 10.0, y == 42.0)
class MyClass
fun foo(x: Int)
is
class MyClass
fun foo(x: Int)
is
do
x=1
end
fun bar(x: Float): Bool
is
do
x=1
end
fun bar(x: Float): Bool
is
do
x=0
end
redef fun bar(x: Float)
is
do
x=0
end
redef fun bar(x: Float)
is
- expects(bar == 10)
- ensures(x > 0)
+ expect(bar == 10)
+ ensure(x > 0)
do
if bar != 10 then print "Error"
end
do
if bar != 10 then print "Error"
end
- expects(not self.baz)
- ensures(my_class.bar == 11)
+ expect(not self.baz)
+ ensure(my_class.bar == 11)
do
if baz then print "Error"
my_class.bar = 11
do
if baz then print "Error"
my_class.bar = 11
class MyClass
init construct(test: Int)
is
class MyClass
init construct(test: Int)
is
class MyClass
fun foo(x: Int)
is
class MyClass
fun foo(x: Int)
is
class MyClass2
fun foo(bool: Bool)
is
class MyClass2
fun foo(bool: Bool)
is
class MyClass
fun foo(x: Int)
is
class MyClass
fun foo(x: Int)
is
class MyClass
fun foo(x: Int, y: Float)
is
class MyClass
fun foo(x: Int, y: Float)
is
redef fun foo(x: Int, y: Float)
is
redef fun foo(x: Int, y: Float)
is
class MyClass
fun foo(x: Int): Int
is
class MyClass
fun foo(x: Int): Int
is
class MyClass
fun foo(x: Int): Bool
is
class MyClass
fun foo(x: Int): Bool
is
class MyClass
fun foo(x: Int, y: Float)
is
class MyClass
fun foo(x: Int, y: Float)
is
redef fun foo(x: Int, y: Float)
is
redef fun foo(x: Int, y: Float)
is
- expects(bar_no_return)
- ensures(assert x == 1)
+ expect(bar_no_return)
+ ensure(assert x == 1)
class MyClass
fun foo(x: Int)
is
class MyClass
fun foo(x: Int)
is
do
if x <= 0 then print "FAIL"
end
do
if x <= 0 then print "FAIL"
end
class MyClass2
fun foo(bool: Bool)
is
class MyClass2
fun foo(bool: Bool)
is
do
if bool then print "FAIL"
end
do
if bool then print "FAIL"
end
class MyClass
fun foo(x: Int)
is
class MyClass
fun foo(x: Int)
is
do
if x <= 0 then print "FAIL"
end
do
if x <= 0 then print "FAIL"
end
class MyClass
fun foo(x: Int)
is
class MyClass
fun foo(x: Int)
is
do
if x <= 0 then print "FAIL"
end
do
if x <= 0 then print "FAIL"
end
do
if x < 0 then print "FAIL"
end
do
if x < 0 then print "FAIL"
end
do
if x != 0 then print "Good"
end
do
if x != 0 then print "Good"
end
do
if x != 1 then print "Error x != 1"
end
do
if x != 1 then print "Error x != 1"
end
fun add_all(x: Array[Object])
is
fun add_all(x: Array[Object])
is
do
print "toto MyArrayInt"
super e
do
print "toto MyArrayInt"
super e
do
print "toto MyArrayInt2"
super e
do
print "toto MyArrayInt2"
super e
- expects(x == 10)
- expects(x >= 10)
+ expect(x == 10)
+ expect(x >= 10)
-Runtime error: Assert 'expects' failed (contracts.nit:31)
+Runtime error: Assert 'expect' failed (contracts.nit:31)
-Runtime error: Assert 'ensures' failed (contracts_abstract.nit:26)
+Runtime error: Assert 'ensure' failed (contracts_abstract.nit:26)
-contracts_add.nit:46,3--17: Useless contract: No contract defined at the introduction of the method
-Runtime error: Assert 'ensures' failed (contracts_add.nit:39)
+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 'expects' failed (contracts_constructor.nit:20)
+Runtime error: Assert 'expect' failed (contracts_constructor.nit:20)
-Runtime error: Assert 'ensures' failed (contracts_ensures.nit:29)
+Runtime error: Assert 'ensure' failed (contracts_ensures.nit:29)
-Runtime error: Assert 'ensures' failed (contracts_ensures_1.nit:20)
+Runtime error: Assert 'ensure' failed (contracts_ensures_1.nit:20)
-Runtime error: Assert 'ensures' failed (contracts_ensures_2.nit:31)
+Runtime error: Assert 'ensure' failed (contracts_ensures_2.nit:31)
-Runtime error: Assert 'ensures' failed (contracts_ensures_3.nit:20)
+Runtime error: Assert 'ensure' failed (contracts_ensures_3.nit:20)
-Runtime error: Assert 'ensures' failed (contracts_ensures_4.nit:31)
+Runtime error: Assert 'ensure' failed (contracts_ensures_4.nit:31)
-Runtime error: Assert 'ensures' failed (contracts_ensures_5.nit:29)
+Runtime error: Assert 'ensure' failed (contracts_ensures_5.nit:29)
-Runtime error: Assert 'ensures' failed (contracts_ensures_sequence.nit:18)
+Runtime error: Assert 'ensure' failed (contracts_ensures_sequence.nit:18)
-contracts_error.nit:23,11--23: Error: expected an expression.
-contracts_error.nit:24,11--23: Error: expected an expression.
+contracts_error.nit:23,10--22: Error: expected an expression.
+contracts_error.nit:24,10--22: Error: expected an expression.
-Runtime error: Assert 'expects' failed (contracts_expects_1.nit:20)
+Runtime error: Assert 'expect' failed (contracts_expects_1.nit:20)
-contracts_expects_3.nit:29,3--17: Useless contract: No contract defined at the introduction of the method
+contracts_expects_3.nit:29,3--16: Useless contract: No contract defined at the introduction of the method
-Runtime error: Assert 'expects' failed (contracts_generic_type.nit:33)
+Runtime error: Assert 'expect' failed (contracts_generic_type.nit:33)
contracts_inheritance.nit:58,6--9: Warning: conflicting property definitions for property `toto` in `MySubArray`: contracts_inheritance$MyArrayInt$toto contracts_inheritance$MyArrayInt2$toto
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 'ensures' failed (contracts_inheritance.nit:32)
+Runtime error: Assert 'ensure' failed (contracts_inheritance.nit:32)
toto MyArrayInt2
toto MyArrayInt
toto ArrayInt
toto MyArrayInt2
toto MyArrayInt
toto ArrayInt
-contracts_same_contract.nit:22,3--18: The method already has a defined `expects` contract at line 21
+contracts_same_contract.nit:22,3--17: The method already has a defined `expect` contract at line 21
-Runtime error: Assert 'expects' failed (contracts_virtual_type.nit:23)
+Runtime error: Assert 'expect' failed (contracts_virtual_type.nit:23)