/// <summary> /// Infers the expression and changes the data type of the existing variable /// </summary> /// <param name="comp">compilation</param> /// <param name="proc">process</param> /// <param name="converter">language converter</param> /// <param name="expression">expression</param> /// <param name="varName">variable name</param> /// <returns>a stored variable with the infered data type by the expression</returns> private static IData ComputeExpression(ICompilateur comp, IProcessInstance proc, ICodeConverter converter, string expression, string varName) { IData converted = null; o2Mate.Expression val = new o2Mate.Expression(); // computes the exact value of the inline expression even using variables but all computable IData res = val.Evaluate(expression, proc.CurrentScope); // compute calculability bool calculability = converter.CurrentFunction.IsStaticControlFlow; // store the result in the scope with the varName parameter if (proc.CurrentScope.Exists(varName)) { // get the variable infos IData myVar = proc.CurrentScope.GetVariable(varName); if (res.IsComputable && calculability) { if (res.DataType != myVar.DataType) { if (myVar.TypeExists(res.DataType)) { // update variable with the new data type, value and computable switch proc.CurrentScope.Update(varName, res.ValueString, myVar.PrefixInfo(res.DataType).BelongsTo, true, res.DataType); } else { // update variable with the new data type, value and computable switch proc.CurrentScope.Update(varName, res.ValueString, myVar.BelongsTo, true, res.DataType); } } else { // the same current data type of the stored variable is infered with the expression myVar.Value = res.ValueString; } // on met à jour les paramètres en indiquant que la variable est mutable comp.UpdateParameters(converter, proc, varName, true); converted = myVar; } else { // à cause de l'état du flux de contrôle (boucles,if,etc), converting expression myVar.IsComputable = false; Expression.Convert(converter, expression, proc.CurrentScope, false, false); converted = Helper.ConvertExpression(comp, proc, converter, expression, varName); } } else { // comme la variable n'existe pas ou plus, une affectation va la créer // de ce fait, si son évaluation est calculable, elle est donc constante if (res.IsComputable) { converted = proc.CurrentScope.Add(varName, res.ValueString, proc.Name, true, res.DataType); } else { // créer une nouvelle variable dans le scope et l'ajouter aux variables locales converted = proc.CurrentScope.Add(varName, "", proc.Name, false, res.DataType); } Helper.AddIntoLocal(converter, converted); } return(converted); }