void case_21() #line 118 "Parser.jay" { yyVal = TopLevelDecl.NewFunctionDecl(new FunctionDeclData( (string)yyVals[-2 + yyTop], (FunctionSignature)yyVals[-1 + yyTop], FSharpOption <BlockData> .Some((BlockData)yyVals[0 + yyTop]))); }
private void Visit(TopLevelDecl d) { if (d is LiteralModuleDecl moduleDecl) { Visit(moduleDecl); } else if (d is ClassDecl classDecl) { Visit(classDecl); } }
public virtual void Visit(TopLevelDecl topLevelDeclaration) { switch (topLevelDeclaration) { case ClassDecl classDeclaration: Visit(classDeclaration); break; case ModuleDecl moduleDeclaration: case DatatypeDecl dataTypeDeclaration: case ValuetypeDecl valueTypeDeclaration: case OpaqueTypeDecl opaqueTypeDeclaration: case NewtypeDecl newTypeDeclaration: case TypeSynonymDecl typeSynonymDeclaration: default: VisitUnknown(topLevelDeclaration, topLevelDeclaration.tok); break; } }
private Symbol?ProcessTopLevelDeclaration(ModuleSymbol moduleSymbol, TopLevelDecl topLevelDeclaration) { _cancellationToken.ThrowIfCancellationRequested(); switch (topLevelDeclaration) { case ClassDecl classDeclaration: return(ProcessClass(moduleSymbol, classDeclaration)); case LiteralModuleDecl literalModuleDeclaration: return(ProcessModule(moduleSymbol, literalModuleDeclaration.ModuleDef)); case ValuetypeDecl valueTypeDeclaration: return(ProcessValueType(moduleSymbol, valueTypeDeclaration)); default: _logger.LogWarning("encountered unknown top level declaration {} of type {}", topLevelDeclaration.Name, topLevelDeclaration.GetType()); return(null); } }
private Symbol?ProcessTopLevelDeclaration(ModuleSymbol moduleSymbol, TopLevelDecl topLevelDeclaration) { switch (topLevelDeclaration) { case ClassDecl classDeclaration: return(ProcessClass(moduleSymbol, classDeclaration)); case LiteralModuleDecl literalModuleDeclaration: return(ProcessModule(moduleSymbol, literalModuleDeclaration.ModuleDef)); case ValuetypeDecl valueTypeDeclaration: return(ProcessValueType(moduleSymbol, valueTypeDeclaration)); case DatatypeDecl dataTypeDeclaration: return(ProcessDataType(moduleSymbol, dataTypeDeclaration)); default: logger.LogDebug("encountered unknown top level declaration {Name} of type {Type}", topLevelDeclaration.Name, topLevelDeclaration.GetType()); return(null); } }
public void AddTopLevelDecl(TopLevelDecl d) { module.ArmadaTranslation.TopLevelDecls.Add(d); }
void CompileTypeLevelDecl(TopLevelDecl d, TextWriter wr) { Contract.Requires(d != null); bool compileIt = true; if (Attributes.ContainsBool(d.Attributes, "compile", ref compileIt) && !compileIt) { return; } if (d is OpaqueTypeDecl) { var at = (OpaqueTypeDecl)d; WriteToken(d.tok); Error("Opaque type ('{0}') cannot be compiled", wr, at.FullName); } else if (d is TypeSynonymDecl) { // do nothing, just bypass type synonyms in the compiler } else if (d is NewtypeDecl) { var nt = (NewtypeDecl)d; WriteToken(d.tok); if (nt.CompileName == "uint64" || nt.CompileName == "uint32" || nt.CompileName == "byte") { // Skip SHA256 types.s.dfy definitions of native types. They are unused, but // are defined in terms of BigInteger, which Kremlin does not support. j.WriteComment("Allowing types.s.dfy definition of " + nt.CompileName); } using (WriteArray()) { j.WriteValue(KremlinAst.DTypeAlias); using (WriteArray()) { // (lident * int * typ) WriteLident(nt.FullName); j.WriteValue(0); // number of parameters (De Bruijn) WriteTypeName(nt.BaseType); } } } else if (d is DatatypeDecl) { var dt = (DatatypeDecl)d; WriteToken(d.tok); if (dt.TypeArgs.Count != 0) { // system.tuple2<> in sha256 is an example, but unused. j.WriteComment("WARNING: DatatypeDecl of parameterized type not supported"); // bugbug: implement. } else { // Define the type if (!CompileDatatypeStruct(dt)) { // Generate constructor functions for that type, if it is a struct rather than an enum CompileDatatypeConstructors(dt); } } } else if (d is IteratorDecl) { var iter = (IteratorDecl)d; WriteToken(d.tok); j.WriteComment("BUGBUG IteratorDecl ignored: " + iter.CompileName); // bugbug: implement } else if (d is TraitDecl) { var trait = (TraitDecl)d; WriteToken(d.tok); j.WriteComment("BUGBUG TraitDecl ignored: " + trait.CompileName); // bugbug: implement } else if (d is ClassDecl) { var cl = (ClassDecl)d; CompileClassMembers(cl); } else if (d is ModuleDecl) { // nop } else { Contract.Assert(false); } }
void SortTopLevelDeclsWorker(TopLevelDecl tld, Declaration d, List<Type> referencedTypes, List<TopLevelDecl> topLevelTypes) { if (d is NewtypeDecl) { var nt = (NewtypeDecl)d; referencedTypes.Add(nt.BaseType); if (tld != null) { topLevelTypes.Add(tld); } } else if (d is DatatypeDecl) { var dt = (DatatypeDecl)d; foreach (var ctor in dt.Ctors) { foreach (Formal arg in ctor.Formals) { if (!arg.IsGhost) { referencedTypes.Add(arg.Type); } } } if (tld != null) { topLevelTypes.Add(tld); } } else if (d is ClassDecl) { var c = (ClassDecl)d; foreach (var cd in c.InheritedMembers) { if (!cd.IsGhost) { SortTopLevelDeclsWorker(null, cd, referencedTypes, topLevelTypes); } } foreach (MemberDecl member in c.Members) { if (!member.IsGhost) { SortTopLevelDeclsWorker(null, member, referencedTypes, topLevelTypes); } } if (tld != null) { topLevelTypes.Add(tld); } } else if (d is MemberDecl) { var m = (MemberDecl)d; if (m is Field) { var f = (Field)m; referencedTypes.Add(f.Type); } else if (m is Function) { var f = (Function)m; foreach (Formal p in f.Formals) { referencedTypes.Add(p.Type); } referencedTypes.Add(f.ResultType); } else if (m is Method) { var meth = (Method)m; foreach (Formal p in meth.Ins) { if (!p.IsGhost) { referencedTypes.Add(p.Type); } } foreach (Formal p in meth.Outs) { if (!p.IsGhost) { referencedTypes.Add(p.Type); } } } } }
void OtherTypeDecl(ModuleDefinition module, out TopLevelDecl td) { IToken id; Attributes attrs = null; var eqSupport = TypeParameter.EqualitySupportValue.Unspecified; var typeArgs = new List<TypeParameter>(); td = null; Type ty; Expect(80); while (la.kind == 46) { Attribute(ref attrs); } NoUSIdent(out id); if (la.kind == 50) { Get(); Expect(54); Expect(51); eqSupport = TypeParameter.EqualitySupportValue.Required; if (la.kind == 52) { GenericParameters(typeArgs); } } else if (StartOf(4)) { if (la.kind == 52) { GenericParameters(typeArgs); } if (la.kind == 67) { Get(); Type(out ty); td = new TypeSynonymDecl(id, id.val, typeArgs, module, ty, attrs); } } else SynErr(146); if (td == null) { td = new OpaqueTypeDecl(id, id.val, module, eqSupport, typeArgs, attrs); } if (la.kind == 28) { while (!(la.kind == 0 || la.kind == 28)) {SynErr(147); Get();} Get(); errors.Warning(t, "the semi-colon that used to terminate an opaque-type declaration has been deprecated; in the new syntax, just leave off the semi-colon"); } }
void NewtypeDecl(ModuleDefinition module, out TopLevelDecl td) { IToken id, bvId; Attributes attrs = null; td = null; Type baseType = null; Expression wh; Expect(79); while (la.kind == 46) { Attribute(ref attrs); } NoUSIdent(out id); Expect(67); if (IsIdentColonOrBar()) { NoUSIdent(out bvId); if (la.kind == 21) { Get(); Type(out baseType); } if (baseType == null) { baseType = new OperationTypeProxy(true, true, false, false, false, false); } Expect(23); Expression(out wh, false, true); td = new NewtypeDecl(theVerifyThisFile ? id : new IncludeToken(id), id.val, module, new BoundVar(bvId, bvId.val, baseType), wh, attrs); } else if (StartOf(3)) { Type(out baseType); td = new NewtypeDecl(theVerifyThisFile ? id : new IncludeToken(id), id.val, module, baseType, attrs); } else SynErr(145); }
void OtherTypeDecl(DeclModifierData dmod, ModuleDefinition module, out TopLevelDecl td) { IToken id, bvId; Attributes attrs = null; var eqSupport = TypeParameter.EqualitySupportValue.Unspecified; var typeArgs = new List<TypeParameter>(); td = null; Type ty = null; Expression constraint; var kind = "Opaque type"; Expect(85); while (la.kind == 50) { Attribute(ref attrs); } NoUSIdent(out id); if (la.kind == 54) { Get(); Expect(58); Expect(55); eqSupport = TypeParameter.EqualitySupportValue.Required; if (la.kind == 56) { GenericParameters(typeArgs); } } else if (StartOf(7)) { if (la.kind == 56) { GenericParameters(typeArgs); } if (la.kind == 74) { Get(); if (IsIdentColonOrBar()) { NoUSIdent(out bvId); if (la.kind == 22) { Get(); Type(out ty); } if (ty == null) { ty = new InferredTypeProxy(); } Expect(24); Expression(out constraint, false, true); td = new SubsetTypeDecl(id, id.val, typeArgs, module, new BoundVar(bvId, bvId.val, ty), constraint, attrs); kind = "Subset type"; } else if (StartOf(6)) { Type(out ty); td = new TypeSynonymDecl(id, id.val, typeArgs, module, ty, attrs); kind = "Type synonym"; } else SynErr(160); } } else SynErr(161); if (td == null) { td = new OpaqueTypeDecl(id, id.val, module, eqSupport, typeArgs, attrs); } CheckDeclModifiers(dmod, kind, AllowedDeclModifiers.None); if (la.kind == 30) { while (!(la.kind == 0 || la.kind == 30)) {SynErr(162); Get();} Get(); errors.Deprecated(t, "the semi-colon that used to terminate an opaque-type declaration has been deprecated; in the new syntax, just leave off the semi-colon"); } }
public void AddTopLevelDecl(TopLevelDecl d, string auxName = null) { proofFiles.AddTopLevelDecl(d, auxName); }
public override TopLevelDecl CloneDeclaration(TopLevelDecl d, ModuleDefinition m) { var dd = base.CloneDeclaration(d, m); if (dd is ModuleExportDecl) { ((ModuleExportDecl)dd).SetupDefaultSignature(); } else if (d is ModuleDecl) { ((ModuleDecl)dd).Signature = ((ModuleDecl)d).Signature; if (d is ModuleFacadeDecl) { ((ModuleFacadeDecl)dd).OriginalSignature = ((ModuleFacadeDecl)d).OriginalSignature; } } return dd; }
private void MergeTopLevelDecls(ModuleDefinition m, TopLevelDecl nw, TopLevelDecl d, int index) { if (d is ModuleDecl) { if (!(nw is ModuleDecl)) { reporter.Error(MessageSource.RefinementTransformer, nw, "a module ({0}) must refine another module", nw.Name); } else if (d is ModuleExportDecl) { if (!(nw is ModuleExportDecl)) { reporter.Error(MessageSource.RefinementTransformer, nw, "a module export ({0}) must refine another export", nw.Name); } else { MergeModuleExports((ModuleExportDecl)nw,(ModuleExportDecl)d); } } else if (!(d is ModuleFacadeDecl)) { reporter.Error(MessageSource.RefinementTransformer, nw, "a module ({0}) can only refine a module facade", nw.Name); } else { // check that the new module refines the previous declaration if (!CheckIsRefinement((ModuleDecl)nw, (ModuleFacadeDecl)d)) reporter.Error(MessageSource.RefinementTransformer, nw.tok, "a module ({0}) can only be replaced by a refinement of the original module", d.Name); } } else if (d is OpaqueTypeDecl) { if (nw is ModuleDecl) { reporter.Error(MessageSource.RefinementTransformer, nw, "a module ({0}) must refine another module", nw.Name); } else { bool dDemandsEqualitySupport = ((OpaqueTypeDecl)d).MustSupportEquality; if (nw is OpaqueTypeDecl) { if (dDemandsEqualitySupport != ((OpaqueTypeDecl)nw).MustSupportEquality) { reporter.Error(MessageSource.RefinementTransformer, nw, "type declaration '{0}' is not allowed to change the requirement of supporting equality", nw.Name); } if (nw.TypeArgs.Count != d.TypeArgs.Count) { reporter.Error(MessageSource.RefinementTransformer, nw, "type '{0}' is not allowed to change its number of type parameters (got {1}, expected {2})", nw.Name, nw.TypeArgs.Count, d.TypeArgs.Count); } } else if (dDemandsEqualitySupport) { if (nw is ClassDecl) { // fine, as long as "nw" takes the right number of type parameters if (nw.TypeArgs.Count != d.TypeArgs.Count) { reporter.Error(MessageSource.RefinementTransformer, nw, "opaque type '{0}' is not allowed to be replaced by a class that takes a different number of type parameters (got {1}, expected {2})", nw.Name, nw.TypeArgs.Count, d.TypeArgs.Count); } } else if (nw is NewtypeDecl) { // fine, as long as "nw" does not take any type parameters if (nw.TypeArgs.Count != 0) { reporter.Error(MessageSource.RefinementTransformer, nw, "opaque type '{0}', which has {1} type argument{2}, is not allowed to be replaced by a newtype, which takes none", nw.Name, d.TypeArgs.Count, d.TypeArgs.Count == 1 ? "" : "s"); } } else if (nw is CoDatatypeDecl) { reporter.Error(MessageSource.RefinementTransformer, nw, "a type declaration that requires equality support cannot be replaced by a codatatype"); } else { Contract.Assert(nw is IndDatatypeDecl || nw is TypeSynonymDecl); if (nw.TypeArgs.Count != d.TypeArgs.Count) { reporter.Error(MessageSource.RefinementTransformer, nw, "opaque type '{0}' is not allowed to be replaced by a type that takes a different number of type parameters (got {1}, expected {2})", nw.Name, nw.TypeArgs.Count, d.TypeArgs.Count); } else { // Here, we need to figure out if the new type supports equality. But we won't know about that until resolution has // taken place, so we defer it until the PostResolve phase. var udt = UserDefinedType.FromTopLevelDecl(nw.tok, nw); postTasks.Enqueue(() => { if (!udt.SupportsEquality) { reporter.Error(MessageSource.RefinementTransformer, udt.tok, "type '{0}' is used to refine an opaque type with equality support, but '{0}' does not support equality", udt.Name); } }); } } } else if (d.TypeArgs.Count != nw.TypeArgs.Count) { reporter.Error(MessageSource.RefinementTransformer, nw, "opaque type '{0}' is not allowed to be replaced by a type that takes a different number of type parameters (got {1}, expected {2})", nw.Name, nw.TypeArgs.Count, d.TypeArgs.Count); } } } else if (nw is OpaqueTypeDecl) { reporter.Error(MessageSource.RefinementTransformer, nw, "an opaque type declaration ({0}) in a refining module cannot replace a more specific type declaration in the refinement base", nw.Name); } else if (nw is DatatypeDecl) { reporter.Error(MessageSource.RefinementTransformer, nw, "a datatype declaration ({0}) in a refinement module can only replace an opaque type declaration", nw.Name); } else if (nw is IteratorDecl) { if (d is IteratorDecl) { m.TopLevelDecls[index] = MergeIterator((IteratorDecl)nw, (IteratorDecl)d); } else { reporter.Error(MessageSource.RefinementTransformer, nw, "an iterator declaration ({0}) is a refining module cannot replace a different kind of declaration in the refinement base", nw.Name); } } else { Contract.Assert(nw is ClassDecl); if (d is DatatypeDecl) { reporter.Error(MessageSource.RefinementTransformer, nw, "a class declaration ({0}) in a refining module cannot replace a different kind of declaration in the refinement base", nw.Name); } else { m.TopLevelDecls[index] = MergeClass((ClassDecl)nw, (ClassDecl)d); } } }
public TopLevelDecl CloneDeclaration(TopLevelDecl d, ModuleDefinition m) { Contract.Requires(d != null); Contract.Requires(m != null); if (d is OpaqueTypeDecl) { var dd = (OpaqueTypeDecl)d; return new OpaqueTypeDecl(Tok(dd.tok), dd.Name, m, dd.EqualitySupport, dd.TypeArgs.ConvertAll(CloneTypeParam), CloneAttributes(dd.Attributes), d); } else if (d is TypeSynonymDecl) { var dd = (TypeSynonymDecl)d; var tps = dd.TypeArgs.ConvertAll(CloneTypeParam); return new TypeSynonymDecl(Tok(dd.tok), dd.Name, tps, m, CloneType(dd.Rhs), CloneAttributes(dd.Attributes), dd); } else if (d is NewtypeDecl) { var dd = (NewtypeDecl)d; if (dd.Var == null) { return new NewtypeDecl(Tok(dd.tok), dd.Name, m, CloneType(dd.BaseType), CloneAttributes(dd.Attributes), dd); } else { return new NewtypeDecl(Tok(dd.tok), dd.Name, m, CloneBoundVar(dd.Var), CloneExpr(dd.Constraint), CloneAttributes(dd.Attributes), dd); } } else if (d is TupleTypeDecl) { var dd = (TupleTypeDecl)d; return new TupleTypeDecl(dd.Dims, dd.Module); } else if (d is IndDatatypeDecl) { var dd = (IndDatatypeDecl)d; var tps = dd.TypeArgs.ConvertAll(CloneTypeParam); var ctors = dd.Ctors.ConvertAll(CloneCtor); var dt = new IndDatatypeDecl(Tok(dd.tok), dd.Name, m, tps, ctors, CloneAttributes(dd.Attributes), dd); return dt; } else if (d is CoDatatypeDecl) { var dd = (CoDatatypeDecl)d; var tps = dd.TypeArgs.ConvertAll(CloneTypeParam); var ctors = dd.Ctors.ConvertAll(CloneCtor); var dt = new CoDatatypeDecl(Tok(dd.tok), dd.Name, m, tps, ctors, CloneAttributes(dd.Attributes), dd); return dt; } else if (d is IteratorDecl) { var dd = (IteratorDecl)d; var tps = dd.TypeArgs.ConvertAll(CloneTypeParam); var ins = dd.Ins.ConvertAll(CloneFormal); var outs = dd.Outs.ConvertAll(CloneFormal); var reads = CloneSpecFrameExpr(dd.Reads); var mod = CloneSpecFrameExpr(dd.Modifies); var decr = CloneSpecExpr(dd.Decreases); var req = dd.Requires.ConvertAll(CloneMayBeFreeExpr); var yreq = dd.YieldRequires.ConvertAll(CloneMayBeFreeExpr); var ens = dd.Ensures.ConvertAll(CloneMayBeFreeExpr); var yens = dd.YieldEnsures.ConvertAll(CloneMayBeFreeExpr); var body = CloneBlockStmt(dd.Body); var iter = new IteratorDecl(Tok(dd.tok), dd.Name, dd.Module, tps, ins, outs, reads, mod, decr, req, ens, yreq, yens, body, CloneAttributes(dd.Attributes), dd.SignatureEllipsis); return iter; } 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), dd); 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, ((DefaultClassDecl)d)); } else { return new ClassDecl(Tok(dd.tok), dd.Name, m, tps, mm, CloneAttributes(dd.Attributes), dd.TraitsTyp.ConvertAll(CloneType), dd); } } else if (d is ModuleDecl) { if (d is LiteralModuleDecl) { var l = new LiteralModuleDecl(((LiteralModuleDecl)d).ModuleDef, m); l.Signature = ((ModuleDecl)d).Signature; return l; } else if (d is AliasModuleDecl) { var a = (AliasModuleDecl)d; var alias = new AliasModuleDecl(a.Path, a.tok, m, a.Opened); alias.Signature = a.Signature; return alias; } else if (d is ModuleFacadeDecl) { var a = (ModuleFacadeDecl)d; var abs = new ModuleFacadeDecl(a.Path, a.tok, m, a.CompilePath, a.Opened); abs.Signature = a.Signature; abs.OriginalSignature = a.OriginalSignature; return abs; } else if (d is ModuleExportDecl) { var a = (ModuleExportDecl)d; var export = new ModuleExportDecl(a.tok, m, a.IsDefault, a.Exports, a.Extends); export.Signature = a.Signature; return export; } else { Contract.Assert(false); // unexpected declaration return null; // to please compiler } } else { Contract.Assert(false); // unexpected declaration return null; // to please compiler } }
public void AddTopLevelDecl(TopLevelDecl d, string auxName = null) { LookupFile(auxName).AddTopLevelDecl(d); }
public void AddTopLevelDecl(TopLevelDecl d) { newTopLevelDecls.Add(d); }
void NewtypeDecl(DeclModifierData dmod, ModuleDefinition module, out TopLevelDecl td) { IToken id, bvId; Attributes attrs = null; td = null; Type baseType = null; Expression wh; CheckDeclModifiers(dmod, "Newtypes", AllowedDeclModifiers.None); Expect(84); while (la.kind == 50) { Attribute(ref attrs); } NoUSIdent(out id); Expect(74); if (IsIdentColonOrBar()) { NoUSIdent(out bvId); if (la.kind == 22) { Get(); Type(out baseType); } if (baseType == null) { baseType = new InferredTypeProxy(); } Expect(24); Expression(out wh, false, true); td = new NewtypeDecl(theVerifyThisFile ? id : new IncludeToken(id), id.val, module, new BoundVar(bvId, bvId.val, baseType), wh, attrs); } else if (StartOf(6)) { Type(out baseType); td = new NewtypeDecl(theVerifyThisFile ? id : new IncludeToken(id), id.val, module, baseType, attrs); } else SynErr(159); }