예제 #1
0
 public void WriteToFile(IProcessInstance proc, FinalFile file)
 {
     if (proc.CurrentDictionnaire.IsArray(this.tabName))
     {
         Array             arr    = proc.CurrentDictionnaire.GetArray(this.tabName) as Array;
         Fields            f      = null;
         o2Mate.Expression expr   = new o2Mate.Expression();
         IData             result = expr.Evaluate(this.expression, proc.CurrentScope);
         if (result != null)
         {
             if (result.ValueInt <= arr.Count)
             {
                 f = arr.Item(result.ValueInt) as Fields;
             }
         }
         else
         {
             if (arr.Count > 0)
             {
                 f = arr.Item(1) as Fields;
             }
         }
         if (f != null && f.Exists(this.fieldName))
         {
             if (proc.CurrentScope.Exists(proc.DefaultWriter))
             {
                 string writer = proc.CurrentScope.GetVariable(proc.DefaultWriter).ValueString;
                 FinalFile.WriteToFile(ref writer, f.GetString(this.fieldName), this.enc);
                 proc.CurrentScope.GetVariable(proc.DefaultWriter).Value = writer;
                 proc.CurrentProject.Add(new ProjectItem(proc.Name, proc.CurrentPositionExecution, "print field", this.tabName, this.fieldName));
             }
         }
     }
 }
예제 #2
0
        public void WriteToFile(IProcessInstance proc, FinalFile file)
        {
            o2Mate.Expression expr   = new o2Mate.Expression();
            IData             result = expr.Evaluate(this.expression, proc.CurrentScope);

            if (result != null)
            {
                if (proc.CurrentScope.Exists(this.varName))
                {
                    IData d = proc.CurrentScope.GetVariable(this.varName);
                    d.Value        = result.ValueString;
                    d.IsComputable = result.IsComputable;
                }
                else
                {
                    proc.CurrentScope.Add(this.varName, result.ValueString, proc.Name, result.IsComputable);
                }
            }
            else
            {
                if (proc.CurrentScope.Exists(this.varName))
                {
                    IData d = proc.CurrentScope.GetVariable(this.varName);
                    d.Value        = "0";
                    d.IsComputable = true;
                }
                else
                {
                    proc.CurrentScope.Add(this.varName, "0", proc.Name, true);
                }
            }
            proc.CurrentProject.Add(new ProjectItem(proc.Name, proc.CurrentPositionExecution, "affectation", this.varName));
        }
예제 #3
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);
 }
예제 #4
0
        /// <summary>
        /// Assumes to be a calculable expression
        /// Evaluates the expression and returns the value
        /// </summary>
        /// <param name="comp">compilation</param>
        /// <param name="proc">process</param>
        /// <param name="converter">language converter</param>
        /// <param name="expression">expression</param>
        /// <returns>a standalone variable object (do not add into the scope)</returns>
        private static IDataNotInScope ComputeExpression(ICompilateur comp, IProcessInstance proc, ICodeConverter converter, string expression)
        {
            // print expression with all variables and additional source
            o2Mate.Expression expr = new o2Mate.Expression();
            IDataNotInScope   val  = expr.Evaluate(expression, proc.CurrentScope);

            return(val);
        }
예제 #5
0
 public void WriteToFile(IProcessInstance proc, FinalFile file)
 {
     if (proc.CurrentDictionnaire.IsArray(this.tabName))
     {
         Array             arr    = proc.CurrentDictionnaire.GetArray(this.tabName) as Array;
         o2Mate.Expression expr   = new o2Mate.Expression();
         IData             result = expr.Evaluate(this.expression, proc.CurrentScope);
         Fields            f      = null;
         if (result != null)
         {
             if (result.ValueInt <= arr.Count)
             {
                 f = arr.Item(result.ValueInt) as Fields;
             }
         }
         else
         {
             if (arr.Count > 0)
             {
                 f = arr.Item(1) as Fields;
             }
         }
         if (f != null && f.Exists(this.fieldName))
         {
             if (proc.CurrentScope.Exists(this.varName))
             {
                 IData d = proc.CurrentScope.GetVariable(this.varName);
                 d.Value        = f.GetString(this.fieldName);
                 d.IsComputable = false;
             }
             else
             {
                 proc.CurrentScope.Add(this.varName, f.GetString(this.fieldName), proc.Name, false);
                 proc.CurrentProject.Add(new ProjectItem(proc.Name, proc.CurrentPositionExecution, "dictionary field", this.varName, this.tabName, this.fieldName));
             }
         }
         else
         {
             if (proc.CurrentScope.Exists(this.varName))
             {
                 IData d = proc.CurrentScope.GetVariable(this.varName);
                 d.Value        = "0";
                 d.IsComputable = false;
             }
             else
             {
                 proc.CurrentScope.Add(this.varName, "0", proc.Name, false);
             }
         }
     }
 }
예제 #6
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);
     }
 }
예제 #7
0
        public void Convert(Converters.ICodeConverter converter, IProcessInstance proc, FinalFile file)
        {
            o2Mate.Expression expr = new o2Mate.Expression();
            this.directories = new List <string>();
            for (int index = 0; index < this.filePath.Count - 1; ++index)
            {
                string expression = this.filePath[index];
                string path       = Helper.ConvertNewExpression(this.cachedComp, proc, converter, expression, EnumDataType.E_STRING_OBJECT);
                this.directories.Add(path);
            }
            this.fileName = new List <string>();
            {
                string   expression = this.filePath[this.filePath.Count - 1];
                string[] split      = expression.Split('.');
                foreach (string s in split)
                {
                    string path = Helper.ConvertNewExpression(this.cachedComp, proc, converter, s, EnumDataType.E_STRING_OBJECT);
                    this.fileName.Add(path);
                }
            }

            if (proc.CurrentScope.Exists(this.writerName))
            {
                this.newWriter = proc.CurrentScope.GetVariable(this.writerName);
                if (this.newWriter.TypeExists(EnumDataType.E_WRITER))
                {
                    proc.CurrentScope.Update(this.writerName, "", this.newWriter.PrefixInfo(EnumDataType.E_WRITER).BelongsTo, false, EnumDataType.E_WRITER);
                    this.cachedComp.UpdateParameters(converter, proc, this.writerName, true);
                }
                else
                {
                    this.newWriter = proc.CurrentScope.Update(this.writerName, "", proc.Name, false, EnumDataType.E_WRITER);
                    IStructure st = converter.CreateNewField(converter.RootStructureInstance, this.newWriter, false);
                    converter.CurrentFunction.LocalVariables.Add(st);
                }
            }
            else
            {
                this.newWriter = proc.CurrentScope.Add(this.writerName, "", proc.Name, false, EnumDataType.E_WRITER);
                IStructure st = converter.CreateNewField(converter.RootStructureInstance, this.newWriter, false);
                converter.CurrentFunction.LocalVariables.Add(st);
            }
            converter.Convert(this);
        }
예제 #8
0
        public void WriteToFile(IProcessInstance proc, FinalFile file)
        {
            int nextPosition;

            o2Mate.Expression expr   = new o2Mate.Expression();
            IData             result = expr.Evaluate(this.expression, proc.CurrentScope);

            if (result != null)
            {
                if (result.ValueInt == 1)
                {
                    nextPosition = proc.GetPositionLabel(this.labelTrue);
                    proc.CurrentProject.Add(new ProjectItem(proc.Name, proc.CurrentPositionExecution, "goto", this.labelTrue));
                }
                else
                {
                    nextPosition = proc.GetPositionLabel(this.labelFalse);
                    proc.CurrentProject.Add(new ProjectItem(proc.Name, proc.CurrentPositionExecution, "goto", this.labelFalse));
                }
                proc.CurrentPositionExecution = nextPosition;
            }
        }
예제 #9
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));
            }
        }
예제 #10
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");
            }
        }
예제 #11
0
        /// <summary>
        /// Process this statement and writes results in a file
        /// </summary>
        /// <param name="proc">process object</param>
        /// <param name="file">final file object</param>
        public void WriteToFile(IProcessInstance proc, FinalFile file)
        {
            proc.CurrentProject.Add(new ProjectItem(proc.Name, proc.CurrentPositionExecution, "use mop", this.Language, this.Command));
            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);
                // évaluation de l'expression (liste)
                string[] tab;
                if (!String.IsNullOrEmpty(this.expression))
                {
                    o2Mate.Expression expr   = new o2Mate.Expression();
                    IData             result = expr.Evaluate("array(" + this.expression + ")", proc.CurrentScope);
                    tab = result.ValueString.Split(',');
                }
                else
                {
                    tab = new string[0];
                }
                // remplacement des valeurs
                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]] += String.Join(",", tab, index, tab.Length - index);
                }
                string code = mopSrc.ReplaceParams(values);
                // charge dans le compilateur l'extrait de code du mop
                XmlDocument doc = new XmlDocument();
                doc.PreserveWhitespace = false;
                doc.LoadXml("<code>" + code + "</code>");
                if (skeletonPath.Count == 0 || String.IsNullOrEmpty(modifier))
                {
                    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");
                }
                else
                {
                    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);
                    if (modifier == "replace")
                    {
                        // 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;
                    }
                    this.cachedComp.Injection(j, doc.DocumentElement, modifier);
                }
            }
            else
            {
                throw new FormatException("Format de la commande '" + this.command + "' inattendue");
            }
        }
예제 #12
0
        /// <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);
        }