示例#1
0
文件: Printer.cs 项目: ggrov/tacny
 void PrintModuleExportDecl(ModuleExportDecl m, int indent, string fileBeingPrinted) {
   ModuleSignature sig = m.Signature;
   if (sig == null) {
     wr.Write(" {");
     // has been resolved yet, just print the strings
     wr.Write("{0}", Util.Comma(m.Exports, id => id.Name));
     wr.Write("}");
   } else {
     wr.WriteLine(" {");
     // print the decls and members in the module
     List<TopLevelDecl> decls = sig.TopLevels.Values.ToList();
     List<MemberDecl> members = sig.StaticMembers.Values.ToList();
     PrintTopLevelDecls(decls, indent + IndentAmount, fileBeingPrinted);
     PrintMembers(members, indent + IndentAmount, fileBeingPrinted);
     Indent(indent);  wr.WriteLine("}");
   }
 }
        private void MergeModuleExports(ModuleExportDecl nw, ModuleExportDecl d)
        {
            if (nw.IsDefault != d.IsDefault) {
            reporter.Error(MessageSource.RefinementTransformer, nw, "can't change if a module export is default ({0})", nw.Name);
              }

              nw.Exports.AddRange(d.Exports);
              nw.Extends.AddRange(d.Extends);
        }
示例#3
0
文件: Cloner.cs 项目: ggrov/tacny
    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
      }
    }
示例#4
0
文件: Parser.cs 项目: ggrov/tacny
	void SubModuleDecl(DeclModifierData dmod, ModuleDefinition parent, out ModuleDecl submodule) {
		Attributes attrs = null;  IToken/*!*/ id;
		List<MemberDecl/*!*/> namedModuleDefaultClassMembers = new List<MemberDecl>();;
		List<IToken> idRefined = null, idPath = null, idAssignment = null;
		ModuleDefinition module;
		submodule = null; // appease compiler
		bool isAbstract = dmod.IsAbstract;
		bool isExclusively = false;
		bool opened = false;
		CheckDeclModifiers(dmod, "Modules", AllowedDeclModifiers.Abstract | AllowedDeclModifiers.Extern);
		
		if (la.kind == 69) {
			Get();
			while (la.kind == 46) {
				Attribute(ref attrs);
			}
			NoUSIdent(out id);
			EncodeExternAsAttribute(dmod, ref attrs, id, /* needAxiom */ false); 
			if (la.kind == 70 || la.kind == 71) {
				if (la.kind == 70) {
					Get();
					Expect(71);
					QualifiedModuleName(out idRefined);
					isExclusively = true; 
				} else {
					Get();
					QualifiedModuleName(out idRefined);
					isExclusively = false; 
				}
			}
			module = new ModuleDefinition(id, id.val, isAbstract, false, isExclusively, idRefined == null ? null : idRefined, parent, attrs, false, this); 
			Expect(46);
			module.BodyStartTok = t; 
			while (StartOf(1)) {
				TopDecl(module, namedModuleDefaultClassMembers, /* isTopLevel */ false, isAbstract);
			}
			Expect(47);
			module.BodyEndTok = t;
			module.TopLevelDecls.Add(new DefaultClassDecl(module, namedModuleDefaultClassMembers));
			submodule = new LiteralModuleDecl(module, parent); 
		} else if (la.kind == 72) {
			Get();
			if (la.kind == 73) {
				Get();
				opened = true;
			}
			NoUSIdent(out id);
			EncodeExternAsAttribute(dmod, ref attrs, id, /* needAxiom */ false); 
			if (StartOf(3)) {
				if (la.kind == 74) {
					Get();
					QualifiedModuleName(out idPath);
					submodule = new AliasModuleDecl(idPath, id, parent, opened); 
				} else if (la.kind == 75) {
					Get();
					QualifiedModuleName(out idPath);
					if (IsDefaultImport()) {
						Expect(76);
						QualifiedModuleName(out idAssignment);
					}
					submodule = new ModuleFacadeDecl(idPath, id, parent, idAssignment, opened); 
					errors.Warning(t, "\"import A as B\" has been deprecated; in the new syntax, it is \"import A:B\"");
					
				} else if (la.kind == 21) {
					Get();
					QualifiedModuleName(out idPath);
					submodule = new ModuleFacadeDecl(idPath, id, parent, idAssignment, opened); 
				} else {
					Get();
					QualifiedModuleName(out idPath);
					idPath.Insert(0, id);
					submodule = new AliasModuleDecl(idPath, id, parent, opened); 
					
				}
			}
			if (la.kind == 28) {
				while (!(la.kind == 0 || la.kind == 28)) {SynErr(153); Get();}
				Get();
				errors.Warning(t, "the semi-colon that used to terminate a sub-module declaration has been deprecated; in the new syntax, just leave off the semi-colon"); 
			}
			if (submodule == null) {
			 idPath = new List<IToken>();
			 idPath.Add(id);
			 submodule = new AliasModuleDecl(idPath, id, parent, opened);
			}
			
		} else if (la.kind == 76 || la.kind == 77) {
			bool isDefault = false;
			bool includeBody;
			IToken exportId;
			List<ExportSignature> exports = new List<ExportSignature>();;
			List<string> extends = new List<string>(); 
			
			if (la.kind == 76) {
				Get();
				isDefault = true; 
			}
			Expect(77);
			NoUSIdent(out exportId);
			if (la.kind == 78) {
				Get();
				NoUSIdent(out id);
				extends.Add(id.val); 
				while (la.kind == 22) {
					Get();
					NoUSIdent(out id);
					extends.Add(id.val); 
				}
			}
			Expect(46);
			NoUSIdent(out id);
			includeBody = false; 
			if (la.kind == 79) {
				Get();
				includeBody = true; 
			}
			exports.Add(new ExportSignature(id, includeBody)); 
			while (la.kind == 22) {
				Get();
				NoUSIdent(out id);
				includeBody = false; 
				if (la.kind == 79) {
					Get();
					includeBody = true; 
				}
				exports.Add(new ExportSignature(id, includeBody)); 
			}
			Expect(47);
			submodule = new ModuleExportDecl(exportId, parent, isDefault, exports, extends);
			
		} else SynErr(154);
	}
示例#5
0
        void PrintModuleExportDecl(ModuleExportDecl m, int indent, string fileBeingPrinted)
        {
            ModuleSignature sig = m.Signature;
              // has been resolved yet, just print the strings
              string bodyKind = "";
              string opaque = "provides";
              string reveal = "reveals";
              string delimeter = " ";

              foreach (ExportSignature id in m.Exports) {
            delimeter = ",";

            if (id.Opaque && bodyKind != opaque) {
              bodyKind = opaque;
              wr.Write(" " + bodyKind);
              delimeter = " ";
            } else if (!id.Opaque && bodyKind != reveal) {
              bodyKind = reveal;
              wr.Write(" " + bodyKind);
              delimeter = " ";
            }
            wr.Write(delimeter + "{0}", id.ToString());
            if (id.Decl != null) {
              wr.WriteLine();
              Indent(indent + IndentAmount);
              wr.WriteLine("/*");
              if (id.Decl is TopLevelDecl) {
            PrintTopLevelDecls(new List<TopLevelDecl> { (TopLevelDecl)id.Decl }, indent + IndentAmount, fileBeingPrinted);
              } else if (id.Decl is MemberDecl) {
            PrintMembers(new List<MemberDecl> { (MemberDecl)id.Decl }, indent + IndentAmount, fileBeingPrinted);
              }

              Indent(indent + IndentAmount);
              wr.WriteLine("*/");
              Indent(indent + IndentAmount);
            }
              }
              wr.WriteLine();
        }
示例#6
0
        void SubModuleDecl(DeclModifierData dmod, ModuleDefinition parent, out ModuleDecl submodule)
        {
            Attributes attrs = null;  IToken/*!*/ id;
            List<MemberDecl/*!*/> namedModuleDefaultClassMembers = new List<MemberDecl>();;
            List<IToken> idPath, idExports;
            IToken idRefined = null;
            ModuleDefinition module;
            submodule = null; // appease compiler
            bool isAbstract = dmod.IsAbstract;
            bool isExclusively = false;
            bool isProtected = dmod.IsProtected;
            bool opened = false;
            CheckDeclModifiers(dmod, "Modules", AllowedDeclModifiers.Abstract | AllowedDeclModifiers.Extern | AllowedDeclModifiers.Protected);

            if (la.kind == 70) {
            Get();
            while (la.kind == 50) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            EncodeExternAsAttribute(dmod, ref attrs, id, /* needAxiom */ false);
            if (la.kind == 71) {
                Get();
                ModuleName(out idRefined);
                isExclusively = false;
            }
            module = new ModuleDefinition(id, id.val, isAbstract, isProtected, false, isExclusively, idRefined, parent, attrs, false); module.IsToBeVerified = theVerifyThisFile;
            Expect(50);
            module.BodyStartTok = t;
            while (StartOf(1)) {
                TopDecl(module, namedModuleDefaultClassMembers, /* isTopLevel */ false, isAbstract);
            }
            Expect(51);
            module.BodyEndTok = t;
            module.TopLevelDecls.Add(new DefaultClassDecl(module, namedModuleDefaultClassMembers));
            submodule = new LiteralModuleDecl(module, parent);
            } else if (la.kind == 72) {
            Get();
            if (la.kind == 73) {
                Get();
                opened = true;
            }
            ModuleName(out id);
            EncodeExternAsAttribute(dmod, ref attrs, id, /* needAxiom */ false);
            if (StartOf(3)) {
                idPath = new List<IToken>(); idExports = new List<IToken>();
                if (la.kind == 28 || la.kind == 29) {
                    QualifiedModuleExportSuffix(idPath, idExports);
                }
                if (idPath.Count > 0)
                 SemErr(idPath[0], "Qualified imports must be given a name.");
                idPath.Insert(0, id);
                submodule = new AliasModuleDecl(idPath, id, parent, opened, idExports);

            } else if (la.kind == 74) {
                Get();
                QualifiedModuleExport(out idPath, out idExports);
                submodule = new AliasModuleDecl(idPath, id, parent, opened, idExports);
            } else if (la.kind == 22) {
                Get();
                QualifiedModuleExport(out idPath, out idExports);
                submodule = new ModuleFacadeDecl(idPath, id, parent, opened, idExports);
            } else SynErr(150);
            if (la.kind == 30) {
                while (!(la.kind == 0 || la.kind == 30)) {SynErr(151); Get();}
                Get();
                errors.Deprecated(t, "the semi-colon that used to terminate a sub-module declaration has been deprecated; in the new syntax, just leave off the semi-colon");
            }
            } else if (la.kind == 75) {
            IToken exportId;
            List<ExportSignature> exports = new List<ExportSignature>();;
              List<string> extends = new List<string>();
              bool provideAll = false;
              bool revealAll = false;
              bool isDefault = false;
              ExportSignature exsig;

            Get();
            exportId = t;
            if (StartOf(4)) {
                ModuleExport(out exportId);
            }
            while (la.kind == 76 || la.kind == 77 || la.kind == 78) {
                if (la.kind == 76) {
                    Get();
                    if (la.kind == 1) {
                        ModuleExportSignature(true, out exsig);
                        exports.Add(exsig);
                        while (la.kind == 23) {
                            Get();
                            ModuleExportSignature(true, out exsig);
                            exports.Add(exsig);
                        }
                    } else if (la.kind == 61) {
                        Get();
                        provideAll = true;
                    } else SynErr(152);
                } else if (la.kind == 77) {
                    Get();
                    if (la.kind == 1) {
                        ModuleExportSignature(false, out exsig);
                        exports.Add(exsig);
                        while (la.kind == 23) {
                            Get();
                            ModuleExportSignature(false, out exsig);
                            exports.Add(exsig);
                        }
                    } else if (la.kind == 61) {
                        Get();
                        revealAll = true;
                    } else SynErr(153);
                } else {
                    Get();
                    ModuleExport(out id);
                    extends.Add(id.val);
                    while (la.kind == 23) {
                        Get();
                        ModuleExport(out id);
                        extends.Add(id.val);
                    }
                }
            }
            if (exportId.val == "export" || exportId.val == parent.Name) {
             isDefault = true;
            }
            submodule = new ModuleExportDecl(exportId, parent, exports, extends, provideAll, revealAll, isDefault);

            } else SynErr(154);
        }