コード例 #1
0
        public void Visit(Block block)
        {
            var previousStaticEnv = _staticEnv;

            _staticEnv = new StaticEnv(previousStaticEnv);
            try {
                foreach (var stmt in block.Statements)
                {
                    stmt.Accept(this);
                }
            } finally {
                _staticEnv = previousStaticEnv;
            }
        }
コード例 #2
0
        public void Visit(FunctionDecl funcDecl)
        {
            Raise <TypeCheckException> .If(_funcDecls.ContainsKey(funcDecl.Name), "Function with existing name!");

            funcDecl.ReturnType = GetType(funcDecl.ReturnTypeName);
            var previousStaticEnv = _staticEnv;

            _staticEnv = new StaticEnv(new OutmostStaticEnv());
            foreach (var p in funcDecl.Params)
            {
                p.Type = GetType(p.TypeName);
                Raise <TypeCheckException> .IfAreSame(p.Type, _voidType, "Struct fields cannot be void");

                var vInfo = new StaticEnvBase.VarInfo(p.Name, p.Type, StaticEnvBase.Kind.Param, p);
                _staticEnv.SetVariable(p.Name, vInfo);
            }
            _funcDecls.Add(funcDecl.Name, funcDecl); // Must be put here to allow recursion...
            var prevFunc = _currFunc;

            _currFunc = funcDecl;
            funcDecl.Body.Accept(this);
            _currFunc  = prevFunc;
            _staticEnv = previousStaticEnv;
        }
コード例 #3
0
 public StaticEnv(StaticEnvBase parent)
 {
     Debug.Assert(parent != null);
     _parent = parent;
 }
コード例 #4
0
 public void Visit(Block block)
 {
     var previousStaticEnv = _staticEnv;
     _staticEnv = new StaticEnv(previousStaticEnv);
     try {
         foreach (var stmt in block.Statements) {
             stmt.Accept(this);
         }
     } finally {
         _staticEnv = previousStaticEnv;
     }
 }
コード例 #5
0
 public StaticEnv(StaticEnvBase parent)
 {
     Debug.Assert(parent != null);
     _parent = parent;
 }
コード例 #6
0
 public void Visit(FunctionDecl funcDecl)
 {
     Raise<TypeCheckException>.If(_funcDecls.ContainsKey(funcDecl.Name), "Function with existing name!");
     funcDecl.ReturnType = GetType(funcDecl.ReturnTypeName);
     var previousStaticEnv = _staticEnv;
     _staticEnv = new StaticEnv(new OutmostStaticEnv());
     foreach (var p in funcDecl.Params) {
         p.Type = GetType(p.TypeName);
         Raise<TypeCheckException>.IfAreSame(p.Type, _voidType, "Struct fields cannot be void");
         var vInfo = new StaticEnvBase.VarInfo(p.Name, p.Type, StaticEnvBase.Kind.Param, p);
         _staticEnv.SetVariable(p.Name, vInfo);
     }
     _funcDecls.Add(funcDecl.Name, funcDecl); // Must be put here to allow recursion...
     var prevFunc = _currFunc;
     _currFunc = funcDecl;
     funcDecl.Body.Accept(this);
     _currFunc = prevFunc;
     _staticEnv = previousStaticEnv;
 }