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; } }
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; }
public StaticEnv(StaticEnvBase parent) { Debug.Assert(parent != null); _parent = parent; }
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; }