public CoolToCil() { method = new Current_Method(); take_data = new Take_str("data"); Data = new Dictionary <string, string>(); Code = new Dictionary <string, CIL_Function>(); Types = new Dictionary <string, CIL_OneType>(); }
public string Visit(Method_Def node) { method = new Current_Method(); string solution = Visit(node.exp); method.Add_Instruction(new CIL_Return(solution)); Code.Add(node.name.name, new CIL_Function(node.name.name, new List <string>(node.args.list_Node.Select(x => x.name.name)), new List <string>(method.locals.Values), method.body)); return(""); }
public CoolToCil() { method = new Current_Method(); take_data = new Take_str("data"); Data = new Dictionary <string, string>(); Data[""] = "vacio"; Code = SystemFunctions.GetAllSysFunctions(); Types = new Dictionary <string, CIL_OneType>(); }
public string Visit(Method_Def node) { method = new Current_Method(); method.args = new List <string>(node.args.list_Node.Select(m => m.name.name)); string solution = node.exp.Visit(this); method.Add_Instruction(new CIL_Return(solution)); string mtdName = node.name.name + "_" + current_type.Name; Code.Add(mtdName, new CIL_Function(mtdName, new List <string>(node.args.list_Node.Select(x => x.name.name)), new List <string>(method.locals.Values), method.body)); return(""); }
public string Visit(Class_Def node) { current_type = Types_Cool[node.type.s]; // Formando el metodo init method = new Current_Method(); string father = Types_Cool[node.type.s].Father.Name; if (father != "IO" && father != "Object") { string f = method.Add_local("father", true); method.Add_Instruction(new CIL_Allocate(f, father)); method.Add_Instruction(new CIL_VCall(f, father, "__init", new List <string> { f })); foreach (string attr in Types[father].Attributes) { string a = method.Add_local("attr", true); method.Add_Instruction(new CIL_GetAttr(a, new CIL_MyVar(f, father), attr)); method.Add_Instruction(new CIL_SetAttr(new CIL_MyVar("this", node.type.s), attr, a)); } } foreach (var attr in node.attr.list_Node) { attr.Visit(this); } method.Add_Instruction(new CIL_Return("this")); string mtdName = "__init_" + node.type.s; Code.Add(mtdName, new CIL_Function(mtdName, new List <string>(), new List <string>(method.locals.Values), method.body)); foreach (Method_Def item in node.method.list_Node) { Visit(item); } return(""); }