コード例 #1
0
 public ProofGenerationParams(Program i_prog, ModuleDefinition i_mProof, LiteralModuleDecl i_mLow, LiteralModuleDecl i_mHigh)
 {
     prog          = i_prog;
     proofFiles    = new ProofFileCollection(i_prog, i_mProof);
     mLow          = i_mLow;
     mHigh         = i_mHigh;
     symbolsLow    = mLow.ModuleDef.ArmadaSymbols;
     symbolsHigh   = mHigh.ModuleDef.ArmadaSymbols;
     originalsLow  = symbolsLow.DefaultClass;
     originalsHigh = symbolsHigh.DefaultClass;
     extraMaterial = new Dictionary <string, string>();
 }
コード例 #2
0
ファイル: DafnyInfo.cs プロジェクト: mschlaipfer/dafny
 private void Visit(LiteralModuleDecl d)
 {
     if (d.Name.Equals("_module"))
     {
         d.ModuleDef.TopLevelDecls.ForEach(Visit);
         return;
     }
     path.Add(d.Name);
     info.ToImport.Add(string.Join(".", path));
     d.ModuleDef.TopLevelDecls.ForEach(Visit);
     path.RemoveAt(path.Count - 1);
 }
コード例 #3
0
        public static string Parse(IList <DafnyFile> files, string programName, ErrorReporter reporter, out Program program)
        {
            Contract.Requires(programName != null);
            Contract.Requires(files != null);
            program = null;

            ModuleDecl module = new LiteralModuleDecl(new DefaultModuleDecl(), null);

            BuiltIns builtIns = new BuiltIns();

            foreach (DafnyFile dafnyFile in files)
            {
                Contract.Assert(dafnyFile != null);
                if (Bpl.CommandLineOptions.Clo.XmlSink != null && Bpl.CommandLineOptions.Clo.XmlSink.IsOpen)
                {
                    Bpl.CommandLineOptions.Clo.XmlSink.WriteFileFragment(dafnyFile.FilePath);
                }
                if (Bpl.CommandLineOptions.Clo.Trace)
                {
                    Console.WriteLine("Parsing " + dafnyFile.FilePath);
                }

                string err = ParseFile(dafnyFile, null, module, builtIns, new Errors(reporter));
                if (err != null)
                {
                    return(err);
                }
            }

            if (!(DafnyOptions.O.DisallowIncludes || DafnyOptions.O.PrintIncludesMode == DafnyOptions.IncludesModes.Immediate))
            {
                string errString = ParseIncludes(module, builtIns, DafnyFile.fileNames(files), new Errors(reporter));
                if (errString != null)
                {
                    return(errString);
                }
            }

            if (DafnyOptions.O.PrintIncludesMode == DafnyOptions.IncludesModes.Immediate)
            {
                DependencyMap dmap = new DependencyMap();
                dmap.AddIncludes(((LiteralModuleDecl)module).ModuleDef.Includes);
                dmap.PrintMap();
            }

            program = new Program(programName, module, builtIns, reporter);

            MaybePrintProgram(program, DafnyOptions.O.DafnyPrintFile, false);

            return(null); // success
        }
コード例 #4
0
ファイル: DareMain.cs プロジェクト: minill/shorty
        private static Program CreateProgramFromFileName(string fileName)
        {
            var nameStart   = fileName.LastIndexOf('\\') + 1;
            var programName = fileName.Substring(nameStart, fileName.Length - nameStart);

            ModuleDecl module   = new LiteralModuleDecl(new DefaultModuleDecl(), null);
            var        builtIns = new BuiltIns();

            Parser.Parse(fileName, module, builtIns, new Errors(Reporter));

            var program = new Program(programName, module, builtIns, Reporter);

            return(program);
        }
コード例 #5
0
        /// <summary>
        /// Invokes Dafny parser on the physical file provided to this instance.
        /// This will find lexer errors.
        /// </summary>
        private bool Parse()
        {
            ModuleDecl module   = new LiteralModuleDecl(new Microsoft.Dafny.DefaultModuleDecl(), null);
            BuiltIns   builtIns = new BuiltIns();
            var        success  = Microsoft.Dafny.Parser.Parse(_file.Sourcecode, _file.Filepath, _file.Filepath, null, module, builtIns, new Microsoft.Dafny.Errors(_reporter)) == 0 &&
                                  Microsoft.Dafny.Main.ParseIncludes(module, builtIns, new List <string>(), new Microsoft.Dafny.Errors(_reporter)) == null;

            if (success)
            {
                _dafnyProgram = new Microsoft.Dafny.Program(_file.Filepath, module, builtIns, _reporter);
                _status       = TranslationStatus.Parsed;
            }
            return(success);
        }
コード例 #6
0
        /// <summary>
        /// Returns null on success, or an error string otherwise.
        /// </summary>
        public string ParseCheck(IList <string /*!*/> /*!*/ fileNames, string /*!*/ programName, out Microsoft.Dafny.Program program)
        //modifies Bpl.CommandLineOptions.Clo.XmlSink.*;
        {
            //Debug.WriteLine("ACTION: Parsing Dafny program");
            Contract.Requires(programName != null);
            Contract.Requires(fileNames != null);
            program = null;
            ModuleDecl module   = new LiteralModuleDecl(new DefaultModuleDecl(), null);
            BuiltIns   builtIns = new BuiltIns();

            foreach (string dafnyFileName in fileNames)
            {
                Contract.Assert(dafnyFileName != null);
                if (Bpl.CommandLineOptions.Clo.XmlSink != null && Bpl.CommandLineOptions.Clo.XmlSink.IsOpen)
                {
                    Bpl.CommandLineOptions.Clo.XmlSink.WriteFileFragment(dafnyFileName);
                }
                if (Bpl.CommandLineOptions.Clo.Trace)
                {
                    Console.WriteLine("Parsing " + dafnyFileName);
                }

                string err = ParseFile(dafnyFileName, Bpl.Token.NoToken, module, builtIns, new Errors(new ConsoleErrorReporter()));
                if (err != null)
                {
                    return(err);
                }
            }

            if (!DafnyOptions.O.DisallowIncludes)
            {
                string errString = ParseIncludes(module, builtIns, fileNames, new Errors(new ConsoleErrorReporter()));
                if (errString != null)
                {
                    return(errString);
                }
            }

            program = new Microsoft.Dafny.Program(programName, module, builtIns, new ConsoleErrorReporter());


            if (Bpl.CommandLineOptions.Clo.NoResolve || Bpl.CommandLineOptions.Clo.NoTypecheck)
            {
                return(null);
            }
            Debug.WriteLine("SUCCESS: Parsing Dafny Program");
            return(null);
        }
コード例 #7
0
ファイル: Utils.cs プロジェクト: mschlaipfer/dafny
        /// <summary>
        /// Parse a string read (from a certain file) to a Dafny Program
        /// </summary>
        public static Program?Parse(string source, string fileName = "")
        {
            ModuleDecl module   = new LiteralModuleDecl(new DefaultModuleDecl(), null);
            var        builtIns = new BuiltIns();
            var        reporter = new ConsoleErrorReporter();
            var        success  = Parser.Parse(source, fileName, fileName, null, module, builtIns,
                                               new Errors(reporter)) == 0 && Microsoft.Dafny.Main.ParseIncludes(module, builtIns,
                                                                                                                new List <string>(), new Errors(reporter)) == null;
            Program?program = null;

            if (success)
            {
                program = new Program(fileName, module, builtIns, reporter);
            }
            new Resolver(program).ResolveProgram(program);
            return(program);
        }
コード例 #8
0
ファイル: TacnyDriver.cs プロジェクト: ggrov/tacny
    public Program ParseAndTypeCheck(bool runResolver)
    {
      var errorReporter = new ConsoleErrorReporter();
      var module = new LiteralModuleDecl(new DefaultModuleDecl(), null);
      var builtIns = new BuiltIns();
      var parseErrors = new Errors(errorReporter);
      var errorCount = Parser.Parse(_snapshot.GetText(), _filename, _filename, module, builtIns, parseErrors);
      var errString = Main.ParseIncludes(module, builtIns, new List<string>(), parseErrors);
      if (errorCount != 0 || errString != null) return null;

      var program = new Program(_filename, module, builtIns, errorReporter);
      if (!runResolver) return program;

      var r = new Resolver(program);
      r.ResolveProgram(program);
      return errorReporter.Count(ErrorLevel.Error) == 0 ? program : null;
    }
コード例 #9
0
        IEnumerable <BoogieProgram> GetBoogie(string dafnyProgramText)
        {
            var module       = new LiteralModuleDecl(new DefaultModuleDecl(), null);
            var fullFilePath = "foo";

            Microsoft.Dafny.Type.ResetScopes();
            var builtIns      = new BuiltIns();
            var errorReporter = new ConsoleErrorReporter();
            var parseResult   = Parser.Parse(dafnyProgramText, fullFilePath, "foo", module, builtIns, errorReporter);

            Assert.Equal(0, parseResult);
            var dafnyProgram = new Microsoft.Dafny.Program(fullFilePath, module, builtIns, errorReporter);

            Main.Resolve(dafnyProgram, errorReporter);
            var boogiePrograms = Translator.Translate(dafnyProgram, errorReporter).Select(t => t.Item2);

            return(boogiePrograms);
        }
コード例 #10
0
        private bool LookupLevel(IToken levelDescriptor, string kind, out LiteralModuleDecl m)
        {
            ModuleDecl md = null;

            m = null;

            if (!bindings.TryLookup(levelDescriptor, out md))
            {
                AH.PrintError(prog, $"Could not find {kind} level {levelDescriptor} referred to in proof module {mProof.Name}");
                return(false);
            }
            if (!(md is LiteralModuleDecl))
            {
                AH.PrintError(prog, $"Low-level {levelDescriptor} referred to in proof module {mProof.Name} isn't a code level");
                return(false);
            }
            m = (LiteralModuleDecl)md;
            return(true);
        }
コード例 #11
0
ファイル: Tests.cs プロジェクト: minill/shorty
        private Program GetProgram(string fileName)
        {
            var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            dir = Directory.GetParent(dir).FullName;
            dir = Directory.GetParent(dir).FullName;
            dir = Directory.GetParent(dir).FullName;
            dir = dir + "\\tests\\" + fileName;
            Console.WriteLine(dir);
            var nameStart   = fileName.LastIndexOf('\\') + 1;
            var programName = fileName.Substring(nameStart, fileName.Length - nameStart);

            ModuleDecl module   = new LiteralModuleDecl(new DefaultModuleDecl(), null);
            var        builtIns = new BuiltIns();

            Parser.Parse(dir, module, builtIns, new Errors(new InvisibleErrorReporter()));

            return(new Program(programName, module, builtIns, new InvisibleErrorReporter()));
        }
コード例 #12
0
        public static string Parse(IList <string> fileNames, string programName, ErrorReporter reporter, out Program program)
        {
            Contract.Requires(programName != null);
            Contract.Requires(fileNames != null);
            program = null;
            ModuleDecl module   = new LiteralModuleDecl(new DefaultModuleDecl(), null);
            BuiltIns   builtIns = new BuiltIns();

            foreach (string dafnyFileName in fileNames)
            {
                Contract.Assert(dafnyFileName != null);
                if (Bpl.CommandLineOptions.Clo.XmlSink != null && Bpl.CommandLineOptions.Clo.XmlSink.IsOpen)
                {
                    Bpl.CommandLineOptions.Clo.XmlSink.WriteFileFragment(dafnyFileName);
                }
                if (Bpl.CommandLineOptions.Clo.Trace)
                {
                    Console.WriteLine("Parsing " + dafnyFileName);
                }

                string err = ParseFile(dafnyFileName, Bpl.Token.NoToken, module, builtIns, new Errors(reporter));
                if (err != null)
                {
                    return(err);
                }
            }

            if (!DafnyOptions.O.DisallowIncludes)
            {
                string errString = ParseIncludes(module, builtIns, fileNames, new Errors(reporter));
                if (errString != null)
                {
                    return(errString);
                }
            }

            program = new Program(programName, module, builtIns, reporter);

            MaybePrintProgram(program, DafnyOptions.O.DafnyPrintFile, false);

            return(null); // success
        }
コード例 #13
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);
        }
コード例 #14
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
      }
    }
コード例 #15
0
ファイル: Parser.cs プロジェクト: Chris-Hawblitzel/dafny
        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);
        }
コード例 #16
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);
	}
コード例 #17
0
ファイル: Dare.cs プロジェクト: ggrov/tacny
 public static Program CloneProgram(Program program)
 {
     var cloner = new Cloner();
     var moduleDecl = new LiteralModuleDecl(cloner.CloneModuleDefinition(program.DefaultModuleDef, program.Name), null);
     return new Program(program.FullName, moduleDecl, program.BuiltIns, new InvisibleErrorReporter());
 }