Skip to content

Commit 81b2a02

Browse files
committed
Fix some whitespace and formatting issues
1 parent 4e4d861 commit 81b2a02

5 files changed

Lines changed: 237 additions & 205 deletions

File tree

src/main/scala/viper/silver/plugin/standard/adt/AdtASTExtension.scala

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import viper.silver.verifier.{ConsistencyError, Failure, VerificationResult}
1515
/**
1616
* This class represents a user-defined ADT.
1717
*
18-
* @param name name of the ADT
18+
* @param name name of the ADT
1919
* @param constructors sequence of corresponding constructors
20-
* @param typVars sequence of type variables (generics)
20+
* @param typVars sequence of type variables (generics)
2121
* @param derivingInfo a map that maps identifiers of derivable functions to a tuple containing an optional type param and a set of excluded constructor argument identifiers
2222
*/
2323
case class Adt(name: String, constructors: Seq[AdtConstructor], typVars: Seq[TypeVar] = Nil, derivingInfo: Map[String, (Option[Type], Set[String])] = Map.empty)
24-
(val pos: Position = NoPosition, val info: Info = NoInfo, val errT: ErrorTrafo = NoTrafos) extends ExtensionMember {
24+
(val pos: Position = NoPosition, val info: Info = NoInfo, val errT: ErrorTrafo = NoTrafos) extends ExtensionMember {
2525
val scopedDecls: Seq[Declaration] = Seq()
2626

2727
override def extensionSubnodes: Seq[Node] = constructors ++ typVars ++ derivingInfo.map(_._2._1).collect { case Some(v) => v }
@@ -31,11 +31,11 @@ case class Adt(name: String, constructors: Seq[AdtConstructor], typVars: Seq[Typ
3131
def showDerivingInfo(di: (String, (Option[Type], Set[String]))): PrettyPrintPrimitives#Cont = {
3232
val (func, (param, blocklist)) = di
3333
text(func) <> (if (param.isEmpty) nil else text("[") <> showType(param.get) <> space <> "]") <>
34-
space <> (if (blocklist.isEmpty) nil else text("without") <> space <> ssep(blocklist.toSeq map text, char (',') <> space))
34+
space <> (if (blocklist.isEmpty) nil else text("without") <> space <> ssep(blocklist.toSeq map text, char(',') <> space))
3535
}
3636

3737
text("adt") <+> name <>
38-
(if (typVars.isEmpty) nil else text("[") <> ssep(typVars map show, char (',') <> space) <> "]") <+>
38+
(if (typVars.isEmpty) nil else text("[") <> ssep(typVars map show, char(',') <> space) <> "]") <+>
3939
braces(nest(defaultIndent,
4040
line <> line <>
4141
ssep(constructors map show, line <> line)
@@ -45,7 +45,7 @@ case class Adt(name: String, constructors: Seq[AdtConstructor], typVars: Seq[Typ
4545
line <> line <>
4646
ssep(derivingInfo.toSeq map showDerivingInfo, line <> line)
4747
) <> line)
48-
)
48+
)
4949
}
5050
}
5151

@@ -54,19 +54,20 @@ case class Adt(name: String, constructors: Seq[AdtConstructor], typVars: Seq[Typ
5454
* Adt - this should be used in general for creation (so that typ is guaranteed to
5555
* be set correctly)
5656
*
57-
* @param name name of the ADT constructor
57+
* @param name name of the ADT constructor
5858
* @param formalArgs sequence of arguments of the constructor
59-
* @param typ the return type of the constructor
60-
* @param adtName the name corresponding of the corresponding ADT
59+
* @param typ the return type of the constructor
60+
* @param adtName the name corresponding of the corresponding ADT
6161
*/
6262
case class AdtConstructor(name: String, formalArgs: Seq[LocalVarDecl])
63-
(val pos: Position, val info: Info, val typ: AdtType, val adtName : String, val errT: ErrorTrafo)
63+
(val pos: Position, val info: Info, val typ: AdtType, val adtName: String, val errT: ErrorTrafo)
6464
extends ExtensionMember {
6565

66-
override def getMetadata:Seq[Any] = {
66+
val scopedDecls: Seq[Declaration] = formalArgs
67+
68+
override def getMetadata: Seq[Any] = {
6769
Seq(pos, info, errT)
6870
}
69-
val scopedDecls: Seq[Declaration] = formalArgs
7071

7172
override def extensionSubnodes: Seq[Node] = formalArgs
7273

@@ -86,7 +87,8 @@ case class AdtConstructor(name: String, formalArgs: Seq[LocalVarDecl])
8687
}
8788

8889
object AdtConstructor {
89-
def apply(adt: Adt, name: String, formalArgs: Seq[LocalVarDecl])(pos: Position = NoPosition, info: Info = NoInfo, errT: ErrorTrafo = NoTrafos): AdtConstructor = {
90+
def apply(adt: Adt, name: String, formalArgs: Seq[LocalVarDecl])
91+
(pos: Position = NoPosition, info: Info = NoInfo, errT: ErrorTrafo = NoTrafos): AdtConstructor = {
9092
AdtConstructor(name, formalArgs)(pos, info, AdtType(adt, (adt.typVars zip adt.typVars).toMap), adt.name, errT)
9193
}
9294
}
@@ -96,15 +98,15 @@ object AdtConstructor {
9698
* Adt - this should be used in general for creation (so that typeParameters is guaranteed to
9799
* be set correctly)
98100
*
99-
* @param adtName The name of the underlying adt.
101+
* @param adtName The name of the underlying adt.
100102
* @param partialTypVarsMap Maps type parameters to (possibly concrete) types. May not map all
101103
* type parameters, may even be empty.
102-
* @param typeParameters The type variables of the ADT type.
104+
* @param typeParameters The type variables of the ADT type.
103105
*/
104106
case class AdtType(adtName: String, partialTypVarsMap: Map[TypeVar, Type])
105107
(val typeParameters: Seq[TypeVar]) extends ExtensionType {
106108

107-
override lazy val check: Seq[ConsistencyError] = if(!(typeParameters.toSet == typVarsMap.keys.toSet)) {
109+
override lazy val check: Seq[ConsistencyError] = if (!(typeParameters.toSet == typVarsMap.keys.toSet)) {
108110
Seq(ConsistencyError(s"${typeParameters.toSet} doesn't equal ${typVarsMap.keys.toSet}", NoPosition))
109111
} else Seq()
110112

@@ -120,8 +122,8 @@ case class AdtType(adtName: String, partialTypVarsMap: Map[TypeVar, Type])
120122
* occurrences of those type variables with the corresponding type.
121123
*/
122124
override def substitute(newTypVarsMap: Map[TypeVar, Type]): Type = {
123-
assert (typVarsMap.keys.toSet equals this.typeParameters.toSet)
124-
val newTypeMap = typVarsMap.map(kv=>kv._1 -> kv._2.substitute(newTypVarsMap))
125+
assert(typVarsMap.keys.toSet equals this.typeParameters.toSet)
126+
val newTypeMap = typVarsMap.map(kv => kv._1 -> kv._2.substitute(newTypVarsMap))
125127
AdtType(adtName, newTypeMap)(typeParameters)
126128
}
127129

@@ -130,7 +132,7 @@ case class AdtType(adtName: String, partialTypVarsMap: Map[TypeVar, Type])
130132

131133
override def prettyPrint: PrettyPrintPrimitives#Cont = {
132134
val typArgs = typeParameters map (t => show(typVarsMap.getOrElse(t, t)))
133-
text(adtName) <> (if (typArgs.isEmpty) nil else brackets(ssep(typArgs, char (',') <> space)))
135+
text(adtName) <> (if (typArgs.isEmpty) nil else brackets(ssep(typArgs, char(',') <> space)))
134136
}
135137

136138
override def withChildren(children: Seq[Any], pos: Option[(Position, Position)], forceRewrite: Boolean): this.type = {
@@ -146,7 +148,7 @@ case class AdtType(adtName: String, partialTypVarsMap: Map[TypeVar, Type])
146148

147149
}
148150

149-
object AdtType{
151+
object AdtType {
150152
def apply(adt: Adt, typVarsMap: Map[TypeVar, Type]): AdtType =
151153
AdtType(adt.name, typVarsMap)(adt.typVars)
152154
}
@@ -157,24 +159,24 @@ object AdtType{
157159
* Adt constructor - this should be used in general for creation (so that typ is guaranteed to
158160
* be set correctly)
159161
*
160-
* @param name The name of the ADT constructor
161-
* @param args A sequence of expressions passed as arguments to the constructor
162+
* @param name The name of the ADT constructor
163+
* @param args A sequence of expressions passed as arguments to the constructor
162164
* @param typVarMap Maps type parameters to (possibly concrete) types. May not map all
163165
* type parameters, may even be empty.
164-
* @param typ The return type of the constructor
165-
* @param adtName The corresponding ADT name
166+
* @param typ The return type of the constructor
167+
* @param adtName The corresponding ADT name
166168
*/
167169
case class AdtConstructorApp(name: String, args: Seq[Exp], typVarMap: Map[TypeVar, Type])
168-
(val pos: Position, val info: Info, override val typ: Type, val adtName:String, val errT: ErrorTrafo)
170+
(val pos: Position, val info: Info, override val typ: Type, val adtName: String, val errT: ErrorTrafo)
169171
extends ExtensionExp {
170-
override lazy val check : Seq[ConsistencyError] = args.flatMap(Consistency.checkPure)
172+
override lazy val check: Seq[ConsistencyError] = args.flatMap(Consistency.checkPure)
171173

172174
override def prettyPrint: PrettyPrintPrimitives#Cont = {
173175
if (typVarMap.nonEmpty)
174176
// Type may be under-constrained, so to be safe we explicitly print out the type.
175-
parens(text(name) <> parens(ssep(args map show, char (',') <> space)) <> char(':') <+> show(typ))
177+
parens(text(name) <> parens(ssep(args map show, char(',') <> space)) <> char(':') <+> show(typ))
176178
else
177-
text(name) <> parens(ssep(args map show, char (',') <> space))
179+
text(name) <> parens(ssep(args map show, char(',') <> space))
178180
}
179181

180182
override def extensionIsPure: Boolean = true
@@ -198,8 +200,10 @@ case class AdtConstructorApp(name: String, args: Seq[Exp], typVarMap: Map[TypeVa
198200
}
199201
}
200202
}
203+
201204
object AdtConstructorApp {
202-
def apply(constructor : AdtConstructor, args: Seq[Exp], typVarMap: Map[TypeVar, Type])(pos: Position = NoPosition, info: Info = NoInfo, errT: ErrorTrafo = NoTrafos) : AdtConstructorApp =
205+
def apply(constructor: AdtConstructor, args: Seq[Exp], typVarMap: Map[TypeVar, Type])
206+
(pos: Position = NoPosition, info: Info = NoInfo, errT: ErrorTrafo = NoTrafos): AdtConstructorApp =
203207
AdtConstructorApp(constructor.name, args, typVarMap)(pos, info, constructor.typ.substitute(typVarMap), constructor.adtName, errT)
204208
}
205209

@@ -208,16 +212,17 @@ object AdtConstructorApp {
208212
* Adt - this should be used in general for creation (so that typ is guaranteed to
209213
* be set correctly)
210214
*
211-
* @param name The name of the argument of an ADT constructor the destructor corresponds to
212-
* @param rcv An expression on with the the destructor is applied
215+
* @param name The name of the argument of an ADT constructor the destructor corresponds to
216+
* @param rcv An expression on with the the destructor is applied
213217
* @param typVarMap Maps type parameters to (possibly concrete) types. May not map all
214218
* type parameters, may even be empty.
215-
* @param typ The return type of the destructor
216-
* @param adtName The corresponding ADT name
219+
* @param typ The return type of the destructor
220+
* @param adtName The corresponding ADT name
217221
*/
218-
case class AdtDestructorApp(name: String, rcv: Exp, typVarMap: Map[TypeVar, Type])(val pos: Position, val info: Info, override val typ: Type, val adtName:String, val errT: ErrorTrafo) extends ExtensionExp {
222+
case class AdtDestructorApp(name: String, rcv: Exp, typVarMap: Map[TypeVar, Type])
223+
(val pos: Position, val info: Info, override val typ: Type, val adtName: String, val errT: ErrorTrafo) extends ExtensionExp {
219224

220-
override lazy val check : Seq[ConsistencyError] = Consistency.checkPure(rcv)
225+
override lazy val check: Seq[ConsistencyError] = Consistency.checkPure(rcv)
221226

222227
override def prettyPrint: PrettyPrintPrimitives#Cont = show(rcv) <> "." <> name
223228

@@ -244,7 +249,8 @@ case class AdtDestructorApp(name: String, rcv: Exp, typVarMap: Map[TypeVar, Type
244249
}
245250

246251
object AdtDestructorApp {
247-
def apply(adt : Adt, name: String, rcv: Exp, typVarMap: Map[TypeVar, Type])(pos: Position = NoPosition, info: Info = NoInfo, errT: ErrorTrafo = NoTrafos) : AdtDestructorApp = {
252+
def apply(adt: Adt, name: String, rcv: Exp, typVarMap: Map[TypeVar, Type])
253+
(pos: Position = NoPosition, info: Info = NoInfo, errT: ErrorTrafo = NoTrafos): AdtDestructorApp = {
248254
val matchingConstructors = adt.constructors flatMap (c => c.formalArgs.filter { lv => lv.name == name })
249255
assert(matchingConstructors.length == 1, s"AdtDestructorApp : expected length 1 but got ${matchingConstructors.length}")
250256
val typ = matchingConstructors.head.typ
@@ -257,17 +263,18 @@ object AdtDestructorApp {
257263
* Adt - this should be used in general for creation (so that adtName is guaranteed to
258264
* be set correctly)
259265
*
260-
* @param name The name of the argument of an ADT constructor the destructor corresponds to
261-
* @param rcv An expression on with the the destructor is applied
266+
* @param name The name of the argument of an ADT constructor the destructor corresponds to
267+
* @param rcv An expression on with the the destructor is applied
262268
* @param typVarMap Maps type parameters to (possibly concrete) types. May not map all
263269
* type parameters, may even be empty.
264-
* @param adtName The corresponding ADT name
270+
* @param adtName The corresponding ADT name
265271
*/
266-
case class AdtDiscriminatorApp(name: String, rcv: Exp, typVarMap: Map[TypeVar, Type])(val pos: Position, val info: Info, val adtName:String, val errT: ErrorTrafo) extends ExtensionExp {
272+
case class AdtDiscriminatorApp(name: String, rcv: Exp, typVarMap: Map[TypeVar, Type])
273+
(val pos: Position, val info: Info, val adtName: String, val errT: ErrorTrafo) extends ExtensionExp {
267274

268-
override def typ: Type = Bool
275+
override lazy val check: Seq[ConsistencyError] = Consistency.checkPure(rcv)
269276

270-
override lazy val check : Seq[ConsistencyError] = Consistency.checkPure(rcv)
277+
override def typ: Type = Bool
271278

272279
override def prettyPrint: PrettyPrintPrimitives#Cont = show(rcv) <> "." <> name <> "?"
273280

@@ -295,7 +302,8 @@ case class AdtDiscriminatorApp(name: String, rcv: Exp, typVarMap: Map[TypeVar, T
295302
}
296303

297304
object AdtDiscriminatorApp {
298-
def apply(adt : Adt, name: String, rcv: Exp, typVarMap: Map[TypeVar, Type])(pos: Position = NoPosition, info: Info = NoInfo, errT: ErrorTrafo = NoTrafos) : AdtDiscriminatorApp = {
305+
def apply(adt: Adt, name: String, rcv: Exp, typVarMap: Map[TypeVar, Type])
306+
(pos: Position = NoPosition, info: Info = NoInfo, errT: ErrorTrafo = NoTrafos): AdtDiscriminatorApp = {
299307
AdtDiscriminatorApp(name, rcv, typVarMap)(pos, info, adt.name, errT)
300308
}
301309
}

0 commit comments

Comments
 (0)