Exemple #1
0
        private void MakeRunnableIfNecessary()
        {
            var compilationOptions = CompilerUtil.ResolveCompilationOptions(_rootProject, _args.ConfigValue);

            // TODO: Make this opt in via another mechanism
            var makeRunnable = compilationOptions.EmitEntryPoint.GetValueOrDefault() ||
                               _rootProject.IsTestProject();

            if (makeRunnable)
            {
                var outputPathCalculator = _rootProject.GetOutputPathCalculator(_args.OutputValue);
                var rids = new List <string>();
                if (string.IsNullOrEmpty(_args.RuntimeValue))
                {
                    rids.AddRange(PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers());
                }
                else
                {
                    rids.Add(_args.RuntimeValue);
                }

                var runtimeContext = ProjectContext.Create(_rootProject.ProjectDirectory, _rootProject.TargetFramework, rids);
                var executable     = new Executable(runtimeContext, outputPathCalculator);
                executable.MakeCompilationOutputRunnable(_args.ConfigValue);
            }
        }
Exemple #2
0
        // computes all the inputs and outputs that would be used in the compilation of a project
        // ensures that all paths are files
        // ensures no missing inputs
        public static CompilerIO GetCompileIO(ProjectContext project, string config, string outputPath, string intermediaryOutputPath, ProjectDependenciesFacade dependencies)
        {
            var compilerIO = new CompilerIO(new List <string>(), new List <string>());

            // input: project.json
            compilerIO.Inputs.Add(project.ProjectFile.ProjectFilePath);

            // input: source files
            compilerIO.Inputs.AddRange(CompilerUtil.GetCompilationSources(project));

            // todo: Factor out dependency resolution between Build and Compile. Ideally Build injects the dependencies into Compile
            // todo: use lock file insteaf of dependencies. One file vs many
            // input: dependencies
            AddDependencies(dependencies, compilerIO);

            // input: key file
            AddKeyFile(project, config, compilerIO);

            // output: compiler output
            compilerIO.Outputs.Add(CompilerUtil.GetCompilationOutput(project.ProjectFile, project.TargetFramework, config, outputPath));

            // input / output: resources without culture
            AddCultureResources(project, intermediaryOutputPath, compilerIO);

            // input / output: resources with culture
            AddNonCultureResources(project, outputPath, compilerIO);

            return(compilerIO);
        }
        public override void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, System.CodeDom.CodeMemberMethod method, System.CodeDom.CodeStatementCollection statements, bool debug)
        {
            IMathExpression mathExp = MathExp;

            if (mathExp != null)
            {
                CodeExpression ceCondition = null;
                if (Condition != null)
                {
                    ceCondition = Condition.ExportCode(methodToCompile);
                    if (ceCondition != null)
                    {
                        ceCondition = CompilerUtil.ConvertToBool(Condition.DataType, ceCondition);
                    }
                }
                CodeExpression ce = mathExp.ReturnCodeExpression(methodToCompile);
                if (ce != null)
                {
                    if (ceCondition == null)
                    {
                        statements.Add(new CodeMethodReturnStatement(ce));
                    }
                    else
                    {
                        CodeConditionStatement cd = new CodeConditionStatement();
                        cd.Condition = ceCondition;
                        cd.TrueStatements.Add(new CodeMethodReturnStatement(ce));
                        statements.Add(cd);
                    }
                }
            }
        }
Exemple #4
0
        private static void AddCultureResources(
            ProjectContext project,
            string outputPath,
            List <string> inputs,
            List <string> outputs,
            CommonCompilerOptions compilationOptions)
        {
            List <CompilerUtil.CultureResgenIO> resources = null;

            if (compilationOptions.EmbedInclude == null)
            {
                resources = CompilerUtil.GetCultureResources(project.ProjectFile, outputPath);
            }
            else
            {
                resources = CompilerUtil.GetCultureResourcesFromIncludeEntries(project.ProjectFile, outputPath, compilationOptions);
            }

            foreach (var cultureResourceIO in resources)
            {
                inputs.AddRange(cultureResourceIO.InputFileToMetadata.Keys);

                if (cultureResourceIO.OutputFile != null)
                {
                    outputs.Add(cultureResourceIO.OutputFile);
                }
            }
        }
Exemple #5
0
        public CodeVariableDeclarationStatement CreateVariableDeclaration()
        {
            Type t = this.GetResolvedDataType();

            if (t != null && !typeof(VoidAction).Equals(t))
            {
                CodeTypeReference ctf = this.GetCodeTypeReference();
                if (ctf != null)
                {
                    ArrayPointer ap = _type as ArrayPointer;
                    if (ap != null)
                    {
                        int[] dims = ap.Dimnesions;
                        if (dims != null && dims.Length == 1)
                        {
                            if (dims[0] >= 0)
                            {
                                if (!t.FullName.EndsWith("[][]", StringComparison.Ordinal))
                                {
                                    CodeArrayCreateExpression init = new CodeArrayCreateExpression(ap.ItemBaseType, dims[0]);
                                    return(new CodeVariableDeclarationStatement(ctf, this.CodeName, init));
                                }
                            }
                        }
                    }
                    return(CompilerUtil.CreateVariableDeclaration(ctf, this.CodeName, this.BaseClassType, this.BaseClassType.IsPrimitive?this.ObjectInstance:null));
                }
            }
            return(null);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="previousAction"></param>
        /// <param name="nextAction"></param>
        /// <param name="compiler"></param>
        /// <param name="method"></param>
        /// <param name="statements"></param>
        public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements)
        {
            string                 indexName = RepeatIndex.CodeName;
            CodeExpression         c         = new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression(indexName), CodeBinaryOperatorType.LessThan, RepeatCount.GetReferenceCode(Method, statements, true));
            CodeIterationStatement cis       = new CodeIterationStatement();

            cis.TestExpression     = c;
            cis.InitStatement      = new CodeVariableDeclarationStatement(typeof(int), indexName, new CodePrimitiveExpression(0));
            cis.IncrementStatement = new CodeSnippetStatement(indexName + "++");
            statements.Add(cis);
            if (_iconList != null)
            {
                foreach (ComponentIcon ci in _iconList)
                {
                    ComponentIconLocal cil = ci as ComponentIconLocal;
                    if (cil != null && cil.ScopeGroupId == this.BranchId)
                    {
                        cil.LocalPointer.AddVariableDeclaration(cis.Statements);
                    }
                }
            }
            SetWithinLoop();
            Method.SubMethod.Push(this);
            CompilerUtil.AddSubMethod(method, this);
            bool bRet = base.OnExportCode(previousAction, nextAction, compiler, method, cis.Statements);

            Method.SubMethod.Pop();
            bRet = CompilerUtil.FinishSubMethod(method, this, cis.Statements, bRet);
            return(bRet);
        }
Exemple #7
0
 public void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug)
 {
     if (IsValid)
     {
         CodeExpression ceCondition = null;
         if (_condition != null)
         {
             ceCondition = _condition.ExportCode(methodToCompile);
             if (ceCondition != null)
             {
                 ceCondition = CompilerUtil.ConvertToBool(_condition.DataType, ceCondition);
             }
         }
         CodeStatementCollection sts = statements;
         if (ceCondition != null)
         {
             CodeConditionStatement cs = new CodeConditionStatement();
             cs.Condition = ceCondition;
             statements.Add(cs);
             sts = cs.TrueStatements;
         }
         CodeExpression right;
         if (_valType.ValueType == EnumValueType.ConstantValue)
         {
             right = _val.GetReferenceCode(methodToCompile, sts, true);
         }
         else
         {
             List <CodeExpression> ps = new List <CodeExpression>();
             ps.Add(_valType.GetReferenceCode(methodToCompile, sts, true));
             if (_val.ConstantValue != null)
             {
                 CodeExpression[] pp = _val.ConstantValue.GetConstructorParameters(methodToCompile, sts);
                 if (pp != null)
                 {
                     ps.AddRange(pp);
                 }
             }
             right = new CodeCastExpression(_var.BaseClassType,
                                            new CodeMethodInvokeExpression(
                                                new CodeTypeReferenceExpression(typeof(Activator)),
                                                "CreateInstance",
                                                ps.ToArray())
                                            );
         }
         CodeExpression left = _var.GetReferenceCode(methodToCompile, sts, false);
         CodeVariableReferenceExpression cvre = left as CodeVariableReferenceExpression;
         CodeSnippetExpression           cse  = right as CodeSnippetExpression;
         if (cvre != null && cse != null && string.CompareOrdinal(cse.Value, string.Format(CultureInfo.InvariantCulture, "{0}++", cvre.VariableName)) == 0)
         {
             CodeExpressionStatement ces = new CodeExpressionStatement(right);
             sts.Add(ces);
         }
         else
         {
             CodeAssignStatement cas = new CodeAssignStatement(left, right);
             sts.Add(cas);
         }
     }
 }
Exemple #8
0
        private static void AddNonCultureResources(
            ProjectContext project,
            string intermediaryOutputPath,
            List <string> inputs,
            IList <string> outputs,
            CommonCompilerOptions compilationOptions)
        {
            List <CompilerUtil.NonCultureResgenIO> resources = null;

            if (compilationOptions.EmbedInclude == null)
            {
                resources = CompilerUtil.GetNonCultureResources(project.ProjectFile, intermediaryOutputPath);
            }
            else
            {
                resources = CompilerUtil.GetNonCultureResourcesFromIncludeEntries(project.ProjectFile, intermediaryOutputPath, compilationOptions);
            }

            foreach (var resourceIO in resources)
            {
                inputs.Add(resourceIO.InputFile);

                if (resourceIO.OutputFile != null)
                {
                    outputs.Add(resourceIO.OutputFile);
                }
            }
        }
        private ResourceFolder GetFolderForPath(string path)
        {
            var components = path.Split('/');

            var f = RootFolder;

            for (var i = 0; i < components.Length - 1; i++)
            {
                var c = CompilerUtil.GetSafeName(components[i], true);

                var isDuplicate = f.Name == c;
                var folderName  = isDuplicate ? "_" + c : c;

                var folder = f.Folders.FirstOrDefault(p => p.Name == folderName);

                if (folder == null)
                {
                    var folderPath = components.Take(i).ToArray();

                    // Post warning the first time this folder is encountered
                    if (isDuplicate)
                    {
                        TSLog.LogWarning(LogCategory.Compile,
                                         string.Format(Strings.Warning_FolderNameCannotBeSameAsParent, string.Join("/", folderPath)));
                    }

                    folder = new ResourceFolder(folderName, string.Join("/", folderPath));
                    f.Folders.Add(folder);
                }

                f = folder;
            }

            return(f);
        }
Exemple #10
0
        private static void AddKeyFile(ProjectContext project, string config, CompilerIO compilerIO)
        {
            var keyFile = CompilerUtil.ResolveCompilationOptions(project, config).KeyFile;

            if (keyFile != null)
            {
                compilerIO.Inputs.Add(keyFile);
            }
        }
Exemple #11
0
        private void CollectCompilerNamePreconditions(ProjectContext project, IncrementalPreconditions preconditions)
        {
            var projectCompiler = CompilerUtil.ResolveCompilerName(project);

            if (KnownCompilers.Any(knownCompiler => knownCompiler.Equals(projectCompiler, StringComparison.Ordinal)))
            {
                preconditions.AddUnknownCompilerPrecondition(project.ProjectName(), projectCompiler);
            }
        }
Exemple #12
0
        private CompilerIO ComputeIO(ProjectGraphNode graphNode)
        {
            var inputs  = new List <string>();
            var outputs = new List <string>();

            var isRootProject = graphNode.IsRoot;
            var project       = graphNode.ProjectContext;

            var calculator         = project.GetOutputPaths(_configuration, _buildBasePath, _outputPath);
            var binariesOutputPath = calculator.CompilationOutputPath;
            var compilerOptions    = project.ProjectFile.GetCompilerOptions(project.TargetFramework, _configuration);

            // input: project.json
            inputs.Add(project.ProjectFile.ProjectFilePath);

            // input: lock file; find when dependencies change
            AddLockFile(project, inputs);

            // input: source files
            inputs.AddRange(CompilerUtil.GetCompilationSources(project, compilerOptions));

            var allOutputPath = new HashSet <string>(calculator.CompilationFiles.All());

            if (isRootProject && project.ProjectFile.HasRuntimeOutput(_configuration))
            {
                var runtimeContext = _workspace.GetRuntimeContext(project, _runtimes);
                foreach (var path in runtimeContext.GetOutputPaths(_configuration, _buildBasePath, _outputPath).RuntimeFiles.All())
                {
                    allOutputPath.Add(path);
                }
            }
            foreach (var dependency in graphNode.Dependencies)
            {
                var outputFiles = dependency.ProjectContext
                                  .GetOutputPaths(_configuration, _buildBasePath, _outputPath)
                                  .CompilationFiles;

                inputs.Add(outputFiles.Assembly);
            }

            // output: compiler outputs
            foreach (var path in allOutputPath)
            {
                outputs.Add(path);
            }

            // input compilation options files
            AddCompilationOptions(project, _configuration, inputs);

            // input / output: resources with culture
            AddNonCultureResources(project, calculator.IntermediateOutputDirectoryPath, inputs, outputs, compilerOptions);

            // input / output: resources without culture
            AddCultureResources(project, binariesOutputPath, inputs, outputs, compilerOptions);

            return(new CompilerIO(inputs, outputs));
        }
        public override void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug)
        {
            IMathExpression mathExp = MathExp;

            if (mathExp != null)
            {
                CodeExpression ceCondition = null;
                if (Condition != null)
                {
                    ceCondition = Condition.ExportCode(methodToCompile);
                    if (ceCondition != null)
                    {
                        ceCondition = CompilerUtil.ConvertToBool(Condition.DataType, ceCondition);
                    }
                }
                CodeExpression ce = mathExp.ReturnCodeExpression(methodToCompile);
                if (ce != null)
                {
                    CodeExpression target = null;
                    CodeVariableDeclarationStatement output = null;
                    if (nextAction != null)
                    {
                        if (nextAction.UseInput)
                        {
                            output = new CodeVariableDeclarationStatement(currentAction.OutputType.TypeString, currentAction.OutputCodeName, ce);
                            statements.Add(output);
                        }
                    }
                    IVariable v = mathExp.OutputVariable;
                    if (v != null)
                    {
                        CodeStatement cs;
                        target = v.ExportCode(methodToCompile);
                        if (output != null)
                        {
                            cs = new CodeAssignStatement(target, new CodeVariableReferenceExpression(currentAction.OutputCodeName));
                        }
                        else
                        {
                            cs = new CodeAssignStatement(target, ce);
                        }
                        if (ceCondition == null)
                        {
                            statements.Add(cs);
                        }
                        else
                        {
                            CodeConditionStatement cd = new CodeConditionStatement();
                            cd.Condition = ceCondition;
                            cd.TrueStatements.Add(cs);
                            statements.Add(cd);
                        }
                    }
                }
            }
        }
Exemple #14
0
        private static void AddCompilationOptions(ProjectContext project, string config, CompilerIO compilerIO)
        {
            var compilerOptions = CompilerUtil.ResolveCompilationOptions(project, config);

            // input: key file
            if (compilerOptions.KeyFile != null)
            {
                compilerIO.Inputs.Add(compilerOptions.KeyFile);
            }
        }
Exemple #15
0
        private void CheckPathProbing(ProjectContext project, IncrementalPreconditions preconditions)
        {
            var pathCommands = CompilerUtil.GetCommandsInvokedByCompile(project)
                               .Select(commandName => Command.Create(commandName, "", project.TargetFramework))
                               .Where(c => Command.CommandResolutionStrategy.Path.Equals(c.ResolutionStrategy));

            foreach (var pathCommand in pathCommands)
            {
                preconditions.AddPathProbingPrecondition(project.ProjectName(), pathCommand.CommandName);
            }
        }
Exemple #16
0
        private void CollectCheckPathProbingPreconditions(ProjectContext project, IncrementalPreconditions preconditions)
        {
            var pathCommands = CompilerUtil.GetCommandsInvokedByCompile(project)
                               .Select(commandName => Command.CreateDotNet(commandName, Enumerable.Empty <string>(), project.TargetFramework))
                               .Where(c => c.ResolutionStrategy.Equals(CommandResolutionStrategy.Path));

            foreach (var pathCommand in pathCommands)
            {
                preconditions.AddPathProbingPrecondition(project.ProjectName(), pathCommand.CommandName);
            }
        }
Exemple #17
0
        private static void AddCultureResources(ProjectContext project, string outputPath, CompilerIO compilerIO)
        {
            foreach (var cultureResourceIO in CompilerUtil.GetCultureResources(project.ProjectFile, outputPath))
            {
                compilerIO.Inputs.AddRange(cultureResourceIO.InputFileToMetadata.Keys);

                if (cultureResourceIO.OutputFile != null)
                {
                    compilerIO.Outputs.Add(cultureResourceIO.OutputFile);
                }
            }
        }
Exemple #18
0
        private static void AddNonCultureResources(ProjectContext project, string intermediaryOutputPath, CompilerIO compilerIO)
        {
            foreach (var resourceIO in CompilerUtil.GetNonCultureResources(project.ProjectFile, intermediaryOutputPath))
            {
                compilerIO.Inputs.Add(resourceIO.InputFile);

                if (resourceIO.OutputFile != null)
                {
                    compilerIO.Outputs.Add(resourceIO.OutputFile);
                }
            }
        }
Exemple #19
0
        // computes all the inputs and outputs that would be used in the compilation of a project
        // ensures that all paths are files
        // ensures no missing inputs
        public CompilerIO GetCompileIO(ProjectContext project, ProjectDependenciesFacade dependencies)
        {
            var buildConfiguration = _args.ConfigValue;
            var buildBasePath      = _args.BuildBasePathValue;
            var outputPath         = _args.OutputValue;
            var isRootProject      = project == _rootProject;

            var compilerIO         = new CompilerIO(new List <string>(), new List <string>());
            var calculator         = project.GetOutputPaths(buildConfiguration, buildBasePath, outputPath);
            var binariesOutputPath = calculator.CompilationOutputPath;

            // input: project.json
            compilerIO.Inputs.Add(project.ProjectFile.ProjectFilePath);

            // input: lock file; find when dependencies change
            AddLockFile(project, compilerIO);

            // input: source files
            compilerIO.Inputs.AddRange(CompilerUtil.GetCompilationSources(project));

            // todo: Factor out dependency resolution between Build and Compile. Ideally Build injects the dependencies into Compile
            // input: dependencies
            AddDependencies(dependencies, compilerIO);

            var allOutputPath = new HashSet <string>(calculator.CompilationFiles.All());

            if (isRootProject && project.ProjectFile.HasRuntimeOutput(buildConfiguration))
            {
                var runtimeContext = project.CreateRuntimeContext(_args.GetRuntimes());
                foreach (var path in runtimeContext.GetOutputPaths(buildConfiguration, buildBasePath, outputPath).RuntimeFiles.All())
                {
                    allOutputPath.Add(path);
                }
            }

            // output: compiler outputs
            foreach (var path in allOutputPath)
            {
                compilerIO.Outputs.Add(path);
            }

            // input compilation options files
            AddCompilationOptions(project, buildConfiguration, compilerIO);

            // input / output: resources with culture
            AddNonCultureResources(project, calculator.IntermediateOutputDirectoryPath, compilerIO);

            // input / output: resources without culture
            AddCultureResources(project, binariesOutputPath, compilerIO);

            return(compilerIO);
        }
 public void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug)
 {
     if (IsValid)
     {
         CodeExpression ceCondition = null;
         if (_condition != null)
         {
             ceCondition = _condition.ExportCode(methodToCompile);
             if (ceCondition != null)
             {
                 ceCondition = CompilerUtil.ConvertToBool(_condition.DataType, ceCondition);
             }
         }
         CodeStatementCollection sts = statements;
         if (ceCondition != null)
         {
             CodeConditionStatement cs = new CodeConditionStatement();
             cs.Condition = ceCondition;
             statements.Add(cs);
             sts = cs.TrueStatements;
         }
         CodeExpression right;
         if (_valType.ValueType == EnumValueType.ConstantValue)
         {
             right = _val.GetReferenceCode(methodToCompile, sts, true);
         }
         else
         {
             List <CodeExpression> ps = new List <CodeExpression>();
             ps.Add(_valType.GetReferenceCode(methodToCompile, sts, true));
             if (_val.ConstantValue != null)
             {
                 CodeExpression[] pp = _val.ConstantValue.GetConstructorParameters(methodToCompile, sts);
                 if (pp != null)
                 {
                     ps.AddRange(pp);
                 }
             }
             right = new CodeCastExpression(_var.ObjectType,
                                            new CodeMethodInvokeExpression(
                                                new CodeTypeReferenceExpression(typeof(Activator)),
                                                "CreateInstance",
                                                ps.ToArray())
                                            );
         }
         CodeExpression      left = _var.GetReferenceCode(methodToCompile, sts, false);
         CodeAssignStatement cas  = new CodeAssignStatement(left, right);
         sts.Add(cas);
     }
 }
Exemple #21
0
        public CodeVariableDeclarationStatement CreateVariableDeclaration()
        {
            Type t = this.GetResolvedDataType();

            if (t != null && !typeof(VoidAction).Equals(t))
            {
                CodeTypeReference ctf = this.GetCodeTypeReference();
                if (ctf != null)
                {
                    return(CompilerUtil.CreateVariableDeclaration(ctf, this.CodeName, this.BaseClassType, this.BaseClassType.IsPrimitive?this.ObjectInstance:null));
                }
            }
            return(null);
        }
Exemple #22
0
        // computes all the inputs and outputs that would be used in the compilation of a project
        // ensures that all paths are files
        // ensures no missing inputs
        public static CompilerIO GetCompileIO(
            ProjectContext project,
            string buildConfiguration,
            string outputPath,
            string intermediaryOutputPath,
            ProjectDependenciesFacade dependencies)
        {
            var compilerIO         = new CompilerIO(new List <string>(), new List <string>());
            var calculator         = project.GetOutputPathCalculator(outputPath);
            var binariesOutputPath = calculator.GetOutputDirectoryPath(buildConfiguration);

            intermediaryOutputPath = calculator.GetIntermediateOutputDirectoryPath(buildConfiguration, intermediaryOutputPath);


            // input: project.json
            compilerIO.Inputs.Add(project.ProjectFile.ProjectFilePath);

            // input: lock file; find when dependencies change
            AddLockFile(project, compilerIO);

            // input: source files
            compilerIO.Inputs.AddRange(CompilerUtil.GetCompilationSources(project));

            // todo: Factor out dependency resolution between Build and Compile. Ideally Build injects the dependencies into Compile
            // input: dependencies
            AddDependencies(dependencies, compilerIO);

            // output: compiler outputs
            foreach (var path in calculator.GetBuildOutputs(buildConfiguration))
            {
                compilerIO.Outputs.Add(path);
            }

            // input compilation options files
            AddCompilationOptions(project, buildConfiguration, compilerIO);

            // input / output: resources without culture
            AddCultureResources(project, intermediaryOutputPath, compilerIO);

            // input / output: resources with culture
            AddNonCultureResources(project, binariesOutputPath, compilerIO);

            return(compilerIO);
        }
Exemple #23
0
        public static void Compile(IProperty SetProperty, CodeExpression rt, ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug)
        {
            CodeAssignStatement cas = new CodeAssignStatement();

            cas.Left = SetProperty.GetReferenceCode(methodToCompile, statements, false);
            if (cas.Left == null)
            {
                compiler.AddError("Error: SetterPointer missing property");
            }
            else
            {
                CodeMethodReferenceExpression cmr = rt as CodeMethodReferenceExpression;
                if (cmr != null)
                {
                    rt = new CodeMethodInvokeExpression(cmr);
                }
                if (nextAction != null && nextAction.UseInput)
                {
                    CodeVariableDeclarationStatement output = new CodeVariableDeclarationStatement(
                        currentAction.OutputType.TypeString, currentAction.OutputCodeName, rt);
                    statements.Add(output);
                    rt = new CodeVariableReferenceExpression(currentAction.OutputCodeName);
                }
                cas.Right = rt;
                bool bThreadSafe = !methodToCompile.MakeUIThreadSafe;
                if (bThreadSafe && currentAction != null)
                {
                    if (!currentAction.IsMainThread && SetProperty.ObjectDevelopType == EnumObjectDevelopType.Library)
                    {
                        bThreadSafe = !CompilerUtil.IsOwnedByControl(SetProperty.Owner);
                    }
                }
                if (!bThreadSafe)
                {
                    statements.Add(new CodeSnippetStatement(CompilerUtil.InvokeStart));
                }
                statements.Add(cas);
                if (!bThreadSafe)
                {
                    statements.Add(new CodeSnippetStatement(CompilerUtil.InvokeEnd));
                }
            }
        }
        public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements)
        {
            BranchList _list = this.ActionList;

            if (_list != null)
            {
                //link both actions
                if (nextAction != null)
                {
                    if (!string.IsNullOrEmpty(OutputCodeName) && OutputType != null && !OutputType.IsVoid)
                    {
                        nextAction.InputName = OutputCodeName;
                        nextAction.InputType = OutputType;
                        nextAction.SetInputName(OutputCodeName, OutputType);
                    }
                }
                //
                CompilerUtil.ClearGroupGotoBranches(method, this.BranchId);
                bool bRet = _list.ExportCode(compiler, method, statements);
                bRet = CompilerUtil.FinishActionGroup(method, statements, this.BranchId, bRet);
                return(bRet);
            }
            return(false);
        }
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            MathNode.Trace("{0}.ExportCode", this.GetType().Name);
            if (_methodPointer == null)
            {
                MathNode.Trace("Warning: method pointer is null");
                return(null);
            }
            bool isWeb = false;

            if (_methodPointer.Owner != null && _methodPointer.Owner.RootPointer != null)
            {
                isWeb = _methodPointer.Owner.RootPointer.IsWebPage;
            }
            if (isWeb && _methodPointer.RunAt == EnumWebRunAt.Client)
            {
                CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression(
                    new CodeVariableReferenceExpression("clientRequest"), "GetStringValue", new CodePrimitiveExpression(DataPassingCodeName));
                return(cmie);
            }
            if (method == null)
            {
                throw new DesignerException("Calling {0}.ExportCode with null method", this.GetType().Name);
            }
            if (method.MethodCode == null)
            {
                throw new DesignerException("Calling {0}.ExportCode with null method.MethodCode", this.GetType().Name);
            }
            CodeStatementCollection supprtStatements = method.MethodCode.Statements;
            int n = ChildNodeCount;

            CodeExpression[] ps;
            if (n > 0)
            {
                IList <IParameter> pList = _methodPointer.MethodPointed.MethodParameterTypes;;

                //_methodPointer.MethodPointed.
                ps = new CodeExpression[n];
                for (int i = 0; i < n; i++)
                {
                    this[i].CompileDataType = new RaisDataType(pList[i].ParameterLibType);
                    if (typeof(string).Equals(pList[i].ParameterLibType))
                    {
                        if (this[i].Parent != null)
                        {
                            MathNodeMethodPointer mmp = this[i].Parent as MathNodeMethodPointer;
                            if (mmp != null && mmp.Method != null && mmp.Method.Owner != null)
                            {
                                if (typeof(DateTime).Equals(mmp.Method.Owner.ObjectType))
                                {
                                    if (this[i].ActualCompiledType != null && typeof(CultureInfo).Equals(this[i].ActualCompiledType.LibType))
                                    {
                                        this[i].CompileDataType = this[i].ActualCompiledType;
                                    }
                                }
                            }
                        }
                    }
                    ps[i] = this[i].ExportCode(method);
                }
            }
            else
            {
                ps = new CodeExpression[] { };
            }
            _methodPointer.SetParameterExpressions(ps);
            CodeExpression ce = _methodPointer.GetReferenceCode(method, supprtStatements, true);

            if (_methodPointer.ReturnBaseType != null && this.CompileDataType != null && this.CompileDataType.Type != null)
            {
                DataTypePointer     targetType = new DataTypePointer(this.CompileDataType.Type);
                DataTypePointer     sourceType = new DataTypePointer(_methodPointer.ReturnBaseType);
                IGenericTypePointer igp        = _methodPointer as IGenericTypePointer;
                if (igp != null)
                {
                    if (targetType.IsGenericType || targetType.IsGenericParameter)
                    {
                        DataTypePointer dtp = igp.GetConcreteType(targetType.BaseClassType);
                        if (dtp != null)
                        {
                            targetType = dtp;
                        }
                    }
                    if (sourceType.IsGenericType || sourceType.IsGenericParameter)
                    {
                        DataTypePointer dtp = igp.GetConcreteType(sourceType.BaseClassType);
                        if (dtp != null)
                        {
                            sourceType = dtp;
                        }
                    }
                }
                if (!targetType.IsAssignableFrom(sourceType))
                {
                    ce = CompilerUtil.GetTypeConversion(targetType, ce, sourceType, supprtStatements);
                }
            }
            return(ce);
        }
Exemple #26
0
        public virtual void Compile(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug)
        {
            if (_method == null)
            {
                return;
            }
            CodeExpression cmi = null;

            if (_method != null)
            {
                _method.SetHolder(_holder);
                CodeMethodReferenceExpression mref = (CodeMethodReferenceExpression)_method.GetReferenceCode(methodToCompile, statements, false);
                CodeMethodInvokeExpression    cmim = new CodeMethodInvokeExpression();
                cmim.Method = mref;
                cmim.Parameters.AddRange(parameters);
                cmi = cmim;
            }

            bool useOutput = false;

            if (!NoReturn && nextAction != null && nextAction.UseInput)
            {
                CodeVariableDeclarationStatement output = new CodeVariableDeclarationStatement(
                    currentAction.OutputType.TypeString, currentAction.OutputCodeName, cmi);
                statements.Add(output);
                cmi = new CodeVariableReferenceExpression(currentAction.OutputCodeName);

                useOutput = true;
            }
            if (HasReturn && returnReceiver != null)
            {
                CodeExpression cr = returnReceiver.GetReferenceCode(methodToCompile, statements, true);
                if (_method.ReturnValue != null)
                {
                    Type          target;
                    IClassWrapper wrapper = returnReceiver as IClassWrapper;
                    if (wrapper != null)
                    {
                        target = wrapper.WrappedType;
                    }
                    else
                    {
                        target = returnReceiver.ObjectType;
                    }
                    Type dt;
                    if (useOutput)
                    {
                        dt = currentAction.OutputType.BaseClassType;
                    }
                    else
                    {
                        dt = _method.ReturnValue.BaseClassType;
                    }
                    CompilerUtil.CreateAssignment(cr, target, cmi, dt, statements, true);
                }
                else
                {
                    CodeAssignStatement cas = new CodeAssignStatement(cr, cmi);
                    statements.Add(cas);
                }
            }
            else
            {
                if (!useOutput)
                {
                    CodeExpressionStatement ces = new CodeExpressionStatement(cmi);
                    statements.Add(ces);
                }
            }
        }
Exemple #27
0
        public override CodeExpression ExportCode(IMethodCompile method)
        {
            CodeExpression ce;

            if (_valuePointer != null)
            {
                bool isWeb = false;
                if (_valuePointer.RootPointer != null)
                {
                    isWeb = _valuePointer.RootPointer.IsWebPage;
                }
                if (!IsField() && isWeb && this.IsWebClientValue())
                {
                    //this is a client property, use clientRequest.GetStringValue(DataPassingCodeName)
                    CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression(
                        new CodeVariableReferenceExpression("clientRequest"), "GetStringValue", new CodePrimitiveExpression(DataPassingCodeName));
                    ce = cmie;
                }
                else
                {
                    ce = _valuePointer.GetReferenceCode(method, method.MethodCode.Statements, _forValue);
                }
                ActualCompiledType = new MathExp.RaisTypes.RaisDataType(_valuePointer.ObjectType);
                if (CompileDataType != null)
                {
                    if (CompileDataType.Type != null && _valuePointer.ObjectType != null)
                    {
                        DataTypePointer     targetType = new DataTypePointer(CompileDataType.Type);
                        DataTypePointer     sourceType = new DataTypePointer(_valuePointer.ObjectType);
                        IGenericTypePointer igp        = _valuePointer as IGenericTypePointer;
                        if (igp != null)
                        {
                            if (targetType.IsGenericType || targetType.IsGenericParameter)
                            {
                                DataTypePointer dtp = igp.GetConcreteType(targetType.BaseClassType);
                                if (dtp != null)
                                {
                                    targetType = dtp;
                                }
                            }
                            if (sourceType.IsGenericType || sourceType.IsGenericParameter)
                            {
                                DataTypePointer dtp = igp.GetConcreteType(sourceType.BaseClassType);
                                if (dtp != null)
                                {
                                    sourceType = dtp;
                                }
                            }
                        }
                        if (!targetType.IsAssignableFrom(sourceType))
                        {
                            ce = CompilerUtil.GetTypeConversion(targetType, ce, sourceType, method.MethodCode.Statements);
                            ActualCompiledType = new MathExp.RaisTypes.RaisDataType(targetType.BaseClassType);
                        }
                    }
                }
            }
            else
            {
                ce = new CodeArgumentReferenceExpression(CodeName);
            }
            return(ce);
        }
Exemple #28
0
        public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements)
        {
            if (IsCompiled)
            {
                return(false);
            }
            //preventing of compiling it twice
            IsCompiled = true;
            bool         isGotoPoint = this.IsGotoPoint;
            ActionBranch nt          = nextAction;

            if (_jumpToId != 0)
            {
                //next action is the one it jumps to
                nt = _jumpToActionBranch;
            }
            MethodSegment           ms0 = null;
            CodeStatementCollection sts = statements;

            if (isGotoPoint)
            {
                //two or more branches in the same thread linked to this branch
                //since goto-label must be in the method scope, not sub-scope, this branch code must be
                //in the method scope
                ms0 = CompilerUtil.GetGotoBranch(method, Method, this.FirstActionId);
                if (ms0 == null)
                {
                    sts = new CodeStatementCollection();
                    ms0 = new MethodSegment(sts);
                    CompilerUtil.AddGotoBranch(method, Method, this.FirstActionId, ms0, this.GroupBranchId);
                }
                else
                {
                    throw new DesignerException("Action list as goto branch {0} compiled twice", this.FirstActionId);
                }
                //use goto statement to jump to this branch is the responsibility of the branches jumping to it.
            }
            if (this.IsWaitingPoint)
            {
                sts.Add(new CodeExpressionStatement(
                            new CodeMethodInvokeExpression(
                                new CodeTypeReferenceExpression(typeof(WaitHandle)), "WaitAll",
                                new CodeVariableReferenceExpression(XmlSerialization.FormatString("wh_{0}_{1}",
                                                                                                  IdToKey(this.StartingBranchId), this.BranchKey)))));
            }
            bool b0 = base.OnExportCode(previousAction, nt, compiler, method, sts);

            if (ms0 != null)
            {
                ms0.Completed = b0;
            }
            if (b0)
            {
                return(true);
            }
            else
            {
                //not all sub-branches of this branch completed.
                //check jumping
                if (_jumpToId != 0)
                {
                    bool bRet = false;
                    //same thread: use goto or fall through; otherwise use waiting point
                    if (_jumpToActionBranch.StartingBranchId == this.StartingBranchId)
                    {
                        //a goto branch, use goto
                        if (_jumpToActionBranch.IsGotoPoint)
                        {
                            sts.Add(new CodeGotoStatement(ActionBranch.IdToLabel(_jumpToId)));
                            bRet = true;
                        }
                        if (!_jumpToActionBranch.IsCompiled)
                        {
                            bool b = _jumpToActionBranch.ExportCode(this, null, compiler, method, sts);
                            if (!_jumpToActionBranch.IsGotoPoint)
                            {
                                bRet = b;
                            }
                        }
                    }
                    return(bRet);
                }
                else
                {
                    //not completed
                    return(false);
                }
            }
        }
        public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements)
        {
            CodeExpression c;

            if (_logicExpression == null)
            {
                c = new CodePrimitiveExpression(true);
            }
            else
            {
                _logicExpression.PrepareForCompile(this.Method);
                c = _logicExpression.ExportCode(this.Method);
            }
            CodeIterationStatement cis = new CodeIterationStatement();

            cis.TestExpression = c;
            if (_initAction != null && _initAction.Action != null)
            {
                CodeStatementCollection sts = new CodeStatementCollection();
                _initAction.Action.ExportCode(null, null, compiler, Method, method, sts, false);
                if (sts.Count > 0)
                {
                    for (int i = 0; i < sts.Count; i++)
                    {
                        if (!(sts[i] is CodeCommentStatement))
                        {
                            cis.InitStatement = sts[i];
                            break;
                        }
                    }
                }
                else
                {
                    cis.InitStatement = new CodeSnippetStatement();
                }
            }
            else
            {
                cis.InitStatement = new CodeSnippetStatement();
            }
            if (_increAction != null && _increAction.Action != null)
            {
                CodeStatementCollection sts = new CodeStatementCollection();
                _increAction.Action.ExportCode(null, null, compiler, Method, method, sts, false);
                if (sts.Count > 0)
                {
                    for (int i = 0; i < sts.Count; i++)
                    {
                        if (!(sts[i] is CodeCommentStatement))
                        {
                            cis.IncrementStatement = sts[i];
                            break;
                        }
                    }
                }
                else
                {
                    cis.IncrementStatement = new CodeSnippetStatement();
                }
            }
            else
            {
                cis.IncrementStatement = new CodeSnippetStatement();
            }
            statements.Add(cis);
            if (_iconList != null)
            {
                foreach (ComponentIcon ci in _iconList)
                {
                    ComponentIconLocal cil = ci as ComponentIconLocal;
                    if (cil != null && cil.ScopeGroupId == this.BranchId)
                    {
                        cil.LocalPointer.AddVariableDeclaration(cis.Statements);
                    }
                }
            }
            Method.SubMethod.Push(this);
            CompilerUtil.AddSubMethod(method, this);
            bool bRet = base.OnExportCode(previousAction, nextAction, compiler, method, cis.Statements);

            Method.SubMethod.Pop();
            bRet = CompilerUtil.FinishSubMethod(method, this, cis.Statements, bRet);
            return(bRet);
        }
        public void Compile(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug)
        {
            if (_method == null)
            {
                return;
            }
            IObjectPointer op = _method.VariablePointer;

            if (op == null)
            {
                return;
            }
            ClassPointer        cp  = op as ClassPointer;
            CustomMethodPointer cmp = null;
            MethodClass         mc  = null;

            if (cp != null)
            {
                mc = cp.GetCustomMethodById(_method.MethodId);
                if (mc != null)
                {
                    cmp = new CustomMethodPointer(mc, _holder);
                    cmp.SetParameterExpressions(_parameterExpressions);
                    cmp.Compile(currentAction, nextAction, compiler, methodToCompile, method, statements, parameters, returnReceiver, debug);
                    return;
                }
            }
            CodeExpression cmi = null;

            if (_method != null)
            {
                CodeMethodReferenceExpression mref = (CodeMethodReferenceExpression)_method.GetReferenceCode(methodToCompile, statements, false);
                CodeMethodInvokeExpression    cmim = new CodeMethodInvokeExpression();
                cmim.Method = mref;
                cmim.Parameters.AddRange(parameters);
                cmi = cmim;
            }
            bool useOutput = false;

            if (!NoReturn && nextAction != null && nextAction.UseInput)
            {
                CodeVariableDeclarationStatement output = new CodeVariableDeclarationStatement(
                    currentAction.OutputType.TypeString, currentAction.OutputCodeName, cmi);
                statements.Add(output);
                cmi       = new CodeVariableReferenceExpression(currentAction.OutputCodeName);
                useOutput = true;
            }
            if (_method.HasReturn && returnReceiver != null)
            {
                CodeExpression cr = returnReceiver.GetReferenceCode(methodToCompile, statements, true);
                if (_method.ReturnType != null)
                {
                    Type          target;
                    IClassWrapper wrapper = returnReceiver as IClassWrapper;
                    if (wrapper != null)
                    {
                        target = wrapper.WrappedType;
                    }
                    else
                    {
                        target = returnReceiver.ObjectType;
                    }
                    Type dt;
                    if (useOutput)
                    {
                        dt = currentAction.OutputType.BaseClassType;
                    }
                    else
                    {
                        dt = _method.ReturnType.BaseClassType;
                    }
                    CompilerUtil.CreateAssignment(cr, target, cmi, dt, statements, true);
                }
                else
                {
                    CodeAssignStatement cas = new CodeAssignStatement(cr, cmi);
                    statements.Add(cas);
                }
            }
            else
            {
                if (!useOutput)
                {
                    CodeExpressionStatement ces = new CodeExpressionStatement(cmi);
                    statements.Add(ces);
                }
            }
        }