Skip to content
This repository was archived by the owner on Aug 9, 2025. It is now read-only.

Commit 29dc254

Browse files
author
VioletGiraffe
committed
1.0.3: bugfix to the previous commit, settings for only checking current #if/#ifdef branches
1 parent 5ceced5 commit 29dc254

File tree

8 files changed

+100
-31
lines changed

8 files changed

+100
-31
lines changed

CPPCheckPlugin/AnalyzerCppcheck.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,28 @@ public override void analyze(List<SourceFile> filesToAnalyze, OutputWindowPane o
6565
cppheckargs += " \"" + file.FilePath + "\"";
6666
}
6767

68-
// Creating the list of all different macros (no duplicates)
69-
HashSet<string> macros = new HashSet<string>();
70-
macros.Add("__cplusplus=199711L"); // At least in VS2012, this is still 199711L
71-
// Assuming all files passed here are from the same project / same toolset, which should be true, so peeking the first file for global settings
72-
switch (filesToAnalyze[0].vcCompilerVersion)
73-
{
74-
case SourceFile.VCCompilerVersion.vc2010:
75-
macros.Add("_MSC_VER=1600");
76-
break;
77-
case SourceFile.VCCompilerVersion.vc2012:
78-
macros.Add("_MSC_VER=1700");
79-
break;
80-
case SourceFile.VCCompilerVersion.vc2013:
81-
macros.Add("_MSC_VER=1800");
82-
break;
83-
case SourceFile.VCCompilerVersion.vcFuture:
84-
macros.Add("_MSC_VER=1900");
85-
break;
86-
}
87-
88-
if (filesToAnalyze.Count == 1) // For single file only checking current configuration (for speed)
68+
if ((filesToAnalyze.Count == 1 && Properties.Settings.Default.FileOnlyCheckCurrentConfig) || (filesToAnalyze.Count > 1 && Properties.Settings.Default.ProjectOnlyCheckCurrentConfig)) // Only checking current macros configuration (for speed)
8969
{
70+
// Creating the list of all different macros (no duplicates)
71+
HashSet<string> macros = new HashSet<string>();
72+
macros.Add("__cplusplus=199711L"); // At least in VS2012, this is still 199711L
73+
// Assuming all files passed here are from the same project / same toolset, which should be true, so peeking the first file for global settings
74+
switch (filesToAnalyze[0].vcCompilerVersion)
75+
{
76+
case SourceFile.VCCompilerVersion.vc2010:
77+
macros.Add("_MSC_VER=1600");
78+
break;
79+
case SourceFile.VCCompilerVersion.vc2012:
80+
macros.Add("_MSC_VER=1700");
81+
break;
82+
case SourceFile.VCCompilerVersion.vc2013:
83+
macros.Add("_MSC_VER=1800");
84+
break;
85+
case SourceFile.VCCompilerVersion.vcFuture:
86+
macros.Add("_MSC_VER=1900");
87+
break;
88+
}
89+
9090
foreach (var file in filesToAnalyze)
9191
{
9292
foreach (string macro in file.Macros)
@@ -107,12 +107,12 @@ public override void analyze(List<SourceFile> filesToAnalyze, OutputWindowPane o
107107

108108
if (isDebugConfiguration)
109109
macros.Add("_DEBUG");
110-
}
111110

112-
foreach (string macro in macros)
113-
{
114-
String macroArgument = " -D" + macro;
115-
cppheckargs += macroArgument;
111+
foreach (string macro in macros)
112+
{
113+
String macroArgument = " -D" + macro;
114+
cppheckargs += macroArgument;
115+
}
116116
}
117117

118118
string analyzerPath = Properties.Settings.Default.CPPcheckPath;

CPPCheckPlugin/CPPCheckPlugin.csproj.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
44
<StartAction>Program</StartAction>
5-
<StartProgram>K:\Program Files %28x86%29\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe</StartProgram>
5+
<StartProgram>C:\Program Files %28x86%29\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe</StartProgram>
66
<StartArguments>/rootsuffix Exp</StartArguments>
77
</PropertyGroup>
88
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<Window x:Class="VSPackage.CPPCheckPlugin.CppcheckSettings"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
Title="Cppcheck settings" Height="141.952" Width="338.968">
4+
Title="Cppcheck settings" Height="146.952"
5+
SizeToContent="WidthAndHeight">
56
<Grid>
6-
<CheckBox Content="Enable inconclusive checks" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.309,0.75" Name="InconclusiveChecks" Checked="inconclusive_Checked" Unchecked="inconclusive_Unchecked"/>
7+
<CheckBox Content="Enable inconclusive checks" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Name="InconclusiveChecks" Checked="inconclusive_Checked" Unchecked="inconclusive_Unchecked"/>
78
<Label Content="Arguments:" HorizontalAlignment="Left" Margin="10,31,0,0" VerticalAlignment="Top" Visibility="Hidden"/>
89
<Button Content="Reset arguments to default" HorizontalAlignment="Stretch" Margin="265,148,265,0" VerticalAlignment="Top" Width="158" Click="onDefaultArguments" Visibility="Hidden"/>
910
<TextBox HorizontalAlignment="Stretch" Margin="10,62,10,0" TextWrapping="NoWrap" Name="ArgumentsEditor" VerticalAlignment="Top" ScrollViewer.CanContentScroll="True" Height="81" Visibility="Hidden"/>
11+
<CheckBox Content="Checking a project: only check currently active #if/#ifdef branches (faster check)" HorizontalAlignment="Left" Margin="10,31,0,0" VerticalAlignment="Top" Name="Project_OnlyCheckCurrentConfig" Checked="Project_OnlyCheckCurrentConfig_Checked" Unchecked="Project_OnlyCheckCurrentConfig_Unchecked"/>
12+
<CheckBox Content="Checking a single file: only check currently active #if/#ifdef branches (faster check)" HorizontalAlignment="Left" Margin="10,52,0,0" VerticalAlignment="Top" Name="File_OnlyCheckCurrentConfig" Checked="File_OnlyCheckCurrentConfig_Checked" Unchecked="File_OnlyCheckCurrentConfig_Unchecked"/>
1013
</Grid>
1114
</Window>

CPPCheckPlugin/CppcheckSettings.xaml.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace VSPackage.CPPCheckPlugin
1919
/// </summary>
2020
public partial class CppcheckSettings : Window
2121
{
22+
public static string DefaultArguments = "--enable=style,information,warning,performance,portability --inline-suppr -q --force --template=vs";
23+
2224
public CppcheckSettings()
2325
{
2426
InitializeComponent();
@@ -32,29 +34,57 @@ public CppcheckSettings()
3234
private void onActivated(object o, EventArgs e)
3335
{
3436
InconclusiveChecks.IsChecked = Properties.Settings.Default.InconclusiveChecksEnabled;
37+
Project_OnlyCheckCurrentConfig.IsChecked = Properties.Settings.Default.ProjectOnlyCheckCurrentConfig;
38+
File_OnlyCheckCurrentConfig.IsChecked = Properties.Settings.Default.FileOnlyCheckCurrentConfig;
3539
ArgumentsEditor.Text = Properties.Settings.Default.DefaultArguments;
3640
}
3741

3842
private void OnClosed(object o, EventArgs e)
3943
{
4044
Properties.Settings.Default["DefaultArguments"] = String.IsNullOrEmpty(ArgumentsEditor.Text) ? DefaultArguments.Replace('\n', ' ').Replace('\r', ' ') : ArgumentsEditor.Text;
45+
Properties.Settings.Default.Save();
4146
}
4247

4348
private void inconclusive_Unchecked(object sender, RoutedEventArgs e)
4449
{
4550
Properties.Settings.Default["InconclusiveChecksEnabled"] = false;
51+
Properties.Settings.Default.Save();
4652
}
4753

4854
private void inconclusive_Checked(object sender, RoutedEventArgs e)
4955
{
5056
Properties.Settings.Default["InconclusiveChecksEnabled"] = true;
57+
Properties.Settings.Default.Save();
5158
}
5259
private void onDefaultArguments(object sender, RoutedEventArgs e)
5360
{
5461
Properties.Settings.Default["DefaultArguments"] = DefaultArguments;
5562
ArgumentsEditor.Text = DefaultArguments;
63+
Properties.Settings.Default.Save();
5664
}
5765

58-
public static string DefaultArguments = "--enable=style,information,warning,performance,portability --inline-suppr -q --force --template=vs";
66+
private void Project_OnlyCheckCurrentConfig_Checked(object sender, RoutedEventArgs e)
67+
{
68+
Properties.Settings.Default["ProjectOnlyCheckCurrentConfig"] = true;
69+
Properties.Settings.Default.Save();
70+
}
71+
72+
private void Project_OnlyCheckCurrentConfig_Unchecked(object sender, RoutedEventArgs e)
73+
{
74+
Properties.Settings.Default["ProjectOnlyCheckCurrentConfig"] = false;
75+
Properties.Settings.Default.Save();
76+
}
77+
78+
private void File_OnlyCheckCurrentConfig_Checked(object sender, RoutedEventArgs e)
79+
{
80+
Properties.Settings.Default["FileOnlyCheckCurrentConfig"] = true;
81+
Properties.Settings.Default.Save();
82+
}
83+
84+
private void File_OnlyCheckCurrentConfig_Unchecked(object sender, RoutedEventArgs e)
85+
{
86+
Properties.Settings.Default["FileOnlyCheckCurrentConfig"] = true;
87+
Properties.Settings.Default.Save();
88+
}
5989
}
6090
}

CPPCheckPlugin/Properties/Settings.Designer.cs

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CPPCheckPlugin/Properties/Settings.settings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@
1111
<Setting Name="DefaultArguments" Type="System.String" Scope="User">
1212
<Value Profile="(Default)" />
1313
</Setting>
14+
<Setting Name="ProjectOnlyCheckCurrentConfig" Type="System.Boolean" Scope="User">
15+
<Value Profile="(Default)">False</Value>
16+
</Setting>
17+
<Setting Name="FileOnlyCheckCurrentConfig" Type="System.Boolean" Scope="User">
18+
<Value Profile="(Default)">True</Value>
19+
</Setting>
1420
</Settings>
1521
</SettingsFile>

CPPCheckPlugin/app.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
<setting name="DefaultArguments" serializeAs="String">
1717
<value />
1818
</setting>
19+
<setting name="ProjectOnlyCheckCurrentConfig" serializeAs="String">
20+
<value>False</value>
21+
</setting>
22+
<setting name="FileOnlyCheckCurrentConfig" serializeAs="String">
23+
<value>True</value>
24+
</setting>
1925
</VSPackage.CPPCheckPlugin.Properties.Settings>
2026
</userSettings>
2127
</configuration>

CPPCheckPlugin/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="127d8bd3-8cd7-491a-9a63-9b4e89118da9" Version="1.0" Language="en-US" Publisher="-" />
4+
<Identity Id="127d8bd3-8cd7-491a-9a63-9b4e89118da9" Version="1.0.3" Language="en-US" Publisher="-" />
55
<DisplayName>cppcheck add-in</DisplayName>
66
<Description xml:space="preserve">Integration for cppcheck - C/C++ code static analysis tool </Description>
77
<License>PackageInstallerLicense.txt</License>

0 commit comments

Comments
 (0)