/// <summary>
 /// Defines or update a variable object stored in the scope; the variable data type is an integer only
 /// Because of assigned from the size of an array, the variable is never computable;
 /// if the variable was computable, it won't be
 /// As the variable value has changed, make a mutable parameter if any
 /// As the variable was not exist in the scope, the variable prefixed name (with a type's prefix) is stored in local
 /// Identical from ConvertNewDictionaryString except a different data type
 /// </summary>
 /// <param name="comp">compilation</param>
 /// <param name="proc">process</param>
 /// <param name="converter">language converter</param>
 /// <param name="varName">variable name to be stored in the scope</param>
 /// <returns>an added variable object stored in the scope</returns>
 public static IData ConvertNewDictionarySize(ICompilateur comp, IProcessInstance proc, ICodeConverter converter, string varName)
 {
     // control if variable is in the scope
     if (proc.CurrentScope.Exists(varName))
     {
         // get the variable infos
         IData myVar = proc.CurrentScope.GetVariable(varName);
         // update variable
         if (myVar.TypeExists(EnumDataType.E_NUMBER))
         {
             proc.CurrentScope.Update(varName, "",
                                      myVar.PrefixInfo(EnumDataType.E_NUMBER).BelongsTo,
                                      false, EnumDataType.E_NUMBER);
         }
         else
         {
             proc.CurrentScope.Update(varName, "", myVar.BelongsTo, false, EnumDataType.E_NUMBER);
         }
         // on met à jour les paramètres en indiquant que la variable est mutable
         comp.UpdateParameters(converter, proc, varName, true);
         return(myVar);
     }
     else
     {
         // créer une nouvelle variable dans le scope; en déduire qu'elle est locale
         IData added = proc.CurrentScope.Add(varName, "", proc.Name, false, EnumDataType.E_NUMBER);
         Helper.AddIntoLocal(converter, added);
         return(added);
     }
 }
Exemple #2
0
 /// <summary>
 /// Saving the object into an xml node
 /// </summary>
 /// <param name="comp">this compiler</param>
 /// <param name="writer">Xml writer object</param>
 /// <param name="child">html child for nested objects</param>
 public void Save(ICompilateur comp, System.Xml.XmlWriter writer, ref System.Windows.Forms.HtmlElement child)
 {
     writer.WriteStartElement("createmop");
     writer.WriteAttributeString("language", this.language);
     writer.WriteAttributeString("name", this.name);
     if (this.indent > 0)
     {
         writer.WriteAttributeString("indent", this.indent.ToString());
     }
     writer.WriteStartElement("legendes");
     this.legendes.Save(writer);
     writer.WriteEndElement();
     writer.WriteStartElement("references");
     foreach (string param in this.refs)
     {
         writer.WriteStartElement("ref");
         writer.WriteString(param);
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
     writer.WriteStartElement("code");
     writer.WriteRaw(this.xmlCode);
     writer.WriteEndElement();
     writer.WriteEndElement();
     child = child.NextSibling;
 }
Exemple #3
0
 public void Parse(ICompilateur comp, System.Xml.XmlNode node)
 {
     if (node.Attributes.GetNamedItem("indent") != null)
     {
         Int32.TryParse(node.Attributes.GetNamedItem("indent").Value, out this.indent);
     }
 }
        /// <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);
        }
 public void Parse(ICompilateur comp, System.Xml.XmlNode node)
 {
     if (node.Attributes.GetNamedItem("indent") != null)
     {
         Int32.TryParse(node.Attributes.GetNamedItem("indent").Value, out this.indent);
     }
     comp.Parse(comp, node.SelectSingleNode("code"));
 }
        /// <summary>
        /// Convert the expression with the desired data type
        /// </summary>
        /// <param name="comp">compilation</param>
        /// <param name="proc">process</param>
        /// <param name="converter">language converter</param>
        /// <param name="expression">expression</param>
        /// <param name="desiredType">desired type conversion</param>
        /// <returns>standalone variable with the result value (do not add into the scope)</returns>
        private static IDataNotInScope ConvertExpression(ICompilateur comp, IProcessInstance proc, ICodeConverter converter, string expression, o2Mate.EnumDataType desiredType)
        {
            // does add additional statements
            o2Mate.Expression.Convert(converter, expression, proc.CurrentScope, true, desiredType, true);
            IDataNotInScope res = new Variable("", false, converter.CurrentFunction.DataTypeResult);

            res.Value = converter.CurrentFunction.CacheSource;
            return(res);
        }
 public void Parse(ICompilateur comp, System.Xml.XmlNode node)
 {
     if (node.Attributes.GetNamedItem("indent") != null)
     {
         Int32.TryParse(node.Attributes.GetNamedItem("indent").Value, out this.indent);
     }
     this.varName    = node.SelectSingleNode("variable").InnerText;
     this.expression = node.SelectSingleNode("expression").InnerText;
 }
 /// <summary>
 /// Parse is not load
 /// </summary>
 /// <param name="comp">compiler object</param>
 /// <param name="node">xml node from reading</param>
 public void Parse(ICompilateur comp, System.Xml.XmlNode node)
 {
     if (node.Attributes.GetNamedItem("indent") != null)
     {
         Int32.TryParse(node.Attributes.GetNamedItem("indent").Value, out this.indent);
     }
     this.language   = node.Attributes.GetNamedItem("language").Value;
     this.command    = node.Attributes.GetNamedItem("command").Value;
     this.expression = node.Attributes.GetNamedItem("expression").Value;
 }
Exemple #9
0
 public void Save(ICompilateur comp, System.Xml.XmlWriter writer, ref System.Windows.Forms.HtmlElement child)
 {
     writer.WriteStartElement("br");
     if (this.indent > 0)
     {
         writer.WriteAttributeString("indent", this.indent.ToString());
     }
     writer.WriteEndElement();
     child = child.NextSibling;
 }
 /// <summary>
 /// Parse is not load
 /// </summary>
 /// <param name="comp">compiler object</param>
 /// <param name="node">xml node from reading</param>
 public void Parse(ICompilateur comp, XmlNode node)
 {
     if (node.Attributes.GetNamedItem("indent") != null)
     {
         Int32.TryParse(node.Attributes.GetNamedItem("indent").Value, out this.indent);
     }
     this.name = node.Attributes.GetNamedItem("name").Value;
     this.legendes.Load(node.SelectSingleNode("legendes"));
     this.xmlCode = node.SelectSingleNode("code").InnerXml;
 }
Exemple #11
0
        public void Parse(ICompilateur comp, System.Xml.XmlNode node)
        {
            if (node.Attributes.GetNamedItem("indent") != null)
            {
                Int32.TryParse(node.Attributes.GetNamedItem("indent").Value, out this.indent);
            }
            // remove whitespace
            string innerText = node.InnerText;

            this.text = innerText.Replace(" ", "").Replace("\t", "").Replace("\n\r", "");
        }
 /// <summary>
 /// Save this statement into an xml file
 /// </summary>
 /// <param name="comp">compiler object</param>
 /// <param name="writer">xml writer object</param>
 /// <param name="child">html child to save</param>
 public void Save(ICompilateur comp, System.Xml.XmlWriter writer, ref System.Windows.Forms.HtmlElement child)
 {
     writer.WriteStartElement("usemop");
     writer.WriteAttributeString("language", this.language);
     writer.WriteAttributeString("command", this.command);
     writer.WriteAttributeString("expression", this.expression);
     if (this.indent > 0)
     {
         writer.WriteAttributeString("indent", this.indent.ToString());
     }
     writer.WriteEndElement();
     child = child.NextSibling;
 }
        /// <summary>
        /// Create a dependant variable : it's a stored variable in a specific use template (implemented for a specific language)
        /// the variable has a data type fixed. If it's not the same, the variable value is converted into the good data type
        /// if needed, this variable makes a mutable parameter
        /// </summary>
        /// <param name="comp">compiler object</param>
        /// <param name="converter">language converter</param>
        /// <param name="proc">process</param>
        /// <param name="ut">UseTemplate object</param>
        /// <param name="valueName">name of the variable</param>
        /// <param name="desiredDataType">fixed data type</param>
        /// <returns>the name of the variable (it comes to non computable)</returns>
        public static string CreateDependantVariable(ICompilateur comp, ICodeConverter converter, IProcessInstance proc, UseTemplate ut, string valueName, EnumDataType desiredDataType)
        {
            string var = valueName;

            if (ut.Parameters.ContainsKey(valueName))
            {
                var = Helper.ReplaceStringParameter(ut, valueName);
            }
            // important : la variable n'est plus calculable
            IData newVar = Helper.ConvertNonComputableVariableType(proc, converter, var, desiredDataType);

            comp.UpdateParameters(converter, proc, newVar.Name, true);
            return(converter.ReturnVarName(newVar));
        }
        /// <summary>
        /// Use this function to convert an expression which can be computable or not
        /// Returns a variable object to do not store in the scope
        /// Supply the type to convert
        /// </summary>
        /// <param name="comp">compilation</param>
        /// <param name="proc">process</param>
        /// <param name="converter">language converter</param>
        /// <param name="expression">expression</param>
        /// <param name="desiredType">desired data type result</param>
        /// <returns>a string with the converted expression</returns>
        public static string ConvertNewExpression(ICompilateur comp, IProcessInstance proc, ICodeConverter converter, string expression, o2Mate.EnumDataType desiredType)
        {
            // convert inline expression using variables stored in scope
            // does add additional statements
            o2Mate.Expression.Convert(converter, expression, proc.CurrentScope, true, desiredType, true);

            // since variable is used, check to all used variable, needed to clarify locals or parameters
            foreach (string used in converter.CurrentFunction.UsedVariables)
            {
                comp.UpdateParameters(converter, proc, used, false);
            }

            return(converter.CurrentFunction.CacheSource);
        }
 public void Save(ICompilateur comp, System.Xml.XmlWriter writer, ref System.Windows.Forms.HtmlElement child)
 {
     writer.WriteStartElement("parallel");
     if (this.indent > 0)
     {
         writer.WriteAttributeString("indent", this.indent.ToString());
     }
     writer.WriteStartElement("code");
     // search next sibling child of code
     System.Windows.Forms.HtmlElement subElement = child.NextSibling;
     comp.Save(writer, ref subElement, this.indent + 1);
     writer.WriteEndElement();
     writer.WriteEndElement();
     child = subElement;
 }
 public void Save(ICompilateur comp, System.Xml.XmlWriter writer, ref System.Windows.Forms.HtmlElement child)
 {
     writer.WriteStartElement("affectation");
     if (this.indent > 0)
     {
         writer.WriteAttributeString("indent", this.indent.ToString());
     }
     writer.WriteStartElement("variable");
     writer.WriteString(this.varName);
     writer.WriteEndElement();
     writer.WriteStartElement("expression");
     writer.WriteString(this.expression);
     writer.WriteEndElement();
     writer.WriteEndElement();
     child = child.NextSibling;
 }
Exemple #17
0
 public void Parse(ICompilateur comp, System.Xml.XmlNode node)
 {
     if (node.Attributes.GetNamedItem("indent") != null)
     {
         Int32.TryParse(node.Attributes.GetNamedItem("indent").Value, out this.indent);
     }
     this.writerName = node.Attributes.GetNamedItem("name").Value;
     this.filePath   = new List <string>();
     if (node.SelectNodes("file")[0].FirstChild != null)
     {
         foreach (XmlNode paramNode in node.SelectNodes("file/expression"))
         {
             string paramValue = paramNode.InnerText;
             this.filePath.Add(paramValue);
         }
     }
 }
 /// <summary>
 /// Save the statement into an xml file
 /// </summary>
 /// <param name="comp">compiler object</param>
 /// <param name="writer">xml writer object</param>
 /// <param name="child">html child to save</param>
 public void Save(ICompilateur comp, XmlWriter writer, ref System.Windows.Forms.HtmlElement child)
 {
     writer.WriteStartElement("syntax");
     writer.WriteAttributeString("name", this.name);
     if (this.indent > 0)
     {
         writer.WriteAttributeString("indent", this.indent.ToString());
     }
     writer.WriteStartElement("legendes");
     this.legendes.Save(writer);
     writer.WriteEndElement();
     writer.WriteStartElement("code");
     writer.WriteRaw(this.xmlCode);
     writer.WriteEndElement();
     writer.WriteEndElement();
     child = child.NextSibling;
 }
        /// <summary>
        /// Dans le cas où la variable n'est pas ou plus calculable
        /// Enregistre une expression dans une variable incalculable permettant d'utiliser l'expression
        /// dans la conversion d'une variable assignée dont le type est défini par l'inférence de l'expression
        /// </summary>
        /// <param name="comp">compilateur</param>
        /// <param name="proc">process</param>
        /// <param name="converter">langage de conversion</param>
        /// <param name="expression">expression</param>
        /// <param name="varName">variable</param>
        /// <returns>l'objet variable utilisé</returns>
        private static IData ConvertExpression(ICompilateur comp, IProcessInstance proc, ICodeConverter converter, string expression, string varName)
        {
            EnumDataType fixedDataType = converter.CurrentFunction.DataTypeResult;

            // 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);
                // the variable exists in the scope, assumed infer the data type from expression
                // include additional statements for converting expression
                o2Mate.Expression.Convert(converter, expression, proc.CurrentScope, true, fixedDataType, true);
                if (myVar.TypeExists(fixedDataType))
                {
                    proc.CurrentScope.Update(varName,
                                             converter.CurrentFunction.CacheSource,
                                             myVar.PrefixInfo(fixedDataType).BelongsTo, false,
                                             fixedDataType);
                }
                else
                {
                    // le nouveau type de données de cette variable doit appartenir au processus
                    // qui a initialisé la variable
                    proc.CurrentScope.Update(varName,
                                             converter.CurrentFunction.CacheSource,
                                             myVar.BelongsTo, false,
                                             fixedDataType);
                }
                // on met à jour les paramètres en indiquant que cette variable est mutable
                comp.UpdateParameters(converter, proc, varName, true);
                return(myVar);
            }
            else
            {
                // convert expression including variable name
                o2Mate.Expression.Convert(converter, expression, proc.CurrentScope, true, fixedDataType, true);
                // create variable, don't use value and assumes to be non-computable and infer data type by the expression
                IData added = proc.CurrentScope.Add(varName,
                                                    converter.CurrentFunction.CacheSource, proc.Name, false,
                                                    fixedDataType);
                Helper.AddIntoLocal(converter, added);
                return(added);
            }
        }
Exemple #20
0
 /// <summary>
 /// Parse but not load
 /// </summary>
 /// <param name="comp">this compiler</param>
 /// <param name="node">xml node to read</param>
 public void Parse(ICompilateur comp, System.Xml.XmlNode node)
 {
     if (node.Attributes.GetNamedItem("indent") != null)
     {
         Int32.TryParse(node.Attributes.GetNamedItem("indent").Value, out this.indent);
     }
     this.language = node.Attributes.GetNamedItem("language").Value;
     this.name     = node.Attributes.GetNamedItem("name").Value;
     this.legendes.Load(node.SelectSingleNode("legendes"));
     this.refs.Clear();
     foreach (XmlNode paramNode in node.SelectNodes("references/ref"))
     {
         if (!this.refs.Contains(paramNode.InnerText))
         {
             this.refs.Add(paramNode.InnerText);
         }
     }
     this.xmlCode = node.SelectSingleNode("code").InnerXml;
 }
 /// <summary>
 /// Parse is not load
 /// </summary>
 /// <param name="comp">compiler object</param>
 /// <param name="node">xml node from reading</param>
 public void Parse(ICompilateur comp, System.Xml.XmlNode node)
 {
     if (node.Attributes.GetNamedItem("indent") != null)
     {
         Int32.TryParse(node.Attributes.GetNamedItem("indent").Value, out this.indent);
     }
     this.path = node.Attributes.GetNamedItem("path").Value;
     this.name = node.Attributes.GetNamedItem("name").Value;
     this.legendes.Load(node.SelectSingleNode("legendes"));
     this.pars = new Dictionary <string, string>();
     foreach (XmlNode paramNode in node.SelectNodes("params/param"))
     {
         if (!this.pars.ContainsKey(paramNode.InnerText))
         {
             this.pars.Add(paramNode.InnerText, "");
         }
     }
     this.xmlCode = node.SelectSingleNode("code").InnerXml;
 }
Exemple #22
0
 public void Save(ICompilateur comp, System.Xml.XmlWriter writer, ref System.Windows.Forms.HtmlElement child)
 {
     writer.WriteStartElement("createwriter");
     writer.WriteAttributeString("name", this.writerName);
     if (this.indent > 0)
     {
         writer.WriteAttributeString("indent", this.indent.ToString());
     }
     writer.WriteStartElement("file");
     foreach (string expression in this.filePath)
     {
         writer.WriteStartElement("expression");
         writer.WriteString(expression);
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
     writer.WriteEndElement();
     child = child.NextSibling;
 }
 public void Save(ICompilateur comp, System.Xml.XmlWriter writer, ref System.Windows.Forms.HtmlElement child)
 {
     writer.WriteStartElement("condition");
     if (this.indent > 0)
     {
         writer.WriteAttributeString("indent", this.indent.ToString());
     }
     writer.WriteStartElement("expression");
     writer.WriteString(this.expression);
     writer.WriteEndElement();
     writer.WriteStartElement("iftrue");
     writer.WriteString(this.labelTrue);
     writer.WriteEndElement();
     writer.WriteStartElement("iffalse");
     writer.WriteString(this.labelFalse);
     writer.WriteEndElement();
     writer.WriteEndElement();
     child = child.NextSibling;
 }
        /// <summary>
        /// Create an expression : expression is written for a specific use template (implemented for a specific language)
        /// the expression is converted if the infered data type in the expression is not the fixed data type
        /// </summary>
        /// <param name="converter">language converter</param>
        /// <param name="comp">compilation</param>
        /// <param name="proc">process</param>
        /// <param name="ut">UseTemplate object</param>
        /// <param name="valueName">name of the variable</param>
        /// <param name="defaultValue">initial value</param>
        /// <param name="desiredDataType">fixed data type</param>
        /// <returns>the converted expression</returns>
        public static string CreateExprVariable(ICodeConverter converter, ICompilateur comp, IProcessInstance proc, UseTemplate ut, string valueName, string defaultValue, EnumDataType desiredDataType)
        {
            // init
            string value = defaultValue;

            if (ut.Parameters.ContainsKey(valueName))
            {
                value = Helper.ReplaceStringParameter(ut, valueName);
            }

            // convertir l'expression
            o2Mate.Expression.Convert(converter, value, proc.CurrentScope, false, desiredDataType);

            // définir en paramètre les variables utilisées
            foreach (string used in converter.CurrentFunction.UsedVariables)
            {
                comp.UpdateParameters(converter, proc, used, false);
            }
            // convertir à nouveau l'expression mais avec des variables
            o2Mate.Expression.Convert(converter, value, proc.CurrentScope, true, desiredDataType, true);
            return(converter.CurrentFunction.CacheSource);
        }
        /// <summary>
        /// Use this function to convert an expression which can be computable or not
        /// Returns a variable object to do not store in the scope
        /// </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 with its value (do not store it in the scope)</returns>
        public static IDataNotInScope ConvertNewExpression(ICompilateur comp, IProcessInstance proc, ICodeConverter converter, string expression)
        {
            // convert inline expression using variables stored in scope
            // does not add additional statements
            o2Mate.Expression.Convert(converter, expression, proc.CurrentScope, false);

            // switch about calculability
            if (converter.CurrentFunction.IsComputableExpression)
            {
                // the value of the expression can be exactly computed among the execution
                return(Helper.ComputeExpression(comp, proc, converter, expression));
            }
            else
            {
                // since variable is not computable, check to all used variable, needed to clarify locals or parameters
                foreach (string used in converter.CurrentFunction.UsedVariables)
                {
                    comp.UpdateParameters(converter, proc, used, false);
                }
                // the value of the expression cannot be exactly computed among the execution
                return(Helper.ConvertExpression(comp, proc, converter, expression));
            }
        }
Exemple #26
0
 public void SetCompile(ICompilateur comp)
 {
     this.cachedComp = comp;
 }
 public void Parse(ICompilateur comp, System.Xml.XmlNode node)
 {
     this.localeName = node.InnerText;
 }
 public void Save(ICompilateur comp, System.Xml.XmlWriter writer, ref System.Windows.Forms.HtmlElement child)
 {
     throw new NotImplementedException();
 }
 public void Save(ICompilateur comp, System.Xml.XmlWriter writer, ref System.Windows.Forms.HtmlElement child)
 {
     writer.WriteStartElement("locale");
     writer.WriteString(this.localeName);
     writer.WriteEndElement();
 }
 public void Parse(ICompilateur comp, System.Xml.XmlNode node)
 {
     throw new NotImplementedException();
 }