summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dan Rosén <danr@chalmers.se>2014-08-11 16:07:38 -0700
committerGravatar Dan Rosén <danr@chalmers.se>2014-08-11 16:07:38 -0700
commit8797f054f44d114147562689d80c9970d8ea4f82 (patch)
tree6a9e99a6a39126f946c0e7dd55cf0fa03a1a0ca7
parent4cbe4583b329a39dee2b4b456758cafbe7e2fa79 (diff)
parent08ab990d6f1a188c6cc039d6a2289daf41ff52d3 (diff)
Merge
-rw-r--r--.hgignore1
-rw-r--r--Binaries/DafnyRuntime.cs7
-rw-r--r--Source/Dafny/Cloner.cs43
-rw-r--r--Source/Dafny/Compiler.cs362
-rw-r--r--Source/Dafny/Dafny.atg40
-rw-r--r--Source/Dafny/DafnyAst.cs113
-rw-r--r--Source/Dafny/Parser.cs1374
-rw-r--r--Source/Dafny/Printer.cs5
-rw-r--r--Source/Dafny/RefinementTransformer.cs84
-rw-r--r--Source/Dafny/Resolver.cs316
-rw-r--r--Source/Dafny/Rewriter.cs6
-rw-r--r--Source/Dafny/Scanner.cs222
-rw-r--r--Source/Dafny/Translator.cs873
-rw-r--r--Source/DafnyDriver/DafnyDriver.cs2
-rw-r--r--Source/DafnyExtension/DafnyRuntime.cs7
-rw-r--r--Source/DafnyExtension/TokenTagger.cs2
-rw-r--r--Test/dafny0/AutoReq.dfy226
-rw-r--r--Test/dafny0/AutoReq.dfy.expect4
-rw-r--r--Test/dafny0/ComputationsLoop.dfy13
-rw-r--r--Test/dafny0/ComputationsLoop.dfy.expect9
-rw-r--r--Test/dafny0/ComputationsLoop2.dfy17
-rw-r--r--Test/dafny0/ComputationsLoop2.dfy.expect13
-rw-r--r--Test/dafny0/EqualityTypes.dfy.expect2
-rw-r--r--Test/dafny0/Modules0.dfy.expect36
-rw-r--r--Test/dafny0/ResolutionErrors.dfy18
-rw-r--r--Test/dafny0/ResolutionErrors.dfy.expect4
-rw-r--r--Test/dafny0/Trait/TraitBasix.dfy173
-rw-r--r--Test/dafny0/Trait/TraitBasix.dfy.expect7
-rw-r--r--Test/dafny0/Trait/TraitExtend.dfy43
-rw-r--r--Test/dafny0/Trait/TraitExtend.dfy.expect3
-rw-r--r--Test/dafny0/Trait/TraitMultiModule.dfy26
-rw-r--r--Test/dafny0/Trait/TraitMultiModule.dfy.expect2
-rw-r--r--Test/dafny0/Trait/TraitOverride0.dfy81
-rw-r--r--Test/dafny0/Trait/TraitOverride0.dfy.expect5
-rw-r--r--Test/dafny0/Trait/TraitOverride1.dfy194
-rw-r--r--Test/dafny0/Trait/TraitOverride1.dfy.expect2
-rw-r--r--Test/dafny0/Trait/TraitPolymorphism.dfy65
-rw-r--r--Test/dafny0/Trait/TraitPolymorphism.dfy.expect4
-rw-r--r--Test/dafny0/Trait/TraitSpecsOverride0.dfy59
-rw-r--r--Test/dafny0/Trait/TraitSpecsOverride0.dfy.expect5
-rw-r--r--Test/dafny0/Trait/TraitUsingParentMembers.dfy44
-rw-r--r--Test/dafny0/Trait/TraitUsingParentMembers.dfy.expect8
-rw-r--r--Test/dafny0/TypeSynonyms.dfy7
-rw-r--r--Test/dafny0/TypeSynonyms.dfy.expect2
-rw-r--r--Test/dafny0/TypeTests.dfy.expect4
-rw-r--r--Test/dafny4/NumberRepresentations.dfy2
-rw-r--r--Util/Emacs/dafny-mode.el1
-rw-r--r--Util/latex/dafny.sty2
-rw-r--r--Util/vim/dafny.vim2
49 files changed, 3293 insertions, 1247 deletions
diff --git a/.hgignore b/.hgignore
index a1219ed2..95b7d862 100644
--- a/.hgignore
+++ b/.hgignore
@@ -12,3 +12,4 @@ syntax: glob
*.dll
*.tmp
*.tmp.dfy
+dafny_all_filesThat_Change.txt
diff --git a/Binaries/DafnyRuntime.cs b/Binaries/DafnyRuntime.cs
index 6f0cab13..d6bd895a 100644
--- a/Binaries/DafnyRuntime.cs
+++ b/Binaries/DafnyRuntime.cs
@@ -656,6 +656,13 @@ namespace Dafny
num = n;
den = d;
}
+ public BigInteger ToBigInteger() {
+ if (0 <= num) {
+ return num / den;
+ } else {
+ return (num - den + 1) / den;
+ }
+ }
/// <summary>
/// Returns values such that aa/dd == a and bb/dd == b.
/// </summary>
diff --git a/Source/Dafny/Cloner.cs b/Source/Dafny/Cloner.cs
index f3a97f92..0f21d50c 100644
--- a/Source/Dafny/Cloner.cs
+++ b/Source/Dafny/Cloner.cs
@@ -67,14 +67,34 @@ namespace Microsoft.Dafny
req, ens, yreq, yens,
body, CloneAttributes(dd.Attributes), dd.SignatureEllipsis);
return iter;
- } else if (d is ClassDecl) {
+ }
+ else if (d is TraitDecl)
+ {
+ if (d is DefaultClassDecl)
+ {
+ var dd = (TraitDecl)d;
+ var tps = dd.TypeArgs.ConvertAll(CloneTypeParam);
+ var mm = dd.Members.ConvertAll(CloneMember);
+ var cl = new DefaultClassDecl(m, mm);
+ return cl;
+ }
+ else
+ {
+ var dd = (TraitDecl)d;
+ var tps = dd.TypeArgs.ConvertAll(CloneTypeParam);
+ var mm = dd.Members.ConvertAll(CloneMember);
+ var cl = new TraitDecl(Tok(dd.tok), dd.Name, m, tps, mm, CloneAttributes(dd.Attributes));
+ return cl;
+ }
+ }
+ else if (d is ClassDecl) {
var dd = (ClassDecl)d;
var tps = dd.TypeArgs.ConvertAll(CloneTypeParam);
var mm = dd.Members.ConvertAll(CloneMember);
if (d is DefaultClassDecl) {
return new DefaultClassDecl(m, mm);
} else {
- return new ClassDecl(Tok(dd.tok), dd.Name, m, tps, mm, CloneAttributes(dd.Attributes));
+ return new ClassDecl(Tok(dd.tok), dd.Name, m, tps, mm, CloneAttributes(dd.Attributes), new List<IToken> { dd.TraitId });
}
} else if (d is ModuleDecl) {
if (d is LiteralModuleDecl) {
@@ -115,13 +135,16 @@ namespace Microsoft.Dafny
if (member is Field) {
Contract.Assert(!(member is SpecialField)); // we don't expect a SpecialField to be cloned (or do we?)
var f = (Field)member;
- return new Field(Tok(f.tok), f.Name, f.IsGhost, f.IsMutable, f.IsUserMutable, CloneType(f.Type), CloneAttributes(f.Attributes));
+ Field field = new Field(Tok(f.tok), f.Name, f.IsGhost, f.IsMutable, f.IsUserMutable, CloneType(f.Type), CloneAttributes(f.Attributes));
+ return field;
} else if (member is Function) {
var f = (Function)member;
- return CloneFunction(f);
+ Function func = CloneFunction(f);
+ return func;
} else {
var m = (Method)member;
- return CloneMethod(m);
+ Method method = CloneMethod(m);
+ return method;
}
}
@@ -145,6 +168,13 @@ namespace Microsoft.Dafny
return new ArrowType(tt.Args.ConvertAll(CloneType), CloneType(tt.Result));
} else if (t is UserDefinedType) {
var tt = (UserDefinedType)t;
+#if TEST_TYPE_SYNONYM_TRANSPARENCY
+ if (tt.Name == "type#synonym#transparency#test") {
+ // time to drop the synonym wrapper
+ var syn = (TypeSynonymDecl)tt.ResolvedClass;
+ return CloneType(syn.Rhs);
+ }
+#endif
return new UserDefinedType(Tok(tt.tok), tt.Name, tt.TypeArgs.ConvertAll(CloneType), tt.Path.ConvertAll(Tok));
} else if (t is InferredTypeProxy) {
return new InferredTypeProxy();
@@ -157,7 +187,8 @@ namespace Microsoft.Dafny
}
public Formal CloneFormal(Formal formal) {
- return new Formal(Tok(formal.tok), formal.Name, CloneType(formal.Type), formal.InParam, formal.IsGhost);
+ Formal f = new Formal(Tok(formal.tok), formal.Name, CloneType(formal.Type), formal.InParam, formal.IsGhost);
+ return f;
}
public BoundVar CloneBoundVar(BoundVar bv) {
diff --git a/Source/Dafny/Compiler.cs b/Source/Dafny/Compiler.cs
index 97a53a66..e01cc6bb 100644
--- a/Source/Dafny/Compiler.cs
+++ b/Source/Dafny/Compiler.cs
@@ -206,10 +206,51 @@ namespace Microsoft.Dafny {
// end of the class
Indent(indent); wr.WriteLine("}");
- } else if (d is ClassDecl) {
+ }
+ else if (d is TraitDecl)
+ {
+ //writing the trait
+ var trait = (TraitDecl)d;
+ Indent(indent);
+ wr.Write("public interface @{0}", trait.CompileName);
+ wr.WriteLine(" {");
+ CompileClassMembers(trait, indent + IndentAmount);
+ Indent(indent); wr.WriteLine("}");
+
+ //writing the _Companion class
+ List<MemberDecl> members = new List<MemberDecl>();
+ foreach (MemberDecl mem in trait.Members)
+ {
+ if (mem.IsStatic && !mem.IsGhost)
+ {
+ if (mem is Function)
+ {
+ if (((Function)mem).Body != null)
+ members.Add(mem);
+ }
+ if (mem is Method)
+ {
+ if (((Method)mem).Body != null)
+ members.Add(mem);
+ }
+ }
+ }
+ var cl = new ClassDecl(d.tok, d.Name, d.Module, d.TypeArgs, members, d.Attributes, null);
+ Indent(indent);
+ wr.Write("public class @_Companion_{0}", cl.CompileName);
+ wr.WriteLine(" {");
+ CompileClassMembers(cl, indent + IndentAmount);
+ Indent(indent); wr.WriteLine("}");
+ }
+ else if (d is ClassDecl) {
var cl = (ClassDecl)d;
Indent(indent);
- wr.Write("public class @{0}", cl.CompileName);
+ if (cl.Trait != null && cl.Trait is TraitDecl)
+ {
+ wr.WriteLine("public class @{0} : @{1}", cl.CompileName, cl.TraitId.val);
+ }
+ else
+ wr.Write("public class @{0}", cl.CompileName);
if (cl.TypeArgs.Count != 0) {
wr.Write("<{0}>", TypeParameters(cl.TypeArgs));
}
@@ -708,98 +749,186 @@ namespace Microsoft.Dafny {
if (member is Field) {
Field f = (Field)member;
if (!f.IsGhost) {
- Indent(indent);
- wr.WriteLine("public {0} @{1} = {2};", TypeName(f.Type), f.CompileName, DefaultValue(f.Type));
+ if (c is TraitDecl)
+ {
+ {
+ Indent(indent);
+ wr.Write("{0} @{1}", TypeName(f.Type), f.CompileName);
+ wr.Write(" {");
+ wr.Write(" get; set; ");
+ wr.WriteLine("}");
+ }
+ }
+ else
+ {
+ if (f.Inherited)
+ {
+ Indent(indent);
+ wr.WriteLine("public {0} @{1};", TypeName(f.Type), f.CompileName);
+ wr.Write("{0} @{1}.@{2}", TypeName(f.Type), c.Trait.CompileName, f.CompileName);
+ wr.WriteLine(" {");
+ wr.WriteLine(" get { ");
+ wr.Write("return this.@{0};", f.CompileName);
+ wr.WriteLine("}");
+ wr.WriteLine(" set { ");
+ wr.WriteLine("this.@{0} = value;", f.CompileName);
+ wr.WriteLine("}");
+ wr.WriteLine("}");
+ }
+ else
+ {
+ Indent(indent);
+ wr.WriteLine("public {0} @{1} = {2};", TypeName(f.Type), f.CompileName, DefaultValue(f.Type));
+ }
+ }
}
-
} else if (member is Function) {
Function f = (Function)member;
- if (f.Body == null) {
- if (!Attributes.Contains(f.Attributes, "axiom")) {
- Error("Function {0} has no body", f.FullName);
- }
- } else if (f.IsGhost) {
- var v = new CheckHasNoAssumes_Visitor(this);
- v.Visit(f.Body);
- } else {
- Indent(indent);
- wr.Write("public {0}{1} @{2}", f.IsStatic ? "static " : "", TypeName(f.ResultType), f.CompileName);
- if (f.TypeArgs.Count != 0) {
- wr.Write("<{0}>", TypeParameters(f.TypeArgs));
- }
- wr.Write("(");
- WriteFormals("", f.Formals);
- wr.WriteLine(") {");
- CompileReturnBody(f.Body, indent + IndentAmount);
- Indent(indent); wr.WriteLine("}");
+ if (c is TraitDecl)
+ {
+ if (member.IsStatic && f.Body == null)
+ {
+ Error("Function {0} has no body", f.FullName);
+ }
+ else if (!member.IsStatic && !member.IsGhost) //static and ghost members are not included in the target trait
+ {
+ Indent(indent);
+ wr.Write("{0} @{1}", TypeName(f.ResultType), f.CompileName);
+ wr.Write("(");
+ WriteFormals("", f.Formals);
+ wr.WriteLine(");");
+ }
+ }
+ else
+ {
+ if (f.Body == null)
+ {
+ if (!Attributes.Contains(f.Attributes, "axiom"))
+ {
+ Error("Function {0} has no body", f.FullName);
+ }
+ }
+ else if (f.IsGhost)
+ {
+ var v = new CheckHasNoAssumes_Visitor(this);
+ v.Visit(f.Body);
+ }
+ else
+ {
+ Indent(indent);
+ wr.Write("public {0}{1} @{2}", f.IsStatic ? "static " : "", TypeName(f.ResultType), f.CompileName);
+ if (f.TypeArgs.Count != 0)
+ {
+ wr.Write("<{0}>", TypeParameters(f.TypeArgs));
+ }
+ wr.Write("(");
+ WriteFormals("", f.Formals);
+ wr.WriteLine(") {");
+ CompileReturnBody(f.Body, indent + IndentAmount);
+ Indent(indent); wr.WriteLine("}");
+ }
}
-
} else if (member is Method) {
Method m = (Method)member;
- if (m.Body == null) {
- if (!Attributes.Contains(m.Attributes, "axiom")) {
- Error("Method {0} has no body", m.FullName);
- }
- } else if (m.IsGhost) {
- var v = new CheckHasNoAssumes_Visitor(this);
- v.Visit(m.Body);
- } else {
- Indent(indent);
- wr.Write("public {0}void @{1}", m.IsStatic ? "static " : "", m.CompileName);
- if (m.TypeArgs.Count != 0) {
- wr.Write("<{0}>", TypeParameters(m.TypeArgs));
- }
- wr.Write("(");
- int nIns = WriteFormals("", m.Ins);
- WriteFormals(nIns == 0 ? "" : ", ", m.Outs);
- wr.WriteLine(")");
- Indent(indent); wr.WriteLine("{");
- foreach (Formal p in m.Outs) {
- if (!p.IsGhost) {
- Indent(indent + IndentAmount);
- wr.WriteLine("@{0} = {1};", p.CompileName, DefaultValue(p.Type));
+ if (c is TraitDecl)
+ {
+ if (member.IsStatic && m.Body == null)
+ {
+ Error("Method {0} has no body", m.FullName);
}
- }
- if (m.Body == null) {
- Error("Method {0} has no body", m.FullName);
- } else {
- if (m.IsTailRecursive) {
- Indent(indent); wr.WriteLine("TAIL_CALL_START: ;");
- if (!m.IsStatic) {
- Indent(indent + IndentAmount); wr.WriteLine("var _this = this;");
- }
+ else if (!member.IsStatic && !member.IsGhost) //static and ghost members are not included in the target trait
+ {
+ Indent(indent);
+ wr.Write("void @{0}", m.CompileName);
+ wr.Write("(");
+ int nIns = WriteFormals("", m.Ins);
+ WriteFormals(nIns == 0 ? "" : ", ", m.Outs);
+ wr.WriteLine(");");
}
- Contract.Assert(enclosingMethod == null);
- enclosingMethod = m;
- TrStmtList(m.Body.Body, indent);
- Contract.Assert(enclosingMethod == m);
- enclosingMethod = null;
- }
- Indent(indent); wr.WriteLine("}");
-
- // allow the Main method to be an instance method
- if (!m.IsStatic && m.Name == "Main" && m.TypeArgs.Count == 0 && m.Ins.Count == 0 && m.Outs.Count == 0 && m.Req.Count == 0) {
- Indent(indent);
- wr.WriteLine("public static void Main(string[] args) {");
- Contract.Assert(m.EnclosingClass == c);
- Indent(indent + IndentAmount);
- wr.Write("@{0} b = new @{0}", c.CompileName);
- if (c.TypeArgs.Count != 0) {
- // instantiate every parameter, it doesn't particularly matter how
- wr.Write("<");
- string sep = "";
- for (int i = 0; i < c.TypeArgs.Count; i++) {
- wr.Write("{0}int", sep);
- sep = ", ";
- }
- wr.Write(">");
+ }
+ else
+ {
+ if (m.Body == null)
+ {
+ if (!Attributes.Contains(m.Attributes, "axiom"))
+ {
+ Error("Method {0} has no body", m.FullName);
+ }
+ }
+ else if (m.IsGhost)
+ {
+ var v = new CheckHasNoAssumes_Visitor(this);
+ v.Visit(m.Body);
+ }
+ else
+ {
+ Indent(indent);
+ wr.Write("public {0}void @{1}", m.IsStatic ? "static " : "", m.CompileName);
+ if (m.TypeArgs.Count != 0)
+ {
+ wr.Write("<{0}>", TypeParameters(m.TypeArgs));
+ }
+ wr.Write("(");
+ int nIns = WriteFormals("", m.Ins);
+ WriteFormals(nIns == 0 ? "" : ", ", m.Outs);
+ wr.WriteLine(")");
+ Indent(indent); wr.WriteLine("{");
+ foreach (Formal p in m.Outs)
+ {
+ if (!p.IsGhost)
+ {
+ Indent(indent + IndentAmount);
+ wr.WriteLine("@{0} = {1};", p.CompileName, DefaultValue(p.Type));
+ }
+ }
+ if (m.Body == null)
+ {
+ Error("Method {0} has no body", m.FullName);
+ }
+ else
+ {
+ if (m.IsTailRecursive)
+ {
+ Indent(indent); wr.WriteLine("TAIL_CALL_START: ;");
+ if (!m.IsStatic)
+ {
+ Indent(indent + IndentAmount); wr.WriteLine("var _this = this;");
+ }
+ }
+ Contract.Assert(enclosingMethod == null);
+ enclosingMethod = m;
+ TrStmtList(m.Body.Body, indent);
+ Contract.Assert(enclosingMethod == m);
+ enclosingMethod = null;
+ }
+ Indent(indent); wr.WriteLine("}");
+
+ // allow the Main method to be an instance method
+ if (!m.IsStatic && m.Name == "Main" && m.TypeArgs.Count == 0 && m.Ins.Count == 0 && m.Outs.Count == 0 && m.Req.Count == 0)
+ {
+ Indent(indent);
+ wr.WriteLine("public static void Main(string[] args) {");
+ Contract.Assert(m.EnclosingClass == c);
+ Indent(indent + IndentAmount);
+ wr.Write("@{0} b = new @{0}", c.CompileName);
+ if (c.TypeArgs.Count != 0)
+ {
+ // instantiate every parameter, it doesn't particularly matter how
+ wr.Write("<");
+ string sep = "";
+ for (int i = 0; i < c.TypeArgs.Count; i++)
+ {
+ wr.Write("{0}int", sep);
+ sep = ", ";
+ }
+ wr.Write(">");
+ }
+ wr.WriteLine("();");
+ Indent(indent + IndentAmount); wr.WriteLine("b.@Main();");
+ Indent(indent); wr.WriteLine("}");
+ }
}
- wr.WriteLine("();");
- Indent(indent + IndentAmount); wr.WriteLine("b.@Main();");
- Indent(indent); wr.WriteLine("}");
- }
}
-
} else {
Contract.Assert(false); throw new cce.UnreachableException(); // unexpected member
}
@@ -1536,8 +1665,6 @@ namespace Microsoft.Dafny {
// ...
// }
if (s.Cases.Count != 0) {
- var sourceType = (UserDefinedType)s.Source.Type;
-
SpillLetVariableDecls(s.Source, indent);
string source = "_source" + tmpVarCount;
tmpVarCount++;
@@ -1547,6 +1674,7 @@ namespace Microsoft.Dafny {
wr.WriteLine(";");
int i = 0;
+ var sourceType = (UserDefinedType)s.Source.Type.NormalizeExpand();
foreach (MatchCaseStmt mc in s.Cases) {
MatchCasePrelude(source, sourceType, cce.NonNull(mc.Ctor), mc.Arguments, i, s.Cases.Count, indent);
TrStmtList(mc.Body, indent);
@@ -1764,7 +1892,14 @@ namespace Microsoft.Dafny {
wr.Write("@" + receiverReplacement);
} else if (s.Method.IsStatic) {
Indent(indent);
- wr.Write(TypeName(cce.NonNull(s.Receiver.Type)));
+ if (s.Receiver.Type is UserDefinedType && ((UserDefinedType)s.Receiver.Type).ResolvedClass is TraitDecl)
+ {
+ wr.Write("@_Companion_{0}", TypeName(cce.NonNull(s.Receiver.Type)).Replace("@", string.Empty));
+ }
+ else
+ {
+ wr.Write(TypeName(cce.NonNull(s.Receiver.Type)));
+ }
} else {
SpillLetVariableDecls(s.Receiver, indent);
Indent(indent);
@@ -1813,7 +1948,7 @@ namespace Microsoft.Dafny {
if (tp.ArrayDimensions == null) {
wr.Write("new {0}()", TypeName(tp.EType));
} else {
- if (tp.EType is IntType || tp.EType.IsTypeParameter) {
+ if (tp.EType.IsIntegerType || tp.EType.IsTypeParameter) {
// Because the default constructor for BigInteger does not generate a valid BigInteger, we have
// to excplicitly initialize the elements of an integer array. This is all done in a helper routine.
wr.Write("Dafny.Helpers.InitNewArray{0}<{1}>", tp.ArrayDimensions.Count, TypeName(tp.EType));
@@ -1995,24 +2130,24 @@ namespace Microsoft.Dafny {
wr.Write(enclosingMethod != null && enclosingMethod.IsTailRecursive ? "_this" : "this");
} else if (expr is IdentifierExpr) {
- IdentifierExpr e = (IdentifierExpr)expr;
+ var e = (IdentifierExpr)expr;
wr.Write("@" + e.Var.CompileName);
} else if (expr is SetDisplayExpr) {
- SetDisplayExpr e = (SetDisplayExpr)expr;
- Type elType = cce.NonNull((SetType)e.Type).Arg;
+ var e = (SetDisplayExpr)expr;
+ var elType = e.Type.AsSetType.Arg;
wr.Write("{0}<{1}>.FromElements", DafnySetClass, TypeName(elType));
TrExprList(e.Elements);
} else if (expr is MultiSetDisplayExpr) {
- MultiSetDisplayExpr e = (MultiSetDisplayExpr)expr;
- Type elType = cce.NonNull((MultiSetType)e.Type).Arg;
+ var e = (MultiSetDisplayExpr)expr;
+ var elType = e.Type.AsMultiSetType.Arg;
wr.Write("{0}<{1}>.FromElements", DafnyMultiSetClass, TypeName(elType));
TrExprList(e.Elements);
} else if (expr is SeqDisplayExpr) {
- SeqDisplayExpr e = (SeqDisplayExpr)expr;
- Type elType = cce.NonNull((SeqType)e.Type).Arg;
+ var e = (SeqDisplayExpr)expr;
+ var elType = e.Type.AsSeqType.Arg;
wr.Write("{0}<{1}>.FromElements", DafnySeqClass, TypeName(elType));
TrExprList(e.Elements);
@@ -2067,11 +2202,12 @@ namespace Microsoft.Dafny {
}
}
} else if (expr is MultiSetFormingExpr) {
- MultiSetFormingExpr e = (MultiSetFormingExpr)expr;
- wr.Write("{0}<{1}>", DafnyMultiSetClass, TypeName(((CollectionType)e.E.Type).Arg));
- if (e.E.Type is SeqType) {
+ var e = (MultiSetFormingExpr)expr;
+ wr.Write("{0}<{1}>", DafnyMultiSetClass, TypeName(e.E.Type.AsCollectionType.Arg));
+ var eeType = e.E.Type.NormalizeExpand();
+ if (eeType is SeqType) {
TrParenExpr(".FromSeq", e.E);
- } else if (e.E.Type is SetType) {
+ } else if (eeType is SetType) {
TrParenExpr(".FromSet", e.E);
} else {
Contract.Assert(false); throw new cce.UnreachableException();
@@ -2191,7 +2327,7 @@ namespace Microsoft.Dafny {
TrParenExpr(e.E);
break;
case UnaryOpExpr.Opcode.Cardinality:
- if (cce.NonNull(e.E.Type).IsArrayType) {
+ if (e.E.Type.IsArrayType) {
wr.Write("new BigInteger(");
TrParenExpr(e.E);
wr.Write(".Length)");
@@ -2207,11 +2343,11 @@ namespace Microsoft.Dafny {
} else if (expr is ConversionExpr) {
var e = (ConversionExpr)expr;
if (e.ToType is IntType) {
- Contract.Assert(e.E.Type is RealType);
+ Contract.Assert(e.E.Type.IsRealType);
TrParenExpr(e.E);
wr.Write(".ToBigInteger()");
} else if (e.ToType is RealType) {
- Contract.Assert(e.E.Type is IntType);
+ Contract.Assert(e.E.Type.IsIntegerType);
wr.Write("new Dafny.BigRational(");
TrExpr(e.E);
wr.Write(", BigInteger.One)");
@@ -2236,10 +2372,9 @@ namespace Microsoft.Dafny {
opString = "&&"; break;
case BinaryExpr.ResolvedOpcode.EqCommon: {
- Type t = cce.NonNull(e.E0.Type);
- if (t.IsDatatype || t.IsTypeParameter) {
+ if (e.E0.Type.IsDatatype || e.E0.Type.IsTypeParameter) {
callString = "Equals";
- } else if (t.IsRefType) {
+ } else if (e.E0.Type.IsRefType) {
// Dafny's type rules are slightly different C#, so we may need a cast here.
// For example, Dafny allows x==y if x:array<T> and y:array<int> and T is some
// type parameter.
@@ -2250,11 +2385,10 @@ namespace Microsoft.Dafny {
break;
}
case BinaryExpr.ResolvedOpcode.NeqCommon: {
- Type t = cce.NonNull(e.E0.Type);
- if (t.IsDatatype || t.IsTypeParameter) {
+ if (e.E0.Type.IsDatatype || e.E0.Type.IsTypeParameter) {
preOpString = "!";
callString = "Equals";
- } else if (t.IsRefType) {
+ } else if (e.E0.Type.IsRefType) {
// Dafny's type rules are slightly different C#, so we may need a cast here.
// For example, Dafny allows x==y if x:array<T> and y:array<int> and T is some
// type parameter.
@@ -2280,7 +2414,7 @@ namespace Microsoft.Dafny {
case BinaryExpr.ResolvedOpcode.Mul:
opString = "*"; break;
case BinaryExpr.ResolvedOpcode.Div:
- if (expr.Type is IntType) {
+ if (expr.Type.IsIntegerType) {
wr.Write("Dafny.Helpers.EuclideanDivision(");
TrParenExpr(e.E0);
wr.Write(", ");
@@ -2291,7 +2425,7 @@ namespace Microsoft.Dafny {
}
break;
case BinaryExpr.ResolvedOpcode.Mod:
- if (expr.Type is IntType) {
+ if (expr.Type.IsIntegerType) {
wr.Write("Dafny.Helpers.EuclideanModulus(");
TrParenExpr(e.E0);
wr.Write(", ");
@@ -2446,7 +2580,7 @@ namespace Microsoft.Dafny {
wr.Write("throw new System.Exception();");
} else {
int i = 0;
- var sourceType = (UserDefinedType)e.Source.Type;
+ var sourceType = (UserDefinedType)e.Source.Type.NormalizeExpand();
foreach (MatchCaseExpr mc in e.Cases) {
MatchCasePrelude(source, sourceType, cce.NonNull(mc.Ctor), mc.Arguments, i, e.Cases.Count, 0);
wr.Write("return ");
@@ -2529,7 +2663,7 @@ namespace Microsoft.Dafny {
// return Dafny.Set<G>.FromCollection(_coll);
// })()
Contract.Assert(e.Bounds != null); // the resolver would have insisted on finding bounds
- var typeName = TypeName(((SetType)e.Type).Arg);
+ var typeName = TypeName(e.Type.AsSetType.Arg);
wr.Write("((Dafny.Helpers.ComprehensionDelegate<{0}>)delegate() {{ ", typeName);
wr.Write("var _coll = new System.Collections.Generic.List<{0}>(); ", typeName);
var n = e.BoundVars.Count;
@@ -2598,8 +2732,8 @@ namespace Microsoft.Dafny {
// return Dafny.Map<U, V>.FromElements(_coll);
// })()
Contract.Assert(e.Bounds != null); // the resolver would have insisted on finding bounds
- var domtypeName = TypeName(((MapType)e.Type).Domain);
- var rantypeName = TypeName(((MapType)e.Type).Range);
+ var domtypeName = TypeName(e.Type.AsMapType.Domain);
+ var rantypeName = TypeName(e.Type.AsMapType.Range);
wr.Write("((Dafny.Helpers.MapComprehensionDelegate<{0},{1}>)delegate() {{ ", domtypeName, rantypeName);
wr.Write("var _coll = new System.Collections.Generic.List<Dafny.Pair<{0},{1}>>(); ", domtypeName, rantypeName);
var n = e.BoundVars.Count;
diff --git a/Source/Dafny/Dafny.atg b/Source/Dafny/Dafny.atg
index dffa2df8..deef9285 100644
--- a/Source/Dafny/Dafny.atg
+++ b/Source/Dafny/Dafny.atg
@@ -207,6 +207,7 @@ Dafny
// to support multiple files, create a default module only if theModule is null
DefaultModuleDecl defaultModule = (DefaultModuleDecl)((LiteralModuleDecl)theModule).ModuleDef;
// theModule should be a DefaultModuleDecl (actually, the singular DefaultModuleDecl)
+ TraitDecl/*!*/ trait;
Contract.Assert(defaultModule != null);
.)
{ "include" string (. {
@@ -227,7 +228,7 @@ Dafny
| DatatypeDecl<defaultModule, out dt> (. defaultModule.TopLevelDecls.Add(dt); .)
| OtherTypeDecl<defaultModule, out td> (. defaultModule.TopLevelDecls.Add(td); .)
| IteratorDecl<defaultModule, out iter> (. defaultModule.TopLevelDecls.Add(iter); .)
-
+ | TraitDecl<defaultModule, out trait> (. defaultModule.TopLevelDecls.Add(trait); .)
| ClassMemberDecl<membersDefaultClass, false>
}
(. // find the default class in the default module, then append membersDefaultClass to its member list
@@ -248,7 +249,8 @@ Dafny
SubModuleDecl<ModuleDefinition parent, out ModuleDecl submodule>
= (. ClassDecl/*!*/ c; DatatypeDecl/*!*/ dt; TopLevelDecl td; IteratorDecl iter;
Attributes attrs = null; IToken/*!*/ id;
- List<MemberDecl/*!*/> namedModuleDefaultClassMembers = new List<MemberDecl>();;
+ TraitDecl/*!*/ trait;
+ List<MemberDecl/*!*/> namedModuleDefaultClassMembers = new List<MemberDecl>();;
List<IToken> idRefined = null, idPath = null, idAssignment = null;
ModuleDefinition module;
ModuleDecl sm;
@@ -265,7 +267,8 @@ SubModuleDecl<ModuleDefinition parent, out ModuleDecl submodule>
"{" (. module.BodyStartTok = t; .)
{ SubModuleDecl<module, out sm> (. module.TopLevelDecls.Add(sm); .)
| ClassDecl<module, out c> (. module.TopLevelDecls.Add(c); .)
- | DatatypeDecl<module, out dt> (. module.TopLevelDecls.Add(dt); .)
+ | TraitDecl<module, out trait> (. module.TopLevelDecls.Add(trait); .)
+ | DatatypeDecl<module, out dt> (. module.TopLevelDecls.Add(dt); .)
| OtherTypeDecl<module, out td> (. module.TopLevelDecls.Add(td); .)
| IteratorDecl<module, out iter> (. module.TopLevelDecls.Add(iter); .)
| ClassMemberDecl<namedModuleDefaultClassMembers, false>
@@ -310,7 +313,8 @@ ClassDecl<ModuleDefinition/*!*/ module, out ClassDecl/*!*/ c>
= (. Contract.Requires(module != null);
Contract.Ensures(Contract.ValueAtReturn(out c) != null);
IToken/*!*/ id;
- Attributes attrs = null;
+ List<IToken>/*!*/ traitId=null;
+ Attributes attrs = null;
List<TypeParameter/*!*/> typeArgs = new List<TypeParameter/*!*/>();
List<MemberDecl/*!*/> members = new List<MemberDecl/*!*/>();
IToken bodyStart;
@@ -320,15 +324,41 @@ ClassDecl<ModuleDefinition/*!*/ module, out ClassDecl/*!*/ c>
{ Attribute<ref attrs> }
NoUSIdent<out id>
[ GenericParameters<typeArgs> ]
+ ["extends" QualifiedName<out traitId>]
"{" (. bodyStart = t; .)
{ ClassMemberDecl<members, true>
}
"}"
- (. c = new ClassDecl(id, id.val, module, typeArgs, members, attrs);
+ (. c = new ClassDecl(id, id.val, module, typeArgs, members, attrs, traitId);
c.BodyStartTok = bodyStart;
c.BodyEndTok = t;
.)
.
+
+ TraitDecl<ModuleDefinition/*!*/ module, out TraitDecl/*!*/ trait>
+ = (. Contract.Requires(module != null);
+ Contract.Ensures(Contract.ValueAtReturn(out trait) != null);
+ IToken/*!*/ id;
+ Attributes attrs = null;
+ List<TypeParameter/*!*/> typeArgs = new List<TypeParameter/*!*/>(); //traits should not support type parameters at the moment
+ List<MemberDecl/*!*/> members = new List<MemberDecl/*!*/>();
+ IToken bodyStart;
+ .)
+ SYNC
+ "trait"
+ { Attribute<ref attrs> }
+ NoUSIdent<out id>
+ [ GenericParameters<typeArgs> ]
+ "{" (. bodyStart = t; .)
+ { ClassMemberDecl<members, true>
+ }
+ "}"
+ (. trait = new TraitDecl(id, id.val, module, typeArgs, members, attrs);
+ trait.BodyStartTok = bodyStart;
+ trait.BodyEndTok = t;
+ .)
+ .
+
ClassMemberDecl<.List<MemberDecl/*!*/>/*!*/ mm, bool allowConstructors.>
= (. Contract.Requires(cce.NonNullElements(mm));
Method/*!*/ m;
diff --git a/Source/Dafny/DafnyAst.cs b/Source/Dafny/DafnyAst.cs
index 54c5c12b..ba21e377 100644
--- a/Source/Dafny/DafnyAst.cs
+++ b/Source/Dafny/DafnyAst.cs
@@ -92,7 +92,7 @@ namespace Microsoft.Dafny {
public readonly ClassDecl ObjectDecl;
public BuiltIns() {
// create class 'object'
- ObjectDecl = new ClassDecl(Token.NoToken, "object", SystemModule, new List<TypeParameter>(), new List<MemberDecl>(), DontCompile());
+ ObjectDecl = new ClassDecl(Token.NoToken, "object", SystemModule, new List<TypeParameter>(), new List<MemberDecl>(), DontCompile(), null);
SystemModule.TopLevelDecls.Add(ObjectDecl);
// add one-dimensional arrays, since they may arise during type checking
// Arrays of other dimensions may be added during parsing as the parser detects the need for these
@@ -130,7 +130,6 @@ namespace Microsoft.Dafny {
arrayTypeDecls.Add(dims, arrayClass);
SystemModule.TopLevelDecls.Add(arrayClass);
}
- udt.ResolvedClass = arrayTypeDecls[dims];
return udt;
}
@@ -331,6 +330,7 @@ namespace Microsoft.Dafny {
/// <summary>
/// Return the type that "this" stands for, getting to the bottom of proxies and following type synonyms.
/// </summary>
+ [Pure]
public Type NormalizeExpand() {
Contract.Ensures(Contract.Result<Type>() != null);
Contract.Ensures(!(Contract.Result<Type>() is TypeProxy) || ((TypeProxy)Contract.Result<Type>()).T == null); // return a proxy only if .T == null
@@ -357,22 +357,34 @@ namespace Microsoft.Dafny {
}
}
+ /// <summary>
+ /// Returns whether or not "this" and "that" denote the same type, module proxies and type synonyms.
+ /// </summary>
[Pure]
public abstract bool Equals(Type that);
+ public bool IsBoolType { get { return NormalizeExpand() is BoolType; } }
+ public bool IsIntegerType { get { return NormalizeExpand() is IntType; } }
+ public bool IsRealType { get { return NormalizeExpand() is RealType; } }
public bool IsSubrangeType {
- get { return this is NatType; }
+ get { return NormalizeExpand() is NatType; }
}
+ public CollectionType AsCollectionType { get { return NormalizeExpand() as CollectionType; } }
+ public SetType AsSetType { get { return NormalizeExpand() as SetType; } }
+ public MultiSetType AsMultiSetType { get { return NormalizeExpand() as MultiSetType; } }
+ public SeqType AsSeqType { get { return NormalizeExpand() as SeqType; } }
+ public MapType AsMapType { get { return NormalizeExpand() as MapType; } }
+
public bool IsRefType {
get {
- if (this is ObjectType) {
+ var t = NormalizeExpand();
+ if (t is ObjectType) {
return true;
} else {
- UserDefinedType udt = this as UserDefinedType;
+ var udt = t as UserDefinedType;
return udt != null && udt.ResolvedParam == null && udt.ResolvedClass is ClassDecl
&& !(udt.ResolvedClass is ArrowType.ArrowTypeDecl);
-
}
}
}
@@ -383,13 +395,14 @@ namespace Microsoft.Dafny {
}
public ArrayClassDecl/*?*/ AsArrayType {
get {
- UserDefinedType udt = UserDefinedType.DenotesClass(this);
+ var t = NormalizeExpand();
+ var udt = UserDefinedType.DenotesClass(t);
return udt == null ? null : udt.ResolvedClass as ArrayClassDecl;
}
}
public TypeSynonymDecl AsTypeSynonym {
get {
- var udt = this as UserDefinedType;
+ var udt = this as UserDefinedType; // note, it is important to use 'this' here, not 'this.NormalizeExpand()'
if (udt == null) {
return null;
} else {
@@ -404,7 +417,7 @@ namespace Microsoft.Dafny {
}
public DatatypeDecl AsDatatype {
get {
- UserDefinedType udt = this as UserDefinedType;
+ var udt = NormalizeExpand() as UserDefinedType;
if (udt == null) {
return null;
} else {
@@ -419,7 +432,7 @@ namespace Microsoft.Dafny {
}
public IndDatatypeDecl AsIndDatatype {
get {
- UserDefinedType udt = this as UserDefinedType;
+ var udt = NormalizeExpand() as UserDefinedType;
if (udt == null) {
return null;
} else {
@@ -434,7 +447,7 @@ namespace Microsoft.Dafny {
}
public CoDatatypeDecl AsCoDatatype {
get {
- UserDefinedType udt = this as UserDefinedType;
+ var udt = NormalizeExpand() as UserDefinedType;
if (udt == null) {
return null;
} else {
@@ -454,7 +467,7 @@ namespace Microsoft.Dafny {
}
public TypeParameter AsTypeParameter {
get {
- UserDefinedType ct = this as UserDefinedType;
+ var ct = NormalizeExpand() as UserDefinedType;
return ct == null ? null : ct.ResolvedParam;
}
}
@@ -468,7 +481,9 @@ namespace Microsoft.Dafny {
/// Returns true if it is known how to meaningfully compare the type's inhabitants.
/// </summary>
public bool IsOrdered {
- get { return !IsTypeParameter && !IsCoDatatype; }
+ get {
+ return !IsTypeParameter && !IsCoDatatype;
+ }
}
public void ForeachTypeComponent(Action<Type> action) {
@@ -494,7 +509,7 @@ namespace Microsoft.Dafny {
return "bool";
}
public override bool Equals(Type that) {
- return that.NormalizeExpand() is BoolType;
+ return that.IsBoolType;
}
}
@@ -630,7 +645,7 @@ namespace Microsoft.Dafny {
public ArrowTypeDecl(List<TypeParameter> tps, Function req, Function reads)
: base(Token.NoToken, "_Func" + (tps.Count-1), FunctionModule, tps,
- new List<MemberDecl>{ req, reads }, null) {
+ new List<MemberDecl>{ req, reads }, null, null) {
Arity = tps.Count-1;
Requires = req;
Reads = reads;
@@ -874,8 +889,14 @@ namespace Microsoft.Dafny {
}
public override bool Equals(Type that) {
- var t = that.NormalizeExpand() as UserDefinedType;
- return t != null && ResolvedClass == t.ResolvedClass && ResolvedParam == t.ResolvedParam;
+ var i = NormalizeExpand();
+ if (i is UserDefinedType) {
+ var ii = (UserDefinedType)i;
+ var t = that.NormalizeExpand() as UserDefinedType;
+ return t != null && ii.ResolvedClass == t.ResolvedClass && ii.ResolvedParam == t.ResolvedParam;
+ } else {
+ return i.Equals(that);
+ }
}
/// <summary>
@@ -912,6 +933,11 @@ namespace Microsoft.Dafny {
if (BuiltIns.IsTupleTypeName(Name)) {
return "(" + Util.Comma(",", TypeArgs, ty => ty.TypeName(context)) + ")";
} else {
+#if TEST_TYPE_SYNONYM_TRANSPARENCY
+ if (Name == "type#synonym#transparency#test" && ResolvedClass is TypeSynonymDecl) {
+ return ((TypeSynonymDecl)ResolvedClass).Rhs.TypeName(context);
+ }
+#endif
string s = "";
foreach (var t in Path) {
if (context != null && t == context.tok) {
@@ -1545,8 +1571,18 @@ namespace Microsoft.Dafny {
}
}
+ public class TraitDecl : ClassDecl
+ {
+ public bool IsParent { set; get; }
+ public TraitDecl(IToken tok, string name, ModuleDefinition module,
+ List<TypeParameter> typeArgs, [Captured] List<MemberDecl> members, Attributes attributes)
+ : base(tok, name, module, typeArgs, members, attributes, null) { }
+ }
+
public class ClassDecl : TopLevelDecl {
public readonly List<MemberDecl> Members;
+ public TraitDecl Trait;
+ public readonly IToken TraitId;
public bool HasConstructor; // filled in (early) during resolution; true iff there exists a member that is a Constructor
[ContractInvariantMethod]
void ObjectInvariant() {
@@ -1554,7 +1590,7 @@ namespace Microsoft.Dafny {
}
public ClassDecl(IToken tok, string name, ModuleDefinition module,
- List<TypeParameter> typeArgs, [Captured] List<MemberDecl> members, Attributes attributes)
+ List<TypeParameter> typeArgs, [Captured] List<MemberDecl> members, Attributes attributes, List<IToken> traitId)
: base(tok, name, module, typeArgs, attributes) {
Contract.Requires(tok != null);
Contract.Requires(name != null);
@@ -1562,6 +1598,8 @@ namespace Microsoft.Dafny {
Contract.Requires(cce.NonNullElements(typeArgs));
Contract.Requires(cce.NonNullElements(members));
Members = members;
+ if (traitId != null && traitId.Count > 0)
+ TraitId = traitId[0]; //there are at most one inheriting trait at the moment
}
public virtual bool IsDefaultClass {
get {
@@ -1572,7 +1610,7 @@ namespace Microsoft.Dafny {
public class DefaultClassDecl : ClassDecl {
public DefaultClassDecl(ModuleDefinition module, [Captured] List<MemberDecl> members)
- : base(Token.NoToken, "_default", module, new List<TypeParameter>(), members, null) {
+ : base(Token.NoToken, "_default", module, new List<TypeParameter>(), members, null,null) {
Contract.Requires(module != null);
Contract.Requires(cce.NonNullElements(members));
}
@@ -1588,7 +1626,7 @@ namespace Microsoft.Dafny {
public ArrayClassDecl(int dims, ModuleDefinition module, Attributes attrs)
: base(Token.NoToken, BuiltIns.ArrayClassName(dims), module,
new List<TypeParameter>(new TypeParameter[]{new TypeParameter(Token.NoToken, "arg")}),
- new List<MemberDecl>(), attrs)
+ new List<MemberDecl>(), attrs,null)
{
Contract.Requires(1 <= dims);
Contract.Requires(module != null);
@@ -1843,7 +1881,7 @@ namespace Microsoft.Dafny {
List<MaybeFreeExpression> yieldRequires,
List<MaybeFreeExpression> yieldEnsures,
BlockStmt body, Attributes attributes, IToken signatureEllipsis)
- : base(tok, name, module, typeArgs, new List<MemberDecl>(), attributes)
+ : base(tok, name, module, typeArgs, new List<MemberDecl>(), attributes,null)
{
Contract.Requires(tok != null);
Contract.Requires(name != null);
@@ -1917,7 +1955,7 @@ namespace Microsoft.Dafny {
public readonly bool IsGhost;
public TopLevelDecl EnclosingClass; // filled in during resolution
public MemberDecl RefinementBase; // filled in during the pre-resolution refinement transformation; null if the member is new here
-
+ public bool Inherited;
public MemberDecl(IToken tok, string name, bool isStatic, bool isGhost, Attributes attributes)
: base(tok, name, attributes) {
Contract.Requires(tok != null);
@@ -2379,6 +2417,7 @@ namespace Microsoft.Dafny {
public bool SignatureIsOmitted { get { return SignatureEllipsis != null; } } // is "false" for all Function objects that survive into resolution
public readonly IToken SignatureEllipsis;
public bool IsBuiltin;
+ public Function OverriddenFunction;
public Type Type {
get {
@@ -2554,6 +2593,7 @@ namespace Microsoft.Dafny {
public bool IsRecursive; // filled in during resolution
public bool IsTailRecursive; // filled in during resolution
public readonly ISet<IVariable> AssignedAssumptionVariables = new HashSet<IVariable>();
+ public Method OverriddenMethod;
[ContractInvariantMethod]
void ObjectInvariant() {
@@ -4396,6 +4436,13 @@ namespace Microsoft.Dafny {
type = value.Normalize();
}
}
+#if TEST_TYPE_SYNONYM_TRANSPARENCY
+ public void DebugTest_ChangeType(Type ty) {
+ Contract.Requires(WasResolved()); // we're here to set it again
+ Contract.Requires(ty != null);
+ type = ty;
+ }
+#endif
public Expression(IToken tok) {
Contract.Requires(tok != null);
@@ -4413,7 +4460,7 @@ namespace Microsoft.Dafny {
public static IEnumerable<Expression> Conjuncts(Expression expr) {
Contract.Requires(expr != null);
- Contract.Requires(expr.Type is BoolType);
+ Contract.Requires(expr.Type.IsBoolType);
Contract.Ensures(cce.NonNullElements(Contract.Result<IEnumerable<Expression>>()));
// strip off parens
@@ -4445,7 +4492,7 @@ namespace Microsoft.Dafny {
public static Expression CreateAdd(Expression e0, Expression e1) {
Contract.Requires(e0 != null);
Contract.Requires(e1 != null);
- Contract.Requires((e0.Type is IntType && e1.Type is IntType) || (e0.Type is RealType && e1.Type is RealType));
+ Contract.Requires((e0.Type.NormalizeExpand() is IntType && e1.Type.NormalizeExpand() is IntType) || (e0.Type.NormalizeExpand() is RealType && e1.Type.NormalizeExpand() is RealType));
Contract.Ensures(Contract.Result<Expression>() != null);
var s = new BinaryExpr(e0.tok, BinaryExpr.Opcode.Add, e0, e1);
s.ResolvedOp = BinaryExpr.ResolvedOpcode.Add; // resolve here
@@ -4459,7 +4506,7 @@ namespace Microsoft.Dafny {
public static Expression CreateSubtract(Expression e0, Expression e1) {
Contract.Requires(e0 != null);
Contract.Requires(e1 != null);
- Contract.Requires((e0.Type is IntType && e1.Type is IntType) || (e0.Type is RealType && e1.Type is RealType));
+ Contract.Requires((e0.Type.NormalizeExpand() is IntType && e1.Type.NormalizeExpand() is IntType) || (e0.Type.NormalizeExpand() is RealType && e1.Type.NormalizeExpand() is RealType));
Contract.Ensures(Contract.Result<Expression>() != null);
var s = new BinaryExpr(e0.tok, BinaryExpr.Opcode.Sub, e0, e1);
s.ResolvedOp = BinaryExpr.ResolvedOpcode.Sub; // resolve here
@@ -4472,7 +4519,7 @@ namespace Microsoft.Dafny {
/// </summary>
public static Expression CreateIncrement(Expression e, int n) {
Contract.Requires(e != null);
- Contract.Requires(e.Type is IntType);
+ Contract.Requires(e.Type.NormalizeExpand() is IntType);
Contract.Requires(0 <= n);
Contract.Ensures(Contract.Result<Expression>() != null);
if (n == 0) {
@@ -4487,7 +4534,7 @@ namespace Microsoft.Dafny {
/// </summary>
public static Expression CreateDecrement(Expression e, int n) {
Contract.Requires(e != null);
- Contract.Requires(e.Type is IntType);
+ Contract.Requires(e.Type.NormalizeExpand() is IntType);
Contract.Requires(0 <= n);
Contract.Ensures(Contract.Result<Expression>() != null);
if (n == 0) {
@@ -4524,7 +4571,7 @@ namespace Microsoft.Dafny {
public static Expression CreateNot(IToken tok, Expression e) {
Contract.Requires(tok != null);
- Contract.Requires(e.Type is BoolType);
+ Contract.Requires(e.Type.IsBoolType);
var un = new UnaryOpExpr(tok, UnaryOpExpr.Opcode.Not, e);
un.Type = Type.Bool; // resolve here
return un;
@@ -4536,7 +4583,7 @@ namespace Microsoft.Dafny {
public static Expression CreateLess(Expression e0, Expression e1) {
Contract.Requires(e0 != null);
Contract.Requires(e1 != null);
- Contract.Requires(e0.Type is IntType && e1.Type is IntType);
+ Contract.Requires(e0.Type.NormalizeExpand() is IntType && e1.Type.NormalizeExpand() is IntType);
Contract.Ensures(Contract.Result<Expression>() != null);
var s = new BinaryExpr(e0.tok, BinaryExpr.Opcode.Lt, e0, e1);
s.ResolvedOp = BinaryExpr.ResolvedOpcode.Lt; // resolve here
@@ -4550,7 +4597,7 @@ namespace Microsoft.Dafny {
public static Expression CreateAtMost(Expression e0, Expression e1) {
Contract.Requires(e0 != null);
Contract.Requires(e1 != null);
- Contract.Requires((e0.Type is IntType && e1.Type is IntType) || (e0.Type is RealType && e1.Type is RealType));
+ Contract.Requires((e0.Type.NormalizeExpand() is IntType && e1.Type.NormalizeExpand() is IntType) || (e0.Type.NormalizeExpand() is RealType && e1.Type.NormalizeExpand() is RealType));
Contract.Ensures(Contract.Result<Expression>() != null);
var s = new BinaryExpr(e0.tok, BinaryExpr.Opcode.Le, e0, e1);
s.ResolvedOp = BinaryExpr.ResolvedOpcode.Le; // resolve here
@@ -4584,7 +4631,7 @@ namespace Microsoft.Dafny {
public static Expression CreateAnd(Expression a, Expression b) {
Contract.Requires(a != null);
Contract.Requires(b != null);
- Contract.Requires(a.Type is BoolType && b.Type is BoolType);
+ Contract.Requires(a.Type.IsBoolType && b.Type.IsBoolType);
Contract.Ensures(Contract.Result<Expression>() != null);
if (LiteralExpr.IsTrue(a)) {
return b;
@@ -4604,7 +4651,7 @@ namespace Microsoft.Dafny {
public static Expression CreateImplies(Expression a, Expression b) {
Contract.Requires(a != null);
Contract.Requires(b != null);
- Contract.Requires(a.Type is BoolType && b.Type is BoolType);
+ Contract.Requires(a.Type.IsBoolType && b.Type.IsBoolType);
Contract.Ensures(Contract.Result<Expression>() != null);
if (LiteralExpr.IsTrue(a) || LiteralExpr.IsTrue(b)) {
return b;
@@ -4623,7 +4670,7 @@ namespace Microsoft.Dafny {
Contract.Requires(test != null);
Contract.Requires(e0 != null);
Contract.Requires(e1 != null);
- Contract.Requires(test.Type is BoolType && e0.Type.Equals(e1.Type));
+ Contract.Requires(test.Type.IsBoolType && e0.Type.Equals(e1.Type));
Contract.Ensures(Contract.Result<Expression>() != null);
var ite = new ITEExpr(test.tok, test, e0, e1);
ite.Type = e0.type; // resolve here
diff --git a/Source/Dafny/Parser.cs b/Source/Dafny/Parser.cs
index b812bf1d..9da363a2 100644
--- a/Source/Dafny/Parser.cs
+++ b/Source/Dafny/Parser.cs
@@ -32,7 +32,7 @@ public class Parser {
public const int _closeparen = 16;
public const int _star = 17;
public const int _notIn = 18;
- public const int maxT = 127;
+ public const int maxT = 129;
const bool T = true;
const bool x = false;
@@ -255,6 +255,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
// to support multiple files, create a default module only if theModule is null
DefaultModuleDecl defaultModule = (DefaultModuleDecl)((LiteralModuleDecl)theModule).ModuleDef;
// theModule should be a DefaultModuleDecl (actually, the singular DefaultModuleDecl)
+ TraitDecl/*!*/ trait;
Contract.Assert(defaultModule != null);
while (la.kind == 19) {
@@ -285,22 +286,27 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
defaultModule.TopLevelDecls.Add(c);
break;
}
- case 31: case 32: {
+ case 33: case 34: {
DatatypeDecl(defaultModule, out dt);
defaultModule.TopLevelDecls.Add(dt);
break;
}
- case 36: {
+ case 38: {
OtherTypeDecl(defaultModule, out td);
defaultModule.TopLevelDecls.Add(td);
break;
}
- case 38: {
+ case 40: {
IteratorDecl(defaultModule, out iter);
defaultModule.TopLevelDecls.Add(iter);
break;
}
- case 29: case 30: case 34: case 44: case 45: case 46: case 47: case 48: case 64: case 65: case 66: {
+ case 30: {
+ TraitDecl(defaultModule, out trait);
+ defaultModule.TopLevelDecls.Add(trait);
+ break;
+ }
+ case 31: case 32: case 36: case 46: case 47: case 48: case 49: case 50: case 66: case 67: case 68: {
ClassMemberDecl(membersDefaultClass, false);
break;
}
@@ -324,6 +330,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
void SubModuleDecl(ModuleDefinition parent, out ModuleDecl submodule) {
ClassDecl/*!*/ c; DatatypeDecl/*!*/ dt; TopLevelDecl td; IteratorDecl iter;
Attributes attrs = null; IToken/*!*/ id;
+ TraitDecl/*!*/ trait;
List<MemberDecl/*!*/> namedModuleDefaultClassMembers = new List<MemberDecl>();;
List<IToken> idRefined = null, idPath = null, idAssignment = null;
ModuleDefinition module;
@@ -361,22 +368,27 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
module.TopLevelDecls.Add(c);
break;
}
- case 31: case 32: {
+ case 30: {
+ TraitDecl(module, out trait);
+ module.TopLevelDecls.Add(trait);
+ break;
+ }
+ case 33: case 34: {
DatatypeDecl(module, out dt);
module.TopLevelDecls.Add(dt);
break;
}
- case 36: {
+ case 38: {
OtherTypeDecl(module, out td);
module.TopLevelDecls.Add(td);
break;
}
- case 38: {
+ case 40: {
IteratorDecl(module, out iter);
module.TopLevelDecls.Add(iter);
break;
}
- case 29: case 30: case 34: case 44: case 45: case 46: case 47: case 48: case 64: case 65: case 66: {
+ case 31: case 32: case 36: case 46: case 47: case 48: case 49: case 50: case 66: case 67: case 68: {
ClassMemberDecl(namedModuleDefaultClassMembers, false);
break;
}
@@ -409,7 +421,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
}
}
if (la.kind == 8) {
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(128); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(130); Get();}
Get();
}
if (submodule == null) {
@@ -418,34 +430,39 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
submodule = new AliasModuleDecl(idPath, id, parent, opened);
}
- } else SynErr(129);
+ } else SynErr(131);
}
void ClassDecl(ModuleDefinition/*!*/ module, out ClassDecl/*!*/ c) {
Contract.Requires(module != null);
Contract.Ensures(Contract.ValueAtReturn(out c) != null);
IToken/*!*/ id;
+ List<IToken>/*!*/ traitId=null;
Attributes attrs = null;
List<TypeParameter/*!*/> typeArgs = new List<TypeParameter/*!*/>();
List<MemberDecl/*!*/> members = new List<MemberDecl/*!*/>();
IToken bodyStart;
- while (!(la.kind == 0 || la.kind == 28)) {SynErr(130); Get();}
+ while (!(la.kind == 0 || la.kind == 28)) {SynErr(132); Get();}
Expect(28);
while (la.kind == 13) {
Attribute(ref attrs);
}
NoUSIdent(out id);
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericParameters(typeArgs);
}
+ if (la.kind == 29) {
+ Get();
+ QualifiedName(out traitId);
+ }
Expect(13);
bodyStart = t;
while (StartOf(2)) {
ClassMemberDecl(members, true);
}
Expect(14);
- c = new ClassDecl(id, id.val, module, typeArgs, members, attrs);
+ c = new ClassDecl(id, id.val, module, typeArgs, members, attrs, traitId);
c.BodyStartTok = bodyStart;
c.BodyEndTok = t;
@@ -461,29 +478,29 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
IToken bodyStart = Token.NoToken; // dummy assignment
bool co = false;
- while (!(la.kind == 0 || la.kind == 31 || la.kind == 32)) {SynErr(131); Get();}
- if (la.kind == 31) {
+ while (!(la.kind == 0 || la.kind == 33 || la.kind == 34)) {SynErr(133); Get();}
+ if (la.kind == 33) {
Get();
- } else if (la.kind == 32) {
+ } else if (la.kind == 34) {
Get();
co = true;
- } else SynErr(132);
+ } else SynErr(134);
while (la.kind == 13) {
Attribute(ref attrs);
}
NoUSIdent(out id);
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericParameters(typeArgs);
}
Expect(25);
bodyStart = t;
DatatypeMemberDecl(ctors);
- while (la.kind == 33) {
+ while (la.kind == 35) {
Get();
DatatypeMemberDecl(ctors);
}
if (la.kind == 8) {
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(133); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(135); Get();}
Get();
}
if (co) {
@@ -504,21 +521,21 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
td = null;
Type ty;
- Expect(36);
+ Expect(38);
while (la.kind == 13) {
Attribute(ref attrs);
}
NoUSIdent(out id);
if (la.kind == 15) {
Get();
- Expect(37);
+ Expect(39);
Expect(16);
eqSupport = TypeParameter.EqualitySupportValue.Required;
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericParameters(typeArgs);
}
} else if (StartOf(3)) {
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericParameters(typeArgs);
}
if (la.kind == 25) {
@@ -526,13 +543,13 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Type(out ty);
td = new TypeSynonymDecl(id, id.val, typeArgs, module, ty, attrs);
}
- } else SynErr(134);
+ } else SynErr(136);
if (td == null) {
td = new OpaqueTypeDecl(id, id.val, module, eqSupport, typeArgs, attrs);
}
if (la.kind == 8) {
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(135); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(137); Get();}
Get();
}
}
@@ -561,19 +578,19 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
IToken bodyStart = Token.NoToken;
IToken bodyEnd = Token.NoToken;
- while (!(la.kind == 0 || la.kind == 38)) {SynErr(136); Get();}
- Expect(38);
+ while (!(la.kind == 0 || la.kind == 40)) {SynErr(138); Get();}
+ Expect(40);
while (la.kind == 13) {
Attribute(ref attrs);
}
NoUSIdent(out id);
- if (la.kind == 15 || la.kind == 42) {
- if (la.kind == 42) {
+ if (la.kind == 15 || la.kind == 44) {
+ if (la.kind == 44) {
GenericParameters(typeArgs);
}
Formals(true, true, ins, out openParen);
- if (la.kind == 39 || la.kind == 40) {
- if (la.kind == 39) {
+ if (la.kind == 41 || la.kind == 42) {
+ if (la.kind == 41) {
Get();
} else {
Get();
@@ -581,10 +598,10 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
}
Formals(false, true, outs, out openParen);
}
- } else if (la.kind == 41) {
+ } else if (la.kind == 43) {
Get();
signatureEllipsis = t; openParen = Token.NoToken;
- } else SynErr(137);
+ } else SynErr(139);
while (StartOf(4)) {
IteratorSpec(reads, mod, decreases, req, ens, yieldReq, yieldEns, ref readsAttrs, ref modAttrs, ref decrAttrs);
}
@@ -602,14 +619,44 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
}
+ void TraitDecl(ModuleDefinition/*!*/ module, out TraitDecl/*!*/ trait) {
+ Contract.Requires(module != null);
+ Contract.Ensures(Contract.ValueAtReturn(out trait) != null);
+ IToken/*!*/ id;
+ Attributes attrs = null;
+ List<TypeParameter/*!*/> typeArgs = new List<TypeParameter/*!*/>(); //traits should not support type parameters at the moment
+ List<MemberDecl/*!*/> members = new List<MemberDecl/*!*/>();
+ IToken bodyStart;
+
+ while (!(la.kind == 0 || la.kind == 30)) {SynErr(140); Get();}
+ Expect(30);
+ while (la.kind == 13) {
+ Attribute(ref attrs);
+ }
+ NoUSIdent(out id);
+ if (la.kind == 44) {
+ GenericParameters(typeArgs);
+ }
+ Expect(13);
+ bodyStart = t;
+ while (StartOf(2)) {
+ ClassMemberDecl(members, true);
+ }
+ Expect(14);
+ trait = new TraitDecl(id, id.val, module, typeArgs, members, attrs);
+ trait.BodyStartTok = bodyStart;
+ trait.BodyEndTok = t;
+
+ }
+
void ClassMemberDecl(List<MemberDecl/*!*/>/*!*/ mm, bool allowConstructors) {
Contract.Requires(cce.NonNullElements(mm));
Method/*!*/ m;
Function/*!*/ f;
MemberModifiers mmod = new MemberModifiers();
- while (la.kind == 29 || la.kind == 30) {
- if (la.kind == 29) {
+ while (la.kind == 31 || la.kind == 32) {
+ if (la.kind == 31) {
Get();
mmod.IsGhost = true;
} else {
@@ -617,15 +664,15 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
mmod.IsStatic = true;
}
}
- if (la.kind == 34) {
+ if (la.kind == 36) {
FieldDecl(mmod, mm);
- } else if (la.kind == 64 || la.kind == 65 || la.kind == 66) {
+ } else if (la.kind == 66 || la.kind == 67 || la.kind == 68) {
FunctionDecl(mmod, out f);
mm.Add(f);
} else if (StartOf(5)) {
MethodDecl(mmod, allowConstructors, out m);
mm.Add(m);
- } else SynErr(138);
+ } else SynErr(141);
}
void Attribute(ref Attributes attrs) {
@@ -648,7 +695,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
IToken id; IToken idPrime; ids = new List<IToken>();
Ident(out id);
ids.Add(id);
- while (la.kind == 63) {
+ while (la.kind == 65) {
IdentOrDigitsSuffix(out id, out idPrime);
ids.Add(id);
if (idPrime != null) { ids.Add(idPrime); }
@@ -667,7 +714,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
x = Token.NoToken;
y = null;
- Expect(63);
+ Expect(65);
if (la.kind == 1) {
Get();
x = t;
@@ -701,7 +748,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
} else if (la.kind == 11) {
Get();
x = t;
- } else SynErr(139);
+ } else SynErr(142);
}
void GenericParameters(List<TypeParameter/*!*/>/*!*/ typeArgs) {
@@ -709,29 +756,29 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
IToken/*!*/ id;
TypeParameter.EqualitySupportValue eqSupport;
- Expect(42);
+ Expect(44);
NoUSIdent(out id);
eqSupport = TypeParameter.EqualitySupportValue.Unspecified;
if (la.kind == 15) {
Get();
- Expect(37);
+ Expect(39);
Expect(16);
eqSupport = TypeParameter.EqualitySupportValue.Required;
}
typeArgs.Add(new TypeParameter(id, id.val, eqSupport));
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
NoUSIdent(out id);
eqSupport = TypeParameter.EqualitySupportValue.Unspecified;
if (la.kind == 15) {
Get();
- Expect(37);
+ Expect(39);
Expect(16);
eqSupport = TypeParameter.EqualitySupportValue.Required;
}
typeArgs.Add(new TypeParameter(id, id.val, eqSupport));
}
- Expect(43);
+ Expect(45);
}
void FieldDecl(MemberModifiers mmod, List<MemberDecl/*!*/>/*!*/ mm) {
@@ -739,8 +786,8 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Attributes attrs = null;
IToken/*!*/ id; Type/*!*/ ty;
- while (!(la.kind == 0 || la.kind == 34)) {SynErr(140); Get();}
- Expect(34);
+ while (!(la.kind == 0 || la.kind == 36)) {SynErr(143); Get();}
+ Expect(36);
if (mmod.IsStatic) { SemErr(t, "fields cannot be declared 'static'"); }
while (la.kind == 13) {
@@ -748,12 +795,12 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
}
FIdentType(out id, out ty);
mm.Add(new Field(id, id.val, mmod.IsGhost, ty, attrs));
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
FIdentType(out id, out ty);
mm.Add(new Field(id, id.val, mmod.IsGhost, ty, attrs));
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(141); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(144); Get();}
Expect(8);
}
@@ -776,9 +823,9 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
IToken bodyEnd = Token.NoToken;
IToken signatureEllipsis = null;
- if (la.kind == 64) {
+ if (la.kind == 66) {
Get();
- if (la.kind == 44) {
+ if (la.kind == 46) {
Get();
isFunctionMethod = true;
}
@@ -788,22 +835,22 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Attribute(ref attrs);
}
NoUSIdent(out id);
- if (la.kind == 15 || la.kind == 42) {
- if (la.kind == 42) {
+ if (la.kind == 15 || la.kind == 44) {
+ if (la.kind == 44) {
GenericParameters(typeArgs);
}
Formals(true, isFunctionMethod, formals, out openParen);
Expect(7);
Type(out returnType);
- } else if (la.kind == 41) {
+ } else if (la.kind == 43) {
Get();
signatureEllipsis = t;
openParen = Token.NoToken;
- } else SynErr(142);
- } else if (la.kind == 65) {
+ } else SynErr(145);
+ } else if (la.kind == 67) {
Get();
isPredicate = true;
- if (la.kind == 44) {
+ if (la.kind == 46) {
Get();
isFunctionMethod = true;
}
@@ -814,7 +861,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
}
NoUSIdent(out id);
if (StartOf(6)) {
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericParameters(typeArgs);
}
if (la.kind == 15) {
@@ -824,12 +871,12 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
SemErr(t, "predicates do not have an explicitly declared return type; it is always bool");
}
}
- } else if (la.kind == 41) {
+ } else if (la.kind == 43) {
Get();
signatureEllipsis = t;
openParen = Token.NoToken;
- } else SynErr(143);
- } else if (la.kind == 66) {
+ } else SynErr(146);
+ } else if (la.kind == 68) {
Get();
isCoPredicate = true;
if (mmod.IsGhost) { SemErr(t, "copredicates cannot be declared 'ghost' (they are ghost by default)"); }
@@ -839,7 +886,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
}
NoUSIdent(out id);
if (StartOf(6)) {
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericParameters(typeArgs);
}
if (la.kind == 15) {
@@ -849,12 +896,12 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
SemErr(t, "copredicates do not have an explicitly declared return type; it is always bool");
}
}
- } else if (la.kind == 41) {
+ } else if (la.kind == 43) {
Get();
signatureEllipsis = t;
openParen = Token.NoToken;
- } else SynErr(144);
- } else SynErr(145);
+ } else SynErr(147);
+ } else SynErr(148);
decreases = isCoPredicate ? null : new List<Expression/*!*/>();
while (StartOf(7)) {
FunctionSpec(reqs, reads, ens, decreases);
@@ -905,21 +952,21 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
IToken bodyStart = Token.NoToken;
IToken bodyEnd = Token.NoToken;
- while (!(StartOf(8))) {SynErr(146); Get();}
- if (la.kind == 44) {
+ while (!(StartOf(8))) {SynErr(149); Get();}
+ if (la.kind == 46) {
Get();
- } else if (la.kind == 45) {
+ } else if (la.kind == 47) {
Get();
isLemma = true;
- } else if (la.kind == 46) {
+ } else if (la.kind == 48) {
Get();
isCoLemma = true;
- } else if (la.kind == 47) {
+ } else if (la.kind == 49) {
Get();
isCoLemma = true;
errors.Warning(t, "the 'comethod' keyword has been deprecated; it has been renamed to 'colemma'");
- } else if (la.kind == 48) {
+ } else if (la.kind == 50) {
Get();
if (allowConstructor) {
isConstructor = true;
@@ -927,7 +974,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
SemErr(t, "constructors are only allowed in classes");
}
- } else SynErr(147);
+ } else SynErr(150);
keywordToken = t;
if (isLemma) {
if (mmod.IsGhost) {
@@ -960,20 +1007,20 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
}
}
- if (la.kind == 15 || la.kind == 42) {
- if (la.kind == 42) {
+ if (la.kind == 15 || la.kind == 44) {
+ if (la.kind == 44) {
GenericParameters(typeArgs);
}
Formals(true, !mmod.IsGhost, ins, out openParen);
- if (la.kind == 40) {
+ if (la.kind == 42) {
Get();
if (isConstructor) { SemErr(t, "constructors cannot have out-parameters"); }
Formals(false, !mmod.IsGhost, outs, out openParen);
}
- } else if (la.kind == 41) {
+ } else if (la.kind == 43) {
Get();
signatureEllipsis = t; openParen = Token.NoToken;
- } else SynErr(148);
+ } else SynErr(151);
while (StartOf(9)) {
MethodSpec(req, mod, ens, dec, ref decAttrs, ref modAttrs);
}
@@ -1029,7 +1076,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
if (StartOf(10)) {
TypeIdentOptional(out id, out name, out ty, out isGhost);
formals.Add(new Formal(id, name, ty, true, isGhost));
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
TypeIdentOptional(out id, out name, out ty, out isGhost);
formals.Add(new Formal(id, name, ty, true, isGhost));
@@ -1047,7 +1094,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
} else if (la.kind == 2) {
Get();
id = t;
- } else SynErr(149);
+ } else SynErr(152);
Expect(7);
Type(out ty);
}
@@ -1061,7 +1108,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Contract.Ensures(Contract.ValueAtReturn(out id)!=null);
Contract.Ensures(Contract.ValueAtReturn(out ty)!=null);
isGhost = false;
- if (la.kind == 29) {
+ if (la.kind == 31) {
Get();
if (allowGhostKeyword) { isGhost = true; } else { SemErr(t, "formal cannot be declared 'ghost' in this context"); }
}
@@ -1119,7 +1166,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Contract.Ensures(Contract.ValueAtReturn(out ty)!=null);
Contract.Ensures(Contract.ValueAtReturn(out identName)!=null);
string name = null; id = Token.NoToken; ty = new BoolType()/*dummy*/; isGhost = false;
- if (la.kind == 29) {
+ if (la.kind == 31) {
Get();
isGhost = true;
}
@@ -1141,7 +1188,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
id = t; name = id.val;
Expect(7);
Type(out ty);
- } else SynErr(150);
+ } else SynErr(153);
if (name != null) {
identName = name;
} else {
@@ -1156,30 +1203,30 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
List<Type> gt = null;
switch (la.kind) {
- case 54: {
+ case 56: {
Get();
tok = t;
break;
}
- case 55: {
+ case 57: {
Get();
tok = t; ty = new NatType();
break;
}
- case 56: {
+ case 58: {
Get();
tok = t; ty = new IntType();
break;
}
- case 57: {
+ case 59: {
Get();
tok = t; ty = new RealType();
break;
}
- case 58: {
+ case 60: {
Get();
tok = t; gt = new List<Type/*!*/>();
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericInstantiation(gt);
}
if (gt.Count > 1) {
@@ -1189,10 +1236,10 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
break;
}
- case 59: {
+ case 61: {
Get();
tok = t; gt = new List<Type/*!*/>();
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericInstantiation(gt);
}
if (gt.Count > 1) {
@@ -1202,10 +1249,10 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
break;
}
- case 60: {
+ case 62: {
Get();
tok = t; gt = new List<Type/*!*/>();
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericInstantiation(gt);
}
if (gt.Count > 1) {
@@ -1215,10 +1262,10 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
break;
}
- case 61: {
+ case 63: {
Get();
tok = t; gt = new List<Type/*!*/>();
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericInstantiation(gt);
}
if (gt.Count == 0) {
@@ -1238,7 +1285,7 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
if (StartOf(11)) {
Type(out ty);
gt.Add(ty);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Type(out ty);
gt.Add(ty);
@@ -1256,11 +1303,11 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
break;
}
- case 1: case 5: case 62: {
+ case 1: case 5: case 64: {
ReferenceType(out tok, out ty);
break;
}
- default: SynErr(151); break;
+ default: SynErr(154); break;
}
if (la.kind == 10) {
Type t2;
@@ -1278,10 +1325,10 @@ bool CloseOptionalBrace(bool usesOptionalBrace) {
Contract.Requires(cce.NonNullElements(formals)); IToken/*!*/ id; Type/*!*/ ty; bool isGhost;
Expect(15);
openParen = t;
- if (la.kind == 1 || la.kind == 29) {
+ if (la.kind == 1 || la.kind == 31) {
GIdentType(allowGhostKeyword, out id, out ty, out isGhost);
formals.Add(new Formal(id, id.val, ty, incoming, isGhost));
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
GIdentType(allowGhostKeyword, out id, out ty, out isGhost);
formals.Add(new Formal(id, id.val, ty, incoming, isGhost));
@@ -1296,7 +1343,7 @@ List<MaybeFreeExpression/*!*/>/*!*/ yieldReq, List<MaybeFreeExpression/*!*/>/*!*
ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
Expression/*!*/ e; FrameExpression/*!*/ fe; bool isFree = false; bool isYield = false; Attributes ensAttrs = null;
- while (!(StartOf(12))) {SynErr(152); Get();}
+ while (!(StartOf(12))) {SynErr(155); Get();}
if (la.kind == 11) {
Get();
while (IsAttribute()) {
@@ -1305,15 +1352,15 @@ ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
if (StartOf(13)) {
FrameExpression(out fe);
reads.Add(fe);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
FrameExpression(out fe);
reads.Add(fe);
}
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(153); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(156); Get();}
Expect(8);
- } else if (la.kind == 49) {
+ } else if (la.kind == 51) {
Get();
while (IsAttribute()) {
Attribute(ref modAttrs);
@@ -1321,27 +1368,27 @@ ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
if (StartOf(13)) {
FrameExpression(out fe);
mod.Add(fe);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
FrameExpression(out fe);
mod.Add(fe);
}
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(154); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(157); Get();}
Expect(8);
} else if (StartOf(14)) {
- if (la.kind == 50) {
+ if (la.kind == 52) {
Get();
isFree = true;
}
- if (la.kind == 53) {
+ if (la.kind == 55) {
Get();
isYield = true;
}
if (la.kind == 12) {
Get();
Expression(out e, false, true);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(155); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(158); Get();}
Expect(8);
if (isYield) {
yieldReq.Add(new MaybeFreeExpression(e, isFree));
@@ -1349,13 +1396,13 @@ ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
req.Add(new MaybeFreeExpression(e, isFree));
}
- } else if (la.kind == 51) {
+ } else if (la.kind == 53) {
Get();
while (IsAttribute()) {
Attribute(ref ensAttrs);
}
Expression(out e, false, true);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(156); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(159); Get();}
Expect(8);
if (isYield) {
yieldEns.Add(new MaybeFreeExpression(e, isFree, ensAttrs));
@@ -1363,16 +1410,16 @@ ref Attributes readsAttrs, ref Attributes modAttrs, ref Attributes decrAttrs) {
ens.Add(new MaybeFreeExpression(e, isFree, ensAttrs));
}
- } else SynErr(157);
- } else if (la.kind == 52) {
+ } else SynErr(160);
+ } else if (la.kind == 54) {
Get();
while (IsAttribute()) {
Attribute(ref decrAttrs);
}
DecreasesList(decreases, false);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(158); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(161); Get();}
Expect(8);
- } else SynErr(159);
+ } else SynErr(162);
}
void BlockStmt(out BlockStmt/*!*/ block, out IToken bodyStart, out IToken bodyEnd) {
@@ -1394,8 +1441,8 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Contract.Requires(cce.NonNullElements(req)); Contract.Requires(cce.NonNullElements(mod)); Contract.Requires(cce.NonNullElements(ens)); Contract.Requires(cce.NonNullElements(decreases));
Expression/*!*/ e; FrameExpression/*!*/ fe; bool isFree = false; Attributes ensAttrs = null;
- while (!(StartOf(16))) {SynErr(160); Get();}
- if (la.kind == 49) {
+ while (!(StartOf(16))) {SynErr(163); Get();}
+ if (la.kind == 51) {
Get();
while (IsAttribute()) {
Attribute(ref modAttrs);
@@ -1403,44 +1450,44 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (StartOf(13)) {
FrameExpression(out fe);
mod.Add(fe);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
FrameExpression(out fe);
mod.Add(fe);
}
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(161); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(164); Get();}
Expect(8);
- } else if (la.kind == 12 || la.kind == 50 || la.kind == 51) {
- if (la.kind == 50) {
+ } else if (la.kind == 12 || la.kind == 52 || la.kind == 53) {
+ if (la.kind == 52) {
Get();
isFree = true;
}
if (la.kind == 12) {
Get();
Expression(out e, false, true);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(162); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(165); Get();}
Expect(8);
req.Add(new MaybeFreeExpression(e, isFree));
- } else if (la.kind == 51) {
+ } else if (la.kind == 53) {
Get();
while (IsAttribute()) {
Attribute(ref ensAttrs);
}
Expression(out e, false, true);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(163); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(166); Get();}
Expect(8);
ens.Add(new MaybeFreeExpression(e, isFree, ensAttrs));
- } else SynErr(164);
- } else if (la.kind == 52) {
+ } else SynErr(167);
+ } else if (la.kind == 54) {
Get();
while (IsAttribute()) {
Attribute(ref decAttrs);
}
DecreasesList(decreases, true);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(165); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(168); Get();}
Expect(8);
- } else SynErr(166);
+ } else SynErr(169);
}
void FrameExpression(out FrameExpression/*!*/ fe) {
@@ -1453,18 +1500,18 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (StartOf(17)) {
Expression(out e, false, false);
feTok = e.tok;
- if (la.kind == 67) {
+ if (la.kind == 69) {
Get();
Ident(out id);
fieldName = id.val; feTok = id;
}
fe = new FrameExpression(feTok, e, fieldName);
- } else if (la.kind == 67) {
+ } else if (la.kind == 69) {
Get();
Ident(out id);
fieldName = id.val;
fe = new FrameExpression(id, new ImplicitThisExpr(id), fieldName);
- } else SynErr(167);
+ } else SynErr(170);
}
void Expression(out Expression e, bool allowSemi, bool allowLambda) {
@@ -1490,7 +1537,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
decreases.Add(e);
}
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
PossiblyWildExpression(out e);
if (!allowWildcard && e is WildcardExpr) {
@@ -1504,15 +1551,15 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
void GenericInstantiation(List<Type/*!*/>/*!*/ gt) {
Contract.Requires(cce.NonNullElements(gt)); Type/*!*/ ty;
- Expect(42);
+ Expect(44);
Type(out ty);
gt.Add(ty);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Type(out ty);
gt.Add(ty);
}
- Expect(43);
+ Expect(45);
}
void ReferenceType(out IToken/*!*/ tok, out Type/*!*/ ty) {
@@ -1521,13 +1568,13 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
List<Type> gt;
List<IToken> path;
- if (la.kind == 62) {
+ if (la.kind == 64) {
Get();
tok = t; ty = new ObjectType();
} else if (la.kind == 5) {
Get();
tok = t; gt = new List<Type>();
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericInstantiation(gt);
}
int dims = tok.val.Length == 5 ? 1 : int.Parse(tok.val.Substring(5));
@@ -1537,16 +1584,16 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Ident(out tok);
gt = new List<Type>();
path = new List<IToken>();
- while (la.kind == 63) {
+ while (la.kind == 65) {
path.Add(tok);
Get();
Ident(out tok);
}
- if (la.kind == 42) {
+ if (la.kind == 44) {
GenericInstantiation(gt);
}
ty = new UserDefinedType(tok, tok.val, gt, path);
- } else SynErr(168);
+ } else SynErr(171);
}
void FunctionSpec(List<Expression/*!*/>/*!*/ reqs, List<FrameExpression/*!*/>/*!*/ reads, List<Expression/*!*/>/*!*/ ens, List<Expression/*!*/> decreases) {
@@ -1555,10 +1602,10 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Contract.Requires(decreases == null || cce.NonNullElements(decreases));
Expression/*!*/ e; FrameExpression/*!*/ fe;
if (la.kind == 12) {
- while (!(la.kind == 0 || la.kind == 12)) {SynErr(169); Get();}
+ while (!(la.kind == 0 || la.kind == 12)) {SynErr(172); Get();}
Get();
Expression(out e, false, true);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(170); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(173); Get();}
Expect(8);
reqs.Add(e);
} else if (la.kind == 11) {
@@ -1566,21 +1613,21 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (StartOf(18)) {
PossiblyWildFrameExpression(out fe);
reads.Add(fe);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
PossiblyWildFrameExpression(out fe);
reads.Add(fe);
}
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(171); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(174); Get();}
Expect(8);
- } else if (la.kind == 51) {
+ } else if (la.kind == 53) {
Get();
Expression(out e, false, true);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(172); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(175); Get();}
Expect(8);
ens.Add(e);
- } else if (la.kind == 52) {
+ } else if (la.kind == 54) {
Get();
if (decreases == null) {
SemErr(t, "'decreases' clauses are meaningless for copredicates, so they are not allowed");
@@ -1588,9 +1635,9 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
DecreasesList(decreases, false);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(173); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(176); Get();}
Expect(8);
- } else SynErr(174);
+ } else SynErr(177);
}
void FunctionBody(out Expression/*!*/ e, out IToken bodyStart, out IToken bodyEnd) {
@@ -1609,7 +1656,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
fe = new FrameExpression(t, new WildcardExpr(t), null);
} else if (StartOf(13)) {
FrameExpression(out fe);
- } else SynErr(175);
+ } else SynErr(178);
}
void LambdaSpec(out Expression req, List<FrameExpression> reads) {
@@ -1641,7 +1688,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = new WildcardExpr(t);
} else if (StartOf(17)) {
Expression(out e, false, false);
- } else SynErr(176);
+ } else SynErr(179);
}
void Stmt(List<Statement/*!*/>/*!*/ ss) {
@@ -1658,58 +1705,58 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
IToken bodyStart, bodyEnd;
int breakCount;
- while (!(StartOf(19))) {SynErr(177); Get();}
+ while (!(StartOf(19))) {SynErr(180); Get();}
switch (la.kind) {
case 13: {
BlockStmt(out bs, out bodyStart, out bodyEnd);
s = bs;
break;
}
- case 84: {
+ case 86: {
AssertStmt(out s);
break;
}
- case 74: {
+ case 76: {
AssumeStmt(out s);
break;
}
- case 85: {
+ case 87: {
PrintStmt(out s);
break;
}
- case 1: case 2: case 3: case 4: case 15: case 33: case 56: case 57: case 114: case 115: case 116: case 117: case 118: case 119: {
+ case 1: case 2: case 3: case 4: case 15: case 35: case 58: case 59: case 116: case 117: case 118: case 119: case 120: case 121: {
UpdateStmt(out s);
break;
}
- case 29: case 34: {
+ case 31: case 36: {
VarDeclStatement(out s);
break;
}
- case 78: {
+ case 80: {
IfStmt(out s);
break;
}
- case 81: {
+ case 83: {
WhileStmt(out s);
break;
}
- case 83: {
+ case 85: {
MatchStmt(out s);
break;
}
- case 86: case 87: {
+ case 88: case 89: {
ForallStmt(out s);
break;
}
- case 89: {
+ case 91: {
CalcStmt(out s);
break;
}
- case 88: {
+ case 90: {
ModifyStmt(out s);
break;
}
- case 68: {
+ case 70: {
Get();
x = t;
NoUSIdent(out id);
@@ -1718,32 +1765,32 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
s.Labels = new LList<Label>(new Label(x, id.val), s.Labels);
break;
}
- case 69: {
+ case 71: {
Get();
x = t; breakCount = 1; label = null;
if (la.kind == 1) {
NoUSIdent(out id);
label = id.val;
- } else if (la.kind == 8 || la.kind == 69) {
- while (la.kind == 69) {
+ } else if (la.kind == 8 || la.kind == 71) {
+ while (la.kind == 71) {
Get();
breakCount++;
}
- } else SynErr(178);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(179); Get();}
+ } else SynErr(181);
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(182); Get();}
Expect(8);
s = label != null ? new BreakStmt(x, t, label) : new BreakStmt(x, t, breakCount);
break;
}
- case 53: case 72: {
+ case 55: case 74: {
ReturnStmt(out s);
break;
}
- case 41: {
+ case 43: {
SkeletonStmt(out s);
break;
}
- default: SynErr(180); break;
+ default: SynErr(183); break;
}
}
@@ -1752,17 +1799,17 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expression e = dummyExpr; Attributes attrs = null;
IToken dotdotdot = null;
- Expect(84);
+ Expect(86);
x = t;
while (IsAttribute()) {
Attribute(ref attrs);
}
if (StartOf(17)) {
Expression(out e, false, true);
- } else if (la.kind == 41) {
+ } else if (la.kind == 43) {
Get();
dotdotdot = t;
- } else SynErr(181);
+ } else SynErr(184);
Expect(8);
if (dotdotdot != null) {
s = new SkeletonStatement(new AssertStmt(x, t, new LiteralExpr(x, true), attrs), dotdotdot, null);
@@ -1777,17 +1824,17 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expression e = dummyExpr; Attributes attrs = null;
IToken dotdotdot = null;
- Expect(74);
+ Expect(76);
x = t;
while (IsAttribute()) {
Attribute(ref attrs);
}
if (StartOf(17)) {
Expression(out e, false, true);
- } else if (la.kind == 41) {
+ } else if (la.kind == 43) {
Get();
dotdotdot = t;
- } else SynErr(182);
+ } else SynErr(185);
Expect(8);
if (dotdotdot != null) {
s = new SkeletonStatement(new AssumeStmt(x, t, new LiteralExpr(x, true), attrs), dotdotdot, null);
@@ -1801,11 +1848,11 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Contract.Ensures(Contract.ValueAtReturn(out s) != null); IToken/*!*/ x; Attributes.Argument/*!*/ arg;
List<Attributes.Argument/*!*/> args = new List<Attributes.Argument/*!*/>();
- Expect(85);
+ Expect(87);
x = t;
AttributeArg(out arg, false);
args.Add(arg);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
AttributeArg(out arg, false);
args.Add(arg);
@@ -1832,38 +1879,38 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
Expect(8);
endTok = t; rhss.Add(new ExprRhs(e, attrs));
- } else if (la.kind == 35 || la.kind == 71 || la.kind == 73) {
+ } else if (la.kind == 37 || la.kind == 73 || la.kind == 75) {
lhss.Add(e); lhs0 = e;
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Lhs(out e);
lhss.Add(e);
}
- if (la.kind == 71) {
+ if (la.kind == 73) {
Get();
x = t;
Rhs(out r, lhs0);
rhss.Add(r);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Rhs(out r, lhs0);
rhss.Add(r);
}
- } else if (la.kind == 73) {
+ } else if (la.kind == 75) {
Get();
x = t;
- if (la.kind == 74) {
+ if (la.kind == 76) {
Get();
suchThatAssume = t;
}
Expression(out suchThat, false, true);
- } else SynErr(183);
+ } else SynErr(186);
Expect(8);
endTok = t;
} else if (la.kind == 7) {
Get();
SemErr(t, "invalid statement (did you forget the 'label' keyword?)");
- } else SynErr(184);
+ } else SynErr(187);
if (suchThat != null) {
s = new AssignSuchThatStmt(x, endTok, lhss, suchThat, suchThatAssume);
} else {
@@ -1887,18 +1934,18 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Attributes attrs = null;
IToken endTok;
- if (la.kind == 29) {
+ if (la.kind == 31) {
Get();
isGhost = true; x = t;
}
- Expect(34);
+ Expect(36);
if (!isGhost) { x = t; }
while (la.kind == 13) {
Attribute(ref attrs);
}
LocalIdentTypeOptional(out d, isGhost);
lhss.Add(d); d.Attributes = attrs; attrs = null;
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
while (la.kind == 13) {
Attribute(ref attrs);
@@ -1906,15 +1953,15 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
LocalIdentTypeOptional(out d, isGhost);
lhss.Add(d); d.Attributes = attrs; attrs = null;
}
- if (la.kind == 71 || la.kind == 73) {
- if (la.kind == 71) {
+ if (la.kind == 73 || la.kind == 75) {
+ if (la.kind == 73) {
Get();
assignTok = t;
lhs0 = new IdentifierExpr(lhss[0].Tok, lhss[0].Name);
Rhs(out r, lhs0);
rhss.Add(r);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Rhs(out r, lhs0);
rhss.Add(r);
@@ -1922,7 +1969,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else {
Get();
assignTok = t;
- if (la.kind == 74) {
+ if (la.kind == 76) {
Get();
suchThatAssume = t;
}
@@ -1962,7 +2009,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
List<GuardedAlternative> alternatives;
ifStmt = dummyStmt; // to please the compiler
- Expect(78);
+ Expect(80);
x = t;
if (IsAlternative()) {
AlternativeBlock(out alternatives, out endTok);
@@ -1976,15 +2023,15 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
BlockStmt(out thn, out bodyStart, out bodyEnd);
endTok = thn.EndTok;
- if (la.kind == 79) {
+ if (la.kind == 81) {
Get();
- if (la.kind == 78) {
+ if (la.kind == 80) {
IfStmt(out s);
els = s; endTok = s.EndTok;
} else if (la.kind == 13) {
BlockStmt(out bs, out bodyStart, out bodyEnd);
els = bs; endTok = bs.EndTok;
- } else SynErr(185);
+ } else SynErr(188);
}
if (guardEllipsis != null) {
ifStmt = new SkeletonStatement(new IfStmt(x, endTok, guard, thn, els), guardEllipsis, null);
@@ -1992,7 +2039,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
ifStmt = new IfStmt(x, endTok, guard, thn, els);
}
- } else SynErr(186);
+ } else SynErr(189);
}
void WhileStmt(out Statement/*!*/ stmt) {
@@ -2008,7 +2055,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
List<GuardedAlternative> alternatives;
stmt = dummyStmt; // to please the compiler
- Expect(81);
+ Expect(83);
x = t;
if (IsLoopSpecOrAlternative()) {
LoopSpec(out invariants, out decreases, out mod, ref decAttrs, ref modAttrs);
@@ -2026,10 +2073,10 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 13) {
BlockStmt(out body, out bodyStart, out bodyEnd);
endTok = body.EndTok;
- } else if (la.kind == 41) {
+ } else if (la.kind == 43) {
Get();
bodyEllipsis = t; endTok = t;
- } else SynErr(187);
+ } else SynErr(190);
if (guardEllipsis != null || bodyEllipsis != null) {
if (mod != null) {
SemErr(mod[0].E.tok, "'modifies' clauses are not allowed on refining loops");
@@ -2045,7 +2092,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
stmt = new WhileStmt(x, endTok, guard, invariants, new Specification<Expression>(decreases, decAttrs), new Specification<FrameExpression>(mod, modAttrs), body);
}
- } else SynErr(188);
+ } else SynErr(191);
}
void MatchStmt(out Statement/*!*/ s) {
@@ -2054,14 +2101,14 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
List<MatchCaseStmt/*!*/> cases = new List<MatchCaseStmt/*!*/>();
bool usesOptionalBrace = false;
- Expect(83);
+ Expect(85);
x = t;
Expression(out e, true, true);
if (la.kind == 13) {
Get();
usesOptionalBrace = true;
}
- while (la.kind == 80) {
+ while (la.kind == 82) {
CaseStatement(out c);
cases.Add(c);
}
@@ -2069,7 +2116,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expect(14);
} else if (StartOf(22)) {
if (usesOptionalBrace) { SemErr(t, "expecting close curly brace"); }
- } else SynErr(189);
+ } else SynErr(192);
s = new MatchStmt(x, t, e, cases, usesOptionalBrace);
}
@@ -2087,15 +2134,15 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
IToken bodyStart, bodyEnd;
IToken tok = Token.NoToken;
- if (la.kind == 86) {
+ if (la.kind == 88) {
Get();
x = t; tok = x;
- } else if (la.kind == 87) {
+ } else if (la.kind == 89) {
Get();
x = t;
errors.Warning(t, "the 'parallel' keyword has been deprecated; the comprehension statement now uses the keyword 'forall' (and the parentheses around the bound variables are now optional)");
- } else SynErr(190);
+ } else SynErr(193);
if (la.kind == 15) {
Get();
usesOptionalParen = true;
@@ -2113,14 +2160,14 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expect(16);
} else if (StartOf(23)) {
if (usesOptionalParen) { SemErr(t, "expecting close parenthesis"); }
- } else SynErr(191);
- while (la.kind == 50 || la.kind == 51) {
+ } else SynErr(194);
+ while (la.kind == 52 || la.kind == 53) {
isFree = false;
- if (la.kind == 50) {
+ if (la.kind == 52) {
Get();
isFree = true;
}
- Expect(51);
+ Expect(53);
Expression(out e, false, true);
ens.Add(new MaybeFreeExpression(e, isFree));
Expect(8);
@@ -2154,7 +2201,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
IToken opTok;
IToken danglingOperator = null;
- Expect(89);
+ Expect(91);
x = t;
if (StartOf(24)) {
CalcOp(out opTok, out calcOp);
@@ -2207,7 +2254,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
BlockStmt body = null; IToken bodyStart;
IToken ellipsisToken = null;
- Expect(88);
+ Expect(90);
tok = t;
while (IsAttribute()) {
Attribute(ref attrs);
@@ -2216,7 +2263,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (StartOf(13)) {
FrameExpression(out fe);
mod.Add(fe);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
FrameExpression(out fe);
mod.Add(fe);
@@ -2229,10 +2276,10 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 13) {
BlockStmt(out body, out bodyStart, out endTok);
} else if (la.kind == 8) {
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(192); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(195); Get();}
Get();
endTok = t;
- } else SynErr(193);
+ } else SynErr(196);
s = new ModifyStmt(tok, endTok, mod, attrs, body);
if (ellipsisToken != null) {
s = new SkeletonStatement(s, ellipsisToken, null);
@@ -2246,17 +2293,17 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
AssignmentRhs r;
bool isYield = false;
- if (la.kind == 72) {
+ if (la.kind == 74) {
Get();
returnTok = t;
- } else if (la.kind == 53) {
+ } else if (la.kind == 55) {
Get();
returnTok = t; isYield = true;
- } else SynErr(194);
+ } else SynErr(197);
if (StartOf(26)) {
Rhs(out r, null);
rhss = new List<AssignmentRhs>(); rhss.Add(r);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Rhs(out r, null);
rhss.Add(r);
@@ -2276,22 +2323,22 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
List<Expression> exprs = null;
IToken tok, dotdotdot, whereTok;
Expression e;
- Expect(41);
+ Expect(43);
dotdotdot = t;
- if (la.kind == 70) {
+ if (la.kind == 72) {
Get();
names = new List<IToken>(); exprs = new List<Expression>(); whereTok = t;
Ident(out tok);
names.Add(tok);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Ident(out tok);
names.Add(tok);
}
- Expect(71);
+ Expect(73);
Expression(out e, false, true);
exprs.Add(e);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Expression(out e, false, true);
exprs.Add(e);
@@ -2315,21 +2362,21 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
r = dummyRhs; // to please compiler
Attributes attrs = null;
- if (la.kind == 75) {
+ if (la.kind == 77) {
Get();
newToken = t;
TypeAndToken(out x, out ty);
- if (la.kind == 15 || la.kind == 63 || la.kind == 76) {
- if (la.kind == 76) {
+ if (la.kind == 15 || la.kind == 65 || la.kind == 78) {
+ if (la.kind == 78) {
Get();
ee = new List<Expression>();
Expressions(ee);
- Expect(77);
+ Expect(79);
var tmp = theBuiltIns.ArrayType(ee.Count, new IntType(), true);
} else {
x = null; args = new List<Expression/*!*/>();
- if (la.kind == 63) {
+ if (la.kind == 65) {
Get();
Ident(out x);
}
@@ -2354,7 +2401,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (StartOf(17)) {
Expression(out e, false, true);
r = new ExprRhs(e);
- } else SynErr(195);
+ } else SynErr(198);
while (la.kind == 13) {
Attribute(ref attrs);
}
@@ -2366,24 +2413,24 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 1) {
DottedIdentifiersAndFunction(out e, false, false);
- while (la.kind == 63 || la.kind == 76) {
+ while (la.kind == 65 || la.kind == 78) {
Suffix(ref e);
}
ApplySuffix(ref e);
} else if (StartOf(27)) {
ConstAtomExpression(out e, false, false);
Suffix(ref e);
- while (la.kind == 63 || la.kind == 76) {
+ while (la.kind == 65 || la.kind == 78) {
Suffix(ref e);
}
- } else SynErr(196);
+ } else SynErr(199);
}
void Expressions(List<Expression/*!*/>/*!*/ args) {
Contract.Requires(cce.NonNullElements(args)); Expression/*!*/ e;
Expression(out e, true, true);
args.Add(e);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Expression(out e, true, true);
args.Add(e);
@@ -2397,7 +2444,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
List<Statement> body;
Expect(13);
- while (la.kind == 80) {
+ while (la.kind == 82) {
Get();
x = t;
Expression(out e, true, false);
@@ -2425,7 +2472,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (StartOf(17)) {
Expression(out ee, true, true);
e = ee;
- } else SynErr(197);
+ } else SynErr(200);
}
void LoopSpec(out List<MaybeFreeExpression/*!*/> invariants, out List<Expression/*!*/> decreases, out List<FrameExpression/*!*/> mod, ref Attributes decAttrs, ref Attributes modAttrs) {
@@ -2436,22 +2483,22 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
mod = null;
while (StartOf(28)) {
- if (la.kind == 50 || la.kind == 82) {
+ if (la.kind == 52 || la.kind == 84) {
Invariant(out invariant);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(198); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(201); Get();}
Expect(8);
invariants.Add(invariant);
- } else if (la.kind == 52) {
- while (!(la.kind == 0 || la.kind == 52)) {SynErr(199); Get();}
+ } else if (la.kind == 54) {
+ while (!(la.kind == 0 || la.kind == 54)) {SynErr(202); Get();}
Get();
while (IsAttribute()) {
Attribute(ref decAttrs);
}
DecreasesList(decreases, true);
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(200); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(203); Get();}
Expect(8);
} else {
- while (!(la.kind == 0 || la.kind == 49)) {SynErr(201); Get();}
+ while (!(la.kind == 0 || la.kind == 51)) {SynErr(204); Get();}
Get();
while (IsAttribute()) {
Attribute(ref modAttrs);
@@ -2460,13 +2507,13 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (StartOf(13)) {
FrameExpression(out fe);
mod.Add(fe);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
FrameExpression(out fe);
mod.Add(fe);
}
}
- while (!(la.kind == 0 || la.kind == 8)) {SynErr(202); Get();}
+ while (!(la.kind == 0 || la.kind == 8)) {SynErr(205); Get();}
Expect(8);
}
}
@@ -2474,12 +2521,12 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
void Invariant(out MaybeFreeExpression/*!*/ invariant) {
bool isFree = false; Expression/*!*/ e; List<string> ids = new List<string>(); invariant = null; Attributes attrs = null;
- while (!(la.kind == 0 || la.kind == 50 || la.kind == 82)) {SynErr(203); Get();}
- if (la.kind == 50) {
+ while (!(la.kind == 0 || la.kind == 52 || la.kind == 84)) {SynErr(206); Get();}
+ if (la.kind == 52) {
Get();
isFree = true;
}
- Expect(82);
+ Expect(84);
while (IsAttribute()) {
Attribute(ref attrs);
}
@@ -2494,14 +2541,14 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
BoundVar/*!*/ bv;
List<Statement/*!*/> body = new List<Statement/*!*/>();
- Expect(80);
+ Expect(82);
x = t;
Ident(out id);
if (la.kind == 15) {
Get();
IdentTypeOptional(out bv);
arguments.Add(bv);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
IdentTypeOptional(out bv);
arguments.Add(bv);
@@ -2523,7 +2570,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (StartOf(17)) {
Expression(out e, allowSemi, true);
arg = new Attributes.Argument(t, e);
- } else SynErr(204);
+ } else SynErr(207);
}
void QuantifierDomain(out List<BoundVar> bvars, out Attributes attrs, out Expression range) {
@@ -2534,7 +2581,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
IdentTypeOptional(out bv);
bvars.Add(bv);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
IdentTypeOptional(out bv);
bvars.Add(bv);
@@ -2542,7 +2589,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
while (IsAttribute()) {
Attribute(ref attrs);
}
- if (la.kind == 33) {
+ if (la.kind == 35) {
Get();
Expression(out range, true, true);
}
@@ -2554,73 +2601,73 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
x = null;
switch (la.kind) {
- case 37: {
+ case 39: {
Get();
x = t; binOp = BinaryExpr.Opcode.Eq;
- if (la.kind == 90) {
+ if (la.kind == 92) {
Get();
- Expect(76);
+ Expect(78);
Expression(out k, true, true);
- Expect(77);
+ Expect(79);
}
break;
}
- case 42: {
+ case 44: {
Get();
x = t; binOp = BinaryExpr.Opcode.Lt;
break;
}
- case 43: {
+ case 45: {
Get();
x = t; binOp = BinaryExpr.Opcode.Gt;
break;
}
- case 91: {
+ case 93: {
Get();
x = t; binOp = BinaryExpr.Opcode.Le;
break;
}
- case 92: {
+ case 94: {
Get();
x = t; binOp = BinaryExpr.Opcode.Ge;
break;
}
- case 93: {
+ case 95: {
Get();
x = t; binOp = BinaryExpr.Opcode.Neq;
break;
}
- case 94: {
+ case 96: {
Get();
x = t; binOp = BinaryExpr.Opcode.Neq;
break;
}
- case 95: {
+ case 97: {
Get();
x = t; binOp = BinaryExpr.Opcode.Le;
break;
}
- case 96: {
+ case 98: {
Get();
x = t; binOp = BinaryExpr.Opcode.Ge;
break;
}
- case 97: case 98: {
+ case 99: case 100: {
EquivOp();
x = t; binOp = BinaryExpr.Opcode.Iff;
break;
}
- case 99: case 100: {
+ case 101: case 102: {
ImpliesOp();
x = t; binOp = BinaryExpr.Opcode.Imp;
break;
}
- case 101: case 102: {
+ case 103: case 104: {
ExpliesOp();
x = t; binOp = BinaryExpr.Opcode.Exp;
break;
}
- default: SynErr(205); break;
+ default: SynErr(208); break;
}
if (k == null) {
op = new Microsoft.Dafny.CalcStmt.BinaryCalcOp(binOp);
@@ -2639,7 +2686,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Token x = la;
IToken endTok = x;
- while (la.kind == 13 || la.kind == 89) {
+ while (la.kind == 13 || la.kind == 91) {
if (la.kind == 13) {
BlockStmt(out block, out bodyStart, out bodyEnd);
endTok = block.EndTok; subhints.Add(block);
@@ -2653,33 +2700,33 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
void EquivOp() {
- if (la.kind == 97) {
+ if (la.kind == 99) {
Get();
- } else if (la.kind == 98) {
+ } else if (la.kind == 100) {
Get();
- } else SynErr(206);
+ } else SynErr(209);
}
void ImpliesOp() {
- if (la.kind == 99) {
+ if (la.kind == 101) {
Get();
- } else if (la.kind == 100) {
+ } else if (la.kind == 102) {
Get();
- } else SynErr(207);
+ } else SynErr(210);
}
void ExpliesOp() {
- if (la.kind == 101) {
+ if (la.kind == 103) {
Get();
- } else if (la.kind == 102) {
+ } else if (la.kind == 104) {
Get();
- } else SynErr(208);
+ } else SynErr(211);
}
void EquivExpression(out Expression e0, bool allowSemi, bool allowLambda) {
Contract.Ensures(Contract.ValueAtReturn(out e0) != null); IToken/*!*/ x; Expression/*!*/ e1;
ImpliesExpliesExpression(out e0, allowSemi, allowLambda);
- while (la.kind == 97 || la.kind == 98) {
+ while (la.kind == 99 || la.kind == 100) {
EquivOp();
x = t;
ImpliesExpliesExpression(out e1, allowSemi, allowLambda);
@@ -2691,7 +2738,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Contract.Ensures(Contract.ValueAtReturn(out e0) != null); IToken/*!*/ x; Expression/*!*/ e1;
LogicalExpression(out e0, allowSemi, allowLambda);
if (StartOf(29)) {
- if (la.kind == 99 || la.kind == 100) {
+ if (la.kind == 101 || la.kind == 102) {
ImpliesOp();
x = t;
ImpliesExpression(out e1, allowSemi, allowLambda);
@@ -2701,7 +2748,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
x = t;
LogicalExpression(out e1, allowSemi, allowLambda);
e0 = new BinaryExpr(x, BinaryExpr.Opcode.Exp, e0, e1);
- while (la.kind == 101 || la.kind == 102) {
+ while (la.kind == 103 || la.kind == 104) {
ExpliesOp();
x = t;
LogicalExpression(out e1, allowSemi, allowLambda);
@@ -2715,12 +2762,12 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Contract.Ensures(Contract.ValueAtReturn(out e0) != null); IToken/*!*/ x; Expression/*!*/ e1;
RelationalExpression(out e0, allowSemi, allowLambda);
if (StartOf(30)) {
- if (la.kind == 103 || la.kind == 104) {
+ if (la.kind == 105 || la.kind == 106) {
AndOp();
x = t;
RelationalExpression(out e1, allowSemi, allowLambda);
e0 = new BinaryExpr(x, BinaryExpr.Opcode.And, e0, e1);
- while (la.kind == 103 || la.kind == 104) {
+ while (la.kind == 105 || la.kind == 106) {
AndOp();
x = t;
RelationalExpression(out e1, allowSemi, allowLambda);
@@ -2731,7 +2778,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
x = t;
RelationalExpression(out e1, allowSemi, allowLambda);
e0 = new BinaryExpr(x, BinaryExpr.Opcode.Or, e0, e1);
- while (la.kind == 105 || la.kind == 106) {
+ while (la.kind == 107 || la.kind == 108) {
OrOp();
x = t;
RelationalExpression(out e1, allowSemi, allowLambda);
@@ -2744,7 +2791,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
void ImpliesExpression(out Expression e0, bool allowSemi, bool allowLambda) {
Contract.Ensures(Contract.ValueAtReturn(out e0) != null); IToken/*!*/ x; Expression/*!*/ e1;
LogicalExpression(out e0, allowSemi, allowLambda);
- if (la.kind == 99 || la.kind == 100) {
+ if (la.kind == 101 || la.kind == 102) {
ImpliesOp();
x = t;
ImpliesExpression(out e1, allowSemi, allowLambda);
@@ -2854,25 +2901,25 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
void AndOp() {
- if (la.kind == 103) {
+ if (la.kind == 105) {
Get();
- } else if (la.kind == 104) {
+ } else if (la.kind == 106) {
Get();
- } else SynErr(209);
+ } else SynErr(212);
}
void OrOp() {
- if (la.kind == 105) {
+ if (la.kind == 107) {
Get();
- } else if (la.kind == 106) {
+ } else if (la.kind == 108) {
Get();
- } else SynErr(210);
+ } else SynErr(213);
}
void Term(out Expression e0, bool allowSemi, bool allowLambda) {
Contract.Ensures(Contract.ValueAtReturn(out e0) != null); IToken/*!*/ x; Expression/*!*/ e1; BinaryExpr.Opcode op;
Factor(out e0, allowSemi, allowLambda);
- while (la.kind == 109 || la.kind == 110) {
+ while (la.kind == 111 || la.kind == 112) {
AddOp(out x, out op);
Factor(out e1, allowSemi, allowLambda);
e0 = new BinaryExpr(x, op, e0, e1);
@@ -2886,49 +2933,49 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
k = null;
switch (la.kind) {
- case 37: {
+ case 39: {
Get();
x = t; op = BinaryExpr.Opcode.Eq;
- if (la.kind == 90) {
+ if (la.kind == 92) {
Get();
- Expect(76);
+ Expect(78);
Expression(out k, true, true);
- Expect(77);
+ Expect(79);
}
break;
}
- case 42: {
+ case 44: {
Get();
x = t; op = BinaryExpr.Opcode.Lt;
break;
}
- case 43: {
+ case 45: {
Get();
x = t; op = BinaryExpr.Opcode.Gt;
break;
}
- case 91: {
+ case 93: {
Get();
x = t; op = BinaryExpr.Opcode.Le;
break;
}
- case 92: {
+ case 94: {
Get();
x = t; op = BinaryExpr.Opcode.Ge;
break;
}
- case 93: {
+ case 95: {
Get();
x = t; op = BinaryExpr.Opcode.Neq;
- if (la.kind == 90) {
+ if (la.kind == 92) {
Get();
- Expect(76);
+ Expect(78);
Expression(out k, true, true);
- Expect(77);
+ Expect(79);
}
break;
}
- case 107: {
+ case 109: {
Get();
x = t; op = BinaryExpr.Opcode.In;
break;
@@ -2938,10 +2985,10 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
x = t; op = BinaryExpr.Opcode.NotIn;
break;
}
- case 108: {
+ case 110: {
Get();
x = t; y = Token.NoToken;
- if (la.kind == 108) {
+ if (la.kind == 110) {
Get();
y = t;
}
@@ -2956,29 +3003,29 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
break;
}
- case 94: {
+ case 96: {
Get();
x = t; op = BinaryExpr.Opcode.Neq;
break;
}
- case 95: {
+ case 97: {
Get();
x = t; op = BinaryExpr.Opcode.Le;
break;
}
- case 96: {
+ case 98: {
Get();
x = t; op = BinaryExpr.Opcode.Ge;
break;
}
- default: SynErr(211); break;
+ default: SynErr(214); break;
}
}
void Factor(out Expression e0, bool allowSemi, bool allowLambda) {
Contract.Ensures(Contract.ValueAtReturn(out e0) != null); IToken/*!*/ x; Expression/*!*/ e1; BinaryExpr.Opcode op;
UnaryExpression(out e0, allowSemi, allowLambda);
- while (la.kind == 17 || la.kind == 111 || la.kind == 112) {
+ while (la.kind == 17 || la.kind == 113 || la.kind == 114) {
MulOp(out x, out op);
UnaryExpression(out e1, allowSemi, allowLambda);
e0 = new BinaryExpr(x, op, e0, e1);
@@ -2987,81 +3034,81 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
void AddOp(out IToken x, out BinaryExpr.Opcode op) {
Contract.Ensures(Contract.ValueAtReturn(out x) != null); x = Token.NoToken; op=BinaryExpr.Opcode.Add/*(dummy)*/;
- if (la.kind == 109) {
+ if (la.kind == 111) {
Get();
x = t; op = BinaryExpr.Opcode.Add;
- } else if (la.kind == 110) {
+ } else if (la.kind == 112) {
Get();
x = t; op = BinaryExpr.Opcode.Sub;
- } else SynErr(212);
+ } else SynErr(215);
}
void UnaryExpression(out Expression e, bool allowSemi, bool allowLambda) {
Contract.Ensures(Contract.ValueAtReturn(out e) != null); IToken/*!*/ x; e = dummyExpr;
switch (la.kind) {
- case 110: {
+ case 112: {
Get();
x = t;
UnaryExpression(out e, allowSemi, allowLambda);
e = new NegationExpression(x, e);
break;
}
- case 108: case 113: {
+ case 110: case 115: {
NegOp();
x = t;
UnaryExpression(out e, allowSemi, allowLambda);
e = new UnaryOpExpr(x, UnaryOpExpr.Opcode.Not, e);
break;
}
- case 29: case 34: case 58: case 68: case 74: case 78: case 83: case 84: case 86: case 89: case 122: case 123: case 124: {
+ case 31: case 36: case 60: case 70: case 76: case 80: case 85: case 86: case 88: case 91: case 124: case 125: case 126: {
EndlessExpression(out e, allowSemi, allowLambda);
break;
}
case 1: {
DottedIdentifiersAndFunction(out e, allowSemi, allowLambda);
- while (la.kind == 63 || la.kind == 76) {
+ while (la.kind == 65 || la.kind == 78) {
Suffix(ref e);
}
ApplySuffix(ref e);
break;
}
- case 13: case 76: {
+ case 13: case 78: {
DisplayExpr(out e);
- while (la.kind == 63 || la.kind == 76) {
+ while (la.kind == 65 || la.kind == 78) {
Suffix(ref e);
}
break;
}
- case 59: {
+ case 61: {
MultiSetExpr(out e);
- while (la.kind == 63 || la.kind == 76) {
+ while (la.kind == 65 || la.kind == 78) {
Suffix(ref e);
}
break;
}
- case 61: {
+ case 63: {
Get();
x = t;
- if (la.kind == 76) {
+ if (la.kind == 78) {
MapDisplayExpr(x, out e);
- while (la.kind == 63 || la.kind == 76) {
+ while (la.kind == 65 || la.kind == 78) {
Suffix(ref e);
}
} else if (la.kind == 1) {
MapComprehensionExpr(x, out e, allowSemi);
} else if (StartOf(32)) {
SemErr("map must be followed by literal in brackets or comprehension.");
- } else SynErr(213);
+ } else SynErr(216);
break;
}
- case 2: case 3: case 4: case 15: case 33: case 56: case 57: case 114: case 115: case 116: case 117: case 118: case 119: {
+ case 2: case 3: case 4: case 15: case 35: case 58: case 59: case 116: case 117: case 118: case 119: case 120: case 121: {
ConstAtomExpression(out e, allowSemi, allowLambda);
- while (la.kind == 63 || la.kind == 76) {
+ while (la.kind == 65 || la.kind == 78) {
Suffix(ref e);
}
break;
}
- default: SynErr(214); break;
+ default: SynErr(217); break;
}
}
@@ -3070,21 +3117,21 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 17) {
Get();
x = t; op = BinaryExpr.Opcode.Mul;
- } else if (la.kind == 111) {
+ } else if (la.kind == 113) {
Get();
x = t; op = BinaryExpr.Opcode.Div;
- } else if (la.kind == 112) {
+ } else if (la.kind == 114) {
Get();
x = t; op = BinaryExpr.Opcode.Mod;
- } else SynErr(215);
+ } else SynErr(218);
}
void NegOp() {
- if (la.kind == 108) {
+ if (la.kind == 110) {
Get();
- } else if (la.kind == 113) {
+ } else if (la.kind == 115) {
Get();
- } else SynErr(216);
+ } else SynErr(219);
}
void EndlessExpression(out Expression e, bool allowSemi, bool allowLambda) {
@@ -3094,44 +3141,44 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = dummyExpr;
switch (la.kind) {
- case 78: {
+ case 80: {
Get();
x = t;
Expression(out e, true, true);
- Expect(120);
+ Expect(122);
Expression(out e0, true, true);
- Expect(79);
+ Expect(81);
Expression(out e1, allowSemi, allowLambda);
e = new ITEExpr(x, e, e0, e1);
break;
}
- case 83: {
+ case 85: {
MatchExpression(out e, allowSemi, allowLambda);
break;
}
- case 86: case 122: case 123: case 124: {
+ case 88: case 124: case 125: case 126: {
QuantifierGuts(out e, allowSemi, allowLambda);
break;
}
- case 58: {
+ case 60: {
ComprehensionExpr(out e, allowSemi, allowLambda);
break;
}
- case 74: case 84: case 89: {
+ case 76: case 86: case 91: {
StmtInExpr(out s);
Expression(out e, allowSemi, allowLambda);
e = new StmtExpr(s.Tok, s, e);
break;
}
- case 29: case 34: {
+ case 31: case 36: {
LetExpr(out e, allowSemi, allowLambda);
break;
}
- case 68: {
+ case 70: {
NamedExpr(out e, allowSemi, allowLambda);
break;
}
- default: SynErr(217); break;
+ default: SynErr(220); break;
}
}
@@ -3144,20 +3191,20 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Ident(out id);
idents.Add(id);
- while (la.kind == 63) {
+ while (la.kind == 65) {
IdentOrDigitsSuffix(out id, out idPrime);
idents.Add(id);
if (idPrime != null) { idents.Add(idPrime); id = idPrime; }
}
- if (la.kind == 15 || la.kind == 90) {
+ if (la.kind == 15 || la.kind == 92) {
args = new List<Expression>();
- if (la.kind == 90) {
+ if (la.kind == 92) {
Get();
id.val = id.val + "#"; Expression k;
- Expect(76);
+ Expect(78);
Expression(out k, true, true);
- Expect(77);
+ Expect(79);
args.Add(k);
}
Expect(15);
@@ -3201,7 +3248,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
List<Expression> multipleIndices = null;
bool func = false;
- if (la.kind == 63) {
+ if (la.kind == 65) {
IdentOrDigitsSuffix(out id, out x);
if (x != null) {
// process id as a Suffix in its own right
@@ -3209,14 +3256,14 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
id = x; // move to the next Suffix
}
- if (la.kind == 15 || la.kind == 90) {
+ if (la.kind == 15 || la.kind == 92) {
args = new List<Expression/*!*/>(); func = true;
- if (la.kind == 90) {
+ if (la.kind == 92) {
Get();
id.val = id.val + "#"; Expression k;
- Expect(76);
+ Expect(78);
Expression(out k, true, true);
- Expect(77);
+ Expect(79);
args.Add(k);
}
Expect(15);
@@ -3228,24 +3275,24 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = new FunctionCallExpr(id, id.val, e, openParen, args);
}
if (!func) { e = new ExprDotName(id, e, id.val); }
- } else if (la.kind == 76) {
+ } else if (la.kind == 78) {
Get();
x = t;
if (StartOf(17)) {
Expression(out ee, true, true);
e0 = ee;
- if (la.kind == 121) {
+ if (la.kind == 123) {
Get();
anyDots = true;
if (StartOf(17)) {
Expression(out ee, true, true);
e1 = ee;
}
- } else if (la.kind == 71) {
+ } else if (la.kind == 73) {
Get();
Expression(out ee, true, true);
e1 = ee;
- } else if (la.kind == 7 || la.kind == 77) {
+ } else if (la.kind == 7 || la.kind == 79) {
while (la.kind == 7) {
Get();
if (multipleLengths == null) {
@@ -3261,8 +3308,8 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
}
- } else if (la.kind == 35 || la.kind == 77) {
- while (la.kind == 35) {
+ } else if (la.kind == 37 || la.kind == 79) {
+ while (la.kind == 37) {
Get();
Expression(out ee, true, true);
if (multipleIndices == null) {
@@ -3272,15 +3319,15 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
multipleIndices.Add(ee);
}
- } else SynErr(218);
- } else if (la.kind == 121) {
+ } else SynErr(221);
+ } else if (la.kind == 123) {
Get();
anyDots = true;
if (StartOf(17)) {
Expression(out ee, true, true);
e1 = ee;
}
- } else SynErr(219);
+ } else SynErr(222);
if (multipleIndices != null) {
e = new MultiSelectExpr(x, e, multipleIndices);
// make sure an array class with this dimensionality exists
@@ -3320,8 +3367,8 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
}
- Expect(77);
- } else SynErr(220);
+ Expect(79);
+ } else SynErr(223);
ApplySuffix(ref e);
}
@@ -3350,15 +3397,15 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
e = new SetDisplayExpr(x, elements);
Expect(14);
- } else if (la.kind == 76) {
+ } else if (la.kind == 78) {
Get();
x = t; elements = new List<Expression/*!*/>();
if (StartOf(17)) {
Expressions(elements);
}
e = new SeqDisplayExpr(x, elements);
- Expect(77);
- } else SynErr(221);
+ Expect(79);
+ } else SynErr(224);
}
void MultiSetExpr(out Expression e) {
@@ -3366,7 +3413,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
IToken/*!*/ x = null; List<Expression/*!*/>/*!*/ elements;
e = dummyExpr;
- Expect(59);
+ Expect(61);
x = t;
if (la.kind == 13) {
Get();
@@ -3384,7 +3431,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expect(16);
} else if (StartOf(32)) {
SemErr("multiset must be followed by multiset literal or expression to coerce in parentheses.");
- } else SynErr(222);
+ } else SynErr(225);
}
void MapDisplayExpr(IToken/*!*/ mapToken, out Expression e) {
@@ -3392,12 +3439,12 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
List<ExpressionPair/*!*/>/*!*/ elements= new List<ExpressionPair/*!*/>() ;
e = dummyExpr;
- Expect(76);
+ Expect(78);
if (StartOf(17)) {
MapLiteralExpressions(out elements);
}
e = new MapDisplayExpr(mapToken, elements);
- Expect(77);
+ Expect(79);
}
void MapComprehensionExpr(IToken mapToken, out Expression e, bool allowSemi) {
@@ -3409,7 +3456,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
IdentTypeOptional(out bv);
bvars.Add(bv);
- if (la.kind == 33) {
+ if (la.kind == 35) {
Get();
Expression(out range, true, true);
}
@@ -3425,17 +3472,17 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = dummyExpr; Type toType = null;
switch (la.kind) {
- case 114: {
+ case 116: {
Get();
e = new LiteralExpr(t, false);
break;
}
- case 115: {
+ case 117: {
Get();
e = new LiteralExpr(t, true);
break;
}
- case 116: {
+ case 118: {
Get();
e = new LiteralExpr(t);
break;
@@ -3450,12 +3497,12 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = new LiteralExpr(t, d);
break;
}
- case 117: {
+ case 119: {
Get();
e = new ThisExpr(t);
break;
}
- case 118: {
+ case 120: {
Get();
x = t;
Expect(15);
@@ -3464,7 +3511,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = new UnaryOpExpr(x, UnaryOpExpr.Opcode.Fresh, e);
break;
}
- case 119: {
+ case 121: {
Get();
x = t;
Expect(15);
@@ -3473,16 +3520,16 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = new OldExpr(x, e);
break;
}
- case 33: {
+ case 35: {
Get();
x = t;
Expression(out e, true, true);
e = new UnaryOpExpr(x, UnaryOpExpr.Opcode.Cardinality, e);
- Expect(33);
+ Expect(35);
break;
}
- case 56: case 57: {
- if (la.kind == 56) {
+ case 58: case 59: {
+ if (la.kind == 58) {
Get();
x = t; toType = new IntType();
} else {
@@ -3499,7 +3546,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
ParensExpression(out e, allowSemi, allowLambda);
break;
}
- default: SynErr(223); break;
+ default: SynErr(226); break;
}
}
@@ -3524,7 +3571,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
n = BigInteger.Zero;
}
- } else SynErr(224);
+ } else SynErr(227);
}
void Dec(out Basetypes.BigDec d) {
@@ -3553,7 +3600,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (StartOf(17)) {
OptTypedExpr(out ee, out tt, true);
args.Add(ee); types.Add(tt);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
OptTypedExpr(out ee, out tt, true);
args.Add(ee); types.Add(tt);
@@ -3632,7 +3679,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
} else if (la.kind == 10) {
Get();
oneShot = true;
- } else SynErr(225);
+ } else SynErr(228);
}
void OptTypedExpr(out Expression e, out Type tt, bool allowSemi) {
@@ -3648,24 +3695,24 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expression/*!*/ d, r;
elements = new List<ExpressionPair/*!*/>();
Expression(out d, true, true);
- Expect(71);
+ Expect(73);
Expression(out r, true, true);
elements.Add(new ExpressionPair(d,r));
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Expression(out d, true, true);
- Expect(71);
+ Expect(73);
Expression(out r, true, true);
elements.Add(new ExpressionPair(d,r));
}
}
void QSep() {
- if (la.kind == 125) {
+ if (la.kind == 127) {
Get();
- } else if (la.kind == 126) {
+ } else if (la.kind == 128) {
Get();
- } else SynErr(226);
+ } else SynErr(229);
}
void MatchExpression(out Expression e, bool allowSemi, bool allowLambda) {
@@ -3673,14 +3720,14 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
List<MatchCaseExpr/*!*/> cases = new List<MatchCaseExpr/*!*/>();
bool usesOptionalBrace = false;
- Expect(83);
+ Expect(85);
x = t;
Expression(out e, allowSemi, true);
if (la.kind == 13) {
Get();
usesOptionalBrace = true;
}
- while (la.kind == 80) {
+ while (la.kind == 82) {
CaseExpression(out c, allowSemi, usesOptionalBrace || allowLambda);
cases.Add(c);
}
@@ -3688,7 +3735,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expect(14);
} else if (StartOf(32)) {
if (usesOptionalBrace) { SemErr(t, "expecting close curly brace"); }
- } else SynErr(227);
+ } else SynErr(230);
e = new MatchExpr(x, e, cases, usesOptionalBrace);
}
@@ -3700,13 +3747,13 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expression range;
Expression/*!*/ body;
- if (la.kind == 86 || la.kind == 122) {
+ if (la.kind == 88 || la.kind == 124) {
Forall();
x = t; univ = true;
- } else if (la.kind == 123 || la.kind == 124) {
+ } else if (la.kind == 125 || la.kind == 126) {
Exists();
x = t;
- } else SynErr(228);
+ } else SynErr(231);
QuantifierDomain(out bvars, out attrs, out range);
QSep();
Expression(out body, allowSemi, allowLambda);
@@ -3726,18 +3773,18 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
Expression range;
Expression body = null;
- Expect(58);
+ Expect(60);
x = t;
IdentTypeOptional(out bv);
bvars.Add(bv);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
IdentTypeOptional(out bv);
bvars.Add(bv);
}
- Expect(33);
+ Expect(35);
Expression(out range, allowSemi, allowLambda);
- if (la.kind == 125 || la.kind == 126) {
+ if (la.kind == 127 || la.kind == 128) {
QSep();
Expression(out body, allowSemi, allowLambda);
}
@@ -3748,13 +3795,13 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
void StmtInExpr(out Statement s) {
s = dummyStmt;
- if (la.kind == 84) {
+ if (la.kind == 86) {
AssertStmt(out s);
- } else if (la.kind == 74) {
+ } else if (la.kind == 76) {
AssumeStmt(out s);
- } else if (la.kind == 89) {
+ } else if (la.kind == 91) {
CalcStmt(out s);
- } else SynErr(229);
+ } else SynErr(232);
}
void LetExpr(out Expression e, bool allowSemi, bool allowLambda) {
@@ -3766,26 +3813,26 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
bool exact = true;
e = dummyExpr;
- if (la.kind == 29) {
+ if (la.kind == 31) {
Get();
isGhost = true; x = t;
}
- Expect(34);
+ Expect(36);
if (!isGhost) { x = t; }
CasePattern(out pat);
if (isGhost) { pat.Vars.Iter(bv => bv.IsGhost = true); }
letLHSs.Add(pat);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
CasePattern(out pat);
if (isGhost) { pat.Vars.Iter(bv => bv.IsGhost = true); }
letLHSs.Add(pat);
}
- if (la.kind == 71) {
+ if (la.kind == 73) {
Get();
- } else if (la.kind == 73) {
+ } else if (la.kind == 75) {
Get();
exact = false;
foreach (var lhs in letLHSs) {
@@ -3794,10 +3841,10 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
}
- } else SynErr(230);
+ } else SynErr(233);
Expression(out e, false, true);
letRHSs.Add(e);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
Expression(out e, false, true);
letRHSs.Add(e);
@@ -3812,7 +3859,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
e = dummyExpr;
Expression expr;
- Expect(68);
+ Expect(70);
x = t;
NoUSIdent(out d);
Expect(7);
@@ -3833,7 +3880,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (la.kind == 1) {
CasePattern(out pat);
arguments.Add(pat);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
CasePattern(out pat);
arguments.Add(pat);
@@ -3845,7 +3892,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
IdentTypeOptional(out bv);
pat = new CasePattern(bv.tok, bv);
- } else SynErr(231);
+ } else SynErr(234);
}
void CaseExpression(out MatchCaseExpr c, bool allowSemi, bool allowLambda) {
@@ -3854,14 +3901,14 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
BoundVar/*!*/ bv;
Expression/*!*/ body;
- Expect(80);
+ Expect(82);
x = t;
Ident(out id);
if (la.kind == 15) {
Get();
IdentTypeOptional(out bv);
arguments.Add(bv);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
IdentTypeOptional(out bv);
arguments.Add(bv);
@@ -3874,19 +3921,19 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
void Forall() {
- if (la.kind == 86) {
+ if (la.kind == 88) {
Get();
- } else if (la.kind == 122) {
+ } else if (la.kind == 124) {
Get();
- } else SynErr(232);
+ } else SynErr(235);
}
void Exists() {
- if (la.kind == 123) {
+ if (la.kind == 125) {
Get();
- } else if (la.kind == 124) {
+ } else if (la.kind == 126) {
Get();
- } else SynErr(233);
+ } else SynErr(236);
}
void AttributeBody(ref Attributes attrs) {
@@ -3900,7 +3947,7 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
if (StartOf(33)) {
AttributeArg(out aArg, true);
aArgs.Add(aArg);
- while (la.kind == 35) {
+ while (la.kind == 37) {
Get();
AttributeArg(out aArg, true);
aArgs.Add(aArg);
@@ -3922,40 +3969,40 @@ List<Expression/*!*/>/*!*/ decreases, ref Attributes decAttrs, ref Attributes mo
}
static readonly bool[,]/*!*/ set = {
- {T,T,T,T, T,x,x,x, T,x,x,T, T,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,T, T,T,T,x, x,x,T,x, x,T,x,x, T,T,T,T, T,T,T,T, T,T,x,x, T,T,x,x, x,x,x,x, x,x,x,x, T,T,x,x, T,x,T,x, x,x,T,x, x,T,T,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,T, x,x,x,x, T,T,T,T, T,x,T,x, T,x,T,x, x,x,x,x, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,T,x, x,x,x,x, x,x,x,x, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {T,x,x,x, x,x,x,x, T,x,x,x, x,x,T,x, x,x,x,x, T,T,x,T, x,T,x,x, T,T,T,T, T,x,T,x, T,x,T,x, x,x,T,x, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {T,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, x,x,x,x, T,T,x,T, x,x,x,x, T,T,T,T, T,x,T,x, T,x,T,x, x,x,T,x, T,T,T,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,T,T,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,T,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,T,x,x, x,x,x,T, T,x,x,x, x,x,T,x, T,x,T,x, x,x,x,T, T,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,T,T, T,T,T,T, x,x,T,T, T,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,T,x,x, x,x,x,x, x,x,x,x, T,T,x,x, T,x,T,x, x,x,T,x, x,T,x,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x},
- {T,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,T,x,x, x,x,x,x, T,x,x,x, x,x,T,x, T,x,T,x, x,x,x,T, T,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,T,T, T,T,T,T, x,x,T,T, T,x,x,x, x},
- {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,T,x,x, x,x,x,T, T,x,x,x, x,x,T,x, T,x,T,x, x,x,x,T, T,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,T,T, T,T,T,T, x,x,T,T, T,x,x,x, x},
- {T,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,T,x,x, x,x,x,x, x,x,x,x, T,T,x,x, T,x,T,x, x,x,T,x, x,T,x,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x},
- {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,T,x,x, x,x,x,x, T,x,x,x, x,x,T,x, T,x,T,x, x,x,x,T, T,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,T,T, T,T,T,T, x,x,T,T, T,x,x,x, x},
- {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,T,x,x, x,x,x,x, T,x,x,x, x,x,T,x, T,x,T,x, x,x,x,T, T,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,T,T, T,T,T,T, x,x,T,T, T,x,x,x, x},
- {x,T,T,T, T,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,T,x,x, x,x,x,x, x,x,x,x, T,T,x,x, T,x,T,x, x,x,T,x, T,T,x,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x},
- {x,T,T,T, T,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,T,T, x,T,x,x, T,T,x,x, x,x,x,x, x,x,x,x, T,T,x,x, T,x,T,x, x,x,T,x, T,T,x,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,T,x,x, x,x,x,T, T,x,x,x, x,x,T,x, T,x,T,x, x,x,x,T, T,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,T,T, T,T,T,T, x,x,T,T, T,x,x,x, x},
- {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,T,x,x, x,x,x,x, T,x,x,x, x,x,T,T, T,x,T,x, x,x,x,T, T,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,T,T, T,T,T,T, x,x,T,T, T,x,x,x, x},
- {x,x,T,T, T,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x},
- {x,T,T,T, T,x,x,T, T,T,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,T, x,T,x,x, x,T,T,T, x,x,x,x, x,T,T,T, T,T,x,x, T,T,x,x, x,x,x,T, x,x,x,T, T,T,x,T, T,T,T,x, T,T,T,T, T,T,T,T, T,T,T,T, T,T,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,T,x,x, x,T,T,x, x},
- {x,T,T,T, T,x,T,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,T,x,x, x,x,x,x, T,x,x,x, x,x,T,x, T,x,T,x, x,x,x,T, T,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,T,T, T,T,T,T, x,x,T,T, T,x,x,x, x}
+ {T,T,T,T, T,x,x,x, T,x,x,T, T,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,T, x,T,T,T, T,x,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, x,x,T,T, x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, T,x,x,x, T,x,x,T, T,T,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,T, x,x,x,x, T,x,T,T, T,T,T,x, T,x,T,x, T,x,x,x, x,x,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, T,x,x,x, x,x,x,x, x,x,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {T,x,x,x, x,x,x,x, T,x,x,x, x,x,T,x, x,x,x,x, T,T,x,T, x,T,x,x, T,x,T,T, T,T,T,x, T,x,T,x, T,x,x,x, T,x,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {T,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, x,x,x,x, T,T,x,T, x,x,x,x, T,x,T,T, T,T,T,x, T,x,T,x, T,x,x,x, T,x,T,T, T,T,T,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,T,T,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,T,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,T, x,x,x,x, x,T,T,x, x,x,x,x, T,x,T,x, T,x,x,x, x,T,T,x, T,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, T,T,T,T, T,T,x,x, T,T,T,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,T, x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, T,x,x,x, T,x,x,T, x,T,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x},
+ {T,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,T, x,x,x,x, x,x,T,x, x,x,x,x, T,x,T,x, T,x,x,x, x,T,T,x, T,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, T,T,T,T, T,T,x,x, T,T,T,x, x,x,x},
+ {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,T, x,x,x,x, x,T,T,x, x,x,x,x, T,x,T,x, T,x,x,x, x,T,T,x, T,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, T,T,T,T, T,T,x,x, T,T,T,x, x,x,x},
+ {T,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,T, x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, T,x,x,x, T,x,x,T, x,T,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x},
+ {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,T, x,x,x,x, x,x,T,x, x,x,x,x, T,x,T,x, T,x,x,x, x,T,T,x, T,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, T,T,T,T, T,T,x,x, T,T,T,x, x,x,x},
+ {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,T, x,x,x,x, x,x,T,x, x,x,x,x, T,x,T,x, T,x,x,x, x,T,T,x, T,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, T,T,T,T, T,T,x,x, T,T,T,x, x,x,x},
+ {x,T,T,T, T,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,T, x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, T,x,x,x, T,x,T,T, x,T,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x},
+ {x,T,T,T, T,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, T,T,x,T, x,x,T,T, x,x,x,x, x,x,x,x, x,x,T,T, x,x,T,x, T,x,x,x, T,x,T,T, x,T,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,T, x,x,x,x, x,T,T,x, x,x,x,x, T,x,T,x, T,x,x,x, x,T,T,x, T,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, T,T,T,T, T,T,x,x, T,T,T,x, x,x,x},
+ {x,T,T,T, T,x,x,x, x,x,x,x, x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,T, x,x,x,x, x,x,T,x, x,x,x,x, T,T,T,x, T,x,x,x, x,T,T,x, T,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, T,T,T,T, T,T,x,x, T,T,T,x, x,x,x},
+ {x,x,T,T, T,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
+ {x,T,T,T, T,x,x,T, T,T,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,T,x,T, x,x,x,T, T,T,x,x, x,x,x,T, T,T,T,T, x,x,T,T, x,x,x,x, x,T,x,x, x,T,T,T, x,T,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,x, T,T,T,T, T,T,T,T, x,x,x,T, T,x,x},
+ {x,T,T,T, T,x,T,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,x,T, x,x,x,x, x,x,T,x, x,x,x,x, T,x,T,x, T,x,x,x, x,T,T,x, T,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,T, T,T,T,T, T,T,x,x, T,T,T,x, x,x,x}
};
} // end Parser
@@ -4009,211 +4056,214 @@ public class Errors {
case 26: s = "\"as\" expected"; break;
case 27: s = "\"default\" expected"; break;
case 28: s = "\"class\" expected"; break;
- case 29: s = "\"ghost\" expected"; break;
- case 30: s = "\"static\" expected"; break;
- case 31: s = "\"datatype\" expected"; break;
- case 32: s = "\"codatatype\" expected"; break;
- case 33: s = "\"|\" expected"; break;
- case 34: s = "\"var\" expected"; break;
- case 35: s = "\",\" expected"; break;
- case 36: s = "\"type\" expected"; break;
- case 37: s = "\"==\" expected"; break;
- case 38: s = "\"iterator\" expected"; break;
- case 39: s = "\"yields\" expected"; break;
- case 40: s = "\"returns\" expected"; break;
- case 41: s = "\"...\" expected"; break;
- case 42: s = "\"<\" expected"; break;
- case 43: s = "\">\" expected"; break;
- case 44: s = "\"method\" expected"; break;
- case 45: s = "\"lemma\" expected"; break;
- case 46: s = "\"colemma\" expected"; break;
- case 47: s = "\"comethod\" expected"; break;
- case 48: s = "\"constructor\" expected"; break;
- case 49: s = "\"modifies\" expected"; break;
- case 50: s = "\"free\" expected"; break;
- case 51: s = "\"ensures\" expected"; break;
- case 52: s = "\"decreases\" expected"; break;
- case 53: s = "\"yield\" expected"; break;
- case 54: s = "\"bool\" expected"; break;
- case 55: s = "\"nat\" expected"; break;
- case 56: s = "\"int\" expected"; break;
- case 57: s = "\"real\" expected"; break;
- case 58: s = "\"set\" expected"; break;
- case 59: s = "\"multiset\" expected"; break;
- case 60: s = "\"seq\" expected"; break;
- case 61: s = "\"map\" expected"; break;
- case 62: s = "\"object\" expected"; break;
- case 63: s = "\".\" expected"; break;
- case 64: s = "\"function\" expected"; break;
- case 65: s = "\"predicate\" expected"; break;
- case 66: s = "\"copredicate\" expected"; break;
- case 67: s = "\"`\" expected"; break;
- case 68: s = "\"label\" expected"; break;
- case 69: s = "\"break\" expected"; break;
- case 70: s = "\"where\" expected"; break;
- case 71: s = "\":=\" expected"; break;
- case 72: s = "\"return\" expected"; break;
- case 73: s = "\":|\" expected"; break;
- case 74: s = "\"assume\" expected"; break;
- case 75: s = "\"new\" expected"; break;
- case 76: s = "\"[\" expected"; break;
- case 77: s = "\"]\" expected"; break;
- case 78: s = "\"if\" expected"; break;
- case 79: s = "\"else\" expected"; break;
- case 80: s = "\"case\" expected"; break;
- case 81: s = "\"while\" expected"; break;
- case 82: s = "\"invariant\" expected"; break;
- case 83: s = "\"match\" expected"; break;
- case 84: s = "\"assert\" expected"; break;
- case 85: s = "\"print\" expected"; break;
- case 86: s = "\"forall\" expected"; break;
- case 87: s = "\"parallel\" expected"; break;
- case 88: s = "\"modify\" expected"; break;
- case 89: s = "\"calc\" expected"; break;
- case 90: s = "\"#\" expected"; break;
- case 91: s = "\"<=\" expected"; break;
- case 92: s = "\">=\" expected"; break;
- case 93: s = "\"!=\" expected"; break;
- case 94: s = "\"\\u2260\" expected"; break;
- case 95: s = "\"\\u2264\" expected"; break;
- case 96: s = "\"\\u2265\" expected"; break;
- case 97: s = "\"<==>\" expected"; break;
- case 98: s = "\"\\u21d4\" expected"; break;
- case 99: s = "\"==>\" expected"; break;
- case 100: s = "\"\\u21d2\" expected"; break;
- case 101: s = "\"<==\" expected"; break;
- case 102: s = "\"\\u21d0\" expected"; break;
- case 103: s = "\"&&\" expected"; break;
- case 104: s = "\"\\u2227\" expected"; break;
- case 105: s = "\"||\" expected"; break;
- case 106: s = "\"\\u2228\" expected"; break;
- case 107: s = "\"in\" expected"; break;
- case 108: s = "\"!\" expected"; break;
- case 109: s = "\"+\" expected"; break;
- case 110: s = "\"-\" expected"; break;
- case 111: s = "\"/\" expected"; break;
- case 112: s = "\"%\" expected"; break;
- case 113: s = "\"\\u00ac\" expected"; break;
- case 114: s = "\"false\" expected"; break;
- case 115: s = "\"true\" expected"; break;
- case 116: s = "\"null\" expected"; break;
- case 117: s = "\"this\" expected"; break;
- case 118: s = "\"fresh\" expected"; break;
- case 119: s = "\"old\" expected"; break;
- case 120: s = "\"then\" expected"; break;
- case 121: s = "\"..\" expected"; break;
- case 122: s = "\"\\u2200\" expected"; break;
- case 123: s = "\"exists\" expected"; break;
- case 124: s = "\"\\u2203\" expected"; break;
- case 125: s = "\"::\" expected"; break;
- case 126: s = "\"\\u2022\" expected"; break;
- case 127: s = "??? expected"; break;
- case 128: s = "this symbol not expected in SubModuleDecl"; break;
- case 129: s = "invalid SubModuleDecl"; break;
- case 130: s = "this symbol not expected in ClassDecl"; break;
- case 131: s = "this symbol not expected in DatatypeDecl"; break;
- case 132: s = "invalid DatatypeDecl"; break;
+ case 29: s = "\"extends\" expected"; break;
+ case 30: s = "\"trait\" expected"; break;
+ case 31: s = "\"ghost\" expected"; break;
+ case 32: s = "\"static\" expected"; break;
+ case 33: s = "\"datatype\" expected"; break;
+ case 34: s = "\"codatatype\" expected"; break;
+ case 35: s = "\"|\" expected"; break;
+ case 36: s = "\"var\" expected"; break;
+ case 37: s = "\",\" expected"; break;
+ case 38: s = "\"type\" expected"; break;
+ case 39: s = "\"==\" expected"; break;
+ case 40: s = "\"iterator\" expected"; break;
+ case 41: s = "\"yields\" expected"; break;
+ case 42: s = "\"returns\" expected"; break;
+ case 43: s = "\"...\" expected"; break;
+ case 44: s = "\"<\" expected"; break;
+ case 45: s = "\">\" expected"; break;
+ case 46: s = "\"method\" expected"; break;
+ case 47: s = "\"lemma\" expected"; break;
+ case 48: s = "\"colemma\" expected"; break;
+ case 49: s = "\"comethod\" expected"; break;
+ case 50: s = "\"constructor\" expected"; break;
+ case 51: s = "\"modifies\" expected"; break;
+ case 52: s = "\"free\" expected"; break;
+ case 53: s = "\"ensures\" expected"; break;
+ case 54: s = "\"decreases\" expected"; break;
+ case 55: s = "\"yield\" expected"; break;
+ case 56: s = "\"bool\" expected"; break;
+ case 57: s = "\"nat\" expected"; break;
+ case 58: s = "\"int\" expected"; break;
+ case 59: s = "\"real\" expected"; break;
+ case 60: s = "\"set\" expected"; break;
+ case 61: s = "\"multiset\" expected"; break;
+ case 62: s = "\"seq\" expected"; break;
+ case 63: s = "\"map\" expected"; break;
+ case 64: s = "\"object\" expected"; break;
+ case 65: s = "\".\" expected"; break;
+ case 66: s = "\"function\" expected"; break;
+ case 67: s = "\"predicate\" expected"; break;
+ case 68: s = "\"copredicate\" expected"; break;
+ case 69: s = "\"`\" expected"; break;
+ case 70: s = "\"label\" expected"; break;
+ case 71: s = "\"break\" expected"; break;
+ case 72: s = "\"where\" expected"; break;
+ case 73: s = "\":=\" expected"; break;
+ case 74: s = "\"return\" expected"; break;
+ case 75: s = "\":|\" expected"; break;
+ case 76: s = "\"assume\" expected"; break;
+ case 77: s = "\"new\" expected"; break;
+ case 78: s = "\"[\" expected"; break;
+ case 79: s = "\"]\" expected"; break;
+ case 80: s = "\"if\" expected"; break;
+ case 81: s = "\"else\" expected"; break;
+ case 82: s = "\"case\" expected"; break;
+ case 83: s = "\"while\" expected"; break;
+ case 84: s = "\"invariant\" expected"; break;
+ case 85: s = "\"match\" expected"; break;
+ case 86: s = "\"assert\" expected"; break;
+ case 87: s = "\"print\" expected"; break;
+ case 88: s = "\"forall\" expected"; break;
+ case 89: s = "\"parallel\" expected"; break;
+ case 90: s = "\"modify\" expected"; break;
+ case 91: s = "\"calc\" expected"; break;
+ case 92: s = "\"#\" expected"; break;
+ case 93: s = "\"<=\" expected"; break;
+ case 94: s = "\">=\" expected"; break;
+ case 95: s = "\"!=\" expected"; break;
+ case 96: s = "\"\\u2260\" expected"; break;
+ case 97: s = "\"\\u2264\" expected"; break;
+ case 98: s = "\"\\u2265\" expected"; break;
+ case 99: s = "\"<==>\" expected"; break;
+ case 100: s = "\"\\u21d4\" expected"; break;
+ case 101: s = "\"==>\" expected"; break;
+ case 102: s = "\"\\u21d2\" expected"; break;
+ case 103: s = "\"<==\" expected"; break;
+ case 104: s = "\"\\u21d0\" expected"; break;
+ case 105: s = "\"&&\" expected"; break;
+ case 106: s = "\"\\u2227\" expected"; break;
+ case 107: s = "\"||\" expected"; break;
+ case 108: s = "\"\\u2228\" expected"; break;
+ case 109: s = "\"in\" expected"; break;
+ case 110: s = "\"!\" expected"; break;
+ case 111: s = "\"+\" expected"; break;
+ case 112: s = "\"-\" expected"; break;
+ case 113: s = "\"/\" expected"; break;
+ case 114: s = "\"%\" expected"; break;
+ case 115: s = "\"\\u00ac\" expected"; break;
+ case 116: s = "\"false\" expected"; break;
+ case 117: s = "\"true\" expected"; break;
+ case 118: s = "\"null\" expected"; break;
+ case 119: s = "\"this\" expected"; break;
+ case 120: s = "\"fresh\" expected"; break;
+ case 121: s = "\"old\" expected"; break;
+ case 122: s = "\"then\" expected"; break;
+ case 123: s = "\"..\" expected"; break;
+ case 124: s = "\"\\u2200\" expected"; break;
+ case 125: s = "\"exists\" expected"; break;
+ case 126: s = "\"\\u2203\" expected"; break;
+ case 127: s = "\"::\" expected"; break;
+ case 128: s = "\"\\u2022\" expected"; break;
+ case 129: s = "??? expected"; break;
+ case 130: s = "this symbol not expected in SubModuleDecl"; break;
+ case 131: s = "invalid SubModuleDecl"; break;
+ case 132: s = "this symbol not expected in ClassDecl"; break;
case 133: s = "this symbol not expected in DatatypeDecl"; break;
- case 134: s = "invalid OtherTypeDecl"; break;
- case 135: s = "this symbol not expected in OtherTypeDecl"; break;
- case 136: s = "this symbol not expected in IteratorDecl"; break;
- case 137: s = "invalid IteratorDecl"; break;
- case 138: s = "invalid ClassMemberDecl"; break;
- case 139: s = "invalid IdentOrDigitsSuffix"; break;
- case 140: s = "this symbol not expected in FieldDecl"; break;
- case 141: s = "this symbol not expected in FieldDecl"; break;
- case 142: s = "invalid FunctionDecl"; break;
- case 143: s = "invalid FunctionDecl"; break;
- case 144: s = "invalid FunctionDecl"; break;
+ case 134: s = "invalid DatatypeDecl"; break;
+ case 135: s = "this symbol not expected in DatatypeDecl"; break;
+ case 136: s = "invalid OtherTypeDecl"; break;
+ case 137: s = "this symbol not expected in OtherTypeDecl"; break;
+ case 138: s = "this symbol not expected in IteratorDecl"; break;
+ case 139: s = "invalid IteratorDecl"; break;
+ case 140: s = "this symbol not expected in TraitDecl"; break;
+ case 141: s = "invalid ClassMemberDecl"; break;
+ case 142: s = "invalid IdentOrDigitsSuffix"; break;
+ case 143: s = "this symbol not expected in FieldDecl"; break;
+ case 144: s = "this symbol not expected in FieldDecl"; break;
case 145: s = "invalid FunctionDecl"; break;
- case 146: s = "this symbol not expected in MethodDecl"; break;
- case 147: s = "invalid MethodDecl"; break;
- case 148: s = "invalid MethodDecl"; break;
- case 149: s = "invalid FIdentType"; break;
- case 150: s = "invalid TypeIdentOptional"; break;
- case 151: s = "invalid TypeAndToken"; break;
- case 152: s = "this symbol not expected in IteratorSpec"; break;
- case 153: s = "this symbol not expected in IteratorSpec"; break;
- case 154: s = "this symbol not expected in IteratorSpec"; break;
+ case 146: s = "invalid FunctionDecl"; break;
+ case 147: s = "invalid FunctionDecl"; break;
+ case 148: s = "invalid FunctionDecl"; break;
+ case 149: s = "this symbol not expected in MethodDecl"; break;
+ case 150: s = "invalid MethodDecl"; break;
+ case 151: s = "invalid MethodDecl"; break;
+ case 152: s = "invalid FIdentType"; break;
+ case 153: s = "invalid TypeIdentOptional"; break;
+ case 154: s = "invalid TypeAndToken"; break;
case 155: s = "this symbol not expected in IteratorSpec"; break;
case 156: s = "this symbol not expected in IteratorSpec"; break;
- case 157: s = "invalid IteratorSpec"; break;
+ case 157: s = "this symbol not expected in IteratorSpec"; break;
case 158: s = "this symbol not expected in IteratorSpec"; break;
- case 159: s = "invalid IteratorSpec"; break;
- case 160: s = "this symbol not expected in MethodSpec"; break;
- case 161: s = "this symbol not expected in MethodSpec"; break;
- case 162: s = "this symbol not expected in MethodSpec"; break;
+ case 159: s = "this symbol not expected in IteratorSpec"; break;
+ case 160: s = "invalid IteratorSpec"; break;
+ case 161: s = "this symbol not expected in IteratorSpec"; break;
+ case 162: s = "invalid IteratorSpec"; break;
case 163: s = "this symbol not expected in MethodSpec"; break;
- case 164: s = "invalid MethodSpec"; break;
+ case 164: s = "this symbol not expected in MethodSpec"; break;
case 165: s = "this symbol not expected in MethodSpec"; break;
- case 166: s = "invalid MethodSpec"; break;
- case 167: s = "invalid FrameExpression"; break;
- case 168: s = "invalid ReferenceType"; break;
- case 169: s = "this symbol not expected in FunctionSpec"; break;
- case 170: s = "this symbol not expected in FunctionSpec"; break;
- case 171: s = "this symbol not expected in FunctionSpec"; break;
+ case 166: s = "this symbol not expected in MethodSpec"; break;
+ case 167: s = "invalid MethodSpec"; break;
+ case 168: s = "this symbol not expected in MethodSpec"; break;
+ case 169: s = "invalid MethodSpec"; break;
+ case 170: s = "invalid FrameExpression"; break;
+ case 171: s = "invalid ReferenceType"; break;
case 172: s = "this symbol not expected in FunctionSpec"; break;
case 173: s = "this symbol not expected in FunctionSpec"; break;
- case 174: s = "invalid FunctionSpec"; break;
- case 175: s = "invalid PossiblyWildFrameExpression"; break;
- case 176: s = "invalid PossiblyWildExpression"; break;
- case 177: s = "this symbol not expected in OneStmt"; break;
- case 178: s = "invalid OneStmt"; break;
- case 179: s = "this symbol not expected in OneStmt"; break;
- case 180: s = "invalid OneStmt"; break;
- case 181: s = "invalid AssertStmt"; break;
- case 182: s = "invalid AssumeStmt"; break;
- case 183: s = "invalid UpdateStmt"; break;
- case 184: s = "invalid UpdateStmt"; break;
- case 185: s = "invalid IfStmt"; break;
- case 186: s = "invalid IfStmt"; break;
- case 187: s = "invalid WhileStmt"; break;
- case 188: s = "invalid WhileStmt"; break;
- case 189: s = "invalid MatchStmt"; break;
- case 190: s = "invalid ForallStmt"; break;
- case 191: s = "invalid ForallStmt"; break;
- case 192: s = "this symbol not expected in ModifyStmt"; break;
- case 193: s = "invalid ModifyStmt"; break;
- case 194: s = "invalid ReturnStmt"; break;
- case 195: s = "invalid Rhs"; break;
- case 196: s = "invalid Lhs"; break;
- case 197: s = "invalid Guard"; break;
- case 198: s = "this symbol not expected in LoopSpec"; break;
- case 199: s = "this symbol not expected in LoopSpec"; break;
- case 200: s = "this symbol not expected in LoopSpec"; break;
+ case 174: s = "this symbol not expected in FunctionSpec"; break;
+ case 175: s = "this symbol not expected in FunctionSpec"; break;
+ case 176: s = "this symbol not expected in FunctionSpec"; break;
+ case 177: s = "invalid FunctionSpec"; break;
+ case 178: s = "invalid PossiblyWildFrameExpression"; break;
+ case 179: s = "invalid PossiblyWildExpression"; break;
+ case 180: s = "this symbol not expected in OneStmt"; break;
+ case 181: s = "invalid OneStmt"; break;
+ case 182: s = "this symbol not expected in OneStmt"; break;
+ case 183: s = "invalid OneStmt"; break;
+ case 184: s = "invalid AssertStmt"; break;
+ case 185: s = "invalid AssumeStmt"; break;
+ case 186: s = "invalid UpdateStmt"; break;
+ case 187: s = "invalid UpdateStmt"; break;
+ case 188: s = "invalid IfStmt"; break;
+ case 189: s = "invalid IfStmt"; break;
+ case 190: s = "invalid WhileStmt"; break;
+ case 191: s = "invalid WhileStmt"; break;
+ case 192: s = "invalid MatchStmt"; break;
+ case 193: s = "invalid ForallStmt"; break;
+ case 194: s = "invalid ForallStmt"; break;
+ case 195: s = "this symbol not expected in ModifyStmt"; break;
+ case 196: s = "invalid ModifyStmt"; break;
+ case 197: s = "invalid ReturnStmt"; break;
+ case 198: s = "invalid Rhs"; break;
+ case 199: s = "invalid Lhs"; break;
+ case 200: s = "invalid Guard"; break;
case 201: s = "this symbol not expected in LoopSpec"; break;
case 202: s = "this symbol not expected in LoopSpec"; break;
- case 203: s = "this symbol not expected in Invariant"; break;
- case 204: s = "invalid AttributeArg"; break;
- case 205: s = "invalid CalcOp"; break;
- case 206: s = "invalid EquivOp"; break;
- case 207: s = "invalid ImpliesOp"; break;
- case 208: s = "invalid ExpliesOp"; break;
- case 209: s = "invalid AndOp"; break;
- case 210: s = "invalid OrOp"; break;
- case 211: s = "invalid RelOp"; break;
- case 212: s = "invalid AddOp"; break;
- case 213: s = "invalid UnaryExpression"; break;
- case 214: s = "invalid UnaryExpression"; break;
- case 215: s = "invalid MulOp"; break;
- case 216: s = "invalid NegOp"; break;
- case 217: s = "invalid EndlessExpression"; break;
- case 218: s = "invalid Suffix"; break;
- case 219: s = "invalid Suffix"; break;
- case 220: s = "invalid Suffix"; break;
- case 221: s = "invalid DisplayExpr"; break;
- case 222: s = "invalid MultiSetExpr"; break;
- case 223: s = "invalid ConstAtomExpression"; break;
- case 224: s = "invalid Nat"; break;
- case 225: s = "invalid LambdaArrow"; break;
- case 226: s = "invalid QSep"; break;
- case 227: s = "invalid MatchExpression"; break;
- case 228: s = "invalid QuantifierGuts"; break;
- case 229: s = "invalid StmtInExpr"; break;
- case 230: s = "invalid LetExpr"; break;
- case 231: s = "invalid CasePattern"; break;
- case 232: s = "invalid Forall"; break;
- case 233: s = "invalid Exists"; break;
+ case 203: s = "this symbol not expected in LoopSpec"; break;
+ case 204: s = "this symbol not expected in LoopSpec"; break;
+ case 205: s = "this symbol not expected in LoopSpec"; break;
+ case 206: s = "this symbol not expected in Invariant"; break;
+ case 207: s = "invalid AttributeArg"; break;
+ case 208: s = "invalid CalcOp"; break;
+ case 209: s = "invalid EquivOp"; break;
+ case 210: s = "invalid ImpliesOp"; break;
+ case 211: s = "invalid ExpliesOp"; break;
+ case 212: s = "invalid AndOp"; break;
+ case 213: s = "invalid OrOp"; break;
+ case 214: s = "invalid RelOp"; break;
+ case 215: s = "invalid AddOp"; break;
+ case 216: s = "invalid UnaryExpression"; break;
+ case 217: s = "invalid UnaryExpression"; break;
+ case 218: s = "invalid MulOp"; break;
+ case 219: s = "invalid NegOp"; break;
+ case 220: s = "invalid EndlessExpression"; break;
+ case 221: s = "invalid Suffix"; break;
+ case 222: s = "invalid Suffix"; break;
+ case 223: s = "invalid Suffix"; break;
+ case 224: s = "invalid DisplayExpr"; break;
+ case 225: s = "invalid MultiSetExpr"; break;
+ case 226: s = "invalid ConstAtomExpression"; break;
+ case 227: s = "invalid Nat"; break;
+ case 228: s = "invalid LambdaArrow"; break;
+ case 229: s = "invalid QSep"; break;
+ case 230: s = "invalid MatchExpression"; break;
+ case 231: s = "invalid QuantifierGuts"; break;
+ case 232: s = "invalid StmtInExpr"; break;
+ case 233: s = "invalid LetExpr"; break;
+ case 234: s = "invalid CasePattern"; break;
+ case 235: s = "invalid Forall"; break;
+ case 236: s = "invalid Exists"; break;
default: s = "error " + n; break;
}
diff --git a/Source/Dafny/Printer.cs b/Source/Dafny/Printer.cs
index ce693036..c6bc563c 100644
--- a/Source/Dafny/Printer.cs
+++ b/Source/Dafny/Printer.cs
@@ -264,7 +264,10 @@ namespace Microsoft.Dafny {
public void PrintClass(ClassDecl c, int indent) {
Contract.Requires(c != null);
Indent(indent);
- PrintClassMethodHelper("class", c.Attributes, c.Name, c.TypeArgs);
+ PrintClassMethodHelper((c is TraitDecl) ? "trait" : "class", c.Attributes, c.Name, c.TypeArgs);
+ if (c.TraitId != null) {
+ wr.Write(" extends {0}", c.TraitId.val);
+ }
if (c.Members.Count == 0) {
wr.WriteLine(" { }");
} else {
diff --git a/Source/Dafny/RefinementTransformer.cs b/Source/Dafny/RefinementTransformer.cs
index d90d2362..a7989cba 100644
--- a/Source/Dafny/RefinementTransformer.cs
+++ b/Source/Dafny/RefinementTransformer.cs
@@ -830,6 +830,90 @@ namespace Microsoft.Dafny
}
}
+ public void CheckOverride_FunctionParameters(Function nw, Function f)
+ {
+ CheckOverride_TypeParameters(nw.tok, f.TypeArgs, nw.TypeArgs, nw.Name, "function", false);
+ CheckOverrideResolvedParameters(nw.tok, f.Formals, nw.Formals, nw.Name, "function", "parameter");
+ if (!ResolvedTypesAreTheSame(nw.ResultType, f.ResultType))
+ {
+ reporter.Error(nw, "the result type of function '{0}' ({1}) differs from the result type of the corresponding function in the module it overrides ({2})", nw.Name, nw.ResultType, f.ResultType);
+ }
+ }
+
+ public void CheckOverride_MethodParameters(Method nw, Method f)
+ {
+ CheckOverride_TypeParameters(nw.tok, f.TypeArgs, nw.TypeArgs, nw.Name, "method", false);
+ CheckOverrideResolvedParameters(nw.tok, f.Ins, nw.Ins, nw.Name, "method", "in-parameter");
+ CheckOverrideResolvedParameters(nw.tok, f.Outs, nw.Outs, nw.Name, "method", "out-parameter");
+ }
+
+ public void CheckOverride_TypeParameters(IToken tok, List<TypeParameter> old, List<TypeParameter> nw, string name, string thing, bool checkNames = true)
+ {
+ Contract.Requires(tok != null);
+ Contract.Requires(old != null);
+ Contract.Requires(nw != null);
+ Contract.Requires(name != null);
+ Contract.Requires(thing != null);
+ if (old.Count != nw.Count)
+ {
+ reporter.Error(tok, "{0} '{1}' is declared with a different number of type parameters ({2} instead of {3}) than the corresponding {0} in the module it overrides", thing, name, nw.Count, old.Count);
+ }
+ else
+ {
+ for (int i = 0; i < old.Count; i++)
+ {
+ var o = old[i];
+ var n = nw[i];
+ if (o.Name != n.Name && checkNames)
+ { // if checkNames is false, then just treat the parameters positionally.
+ reporter.Error(n.tok, "type parameters are not allowed to be renamed from the names given in the {0} in the module being overriden (expected '{1}', found '{2}')", thing, o.Name, n.Name);
+ }
+ else
+ {
+ // Here's how we actually compute it:
+ if (o.EqualitySupport != TypeParameter.EqualitySupportValue.InferredRequired && o.EqualitySupport != n.EqualitySupport)
+ {
+ reporter.Error(n.tok, "type parameter '{0}' is not allowed to change the requirement of supporting equality", n.Name);
+ }
+ }
+ }
+ }
+ }
+
+ public void CheckOverrideResolvedParameters(IToken tok, List<Formal> old, List<Formal> nw, string name, string thing, string parameterKind)
+ {
+ Contract.Requires(tok != null);
+ Contract.Requires(old != null);
+ Contract.Requires(nw != null);
+ Contract.Requires(name != null);
+ Contract.Requires(thing != null);
+ Contract.Requires(parameterKind != null);
+ if (old.Count != nw.Count)
+ {
+ reporter.Error(tok, "{0} '{1}' is declared with a different number of {2} ({3} instead of {4}) than the corresponding {0} in the module it overrides", thing, name, parameterKind, nw.Count, old.Count);
+ }
+ else
+ {
+ for (int i = 0; i < old.Count; i++)
+ {
+ var o = old[i];
+ var n = nw[i];
+ if (!o.IsGhost && n.IsGhost)
+ {
+ reporter.Error(n.tok, "{0} '{1}' of {2} {3} cannot be changed, compared to the corresponding {2} in the module it overrides, from non-ghost to ghost", parameterKind, n.Name, thing, name);
+ }
+ else if (o.IsGhost && !n.IsGhost)
+ {
+ reporter.Error(n.tok, "{0} '{1}' of {2} {3} cannot be changed, compared to the corresponding {2} in the module it overrides, from ghost to non-ghost", parameterKind, n.Name, thing, name);
+ }
+ else if (!ResolvedTypesAreTheSame(o.Type, n.Type))
+ {
+ reporter.Error(n.tok, "the type of {0} '{1}' is different from the type of the same {0} in the corresponding {2} in the module it overrides ('{3}' instead of '{4}')", parameterKind, n.Name, thing, n.Type, o.Type);
+ }
+ }
+ }
+ }
+
void CheckAgreement_Parameters(IToken tok, List<Formal> old, List<Formal> nw, string name, string thing, string parameterKind) {
Contract.Requires(tok != null);
Contract.Requires(old != null);
diff --git a/Source/Dafny/Resolver.cs b/Source/Dafny/Resolver.cs
index 5bb85d35..35445e89 100644
--- a/Source/Dafny/Resolver.cs
+++ b/Source/Dafny/Resolver.cs
@@ -136,14 +136,15 @@ namespace Microsoft.Dafny
return nm;
}
}
- //Dictionary<string/*!*/, Tuple<DatatypeCtor, bool>> allDatatypeCtors;
+ //Dictionary<string, Tuple<DatatypeCtor, bool>> allDatatypeCtors;
- readonly Dictionary<ClassDecl/*!*/, Dictionary<string/*!*/, MemberDecl/*!*/>/*!*/>/*!*/ classMembers = new Dictionary<ClassDecl/*!*/, Dictionary<string/*!*/, MemberDecl/*!*/>/*!*/>();
- readonly Dictionary<DatatypeDecl/*!*/, Dictionary<string/*!*/, MemberDecl/*!*/>/*!*/>/*!*/ datatypeMembers = new Dictionary<DatatypeDecl/*!*/, Dictionary<string/*!*/, MemberDecl/*!*/>/*!*/>();
- readonly Dictionary<DatatypeDecl/*!*/, Dictionary<string/*!*/, DatatypeCtor/*!*/>/*!*/>/*!*/ datatypeCtors = new Dictionary<DatatypeDecl/*!*/, Dictionary<string/*!*/, DatatypeCtor/*!*/>/*!*/>();
- readonly Graph<ModuleDecl/*!*/>/*!*/ dependencies = new Graph<ModuleDecl/*!*/>();
+ readonly Dictionary<ClassDecl, Dictionary<string, MemberDecl>> classMembers = new Dictionary<ClassDecl, Dictionary<string, MemberDecl>>();
+ readonly Dictionary<DatatypeDecl, Dictionary<string, MemberDecl>> datatypeMembers = new Dictionary<DatatypeDecl, Dictionary<string, MemberDecl>>();
+ readonly Dictionary<DatatypeDecl, Dictionary<string, DatatypeCtor>> datatypeCtors = new Dictionary<DatatypeDecl, Dictionary<string, DatatypeCtor>>();
+ readonly Graph<ModuleDecl> dependencies = new Graph<ModuleDecl>();
private ModuleSignature systemNameInfo = null;
private bool useCompileSignatures = false;
+ private RefinementTransformer refinementTransformer = null;
public Resolver(Program prog) {
Contract.Requires(prog != null);
@@ -474,16 +475,17 @@ namespace Microsoft.Dafny
} else {
Expression e = fe.E; // keep only fe.E, drop any fe.Field designation
Contract.Assert(e.Type != null); // should have been resolved already
- if (e.Type.IsRefType) {
+ var eType = e.Type.NormalizeExpand();
+ if (eType.IsRefType) {
// e represents a singleton set
if (singletons == null) {
singletons = new List<Expression>();
}
singletons.Add(e);
- } else if (e.Type is SeqType) {
+ } else if (eType is SeqType) {
// e represents a sequence
// Add: set x :: x in e
- var bv = new BoundVar(e.tok, "_s2s_" + tmpVarCount, ((SeqType)e.Type).Arg);
+ var bv = new BoundVar(e.tok, "_s2s_" + tmpVarCount, ((SeqType)eType).Arg);
tmpVarCount++;
var bvIE = new IdentifierExpr(e.tok, bv.Name);
bvIE.Var = bv; // resolve here
@@ -496,7 +498,7 @@ namespace Microsoft.Dafny
sets.Add(s);
} else {
// e is already a set
- Contract.Assert(e.Type is SetType);
+ Contract.Assert(eType is SetType);
sets.Add(e);
}
}
@@ -947,7 +949,11 @@ namespace Microsoft.Dafny
}
}
cl.HasConstructor = hasConstructor;
- if (cl.IsDefaultClass) {
+ if (cl is TraitDecl && cl.HasConstructor)
+ {
+ Error(cl, "a trait is not allowed to declare a constructor");
+ }
+ if (cl.IsDefaultClass) {
foreach (MemberDecl m in cl.Members) {
if (m.IsStatic && (m is Function || m is Method)) {
sig.StaticMembers[m.Name] = m;
@@ -1056,9 +1062,10 @@ namespace Microsoft.Dafny
var dd = (ClassDecl)d;
var tps = dd.TypeArgs.ConvertAll(CloneTypeParam);
var mm = dd.Members.ConvertAll(CloneMember);
+ List<IToken> trait = null;
if (dd is DefaultClassDecl) {
return new DefaultClassDecl(m, mm);
- } else return new ClassDecl(dd.tok, dd.Name, m, tps, mm, null);
+ } else return new ClassDecl(dd.tok, dd.Name, m, tps, mm, null,trait);
} else if (d is ModuleDecl) {
if (d is LiteralModuleDecl) {
return new LiteralModuleDecl(((LiteralModuleDecl)d).ModuleDef, m);
@@ -1447,6 +1454,14 @@ namespace Microsoft.Dafny
allTypeParameters.PopMarker();
}
+ // Now that all traits have been resolved, let classes inherit the trait members
+ foreach (var d in declarations) {
+ var cl = d as ClassDecl;
+ if (cl != null) {
+ InheritTraitMembers(cl);
+ }
+ }
+
// perform acyclicity test on type synonyms
var cycle = typeSynonymDependencies.TryFindCycle();
if (cycle != null) {
@@ -1466,6 +1481,10 @@ namespace Microsoft.Dafny
// Resolve the meat of classes and iterators, the definitions of type synonyms, and the type parameters of all top-level type declarations
foreach (TopLevelDecl d in declarations) {
Contract.Assert(d != null);
+ if (d is TraitDecl && d.TypeArgs != null && d.TypeArgs.Count > 0)
+ {
+ Error(d, "a trait cannot declare type parameters");
+ }
allTypeParameters.PushMarker();
ResolveTypeParameters(d.TypeArgs, false, d);
if (!(d is IteratorDecl)) {
@@ -2028,7 +2047,7 @@ namespace Microsoft.Dafny
Contract.Requires(tok != null);
Contract.Requires(t != null);
Contract.Requires(what != null);
- t = t.Normalize();
+ t = t.NormalizeExpand();
if (t is TypeProxy && (aggressive || !(t is InferredTypeProxy || t is ParamTypeProxy || t is ObjectTypeProxy))) {
Error(tok, "the type of this {0} is underspecified, but it cannot be an opaque type.", what);
return false;
@@ -2766,12 +2785,33 @@ namespace Microsoft.Dafny
/// <summary>
/// Assumes type parameters have already been pushed
/// </summary>
- void ResolveClassMemberTypes(ClassDecl/*!*/ cl) {
+ void ResolveClassMemberTypes(ClassDecl cl) {
Contract.Requires(cl != null);
Contract.Requires(currentClass == null);
Contract.Ensures(currentClass == null);
currentClass = cl;
+
+ // Resolve names of traits extended
+ if (cl.TraitId != null) {
+ var trait = classMembers.Keys.FirstOrDefault(traitDecl => traitDecl.CompileName == cl.TraitId.val);
+ if (trait == null) {
+ Error(cl.TraitId, "unresolved identifier: {0}", cl.TraitId.val);
+ } else if (!(trait is TraitDecl)) {
+ Error(cl.TraitId, "identifier '{0}' does not denote a trait", cl.TraitId.val);
+ } else {
+ //disallowing inheritance in multi module case
+ string clModName = cl.Module.CompileName.Replace("_Compile", string.Empty);
+ string traitModName = trait.Module.CompileName.Replace("_Compile", string.Empty);
+ if (clModName != traitModName) {
+ Error(cl.TraitId, string.Format("class {0} is in a different module than trait {1}. A class may only extend a trait in the same module",
+ cl.FullName, trait.FullName));
+ } else {
+ cl.Trait = (TraitDecl)trait;
+ }
+ }
+ }
+
foreach (MemberDecl member in cl.Members) {
member.EnclosingClass = cl;
if (member is Field) {
@@ -2815,9 +2855,129 @@ namespace Microsoft.Dafny
Contract.Assert(false); throw new cce.UnreachableException(); // unexpected member type
}
}
+
currentClass = null;
}
+ void InheritTraitMembers(ClassDecl cl) {
+ Contract.Requires(cl != null);
+
+ //merging class members with parent members if any
+ if (cl.Trait != null) {
+ var clMembers = classMembers[cl];
+ var traitMembers = classMembers[cl.Trait];
+ //merging current class members with the inheriting trait
+ foreach (KeyValuePair<string, MemberDecl> traitMem in traitMembers) {
+ MemberDecl clMember;
+ if (clMembers.TryGetValue(traitMem.Key, out clMember)) {
+ //check if the signature of the members are equal and the member is body-less
+ if (traitMem.Value is Method) {
+ Method traitMethod = (Method)traitMem.Value;
+ // TODO: should check that the class member is also a method, and the same kind of method
+ Method classMethod = (Method)clMember;
+ //refinementTransformer.CheckMethodsAreRefinements(classMethod, traitMethod);
+ if (traitMethod.Body != null && !clMembers[classMethod.CompileName].Inherited) //if the existing method in the class is not that inherited one from the parent
+ Error(classMethod, "a class cannot override implemented methods");
+ else {
+ classMethod.OverriddenMethod = traitMethod;
+ //adding a call graph edge from the trait method to that of class
+ cl.Module.CallGraph.AddEdge(traitMethod, classMethod);
+
+ //checking specifications
+ //class method must provide its own specifications in case the overriden method has provided any
+ if ((classMethod.Req == null || classMethod.Req.Count == 0) && (classMethod.OverriddenMethod.Req != null && classMethod.OverriddenMethod.Req.Count > 0)) //it means m.OverriddenMethod.Req => m.Req
+ {
+ Error(classMethod, "Method must provide its own Requires clauses anew");
+ }
+ if ((classMethod.Ens == null || classMethod.Ens.Count == 0) && (classMethod.OverriddenMethod.Ens != null && classMethod.OverriddenMethod.Ens.Count > 0)) //it means m.OverriddenMethod.Ens => m.Ens
+ {
+ Error(classMethod, "Method must provide its own Ensures clauses anew");
+ }
+ if ((classMethod.Mod == null || classMethod.Mod.Expressions == null || classMethod.Mod.Expressions.Count == 0) && (classMethod.OverriddenMethod.Mod != null && classMethod.OverriddenMethod.Mod.Expressions != null && classMethod.OverriddenMethod.Mod.Expressions.Count > 0)) //it means m.OverriddenMethod.Mod => m.Mod
+ {
+ Error(classMethod, "Method must provide its own Modifies clauses anew");
+ }
+ if ((classMethod.Decreases == null || classMethod.Decreases.Expressions == null || classMethod.Decreases.Expressions.Count == 0) && (classMethod.OverriddenMethod.Decreases != null && classMethod.OverriddenMethod.Decreases.Expressions != null && classMethod.OverriddenMethod.Decreases.Expressions.Count > 0)) //it means m.OverriddenMethod.Decreases => m.Decreases
+ {
+ Error(classMethod, "Method must provide its own Decreases clauses anew");
+ }
+ }
+ } else if (traitMem.Value is Function) {
+ Function traitFunction = (Function)traitMem.Value;
+ Function classFunction = (Function)clMember;
+ //refinementTransformer.CheckFunctionsAreRefinements(classFunction, traitFunction);
+ if (traitFunction.Body != null && !classMembers[cl][classFunction.CompileName].Inherited)
+ Error(classFunction, "a class cannot override implemented functions");
+ else {
+ classFunction.OverriddenFunction = traitFunction;
+ //adding a call graph edge from the trait method to that of class
+ cl.Module.CallGraph.AddEdge(traitFunction, classFunction);
+
+ //checking specifications
+ //class function must provide its own specifications in case the overriden function has provided any
+ if ((classFunction.Req == null || classFunction.Req.Count == 0) && (classFunction.OverriddenFunction.Req != null && classFunction.OverriddenFunction.Req.Count > 0)) //it means m.OverriddenMethod.Req => m.Req
+ {
+ Error(classFunction, "Function must provide its own Requires clauses anew");
+ }
+ if ((classFunction.Ens == null || classFunction.Ens.Count == 0) && (classFunction.OverriddenFunction.Ens != null && classFunction.OverriddenFunction.Ens.Count > 0)) //it means m.OverriddenMethod.Ens => m.Ens
+ {
+ Error(classFunction, "Function must provide its own Ensures clauses anew");
+ }
+ if ((classFunction.Reads == null || classFunction.Reads.Count == 0) && (classFunction.OverriddenFunction.Reads != null && classFunction.OverriddenFunction.Reads.Count > 0)) //it means m.OverriddenMethod.Mod => m.Mod
+ {
+ Error(classFunction, "Function must provide its own Reads clauses anew");
+ }
+ if ((classFunction.Decreases == null || classFunction.Decreases.Expressions == null || classFunction.Decreases.Expressions.Count == 0) && (classFunction.OverriddenFunction.Decreases != null && classFunction.OverriddenFunction.Decreases.Expressions != null && classFunction.OverriddenFunction.Decreases.Expressions.Count > 0)) //it means m.OverriddenMethod.Decreases => m.Decreases
+ {
+ Error(classFunction, "Function must provide its own Decreases clauses anew");
+ }
+ }
+ } else if (traitMem.Value is Field) {
+ Field traitField = (Field)traitMem.Value;
+ Field classField = (Field)clMember;
+ if (!clMembers[classField.CompileName].Inherited)
+ Error(classField, "member in the class has been already inherited from its parent trait");
+ }
+ } else {
+ //the member is not already in the class
+ // enter the trait member in the symbol table for the class
+ clMembers.Add(traitMem.Key, traitMem.Value);
+ }
+ }//foreach
+
+ //checking to make sure all body-less methods/functions have been implemented in the child class
+ if (refinementTransformer == null)
+ refinementTransformer = new RefinementTransformer(this, AdditionalInformationReporter, null);
+ foreach (MemberDecl traitMember in cl.Trait.Members.Where(mem => mem is Function || mem is Method)) {
+ if (traitMember is Function) {
+ Function traitFunc = (Function)traitMember;
+ if (traitFunc.Body == null) //we do this check only if trait function body is null
+ {
+ var classMem = cl.Members.Where(clMem => clMem is Function).FirstOrDefault(clMem => ((Function)clMem).Body != null && clMem.CompileName == traitMember.CompileName);
+ if (classMem != null) {
+ Function classFunc = (Function)classMem;
+ refinementTransformer.CheckOverride_FunctionParameters(classFunc, traitFunc);
+ } else if (!cl.Module.IsAbstract && traitFunc.Body == null && classMem == null)
+ Error(cl, "class: {0} does not implement trait member: {1}", cl.CompileName, traitFunc.CompileName);
+ }
+ }
+ if (traitMember is Method) {
+ Method traitMethod = (Method)traitMember;
+ if (traitMethod.Body == null) //we do this check only if trait method body is null
+ {
+ var classMem = cl.Members.Where(clMem => clMem is Method).FirstOrDefault(clMem => ((Method)clMem).Body != null && clMem.CompileName == traitMember.CompileName);
+ if (classMem != null) {
+ Method classMethod = (Method)classMem;
+ refinementTransformer.CheckOverride_MethodParameters(classMethod, traitMethod);
+ }
+ if (!cl.Module.IsAbstract && traitMethod.Body == null && classMem == null)
+ Error(cl, "class: {0} does not implement trait member: {1}", cl.CompileName, traitMethod.CompileName);
+ }
+ }
+ }
+ }
+ }
+
/// <summary>
/// Assumes type parameters have already been pushed, and that all types in class members have been resolved
/// </summary>
@@ -2898,11 +3058,12 @@ namespace Microsoft.Dafny
}
}
- void AddDatatypeDependencyEdge(IndDatatypeDecl/*!*/ dt, Type/*!*/ tp, Graph<IndDatatypeDecl/*!*/>/*!*/ dependencies) {
+ void AddDatatypeDependencyEdge(IndDatatypeDecl dt, Type tp, Graph<IndDatatypeDecl> dependencies) {
Contract.Requires(dt != null);
Contract.Requires(tp != null);
Contract.Requires(dependencies != null); // more expensive check: Contract.Requires(cce.NonNullElements(dependencies));
+ tp = tp.NormalizeExpand();
var dependee = tp.AsIndDatatype;
if (dependee != null && dt.Module == dependee.Module) {
dependencies.AddEdge(dt, dependee);
@@ -2995,6 +3156,7 @@ namespace Microsoft.Dafny
}
bool CheckCanBeConstructed(Type tp, List<TypeParameter> typeParametersUsed) {
+ tp = tp.NormalizeExpand();
var dependee = tp.AsIndDatatype;
if (dependee == null) {
// the type is not an inductive datatype, which means it is always possible to construct it
@@ -3227,8 +3389,9 @@ namespace Microsoft.Dafny
ResolveExpression(fe.E, false, codeContext);
Type t = fe.E.Type;
Contract.Assert(t != null); // follows from postcondition of ResolveExpression
- if (t is CollectionType) {
- t = ((CollectionType)t).Arg;
+ var collType = t.AsCollectionType;
+ if (collType != null) {
+ t = collType.Arg;
}
if (!UnifyTypes(t, new ObjectType())) {
Error(fe.E, "a {0}-clause expression must denote an object or a collection of objects (instead got {1})", kind, fe.E.Type);
@@ -3772,6 +3935,10 @@ namespace Microsoft.Dafny
} else if (type is UserDefinedType) {
var t = (UserDefinedType)type;
var isArrow = t is ArrowType;
+ if (!isArrow && (t.ResolvedClass != null || t.ResolvedParam != null)) {
+ // Apparently, this type has already been resolved
+ return null;
+ }
foreach (Type tt in t.TypeArgs) {
ResolveType(t.tok, tt, option, defaultTypeArguments);
if (tt.IsSubrangeType && !isArrow) {
@@ -3960,6 +4127,10 @@ namespace Microsoft.Dafny
successSoFar = UnifyTypes(aa.TypeArgs[i], bb.TypeArgs[i]);
}
return successSoFar;
+ } else if ((bb.ResolvedClass is ClassDecl) && (aa.ResolvedClass is TraitDecl)) {
+ return ((ClassDecl)bb.ResolvedClass).Trait.FullCompileName == ((TraitDecl)aa.ResolvedClass).FullCompileName;
+ } else if ((aa.ResolvedClass is ClassDecl) && (bb.ResolvedClass is TraitDecl)) {
+ return ((ClassDecl)aa.ResolvedClass).Trait.FullCompileName == ((TraitDecl)bb.ResolvedClass).FullCompileName;
} else if (aa.ResolvedParam != null && aa.ResolvedParam == bb.ResolvedParam) {
// type parameters
if (aa.TypeArgs.Count != bb.TypeArgs.Count) {
@@ -3977,7 +4148,6 @@ namespace Microsoft.Dafny
// something is wrong; either aa or bb wasn't properly resolved, or they don't unify
return false;
}
-
} else {
Contract.Assert(false); throw new cce.UnreachableException(); // unexpected type
}
@@ -4016,7 +4186,7 @@ namespace Microsoft.Dafny
// In the remaining cases, proxy is a restricted proxy and t is a non-proxy
} else if (proxy is DatatypeProxy) {
var dtp = (DatatypeProxy)proxy;
- if (!dtp.Co && t.IsIndDatatype) {
+ if (!dtp.Co && t.NormalizeExpand().IsIndDatatype) {
// all is fine, proxy can be redirected to t
} else if (dtp.Co && t.IsCoDatatype) {
// all is fine, proxy can be redirected to t
@@ -4059,7 +4229,7 @@ namespace Microsoft.Dafny
} else if (!UnifyTypes(iProxy.Arg, iProxy.Range)) {
return false;
}
- } else if (iProxy.AllowArray && t.IsArrayType && (t.AsArrayType).Dims == 1) {
+ } else if (iProxy.AllowArray && t.IsArrayType && t.AsArrayType.Dims == 1) {
Type elType = UserDefinedType.ArrayElementType(t);
if (!UnifyTypes(iProxy.Domain, Type.Int)) {
return false;
@@ -4126,7 +4296,7 @@ namespace Microsoft.Dafny
} else if (b is IndexableTypeProxy && ((IndexableTypeProxy)b).AllowArray) {
var ib = (IndexableTypeProxy)b;
// the intersection of ObjectTypeProxy and IndexableTypeProxy is an array type
- a.T = builtIns.ArrayType(1, ib.Arg);
+ a.T = ResolvedArrayType(Token.NoToken, 1, ib.Arg);
b.T = a.T;
return UnifyTypes(ib.Arg, ib.Range);
} else {
@@ -4208,6 +4378,20 @@ namespace Microsoft.Dafny
}
/// <summary>
+ /// Returns a resolved type denoting an array type with dimension "dims" and element type "arg".
+ /// Callers are expected to provide "arg" as an already resolved type. (Note, a proxy type is resolved--
+ /// only types that contain identifiers stand the possibility of not being resolved.)
+ /// </summary>
+ Type ResolvedArrayType(IToken tok, int dims, Type arg) {
+ Contract.Requires(tok != null);
+ Contract.Requires(1 <= dims);
+ Contract.Requires(arg != null);
+ var at = builtIns.ArrayType(tok, dims, new List<Type> { arg }, false);
+ ResolveType(tok, at, ResolveTypeOptionEnum.DontInfer, null);
+ return at;
+ }
+
+ /// <summary>
/// "specContextOnly" means that the statement must be erasable, that is, it should be okay to omit it
/// at run time. That means it must not have any side effects on non-ghost variables, for example.
/// </summary>
@@ -4394,7 +4578,7 @@ namespace Microsoft.Dafny
{
Error(local.Tok, "assumption variable must be ghost");
}
- if (!(local.Type is BoolType))
+ if (!(local.Type.IsBoolType))
{
Error(s, "assumption variable must be of type 'bool'");
}
@@ -4788,7 +4972,7 @@ namespace Microsoft.Dafny
}
UserDefinedType sourceType = null;
DatatypeDecl dtd = null;
- if (s.Source.Type.NormalizeExpand().IsDatatype) {
+ if (s.Source.Type.IsDatatype) {
sourceType = (UserDefinedType)s.Source.Type.NormalizeExpand();
dtd = cce.NonNull((DatatypeDecl)sourceType.ResolvedClass);
}
@@ -4902,7 +5086,7 @@ namespace Microsoft.Dafny
guess = Expression.CreateSubtract(bin.E0, bin.E1);
break;
case BinaryExpr.ResolvedOpcode.NeqCommon:
- if (bin.E0.Type is IntType || bin.E0.Type is RealType) {
+ if (bin.E0.Type.IsIntegerType || bin.E0.Type.IsRealType) {
// for A != B where A and B are integers, use the absolute difference between A and B (that is: if A <= B then B-A else A-B)
var AminusB = Expression.CreateSubtract(bin.E0, bin.E1);
var BminusA = Expression.CreateSubtract(bin.E1, bin.E0);
@@ -5346,7 +5530,7 @@ namespace Microsoft.Dafny
}
} else if (lhs is SeqSelectExpr) {
var ll = (SeqSelectExpr)lhs;
- if (!UnifyTypes(ll.Seq.Type, builtIns.ArrayType(1, new InferredTypeProxy()))) {
+ if (!UnifyTypes(ll.Seq.Type, ResolvedArrayType(ll.Seq.tok, 1, new InferredTypeProxy()))) {
Error(ll.Seq, "LHS of array assignment must denote an array element (found {0})", ll.Seq.Type);
}
if (!ll.SelectOne) {
@@ -5649,8 +5833,6 @@ namespace Microsoft.Dafny
}
}
-
-
Type ResolveTypeRhs(TypeRhs rr, Statement stmt, bool specContextOnly, ICodeContext codeContext) {
Contract.Requires(rr != null);
Contract.Requires(stmt != null);
@@ -5667,9 +5849,6 @@ namespace Microsoft.Dafny
Contract.Assert(rr.Arguments == null && rr.OptionalNameComponent == null && rr.InitCall == null);
ResolveType(stmt.Tok, rr.EType, ResolveTypeOptionEnum.InferTypeProxies, null);
int i = 0;
- if (rr.EType.IsSubrangeType) {
- Error(stmt, "sorry, cannot instantiate 'array' type with a subrange type");
- }
foreach (Expression dim in rr.ArrayDimensions) {
Contract.Assert(dim != null);
ResolveExpression(dim, true, codeContext);
@@ -5678,7 +5857,7 @@ namespace Microsoft.Dafny
}
i++;
}
- rr.Type = builtIns.ArrayType(rr.ArrayDimensions.Count, rr.EType);
+ rr.Type = ResolvedArrayType(stmt.Tok, rr.ArrayDimensions.Count, rr.EType);
} else {
var initCallTok = rr.Tok;
if (rr.OptionalNameComponent == null && rr.Arguments != null) {
@@ -5718,10 +5897,13 @@ namespace Microsoft.Dafny
// ---------- new C
Contract.Assert(rr.ArrayDimensions == null && rr.OptionalNameComponent == null && rr.InitCall == null);
}
- if (!callsConstructor && rr.EType is UserDefinedType) {
- var udt = (UserDefinedType)rr.EType;
+ if (rr.EType.NormalizeExpand() is UserDefinedType) {
+ var udt = (UserDefinedType)rr.EType.NormalizeExpand();
var cl = (ClassDecl)udt.ResolvedClass; // cast is guaranteed by the call to rr.EType.IsRefType above, together with the "rr.EType is UserDefinedType" test
- if (cl.HasConstructor) {
+ if (cl is TraitDecl) {
+ Error(stmt, "new cannot be applied to a trait");
+ }
+ if (!callsConstructor && cl.HasConstructor) {
Error(stmt, "when allocating an object of type '{0}', one of its constructor methods must be called", cl.Name);
}
}
@@ -5855,6 +6037,20 @@ namespace Microsoft.Dafny
}
} else if (t.ResolvedClass != null) {
List<Type> newArgs = null; // allocate it lazily
+ var resolvedClass = t.ResolvedClass;
+#if TEST_TYPE_SYNONYM_TRANSPARENCY
+ if (resolvedClass is TypeSynonymDecl && resolvedClass.Name == "type#synonym#transparency#test") {
+ // Usually, all type parameters mentioned in the definition of a type synonym are also type parameters
+ // to the type synonym itself, but in this instrumented testing, that is not so, so we also do a substitution
+ // in the .Rhs of the synonym.
+ var syn = (TypeSynonymDecl)resolvedClass;
+ var r = SubstType(syn.Rhs, subst);
+ if (r != syn.Rhs) {
+ resolvedClass = new TypeSynonymDecl(syn.tok, syn.Name, syn.TypeArgs, syn.Module, r, null);
+ newArgs = new List<Type>();
+ }
+ }
+#endif
for (int i = 0; i < t.TypeArgs.Count; i++) {
Type p = t.TypeArgs[i];
Type s = SubstType(p, subst);
@@ -5873,7 +6069,7 @@ namespace Microsoft.Dafny
// there were no substitutions
return type;
} else {
- return new UserDefinedType(t.tok, t.Name, t.ResolvedClass, newArgs, t.Path);
+ return new UserDefinedType(t.tok, t.Name, resolvedClass, newArgs, t.Path);
}
} else {
// there's neither a resolved param nor a resolved class, which means the UserDefinedType wasn't
@@ -5919,6 +6115,17 @@ namespace Microsoft.Dafny
/// "twoState" implies that "old" and "fresh" expressions are allowed.
/// </summary>
public void ResolveExpression(Expression expr, bool twoState, ICodeContext codeContext) {
+#if TEST_TYPE_SYNONYM_TRANSPARENCY
+ ResolveExpressionX(expr, twoState, codeContext);
+ // For testing purposes, change the type of "expr" to a type synonym (mwo-ha-ha-ha!)
+ var t = expr.Type;
+ Contract.Assert(t != null);
+ var sd = new TypeSynonymDecl(expr.tok, "type#synonym#transparency#test", new List<TypeParameter>(), codeContext.EnclosingModule, t, null);
+ var ts = new UserDefinedType(expr.tok, "type#synonym#transparency#test", sd, new List<Type>(), null);
+ expr.DebugTest_ChangeType(ts);
+ }
+ public void ResolveExpressionX(Expression expr, bool twoState, ICodeContext codeContext) {
+#endif
Contract.Requires(expr != null);
Contract.Requires(codeContext != null);
Contract.Ensures(expr.Type != null);
@@ -5960,7 +6167,7 @@ namespace Microsoft.Dafny
e.ResolvedExpression = e.E;
} else {
Expression zero;
- if (e.E.Type is RealType) {
+ if (e.E.Type.IsRealType) {
// we know for sure that this is a real-unary-minus
zero = new LiteralExpr(e.tok, Basetypes.BigDec.ZERO);
} else {
@@ -6130,7 +6337,7 @@ namespace Microsoft.Dafny
ResolveExpression(e.Array, twoState, codeContext);
Contract.Assert(e.Array.Type != null); // follows from postcondition of ResolveExpression
Type elementType = new InferredTypeProxy();
- if (!UnifyTypes(e.Array.Type, builtIns.ArrayType(e.Indices.Count, elementType))) {
+ if (!UnifyTypes(e.Array.Type, ResolvedArrayType(e.Array.tok, e.Indices.Count, elementType))) {
Error(e.Array, "array selection requires an array{0} (got {1})", e.Indices.Count, e.Array.Type);
}
int i = 0;
@@ -6185,8 +6392,8 @@ namespace Microsoft.Dafny
}
expr.Type = e.Seq.Type;
- } else if (e.Seq.Type is UserDefinedType && ((UserDefinedType)e.Seq.Type).IsDatatype) {
- DatatypeDecl dt = ((UserDefinedType)e.Seq.Type).AsDatatype;
+ } else if (e.Seq.Type.IsDatatype) {
+ var dt = e.Seq.Type.AsDatatype;
if (!(e.Index is IdentifierSequence || (e.Index is LiteralExpr && ((LiteralExpr)e.Index).Value is BigInteger))) {
Error(expr, "datatype updates must be to datatype destructors");
@@ -6269,7 +6476,7 @@ namespace Microsoft.Dafny
if (!UnifyTypes(e.E.Type, new SetType(new InferredTypeProxy())) && !UnifyTypes(e.E.Type, new SeqType(new InferredTypeProxy()))) {
Error(e.tok, "can only form a multiset from a seq or set.");
}
- expr.Type = new MultiSetType(((CollectionType)e.E.Type).Arg);
+ expr.Type = new MultiSetType(e.E.Type.AsCollectionType.Arg);
} else if (expr is UnaryOpExpr) {
var e = (UnaryOpExpr)expr;
@@ -6293,10 +6500,10 @@ namespace Microsoft.Dafny
Error(expr, "fresh expressions are not allowed in this context");
}
// the type of e.E must be either an object or a collection of objects
- Type t = e.E.Type;
+ Type t = e.E.Type.NormalizeExpand();
Contract.Assert(t != null); // follows from postcondition of ResolveExpression
if (t is CollectionType) {
- t = ((CollectionType)t).Arg;
+ t = ((CollectionType)t).Arg.NormalizeExpand();
}
if (t is ObjectType) {
// fine
@@ -6318,11 +6525,11 @@ namespace Microsoft.Dafny
ResolveType(e.tok, e.ToType, new ResolveTypeOption(ResolveTypeOptionEnum.DontInfer), null);
ResolveExpression(e.E, twoState, codeContext);
if (e.ToType is IntType) {
- if (!(e.E.Type is RealType)) {
+ if (!(e.E.Type.IsRealType)) {
Error(expr, "type conversion to int is allowed only from real (got {0})", e.E.Type);
}
} else if (e.ToType is RealType) {
- if (!(e.E.Type is IntType)) {
+ if (!(e.E.Type.IsIntegerType)) {
Error(expr, "type conversion to real is allowed only from int (got {0})", e.E.Type);
}
} else {
@@ -6388,15 +6595,15 @@ namespace Microsoft.Dafny
case BinaryExpr.Opcode.Lt:
case BinaryExpr.Opcode.Le:
case BinaryExpr.Opcode.Add: {
- if (e.Op == BinaryExpr.Opcode.Lt && e.E0.Type.IsIndDatatype) {
+ if (e.Op == BinaryExpr.Opcode.Lt && (e.E0.Type.NormalizeExpand().IsIndDatatype || e.E0.Type.IsTypeParameter)) {
if (UnifyTypes(e.E1.Type, new DatatypeProxy(false))) {
e.ResolvedOp = BinaryExpr.ResolvedOpcode.RankLt;
} else {
Error(expr, "arguments to rank comparison must be datatypes (instead of {0})", e.E1.Type);
}
expr.Type = Type.Bool;
- } else if (e.Op == BinaryExpr.Opcode.Lt && e.E1.Type.IsIndDatatype) {
- if (UnifyTypes(e.E0.Type, new DatatypeProxy(false)) || e.E0.Type.IsTypeParameter) {
+ } else if (e.Op == BinaryExpr.Opcode.Lt && e.E1.Type.NormalizeExpand().IsIndDatatype) {
+ if (UnifyTypes(e.E0.Type, new DatatypeProxy(false))) {
e.ResolvedOp = BinaryExpr.ResolvedOpcode.RankLt;
} else {
Error(expr, "arguments to rank comparison must be datatypes (instead of {0})", e.E0.Type);
@@ -6425,14 +6632,14 @@ namespace Microsoft.Dafny
case BinaryExpr.Opcode.Mul:
case BinaryExpr.Opcode.Gt:
case BinaryExpr.Opcode.Ge: {
- if (e.Op == BinaryExpr.Opcode.Gt && e.E0.Type.IsIndDatatype) {
+ if (e.Op == BinaryExpr.Opcode.Gt && e.E0.Type.NormalizeExpand().IsIndDatatype) {
if (UnifyTypes(e.E1.Type, new DatatypeProxy(false)) || e.E1.Type.IsTypeParameter) {
e.ResolvedOp = BinaryExpr.ResolvedOpcode.RankGt;
} else {
Error(expr, "arguments to rank comparison must be datatypes (instead of {0})", e.E1.Type);
}
expr.Type = Type.Bool;
- } else if (e.Op == BinaryExpr.Opcode.Gt && e.E1.Type.IsIndDatatype) {
+ } else if (e.Op == BinaryExpr.Opcode.Gt && (e.E1.Type.NormalizeExpand().IsIndDatatype || e.E1.Type.IsTypeParameter)) {
if (UnifyTypes(e.E0.Type, new DatatypeProxy(false))) {
e.ResolvedOp = BinaryExpr.ResolvedOpcode.RankGt;
} else {
@@ -6775,7 +6982,7 @@ namespace Microsoft.Dafny
Contract.Assert(me.Source.Type != null); // follows from postcondition of ResolveExpression
UserDefinedType sourceType = null;
DatatypeDecl dtd = null;
- if (me.Source.Type.NormalizeExpand().IsDatatype) {
+ if (me.Source.Type.IsDatatype) {
sourceType = (UserDefinedType)me.Source.Type.NormalizeExpand();
dtd = cce.NonNull((DatatypeDecl)sourceType.ResolvedClass);
}
@@ -6870,7 +7077,7 @@ namespace Microsoft.Dafny
DatatypeDecl dtd = null;
UserDefinedType udt = null;
if (sourceType.IsDatatype) {
- udt = (UserDefinedType)sourceType;
+ udt = (UserDefinedType)sourceType.NormalizeExpand();
dtd = (DatatypeDecl)udt.ResolvedClass;
}
// Find the constructor in the given datatype
@@ -6960,7 +7167,9 @@ namespace Microsoft.Dafny
}
}
- public bool ComparableTypes(Type A, Type B) {
+ private bool ComparableTypes(Type A, Type B) {
+ A = A.NormalizeExpand();
+ B = B.NormalizeExpand();
if (A.IsArrayType && B.IsArrayType) {
Type a = UserDefinedType.ArrayElementType(A);
Type b = UserDefinedType.ArrayElementType(B);
@@ -7620,12 +7829,12 @@ namespace Microsoft.Dafny
for (int j = 0; j < bvars.Count; j++) {
var bv = bvars[j];
var bounds = new List<ComprehensionExpr.BoundedPool>();
- if (bv.Type is BoolType) {
+ if (bv.Type.IsBoolType) {
// easy
bounds.Add(new ComprehensionExpr.BoolBoundedPool());
} else {
bool foundBoundsForBv = false;
- if (bv.Type.IsIndDatatype && (bv.Type.AsIndDatatype).HasFinitePossibleValues) {
+ if (bv.Type.IsIndDatatype && bv.Type.AsIndDatatype.HasFinitePossibleValues) {
bounds.Add(new ComprehensionExpr.DatatypeBoundedPool(bv.Type.AsIndDatatype));
foundBoundsForBv = true;
}
@@ -8123,6 +8332,7 @@ namespace Microsoft.Dafny
/// </summary>
public static BinaryExpr.ResolvedOpcode ResolveOp(BinaryExpr.Opcode op, Type operandType) {
Contract.Requires(operandType != null);
+ operandType = operandType.NormalizeExpand();
switch (op) {
case BinaryExpr.Opcode.Iff: return BinaryExpr.ResolvedOpcode.Iff;
case BinaryExpr.Opcode.Imp: return BinaryExpr.ResolvedOpcode.Imp;
diff --git a/Source/Dafny/Rewriter.cs b/Source/Dafny/Rewriter.cs
index f57c1380..3f4f57b8 100644
--- a/Source/Dafny/Rewriter.cs
+++ b/Source/Dafny/Rewriter.cs
@@ -174,7 +174,7 @@ namespace Microsoft.Dafny
}
} else if (member is Function && member.Name == "Valid" && !member.IsStatic) {
var fn = (Function)member;
- if (fn.Formals.Count == 0 && fn.ResultType is BoolType) {
+ if (fn.Formals.Count == 0 && fn.ResultType.IsBoolType) {
Valid = fn;
}
}
@@ -201,7 +201,7 @@ namespace Microsoft.Dafny
Boogie.IToken tok = new AutoGeneratedToken(member.tok);
if (member is Function && member.Name == "Valid" && !member.IsStatic) {
var valid = (Function)member;
- if (valid.IsGhost && valid.ResultType is BoolType) {
+ if (valid.IsGhost && valid.ResultType.IsBoolType) {
Expression c;
if (valid.RefinementBase == null) {
var c0 = BinBoolExpr(tok, BinaryExpr.ResolvedOpcode.InSet, self, Repr); // this in Repr
@@ -265,7 +265,7 @@ namespace Microsoft.Dafny
var valid = new FunctionCallExpr(tok, "Valid", implicitSelf, tok, new List<Expression>());
valid.Function = Valid;
valid.Type = Type.Bool;
- // Add the identity substitution to this call
+ // Add the identity substitution to this call
valid.TypeArgumentSubstitutions = new Dictionary<TypeParameter, Type>();
foreach (var p in cl.TypeArgs) {
valid.TypeArgumentSubstitutions.Add(p, new UserDefinedType(p));
diff --git a/Source/Dafny/Scanner.cs b/Source/Dafny/Scanner.cs
index 7d453d2d..30e4071c 100644
--- a/Source/Dafny/Scanner.cs
+++ b/Source/Dafny/Scanner.cs
@@ -211,8 +211,8 @@ public class UTF8Buffer: Buffer {
public class Scanner {
const char EOL = '\n';
const int eofSym = 0; /* pdt */
- const int maxT = 127;
- const int noSym = 127;
+ const int maxT = 129;
+ const int noSym = 129;
[ContractInvariantMethod]
@@ -502,64 +502,66 @@ public class Scanner {
case "as": t.kind = 26; break;
case "default": t.kind = 27; break;
case "class": t.kind = 28; break;
- case "ghost": t.kind = 29; break;
- case "static": t.kind = 30; break;
- case "datatype": t.kind = 31; break;
- case "codatatype": t.kind = 32; break;
- case "var": t.kind = 34; break;
- case "type": t.kind = 36; break;
- case "iterator": t.kind = 38; break;
- case "yields": t.kind = 39; break;
- case "returns": t.kind = 40; break;
- case "method": t.kind = 44; break;
- case "lemma": t.kind = 45; break;
- case "colemma": t.kind = 46; break;
- case "comethod": t.kind = 47; break;
- case "constructor": t.kind = 48; break;
- case "modifies": t.kind = 49; break;
- case "free": t.kind = 50; break;
- case "ensures": t.kind = 51; break;
- case "decreases": t.kind = 52; break;
- case "yield": t.kind = 53; break;
- case "bool": t.kind = 54; break;
- case "nat": t.kind = 55; break;
- case "int": t.kind = 56; break;
- case "real": t.kind = 57; break;
- case "set": t.kind = 58; break;
- case "multiset": t.kind = 59; break;
- case "seq": t.kind = 60; break;
- case "map": t.kind = 61; break;
- case "object": t.kind = 62; break;
- case "function": t.kind = 64; break;
- case "predicate": t.kind = 65; break;
- case "copredicate": t.kind = 66; break;
- case "label": t.kind = 68; break;
- case "break": t.kind = 69; break;
- case "where": t.kind = 70; break;
- case "return": t.kind = 72; break;
- case "assume": t.kind = 74; break;
- case "new": t.kind = 75; break;
- case "if": t.kind = 78; break;
- case "else": t.kind = 79; break;
- case "case": t.kind = 80; break;
- case "while": t.kind = 81; break;
- case "invariant": t.kind = 82; break;
- case "match": t.kind = 83; break;
- case "assert": t.kind = 84; break;
- case "print": t.kind = 85; break;
- case "forall": t.kind = 86; break;
- case "parallel": t.kind = 87; break;
- case "modify": t.kind = 88; break;
- case "calc": t.kind = 89; break;
- case "in": t.kind = 107; break;
- case "false": t.kind = 114; break;
- case "true": t.kind = 115; break;
- case "null": t.kind = 116; break;
- case "this": t.kind = 117; break;
- case "fresh": t.kind = 118; break;
- case "old": t.kind = 119; break;
- case "then": t.kind = 120; break;
- case "exists": t.kind = 123; break;
+ case "extends": t.kind = 29; break;
+ case "trait": t.kind = 30; break;
+ case "ghost": t.kind = 31; break;
+ case "static": t.kind = 32; break;
+ case "datatype": t.kind = 33; break;
+ case "codatatype": t.kind = 34; break;
+ case "var": t.kind = 36; break;
+ case "type": t.kind = 38; break;
+ case "iterator": t.kind = 40; break;
+ case "yields": t.kind = 41; break;
+ case "returns": t.kind = 42; break;
+ case "method": t.kind = 46; break;
+ case "lemma": t.kind = 47; break;
+ case "colemma": t.kind = 48; break;
+ case "comethod": t.kind = 49; break;
+ case "constructor": t.kind = 50; break;
+ case "modifies": t.kind = 51; break;
+ case "free": t.kind = 52; break;
+ case "ensures": t.kind = 53; break;
+ case "decreases": t.kind = 54; break;
+ case "yield": t.kind = 55; break;
+ case "bool": t.kind = 56; break;
+ case "nat": t.kind = 57; break;
+ case "int": t.kind = 58; break;
+ case "real": t.kind = 59; break;
+ case "set": t.kind = 60; break;
+ case "multiset": t.kind = 61; break;
+ case "seq": t.kind = 62; break;
+ case "map": t.kind = 63; break;
+ case "object": t.kind = 64; break;
+ case "function": t.kind = 66; break;
+ case "predicate": t.kind = 67; break;
+ case "copredicate": t.kind = 68; break;
+ case "label": t.kind = 70; break;
+ case "break": t.kind = 71; break;
+ case "where": t.kind = 72; break;
+ case "return": t.kind = 74; break;
+ case "assume": t.kind = 76; break;
+ case "new": t.kind = 77; break;
+ case "if": t.kind = 80; break;
+ case "else": t.kind = 81; break;
+ case "case": t.kind = 82; break;
+ case "while": t.kind = 83; break;
+ case "invariant": t.kind = 84; break;
+ case "match": t.kind = 85; break;
+ case "assert": t.kind = 86; break;
+ case "print": t.kind = 87; break;
+ case "forall": t.kind = 88; break;
+ case "parallel": t.kind = 89; break;
+ case "modify": t.kind = 90; break;
+ case "calc": t.kind = 91; break;
+ case "in": t.kind = 109; break;
+ case "false": t.kind = 116; break;
+ case "true": t.kind = 117; break;
+ case "null": t.kind = 118; break;
+ case "this": t.kind = 119; break;
+ case "fresh": t.kind = 120; break;
+ case "old": t.kind = 121; break;
+ case "then": t.kind = 122; break;
+ case "exists": t.kind = 125; break;
default: break;
}
}
@@ -710,68 +712,68 @@ public class Scanner {
else if (ch >= '0' && ch <= '9') {AddCh(); goto case 32;}
else {t.kind = 5; break;}
case 33:
- {t.kind = 35; break;}
+ {t.kind = 37; break;}
case 34:
- {t.kind = 41; break;}
+ {t.kind = 43; break;}
case 35:
- {t.kind = 67; break;}
+ {t.kind = 69; break;}
case 36:
- {t.kind = 71; break;}
- case 37:
{t.kind = 73; break;}
+ case 37:
+ {t.kind = 75; break;}
case 38:
- {t.kind = 76; break;}
+ {t.kind = 78; break;}
case 39:
- {t.kind = 77; break;}
+ {t.kind = 79; break;}
case 40:
- {t.kind = 90; break;}
- case 41:
{t.kind = 92; break;}
+ case 41:
+ {t.kind = 94; break;}
case 42:
- {t.kind = 93; break;}
+ {t.kind = 95; break;}
case 43:
- {t.kind = 94; break;}
+ {t.kind = 96; break;}
case 44:
- {t.kind = 95; break;}
+ {t.kind = 97; break;}
case 45:
- {t.kind = 96; break;}
+ {t.kind = 98; break;}
case 46:
- {t.kind = 97; break;}
+ {t.kind = 99; break;}
case 47:
- {t.kind = 98; break;}
+ {t.kind = 100; break;}
case 48:
- {t.kind = 99; break;}
+ {t.kind = 101; break;}
case 49:
- {t.kind = 100; break;}
- case 50:
{t.kind = 102; break;}
+ case 50:
+ {t.kind = 104; break;}
case 51:
if (ch == '&') {AddCh(); goto case 52;}
else {goto case 0;}
case 52:
- {t.kind = 103; break;}
+ {t.kind = 105; break;}
case 53:
- {t.kind = 104; break;}
+ {t.kind = 106; break;}
case 54:
- {t.kind = 105; break;}
+ {t.kind = 107; break;}
case 55:
- {t.kind = 106; break;}
+ {t.kind = 108; break;}
case 56:
- {t.kind = 109; break;}
- case 57:
{t.kind = 111; break;}
+ case 57:
+ {t.kind = 113; break;}
case 58:
- {t.kind = 112; break;}
+ {t.kind = 114; break;}
case 59:
- {t.kind = 113; break;}
+ {t.kind = 115; break;}
case 60:
- {t.kind = 122; break;}
- case 61:
{t.kind = 124; break;}
+ case 61:
+ {t.kind = 126; break;}
case 62:
- {t.kind = 125; break;}
+ {t.kind = 127; break;}
case 63:
- {t.kind = 126; break;}
+ {t.kind = 128; break;}
case 64:
recEnd = pos; recKind = 7;
if (ch == '=') {AddCh(); goto case 36;}
@@ -784,46 +786,46 @@ public class Scanner {
else if (ch == '=') {AddCh(); goto case 72;}
else {t.kind = 25; break;}
case 66:
- recEnd = pos; recKind = 110;
+ recEnd = pos; recKind = 112;
if (ch == '>') {AddCh(); goto case 15;}
- else {t.kind = 110; break;}
+ else {t.kind = 112; break;}
case 67:
- recEnd = pos; recKind = 108;
+ recEnd = pos; recKind = 110;
if (ch == 'i') {AddCh(); goto case 21;}
else if (ch == '=') {AddCh(); goto case 42;}
- else {t.kind = 108; break;}
+ else {t.kind = 110; break;}
case 68:
- recEnd = pos; recKind = 33;
+ recEnd = pos; recKind = 35;
if (ch == '|') {AddCh(); goto case 54;}
- else {t.kind = 33; break;}
+ else {t.kind = 35; break;}
case 69:
- recEnd = pos; recKind = 63;
+ recEnd = pos; recKind = 65;
if (ch == '.') {AddCh(); goto case 73;}
- else {t.kind = 63; break;}
+ else {t.kind = 65; break;}
case 70:
- recEnd = pos; recKind = 42;
+ recEnd = pos; recKind = 44;
if (ch == '=') {AddCh(); goto case 74;}
- else {t.kind = 42; break;}
+ else {t.kind = 44; break;}
case 71:
- recEnd = pos; recKind = 43;
+ recEnd = pos; recKind = 45;
if (ch == '=') {AddCh(); goto case 41;}
- else {t.kind = 43; break;}
+ else {t.kind = 45; break;}
case 72:
- recEnd = pos; recKind = 37;
+ recEnd = pos; recKind = 39;
if (ch == '>') {AddCh(); goto case 48;}
- else {t.kind = 37; break;}
+ else {t.kind = 39; break;}
case 73:
- recEnd = pos; recKind = 121;
+ recEnd = pos; recKind = 123;
if (ch == '.') {AddCh(); goto case 34;}
- else {t.kind = 121; break;}
+ else {t.kind = 123; break;}
case 74:
- recEnd = pos; recKind = 91;
+ recEnd = pos; recKind = 93;
if (ch == '=') {AddCh(); goto case 75;}
- else {t.kind = 91; break;}
+ else {t.kind = 93; break;}
case 75:
- recEnd = pos; recKind = 101;
+ recEnd = pos; recKind = 103;
if (ch == '>') {AddCh(); goto case 46;}
- else {t.kind = 101; break;}
+ else {t.kind = 103; break;}
}
t.val = new String(tval, 0, tlen);
diff --git a/Source/Dafny/Translator.cs b/Source/Dafny/Translator.cs
index 63158bd7..03020860 100644
--- a/Source/Dafny/Translator.cs
+++ b/Source/Dafny/Translator.cs
@@ -613,16 +613,21 @@ namespace Microsoft.Dafny {
sink.TopLevelDeclarations.Add(new Bpl.Axiom(ctor.tok, q, "Constructor injectivity"));
if (dt is IndDatatypeDecl) {
- if (arg.Type.IsDatatype || arg.Type.IsTypeParameter) {
+ var argType = arg.Type.NormalizeExpand();
+ if (argType.IsDatatype || argType.IsTypeParameter) {
// for datatype: axiom (forall params :: DtRank(params_i) < DtRank(#dt.ctor(params)));
// for type-parameter type: axiom (forall params :: DtRank(Unbox(params_i)) < DtRank(#dt.ctor(params)));
CreateBoundVariables(ctor.Formals, out bvs, out args);
Bpl.Expr lhs = FunctionCall(ctor.tok, arg.Type.IsDatatype ? BuiltinFunction.DtRank : BuiltinFunction.BoxRank, null, args[i]);
+ /* CHECK
+ Bpl.Expr lhs = FunctionCall(ctor.tok, BuiltinFunction.DtRank, null,
+ argType.IsDatatype ? args[i] : FunctionCall(ctor.tok, BuiltinFunction.Unbox, predef.DatatypeType, args[i]));
+ */
Bpl.Expr rhs = FunctionCall(ctor.tok, ctor.FullName, predef.DatatypeType, args);
rhs = FunctionCall(ctor.tok, BuiltinFunction.DtRank, null, rhs);
q = new Bpl.ForallExpr(ctor.tok, bvs, Bpl.Expr.Lt(lhs, rhs));
sink.TopLevelDeclarations.Add(new Bpl.Axiom(ctor.tok, q, "Inductive rank"));
- } else if (arg.Type is SeqType) {
+ } else if (argType is SeqType) {
// axiom (forall params, i: int :: 0 <= i && i < |arg| ==> DtRank(arg[i]) < DtRank(#dt.ctor(params)));
// that is:
// axiom (forall params, i: int :: 0 <= i && i < |arg| ==> DtRank(Unbox(Seq#Index(arg,i))) < DtRank(#dt.ctor(params)));
@@ -647,7 +652,7 @@ namespace Microsoft.Dafny {
rhs = FunctionCall(ctor.tok, BuiltinFunction.DtRank, null, rhs);
q = new Bpl.ForallExpr(ctor.tok, bvs, Bpl.Expr.Lt(lhs, rhs));
sink.TopLevelDeclarations.Add(new Bpl.Axiom(ctor.tok, q, "Inductive seq rank"));
- } else if (arg.Type is SetType) {
+ } else if (argType is SetType) {
// axiom (forall params, d: Datatype :: arg[d] ==> DtRank(d) < DtRank(#dt.ctor(params)));
// that is:
// axiom (forall params, d: Datatype :: arg[Box(d)] ==> DtRank(d) < DtRank(#dt.ctor(params)));
@@ -661,7 +666,7 @@ namespace Microsoft.Dafny {
rhs = FunctionCall(ctor.tok, BuiltinFunction.DtRank, null, rhs);
q = new Bpl.ForallExpr(ctor.tok, bvs, Bpl.Expr.Imp(ante, Bpl.Expr.Lt(lhs, rhs)));
sink.TopLevelDeclarations.Add(new Bpl.Axiom(ctor.tok, q, "Inductive set rank"));
- } else if (arg.Type is MultiSetType) {
+ } else if (argType is MultiSetType) {
// axiom (forall params, d: Datatype :: 0 < arg[d] ==> DtRank(d) < DtRank(#dt.ctor(params)));
// that is:
// axiom (forall params, d: Datatype :: 0 < arg[Box(d)] ==> DtRank(d) < DtRank(#dt.ctor(params)));
@@ -960,6 +965,12 @@ namespace Microsoft.Dafny {
// Makes a call to equality, if k is null, or otherwise prefix equality. For codatatypes.
Bpl.Expr CoEqualCall(CoDatatypeDecl codecl, List<Bpl.Expr> largs, List<Bpl.Expr> rargs, Bpl.Expr k, Bpl.Expr l, Bpl.Expr A, Bpl.Expr B, IToken tok = null) {
+ Contract.Requires(codecl != null);
+ Contract.Requires(largs != null);
+ Contract.Requires(rargs != null);
+ Contract.Requires(l != null);
+ Contract.Requires(A != null);
+ Contract.Requires(B != null);
if (tok == null) {
tok = A.tok;
}
@@ -974,6 +985,12 @@ namespace Microsoft.Dafny {
// Same as above, but with Dafny-typed type-argument lists
Bpl.Expr CoEqualCall(CoDatatypeDecl codecl, List<Type> largs, List<Type> rargs, Bpl.Expr k, Bpl.Expr l, Bpl.Expr A, Bpl.Expr B, IToken tok = null) {
+ Contract.Requires(codecl != null);
+ Contract.Requires(largs != null);
+ Contract.Requires(rargs != null);
+ Contract.Requires(l != null);
+ Contract.Requires(A != null);
+ Contract.Requires(B != null);
return CoEqualCall(codecl, Map(largs, TypeToTy), Map(rargs, TypeToTy), k, l, A, B, tok);
}
@@ -1096,7 +1113,18 @@ namespace Microsoft.Dafny {
if (c == program.BuiltIns.ObjectDecl) {
rhs = Bpl.Expr.True;
} else {
- rhs = BplOr(o_null, DType(o, o_ty));
+ //generating $o == null || implements$J(dtype(x))
+ if (c is TraitDecl)
+ {
+ var t = (TraitDecl)c;
+ var dtypeFunc = FunctionCall(o.tok, BuiltinFunction.DynamicType, null, o);
+ Bpl.Expr implementsFunc = FunctionCall(t.tok, "implements$" + t.Name, Bpl.Type.Bool, new List<Expr> { dtypeFunc });
+ rhs = BplOr(o_null, implementsFunc);
+ }
+ else
+ {
+ rhs = BplOr(o_null, DType(o, o_ty));
+ }
}
body = BplIff(is_o, rhs);
}
@@ -1104,6 +1132,31 @@ namespace Microsoft.Dafny {
sink.TopLevelDeclarations.Add(new Bpl.Axiom(c.tok, BplForall(vars, BplTrigger(is_o), body), name));
});
+ //this adds: function implements$J(ClassName): bool;
+ if (c is TraitDecl)
+ {
+ var arg_ref = new Bpl.Formal(c.tok, new Bpl.TypedIdent(c.tok, Bpl.TypedIdent.NoName, predef.Ty), true);
+ var res = new Bpl.Formal(c.tok, new Bpl.TypedIdent(c.tok, Bpl.TypedIdent.NoName, Bpl.Type.Bool), false);
+ var implement_intr = new Bpl.Function(c.tok, "implements$" + c.Name, new List<Variable> { arg_ref }, res);
+ sink.TopLevelDeclarations.Add(implement_intr);
+ }
+ //this adds: axiom implements$J(class.C);
+ else if (c is ClassDecl)
+ {
+ if (c.Trait != null)
+ {
+ //var dtypeFunc = FunctionCall(c.tok, BuiltinFunction.DynamicType, null, o);
+ //Bpl.Expr implementsFunc = FunctionCall(t.tok, "implements$" + t.Name, Bpl.Type.Bool, new List<Expr> { dtypeFunc });
+
+ var args = new Bpl.Formal(c.tok, new Bpl.TypedIdent(c.tok, Bpl.TypedIdent.NoName, predef.ClassNameType), true);
+ var ret_value = new Bpl.Formal(c.tok, new Bpl.TypedIdent(c.tok, Bpl.TypedIdent.NoName, Bpl.Type.Bool), false);
+ var funCall = new Bpl.FunctionCall(new Bpl.Function(c.tok, "implements$" + c.TraitId.val, new List<Variable> { args }, ret_value));
+ var expr = new Bpl.NAryExpr(c.tok, funCall, new List<Expr> { new Bpl.IdentifierExpr(c.tok, string.Format("class.{0}", c.FullSanitizedName), predef.ClassNameType) });
+ var implements_axiom = new Bpl.Axiom(c.tok, expr);
+ sink.TopLevelDeclarations.Add(implements_axiom);
+ }
+ }
+
foreach (MemberDecl member in c.Members) {
currentDeclaration = member;
if (member is Field) {
@@ -1124,6 +1177,10 @@ namespace Microsoft.Dafny {
AddClassMember_Function(f);
if (!IsOpaqueFunction(f) && !f.IsBuiltin && !(f.tok is IncludeToken)) { // Opaque function's well-formedness is checked on the full version
AddWellformednessCheck(f);
+ if (f.OverriddenFunction != null) //it means that f is overriding its associated parent function
+ {
+ AddFunctionOverrideCheckImpl(f);
+ }
}
var cop = f as CoPredicate;
if (cop != null) {
@@ -1143,6 +1200,12 @@ namespace Microsoft.Dafny {
if (!(m.tok is IncludeToken)) {
AddMethodImpl(m, proc, true);
}
+ if (m.OverriddenMethod != null) //method has overrided a parent method
+ {
+ var procOverrideChk = AddMethod(m, MethodTranslationKind.OverrideCheck);
+ sink.TopLevelDeclarations.Add(procOverrideChk);
+ AddMethodOverrideCheckImpl(m, procOverrideChk);
+ }
}
// the method spec itself
sink.TopLevelDeclarations.Add(AddMethod(m, MethodTranslationKind.InterModuleCall));
@@ -2473,7 +2536,7 @@ namespace Microsoft.Dafny {
var decrCaller = new List<Expr>();
foreach (var ee in m.Decreases.Expressions) {
decrToks.Add(ee.tok);
- decrTypes.Add(ee.Type);
+ decrTypes.Add(ee.Type.NormalizeExpand());
decrCaller.Add(exprTran.TrExpr(ee));
Expression es = Substitute(ee, receiverReplacement, substMap);
es = Substitute(es, null, decrSubstMap);
@@ -2566,6 +2629,552 @@ namespace Microsoft.Dafny {
_tmpIEs.Clear();
}
+ private void AddFunctionOverrideCheckImpl(Function f)
+ {
+ Contract.Requires(f != null);
+ //Contract.Requires(proc != null);
+ Contract.Requires(sink != null && predef != null);
+ Contract.Requires(f.OverriddenFunction != null);
+ Contract.Requires(f.Formals.Count == f.OverriddenFunction.Formals.Count);
+ Contract.Requires(currentModule == null && codeContext == null && loopHeapVarCount == 0 && _tmpIEs.Count == 0);
+ Contract.Ensures(currentModule == null && codeContext == null && loopHeapVarCount == 0 && _tmpIEs.Count == 0);
+
+ #region first procedure, no impl yet
+ //Function nf = new Function(f.tok, "OverrideCheck_" + f.Name, f.IsStatic, f.IsGhost, f.TypeArgs, f.OpenParen, f.Formals, f.ResultType, f.Req, f.Reads, f.Ens, f.Decreases, f.Body, f.Attributes, f.SignatureEllipsis);
+ //AddFunction(f);
+ currentModule = f.EnclosingClass.Module;
+ codeContext = f;
+
+ ExpressionTranslator etran = new ExpressionTranslator(this, predef, f.tok);
+ // parameters of the procedure
+ List<Variable> inParams = new List<Variable>();
+ if (!f.IsStatic)
+ {
+ Bpl.Expr wh = Bpl.Expr.And(
+ Bpl.Expr.Neq(new Bpl.IdentifierExpr(f.tok, "this", predef.RefType), predef.Null),
+ etran.GoodRef(f.tok, new Bpl.IdentifierExpr(f.tok, "this", predef.RefType), Resolver.GetReceiverType(f.tok, f)));
+ Bpl.Formal thVar = new Bpl.Formal(f.tok, new Bpl.TypedIdent(f.tok, "this", predef.RefType, wh), true);
+ inParams.Add(thVar);
+ }
+ foreach (Formal p in f.Formals)
+ {
+ Bpl.Type varType = TrType(p.Type);
+ Bpl.Expr wh = GetWhereClause(p.tok, new Bpl.IdentifierExpr(p.tok, p.AssignUniqueName(f), varType), p.Type, etran);
+ inParams.Add(new Bpl.Formal(p.tok, new Bpl.TypedIdent(p.tok, p.AssignUniqueName(f), varType, wh), true));
+ }
+ List<TypeVariable> typeParams = TrTypeParamDecls(f.TypeArgs);
+ // the procedure itself
+ var req = new List<Bpl.Requires>();
+ // free requires mh == ModuleContextHeight && fh == FunctionContextHeight;
+ req.Add(Requires(f.tok, true, etran.HeightContext(f), null, null));
+ // modifies $Heap, $Tick
+ var mod = new List<Bpl.IdentifierExpr> { (Bpl.IdentifierExpr/*TODO: this cast is rather dubious*/)etran.HeapExpr, etran.Tick() };
+ // check that postconditions hold
+ var ens = new List<Bpl.Ensures>();
+ foreach (Expression p in f.Ens)
+ {
+ var functionHeight = currentModule.CallGraph.GetSCCRepresentativeId(f);
+ var splits = new List<SplitExprInfo>();
+ bool splitHappened/*we actually don't care*/ = TrSplitExpr(p, splits, true, functionHeight,false, etran);
+ foreach (var s in splits)
+ {
+ if (s.IsChecked && !RefinementToken.IsInherited(s.E.tok, currentModule))
+ {
+ ens.Add(Ensures(s.E.tok, false, s.E, null, null));
+ }
+ }
+ }
+ Bpl.Procedure proc = new Bpl.Procedure(f.tok, "OverrideCheck$$" + f.FullSanitizedName, typeParams, inParams, new List<Variable>(),
+ req, mod, ens, etran.TrAttributes(f.Attributes, null));
+ sink.TopLevelDeclarations.Add(proc);
+ var implInParams = Bpl.Formal.StripWhereClauses(inParams);
+
+ #endregion
+
+ //List<Variable> outParams = Bpl.Formal.StripWhereClauses(proc.OutParams);
+
+ Bpl.StmtListBuilder builder = new Bpl.StmtListBuilder();
+ List<Variable> localVariables = new List<Variable>();
+ //GenerateImplPrelude(m, wellformednessProc, inParams, outParams, builder, localVariables);
+
+ var substMap = new Dictionary<IVariable, Expression>();
+ for (int i = 0; i < f.Formals.Count; i++)
+ {
+ //get corresponsing formal in the class
+ var ie = new IdentifierExpr(f.Formals[i].tok, f.Formals[i].AssignUniqueName(f));
+ ie.Var = f.Formals[i]; ie.Type = ie.Var.Type;
+ substMap.Add(f.OverriddenFunction.Formals[i], ie);
+ }
+
+ Bpl.StmtList stmts;
+ //adding assume Pre’; assert P; // this checks that Pre’ implies P
+ AddFunctionOverrideReqsChk(f, builder, etran, substMap);
+
+ //adding assert R <= Rank’;
+ AddFunctionOverrideTerminationChk(f, builder, etran, substMap);
+
+ //adding assert W <= Frame’
+ AddFunctionOverrideSubsetChk(f, builder, etran, localVariables, substMap);
+
+ //change the heap at locations W
+ HavocFunctionFrameLocations(f, builder, etran, localVariables);
+
+ //adding assume Q; assert Post’;
+ AddFunctionOverrideEnsChk(f, builder, etran, substMap, implInParams);
+
+ //creating an axiom that conncets J.F and C.F
+ //which is a class function and overridden trait function
+ AddFunctionOverrideAxiom(f);
+
+ stmts = builder.Collect(f.tok);
+
+ QKeyValue kv = etran.TrAttributes(f.Attributes, null);
+
+ Bpl.Implementation impl = new Bpl.Implementation(f.tok, proc.Name, typeParams, implInParams, new List<Variable>(), localVariables, stmts, kv);
+ sink.TopLevelDeclarations.Add(impl);
+
+ if (InsertChecksums)
+ {
+ InsertChecksum(f, proc, true);
+ }
+
+ currentModule = null;
+ codeContext = null;
+ loopHeapVarCount = 0;
+ otherTmpVarCount = 0;
+ _tmpIEs.Clear();
+ }
+
+ private void AddFunctionOverrideAxiom(Function f)
+ {
+ Contract.Requires(f != null);
+ Contract.Requires(sink != null && predef != null);
+ // function override axiom
+ // axiom (forall $heap: HeapType, this: ref, x#0: int ::
+ // { J.F($heap, this, x#0) }
+ // this != null && dtype(this) == class.C
+ // ==>
+ // J.F($heap, this, x#0) == C.F($heap, this, x#0));
+
+ var formals = new List<Variable>();
+ var argsC = new List<Bpl.Expr>();
+ var argsT = new List<Bpl.Expr>();
+
+ var bv = new Bpl.BoundVariable(f.tok, new Bpl.TypedIdent(f.tok, "$ly", predef.LayerType));
+ var s = new Bpl.IdentifierExpr(f.tok, bv);
+ if (f.IsRecursive)
+ {
+ formals.Add(bv);
+ argsC.Add(FunctionCall(f.tok, BuiltinFunction.LayerSucc, null, s));
+ argsT.Add(FunctionCall(f.tok, BuiltinFunction.LayerSucc, null, s));
+ }
+
+ bv = new Bpl.BoundVariable(f.tok, new Bpl.TypedIdent(f.tok, predef.HeapVarName, predef.HeapType));
+ formals.Add(bv);
+ s = new Bpl.IdentifierExpr(f.tok, bv);
+ argsC.Add(s);
+ argsT.Add(s);
+
+ if (!f.IsStatic)
+ {
+ bv = new Bpl.BoundVariable(f.tok, new Bpl.TypedIdent(f.tok, "this", predef.RefType));
+ formals.Add(bv);
+ s = new Bpl.IdentifierExpr(f.tok, bv);
+ argsC.Add(s);
+ argsT.Add(s);
+ }
+ foreach (var p in f.Formals)
+ {
+ bv = new Bpl.BoundVariable(p.tok, new Bpl.TypedIdent(p.tok, f.FullSanitizedName + "_" + p.AssignUniqueName(f), TrType(p.Type)));
+ formals.Add(bv);
+ s = new Bpl.IdentifierExpr(f.tok, bv);
+ argsC.Add(s);
+ }
+ foreach (var p in f.OverriddenFunction.Formals)
+ {
+ bv = new Bpl.BoundVariable(p.tok, new Bpl.TypedIdent(p.tok, f.OverriddenFunction.FullSanitizedName + "_" + p.AssignUniqueName(f.OverriddenFunction), TrType(p.Type)));
+ formals.Add(bv);
+ s = new Bpl.IdentifierExpr(f.OverriddenFunction.tok, bv);
+ argsT.Add(s);
+ }
+
+ var funcIdC = new Bpl.FunctionCall(new Bpl.IdentifierExpr(f.tok, f.FullSanitizedName, TrType(f.ResultType)));
+ var funcIdT = new Bpl.FunctionCall(new Bpl.IdentifierExpr(f.OverriddenFunction.tok, f.OverriddenFunction.FullSanitizedName, TrType(f.OverriddenFunction.ResultType)));
+ var funcApplC = new Bpl.NAryExpr(f.tok, funcIdC, argsC);
+ var funcApplT = new Bpl.NAryExpr(f.OverriddenFunction.tok, funcIdT, argsT);
+
+ var typeParams = TrTypeParamDecls(f.TypeArgs);
+
+ Bpl.Trigger tr = new Bpl.Trigger(f.OverriddenFunction.tok, true, new List<Bpl.Expr> { funcApplT, funcApplC });
+ Bpl.Expr ax = new Bpl.ForallExpr(f.tok, typeParams, formals, null, tr, Bpl.Expr.Eq(funcApplC, funcApplT));
+ sink.TopLevelDeclarations.Add(new Bpl.Axiom(f.tok, ax, "function override axiom"));
+ }
+
+ private void AddFunctionOverrideEnsChk(Function f, StmtListBuilder builder, ExpressionTranslator etran, Dictionary<IVariable, Expression> substMap, List<Variable> implInParams)
+ {
+ //generating class post-conditions
+ foreach (var en in f.Ens)
+ {
+ builder.Add(new Bpl.AssumeCmd(f.tok, etran.TrExpr(en)));
+ }
+
+ //generating assume J.F(ins) == C.F(ins)
+ Bpl.FunctionCall funcIdC = new Bpl.FunctionCall(new Bpl.IdentifierExpr(f.tok, f.FullSanitizedName, TrType(f.ResultType)));
+ Bpl.FunctionCall funcIdT = new Bpl.FunctionCall(new Bpl.IdentifierExpr(f.OverriddenFunction.tok, f.OverriddenFunction.FullSanitizedName, TrType(f.OverriddenFunction.ResultType)));
+ List<Bpl.Expr> argsC = new List<Bpl.Expr>();
+ List<Bpl.Expr> argsT = new List<Bpl.Expr>();
+ if (f.IsRecursive)
+ {
+ argsC.Add(etran.LayerN(1));
+ }
+ if (f.OverriddenFunction.IsRecursive)
+ {
+ argsT.Add(etran.LayerN(1));
+ }
+ argsC.Add(etran.HeapExpr);
+ argsT.Add(etran.HeapExpr);
+ foreach (Variable p in implInParams)
+ {
+ argsC.Add(new Bpl.IdentifierExpr(f.tok, p));
+ argsT.Add(new Bpl.IdentifierExpr(f.OverriddenFunction.tok, p));
+ }
+ Bpl.Expr funcExpC = new Bpl.NAryExpr(f.tok, funcIdC, argsC);
+ Bpl.Expr funcExpT = new Bpl.NAryExpr(f.OverriddenFunction.tok, funcIdT, argsT);
+ builder.Add(new Bpl.AssumeCmd(f.tok, Bpl.Expr.Eq(funcExpC, funcExpT)));
+
+ //generating trait post-conditions with class variables
+ foreach (var en in f.OverriddenFunction.Ens)
+ {
+ Expression postcond = Substitute(en, null, substMap);
+ bool splitHappened;
+ var reqSplitedE = TrSplitExpr(postcond, etran,false, out splitHappened);
+ foreach (var s in reqSplitedE)
+ {
+ var assert = new Bpl.AssertCmd(f.tok, s.E);
+ assert.ErrorData = "Error: the function must provide an equal or more detailed postcondition than in its parent trait";
+ builder.Add(assert);
+ }
+ }
+ }
+
+ private void HavocFunctionFrameLocations(Function f, StmtListBuilder builder, ExpressionTranslator etran, List<Variable> localVariables)
+ {
+ // play havoc with the heap according to the modifies clause
+ builder.Add(new Bpl.HavocCmd(f.tok, new List<Bpl.IdentifierExpr> { (Bpl.IdentifierExpr/*TODO: this cast is rather dubious*/)etran.HeapExpr }));
+ // assume the usual two-state boilerplate information
+ foreach (BoilerplateTriple tri in GetTwoStateBoilerplate(f.tok, f.Reads, f.IsGhost, etran.Old, etran, etran.Old))
+ {
+ if (tri.IsFree)
+ {
+ builder.Add(new Bpl.AssumeCmd(f.tok, tri.Expr));
+ }
+ }
+ }
+
+ private void AddFunctionOverrideSubsetChk(Function func, StmtListBuilder builder, ExpressionTranslator etran, List<Variable> localVariables, Dictionary<IVariable, Expression> substMap)
+ {
+ //getting framePrime
+ List<FrameExpression> traitFrameExps = new List<FrameExpression>();
+ foreach (var e in func.OverriddenFunction.Reads)
+ {
+ var newE = Substitute(e.E, null, substMap);
+ FrameExpression fe = new FrameExpression(e.tok, newE, e.FieldName);
+ traitFrameExps.Add(fe);
+ }
+
+ QKeyValue kv = etran.TrAttributes(func.Attributes, null);
+
+ IToken tok = func.tok;
+ // Declare a local variable $_Frame: <alpha>[ref, Field alpha]bool
+ Bpl.IdentifierExpr traitFrame = etran.TheFrame(func.OverriddenFunction.tok); // this is a throw-away expression, used only to extract the type and name of the $_Frame variable
+ traitFrame.Name = func.EnclosingClass.Name + "_" + traitFrame.Name;
+ Contract.Assert(traitFrame.Type != null); // follows from the postcondition of TheFrame
+ Bpl.LocalVariable frame = new Bpl.LocalVariable(tok, new Bpl.TypedIdent(tok, null ?? traitFrame.Name, traitFrame.Type));
+ localVariables.Add(frame);
+ // $_Frame := (lambda<alpha> $o: ref, $f: Field alpha :: $o != null && $Heap[$o,alloc] ==> ($o,$f) in Modifies/Reads-Clause);
+ Bpl.TypeVariable alpha = new Bpl.TypeVariable(tok, "alpha");
+ Bpl.BoundVariable oVar = new Bpl.BoundVariable(tok, new Bpl.TypedIdent(tok, "$o", predef.RefType));
+ Bpl.IdentifierExpr o = new Bpl.IdentifierExpr(tok, oVar);
+ Bpl.BoundVariable fVar = new Bpl.BoundVariable(tok, new Bpl.TypedIdent(tok, "$f", predef.FieldName(tok, alpha)));
+ Bpl.IdentifierExpr f = new Bpl.IdentifierExpr(tok, fVar);
+ Bpl.Expr ante = Bpl.Expr.And(Bpl.Expr.Neq(o, predef.Null), etran.IsAlloced(tok, o));
+ Bpl.Expr consequent = InRWClause(tok, o, f, traitFrameExps, etran, null, null);
+ Bpl.Expr lambda = new Bpl.LambdaExpr(tok, new List<TypeVariable> { alpha }, new List<Variable> { oVar, fVar }, null,
+ Bpl.Expr.Imp(ante, consequent));
+
+ //to initialize $_Frame variable to Frame'
+ builder.Add(Bpl.Cmd.SimpleAssign(tok, new Bpl.IdentifierExpr(tok, frame), lambda));
+
+ // emit: assert (forall<alpha> o: ref, f: Field alpha :: o != null && $Heap[o,alloc] && (o,f) in subFrame ==> $_Frame[o,f]);
+ Bpl.Expr oInCallee = InRWClause(tok, o, f, func.Reads, etran, null, null);
+ Bpl.Expr consequent2 = InRWClause(tok, o, f, traitFrameExps, etran, null, null);
+ Bpl.Expr q = new Bpl.ForallExpr(tok, new List<TypeVariable> { alpha }, new List<Variable> { oVar, fVar },
+ Bpl.Expr.Imp(Bpl.Expr.And(ante, oInCallee), consequent2));
+ builder.Add(Assert(tok, q, "expression may read an object not in the parent trait context's reads clause", kv));
+ }
+
+ private void AddFunctionOverrideTerminationChk(Function f, StmtListBuilder builder, ExpressionTranslator etran, Dictionary<IVariable, Expression> substMap)
+ {
+ var decrToks = new List<IToken>();
+ var decrTypes1 = new List<Type>();
+ var decrTypes2 = new List<Type>();
+ var decrClass = new List<Expr>();
+ var decrTrait = new List<Expr>();
+ if (f.Decreases != null)
+ {
+ foreach (var decC in f.Decreases.Expressions)
+ {
+ decrToks.Add(decC.tok);
+ decrTypes1.Add(decC.Type);
+ decrClass.Add(etran.TrExpr(decC));
+ }
+ }
+ if (f.OverriddenFunction.Decreases != null)
+ {
+ foreach (var decT in f.OverriddenFunction.Decreases.Expressions)
+ {
+ var decCNew = Substitute(decT, null, substMap);
+ decrTypes2.Add(decCNew.Type);
+ decrTrait.Add(etran.TrExpr(decCNew));
+ }
+ }
+ var decrChk = DecreasesCheck(decrToks, decrTypes1, decrTypes2, decrClass, decrTrait, null, null, true, false);
+ builder.Add(new Bpl.AssertCmd(f.tok, decrChk));
+ }
+
+ private void AddFunctionOverrideReqsChk(Function f, StmtListBuilder builder, ExpressionTranslator etran, Dictionary<IVariable, Expression> substMap)
+ {
+ //generating trait pre-conditions with class variables
+ foreach (var req in f.OverriddenFunction.Req)
+ {
+ Expression precond = Substitute(req, null, substMap);
+ builder.Add(new Bpl.AssumeCmd(f.tok, etran.TrExpr(precond)));
+ }
+ //generating class pre-conditions
+ foreach (var req in f.Req)
+ {
+ bool splitHappened;
+ var reqSplitedE = TrSplitExpr(req, etran,false, out splitHappened);
+ foreach (var s in reqSplitedE)
+ {
+ var assert = new Bpl.AssertCmd(f.tok, s.E);
+ assert.ErrorData = "Error: the function must provide an equal or more permissive precondition than in its parent trait";
+ builder.Add(assert);
+ }
+ }
+ }
+
+ private void AddMethodOverrideCheckImpl(Method m, Bpl.Procedure proc)
+ {
+ Contract.Requires(m != null);
+ Contract.Requires(proc != null);
+ Contract.Requires(sink != null && predef != null);
+ Contract.Requires(m.OverriddenMethod != null);
+ Contract.Requires(m.Ins.Count == m.OverriddenMethod.Ins.Count);
+ Contract.Requires(m.Outs.Count == m.OverriddenMethod.Outs.Count);
+ //Contract.Requires(wellformednessProc || m.Body != null);
+ Contract.Requires(currentModule == null && codeContext == null && loopHeapVarCount == 0 && _tmpIEs.Count == 0);
+ Contract.Ensures(currentModule == null && codeContext == null && loopHeapVarCount == 0 && _tmpIEs.Count == 0);
+
+ currentModule = m.EnclosingClass.Module;
+ codeContext = m;
+
+ List<TypeVariable> typeParams = TrTypeParamDecls(m.TypeArgs);
+ List<Variable> inParams = Bpl.Formal.StripWhereClauses(proc.InParams);
+ List<Variable> outParams = Bpl.Formal.StripWhereClauses(proc.OutParams);
+
+ Bpl.StmtListBuilder builder = new Bpl.StmtListBuilder();
+ ExpressionTranslator etran = new ExpressionTranslator(this, predef, m.tok);
+ List<Variable> localVariables = new List<Variable>();
+ //GenerateImplPrelude(m, wellformednessProc, inParams, outParams, builder, localVariables);
+
+ var substMap = new Dictionary<IVariable, Expression>();
+ for (int i = 0; i < m.Ins.Count; i++)
+ {
+ //get corresponsing formal in the class
+ var ie = new IdentifierExpr(m.Ins[i].tok, m.Ins[i].AssignUniqueName(m));
+ ie.Var = m.Ins[i]; ie.Type = ie.Var.Type;
+ substMap.Add(m.OverriddenMethod.Ins[i], ie);
+ }
+ for (int i = 0; i < m.Outs.Count; i++)
+ {
+ //get corresponsing formal in the class
+ var ie = new IdentifierExpr(m.Outs[i].tok, m.Outs[i].AssignUniqueName(m));
+ ie.Var = m.Outs[i]; ie.Type = ie.Var.Type;
+ substMap.Add(m.OverriddenMethod.Outs[i], ie);
+ }
+
+ Bpl.StmtList stmts;
+ //adding assume Pre’; assert P; // this checks that Pre’ implies P
+ AddMethodOverrideReqsChk(m, builder, etran, substMap);
+
+ //adding assert R <= Rank’;
+ AddMethodOverrideTerminationChk(m, builder, etran, substMap);
+
+ //adding assert W <= Frame’
+ AddMethodOverrideSubsetChk(m, builder, etran, localVariables, substMap);
+
+ //change the heap at locations W
+ HavocMethodFrameLocations(m, builder, etran, localVariables);
+
+ //adding assume Q; assert Post’;
+ AddMethodOverrideEnsChk(m, builder, etran, substMap);
+
+ stmts = builder.Collect(m.tok);
+
+ QKeyValue kv = etran.TrAttributes(m.Attributes, null);
+
+ Bpl.Implementation impl = new Bpl.Implementation(m.tok, proc.Name, typeParams, inParams, outParams, localVariables, stmts, kv);
+ sink.TopLevelDeclarations.Add(impl);
+
+ if (InsertChecksums)
+ {
+ InsertChecksum(m, impl);
+ }
+
+ currentModule = null;
+ codeContext = null;
+ loopHeapVarCount = 0;
+ otherTmpVarCount = 0;
+ _tmpIEs.Clear();
+ }
+
+ private void HavocMethodFrameLocations(Method m, Bpl.StmtListBuilder builder, ExpressionTranslator etran, List<Variable> localVariables)
+ {
+ Contract.Requires(m != null);
+ Contract.Requires(m.EnclosingClass != null && m.EnclosingClass is ClassDecl);
+
+ // play havoc with the heap according to the modifies clause
+ builder.Add(new Bpl.HavocCmd(m.tok, new List<Bpl.IdentifierExpr> { (Bpl.IdentifierExpr/*TODO: this cast is rather dubious*/)etran.HeapExpr }));
+ // assume the usual two-state boilerplate information
+ foreach (BoilerplateTriple tri in GetTwoStateBoilerplate(m.tok, m.Mod.Expressions, m.IsGhost, etran.Old, etran, etran.Old))
+ {
+ if (tri.IsFree)
+ {
+ builder.Add(new Bpl.AssumeCmd(m.tok, tri.Expr));
+ }
+ }
+ }
+
+ private void AddMethodOverrideEnsChk(Method m, Bpl.StmtListBuilder builder, ExpressionTranslator etran, Dictionary<IVariable, Expression> substMap)
+ {
+ //generating class post-conditions
+ foreach (var en in m.Ens)
+ {
+ builder.Add(new Bpl.AssumeCmd(m.tok, etran.TrExpr(en.E)));
+ }
+ //generating trait post-conditions with class variables
+ foreach (var en in m.OverriddenMethod.Ens)
+ {
+ Expression postcond = Substitute(en.E, null, substMap);
+ bool splitHappened;
+ var reqSplitedE = TrSplitExpr(postcond, etran,false, out splitHappened);
+ foreach (var s in reqSplitedE)
+ {
+ var assert = new Bpl.AssertCmd(m.tok, s.E);
+ assert.ErrorData = "Error: the method must provide an equal or more detailed postcondition than in its parent trait";
+ builder.Add(assert);
+ }
+ }
+ }
+
+ private void AddMethodOverrideReqsChk(Method m, Bpl.StmtListBuilder builder, ExpressionTranslator etran, Dictionary<IVariable, Expression> substMap)
+ {
+ //generating trait pre-conditions with class variables
+ foreach (var req in m.OverriddenMethod.Req)
+ {
+ Expression precond = Substitute(req.E, null, substMap);
+ builder.Add(new Bpl.AssumeCmd(m.tok, etran.TrExpr(precond)));
+ }
+ //generating class pre-conditions
+ foreach (var req in m.Req)
+ {
+ bool splitHappened;
+ var reqSplitedE = TrSplitExpr(req.E, etran,false, out splitHappened);
+ foreach (var s in reqSplitedE)
+ {
+ var assert = new Bpl.AssertCmd(m.tok, s.E);
+ assert.ErrorData = "Error: the method must provide an equal or more permissive precondition than in its parent trait";
+ builder.Add(assert);
+ }
+ }
+ }
+
+ private void AddMethodOverrideTerminationChk(Method m, Bpl.StmtListBuilder builder, ExpressionTranslator etran, Dictionary<IVariable, Expression> substMap)
+ {
+ var decrToks = new List<IToken>();
+ var decrTypes1 = new List<Type>();
+ var decrTypes2 = new List<Type>();
+ var decrClass = new List<Expr>();
+ var decrTrait = new List<Expr>();
+ if (m.Decreases != null)
+ {
+ foreach (var decC in m.Decreases.Expressions)
+ {
+ decrToks.Add(decC.tok);
+ decrTypes1.Add(decC.Type);
+ decrClass.Add(etran.TrExpr(decC));
+ }
+ }
+ if (m.OverriddenMethod.Decreases != null)
+ {
+ foreach (var decT in m.OverriddenMethod.Decreases.Expressions)
+ {
+ var decCNew = Substitute(decT, null, substMap);
+ decrTypes2.Add(decCNew.Type);
+ decrTrait.Add(etran.TrExpr(decCNew));
+ }
+ }
+ var decrChk = DecreasesCheck(decrToks, decrTypes1, decrTypes2, decrClass, decrTrait, null, null, true, false);
+ builder.Add(new Bpl.AssertCmd(m.tok, decrChk));
+ }
+
+ private void AddMethodOverrideSubsetChk(Method m, Bpl.StmtListBuilder builder, ExpressionTranslator etran, List<Variable> localVariables, Dictionary<IVariable, Expression> substMap)
+ {
+ //getting framePrime
+ List<FrameExpression> traitFrameExps = new List<FrameExpression>();
+ List<FrameExpression> classFrameExps = m.Mod != null ? m.Mod.Expressions : new List<FrameExpression>();
+ if (m.OverriddenMethod.Mod != null)
+ {
+ foreach (var e in m.OverriddenMethod.Mod.Expressions)
+ {
+ var newE = Substitute(e.E, null, substMap);
+ FrameExpression fe = new FrameExpression(e.tok, newE, e.FieldName);
+ traitFrameExps.Add(fe);
+ }
+ }
+
+ QKeyValue kv = etran.TrAttributes(m.Attributes, null);
+
+ IToken tok = m.tok;
+ // Declare a local variable $_Frame: <alpha>[ref, Field alpha]bool
+ Bpl.IdentifierExpr traitFrame = etran.TheFrame(m.OverriddenMethod.tok); // this is a throw-away expression, used only to extract the type and name of the $_Frame variable
+ traitFrame.Name = m.EnclosingClass.Name + "_" + traitFrame.Name;
+ Contract.Assert(traitFrame.Type != null); // follows from the postcondition of TheFrame
+ Bpl.LocalVariable frame = new Bpl.LocalVariable(tok, new Bpl.TypedIdent(tok, null ?? traitFrame.Name, traitFrame.Type));
+ localVariables.Add(frame);
+ // $_Frame := (lambda<alpha> $o: ref, $f: Field alpha :: $o != null && $Heap[$o,alloc] ==> ($o,$f) in Modifies/Reads-Clause);
+ Bpl.TypeVariable alpha = new Bpl.TypeVariable(tok, "alpha");
+ Bpl.BoundVariable oVar = new Bpl.BoundVariable(tok, new Bpl.TypedIdent(tok, "$o", predef.RefType));
+ Bpl.IdentifierExpr o = new Bpl.IdentifierExpr(tok, oVar);
+ Bpl.BoundVariable fVar = new Bpl.BoundVariable(tok, new Bpl.TypedIdent(tok, "$f", predef.FieldName(tok, alpha)));
+ Bpl.IdentifierExpr f = new Bpl.IdentifierExpr(tok, fVar);
+ Bpl.Expr ante = Bpl.Expr.And(Bpl.Expr.Neq(o, predef.Null), etran.IsAlloced(tok, o));
+ Bpl.Expr consequent = InRWClause(tok, o, f, traitFrameExps, etran, null, null);
+ Bpl.Expr lambda = new Bpl.LambdaExpr(tok, new List<TypeVariable> { alpha }, new List<Variable> { oVar, fVar }, null,
+ Bpl.Expr.Imp(ante, consequent));
+
+ //to initialize $_Frame variable to Frame'
+ builder.Add(Bpl.Cmd.SimpleAssign(tok, new Bpl.IdentifierExpr(tok, frame), lambda));
+
+ // emit: assert (forall<alpha> o: ref, f: Field alpha :: o != null && $Heap[o,alloc] && (o,f) in subFrame ==> $_Frame[o,f]);
+ Bpl.Expr oInCallee = InRWClause(tok, o, f, classFrameExps, etran, null, null);
+ Bpl.Expr consequent2 = InRWClause(tok, o, f, traitFrameExps, etran, null, null);
+ Bpl.Expr q = new Bpl.ForallExpr(tok, new List<TypeVariable> { alpha }, new List<Variable> { oVar, fVar },
+ Bpl.Expr.Imp(Bpl.Expr.And(ante, oInCallee), consequent2));
+ builder.Add(Assert(tok, q, "expression may modify an object not in the parent trait context's modifies clause", kv));
+ }
+
private void InsertChecksum(Method m, Bpl.Declaration decl, bool specificationOnly = false)
{
byte[] data;
@@ -2998,8 +3607,8 @@ namespace Microsoft.Dafny {
#endif
}
- Bpl.Expr/*!*/ InRWClause(IToken/*!*/ tok, Bpl.Expr/*!*/ o, Bpl.Expr/*!*/ f, List<FrameExpression/*!*/>/*!*/ rw, ExpressionTranslator/*!*/ etran,
- Expression receiverReplacement, Dictionary<IVariable,Expression/*!*/> substMap) {
+ Bpl.Expr/*!*/ InRWClause(IToken tok, Bpl.Expr o, Bpl.Expr f, List<FrameExpression> rw, ExpressionTranslator etran,
+ Expression receiverReplacement, Dictionary<IVariable,Expression> substMap) {
Contract.Requires(tok != null);
Contract.Requires(o != null);
// Contract.Requires(f != null); // f == null means approximate
@@ -3021,12 +3630,13 @@ namespace Microsoft.Dafny {
e = Substitute(e, receiverReplacement, substMap);
}
Bpl.Expr disjunct;
+ var eType = e.Type.NormalizeExpand();
if (e is WildcardExpr) {
disjunct = Bpl.Expr.True;
- } else if (e.Type is SetType) {
+ } else if (eType is SetType) {
// old(e)[Box(o)]
- disjunct = etran.TrInSet(tok, o, e, ((SetType)e.Type).Arg);
- } else if (e.Type is SeqType) {
+ disjunct = etran.TrInSet(tok, o, e, ((SetType)eType).Arg);
+ } else if (eType is SeqType) {
// (exists i: int :: 0 <= i && i < Seq#Length(old(e)) && Seq#Index(old(e),i) == Box(o))
Bpl.Expr boxO = FunctionCall(tok, BuiltinFunction.Box, null, o);
Bpl.Variable iVar = new Bpl.BoundVariable(tok, new Bpl.TypedIdent(tok, "$i", Bpl.Type.Int));
@@ -3309,7 +3919,6 @@ namespace Microsoft.Dafny {
}
} else if (expr is SeqSelectExpr) {
SeqSelectExpr e = (SeqSelectExpr)expr;
- //bool isSequence = e.Seq.Type is SeqType;
Bpl.Expr total = CanCallAssumption(e.Seq, etran);
Bpl.Expr seq = etran.TrExpr(e.Seq);
Bpl.Expr e0 = null;
@@ -3709,20 +4318,21 @@ namespace Microsoft.Dafny {
}
} else if (expr is SeqSelectExpr) {
SeqSelectExpr e = (SeqSelectExpr)expr;
- bool isSequence = e.Seq.Type is SeqType;
+ var eSeqType = e.Seq.Type.NormalizeExpand();
+ bool isSequence = eSeqType is SeqType;
CheckWellformed(e.Seq, options, locals, builder, etran);
Bpl.Expr seq = etran.TrExpr(e.Seq);
- if (e.Seq.Type.IsArrayType) {
+ if (eSeqType.IsArrayType) {
builder.Add(Assert(e.Seq.tok, Bpl.Expr.Neq(seq, predef.Null), "array may be null"));
}
Bpl.Expr e0 = null;
- if (e.Seq.Type is MapType) {
+ if (eSeqType is MapType) {
e0 = etran.TrExpr(e.E0);
CheckWellformed(e.E0, options, locals, builder, etran);
Bpl.Expr inDomain = FunctionCall(expr.tok, BuiltinFunction.MapDomain, predef.MapType(e.tok, predef.BoxType, predef.BoxType), seq);
inDomain = Bpl.Expr.Select(inDomain, BoxIfNecessary(e.tok, e0, e.E0.Type));
builder.Add(Assert(expr.tok, inDomain, "element may not be in domain", options.AssertKv));
- } else if (e.Seq.Type is MultiSetType) {
+ } else if (eSeqType is MultiSetType) {
// cool
} else {
@@ -3736,14 +4346,14 @@ namespace Microsoft.Dafny {
builder.Add(Assert(expr.tok, InSeqRange(expr.tok, etran.TrExpr(e.E1), seq, isSequence, e0, true), "upper bound " + (e.E0 == null ? "" : "below lower bound or ") + "above length of " + (isSequence ? "sequence" : "array"), options.AssertKv));
}
}
- if (options.DoReadsChecks && e.Seq.Type.IsArrayType) {
+ if (options.DoReadsChecks && eSeqType.IsArrayType) {
if (e.SelectOne) {
Contract.Assert(e.E0 != null);
Bpl.Expr fieldName = FunctionCall(expr.tok, BuiltinFunction.IndexField, null, etran.TrExpr(e.E0));
options.AssertSink(this, builder)(expr.tok, Bpl.Expr.SelectTok(expr.tok, etran.TheFrame(expr.tok), seq, fieldName), "insufficient reads clause to read array element", options.AssertKv);
} else {
Bpl.Expr lowerBound = e.E0 == null ? Bpl.Expr.Literal(0) : etran.TrExpr(e.E0);
- Contract.Assert((e.Seq.Type).AsArrayType.Dims == 1);
+ Contract.Assert(eSeqType.AsArrayType.Dims == 1);
Bpl.Expr upperBound = e.E1 == null ? ArrayLength(e.tok, seq, 1, 0) : etran.TrExpr(e.E1);
// check that, for all i in lowerBound..upperBound, a[i] is in the frame
Bpl.BoundVariable iVar = new Bpl.BoundVariable(e.tok, new Bpl.TypedIdent(e.tok, "$i", Bpl.Type.Int));
@@ -3783,20 +4393,14 @@ namespace Microsoft.Dafny {
Bpl.Expr index = etran.TrExpr(e.Index);
Bpl.Expr value = etran.TrExpr(e.Value);
CheckWellformed(e.Index, options, locals, builder, etran);
- if (e.Seq.Type is SeqType)
- {
+ var eSeqType = e.Seq.Type.NormalizeExpand();
+ if (eSeqType is SeqType) {
builder.Add(Assert(expr.tok, InSeqRange(expr.tok, index, seq, true, null, false), "index out of range", options.AssertKv));
- }
- else if (e.Seq.Type is MapType)
- {
+ } else if (eSeqType is MapType) {
// updates to maps are always valid if the values are well formed
- }
- else if (e.Seq.Type is MultiSetType)
- {
+ } else if (eSeqType is MultiSetType) {
builder.Add(Assert(expr.tok, Bpl.Expr.Le(Bpl.Expr.Literal(0), value), "new number of occurrences might be negative", options.AssertKv));
- }
- else
- {
+ } else {
Contract.Assert(false);
}
CheckWellformed(e.Value, options, locals, builder, etran);
@@ -4037,7 +4641,7 @@ namespace Microsoft.Dafny {
break;
case BinaryExpr.ResolvedOpcode.Div:
case BinaryExpr.ResolvedOpcode.Mod: {
- Bpl.Expr zero = (e.E1.Type is RealType) ? Bpl.Expr.Literal(Basetypes.BigDec.ZERO) : Bpl.Expr.Literal(0);
+ Bpl.Expr zero = (e.E1.Type.IsRealType) ? Bpl.Expr.Literal(Basetypes.BigDec.ZERO) : Bpl.Expr.Literal(0);
CheckWellformed(e.E1, options, locals, builder, etran);
builder.Add(Assert(expr.tok, Bpl.Expr.Neq(etran.TrExpr(e.E1), zero), "possible division by zero", options.AssertKv));
}
@@ -5012,7 +5616,7 @@ namespace Microsoft.Dafny {
/// Note that SpecWellformedness and Implementation have procedure implementations
/// but no callers, and vice versa for InterModuleCall, IntraModuleCall, and CoCall.
/// </summary>
- enum MethodTranslationKind { SpecWellformedness, InterModuleCall, IntraModuleCall, CoCall, Implementation }
+ enum MethodTranslationKind { SpecWellformedness, InterModuleCall, IntraModuleCall, CoCall, Implementation, OverrideCheck }
/// <summary>
/// This method is expected to be called at most once for each parameter combination, and in particular
@@ -5039,7 +5643,7 @@ namespace Microsoft.Dafny {
var mod = new List<Bpl.IdentifierExpr>();
var ens = new List<Bpl.Ensures>();
// FREE PRECONDITIONS
- if (kind == MethodTranslationKind.SpecWellformedness || kind == MethodTranslationKind.Implementation) { // the other cases have no need for a free precondition
+ if (kind == MethodTranslationKind.SpecWellformedness || kind == MethodTranslationKind.Implementation || kind== MethodTranslationKind.OverrideCheck) { // the other cases have no need for a free precondition
// free requires mh == ModuleContextHeight && fh == FunctionContextHeight;
req.Add(Requires(m.tok, true, etran.HeightContext(m), null, null));
}
@@ -5048,7 +5652,8 @@ namespace Microsoft.Dafny {
var bodyKind = kind == MethodTranslationKind.SpecWellformedness || kind == MethodTranslationKind.Implementation;
- if (kind != MethodTranslationKind.SpecWellformedness) {
+ if (kind != MethodTranslationKind.SpecWellformedness && kind != MethodTranslationKind.OverrideCheck)
+ {
// USER-DEFINED SPECIFICATIONS
var comment = "user-defined preconditions";
foreach (var p in m.Req) {
@@ -5129,6 +5734,8 @@ namespace Microsoft.Dafny {
return "CoCall$$" + m.FullSanitizedName;
case MethodTranslationKind.Implementation:
return "Impl$$" + m.FullSanitizedName;
+ case MethodTranslationKind.OverrideCheck:
+ return "OverrideCheck$$" + m.FullSanitizedName;
default:
Contract.Assert(false); // unexpected kind
throw new cce.UnreachableException();
@@ -6421,7 +7028,8 @@ namespace Microsoft.Dafny {
IEnumerable<Expression> GuessWitnesses(BoundVar x, Expression expr) {
Contract.Requires(x != null);
Contract.Requires(expr != null);
- if (x.Type is BoolType) {
+ var xType = x.Type.NormalizeExpand();
+ if (xType is BoolType) {
var lit = new LiteralExpr(x.tok, false);
lit.Type = Type.Bool; // resolve here
yield return lit;
@@ -6429,13 +7037,13 @@ namespace Microsoft.Dafny {
lit.Type = Type.Bool; // resolve here
yield return lit;
yield break; // there are no more possible witnesses for booleans
- } else if (x.Type.IsRefType) {
+ } else if (xType.IsRefType) {
var lit = new LiteralExpr(x.tok); // null
- lit.Type = x.Type;
+ lit.Type = xType;
yield return lit;
- } else if (x.Type.IsDatatype) {
- var dt = x.Type.AsDatatype;
- Expression zero = Zero(x.tok, x.Type);
+ } else if (xType.IsDatatype) {
+ var dt = xType.AsDatatype;
+ Expression zero = Zero(x.tok, xType);
if (zero != null) {
yield return zero;
}
@@ -6443,28 +7051,28 @@ namespace Microsoft.Dafny {
if (ctor.Formals.Count == 0) {
var v = new DatatypeValue(x.tok, dt.Name, ctor.Name, new List<Expression>());
v.Ctor = ctor; // resolve here
- v.InferredTypeArgs = x.Type.TypeArgs; // resolved here.
+ v.InferredTypeArgs = xType.TypeArgs; // resolved here.
v.Type = new UserDefinedType(x.tok, dt.Name, dt, new List<Type>()); // resolve here
yield return v;
}
}
- } else if (x.Type is SetType) {
+ } else if (xType is SetType) {
var empty = new SetDisplayExpr(x.tok, new List<Expression>());
- empty.Type = x.Type;
+ empty.Type = xType;
yield return empty;
- } else if (x.Type is MultiSetType) {
+ } else if (xType is MultiSetType) {
var empty = new MultiSetDisplayExpr(x.tok, new List<Expression>());
- empty.Type = x.Type;
+ empty.Type = xType;
yield return empty;
- } else if (x.Type is SeqType) {
+ } else if (xType is SeqType) {
var empty = new SeqDisplayExpr(x.tok, new List<Expression>());
- empty.Type = x.Type;
+ empty.Type = xType;
yield return empty;
- } else if (x.Type is IntType) {
+ } else if (xType is IntType) {
var lit = new LiteralExpr(x.tok, 0);
lit.Type = Type.Int; // resolve here
yield return lit;
- } else if (x.Type is RealType) {
+ } else if (xType is RealType) {
var lit = new LiteralExpr(x.tok, Basetypes.BigDec.ZERO);
lit.Type = Type.Real; // resolve here
yield return lit;
@@ -7279,12 +7887,12 @@ namespace Microsoft.Dafny {
// include a free invariant that says that all completed iterations so far have only decreased the termination metric
if (initDecr != null) {
- List<IToken> toks = new List<IToken>();
- List<Type> types = new List<Type>();
- List<Expr> decrs = new List<Expr>();
+ var toks = new List<IToken>();
+ var types = new List<Type>();
+ var decrs = new List<Expr>();
foreach (Expression e in theDecreases) {
toks.Add(e.tok);
- types.Add(cce.NonNull(e.Type));
+ types.Add(e.Type.NormalizeExpand());
decrs.Add(etran.TrExpr(e));
}
Bpl.Expr decrCheck = DecreasesCheck(toks, types, types, decrs, initDecr, null, null, true, false);
@@ -7315,12 +7923,12 @@ namespace Microsoft.Dafny {
// time for the actual loop body
bodyTr(loopBodyBuilder, updatedFrameEtran);
// check definedness of decreases expressions
- List<IToken> toks = new List<IToken>();
- List<Type> types = new List<Type>();
- List<Expr> decrs = new List<Expr>();
+ var toks = new List<IToken>();
+ var types = new List<Type>();
+ var decrs = new List<Expr>();
foreach (Expression e in theDecreases) {
toks.Add(e.tok);
- types.Add(cce.NonNull(e.Type));
+ types.Add(e.Type.NormalizeExpand());
decrs.Add(etran.TrExpr(e));
}
Bpl.Expr decrCheck = DecreasesCheck(toks, types, types, decrs, oldBfs, loopBodyBuilder, " at end of loop iteration", false, false);
@@ -7735,8 +8343,8 @@ namespace Microsoft.Dafny {
break;
}
toks.Add(tok);
- types0.Add(e0.Type);
- types1.Add(e1.Type);
+ types0.Add(e0.Type.NormalizeExpand());
+ types1.Add(e1.Type.NormalizeExpand());
callee.Add(etranCurrent.TrExpr(e0));
caller.Add(etranInitial.TrExpr(e1));
}
@@ -7757,6 +8365,7 @@ namespace Microsoft.Dafny {
/// or has gone down or stayed the same (if allowNoChange).
/// ee0 represents the new values and ee1 represents old values.
/// If builder is non-null, then the check '0 ATMOST decr' is generated to builder.
+ /// Requires all types in types0 and types1 to be non-proxy non-synonym types (that is, callers should invoke NormalizeExpand)
/// </summary>
Bpl.Expr DecreasesCheck(List<IToken> toks, List<Type> types0, List<Type> types1, List<Bpl.Expr> ee0, List<Bpl.Expr> ee1,
Bpl.StmtListBuilder builder, string suffixMsg, bool allowNoChange, bool includeLowerBound)
@@ -7860,6 +8469,9 @@ namespace Microsoft.Dafny {
else return null;
}
+ /// <summary>
+ /// Requires ty0 and ty1 to be non-proxy non-synonym types (that is, caller is expected have have invoked NormalizeExpand)
+ /// </summary>
void ComputeLessEq(IToken tok, Type ty0, Type ty1, Bpl.Expr e0, Bpl.Expr e1, out Bpl.Expr less, out Bpl.Expr atmost, out Bpl.Expr eq, bool includeLowerBound)
{
Contract.Requires(tok != null);
@@ -7872,8 +8484,6 @@ namespace Microsoft.Dafny {
Contract.Ensures(Contract.ValueAtReturn(out atmost)!=null);
Contract.Ensures(Contract.ValueAtReturn(out eq)!=null);
- ty0 = ty0.NormalizeExpand();
- ty1 = ty1.NormalizeExpand();
var rk0 = RankFunction(ty0);
var rk1 = RankFunction(ty1);
if (rk0 != null && rk1 != null && rk0 != rk1) {
@@ -8154,7 +8764,7 @@ namespace Microsoft.Dafny {
Contract.Requires(type != null);
Contract.Ensures(Contract.Result<Bpl.Expr>() != null);
- if (type.NormalizeExpand() is BoolType) {
+ if (type.IsBoolType) {
return FunctionCall(box.tok, BuiltinFunction.IsCanonicalBoolBox, null, box);
} else {
return Bpl.Expr.True;
@@ -8594,7 +9204,8 @@ namespace Microsoft.Dafny {
Contract.Requires(builder != null);
var cre = CheckSubrange_Expr(tok, bRhs, tp);
- var msg = (tp is NatType) ? "value assigned to a nat must be non-negative" :
+ var msg = (tp.NormalizeExpand() is NatType) ?
+ "value assigned to a nat must be non-negative" :
"value does not satisfy the subrange criteria";
builder.Add(Assert(tok, cre, msg));
}
@@ -8606,7 +9217,7 @@ namespace Microsoft.Dafny {
// Only need to check this for natural numbers for now.
// We should always be able to use Is, but this is an optimisation.
- if (tp is NatType) {
+ if (tp.NormalizeExpand() is NatType) {
return MkIs(bRhs, tp);
} else {
return Bpl.Expr.True;
@@ -9353,20 +9964,21 @@ namespace Microsoft.Dafny {
} else if (expr is SeqSelectExpr) {
SeqSelectExpr e = (SeqSelectExpr)expr;
Bpl.Expr seq = TrExpr(e.Seq);
+ var seqType = e.Seq.Type.NormalizeExpand();
Type elmtType = null;
Type domainType = null;
- Contract.Assert(e.Seq.Type != null); // the expression has been successfully resolved
- if (e.Seq.Type.IsArrayType) {
+ Contract.Assert(seqType != null); // the expression has been successfully resolved
+ if (seqType.IsArrayType) {
domainType = Type.Int;
- elmtType = UserDefinedType.ArrayElementType(e.Seq.Type);
- } else if (e.Seq.Type is SeqType) {
+ elmtType = UserDefinedType.ArrayElementType(seqType);
+ } else if (seqType is SeqType) {
domainType = Type.Int;
- elmtType = ((SeqType)e.Seq.Type).Arg;
- } else if (e.Seq.Type is MapType) {
- domainType = ((MapType)e.Seq.Type).Domain;
- elmtType = ((MapType)e.Seq.Type).Range;
- } else if (e.Seq.Type is MultiSetType) {
- domainType = ((MultiSetType)e.Seq.Type).Arg;
+ elmtType = ((SeqType)seqType).Arg;
+ } else if (seqType is MapType) {
+ domainType = ((MapType)seqType).Domain;
+ elmtType = ((MapType)seqType).Range;
+ } else if (seqType is MultiSetType) {
+ domainType = ((MultiSetType)seqType).Arg;
elmtType = Type.Int;
} else { Contract.Assert(false); }
Bpl.Type elType = translator.TrType(elmtType);
@@ -9376,23 +9988,23 @@ namespace Microsoft.Dafny {
if (e.SelectOne) {
Contract.Assert(e1 == null);
Bpl.Expr x;
- if (e.Seq.Type.IsArrayType) {
+ if (seqType.IsArrayType) {
Bpl.Expr fieldName = translator.FunctionCall(expr.tok, BuiltinFunction.IndexField, null, e0);
x = ReadHeap(expr.tok, HeapExpr, TrExpr(e.Seq), fieldName);
- } else if(e.Seq.Type is SeqType) {
+ } else if (seqType is SeqType) {
x = translator.FunctionCall(expr.tok, BuiltinFunction.SeqIndex, predef.BoxType, seq, e0);
- } else if (e.Seq.Type is MapType) {
+ } else if (seqType is MapType) {
x = translator.FunctionCall(expr.tok, BuiltinFunction.MapElements, predef.MapType(e.tok, predef.BoxType, predef.BoxType), seq);
x = Bpl.Expr.Select(x, BoxIfNecessary(e.tok, e0, domainType));
- } else if (e.Seq.Type is MultiSetType) {
+ } else if (seqType is MultiSetType) {
x = Bpl.Expr.SelectTok(expr.tok, TrExpr(e.Seq), BoxIfNecessary(expr.tok, e0, domainType));
} else { Contract.Assert(false); x = null; }
- if (!ModeledAsBoxType(elmtType) && !(e.Seq.Type is MultiSetType)) {
+ if (!ModeledAsBoxType(elmtType) && !(seqType is MultiSetType)) {
x = translator.FunctionCall(expr.tok, BuiltinFunction.Unbox, elType, x);
}
return x;
} else {
- if (e.Seq.Type.IsArrayType) {
+ if (seqType.IsArrayType) {
seq = translator.FunctionCall(expr.tok, BuiltinFunction.SeqFromArray, elType, HeapExpr, seq);
}
var isLit = translator.IsLit(seq);
@@ -9421,24 +10033,25 @@ namespace Microsoft.Dafny {
else
{
Bpl.Expr seq = TrExpr(e.Seq);
- if (e.Seq.Type is SeqType)
+ var seqType = e.Seq.Type.NormalizeExpand();
+ if (seqType is SeqType)
{
- Type elmtType = cce.NonNull((SeqType)e.Seq.Type).Arg;
+ Type elmtType = cce.NonNull((SeqType)seqType).Arg;
Bpl.Expr index = TrExpr(e.Index);
Bpl.Expr val = BoxIfNecessary(expr.tok, TrExpr(e.Value), elmtType);
return translator.FunctionCall(expr.tok, BuiltinFunction.SeqUpdate, predef.BoxType, seq, index, val);
}
- else if (e.Seq.Type is MapType)
+ else if (seqType is MapType)
{
- MapType mt = (MapType)e.Seq.Type;
+ MapType mt = (MapType)seqType;
Bpl.Type maptype = predef.MapType(expr.tok, predef.BoxType, predef.BoxType);
Bpl.Expr index = BoxIfNecessary(expr.tok, TrExpr(e.Index), mt.Domain);
Bpl.Expr val = BoxIfNecessary(expr.tok, TrExpr(e.Value), mt.Range);
return translator.FunctionCall(expr.tok, "Map#Build", maptype, seq, index, val);
}
- else if (e.Seq.Type is MultiSetType)
+ else if (seqType is MultiSetType)
{
- Type elmtType = cce.NonNull((MultiSetType)e.Seq.Type).Arg;
+ Type elmtType = cce.NonNull((MultiSetType)seqType).Arg;
Bpl.Expr index = BoxIfNecessary(expr.tok, TrExpr(e.Index), elmtType);
Bpl.Expr val = TrExpr(e.Value);
return Bpl.Expr.StoreTok(expr.tok, seq, index, val);
@@ -9529,10 +10142,11 @@ namespace Microsoft.Dafny {
} else if (expr is MultiSetFormingExpr) {
MultiSetFormingExpr e = (MultiSetFormingExpr)expr;
- if (e.E.Type is SetType) {
- return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetFromSet, translator.TrType(cce.NonNull((SetType)e.E.Type).Arg), TrExpr(e.E));
- } else if (e.E.Type is SeqType) {
- return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetFromSeq, translator.TrType(cce.NonNull((SeqType)e.E.Type).Arg), TrExpr(e.E));
+ var eType = e.E.Type.NormalizeExpand();
+ if (eType is SetType) {
+ return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetFromSet, translator.TrType(cce.NonNull((SetType)eType).Arg), TrExpr(e.E));
+ } else if (eType is SeqType) {
+ return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetFromSeq, translator.TrType(cce.NonNull((SeqType)eType).Arg), TrExpr(e.E));
} else {
Contract.Assert(false); throw new cce.UnreachableException();
}
@@ -9546,29 +10160,31 @@ namespace Microsoft.Dafny {
case UnaryOpExpr.Opcode.Not:
return Bpl.Expr.Unary(expr.tok, UnaryOperator.Opcode.Not, arg);
case UnaryOpExpr.Opcode.Cardinality:
- if (e.E.Type is SeqType) {
+ var eType = e.E.Type.NormalizeExpand();
+ if (eType is SeqType) {
return translator.FunctionCall(expr.tok, BuiltinFunction.SeqLength, null, arg);
- } else if (e.E.Type is SetType) {
+ } else if (eType is SetType) {
return translator.FunctionCall(expr.tok, BuiltinFunction.SetCard, null, arg);
- } else if (e.E.Type is MultiSetType) {
+ } else if (eType is MultiSetType) {
return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetCard, null, arg);
- } else if (e.E.Type is MapType) {
+ } else if (eType is MapType) {
return translator.FunctionCall(expr.tok, BuiltinFunction.MapCard, null, arg);
} else {
Contract.Assert(false); throw new cce.UnreachableException(); // unexpected sized type
}
case UnaryOpExpr.Opcode.Fresh:
- if (e.E.Type is SetType) {
+ var eeType = e.E.Type.NormalizeExpand();
+ if (eeType is SetType) {
// generate: (forall $o: ref :: $o != null && X[Box($o)] ==> !old($Heap)[$o,alloc])
// TODO: trigger?
Bpl.Variable oVar = new Bpl.BoundVariable(expr.tok, new Bpl.TypedIdent(expr.tok, "$o", predef.RefType));
Bpl.Expr o = new Bpl.IdentifierExpr(expr.tok, oVar);
Bpl.Expr oNotNull = Bpl.Expr.Neq(o, predef.Null);
- Bpl.Expr oInSet = TrInSet(expr.tok, o, e.E, ((SetType)e.E.Type).Arg);
+ Bpl.Expr oInSet = TrInSet(expr.tok, o, e.E, ((SetType)eeType).Arg);
Bpl.Expr oIsFresh = Bpl.Expr.Not(Old.IsAlloced(expr.tok, o));
Bpl.Expr body = Bpl.Expr.Imp(Bpl.Expr.And(oNotNull, oInSet), oIsFresh);
return new Bpl.ForallExpr(expr.tok, new List<Variable> { oVar }, body);
- } else if (e.E.Type is SeqType) {
+ } else if (eeType is SeqType) {
// generate: (forall $i: int :: 0 <= $i && $i < Seq#Length(X) && Unbox(Seq#Index(X,$i)) != null ==> !old($Heap)[Unbox(Seq#Index(X,$i)),alloc])
// TODO: trigger?
Bpl.Variable iVar = new Bpl.BoundVariable(expr.tok, new Bpl.TypedIdent(expr.tok, "$i", Bpl.Type.Int));
@@ -9580,9 +10196,9 @@ namespace Microsoft.Dafny {
Bpl.Expr xsubiNotNull = Bpl.Expr.Neq(XsubI, predef.Null);
Bpl.Expr body = Bpl.Expr.Imp(Bpl.Expr.And(iBounds, xsubiNotNull), oIsFresh);
return new Bpl.ForallExpr(expr.tok, new List<Variable> { iVar }, body);
- } else if (e.E.Type.IsDatatype) {
- // translator.FunctionCall(e.tok, BuiltinFunction.DtAlloc, null, TrExpr(e.E), Old.HeapExpr);
- Bpl.Expr alloc = translator.MkIsAlloc(TrExpr(e.E), e.E.Type, Old.HeapExpr);
+ } else if (eeType.IsDatatype) {
+ // translator.FunctionCall(e.tok, BuiltinFunction.DtAlloc, null, TrExpr(e.E), Old.HeapExpr);
+ Bpl.Expr alloc = translator.MkIsAlloc(TrExpr(e.E), eeType, Old.HeapExpr);
return Bpl.Expr.Unary(expr.tok, UnaryOperator.Opcode.Not, alloc);
} else {
// generate: x != null && !old($Heap)[x]
@@ -9609,7 +10225,7 @@ namespace Microsoft.Dafny {
} else if (expr is BinaryExpr) {
BinaryExpr e = (BinaryExpr)expr;
- bool isReal = e.E0.Type is RealType;
+ bool isReal = e.E0.Type.IsRealType;
Bpl.Expr e0 = TrExpr(e.E0);
if (e.ResolvedOp == BinaryExpr.ResolvedOpcode.InSet) {
return TrInSet(expr.tok, e0, e.E1, cce.NonNull(e.E0.Type)); // let TrInSet translate e.E1
@@ -9655,16 +10271,20 @@ namespace Microsoft.Dafny {
case BinaryExpr.ResolvedOpcode.EqCommon:
keepLits = true;
- if (e.E0.Type.IsCoDatatype) {
- var cot = e.E0.Type.AsCoDatatype;
- return translator.CoEqualCall(cot, e.E0.Type.TypeArgs, e.E1.Type.TypeArgs, null, LayerN(2), e0, e1, expr.tok);
+ var cot = e.E0.Type.AsCoDatatype;
+ if (cot != null) {
+ var e0args = e.E0.Type.NormalizeExpand().TypeArgs;
+ var e1args = e.E1.Type.NormalizeExpand().TypeArgs;
+ return translator.CoEqualCall(cot, e0args, e1args, null, LayerN(2), e0, e1, expr.tok);
}
typ = Bpl.Type.Bool;
bOpcode = BinaryOperator.Opcode.Eq; break;
case BinaryExpr.ResolvedOpcode.NeqCommon:
- if (e.E0.Type.IsCoDatatype) {
- var cot = e.E0.Type.AsCoDatatype;
- var x = translator.CoEqualCall(cot, e.E0.Type.TypeArgs, e.E1.Type.TypeArgs, null, LayerN(2), e0, e1, expr.tok);
+ var cotx = e.E0.Type.AsCoDatatype;
+ if (cotx != null) {
+ var e0args = e.E0.Type.NormalizeExpand().TypeArgs;
+ var e1args = e.E1.Type.NormalizeExpand().TypeArgs;
+ var x = translator.CoEqualCall(cotx, e0args, e1args, null, LayerN(2), e0, e1, expr.tok);
return Bpl.Expr.Unary(expr.tok, UnaryOperator.Opcode.Not, x);
}
typ = Bpl.Type.Bool;
@@ -9724,11 +10344,11 @@ namespace Microsoft.Dafny {
case BinaryExpr.ResolvedOpcode.NotInSet:
Contract.Assert(false); throw new cce.UnreachableException(); // this case handled above
case BinaryExpr.ResolvedOpcode.Union:
- return translator.FunctionCall(expr.tok, BuiltinFunction.SetUnion, translator.TrType(cce.NonNull((SetType)expr.Type).Arg), e0, e1);
+ return translator.FunctionCall(expr.tok, BuiltinFunction.SetUnion, translator.TrType(expr.Type.AsSetType.Arg), e0, e1);
case BinaryExpr.ResolvedOpcode.Intersection:
- return translator.FunctionCall(expr.tok, BuiltinFunction.SetIntersection, translator.TrType(cce.NonNull((SetType)expr.Type).Arg), e0, e1);
+ return translator.FunctionCall(expr.tok, BuiltinFunction.SetIntersection, translator.TrType(expr.Type.AsSetType.Arg), e0, e1);
case BinaryExpr.ResolvedOpcode.SetDifference:
- return translator.FunctionCall(expr.tok, BuiltinFunction.SetDifference, translator.TrType(cce.NonNull((SetType)expr.Type).Arg), e0, e1);
+ return translator.FunctionCall(expr.tok, BuiltinFunction.SetDifference, translator.TrType(expr.Type.AsSetType.Arg), e0, e1);
case BinaryExpr.ResolvedOpcode.MultiSetEq:
return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetEqual, null, e0, e1);
@@ -9753,11 +10373,11 @@ namespace Microsoft.Dafny {
case BinaryExpr.ResolvedOpcode.NotInMultiSet:
Contract.Assert(false); throw new cce.UnreachableException(); // this case handled above
case BinaryExpr.ResolvedOpcode.MultiSetUnion:
- return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetUnion, translator.TrType(cce.NonNull((MultiSetType)expr.Type).Arg), e0, e1);
+ return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetUnion, translator.TrType(expr.Type.AsMultiSetType.Arg), e0, e1);
case BinaryExpr.ResolvedOpcode.MultiSetIntersection:
- return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetIntersection, translator.TrType(cce.NonNull((MultiSetType)expr.Type).Arg), e0, e1);
+ return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetIntersection, translator.TrType(expr.Type.AsMultiSetType.Arg), e0, e1);
case BinaryExpr.ResolvedOpcode.MultiSetDifference:
- return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetDifference, translator.TrType(cce.NonNull((MultiSetType)expr.Type).Arg), e0, e1);
+ return translator.FunctionCall(expr.tok, BuiltinFunction.MultiSetDifference, translator.TrType(expr.Type.AsMultiSetType.Arg), e0, e1);
case BinaryExpr.ResolvedOpcode.SeqEq:
return translator.FunctionCall(expr.tok, BuiltinFunction.SeqEqual, null, e0, e1);
@@ -9774,7 +10394,7 @@ namespace Microsoft.Dafny {
translator.FunctionCall(expr.tok, BuiltinFunction.SeqSameUntil, null, e0, e1, len0));
}
case BinaryExpr.ResolvedOpcode.Concat:
- return translator.FunctionCall(expr.tok, BuiltinFunction.SeqAppend, translator.TrType(cce.NonNull((SeqType)expr.Type).Arg), e0, e1);
+ return translator.FunctionCall(expr.tok, BuiltinFunction.SeqAppend, translator.TrType(expr.Type.AsSeqType.Arg), e0, e1);
case BinaryExpr.ResolvedOpcode.InSeq:
return translator.FunctionCall(expr.tok, BuiltinFunction.SeqContains, null, e1,
BoxIfNecessary(expr.tok, e0, cce.NonNull(e.E0.Type)));
@@ -9819,9 +10439,11 @@ namespace Microsoft.Dafny {
switch (e.Op) {
case TernaryExpr.Opcode.PrefixEqOp:
case TernaryExpr.Opcode.PrefixNeqOp:
- var cot = e.E1.Type.AsCoDatatype;
+ var e1type = e.E1.Type.NormalizeExpand();
+ var e2type = e.E2.Type.NormalizeExpand();
+ var cot = e1type.AsCoDatatype;
Contract.Assert(cot != null); // the argument types of prefix equality (and prefix disequality) are codatatypes
- var r = translator.CoEqualCall(cot, e.E1.Type.TypeArgs, e.E2.Type.TypeArgs, e0, LayerN(2), e1, e2);
+ var r = translator.CoEqualCall(cot, e1type.TypeArgs, e2type.TypeArgs, e0, LayerN(2), e1, e2);
if (e.Op == TernaryExpr.Opcode.PrefixEqOp) {
return r;
} else {
@@ -10909,7 +11531,7 @@ namespace Microsoft.Dafny {
/// </summary>
bool TrSplitExpr(Expression expr, List<SplitExprInfo/*!*/>/*!*/ splits, bool position, int heightLimit, bool apply_induction, ExpressionTranslator etran) {
Contract.Requires(expr != null);
- Contract.Requires(expr.Type is BoolType || (expr is BoxingCastExpr && ((BoxingCastExpr)expr).E.Type is BoolType));
+ Contract.Requires(expr.Type.IsBoolType || (expr is BoxingCastExpr && ((BoxingCastExpr)expr).E.Type.IsBoolType));
Contract.Requires(splits != null);
Contract.Requires(etran != null);
@@ -10985,7 +11607,9 @@ namespace Microsoft.Dafny {
} else if (expr is TernaryExpr) {
var e = (TernaryExpr)expr;
if ((e.Op == TernaryExpr.Opcode.PrefixEqOp && position) || (e.Op == TernaryExpr.Opcode.PrefixNeqOp && !position)) {
- var codecl = e.E1.Type.AsCoDatatype;
+ var e1type = e.E1.Type.NormalizeExpand();
+ var e2type = e.E2.Type.NormalizeExpand();
+ var codecl = e1type.AsCoDatatype;
Contract.Assert(codecl != null);
var k = etran.TrExpr(e.E0);
var A = etran.TrExpr(e.E1);
@@ -10995,7 +11619,7 @@ namespace Microsoft.Dafny {
// checked $PrefixEqual#Dt(k, A, B) || (0 < k ==> A.Cons? ==> B.Cons? && A.head == B.head && $PrefixEqual#2#Dt(k - 1, A.tail, B.tail)) // note the #2 in the recursive call, just like for user-defined predicates that are inlined by TrSplitExpr
// free $PrefixEqual#Dt(k, A, B);
var kPos = Bpl.Expr.Lt(Bpl.Expr.Literal(0), k);
- var prefixEqK = CoEqualCall(codecl, e.E1.Type.TypeArgs, e.E2.Type.TypeArgs, k, etran.LayerN(2), A, B); // FunctionCall(expr.tok, CoPrefixName(codecl, 1), Bpl.Type.Bool, k, A, B);
+ var prefixEqK = CoEqualCall(codecl, e1type.TypeArgs, e2type.TypeArgs, k, etran.LayerN(2), A, B); // FunctionCall(expr.tok, CoPrefixName(codecl, 1), Bpl.Type.Bool, k, A, B);
var kMinusOne = Bpl.Expr.Sub(k, Bpl.Expr.Literal(1));
// for the inlining of the definition of prefix equality, translate the two main equality operands arguments with a higher offset (to obtain #2 functions)
var etran2 = etran.LayerOffset(1);
@@ -11004,7 +11628,7 @@ namespace Microsoft.Dafny {
var needsTokenAdjust = TrSplitNeedsTokenAdjustment(expr);
// Dan: dafny4/Circ.dfy needs this one to be 2+, rather than 1+
Bpl.Expr layer = LayerSucc(etran.layerInterCluster, 2);
- foreach (var c in CoPrefixEquality(needsTokenAdjust ? new ForceCheckToken(expr.tok) : expr.tok, codecl, e.E1.Type.TypeArgs, e.E2.Type.TypeArgs, kMinusOne, layer, A2, B2, true)) {
+ foreach (var c in CoPrefixEquality(needsTokenAdjust ? new ForceCheckToken(expr.tok) : expr.tok, codecl, e1type.TypeArgs, e2type.TypeArgs, kMinusOne, layer, A2, B2, true)) {
var p = Bpl.Expr.Binary(c.tok, BinaryOperator.Opcode.Or, prefixEqK, Bpl.Expr.Imp(kPos, c));
splits.Add(new SplitExprInfo(SplitExprInfo.K.Checked, p));
}
@@ -11152,7 +11776,7 @@ namespace Microsoft.Dafny {
var substMap = new Dictionary<IVariable, Expression>();
foreach (var n in inductionVariables) {
toks.Add(n.tok);
- types.Add(n.Type);
+ types.Add(n.Type.NormalizeExpand());
BoundVar k = new BoundVar(n.tok, n.Name + "$ih#" + otherTmpVarCount, n.Type);
otherTmpVarCount++;
kvars.Add(k);
@@ -11582,6 +12206,7 @@ namespace Microsoft.Dafny {
}
IEnumerable<Bpl.Expr> InductionCases(Type ty, Bpl.Expr expr, ExpressionTranslator etran) {
+ ty = ty.NormalizeExpand();
IndDatatypeDecl dt = ty.AsIndDatatype;
if (dt == null) {
yield return Bpl.Expr.True;
@@ -11652,7 +12277,7 @@ namespace Microsoft.Dafny {
if (ty.IsTypeParameter && ! ty.AsTypeParameter.IsAbstractTypeDeclaration) {
fvs.Add(ty.AsTypeParameter);
}
- ty.TypeArgs.Iter(tt => ComputeFreeTypeVariables(tt, fvs));
+ ty.NormalizeExpand().TypeArgs.Iter(tt => ComputeFreeTypeVariables(tt, fvs));
}
static void ComputeFreeVariables(Expression expr, ISet<IVariable> fvs, ref bool usesHeap, ref bool usesOldHeap, ref Type usesThis, bool inOldContext) {
@@ -12774,12 +13399,14 @@ namespace Microsoft.Dafny {
return Util.Concat(xs, ys);
}
-
static List<B> Map<A,B>(IEnumerable<A> xs, Func<A,B> f) {
return Util.Map(xs, f);
}
- static void MapM<A>(IEnumerable<A> xs, Action<A> K) {
+ public static void MapM<A>(IEnumerable<A> xs, Action<A> K)
+ {
+ Contract.Requires(xs != null);
+ Contract.Requires(K != null);
foreach (A x in xs) {
K(x);
}
diff --git a/Source/DafnyDriver/DafnyDriver.cs b/Source/DafnyDriver/DafnyDriver.cs
index e3e29c58..cb645d2f 100644
--- a/Source/DafnyDriver/DafnyDriver.cs
+++ b/Source/DafnyDriver/DafnyDriver.cs
@@ -39,6 +39,8 @@ namespace Microsoft.Dafny
exitValue = ExitValue.PREPROCESSING_ERROR;
goto END;
}
+ //CommandLineOptions.Clo.Files = new List<string> { @"C:\dafny\Test\dafny0\Trait\TraitOverride1.dfy" };
+
if (CommandLineOptions.Clo.Files.Count == 0)
{
printer.ErrorWriteLine(Console.Out, "*** Error: No input files were specified.");
diff --git a/Source/DafnyExtension/DafnyRuntime.cs b/Source/DafnyExtension/DafnyRuntime.cs
index 6f0cab13..d6bd895a 100644
--- a/Source/DafnyExtension/DafnyRuntime.cs
+++ b/Source/DafnyExtension/DafnyRuntime.cs
@@ -656,6 +656,13 @@ namespace Dafny
num = n;
den = d;
}
+ public BigInteger ToBigInteger() {
+ if (0 <= num) {
+ return num / den;
+ } else {
+ return (num - den + 1) / den;
+ }
+ }
/// <summary>
/// Returns values such that aa/dd == a and bb/dd == b.
/// </summary>
diff --git a/Source/DafnyExtension/TokenTagger.cs b/Source/DafnyExtension/TokenTagger.cs
index 5068354a..438d9be6 100644
--- a/Source/DafnyExtension/TokenTagger.cs
+++ b/Source/DafnyExtension/TokenTagger.cs
@@ -284,6 +284,8 @@ namespace DafnyLanguage
case "calc":
case "case":
case "class":
+ case "trait":
+ case "extends":
case "codatatype":
case "colemma":
case "constructor":
diff --git a/Test/dafny0/AutoReq.dfy b/Test/dafny0/AutoReq.dfy
index efe88446..9e0d3b63 100644
--- a/Test/dafny0/AutoReq.dfy
+++ b/Test/dafny0/AutoReq.dfy
@@ -146,170 +146,170 @@ module {:autoReq} QuantifierTestsHard {
function n(x:int) : bool
function f1(x:int) : bool
- requires x > 3;
- requires x < 16;
+ requires x > 3;
+ requires x < 16;
function variable_uniqueness_test(x:int) : bool
{
(forall y:int :: m(y))
- &&
- f1(x)
+ &&
+ f1(x)
}
}
module CorrectReqOrdering {
- function f1(x:int) : bool
- requires x > 3;
+ function f1(x:int) : bool
+ requires x > 3;
- function f2(b:bool) : bool
- requires b;
+ function f2(b:bool) : bool
+ requires b;
- // Should pass if done correctly.
- // However, if Dafny incorrectly put the requires for f2 first,
- // then the requires for f1 won't be satisfied
- function {:autoReq} f3(z:int) : bool
- {
- f2(f1(z))
- }
+ // Should pass if done correctly.
+ // However, if Dafny incorrectly put the requires for f2 first,
+ // then the requires for f1 won't be satisfied
+ function {:autoReq} f3(z:int) : bool
+ {
+ f2(f1(z))
+ }
}
-module ShortCircuiting {
- function f1(x:int) : bool
- requires x > 3;
+module ShortCircuiting {
+ function f1(x:int) : bool
+ requires x > 3;
- function f2(y:int) : bool
- requires y < 10;
+ function f2(y:int) : bool
+ requires y < 10;
- function {:autoReq} test1(x':int, y':int) : bool
- {
- f1(x') && f2(y')
- }
+ function {:autoReq} test1(x':int, y':int) : bool
+ {
+ f1(x') && f2(y')
+ }
- function {:autoReq} test2(x':int, y':int) : bool
- {
- f1(x') ==> f2(y')
- }
+ function {:autoReq} test2(x':int, y':int) : bool
+ {
+ f1(x') ==> f2(y')
+ }
- function {:autoReq} test3(x':int, y':int) : bool
- {
- f1(x') || f2(y')
- }
+ function {:autoReq} test3(x':int, y':int) : bool
+ {
+ f1(x') || f2(y')
+ }
}
module Lets {
- function f1(x:int) : bool
- requires x > 3;
+ function f1(x:int) : bool
+ requires x > 3;
- function {:autoReq} test1(x':int) : bool
- {
- var y' := 3*x'; f1(y')
- }
+ function {:autoReq} test1(x':int) : bool
+ {
+ var y' := 3*x'; f1(y')
+ }
}
// Test nested module specification of :autoReq attribute
module {:autoReq} M1 {
- module M2 {
- function f(x:int) : bool
- requires x > 3;
- {
- x > 7
- }
-
- // Should succeed thanks to auto-generation based on f's requirements
- function {:autoReq} h(y:int) : bool
- {
- f(y)
- }
+ module M2 {
+ function f(x:int) : bool
+ requires x > 3;
+ {
+ x > 7
}
+
+ // Should succeed thanks to auto-generation based on f's requirements
+ function {:autoReq} h(y:int) : bool
+ {
+ f(y)
+ }
+ }
}
module Datatypes {
- datatype TheType = TheType_builder(x:int) | TheType_copier(t:TheType);
+ datatype TheType = TheType_builder(x:int) | TheType_copier(t:TheType);
- function f1(t:TheType):bool
- requires t.TheType_builder? && t.x > 3;
+ function f1(t:TheType):bool
+ requires t.TheType_builder? && t.x > 3;
- function {:autoReq} test(t:TheType) : bool
- {
- f1(t)
- }
+ function {:autoReq} test(t:TheType) : bool
+ {
+ f1(t)
+ }
- function f2(x:int) : bool
- requires forall t:TheType :: t.TheType_builder? && t.x > x;
- {
- true
- }
+ function f2(x:int) : bool
+ requires forall t:TheType :: t.TheType_builder? && t.x > x;
+ {
+ true
+ }
- // Should cause a function-requirement violation without autoReq
- function f3(y:int) : bool
- {
- f2(y)
- }
+ // Should cause a function-requirement violation without autoReq
+ function f3(y:int) : bool
+ {
+ f2(y)
+ }
- function {:autoReq} test2(z:int) : bool
- {
- f2(z)
- }
+ function {:autoReq} test2(z:int) : bool
+ {
+ f2(z)
+ }
}
module Matches {
- datatype TheType = TheType_builder(x:int) | TheType_copier(t:TheType);
+ datatype TheType = TheType_builder(x:int) | TheType_copier(t:TheType);
- function f1(x:int):bool
- requires x > 3;
+ function f1(x:int):bool
+ requires x > 3;
- function {:autoReq} basic_test(t:TheType) : bool
- {
- match t
- case TheType_builder(x) => f1(x)
- case TheType_copier(t) => true
- }
+ function {:autoReq} basic_test(t:TheType) : bool
+ {
+ match t
+ case TheType_builder(x) => f1(x)
+ case TheType_copier(t) => true
+ }
}
// Make sure :autoReq works with static functions
module StaticTest {
- static function f(x:int) : bool
- requires x > 3;
- {
- x > 7
- }
+ static function f(x:int) : bool
+ requires x > 3;
+ {
+ x > 7
+ }
- static function {:autoReq} g(z:int) : bool
- requires f(z);
- {
- true
- }
-
- // Should succeed thanks to auto-generation based on f's requirements
- static function {:autoReq} h(y:int) : bool
- {
- g(y)
- }
+ static function {:autoReq} g(z:int) : bool
+ requires f(z);
+ {
+ true
+ }
- static predicate IsEven(x:int)
+ // Should succeed thanks to auto-generation based on f's requirements
+ static function {:autoReq} h(y:int) : bool
+ {
+ g(y)
+ }
- static function EvenDoubler(x:int) : int
- requires IsEven(x);
+ static predicate IsEven(x:int)
- // Should succeed thanks to auto-generated requirement of IsEven
- static function {:autoReq} test(y:int) : int
- {
- EvenDoubler(y)
- }
+ static function EvenDoubler(x:int) : int
+ requires IsEven(x);
+
+ // Should succeed thanks to auto-generated requirement of IsEven
+ static function {:autoReq} test(y:int) : int
+ {
+ EvenDoubler(y)
+ }
}
module OpaqueTest {
- static function bar(x:int) : int
- requires x>7;
- {
- x-2
- }
+ static function bar(x:int) : int
+ requires x>7;
+ {
+ x-2
+ }
- static function {:autoReq} {:opaque} foo(x:int) : int
- {
- bar(x)
- }
+ static function {:autoReq} {:opaque} foo(x:int) : int
+ {
+ bar(x)
+ }
}
diff --git a/Test/dafny0/AutoReq.dfy.expect b/Test/dafny0/AutoReq.dfy.expect
index 617e6003..547b676d 100644
--- a/Test/dafny0/AutoReq.dfy.expect
+++ b/Test/dafny0/AutoReq.dfy.expect
@@ -1,5 +1,5 @@
-AutoReq.dfy(247,3): Error: possible violation of function precondition
-AutoReq.dfy(239,12): Related location
+AutoReq.dfy(247,5): Error: possible violation of function precondition
+AutoReq.dfy(239,14): Related location
Execution trace:
(0,0): anon0
(0,0): anon3_Else
diff --git a/Test/dafny0/ComputationsLoop.dfy b/Test/dafny0/ComputationsLoop.dfy
new file mode 100644
index 00000000..b89455a2
--- /dev/null
+++ b/Test/dafny0/ComputationsLoop.dfy
@@ -0,0 +1,13 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+function KeepDoin'It(x: nat): nat
+ decreases x;
+{
+ KeepDoin'It(x + 1)
+}
+
+lemma Test(r: nat)
+{
+ assert KeepDoin'It(20) == r;
+} \ No newline at end of file
diff --git a/Test/dafny0/ComputationsLoop.dfy.expect b/Test/dafny0/ComputationsLoop.dfy.expect
new file mode 100644
index 00000000..d9d48024
--- /dev/null
+++ b/Test/dafny0/ComputationsLoop.dfy.expect
@@ -0,0 +1,9 @@
+ComputationsLoop.dfy(7,3): Error: failure to decrease termination measure
+Execution trace:
+ (0,0): anon0
+ (0,0): anon3_Else
+ComputationsLoop.dfy(12,26): Error: assertion violation
+Execution trace:
+ (0,0): anon0
+
+Dafny program verifier finished with 1 verified, 2 errors
diff --git a/Test/dafny0/ComputationsLoop2.dfy b/Test/dafny0/ComputationsLoop2.dfy
new file mode 100644
index 00000000..d03d7c79
--- /dev/null
+++ b/Test/dafny0/ComputationsLoop2.dfy
@@ -0,0 +1,17 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+function KeepDoin'It(x: nat): nat
+{
+ KeepDoin'ItToo(x + 1)
+}
+
+function KeepDoin'ItToo(x: nat): nat
+{
+ KeepDoin'It(x + 1)
+}
+
+lemma Test(r: nat)
+{
+ assert KeepDoin'It(20) == r;
+} \ No newline at end of file
diff --git a/Test/dafny0/ComputationsLoop2.dfy.expect b/Test/dafny0/ComputationsLoop2.dfy.expect
new file mode 100644
index 00000000..0a45e6d0
--- /dev/null
+++ b/Test/dafny0/ComputationsLoop2.dfy.expect
@@ -0,0 +1,13 @@
+ComputationsLoop2.dfy(6,3): Error: cannot prove termination; try supplying a decreases clause
+Execution trace:
+ (0,0): anon0
+ (0,0): anon3_Else
+ComputationsLoop2.dfy(11,3): Error: cannot prove termination; try supplying a decreases clause
+Execution trace:
+ (0,0): anon0
+ (0,0): anon3_Else
+ComputationsLoop2.dfy(16,26): Error: assertion violation
+Execution trace:
+ (0,0): anon0
+
+Dafny program verifier finished with 1 verified, 3 errors
diff --git a/Test/dafny0/EqualityTypes.dfy.expect b/Test/dafny0/EqualityTypes.dfy.expect
index 410e4507..70e46ff0 100644
--- a/Test/dafny0/EqualityTypes.dfy.expect
+++ b/Test/dafny0/EqualityTypes.dfy.expect
@@ -5,7 +5,7 @@ EqualityTypes.dfy(41,8): Error: opaque type 'Y' is not allowed to be replaced by
EqualityTypes.dfy(45,11): Error: type 'X' is used to refine an opaque type with equality support, but 'X' does not support equality
EqualityTypes.dfy(46,11): Error: type 'Y' is used to refine an opaque type with equality support, but 'Y' does not support equality
EqualityTypes.dfy(66,7): Error: == can only be applied to expressions of types that support equality (got Dt<T>)
-EqualityTypes.dfy(85,8): Error: type parameter 0 (T) passed to method M must support equality (got _T0)
+EqualityTypes.dfy(85,8): Error: type parameter 0 (T) passed to method M must support equality (got _T0) (perhaps try declaring type parameter '_T0' on line 81 as '_T0(==)', which says it can only be instantiated with a type that supports equality)
EqualityTypes.dfy(109,7): Error: == can only be applied to expressions of types that support equality (got D)
EqualityTypes.dfy(114,13): Error: == can only be applied to expressions of types that support equality (got D)
EqualityTypes.dfy(118,16): Error: == can only be applied to expressions of types that support equality (got D)
diff --git a/Test/dafny0/Modules0.dfy.expect b/Test/dafny0/Modules0.dfy.expect
index 3d8a5099..1a06d8f2 100644
--- a/Test/dafny0/Modules0.dfy.expect
+++ b/Test/dafny0/Modules0.dfy.expect
@@ -4,26 +4,42 @@ Modules0.dfy(10,7): Error: Duplicate name of top-level declaration: WazzupA
Modules0.dfy(13,7): Error: Duplicate name of top-level declaration: WazzupB
Modules0.dfy(14,8): Error: Duplicate name of top-level declaration: WazzupB
Modules0.dfy(15,11): Error: Duplicate name of top-level declaration: WazzupB
-Modules0.dfy(56,18): Error: Undeclared top-level type or type parameter: MyClass1 (did you forget to qualify a name?)
-Modules0.dfy(57,18): Error: Undeclared top-level type or type parameter: MyClass2 (did you forget to qualify a name?)
-Modules0.dfy(68,18): Error: Undeclared top-level type or type parameter: MyClass2 (did you forget to qualify a name?)
-Modules0.dfy(75,20): Error: Undeclared top-level type or type parameter: MyClass1 (did you forget to qualify a name?)
-Modules0.dfy(75,34): Error: Undeclared top-level type or type parameter: MyClass0 (did you forget to qualify a name?)
-Modules0.dfy(78,23): Error: Undeclared top-level type or type parameter: MyClass0 (did you forget to qualify a name?)
-Modules0.dfy(83,24): Error: Undeclared top-level type or type parameter: MyClassY (did you forget to qualify a name?)
-Modules0.dfy(92,16): Error: Undeclared top-level type or type parameter: ClassG (did you forget to qualify a name?)
+Modules0.dfy(56,21): Error: Undeclared top-level type or type parameter: MyClass1 (did you forget to qualify a name?)
+Modules0.dfy(57,21): Error: Undeclared top-level type or type parameter: MyClass2 (did you forget to qualify a name?)
+Modules0.dfy(68,21): Error: Undeclared top-level type or type parameter: MyClass2 (did you forget to qualify a name?)
+Modules0.dfy(76,9): Error: type MyClass1 does not have a member Down
+Modules0.dfy(76,9): Error: type MyClass1 does not have a member Down
+Modules0.dfy(76,6): Error: expected method call, found expression
+Modules0.dfy(79,9): Error: type MyClass0 does not have a member Down
+Modules0.dfy(79,9): Error: type MyClass0 does not have a member Down
+Modules0.dfy(79,6): Error: expected method call, found expression
+Modules0.dfy(84,8): Error: type MyClassY does not have a member M
+Modules0.dfy(84,8): Error: type MyClassY does not have a member M
+Modules0.dfy(84,6): Error: expected method call, found expression
+Modules0.dfy(92,19): Error: Undeclared top-level type or type parameter: ClassG (did you forget to qualify a name?)
Modules0.dfy(224,15): Error: Undeclared top-level type or type parameter: X (did you forget to qualify a name?)
Modules0.dfy(224,8): Error: new can be applied only to reference types (got X)
Modules0.dfy(233,13): Error: Undeclared type X in module B
Modules0.dfy(243,13): Error: unresolved identifier: X
Modules0.dfy(244,15): Error: member DoesNotExist does not exist in class X
+Modules0.dfy(244,15): Error: member DoesNotExist does not exist in class X
Modules0.dfy(283,19): Error: Undeclared top-level type or type parameter: D (did you forget to qualify a name?)
Modules0.dfy(283,12): Error: new can be applied only to reference types (got D)
Modules0.dfy(286,25): Error: type of the receiver is not fully determined at this program point
+Modules0.dfy(286,25): Error: type of the receiver is not fully determined at this program point
+Modules0.dfy(287,16): Error: type of the receiver is not fully determined at this program point
Modules0.dfy(287,16): Error: type of the receiver is not fully determined at this program point
Modules0.dfy(287,6): Error: expected method call, found expression
Modules0.dfy(288,16): Error: type of the receiver is not fully determined at this program point
+Modules0.dfy(288,16): Error: type of the receiver is not fully determined at this program point
Modules0.dfy(288,6): Error: expected method call, found expression
Modules0.dfy(310,24): Error: module Q_Imp does not exist
-Modules0.dfy(100,14): Error: Undeclared top-level type or type parameter: MyClassY (did you forget to qualify a name?)
-28 resolution/type errors detected in Modules0.dfy
+Modules0.dfy(102,6): Error: type MyClassY does not have a member M
+Modules0.dfy(102,6): Error: type MyClassY does not have a member M
+Modules0.dfy(102,4): Error: expected method call, found expression
+Modules0.dfy(127,11): Error: ghost variables are allowed only in specification contexts
+Modules0.dfy(141,11): Error: old expressions are allowed only in specification and ghost contexts
+Modules0.dfy(142,11): Error: fresh expressions are allowed only in specification and ghost contexts
+Modules0.dfy(143,11): Error: unresolved identifier: allocated
+Modules0.dfy(146,19): Error: unresolved identifier: allocated
+44 resolution/type errors detected in Modules0.dfy
diff --git a/Test/dafny0/ResolutionErrors.dfy b/Test/dafny0/ResolutionErrors.dfy
index 520b2e38..9f6c948a 100644
--- a/Test/dafny0/ResolutionErrors.dfy
+++ b/Test/dafny0/ResolutionErrors.dfy
@@ -1007,20 +1007,20 @@ module CycleError2 {
type A = B // error: cycle: A -> B -> A
type B = set<A>
}
-module Good0 {
+module CycleErrors3 {
type A = (B, D<bool>)
type B = C
class C {
var a: A; // this is fine
}
- datatype D<X> = Make(A, B, C) // this is fine, too
+ datatype D<X> = Make(A, B, C) // error: cannot construct a D<X>
}
-module CycleError3 {
+module CycleError4 {
type A = B // error: cycle: A -> B -> A
type B = C<A>
class C<T> { }
}
-module CycleError4 {
+module CycleError5 {
type A = B // error: cycle: A -> B -> A
type B = Dt<A>
datatype Dt<T> = Make(T)
@@ -1090,3 +1090,13 @@ module OpaqueTypes1 {
assert p != q; // error: types must be the same in order to do compare
}
}
+
+// ----- new trait -------------------------------------------
+
+
+trait J { }
+type JJ = J
+method TraitSynonym()
+{
+ var x := new JJ; // error: new cannot be applied to a trait
+}
diff --git a/Test/dafny0/ResolutionErrors.dfy.expect b/Test/dafny0/ResolutionErrors.dfy.expect
index 49cfe650..b11fa9f8 100644
--- a/Test/dafny0/ResolutionErrors.dfy.expect
+++ b/Test/dafny0/ResolutionErrors.dfy.expect
@@ -63,6 +63,7 @@ ResolutionErrors.dfy(993,22): Error: Undeclared top-level type or type parameter
ResolutionErrors.dfy(1000,7): Error: Cycle among type synonyms: A -> A
ResolutionErrors.dfy(1003,7): Error: Cycle among type synonyms: A -> B -> A
ResolutionErrors.dfy(1007,7): Error: Cycle among type synonyms: A -> B -> A
+ResolutionErrors.dfy(1016,11): Error: because of cyclic dependencies among constructor argument types, no instances of datatype 'D' can be constructed
ResolutionErrors.dfy(1019,7): Error: Cycle among type synonyms: A -> B -> A
ResolutionErrors.dfy(1024,7): Error: Cycle among type synonyms: A -> B -> A
ResolutionErrors.dfy(1043,21): Error: unresolved identifier: x
@@ -171,4 +172,5 @@ ResolutionErrors.dfy(956,10): Error: second argument to % must be of type int (i
ResolutionErrors.dfy(960,7): Error: type conversion to real is allowed only from int (got real)
ResolutionErrors.dfy(961,7): Error: type conversion to int is allowed only from real (got int)
ResolutionErrors.dfy(962,7): Error: type conversion to int is allowed only from real (got nat)
-173 resolution/type errors detected in ResolutionErrors.dfy
+ResolutionErrors.dfy(1101,8): Error: new cannot be applied to a trait
+175 resolution/type errors detected in ResolutionErrors.dfy
diff --git a/Test/dafny0/Trait/TraitBasix.dfy b/Test/dafny0/Trait/TraitBasix.dfy
new file mode 100644
index 00000000..e16e8fc4
--- /dev/null
+++ b/Test/dafny0/Trait/TraitBasix.dfy
@@ -0,0 +1,173 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+module m1
+{
+ trait I1
+ {
+ function M1(x:int,y:int) :int
+ {
+ x*y
+ }
+ }
+
+
+ trait I2 //all is fine in this trait
+ {
+ var x: int;
+
+ function method Twice(): int
+ reads this;
+ {
+ x + x
+ }
+
+ function method F(z: int): int
+ reads this;
+
+
+ method Compute(s: bool) returns (t: int, u: int)
+ modifies this;
+ {
+ if s {
+ t, u := F(F(15)), Twice();
+ } else {
+ t := Twice();
+ x := F(45);
+ u := Twice();
+ var p := Customizable(u);
+ return t+p, u;
+ }
+ }
+
+ method Customizable(w: int) returns (p: int)
+ modifies this;
+
+
+ static method StaticM(a: int) returns (b: int)
+ {
+ b := a;
+ }
+
+ static method SS(a: int) returns (b:int)
+ {
+ b:=a*2;
+ }
+ }
+
+ method I2Client(j: I2) returns (p: int) //all is fine in this client method
+ requires j != null;
+ modifies j;
+ {
+ j.x := 100;
+ var h := j.Twice() + j.F(j.Twice());
+ var a, b := j.Compute(h < 33);
+ var c, d := j.Compute(33 <= h);
+ p := j.Customizable(a + b + c + d);
+ p := I2.StaticM(p);
+ }
+
+ class I0Child extends I2 //errors, body-less methods/functions in the parent have not implemented here
+ {
+ function method F(z: int): int
+ reads this;
+ {
+ z
+ }
+ var x: int; //error, x has been declared in the parent trait
+ }
+
+ class I0Child2 extends I2
+ {
+ method Customizable(w: int) returns (p: int)
+ modifies this;
+ {
+ w:=w+1;
+ }
+
+ var c1: I0Child;
+ }
+
+ class IXChild extends IX //error, IX trait is undefined
+ {
+
+ }
+}
+
+
+trait I0
+{
+ var x: int;
+ constructor I0(x0: int) // error: constructor is not allowed in a trait
+ {
+ x:=x0;
+ }
+}
+
+trait I1
+{
+ function M1(x:int,y:int) :int
+ {
+ x*y
+ }
+}
+
+method TestI1()
+{
+ var i1 := new I1; //error: new is not allowed in a trait
+}
+
+trait I2 //all is fine in this trait
+{
+ var x: int;
+
+ function method Twice(): int
+ reads this;
+ {
+ x + x
+ }
+
+ function method F(z: int): int
+ reads this;
+
+
+ method Compute(s: bool) returns (t: int, u: int)
+ modifies this;
+ {
+ if s {
+ t, u := F(F(15)), Twice();
+ } else {
+ t := Twice();
+ x := F(45);
+ u := Twice();
+ var p := Customizable(u);
+ return t+p, u;
+ }
+ }
+
+ method Customizable(w: int) returns (p: int)
+ modifies this;
+
+
+ static method StaticM(a: int) returns (b: int)
+ {
+ b := a;
+ }
+
+ static method SS(a: int) returns (b:int)
+ {
+ b:=a*2;
+ }
+}
+
+method I2Client(j: I2) returns (p: int) //all is fine in this client method
+ requires j != null;
+ modifies j;
+{
+ j.x := 100;
+ var h := j.Twice() + j.F(j.Twice());
+ var a, b := j.Compute(h < 33);
+ var c, d := j.Compute(33 <= h);
+ p := j.Customizable(a + b + c + d);
+ p := I2.StaticM(p);
+}
diff --git a/Test/dafny0/Trait/TraitBasix.dfy.expect b/Test/dafny0/Trait/TraitBasix.dfy.expect
new file mode 100644
index 00000000..4a908ee7
--- /dev/null
+++ b/Test/dafny0/Trait/TraitBasix.dfy.expect
@@ -0,0 +1,7 @@
+TraitBasix.dfy(91,23): Error: unresolved identifier: IX
+TraitBasix.dfy(77,13): Error: member in the class has been already inherited from its parent trait
+TraitBasix.dfy(70,7): Error: class: I0Child does not implement trait member: Customizable
+TraitBasix.dfy(80,7): Error: class: I0Child2 does not implement trait member: F
+TraitBasix.dfy(98,6): Error: a trait is not allowed to declare a constructor
+TraitBasix.dfy(117,10): Error: new cannot be applied to a trait
+6 resolution/type errors detected in TraitBasix.dfy
diff --git a/Test/dafny0/Trait/TraitExtend.dfy b/Test/dafny0/Trait/TraitExtend.dfy
new file mode 100644
index 00000000..1a59439c
--- /dev/null
+++ b/Test/dafny0/Trait/TraitExtend.dfy
@@ -0,0 +1,43 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+trait t
+{
+ var f: int;
+
+ function method Plus (x:int, y:int) : int
+ requires x>y;
+ {
+ x + y
+ }
+
+ function method Mul (x:int, y:int, z:int) : int
+ requires x>y;
+ {
+ x * y * z
+ }
+
+ //function method BodyLess1() : int
+
+ static method GetPhoneNumber (code:int, n:int) returns (z:int)
+ {
+ z := code + n;
+ }
+
+ method TestPhone ()
+ {
+ var num : int;
+ num := GetPhoneNumber (10, 30028);
+ }
+}
+
+class c1 extends t
+{
+ method P2(x:int, y:int) returns (z:int)
+ requires x>y;
+ {
+ z:= Plus(x,y) + Mul (x,y,1);
+ var j:int := Mul (x,y); //error, too few parameters in calling inherited method
+ var k:int := Plus(x,y,1); //error, too many parameters in calling inherited method
+ }
+} \ No newline at end of file
diff --git a/Test/dafny0/Trait/TraitExtend.dfy.expect b/Test/dafny0/Trait/TraitExtend.dfy.expect
new file mode 100644
index 00000000..73a24ad8
--- /dev/null
+++ b/Test/dafny0/Trait/TraitExtend.dfy.expect
@@ -0,0 +1,3 @@
+TraitExtend.dfy(40,20): Error: wrong number of function arguments (got 2, expected 3)
+TraitExtend.dfy(41,20): Error: wrong number of function arguments (got 3, expected 2)
+2 resolution/type errors detected in TraitExtend.dfy
diff --git a/Test/dafny0/Trait/TraitMultiModule.dfy b/Test/dafny0/Trait/TraitMultiModule.dfy
new file mode 100644
index 00000000..f60db7b4
--- /dev/null
+++ b/Test/dafny0/Trait/TraitMultiModule.dfy
@@ -0,0 +1,26 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+module M1
+{
+ trait T1
+ {
+ method M1 (a:int)
+ }
+ class C1 extends T1
+ {
+ method M1 (x:int)
+ {
+ var y: int := x;
+ }
+ }
+}
+
+module M2
+{
+ class C2 extends T1
+ {
+
+ }
+
+} \ No newline at end of file
diff --git a/Test/dafny0/Trait/TraitMultiModule.dfy.expect b/Test/dafny0/Trait/TraitMultiModule.dfy.expect
new file mode 100644
index 00000000..b9031dac
--- /dev/null
+++ b/Test/dafny0/Trait/TraitMultiModule.dfy.expect
@@ -0,0 +1,2 @@
+TraitMultiModule.dfy(21,20): Error: class M2.C2 is in a different module than trait M1.T1. A class may only extend a trait in the same module
+1 resolution/type errors detected in TraitMultiModule.dfy
diff --git a/Test/dafny0/Trait/TraitOverride0.dfy b/Test/dafny0/Trait/TraitOverride0.dfy
new file mode 100644
index 00000000..a8fb8596
--- /dev/null
+++ b/Test/dafny0/Trait/TraitOverride0.dfy
@@ -0,0 +1,81 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+trait T1
+{
+ var f: int;
+
+ function method Plus (x:int, y:int) : int
+ requires x>y;
+ {
+ x + y
+ }
+
+ function method Mul (x:int, y:int, z:int) : int
+ requires x>y;
+ {
+ x * y * z
+ }
+
+ function method BodyLess1() : int
+
+ function method BodyLess2(a:int, b:int) : int
+
+ static method GetPhoneNumber (code:int, n:int) returns (z:int)
+ {
+ z := code + n;
+ }
+
+ method TestPhone ()
+ {
+ var num : int;
+ num := GetPhoneNumber (10, 30028);
+ }
+}
+
+trait T2
+{
+}
+
+class C1 extends T1
+{
+ method P2(x:int, y:int) returns (z:int)
+ requires x>y;
+ {
+ z:= Plus(x,y) + Mul (x,y,1);
+ }
+
+ function method BodyLess1(i:int) : int //error, overriding function has too many parameters
+ {
+ 12
+ }
+
+ function method Mul (x:int, y:int, z:int) : int //error, can not override implemented methods
+ requires x>y;
+ {
+ x * y * z
+ }
+
+ function method BodyLess2(a:int, b:int) : int
+ {
+ a+b
+ }
+}
+
+class C2 extends T1
+{
+ //error, there are body-less methods in the parent trait that must be implemented
+}
+
+abstract module AM1
+{
+ trait T2
+ {
+ method Calc(i:int, j:int) returns (k:int)
+ }
+
+ class T2Client extends T2
+ {
+ method Calc(ii:int, jj:int) returns (kk:int)
+ }
+} \ No newline at end of file
diff --git a/Test/dafny0/Trait/TraitOverride0.dfy.expect b/Test/dafny0/Trait/TraitOverride0.dfy.expect
new file mode 100644
index 00000000..1e7bface
--- /dev/null
+++ b/Test/dafny0/Trait/TraitOverride0.dfy.expect
@@ -0,0 +1,5 @@
+TraitOverride0.dfy(53,20): Error: a class cannot override implemented functions
+TraitOverride0.dfy(48,20): Error: function 'BodyLess1' is declared with a different number of parameter (1 instead of 0) than the corresponding function in the module it overrides
+TraitOverride0.dfy(65,6): Error: class: C2 does not implement trait member: BodyLess1
+TraitOverride0.dfy(65,6): Error: class: C2 does not implement trait member: BodyLess2
+4 resolution/type errors detected in TraitOverride0.dfy
diff --git a/Test/dafny0/Trait/TraitOverride1.dfy b/Test/dafny0/Trait/TraitOverride1.dfy
new file mode 100644
index 00000000..90a25f53
--- /dev/null
+++ b/Test/dafny0/Trait/TraitOverride1.dfy
@@ -0,0 +1,194 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+//everything should work OK in this test file
+trait T1
+{
+ function method Plus (x:int, y:int) : int
+ requires x>y;
+ {
+ x + y
+ }
+
+ function method bb(x:int):int
+ requires x>10;
+
+ function method BodyLess1(a:int) : int
+ requires a > 0;
+
+ function method dd(a:int) : int
+
+ method Testing()
+}
+
+class C1 extends T1
+{
+ function method dd(x:int):int
+ {
+ 2
+ }
+
+ method Testing()
+ {
+ var x:int := 11;
+ x := bb(x);
+ }
+
+ function method bb(x:int):int
+ requires x >10;
+ {
+ x
+ }
+ function method BodyLess1(bda:int) : int
+ requires bda > (-10);
+ {
+ 2
+ }
+
+ method CallBodyLess(x:int)
+ requires x > (-10);
+ {
+ var k:int := BodyLess1(x);
+ assert (k==2);
+ }
+}
+
+trait T2
+{
+ function method F(x: int): int
+ requires x < 100;
+ ensures F(x) < 100;
+
+ method M(x: int) returns (y: int)
+ requires 0 <= x;
+ ensures x < y;
+}
+
+class C2 extends T2
+{
+ function method F(x: int): int
+ requires x < 100;
+ ensures F(x) < 100;
+ {
+ x
+ }
+
+ method M(x: int) returns (y: int)
+ requires -2000 <= x; // a more permissive precondition than in the interface
+ ensures 2*x < y; // a more detailed postcondition than in the interface
+ {
+ y := (2 * x) + 1;
+ }
+}
+
+
+trait T3
+{
+ function method F(y: int): int
+ function method G(y: int): int { 12 }
+ method M(y: int)
+ method N(y: int) {
+ var a:int := 100;
+ assert a==100;
+ }
+}
+class C3 extends T3
+{
+ function method NewFunc (a:int, b:int) : int
+ {
+ a + b
+ }
+ function method F(y: int): int { 20 }
+ method M(y: int) {
+ var a:int := 100;
+ assert a==100;
+ }
+}
+
+trait t
+{
+ function f(s2:int):int
+ ensures f(s2) > 0;
+ //requires s != null && s.Length > 1;
+ //reads s, s2;
+}
+
+class c extends t
+{
+ function f(s3:int):int
+ ensures f(s3) > 1;
+ //requires s0 != null && s0.Length > (0);
+ //reads s0;
+ {
+ 2
+ }
+}
+
+trait P1
+{
+ method M(N: int, a: array<int>) returns (sum: int)
+ {
+ sum := 1;
+ }
+}
+
+class CC1 extends P1
+{
+
+}
+
+trait TT
+{
+ static function method M(a:int, b:int) : int
+ ensures M(a,b) == a + b;
+ {
+ a + b
+ }
+}
+
+class CC extends TT
+{
+ method Testing(a:int,b:int)
+ {
+ assert (TT.M(a,b) == a + b);
+ }
+}
+
+
+trait T4
+{
+ function method F(y: int): int
+
+ function method G(y: int): int
+ {
+ 100
+ }
+
+ method M(y: int) returns (kobra:int)
+ requires y > 0;
+ ensures kobra > 0;
+
+ method N(y: int)
+ {
+ var x: int;
+ var y : int;
+ y := 10;
+ x := 1000;
+ y := y + x;
+ }
+}
+
+class C4 extends T4
+{
+ function method F(y: int): int
+ {
+ 200
+ }
+
+ method M(kk:int) returns (ksos:int)
+ requires kk > (-1);
+ ensures ksos > 0;
+ {
+ ksos:=10;
+ }
+}
diff --git a/Test/dafny0/Trait/TraitOverride1.dfy.expect b/Test/dafny0/Trait/TraitOverride1.dfy.expect
new file mode 100644
index 00000000..c90560b0
--- /dev/null
+++ b/Test/dafny0/Trait/TraitOverride1.dfy.expect
@@ -0,0 +1,2 @@
+
+Dafny program verifier finished with 52 verified, 0 errors
diff --git a/Test/dafny0/Trait/TraitPolymorphism.dfy b/Test/dafny0/Trait/TraitPolymorphism.dfy
new file mode 100644
index 00000000..b1ee9eea
--- /dev/null
+++ b/Test/dafny0/Trait/TraitPolymorphism.dfy
@@ -0,0 +1,65 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+trait T1
+{
+ var f: int;
+
+ function method Plus (x:int, y:int) : int
+ requires x>y;
+ {
+ x + y
+ }
+
+ function method Mul (x:int, y:int, z:int) : int
+ requires x>y;
+ {
+ x * y * z
+ }
+
+ //function method BodyLess1() : int
+
+ static method GetPhoneNumber (code:int, n:int) returns (z:int)
+ {
+ z := code + n;
+ }
+
+ method TestPhone ()
+ {
+ var num : int;
+ num := GetPhoneNumber (10, 30028);
+ }
+}
+
+trait T2
+{
+}
+
+class C1 extends T1
+{
+ method P2(x:int, y:int) returns (z:int)
+ requires x>y;
+ {
+ z:= Plus(x,y) + Mul (x,y,1);
+ }
+}
+
+
+
+method Good(c: C1) returns (t: T1)
+ensures c == t;
+{
+ t := c;
+}
+
+method Bad1(c: C1) returns (t: T2)
+ensures c == t;
+{
+ t := c; //error, C1 has not implemented T2
+}
+
+method Bad2(c: C1) returns (t: T1)
+ensures c == t;
+{
+ c := t; //error, can not assign a trait to a class
+}
diff --git a/Test/dafny0/Trait/TraitPolymorphism.dfy.expect b/Test/dafny0/Trait/TraitPolymorphism.dfy.expect
new file mode 100644
index 00000000..8c68b4b9
--- /dev/null
+++ b/Test/dafny0/Trait/TraitPolymorphism.dfy.expect
@@ -0,0 +1,4 @@
+TraitPolymorphism.dfy(56,10): Error: arguments must have the same type (got C1 and T2)
+TraitPolymorphism.dfy(58,6): Error: RHS (of type C1) not assignable to LHS (of type T2)
+TraitPolymorphism.dfy(64,4): Error: LHS of assignment must denote a mutable variable
+3 resolution/type errors detected in TraitPolymorphism.dfy
diff --git a/Test/dafny0/Trait/TraitSpecsOverride0.dfy b/Test/dafny0/Trait/TraitSpecsOverride0.dfy
new file mode 100644
index 00000000..614adc2d
--- /dev/null
+++ b/Test/dafny0/Trait/TraitSpecsOverride0.dfy
@@ -0,0 +1,59 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+
+trait J
+{
+ function method F(k:int, y: array<int>): int
+ reads y;
+ decreases k;
+
+ function method G(y: int): int
+ {
+ 100
+ }
+
+ method M(y: int) returns (kobra:int)
+ requires y > 0;
+ ensures kobra > 0;
+
+ method N(y: int)
+ {
+ var x: int;
+ var y : int;
+ y := 10;
+ x := 1000;
+ y := y + x;
+ }
+
+ method arrM (y: array<int>, x: int, a: int, b: int) returns (c: int)
+ requires a > b;
+ requires y != null && y.Length > 0;
+ ensures c == a + b;
+ modifies y;
+ decreases x;
+}
+
+class C extends J
+{
+ function method F(kk:int, yy: array<int>): int
+ {
+ 200
+ }
+
+ method M(kk:int) returns (ksos:int) //errors here, M must provide its own specifications
+ {
+ ksos:=10;
+ }
+
+ method arrM (y1: array<int>, x1: int, a1: int, b1: int) returns (c1: int)
+ requires a1 > b1;
+ requires y1 != null && y1.Length > 0;
+ ensures c1 == a1 + b1;
+ modifies y1;
+ decreases x1;
+ {
+ y1[0] := a1 + b1;
+ c1 := a1 + b1;
+ }
+} \ No newline at end of file
diff --git a/Test/dafny0/Trait/TraitSpecsOverride0.dfy.expect b/Test/dafny0/Trait/TraitSpecsOverride0.dfy.expect
new file mode 100644
index 00000000..750e13e0
--- /dev/null
+++ b/Test/dafny0/Trait/TraitSpecsOverride0.dfy.expect
@@ -0,0 +1,5 @@
+TraitSpecsOverride0.dfy(39,17): Error: Function must provide its own Reads clauses anew
+TraitSpecsOverride0.dfy(39,17): Error: Function must provide its own Decreases clauses anew
+TraitSpecsOverride0.dfy(44,8): Error: Method must provide its own Requires clauses anew
+TraitSpecsOverride0.dfy(44,8): Error: Method must provide its own Ensures clauses anew
+4 resolution/type errors detected in TraitSpecsOverride0.dfy
diff --git a/Test/dafny0/Trait/TraitUsingParentMembers.dfy b/Test/dafny0/Trait/TraitUsingParentMembers.dfy
new file mode 100644
index 00000000..dd45d0e6
--- /dev/null
+++ b/Test/dafny0/Trait/TraitUsingParentMembers.dfy
@@ -0,0 +1,44 @@
+// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+
+trait P1
+{
+ method N0() {
+ var a: array<int>;
+ if (a != null && 5 < a.Length) {
+ a[5] := 12; // error: violates modifies clause
+ }
+ }
+
+ method Mul(x: int, y: int) returns (r: int)
+ requires 0 <= x && 0 <= y;
+ ensures r == x*y;
+ decreases x;
+}
+
+class C1 extends P1
+{
+ method Mul(x: int, y: int) returns (r: int)
+ requires 0 <= x && 0 <= y;
+ ensures r == x*y;
+ decreases x;
+ {
+ if (x == 0) {
+ r := 0;
+ } else {
+ var m := Mul(x-1, y);
+ r := m + y;
+ }
+ }
+
+ method Testing(arr:array<int>)
+ requires arr != null && arr.Length == 2 && arr[0]== 1 && arr[1] == 10;
+ {
+ N0(); //calling parent trait methods
+ var x := 2;
+ var y := 5;
+ var z := Mul(x,y);
+ assert (z == 10);
+ }
+} \ No newline at end of file
diff --git a/Test/dafny0/Trait/TraitUsingParentMembers.dfy.expect b/Test/dafny0/Trait/TraitUsingParentMembers.dfy.expect
new file mode 100644
index 00000000..b59d7b80
--- /dev/null
+++ b/Test/dafny0/Trait/TraitUsingParentMembers.dfy.expect
@@ -0,0 +1,8 @@
+TraitUsingParentMembers.dfy(10,9): Error: assignment may update an array element not in the enclosing context's modifies clause
+Execution trace:
+ (0,0): anon0
+ (0,0): anon5_Then
+ (0,0): anon2
+ (0,0): anon6_Then
+
+Dafny program verifier finished with 7 verified, 1 error
diff --git a/Test/dafny0/TypeSynonyms.dfy b/Test/dafny0/TypeSynonyms.dfy
index 4bec5253..85beb340 100644
--- a/Test/dafny0/TypeSynonyms.dfy
+++ b/Test/dafny0/TypeSynonyms.dfy
@@ -44,3 +44,10 @@ function Skip(s: Synonym3): Synonym0
case Nil => Nil
case Cons(_, tail) => tail
}
+
+type MyMap = map<int, map<real, bool>>
+
+predicate MyMapProperty(m: MyMap, x: int)
+{
+ x in m && real(x) in m[x] && m[x][real(x)]
+}
diff --git a/Test/dafny0/TypeSynonyms.dfy.expect b/Test/dafny0/TypeSynonyms.dfy.expect
index 4ef2de53..76f19e0d 100644
--- a/Test/dafny0/TypeSynonyms.dfy.expect
+++ b/Test/dafny0/TypeSynonyms.dfy.expect
@@ -1,2 +1,2 @@
-Dafny program verifier finished with 6 verified, 0 errors
+Dafny program verifier finished with 7 verified, 0 errors
diff --git a/Test/dafny0/TypeTests.dfy.expect b/Test/dafny0/TypeTests.dfy.expect
index 62e41019..5d78fe16 100644
--- a/Test/dafny0/TypeTests.dfy.expect
+++ b/Test/dafny0/TypeTests.dfy.expect
@@ -25,8 +25,8 @@ TypeTests.dfy(106,3): Error: cannot assign to a range of array elements (try the
TypeTests.dfy(107,3): Error: cannot assign to a range of array elements (try the 'forall' statement)
TypeTests.dfy(113,6): Error: sorry, cannot instantiate collection type with a subrange type
TypeTests.dfy(114,9): Error: sorry, cannot instantiate type parameter with a subrange type
-TypeTests.dfy(115,8): Error: sorry, cannot instantiate 'array' type with a subrange type
-TypeTests.dfy(116,8): Error: sorry, cannot instantiate 'array' type with a subrange type
+TypeTests.dfy(115,8): Error: sorry, cannot instantiate type parameter with a subrange type
+TypeTests.dfy(116,8): Error: sorry, cannot instantiate type parameter with a subrange type
TypeTests.dfy(128,15): Error: ghost variables are allowed only in specification contexts
TypeTests.dfy(138,4): Error: cannot assign to non-ghost variable in a ghost context
TypeTests.dfy(139,7): Error: cannot assign to non-ghost variable in a ghost context
diff --git a/Test/dafny4/NumberRepresentations.dfy b/Test/dafny4/NumberRepresentations.dfy
index 3096616f..4269d24d 100644
--- a/Test/dafny4/NumberRepresentations.dfy
+++ b/Test/dafny4/NumberRepresentations.dfy
@@ -1,4 +1,4 @@
-// RUN: %dafny /compile:0 /dprint:"%t.dprint" /doNotUseParallelism "%s" > "%t"
+// RUN: %dafny /compile:0 /dprint:"%t.dprint" "%s" > "%t"
// RUN: %diff "%s.expect" "%t"
// We consider a number representation that consists of a sequence of digits. The least
diff --git a/Util/Emacs/dafny-mode.el b/Util/Emacs/dafny-mode.el
index 6c59c50a..d589fb78 100644
--- a/Util/Emacs/dafny-mode.el
+++ b/Util/Emacs/dafny-mode.el
@@ -31,6 +31,7 @@
`(,(dafny-regexp-opt '(
"class" "datatype" "codatatype" "type" "iterator"
+ "trait" "extends"
"function" "predicate" "copredicate"
"ghost" "var" "method" "lemma" "constructor" "colemma"
"abstract" "module" "import" "default" "as" "opened" "static" "refines"
diff --git a/Util/latex/dafny.sty b/Util/latex/dafny.sty
index 785cf6f1..40b994ba 100644
--- a/Util/latex/dafny.sty
+++ b/Util/latex/dafny.sty
@@ -5,7 +5,7 @@
\usepackage{listings}
\lstdefinelanguage{dafny}{
- morekeywords={class,datatype,codatatype,type,iterator,
+ morekeywords={class,datatype,codatatype,type,iterator,trait,extends,
bool,nat,int,real,object,set,multiset,seq,array,array2,array3,map,
function,predicate,copredicate,
ghost,var,static,refines,
diff --git a/Util/vim/dafny.vim b/Util/vim/dafny.vim
index c706ac5f..58820c0f 100644
--- a/Util/vim/dafny.vim
+++ b/Util/vim/dafny.vim
@@ -7,7 +7,7 @@ syntax clear
syntax case match
syntax keyword dafnyFunction function predicate copredicate
syntax keyword dafnyMethod method lemma constructor colemma
-syntax keyword dafnyTypeDef class datatype codatatype type iterator
+syntax keyword dafnyTypeDef class datatype codatatype type iterator trait extends
syntax keyword dafnyModule abstract module import opened as default
syntax keyword dafnyConditional if then else match case
syntax keyword dafnyRepeat while