public void Visit(AssignExprContext parserRule, IObjectContext <IVar, IVar> context) { if (!context.IsDefineVar(parserRule.id.Text)) { errorLogger.LogError($"({parserRule.id.Line},{parserRule.id.Column + 1}) - NameError : The variable '{parserRule.id.Text}' does not exist in the current context"); parserRule.computedType = globalContext.Undefined; } else { var variable = context.GetVar(parserRule.id.Text).Type; Visit(parserRule.expresion, context); //si el tipo de la variable no esta definido if (!globalContext.IfDefineType(variable.Name)) { parserRule.computedType = globalContext.Undefined; } //si el tipo de la expresion es Undefined no entra aqui y se le asigna despues else if (!parserRule.expresion.computedType.Conform(variable)) { errorLogger.LogError($"({parserRule.Start.Line},{parserRule.Start.Column + 1}) - Type Error : In the assignment the static type of the expression '{parserRule.expresion.computedType.Name}' not conform to the declared type of the identifier '{variable.Name}'"); parserRule.computedType = globalContext.Undefined;//Si el tipo que devuelve la expresion no conforma con el de la variable se devuelve undefined (puede que lo quite) } else { parserRule.computedType = parserRule.expresion.computedType; } } }
public IHolderCil Visit(AssignExprContext parserRule, IFunctionCil cilTree, IContextCil contextCil) { var valueExpr = Visit(parserRule.expresion, cilTree, contextCil); if (!contextCil.variables.ContainsKey(parserRule.id.Text)) { var value = new LocalCil($"_value{cilTree.LocalCils.Count}"); cilTree.LocalCils.Add(value); cilTree.ThreeDirInses.Add(new SetAttrCil(cilTree.self, typeCil.GetAttributeCilsByCoolName(parserRule.id.Text), valueExpr)); cilTree.ThreeDirInses.Add(new GetAttrCil(value, cilTree.self, typeCil.GetAttributeCilsByCoolName(parserRule.id.Text))); return(value); } else { var value = contextCil.variables[parserRule.id.Text]; cilTree.ThreeDirInses.Add(new AssigCil(value, valueExpr)); return(value); } }