Skip to content

Commit

Permalink
Rearrange VS2010 parameter
Browse files Browse the repository at this point in the history
- remove constant commonDefines
- move VS2010 specific command parameter to ParseV100CompilerOptions()
  • Loading branch information
Bertk committed Jun 28, 2015
1 parent 88b61c3 commit e591795
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
23 changes: 10 additions & 13 deletions cxx-squid/src/main/java/org/sonar/cxx/CxxVCppBuildLogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,24 @@ private void parseVCppCompilerCLLine(String line, String projectPath, String fil
ParseInclude(includeElem, projectPath, fileElement);
}

for (String includeElem : getMatches(Pattern.compile("/I([^\\s\"]+) "),
line)) {
for (String includeElem : getMatches(Pattern.compile("/I([^\\s\"]+) "), line)) {
ParseInclude(includeElem, projectPath, fileElement);
}

for (String macroElem : getMatches(Pattern.compile("[/-]D\\s([^\\s]+)"),
line)) {
for (String macroElem : getMatches(Pattern.compile("[/-]D\\s([^\\s]+)"), line)) {
AddMacro(macroElem, fileElement);
}

for (String macroElem : getMatches(Pattern.compile("[/-]D([^\\s]+)"),
line)) {
for (String macroElem : getMatches(Pattern.compile("[/-]D([^\\s]+)"), line)) {
AddMacro(macroElem, fileElement);
}

// https://msdn.microsoft.com/en-us/library/vstudio/b0084kay(v=vs.100).aspx
// https://msdn.microsoft.com/en-us/library/vstudio/b0084kay(v=vs.110).aspx
// https://msdn.microsoft.com/en-us/library/vstudio/b0084kay(v=vs.120).aspx
// https://msdn.microsoft.com/en-us/library/vstudio/b0084kay(v=vs.140).aspx
ParseCommonCompilerOptions(line, fileElement);

if (platformToolset.equals(VSVersion.V100)) {
ParseV100CompilerOptions(line, fileElement);
} else if (platformToolset.equals(VSVersion.V110)) {
Expand All @@ -167,7 +164,7 @@ private void parseVCppCompilerCLLine(String line, String projectPath, String fil
ParseV120CompilerOptions(line, fileElement);
} else if (platformToolset.equals(VSVersion.V140)) {
ParseV140CompilerOptions(line, fileElement);
}
}
}

private List<String> getMatches(Pattern pattern, String text) {
Expand Down Expand Up @@ -391,10 +388,6 @@ else if(platform.equals("Win32")||line.contains("/D WIN32")) {
//This is not defined for x64 processors.
AddMacro("_M_IX86", fileElement);
}
// VC++ 16.0
if (line.contains("/GX ")) {
AddMacro("_CPPUNWIND", fileElement);
}
// VC++ 17.0, 18.0, 19.0
// _CPPUNWIND Defined for code compiled by using one of the /EH (Exception Handling Model) flags.
if (line.contains("/EHs ") ||
Expand All @@ -418,6 +411,10 @@ private void ParseV100CompilerOptions(String line, String fileElement) {
//_MFC_VER Defines the MFC version. For example, in Visual Studio 2010, _MFC_VER is defined as 0x0C00.
AddMacro("_MFC_VER=0x0A00", fileElement);
AddMacro("_ATL_VER=0x0A00", fileElement);
// VC++ 16.0
if (line.contains("/GX ")) {
AddMacro("_CPPUNWIND", fileElement);
}
}

private void ParseV110CompilerOptions(String line, String fileElement) {
Expand Down
33 changes: 16 additions & 17 deletions cxx-squid/src/test/java/org/sonar/cxx/CxxConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class CxxConfigurationTest {

private static final String vcKey = "Visual C++";
private static final String vcCharSet = "UTF8";
private static final int commonDefines = 14;

@Test
public void emptyValueShouldReturnNoDirsOrDefines() {
Expand Down Expand Up @@ -68,11 +67,11 @@ public void correctlyCreatesConfiguration1() {
config.setCompilationPropertiesWithBuildLog(files, vcKey, vcCharSet);

assertThat(config.getIncludeDirectories().size()).isEqualTo(13);
assertThat(config.getDefines().size()).isEqualTo(commonDefines + 17);
assertThat(config.getDefines().size()).isEqualTo(26 + 5);
}

@Test
public void shouldHandleSpeciificCommonOptionsCorrectly() {
public void shouldHandleSpecificCommonOptionsCorrectly() {
CxxConfiguration config = new CxxConfiguration();
config.setBaseDir(".");
List<File> files = new ArrayList<>();
Expand All @@ -81,7 +80,7 @@ public void shouldHandleSpeciificCommonOptionsCorrectly() {

assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(commonDefines + 11);
assertThat(defines.size()).isEqualTo(20 + 5);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines).as("_OPENMP");
Assertions.assertThat(defines).as("_WIN32");
Expand All @@ -97,30 +96,30 @@ public void shouldHandleSpeciificCommonOptionsCorrectly() {
Assertions.assertThat(defines).as("_VC_NODEFAULTLIB");
}

public void shouldHandleSpeciificCommonWin32OptionsCorrectly() {
public void shouldHandleSpecificCommonWin32OptionsCorrectly() {
CxxConfiguration config = new CxxConfiguration();
List<File> files = new ArrayList<>();
files.add(new File("src/test/resources/compiler/platformCommonWin32.txt"));
config.setCompilationPropertiesWithBuildLog(files, vcKey, vcCharSet);

assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(3);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines).as("_WIN32");
}

@Test
public void shouldHandleSpeciificCommonx64OptionsCorrectly() {
public void shouldHandleSpecificCommonx64OptionsCorrectly() {
CxxConfiguration config = new CxxConfiguration();
config.setBaseDir(".");
List<File> files = new ArrayList<>();
files.add(new File("src/test/resources/compiler/platformCommonX64.txt"));
config.setCompilationPropertiesWithBuildLog(files, vcKey, vcCharSet);

assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(commonDefines + 6);
assertThat(defines.size()).isEqualTo(15 + 5);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines).as("_Wp64");
Assertions.assertThat(defines).as("_WIN32");
Expand All @@ -131,7 +130,7 @@ public void shouldHandleSpeciificCommonx64OptionsCorrectly() {
}

@Test
public void shouldHandleSpeciificV100OptionsCorrectly() {
public void shouldHandleSpecificV100OptionsCorrectly() {
CxxConfiguration config = new CxxConfiguration();
config.setBaseDir(".");
List<File> files = new ArrayList<File>();
Expand All @@ -140,7 +139,7 @@ public void shouldHandleSpeciificV100OptionsCorrectly() {

assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(commonDefines + 4);
assertThat(defines.size()).isEqualTo(12 + 6);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines).as("_CPPUNWIND");
Assertions.assertThat(defines).as("_M_IX86");
Expand All @@ -149,7 +148,7 @@ public void shouldHandleSpeciificV100OptionsCorrectly() {
}

@Test
public void shouldHandleSpeciificV110OptionsCorrectly() {
public void shouldHandleSpecificV110OptionsCorrectly() {
CxxConfiguration config = new CxxConfiguration();
config.setBaseDir(".");
List<File> files = new ArrayList<File>();
Expand All @@ -158,7 +157,7 @@ public void shouldHandleSpeciificV110OptionsCorrectly() {

assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(commonDefines + 5);
assertThat(defines.size()).isEqualTo(13 + 6);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines).as("__cplusplus_winrt");
Assertions.assertThat(defines).as("_CPPUNWIND");
Expand All @@ -168,7 +167,7 @@ public void shouldHandleSpeciificV110OptionsCorrectly() {
}

@Test
public void shouldHandleSpeciificV120OptionsCorrectly() {
public void shouldHandleSpecificV120OptionsCorrectly() {
CxxConfiguration config = new CxxConfiguration();
config.setBaseDir(".");
List<File> files = new ArrayList<>();
Expand All @@ -177,7 +176,7 @@ public void shouldHandleSpeciificV120OptionsCorrectly() {

assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(commonDefines + 7);
assertThat(defines.size()).isEqualTo(15 + 6);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines).as("__AVX2__");
Assertions.assertThat(defines).as("__AVX__");
Expand All @@ -190,7 +189,7 @@ public void shouldHandleSpeciificV120OptionsCorrectly() {
}

@Test
public void shouldHandleSpeciificV140OptionsCorrectly() {
public void shouldHandleSpecificV140OptionsCorrectly() {
CxxConfiguration config = new CxxConfiguration();
config.setBaseDir(".");
List<File> files = new ArrayList<>();
Expand All @@ -199,7 +198,7 @@ public void shouldHandleSpeciificV140OptionsCorrectly() {

assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(commonDefines + 7);
assertThat(defines.size()).isEqualTo(15 + 6);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines).as("__AVX2__");
Assertions.assertThat(defines).as("__AVX__");
Expand Down

0 comments on commit e591795

Please sign in to comment.