예제 #1
0
파일: DocTree.cs 프로젝트: nhweston/dfy
 private ImportNode ToImportNode(AliasModuleDecl am)
 {
     Console.WriteLine("Import: " + am.Name);
     return(new ImportNode {
         Name = am.Name,
         Target = ToTokenNode(am.TargetQId.Root.tok),
         IsOpened = am.Opened,
         Token = ToTokenNode(am.tok),
     });
 }
예제 #2
0
 public override void Visit(AliasModuleDecl o)
 {
     CreateSymbol(
         name: o.Name,
         positionAsToken: o.tok,
         bodyStartPosAsToken: null,
         bodyEndPosAsToken: null,
         kind: Kind.Module,
         type: null,
         isDeclaration: true,
         addUsageAtDeclaration: false,
         canHaveChildren: false,
         canBeUsed: true
         );
 }
 public virtual void Visit(AliasModuleDecl aliasModuleDecl)
 {
 }
예제 #4
0
파일: Parser.cs 프로젝트: dbremner/dafny
        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;
            ModuleDecl sm;
            submodule = null; // appease compiler
            bool isAbstract = false;
            bool isExclusively = false;
            bool opened = false;

            if (la.kind == 61 || la.kind == 62) {
            if (la.kind == 61) {
                Get();
                isAbstract = true;
            }
            Expect(62);
            while (la.kind == 46) {
                Attribute(ref attrs);
            }
            NoUSIdent(out id);
            if (la.kind == 63 || la.kind == 64) {
                if (la.kind == 63) {
                    Get();
                    Expect(64);
                    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)) {
                switch (la.kind) {
                case 61: case 62: case 65: {
                    SubModuleDecl(module, out sm);
                    module.TopLevelDecls.Add(sm);
                    break;
                }
                case 70: {
                    ClassDecl(module, out c);
                    module.TopLevelDecls.Add(c);
                    break;
                }
                case 72: {
                    TraitDecl(module, out trait);
                    module.TopLevelDecls.Add(trait);
                    break;
                }
                case 76: case 77: {
                    DatatypeDecl(module, out dt);
                    module.TopLevelDecls.Add(dt);
                    break;
                }
                case 79: {
                    NewtypeDecl(module, out td);
                    module.TopLevelDecls.Add(td);
                    break;
                }
                case 80: {
                    OtherTypeDecl(module, out td);
                    module.TopLevelDecls.Add(td);
                    break;
                }
                case 81: {
                    IteratorDecl(module, out iter);
                    module.TopLevelDecls.Add(iter);
                    break;
                }
                case 38: case 39: case 40: case 41: case 42: case 73: case 74: case 75: case 78: case 84: case 85: case 86: case 87: {
                    ClassMemberDecl(namedModuleDefaultClassMembers, false, !DafnyOptions.O.AllowGlobals, DafnyOptions.O.IronDafny && isAbstract);
                    break;
                }
                }
            }
            Expect(47);
            module.BodyEndTok = t;
            module.TopLevelDecls.Add(new DefaultClassDecl(module, namedModuleDefaultClassMembers));
            submodule = new LiteralModuleDecl(module, parent);
            } else if (la.kind == 65) {
            Get();
            if (la.kind == 66) {
                Get();
                opened = true;
            }
            NoUSIdent(out id);
            if (la.kind == 67 || la.kind == 68) {
                if (la.kind == 67) {
                    Get();
                    QualifiedModuleName(out idPath);
                    submodule = new AliasModuleDecl(idPath, id, parent, opened);
                } else {
                    Get();
                    QualifiedModuleName(out idPath);
                    if (la.kind == 69) {
                        Get();
                        QualifiedModuleName(out idAssignment);
                    }
                    submodule = new ModuleFacadeDecl(idPath, id, parent, idAssignment, opened);
                }
            }
            if (la.kind == 28) {
                while (!(la.kind == 0 || la.kind == 28)) {SynErr(139); 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 SynErr(140);
        }
 public override void Visit(AliasModuleDecl o)
 {
 }
 public override void Leave(AliasModuleDecl o)
 {
 }
예제 #7
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
      }
    }
예제 #8
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);
	}
예제 #9
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);
        }