@@ -37,49 +37,16 @@ sealed trait Stmt extends Hashable with Infoed with Positioned with Transformabl
3737 }
3838}
3939
40- /** A statement that creates a new object and assigns it to a local variable. */
41- case class NewStmt (lhs : LocalVar , fields : Seq [ Field ] )(val pos : Position = NoPosition , val info : Info = NoInfo , val errT : ErrorTrafo = NoTrafos ) extends Stmt {
40+ /** An assignment to a field or a local variable. */
41+ case class Assign [ T <: Lhs ] (lhs : T , rhs : Exp )(val pos : Position = NoPosition , val info : Info = NoInfo , val errT : ErrorTrafo = NoTrafos ) extends Stmt {
4242 override lazy val check : Seq [ConsistencyError ] =
4343 (if (! Consistency .noResult(this )) Seq (ConsistencyError (" Result variables are only allowed in postconditions of functions." , pos)) else Seq ()) ++
44- (if (! (Ref isSubtype lhs)) Seq (ConsistencyError (s " Left-hand side of New statement must be Ref type, but found ${lhs.typ}" , lhs.pos)) else Seq ())
45-
46- }
47-
48- /** An assignment to a field or a local variable */
49- sealed trait AbstractAssign extends Stmt {
50-
51- def lhs : Lhs
52-
53- def rhs : Exp
54- }
55-
56- object AbstractAssign {
57- def apply (lhs : Lhs , rhs : Exp )(pos : Position = NoPosition , info : Info = NoInfo , errT : ErrorTrafo = NoTrafos ) = lhs match {
58- case l : LocalVar => LocalVarAssign (l, rhs)(pos, info, errT)
59- case l : FieldAccess => FieldAssign (l, rhs)(pos, info, errT)
60- }
61-
62- def unapply (a : AbstractAssign ) = Some ((a.lhs, a.rhs))
63- }
64-
65- /** An assignment to a local variable. */
66- case class LocalVarAssign (lhs : LocalVar , rhs : Exp )(val pos : Position = NoPosition , val info : Info = NoInfo , val errT : ErrorTrafo = NoTrafos ) extends AbstractAssign {
67- override lazy val check : Seq [ConsistencyError ] =
68- (if (! Consistency .noResult(this )) Seq (ConsistencyError (" Result variables are only allowed in postconditions of functions." , pos)) else Seq ()) ++
69- Consistency .checkPure(rhs) ++
70- (if (! Consistency .isAssignable(rhs, lhs)) Seq (ConsistencyError (s " Right-hand side $rhs is not assignable to left-hand side $lhs. " , lhs.pos)) else Seq ())
71- }
72-
73- /** An assignment to a field variable. */
74- case class FieldAssign (lhs : FieldAccess , rhs : Exp )(val pos : Position = NoPosition , val info : Info = NoInfo , val errT : ErrorTrafo = NoTrafos ) extends AbstractAssign {
75- override lazy val check : Seq [ConsistencyError ] =
76- (if (! Consistency .noResult(this )) Seq (ConsistencyError (" Result variables are only allowed in postconditions of functions." , pos)) else Seq ()) ++
77- Consistency .checkPure(rhs) ++
44+ Consistency .checkCanAssignFrom(rhs) ++
7845 (if (! Consistency .isAssignable(rhs, lhs)) Seq (ConsistencyError (s " Right-hand side $rhs is not assignable to left-hand side $lhs. " , lhs.pos)) else Seq ())
7946}
8047
8148/** A method call. */
82- case class MethodCall (methodName : String , args : Seq [Exp ], targets : Seq [LocalVar ])(val pos : Position , val info : Info , val errT : ErrorTrafo ) extends Stmt {
49+ case class MethodCall (methodName : String , args : Seq [Exp ], targets : Seq [Lhs ])(val pos : Position , val info : Info , val errT : ErrorTrafo ) extends Stmt {
8350 override lazy val check : Seq [ConsistencyError ] = {
8451 var s = Seq .empty[ConsistencyError ]
8552 if (! Consistency .noResult(this ))
@@ -92,7 +59,7 @@ case class MethodCall(methodName: String, args: Seq[Exp], targets: Seq[LocalVar]
9259}
9360
9461object MethodCall {
95- def apply (method : Method , args : Seq [Exp ], targets : Seq [LocalVar ])(pos : Position = NoPosition , info : Info = NoInfo , errT : ErrorTrafo = NoTrafos ): MethodCall = {
62+ def apply (method : Method , args : Seq [Exp ], targets : Seq [Lhs ])(pos : Position = NoPosition , info : Info = NoInfo , errT : ErrorTrafo = NoTrafos ): MethodCall = {
9663 MethodCall (method.name, args, targets)(pos, info, errT)
9764 }
9865}
0 commit comments