public void Visit(CompaExprContext parserRule, IObjectContext <IVar, IVar> context) { Visit(parserRule.left, context); Visit(parserRule.right, context); if (!globalContext.IfDefineType(parserRule.left.computedType.Name) || !globalContext.IfDefineType(parserRule.right.computedType.Name)) { parserRule.computedType = globalContext.Undefined; } else if (parserRule.op.Text == "=") { //Si al menos uno es de tipo int, bool o' string y los tipos son diferentes capturamos el error if (!parserRule.right.computedType.Equals(parserRule.left.computedType) && (parserRule.left.computedType.Equals(globalContext.Int) || parserRule.left.computedType.Equals(globalContext.Bool) || parserRule.left.computedType.Equals(globalContext.String) || parserRule.right.computedType.Equals(globalContext.Int) || parserRule.right.computedType.Equals(globalContext.Bool) || parserRule.right.computedType.Equals(globalContext.String))) { errorLogger.LogError($"({parserRule.Start.Line},{parserRule.Start.Column + 1}) - Type Error: Operator '{parserRule.op.Text }' cannot be applied to operands of type '{parserRule.left.computedType.Name}' and '{parserRule.right.computedType.Name}'"); parserRule.computedType = globalContext.Undefined; } else { parserRule.computedType = globalContext.Bool; } } else { //Lo dejo como un tipo idefinido if (!parserRule.left.computedType.Equals(globalContext.Int) || !parserRule.right.computedType.Equals(globalContext.Int)) { errorLogger.LogError($"({parserRule.Start.Line},{parserRule.Start.Column + 1}) - Type Error: Operator '{parserRule.op.Text }' cannot be applied to operands of type '{parserRule.left.computedType.Name}' and '{parserRule.right.computedType.Name}'"); parserRule.computedType = globalContext.Undefined; } else { parserRule.computedType = globalContext.Bool; } } }
public IHolderCil Visit(CompaExprContext parserRule, IFunctionCil cilTree, IContextCil contextCil) { var value = new LocalCil($"_value{cilTree.LocalCils.Count}"); cilTree.LocalCils.Add(value); var valueLeft = Visit(parserRule.left, cilTree, contextCil); var valueRight = Visit(parserRule.right, cilTree, contextCil); if (parserRule.left.computedType == GlobalContext.Int) { valueLeft = GetValue(valueLeft, cilTree, CilAst.Int); valueRight = GetValue(valueRight, cilTree, CilAst.Int); } else if (parserRule.left.computedType == GlobalContext.Bool) { valueLeft = GetValue(valueLeft, cilTree, CilAst.Bool); valueRight = GetValue(valueRight, cilTree, CilAst.Bool); } else if (parserRule.left.computedType == GlobalContext.String) { valueLeft = GetValue(valueLeft, cilTree, CilAst.String); valueRight = GetValue(valueRight, cilTree, CilAst.String); } switch (parserRule.op.Text) { case "<": cilTree.ThreeDirInses.Add(new MinorCil(value, valueLeft, valueRight)); break; case "<=": cilTree.ThreeDirInses.Add(new Minor_EqualCil(value, valueLeft, valueRight)); break; case "=": if (parserRule.left.computedType == GlobalContext.String) { cilTree.ThreeDirInses.Add(new EqualStringCil(value, valueLeft, valueRight)); } else { cilTree.ThreeDirInses.Add(new EqualCil(value, valueLeft, valueRight)); } break; default: break; } return(CreateABasicTypeWhitVal(cilTree, CilAst.Bool, value)); }