/// <summary> /// Fill a new method /// </summary> /// <param name="comp">compilation</param> /// <param name="subProc">sub process object</param> /// <param name="converter">language converter</param> /// <param name="f">new function</param> /// <param name="file">writing in</param> public static void FillNewMethod(ICompilateurInstance comp, IProcess subProc, ICodeConverter converter, IFunction f, FinalFile file) { // la fonction est implémentée converter.PushFunction(converter.CurrentFunction); f.PropagateControlFlow(converter.CurrentFunction); converter.SetCurrentFunction(f); subProc.FunctionName = converter.ProcessAsFunction; converter.CurrentFunction.ForwardControlFlowSub(); comp.Convert(converter, subProc, file); converter.CurrentFunction.BackwardControlFlowSub(); converter.SetCurrentFunction(converter.PopFunction()); }
public void Convert(ICodeConverter converter, IProcess proc, FinalFile file) { Process jobProc = new Process(); Function f = new Function(); f.IsJob = true; f.Name = this.jobName; // la première fonction commence à xxx_1 f.InstanceNumber = converter.ImplementedFunctions.FindAll(new Predicate <IFunction>(delegate(IFunction func) { return(func.IsJob && func.StrictName == this.jobName); })).Count + 1; jobProc.Name = ":" + f.Name; jobProc.FunctionName = f.Name; this.cachedComp.PushProcess(jobProc); converter.ImplementedFunctions.Add(f); converter.PushFunction(converter.CurrentFunction); converter.SetCurrentFunction(f); }
public void Convert(ICodeConverter converter, IProcess proc, FinalFile file) { this.cachedComp.PopProcess(); converter.SetCurrentFunction(converter.PopFunction()); }
public static void IsolatedFunction(ICompilateurInstance comp, IProcessInstance proc, ICodeConverter converter, IsolatedFunctionDelegate d) { if (converter.CurrentFunction.IsStaticControlFlow) { Dictionary <string, IParameter> varNames, leftNames; Action <KeyValuePair <string, IParameter> > action; TypedVariable tv; IFunction prec = converter.CurrentFunction; IFunction thisFunc = new Function(); thisFunc.IndentSize = prec.IndentSize; thisFunc.IsVisible = true; thisFunc.StrictName = "inner_" + comp.Unique.ComputeNewString(); thisFunc.PropagateControlFlow(prec); // ajoute la fonction dans la liste converter.ImplementedFunctions.Add(thisFunc); // change la fonction courante converter.SetCurrentFunction(thisFunc); d(); // retourne à la fonction précédente pour traiter le changement de type converter.SetCurrentFunction(prec); // supprime la fonction de la liste converter.ImplementedFunctions.Remove(thisFunc); leftNames = new Dictionary <string, IParameter>(); // élimine les variables passées en paramètre qui n'ont pas changé de type thisFunc.Parameters.ForEach(new Action <IParameter>(delegate(IParameter par) { if (!leftNames.ContainsKey(par.VariableName) && par.Order != EnumParameterOrder.E_NEW) { leftNames.Add(par.VariableName, par); } })); // enregistre le nom distinct des variables passées en paramètre qui soient mutable et initiale varNames = new Dictionary <string, IParameter>(); thisFunc.Parameters.ForEach(new Action <IParameter>(delegate(IParameter par) { if (!varNames.ContainsKey(par.VariableName) && leftNames.ContainsKey(par.VariableName) && par.IsMutableParameter && par.Order == EnumParameterOrder.E_NEW) { varNames.Add(par.VariableName, par); } })); // modifie toutes les variables en SimpleType action = new Action <KeyValuePair <string, IParameter> >(delegate(KeyValuePair <string, IParameter> kv) { Regex reg = new Regex(@"\$\[([^:]*):([a-z]+_" + kv.Key + @")\]"); thisFunc.Source = reg.Replace(thisFunc.Source, new MatchEvaluator(delegate(Match m) { string type = m.Groups[1].Value; string name = m.Groups[2].Value; int pos = name.IndexOf('_'); string result = String.Empty; if (pos != -1) { result = "$[" + type + ":st_" + name.Substring(pos + 1) + "]"; } else { result = "$[" + type + ":st_" + name + "]"; } return(result); })); tv = new TypedVariable(kv.Value.VariableName, kv.Value.FormalParameter, kv.Value.DataType, EnumDataType.E_SIMPLETYPE); tv.MoveType(converter, proc.CurrentScope); }); foreach (KeyValuePair <string, IParameter> kv in varNames.Except(leftNames)) { action(kv); } // copie de l'implémentation de cette fonction dans la fonction en cours prec.Source += thisFunc.Source; // copies des variables locales de cette fonction dans la fonction en cours thisFunc.LocalVariables.ForEach(new Action <IStructure>(delegate(IStructure loc) { if (!converter.CurrentFunction.LocalVariables.Exists(new Predicate <IStructure>(delegate(IStructure cur) { return(cur.PrefixedFieldName == loc.PrefixedFieldName); }))) { converter.CurrentFunction.LocalVariables.Add(loc); } })); // mettre à jour les paramètres foreach (KeyValuePair <string, IParameter> kv in varNames.Except(leftNames)) { List <IParameter> pars = thisFunc.Parameters.FindAll(new Predicate <IParameter>(delegate(IParameter par) { return(par.VariableName == kv.Key); })); if (pars.Count > 1) { pars.ForEach(new Action <IParameter>(delegate(IParameter update) { if (update.Order == EnumParameterOrder.E_LAST) { tv = new TypedVariable(update.VariableName, update.FormalParameter, EnumDataType.E_SIMPLETYPE, update.DataType); tv.MoveType(converter, proc.CurrentScope); } })); } else if (pars.Count == 1) { tv = new TypedVariable(pars[0].VariableName, pars[0].FormalParameter, EnumDataType.E_SIMPLETYPE, pars[0].DataType); tv.MoveType(converter, proc.CurrentScope); } } } else { d(); } }