@@ -436,6 +436,16 @@ case class PWandType()(val pos: (Position, Position)) extends PInternalType {
436436 override def isValidOrUndeclared = true
437437}
438438
439+ /**
440+ */
441+ case class PFunctionType (resultType : PType ) extends PType {
442+ override val pos : (Position , Position ) = resultType.pos
443+ override def isValidOrUndeclared : Boolean = resultType.isValidOrUndeclared
444+ override def substitute (ts : PTypeSubstitution ): PType = this .copy(resultType = resultType.substitute(ts))
445+ override def subNodes : Seq [PType ] = Seq (resultType)
446+ override def toString = " $fn:" + resultType.toString
447+ }
448+
439449// /////////////////////////////////////////////////////////////////////////////////////
440450// Expressions
441451// typeSubstitutions are the possible substitutions used for type checking and inference
@@ -622,14 +632,14 @@ case class PCall(func: PIdnUse, args: Seq[PExp], typeAnnotated: Option[PType] =
622632 override def macroArgs = args
623633
624634 override def signatures = if (function != null && function.formalArgs.size == args.size) (function match {
625- case _ : PFunction => List (
626- new PTypeSubstitution (args.indices.map(i => POpApp .pArg(i).domain.name -> function .formalArgs(i).typ) :+ (POpApp .pRes.domain.name -> function .typ))
635+ case pf : PFunction => List (
636+ new PTypeSubstitution (args.indices.map(i => POpApp .pArg(i).domain.name -> pf .formalArgs(i).typ) :+ (POpApp .pRes.domain.name -> pf .typ.resultType ))
627637 )
628638 case pdf : PDomainFunction =>
629639 List (
630640 new PTypeSubstitution (
631- args.indices.map(i => POpApp .pArg(i).domain.name -> function .formalArgs(i).typ.substitute(domainTypeRenaming.get)) :+
632- (POpApp .pRes.domain.name -> pdf.typ.substitute(domainTypeRenaming.get)))
641+ args.indices.map(i => POpApp .pArg(i).domain.name -> pdf .formalArgs(i).typ.substitute(domainTypeRenaming.get)) :+
642+ (POpApp .pRes.domain.name -> pdf.typ.resultType. substitute(domainTypeRenaming.get)))
633643 )
634644
635645 })
@@ -1380,7 +1390,8 @@ trait PAnyFunction extends PSingleMember with PTypedDeclaration {
13801390
13811391 def formalArgs : Seq [PAnyFormalArgDecl ]
13821392
1383- def typ : PType
1393+ def resultType : PType
1394+ override def typ : PFunctionType = PFunctionType (resultType)
13841395}
13851396
13861397case class PProgram (imports : Seq [PImport ], macros : Seq [PDefine ], domains : Seq [PDomain ], fields : Seq [PField ], functions : Seq [PFunction ], predicates : Seq [PPredicate ], methods : Seq [PMethod ], extensions : Seq [PExtender ], errors : Seq [ParseReport ])(val pos : (Position , Position )) extends PNode
@@ -1411,16 +1422,16 @@ case class PMethod(idndef: PIdnDef, formalArgs: Seq[PFormalArgDecl], formalRetur
14111422
14121423case class PDomain (idndef : PIdnDef , typVars : Seq [PTypeVarDecl ], funcs : Seq [PDomainFunction ], axioms : Seq [PAxiom ], interpretations : Option [Map [String , String ]])
14131424 (val pos : (Position , Position ), val annotations : Seq [(String , Seq [String ])]) extends PSingleMember
1414- case class PFunction (idndef : PIdnDef , formalArgs : Seq [PFormalArgDecl ], typ : PType , pres : Seq [PExp ], posts : Seq [PExp ], body : Option [PExp ])
1425+ case class PFunction (idndef : PIdnDef , formalArgs : Seq [PFormalArgDecl ], resultType : PType , pres : Seq [PExp ], posts : Seq [PExp ], body : Option [PExp ])
14151426 (val pos : (Position , Position ), val annotations : Seq [(String , Seq [String ])]) extends PAnyFunction {
1416- def deepCopy (idndef : PIdnDef = this .idndef, formalArgs : Seq [PFormalArgDecl ] = this .formalArgs, typ : PType = this .typ , pres : Seq [PExp ] = this .pres, posts : Seq [PExp ] = this .posts, body : Option [PExp ] = this .body): PFunction = {
1427+ def deepCopy (idndef : PIdnDef = this .idndef, formalArgs : Seq [PFormalArgDecl ] = this .formalArgs, resultType : PType = this .resultType , pres : Seq [PExp ] = this .pres, posts : Seq [PExp ] = this .posts, body : Option [PExp ] = this .body): PFunction = {
14171428 StrategyBuilder .Slim [PNode ]({
1418- case p : PFunction => PFunction (idndef, formalArgs, typ , pres, posts, body)(p.pos, p.annotations)
1429+ case p : PFunction => PFunction (idndef, formalArgs, resultType , pres, posts, body)(p.pos, p.annotations)
14191430 }).execute[PFunction ](this )
14201431 }
14211432}
14221433
1423- case class PDomainFunction (idndef : PIdnDef , formalArgs : Seq [PAnyFormalArgDecl ], typ : PType , unique : Boolean , interpretation : Option [String ])
1434+ case class PDomainFunction (idndef : PIdnDef , formalArgs : Seq [PAnyFormalArgDecl ], resultType : PType , unique : Boolean , interpretation : Option [String ])
14241435 (val domainName : PIdnUse )(val pos : (Position , Position ), val annotations : Seq [(String , Seq [String ])]) extends PAnyFunction
14251436case class PAxiom (idndef : Option [PIdnDef ], exp : PExp )(val domainName : PIdnUse )(val pos : (Position , Position ), val annotations : Seq [(String , Seq [String ])]) extends PScope
14261437case class PField (fields : Seq [PFieldDecl ])(val pos : (Position , Position ), val annotations : Seq [(String , Seq [String ])]) extends PMember {
0 commit comments