public IHolderCil Visit(CaseExprContext parserRule, IFunctionCil cilTree, IContextCil contextCil) { var value = new LocalCil($"_value{cilTree.LocalCils.Count}"); cilTree.LocalCils.Add(value); var expr0 = Visit(parserRule.expresion, cilTree, contextCil); //is void var TypeValue = new LocalCil($"_TypeValue{cilTree.LocalCils.Count}"); var not_is_void = new LocalCil($"not_is_void{cilTree.LocalCils.Count}"); cilTree.LocalCils.Add(TypeValue); cilTree.LocalCils.Add(not_is_void); cilTree.ThreeDirInses.Add(new TypeOf(TypeValue, expr0)); cilTree.ThreeDirInses.Add(new NotEqualCil(not_is_void, TypeValue, CilAst.GetTypeCilByName("void"))); //lanzamos el error Visit_Runtime_Error_whit_Cond(not_is_void, cilTree, $"\"({parserRule.Start.Line},{parserRule.Start.Column + 1}) - Rutime Error: A case on void\""); //ejecucion del case var closestAncestor = new LocalCil($"_closestAncestor{cilTree.LocalCils.Count}"); cilTree.LocalCils.Add(closestAncestor); //Inicializo el valor de numberType en 0 y closestAncestor con object var isNotConform = new LocalCil($"_isNotConform{cilTree.LocalCils.Count}"); cilTree.LocalCils.Add(isNotConform); var branches = parserRule._branches.Concat(new List <BranchContext>() { parserRule.firstBranch }).OrderBy(t => - (CilAst.GetTypeCilByName(t.typeText).IndexOfPrecedence)).ToArray(); //El tipo de la primera rama var End = cilTree.CreateLabel("End_"); for (int i = 0; i < branches.Length; i++) { var branch = branches[i]; var nextLabel = cilTree.CreateLabel("Case_"); //tipo de la rama var typeBranch = CilAst.GetTypeCilByName(branch.typeText, typeCil); cilTree.ThreeDirInses.Add(new IsNotConformCil(isNotConform, TypeValue, typeBranch)); cilTree.ThreeDirInses.Add(new IfGoto(isNotConform, nextLabel)); var valueBranch = new LocalCil(branch.idText);//preguntarle as zahuis cilTree.LocalCils.Add(valueBranch); cilTree.ThreeDirInses.Add(new AssigCil(valueBranch, expr0)); var newContextCil = contextCil.CreateAChild(); newContextCil.Define(branch.idText); var valueExpr = Visit(branch.expression, cilTree, newContextCil); cilTree.ThreeDirInses.Add(new AssigCil(value, valueExpr)); cilTree.ThreeDirInses.Add(new GotoCil(End)); cilTree.ThreeDirInses.Add(new Label(nextLabel)); } Visit_Runtime_Error(cilTree, $"\"linea {parserRule.Start.Line} y columna {parserRule.Start.Column + 1} Execution of a case statement without a matching branch\""); cilTree.ThreeDirInses.Add(new Label(End)); return(value); }
public IHolderCil Visit(LetBodyContext parserRule, IFunctionCil cilTree, IContextCil contextCil) { var newContextCil = contextCil.CreateAChild(); Visit(parserRule.declaretion, cilTree, newContextCil); return(Visit(parserRule.body, cilTree, newContextCil)); }