void CheckInt(Exp e) { if (e.ExpType != typeof(int)) { if (e is VarExp && e.ExpType == typeof(void)) //Param Variable. Type unknown. Assume first occurence { e.ExpType = typeof(int); CurrentFuncDef.Add(((VarExp)e).Name, typeof(int)); } else if (e is DoVarExp && e.ExpType == typeof(void)) //Do Variable. Type unknown. Assume first occurence { e.ExpType = typeof(int); DoVars.Add(((DoVarExp)e).Pos, typeof(int)); } else if (e is CallExp && e.ExpType == typeof(void)) //Recursive function call. Assume first occurence { e.ExpType = typeof(int); } else if (!(e is CarExp)) //CarExp will be coerceto int { Console.WriteLine("Int expected"); success = false; } } }
void CheckList(ref Exp e) { if (e.ExpType == typeof(int)) { e = new ToListExp(e); e.ExpType = typeof(CList); } if (e.ExpType != typeof(CList)) { if (e is VarExp && e.ExpType == typeof(void)) { e.ExpType = typeof(CList); CurrentFuncDef.Add(((VarExp)e).Name, typeof(CList)); } else if (e is DoVarExp && e.ExpType == typeof(void)) { e.ExpType = typeof(CList); DoVars.Add(((DoVarExp)e).Pos, typeof(CList)); } else if (e is CallExp && e.ExpType == typeof(void)) //Recursive function call. Assume first occurence { e.ExpType = typeof(int); } else if (!(e is IntExp)) //IntExp will be coerceto List { Console.WriteLine("List expected"); success = false; } } }
public void DoVarDef(DoVarDef e) { e.Init.Visit(this); if (e.Init.ExpType != typeof(void)) //If type of init is known put it in. { if (DoVars[e.Pos] == null) { DoVars.Add(e.Pos, e.Init.ExpType); //Else DoVarExp will add typeof(void) } } e.Iter.Visit(this); if (e.Init.ExpType == typeof(void) && e.Init is VarExp) //If e.Init is VarExp which currently has no type. { e.Init.ExpType = (Type)DoVars[e.Pos]; //Assign it since now we know the type required. CurrentFuncDef.Add(((VarExp)e.Init).Name, e.Init.ExpType); } if (e.Init.ExpType != e.Iter.ExpType) { Console.WriteLine("Do Expression: Init and Iterations have different type"); success = false; } }