Example #1
0
 /// <summary>
 /// Generate the code for a single computation
 /// </summary>
 /// <param name="codeInfo"></param>
 protected virtual void GenerateSingleComputationCode(GMacComputationCodeInfo codeInfo)
 {
     //Generate assignment statement for this computation
     SyntaxList.Add(
         GMacLanguage
         .SyntaxFactory
         .AssignToLocalVariable(codeInfo.TargetVariableName, codeInfo.RhsExpressionCode)
         );
 }
Example #2
0
        /// <summary>
        /// Generate the low-level assignments code from the low-level optimized macro code
        /// </summary>
        private void GenerateProcessingCode()
        {
            ExpressionConverter.ActiveCodeBlock = CodeBlock;

            //Iterate over optimized low-level computations
            foreach (var computedVar in CodeBlock.ComputedVariables)
            {
                //Convert the rhs text expression tree into target language code
                var rhsExprCode =
                    ExpressionConverter.Convert(computedVar.RhsExpr);

                //Create the codeInfo object
                var codeInfo = new GMacComputationCodeInfo()
                {
                    ComputedVariable     = computedVar,
                    RhsExpressionCode    = rhsExprCode,
                    GMacLanguage         = GMacLanguage,
                    EnableCodeGeneration = true
                };

                //Generate the assignment target code based on the codeInfo object
                //Execute this action before generating computation code
                if (ReferenceEquals(ActionBeforeGenerateSingleComputation, null) == false)
                {
                    ActionBeforeGenerateSingleComputation(SyntaxList, codeInfo);
                }

                //If the action prevented generation of code don't generating computation code
                if (codeInfo.EnableCodeGeneration)
                {
                    GenerateSingleComputationCode(codeInfo);
                }

                //Execute this action after generating computation code
                if (ReferenceEquals(ActionAfterGenerateSingleComputation, null) == false)
                {
                    ActionAfterGenerateSingleComputation(SyntaxList, codeInfo);
                }
            }

            SyntaxList.AddEmptyLine();
        }