예제 #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     o2Mate.Expression expr = new o2Mate.Expression();
     o2Mate.Scope      s    = new o2Mate.Scope();
     s.Add("i", "1", "", true);
     o2Mate.IData data = expr.Evaluate("i+1", s);
     MessageBox.Show(data.ValueString);
 }
예제 #2
0
 public void ExtractDictionary(IProcessInstance proc)
 {
     // on veut savoir si l'expression est calculable ou pas
     o2Mate.Expression expr = new o2Mate.Expression();
     o2Mate.IData      res  = expr.Evaluate(this.expression, proc.CurrentScope);
     if (res.IsComputable)
     {
         proc.CurrentScope.Add(this.varName, res.ValueString, proc.Name, true);
     }
     else
     {
         proc.CurrentScope.Add(this.varName, "", proc.Name, false);
     }
 }
예제 #3
0
 /// <summary>
 /// Creates a new field into a structure to hold a variable in a scope with its current data type
 /// </summary>
 /// <param name="name">name of the instance structure</param>
 /// <param name="d">variable object</param>
 /// <param name="isMutable">mutable switch</param>
 public Structure(string name, o2Mate.IData d, bool isMutable)
 {
     this.instanceName = name;
     this.asStructure  = false;
     if (d != null)
     {
         this.fieldName  = d.Name;
         this.prefixName = d.Prefix;
         this.dataType   = d.DataType;
         this.isMutable  = isMutable;
         this.isGlobal   = d.IsGlobal;
     }
     else
     {
         throw new ArgumentException("Field object cannot be null");
     }
 }
        /// <summary>
        /// Create a new sub field and alias a variable in scope
        /// </summary>
        /// <param name="instanceName">name of the structure instance (throw exception if not exists)</param>
        /// <param name="field">an existing variable object (from scope)</param>
        /// <param name="isMutable">mutable switch</param>
        /// <returns>a structure object</returns>
        public IStructure CreateNewField(string instanceName, o2Mate.IData field, bool isMutable)
        {
            string typeName = String.Empty;

            if (!this.CurrentFunction.InstancesStructure.ContainsKey(instanceName))
            {
                throw new ArgumentException("L'instance '" + instanceName + "' n'existait pas dans la fonction en cours.");
            }
            else
            {
                typeName = this.CurrentFunction.InstancesStructure[instanceName];
            }
            IStructure st = new Structure(instanceName, field, isMutable);

            if (!this.StructureNames.ContainsKey(typeName))
            {
                this.StructureNames[typeName].Add(st);
            }
            return(st);
        }
 /// <summary>
 /// This function serves to return the name of a variable
 /// dependent if the language is a strongly typed language
 /// </summary>
 /// <param name="var">the variable object</param>
 /// <returns>the adequate name of the variable</returns>
 public string ReturnVarName(o2Mate.IData var)
 {
     return(var.Name);
 }
예제 #6
0
 /// <summary>
 /// This function serves to return the name of a variable
 /// dependent if the language is a strongly typed language
 /// </summary>
 /// <param name="var">the variable object</param>
 /// <returns>the adequate name of the variable</returns>
 public string ReturnVarName(o2Mate.IData var)
 {
     return(PowerShellConverter.Escape(var.Name));
 }
예제 #7
0
        public void WriteToFile(IProcessInstance proc, FinalFile file)
        {
            string fileName = FinalFile.BuildDirectory;

            for (int index = 0; index < this.filePath.Count - 1; ++index)
            {
                string            expression = this.filePath[index];
                o2Mate.Expression expr       = new o2Mate.Expression();
                o2Mate.IData      result     = expr.Evaluate(expression, proc.CurrentScope);
                string            value      = result.ValueString;
                foreach (char c in Path.GetInvalidPathChars())
                {
                    int position = -1;
                    if ((position = value.IndexOf(c)) != -1)
                    {
                        value = value.Substring(0, position) + value.Substring(position + 1);
                    }
                }
                fileName += value + Path.DirectorySeparatorChar;
                FinalFile.EnsureDirectoryCreated(fileName);
            }
            {
                string            expression = this.filePath[this.filePath.Count - 1];
                o2Mate.Expression expr       = new o2Mate.Expression();
                // le séparateur . permet d'utiliser des expressions
                string[] split = expression.Split('.');
                bool     first = true;
                foreach (string s in split)
                {
                    o2Mate.IData result = expr.Evaluate(s, proc.CurrentScope);
                    string       value  = result.ValueString;
                    foreach (char c in Path.GetInvalidFileNameChars())
                    {
                        int position = -1;
                        if ((position = value.IndexOf(c)) != -1)
                        {
                            value = value.Substring(0, position) + value.Substring(position + 1);
                        }
                    }
                    if (!first)
                    {
                        fileName += ".";
                    }
                    else
                    {
                        first = false;
                    }
                    fileName += value;
                }
            }
            FinalFile.EraseFile(fileName);
            if (proc.CurrentScope.Exists(this.writerName))
            {
                IData d = proc.CurrentScope.GetVariable(this.writerName);
                d.Value        = "{\"" + fileName + "\",0,true}";
                d.IsComputable = true;
                proc.CurrentProject.Add(new ProjectItem(proc.Name, proc.CurrentPositionExecution, "create writer", this.writerName, fileName));
            }
            else
            {
                proc.CurrentScope.Add(this.writerName, "{\"" + fileName + "\",0,true}", proc.Name, true);
                proc.CurrentProject.Add(new ProjectItem(proc.Name, proc.CurrentPositionExecution, "create writer", this.writerName, fileName));
            }
        }
예제 #8
0
        /// <summary>
        /// Converts this statement for a particular programming language destination
        /// </summary>
        /// <param name="converter">converter object</param>
        /// <param name="proc">process object</param>
        /// <param name="file">final file</param>
        public void Convert(Converters.ICodeConverter converter, IProcessInstance proc, FinalFile file)
        {
            string        name         = null;
            List <string> skeletonPath = null;
            string        modifier     = null;

            if (this.ParseCommand(this.command, out name, out skeletonPath, out modifier))
            {
                // rechercher le MOP source
                CreateMOP mopSrc = this.cachedComp.GetMOP(this.language, name);

                // charge l'extrait de code du mop
                XmlDocument doc = new XmlDocument();
                doc.PreserveWhitespace = false;
                doc.LoadXml("<code>" + mopSrc.XmlCode + "</code>");

                if (skeletonPath.Count == 0 || String.IsNullOrEmpty(modifier))
                {
                    // cas lorsque l'on insère dans le processus en cours

                    // fabrication d'un processus
                    Process subProcess = new Process();
                    subProcess.Name = this.MOPToFunctionName(mopSrc.Language + "_" + mopSrc.Name);

                    // ajouter les affectations pour chaque paramètre
                    string[] tab;
                    if (!String.IsNullOrEmpty(this.expression))
                    {
                        tab = this.expression.Split(',');
                    }
                    else
                    {
                        tab = new string[0];
                    }
                    int index = 0;
                    Dictionary <string, string> values = new Dictionary <string, string>();
                    while (index < mopSrc.References.Count)
                    {
                        if (index < tab.Length)
                        {
                            values.Add(mopSrc.References[index], tab[index]);
                        }
                        ++index;
                    }
                    if (index < tab.Length && mopSrc.References.Count > 0)
                    {
                        values[mopSrc.References[mopSrc.References.Count - 1]] += "array(" + String.Join(",", tab, index, tab.Length - index) + ")";
                    }
                    foreach (KeyValuePair <string, string> kv in values)
                    {
                        Converters.Parameter param = new Parameter();
                        param.FormalParameter      = kv.Key.Trim();
                        param.ReplacementParameter = kv.Value.Trim();
                        o2Mate.Expression expr = new o2Mate.Expression();
                        o2Mate.IData      res  = expr.Evaluate(kv.Value.Trim(), proc.CurrentScope);
                        param.EffectiveParameter = res.ValueString;
                        param.IsComputable       = res.IsComputable;
                        subProcess.Replacements.Add(param);
                    }

                    if (this.localInjector != null)
                    {
                        // on recherche le début de l'injection
                        this.localInjector.InjectedProcess.Remove(this.localInjector.Current, this.localInjector.After - 1);
                        this.localInjector.InjectedProcess.Remove(this.localInjector.Before, this.localInjector.Current - 1);
                        this.localInjector.Current = this.localInjector.Before;
                        this.localInjector.After   = this.localInjector.Before + 1;
                    }
                    else
                    {
                        this.localInjector                 = new Injector();
                        this.localInjector.Current         = this.localInjector.Before = proc.Objects.IndexOf(this);
                        this.localInjector.After           = this.localInjector.Before + 1;
                        this.localInjector.InjectedProcess = proc;
                    }
                    this.cachedComp.Injection(this.localInjector, doc.DocumentElement, "after");

                    // on implémente une fonction avec ce processus
                    Call c = new Call(this.cachedComp, proc);
                    c.ProcessName = subProcess.Name;
                    c.Convert(converter, proc, file);
                }
                else
                {
                    // cas d'utilisation d'un inserteur

                    string insert = String.Empty;
                    bool   first  = true;
                    foreach (string path in skeletonPath)
                    {
                        if (!first)
                        {
                            insert += "/";
                        }
                        else
                        {
                            first = false;
                        }
                        insert += path;
                    }
                    Injector j = this.cachedComp.GetInjector(insert);

                    // lorsque l'injecteur a déjà été utilisé
                    if (!j.IsEmpty && modifier == "replace")
                    {
                        // on efface tout
                        // on recherche le début de l'injection
                        j.InjectedProcess.Remove(j.Current, j.After - 1);
                        j.InjectedProcess.Remove(j.Before, j.Current - 1);
                        j.Current = j.Before;
                        j.After   = j.Before + 1;
                    }

                    // ajouter les affectations pour chaque paramètre
                    string[] tab;
                    if (!String.IsNullOrEmpty(this.expression))
                    {
                        tab = this.expression.Split(',');
                    }
                    else
                    {
                        tab = new string[0];
                    }
                    int index = 0;
                    Dictionary <string, string> values = new Dictionary <string, string>();
                    while (index < mopSrc.References.Count)
                    {
                        if (index < tab.Length)
                        {
                            values.Add(mopSrc.References[index], tab[index]);
                        }
                        ++index;
                    }
                    if (index < tab.Length && mopSrc.References.Count > 0)
                    {
                        values[mopSrc.References[mopSrc.References.Count - 1]] += "array(" + String.Join(",", tab, index, tab.Length - index) + ")";
                    }

                    j.InjectedProcess.Replacements.Clear();
                    foreach (KeyValuePair <string, string> kv in values)
                    {
                        Converters.Parameter param = new Parameter();
                        param.FormalParameter      = kv.Key.Trim();
                        param.ReplacementParameter = kv.Value.Trim();
                        o2Mate.Expression expr = new o2Mate.Expression();
                        o2Mate.IData      res  = expr.Evaluate(kv.Value.Trim(), proc.CurrentScope);
                        param.EffectiveParameter = res.ValueString;
                        param.IsComputable       = res.IsComputable;
                        j.InjectedProcess.Replacements.Add(param);
                    }

                    this.cachedComp.Injection(j, doc.DocumentElement, modifier);
                    // le processus a été modifié
                    j.InjectedProcess.HasChanged = true;
                }
            }
            else
            {
                throw new FormatException("Format de la commande '" + this.command + "' inattendue");
            }
        }