Beispiel #1
0
        private ProjectProperties GetProjectData()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Solution solution = GetActiveSolution();

            if (solution == null)
            {
                return(null);
            }

            Project project = GetActiveProject();

            if (project == null)
            {
                return(null);
            }

            VCProject prj = project.Object as VCProject;

            if (prj == null)
            {
                return(null);
            }

            VCConfiguration config = prj.ActiveConfiguration;

            if (config == null)
            {
                return(null);
            }

            VCPlatform platform = config.Platform;

            if (platform == null)
            {
                return(null);
            }

            var vctools = config.Tools as IVCCollection;

            if (vctools == null)
            {
                return(null);
            }

            var midl = vctools.Item("VCMidlTool") as VCMidlTool;

            ProjectProperties ret = new ProjectProperties();

            ret.Target = midl != null && midl.TargetEnvironment == midlTargetEnvironment.midlTargetWin32 ? ProjectProperties.TargetType.x86 : ProjectProperties.TargetType.x64;

            //Working directory (always local to processed file)
            ret.WorkingDirectory = Path.GetDirectoryName(project.FullName);

            //TODO ~ ramonv ~ find a way to extract the /std value

            //Include dirs / files and preprocessor
            AppendMSBuildStringToList(ret.IncludeDirectories, platform.Evaluate(platform.IncludeDirectories));
            AppendProjectProperties(ret, vctools.Item("VCCLCompilerTool") as VCCLCompilerTool, vctools.Item("VCNMakeTool") as VCNMakeTool, platform);

            try
            {
                //Get settings from the single file (this might fail badly if there are no settings to catpure)
                var applicationObject = ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2;
                Assumes.Present(applicationObject);
                ProjectItem item   = applicationObject.ActiveDocument.ProjectItem;
                VCFile      vcfile = item.Object as VCFile;

                IVCCollection       fileCfgs   = (IVCCollection)vcfile.FileConfigurations;
                VCFileConfiguration fileConfig = fileCfgs.Item(config.Name) as VCFileConfiguration;

                AppendProjectProperties(ret, fileConfig.Tool as VCCLCompilerTool, fileConfig.Tool as VCNMakeTool, platform);
            }
            catch (Exception) {}

            SolutionSettings customSettings = SettingsManager.Instance.Settings;

            if (customSettings != null)
            {
                AppendMSBuildStringToList(ret.IncludeDirectories, platform.Evaluate(customSettings.AdditionalIncludeDirs));
                AppendMSBuildStringToList(ret.ForceIncludes, platform.Evaluate(customSettings.AdditionalForceIncludes));
                AppendMSBuildStringToList(ret.PrepocessorDefinitions, platform.Evaluate(customSettings.AdditionalPreprocessorDefinitions));
                ret.ExtraArguments = platform.Evaluate(customSettings.AdditionalCommandLine);
                ret.ShowWarnings   = customSettings.EnableWarnings;
            }

            //Exclude directories
            RemoveMSBuildStringFromList(ret.IncludeDirectories, platform.Evaluate(platform.ExcludeDirectories));

            return(ret);
        }
Beispiel #2
0
        public async Task <ParseResult> ParseAsync(ProjectProperties projProperties, DocumentLocation location)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            ParseResult ret = new ParseResult();

            if (location.Filename == null || location.Filename.Length == 0)
            {
                OutputLog.Error("No file provided for parsing");
                ret.Status = ParseResult.StatusCode.InvalidInput;
                return(ret);
            }

            //SetLog(str => OutputLog.Log(str));

            AdjustPaths(projProperties.IncludeDirectories);
            AdjustPaths(projProperties.ForceIncludes);

            string includes = GenerateCommandStr("-I", projProperties.IncludeDirectories);
            string forceInc = GenerateCommandStr("-include", projProperties.ForceIncludes);
            string defines  = GenerateCommandStr("-D", projProperties.PrepocessorDefinitions);
            string workDir  = projProperties.WorkingDirectory.Length == 0 ? "" : " -working-directory=" + AdjustPath(projProperties.WorkingDirectory);
            string flags    = projProperties.ShowWarnings? "" : " -w";
            string extra    = projProperties.ExtraArguments.Length == 0? "" : " " + projProperties.ExtraArguments;

            string archStr = projProperties != null && projProperties.Target == ProjectProperties.TargetType.x86 ? "-m32" : "-m64";
            string toolCmd = AdjustPath(location.Filename) + " -- -x c++ " + archStr + flags + defines + includes + forceInc + workDir + extra;

            OutputLog.Focus();
            OutputLog.Log("Looking for structures at " + location.Filename + ":" + location.Line + ":" + location.Column + "...");

            if (PrintCommandLine)
            {
                OutputLog.Log("COMMAND LINE: " + toolCmd);
            }

            var watch = System.Diagnostics.Stopwatch.StartNew();

            var valid = await System.Threading.Tasks.Task.Run(() => ParseLocation(toolCmd, location.Filename, location.Line, location.Column));

            watch.Stop();
            const long TicksPerMicrosecond = (TimeSpan.TicksPerMillisecond / 1000);
            string     timeStr             = " (" + GetTimeStr((ulong)(watch.ElapsedTicks / TicksPerMicrosecond)) + ")";

            ProcessLog();

            if (valid)
            {
                //capture data
                uint   size   = 0;
                IntPtr result = GetData(ref size);

                if (size > 0)
                {
                    byte[] managedArray = new byte[size];
                    Marshal.Copy(result, managedArray, 0, (int)size);

                    using (BinaryReader reader = new BinaryReader(new MemoryStream(managedArray)))
                    {
                        ret.Layout = ReadNode(reader);
                        FinalizeNode(ret.Layout);
                    }

                    OutputLog.Log("Found structure " + ret.Layout.Type + "." + timeStr);
                    ret.Status = ParseResult.StatusCode.Found;
                }
                else
                {
                    OutputLog.Log("No structure found at the given location." + timeStr);
                    ret.Status = ParseResult.StatusCode.NotFound;
                }
            }
            else
            {
                OutputLog.Error("Unable to scan the given location." + timeStr);
                ret.Status = ParseResult.StatusCode.ParseFailed;
            }

            Clear();

            return(ret);
        }
 protected virtual void ProcessPostProjectData(ProjectProperties projProperties)
 {
 }
        public override ProjectProperties GetProjectData()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            OutputLog.Log("Capturing configuration from VS projects...");

            Project project = EditorUtils.GetActiveProject();

            VCProject prj = project.Object as VCProject;

            if (prj == null)
            {
                return(null);
            }

            VCConfiguration config = prj.ActiveConfiguration;

            if (config == null)
            {
                return(null);
            }

            VCPlatform platform = config.Platform;

            if (platform == null)
            {
                return(null);
            }

            var vctools = config.Tools as IVCCollection;

            if (vctools == null)
            {
                return(null);
            }

            var midl = vctools.Item("VCMidlTool") as VCMidlTool;

            var evaluator = new MacroEvaluatorVisualPlatform(platform);

            ProjectProperties ret = new ProjectProperties();

            ret.Target   = midl != null && midl.TargetEnvironment == midlTargetEnvironment.midlTargetWin32 ? ProjectProperties.TargetType.x86 : ProjectProperties.TargetType.x64;
            ret.Standard = GetStandardVersion(config);

            //Working directory (always local to processed file)
            ret.WorkingDirectory = Path.GetDirectoryName(project.FullName);

            //Include dirs / files and preprocessor
            AppendMSBuildStringToList(ret.IncludeDirectories, evaluator.Evaluate(platform.IncludeDirectories));
            AppendProjectProperties(ret, vctools.Item("VCCLCompilerTool") as VCCLCompilerTool, vctools.Item("VCNMakeTool") as VCNMakeTool, evaluator);

            //Get settings from the single file (this might fail badly if there are no settings to catpure)
            var applicationObject = EditorUtils.ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2;

            Assumes.Present(applicationObject);
            ProjectItem         item       = applicationObject.ActiveDocument.ProjectItem;
            VCFile              vcfile     = item != null ? item.Object as VCFile : null;
            IVCCollection       fileCfgs   = vcfile != null ? (IVCCollection)vcfile.FileConfigurations : null;
            VCFileConfiguration fileConfig = fileCfgs != null?fileCfgs.Item(config.Name) as VCFileConfiguration : null;

            VCCLCompilerTool fileToolCL    = null;
            VCNMakeTool      fileToolNMake = null;

            try
            {
                fileToolCL    = fileConfig.Tool as VCCLCompilerTool;
                fileToolNMake = fileConfig.Tool as VCNMakeTool;
            }
            catch (Exception e)
            {
                //If we really need this data we can always parse the vcxproj as an xml
                OutputLog.Log("File specific properties not found, only project properties used (" + e.Message + ")");
            }

            AppendProjectProperties(ret, fileToolCL, fileToolNMake, evaluator);

            CaptureExtraProperties(ret, evaluator);

            AddCustomSettings(ret, evaluator);

            RemoveMSBuildStringFromList(ret.IncludeDirectories, evaluator.Evaluate(platform.ExcludeDirectories)); //Exclude directories

            ProcessPostProjectData(ret);

            return(ret);
        }
 protected virtual void CaptureExtraProperties(ProjectProperties projProperties, IMacroEvaluator evaluator)
 {
 }