예제 #1
0
 public MacroEntry(MacroEntry other)
 {
     Id          = other.Id;
     Enabled     = other.Enabled;
     Type        = other.Type;
     Binding     = new MacroBinding(other.Binding);
     Function    = other.Function.Clone() as MacroFunction;
     Description = other.Description;
 }
예제 #2
0
        private void GenerateMacro_OptimizedBodyCallCode()
        {
            var itemText = MacroBinding.GenerateMacroBodyCallCode(
                AstMacroBodyKind.OptimizedCompiledBody,
                true
                );

            MacroCodeGenerator.ReportNormal("Optimized Body Call Code", itemText);
        }
예제 #3
0
        private void GenerateMacro_ParsedBodyCallCode()
        {
            var itemText = MacroBinding.GenerateMacroBodyCallCode(
                AstMacroBodyKind.ParsedBody,
                true
                );

            MacroCodeGenerator.ReportNormal("Parsed Body Call Code", itemText);
        }
예제 #4
0
        private void AddMacroParameterBinding(string line)
        {
            var eqIndex = line.IndexOf('=');

            if (eqIndex < 0)
            {
                MacroBinding.BindToVariables(line);

                return;
            }

            var lhs = line.Substring(0, eqIndex - 1).Trim();
            var rhs = line.Substring(eqIndex + 1).Trim();

            MacroBinding.BindScalarToConstant(lhs, rhs);
        }
예제 #5
0
 public MacroEntry()
 {
     Binding = new MacroBinding();
 }
예제 #6
0
        /// <summary>
        /// Generate optimized macro code in the target language given a list of macro parameters bindings
        /// </summary>
        /// <returns></returns>
        public override string Generate()
        {
            //Initialize components of macro code generator
            SyntaxList.Clear();

            MacroBinding.Clear();

            CodeBlock = null;

            TargetVariablesNaming = null;

            if (AllowGenerateMacroCode == false)
            {
                return(string.Empty);
            }

            LibraryComposer.CheckProgressRequestStop();

            var progressId = this.ReportStart(
                "Generating Macro Code For: " + BaseMacro.AccessName
                );

            try
            {
                //Bind macro parameters to variables and constants as needed
                if (ActionSetMacroParametersBindings == null)
                {
                    DefaultActionSetMacroParametersBindings(MacroBinding);
                }
                else
                {
                    ActionSetMacroParametersBindings(MacroBinding);
                }

                if (IsMacroBindingReady == false)
                {
                    this.ReportWarning("Macro Binding Not Ready", MacroBinding.ToString());
                    this.ReportFinish(progressId);

                    return(string.Empty);
                }

                this.ReportNormal("Macro Binding Ready", MacroBinding.ToString());

                //Create the optimizd code block holding abstract computations based on the macro parameters
                //bindings. This step is typically the most time consuming because of many symbolic computations
                CodeBlock = MacroBinding.CreateOptimizedCodeBlock();


                //Assign target variable names to low-level code block variables. The code block is generated
                //automatically in the call to the OptimizedCodeBlock member
                TargetVariablesNaming = new GMacTargetVariablesNaming(GMacLanguage, CodeBlock);

                if (ActionSetTargetVariablesNames == null)
                {
                    DefaultActionSetTargetVariablesNames(TargetVariablesNaming);
                }
                else
                {
                    ActionSetTargetVariablesNames(TargetVariablesNaming);
                }


                //Generate code before computations for comments, temp declarations, and the like
                var result =
                    ActionBeforeGenerateComputations == null
                        ? DefaultActionBeforeGenerateComputations(this)
                        : ActionBeforeGenerateComputations(this);


                //Generate computations code if allowed by last action result
                if (result)
                {
                    GenerateProcessingCode();
                }


                //Generate code after computations for comments, temp destruction, and the like
                if (ActionAfterGenerateComputations == null)
                {
                    DefaultActionAfterGenerateComputations(this);
                }
                else
                {
                    ActionAfterGenerateComputations(this);
                }
            }
            catch (Exception e)
            {
                this.ReportError(e);
            }

            //Clean everything up and return final generated code
            ExpressionConverter.ActiveCodeBlock = null;

            //Un-parse the SyntaxList into the final code
            var codeText = CodeGenerator.GenerateCode(SyntaxList);

            this.ReportFinish(progressId, codeText);

            return(codeText);
        }
예제 #7
0
        private void GenerateMacro()
        {
            listBoxGenerationStage.Items.Clear();

            textBoxDisplay.Text = String.Empty;

            Graph = null;

            if (UpdateMacroBindingTextData() == false)
            {
                return;
            }

            GMacSystemUtils.ResetProgress();

            MacroBinding = GMacMacroBinding.Create(SelectedMacro);

            MacroCodeGenerator = new SingleMacroGen(MacroBinding)
            {
                MacroGenDefaults = { AllowGenerateMacroCode = true }
            };

            foreach (var bindingData in BindingTextData.Bindings)
            {
                if (bindingData.IsConstantBinding)
                {
                    MacroBinding.BindScalarToConstant(
                        bindingData.ValueAccessName,
                        bindingData.ConstantValueText
                        );

                    continue;
                }

                var testValueExpr =
                    bindingData.HasTestValue
                    ? bindingData.TestValueText.ToExpr(SymbolicUtils.Cas)
                    : null;

                MacroBinding.BindToVariables(bindingData.ValueAccessName, testValueExpr);

                if (bindingData.HasTargetVariableName)
                {
                    MacroCodeGenerator
                    .TargetVariablesNamesDictionary.Add(
                        bindingData.ValueAccessName,
                        bindingData.TargetVariableName
                        );
                }
            }

            GenerateMacro_DslCode();

            GenerateMacro_ParsedBody();

            GenerateMacro_CompiledBody();

            GenerateMacro_OptimizedBody();

            GenerateMacro_RawBodyCallCode();

            GenerateMacro_ParsedBodyCallCode();

            GenerateMacro_CompiledBodyCallCode();

            GenerateMacro_OptimizedBodyCallCode();

            GenerateMacro_SampleTargetCode();

            ProgressHistory =
                MacroCodeGenerator
                .Progress
                .History
                .ReadHistory()
                .ToDictionary(item => item.ProgressId);

            foreach (var item in ProgressHistory)
            {
                listBoxGenerationStage.Items.Add(item.Value.FullTitle);
            }

            Graph = MacroCodeGenerator.Graph;
        }