public static void editVar(VariableDeclaration variable, IExecutable scope) { string oldName = variable.CreatedVariable.Name, newName; bool oldCstState = variable.CreatedVariable.Constant; do { var dialog = new createVar(variable, true); dialog.Owner = MainDialog; if (dialog.ShowDialog() == true) { newName = dialog.varName.Text; variable.CreatedVariable.Name = ""; variable.CreatedVariable.Constant = dialog.varConst.IsChecked.Value; if (!isNameConventionnal(newName)) { MessageBox.Show(dialog, "nom non conventionnel !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else if (!isNameAvailable(newName, scope)) { MessageBox.Show(dialog, "nom déjà utilisé !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else { if (variable.CreatedVariable.Constant) { IValue cstValule; try { cstValule = ILANET.Parser.Parser.ParseValue(dialog.constValue.Text, CurrentILAcode, scope, true); } catch (Exception e) { MessageBox.Show(MainDialog, e.Message, "erreur", MessageBoxButton.OK, MessageBoxImage.Error); variable.CreatedVariable.Name = ""; continue; } variable.CreatedVariable.ConstantValue = cstValule; } if (!(variable.CreatedVariable.Type is Native)) { int i = 0; foreach (var item in CurrentILAcode.Declarations) { if (item is TypeDeclaration td) { if (i == dialog.varType.SelectedIndex) { variable.CreatedVariable.Type = td.CreatedType; } i++; } } } var comm = new Comment { Message = dialog.comments.Text, MultiLine = dialog.comments.Text.Contains('\n') }; variable.AboveComment = comm; variable.InlineComment = dialog.inlineComm.Text; variable.CreatedVariable.Name = newName; return; } } else { variable.CreatedVariable.Name = oldName; variable.CreatedVariable.Constant = oldCstState; break; } } while (!(isNameAvailable(variable.CreatedVariable.Name, scope) && isNameConventionnal(variable.CreatedVariable.Name))); }
public static void createVar(int type, IExecutable scope) //0 = int, 1 = float, 2 = char, 3 = bool, 4 = string, 5 = custom { var decl = new VariableDeclaration(); var variable = new Variable(); decl.CreatedVariable = variable; variable.Name = "nouvelle_variable"; switch (type) { case 0: variable.Type = GenericType.Int; break; case 1: variable.Type = GenericType.Float; break; case 2: variable.Type = GenericType.Char; break; case 3: variable.Type = GenericType.Bool; break; case 4: variable.Type = GenericType.String; break; case 5: { foreach (var item in CurrentILAcode.Declarations) { if (item is TypeDeclaration td) { variable.Type = td.CreatedType; break; } } break; } } do { var dialog = new createVar(decl); dialog.Owner = MainDialog; if (dialog.ShowDialog() == true) { variable.Name = dialog.varName.Text; variable.Constant = dialog.varConst.IsChecked.Value; if (!isNameConventionnal(variable.Name)) { MessageBox.Show(dialog, "nom non conventionnel !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else if (!isNameAvailable(variable.Name, scope)) { MessageBox.Show(dialog, "nom déjà utilisé !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else { if (variable.Constant) { IValue cstValule; try { cstValule = ILANET.Parser.Parser.ParseValue(dialog.constValue.Text, CurrentILAcode, scope, true); } catch (Exception e) { MessageBox.Show(MainDialog, e.Message, "erreur", MessageBoxButton.OK, MessageBoxImage.Error); variable.Name = ""; continue; } variable.ConstantValue = cstValule; } if (!(variable.Type is Native) && dialog.varType.SelectedIndex == -1) { MessageBox.Show(MainDialog, "Aucun type choisi", "erreur", MessageBoxButton.OK, MessageBoxImage.Warning); variable.Name = ""; continue; } if (!(variable.Type is Native)) { variable.Type = (VarType)((ToStringOverrider)dialog.varType.SelectedItem).Content; } var comm = new Comment { Message = dialog.comments.Text, MultiLine = dialog.comments.Text.Contains('\n') }; decl.InlineComment = dialog.inlineComm.Text; decl.AboveComment = comm; if (scope is Module m) { m.Declarations.Add(decl); } else if (scope is Program p) { p.Declarations.Add(decl); } return; } } else { break; } } while (!(isNameAvailable(variable.Name, scope) && isNameConventionnal(variable.Name))); }