Esempio n. 1
0
        public void WriteInMicrosoftCPP(ICodeConverter converter)
        {
            // aller chercher les variables exterieures au processus appellé
            IFunction f = converter.ImplementedFunctions.FindLast(new Predicate <IFunction>(delegate(IFunction func) { return(func.IsJob && func.StrictName == this.processName); }));

            if (!converter.CallingFunctions.Exists(new Predicate <IFunction>(delegate(IFunction func) { return(func.IsJob && func.StrictName == this.processName && func.InstanceNumber == f.InstanceNumber); })))
            {
                converter.CallingFunctions.Add(f);
            }

            ++converter.CurrentFunction.PrivateVariableCounter;
            // obligé de créer une nouvelle fonction à implementer
            IFunction jobFunc = new Function();

            jobFunc.StrictName     = f.StrictName;
            jobFunc.InstanceNumber = f.InstanceNumber;
            // indiquer le paramètre de la structure comme étant void *
            IParameter param = f.Parameters[0].Clone() as IParameter;

            param.DataType           = EnumDataType.E_VOID;
            param.IsMutableParameter = true;
            jobFunc.Parameters.Add(param);
            jobFunc.AddToSource("job_" + f.Name + "((" + this.StructureReference.StructureType + "*)" + param.EffectiveParameter + ");" + Environment.NewLine);
            if (!converter.ImplementedFunctions.Exists(new Predicate <IFunction>(delegate(IFunction func) { return(!func.IsJob && func.StrictName == jobFunc.StrictName && func.InstanceNumber == jobFunc.InstanceNumber); })))
            {
                converter.ImplementedFunctions.Add(jobFunc);
            }
            if (!converter.CallingFunctions.Exists(new Predicate <IFunction>(delegate(IFunction func) { return(!func.IsJob && func.StrictName == jobFunc.StrictName && func.InstanceNumber == jobFunc.InstanceNumber); })))
            {
                converter.CallingFunctions.Add(jobFunc);
            }

            string localName = "p" + converter.CurrentFunction.PrivateVariableCounter.ToString();

            converter.CurrentFunction.AddToSource("Parallel " + localName +
                                                  "((void*)&" + this.StructureReference.PrefixedFieldName + ", gcnew Parallel::worker(this, &Compiled::" +
                                                  "func_" + jobFunc.Name + "));" + Environment.NewLine);
            converter.CurrentFunction.AddToSource(localName + ".Start();" + Environment.NewLine);
        }