public IHolderCil Visit(CondExprContext parserRule, IFunctionCil cilTree, IContextCil contextCil) { var value = new LocalCil($"_value{cilTree.LocalCils.Count}"); cilTree.LocalCils.Add(value); var condValue = Visit(parserRule.ifExpr, cilTree, contextCil); condValue = GetValue(condValue, cilTree, CilAst.Bool); var labelElse = cilTree.CreateLabel("else"); cilTree.ThreeDirInses.Add(new IfGoto(condValue, labelElse)); //genero el codigo de elseValue var elseValue = Visit(parserRule.elseExpr, cilTree, contextCil); var labelEnd = cilTree.CreateLabel("end"); //El resultado lo almaceno en value cilTree.ThreeDirInses.Add(new AssigCil(value, elseValue)); //Voy pa la etiquta end cilTree.ThreeDirInses.Add(new GotoCil(labelEnd)); //Pongo la etiqueta de else cilTree.ThreeDirInses.Add(new Label(labelElse)); //genero el codigo de thenValue var thenValue = Visit(parserRule.thenExpr, cilTree, contextCil); //Asigno el valor a esle value cilTree.ThreeDirInses.Add(new AssigCil(value, thenValue)); //Pongo la etiqueta end cilTree.ThreeDirInses.Add(new Label(labelEnd)); //retorno el valor return(value); }
//No se si la cond su tipo no es bool devuelvo un tipo no definido public void Visit(CondExprContext parserRule, IObjectContext <IVar, IVar> context) { Visit(parserRule.ifExpr, context); Visit(parserRule.thenExpr, context); Visit(parserRule.elseExpr, context); //Si la expresion ifExpr es undefined devuelvo como tipo estatico undefined if (!globalContext.IfDefineType(parserRule.ifExpr.computedType)) { parserRule.computedType = globalContext.Undefined; } else if (!parserRule.ifExpr.computedType.Equals(globalContext.Bool)) { errorLogger.LogError($"({parserRule.ifExpr.Start.Line},{parserRule.ifExpr.Start.Column + 1}) - TypeError: The predicate of de conditionals must have static type 'Bool', not '{parserRule.ifExpr.computedType.Name}'"); parserRule.computedType = globalContext.Undefined; } else//Si al menos uno es undefined entonces el tipo estatico lo sera { parserRule.computedType = parserRule.thenExpr.computedType.Join(parserRule.elseExpr.computedType); } }