/// <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 the data type, the prefix and the name /// </summary> /// <param name="instanceName">name of the structure instance (throw exception if not exists)</param> /// <param name="dataType">data type</param> /// <param name="fieldName">variable name</param> /// <param name="isMutable">mutable parameter</param> /// <returns>a structure object</returns> public IStructure CreateNewField(string instanceName, o2Mate.EnumDataType dataType, string fieldName, 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, fieldName, dataType, isMutable); if (!this.StructureNames.ContainsKey(typeName)) { this.StructureNames[typeName].Add(st); } return(st); }
/// <summary> /// Creates a new field into a structure to hold /// </summary> /// <param name="name">name of the instance structure</param> /// <param name="fieldName">field name</param> /// <param name="dataType">data type</param> /// <param name="isMutable">mutable switch</param> public Structure(string name, string fieldName, o2Mate.EnumDataType dataType, bool isMutable) { this.instanceName = name; this.asStructure = false; int posUnderscore = fieldName.IndexOf('_'); if (posUnderscore != -1) { this.prefixName = fieldName.Substring(0, posUnderscore + 1); this.fieldName = fieldName.Substring(posUnderscore + 1); } else { this.prefixName = o2Mate.Scope.StandardPrefix(dataType); this.fieldName = fieldName; } this.dataType = dataType; this.isMutable = isMutable; this.isGlobal = false; }
/// <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); }
/// <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); }