1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Propagated from 2.1 branch.

Fix for SCD bugs 80269 & 80271.
Test for bug 80271.
This commit is contained in:
Vladimir Hirsl 2004-12-07 22:25:07 +00:00
parent 3022e88fa1
commit 8b5a3c56f3
3 changed files with 32 additions and 17 deletions

View file

@ -94,7 +94,7 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser {
return false;
Iterator I = allTokens.iterator();
String token = ((String) I.next()).toLowerCase();
if (token.indexOf("gcc") != -1 || token.indexOf("g++") != -1 || token.indexOf("gcc") != -1) {//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (token.indexOf("gcc") != -1 || token.indexOf("g++") != -1) {//$NON-NLS-1$ //$NON-NLS-2$
// Recognized gcc or g++ compiler invocation
List includes = new ArrayList();
List symbols = new ArrayList();
@ -121,6 +121,12 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser {
}
else if (fileName == null) {
String possibleFileName = token.toLowerCase();
if ((possibleFileName.startsWith(DOUBLE_QUOTE_STRING) &&
possibleFileName.endsWith(DOUBLE_QUOTE_STRING)) ||
(possibleFileName.startsWith(SINGLE_QUOTE_STRING) &&
possibleFileName.endsWith(SINGLE_QUOTE_STRING))) {
possibleFileName = possibleFileName.substring(1, possibleFileName.length()-1).trim();
}
if (possibleFileName.endsWith(".c") || //$NON-NLS-1$
possibleFileName.endsWith(".cpp") || //$NON-NLS-1$
possibleFileName.endsWith(".cc") || //$NON-NLS-1$
@ -183,7 +189,7 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser {
int prevIndex = 0;
for (int index = line.indexOf(fDashI, prevIndex); index != -1;
prevIndex = index+2, index = line.indexOf(fDashI, prevIndex)) {
String delimiter = "\\s"; //$NON-NLS-1$
String delimiter = "\\s+"; //$NON-NLS-1$
if (line.charAt(index-1) == '\'' || line.charAt(index-1) == '\"') {
// look for only one more ' or "
delimiter = String.valueOf(line.charAt(index-1));
@ -225,9 +231,10 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser {
private void parseLineForSymbolDefinitions(String line, List symbols) {
final String fDashD = "-D"; //$NON-NLS-1$
int prevIndex = 0;
String delimiter = null;
String splitRegex = "\\s+"; //$NON-NLS-1$
for (int index = line.indexOf(fDashD, prevIndex); index != -1;
prevIndex = index+2, index = line.indexOf(fDashD, prevIndex)) {
String delimiter = "\\s"; //$NON-NLS-1$
int nDelimiterSymbols = 2;
String postfix = line.substring(index+2).trim();
if (postfix.charAt(0) == '-') { // empty -D
@ -239,7 +246,7 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser {
nDelimiterSymbols = 1;
}
else {
String[] tokens = postfix.split(delimiter, 2);
String[] tokens = postfix.split(splitRegex, 2);
if (tokens.length > 0 && tokens[0].length() > 0) {
int sQuoteIndex = tokens[0].indexOf(SINGLE_QUOTE_STRING);
int dQuoteIndex = tokens[0].indexOf(DOUBLE_QUOTE_STRING);
@ -248,6 +255,7 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser {
if (!symbols.contains(tokens[0])) {
symbols.add(tokens[0]);
}
continue;
}
else {
delimiter = (sQuoteIndex != -1 && (dQuoteIndex == -1 || sQuoteIndex < dQuoteIndex)) ? SINGLE_QUOTE_STRING : DOUBLE_QUOTE_STRING;

View file

@ -34,7 +34,7 @@ public class AllStandardBuildTests extends TestSuite {
public static Test suite() {
TestSuite suite = new AllStandardBuildTests("Test for org.eclipse.cdt.standardbuild.core.tests");
//$JUnit-BEGIN$
suite.addTest(ScannerConfigConsoleParserTests.suite());
suite.addTestSuite(ScannerConfigConsoleParserTests.class);
//$JUnit-END$
return suite;
}

View file

@ -19,9 +19,7 @@ import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCScannerInfoConsoleParser;
import org.eclipse.core.resources.IResource;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Scanner configuration console parser tests
@ -55,15 +53,6 @@ public class ScannerConfigConsoleParserTests extends TestCase {
clParser = null;
}
public static Test suite() {
TestSuite suite = new TestSuite(ScannerConfigConsoleParserTests.class.getName());
suite.addTest(new ScannerConfigConsoleParserTests("testParsingIncludePaths"));
suite.addTest(new ScannerConfigConsoleParserTests("testParsingSymbolDefinitions"));
return suite;
}
/*
* Tests GCCScannerInfoConsoleParser. Utility object not provided.
* Only tests parsing of the imput (make build output)
@ -115,6 +104,7 @@ public class ScannerConfigConsoleParserTests extends TestCase {
assertTrue(sumIncludes.contains("//server5/include"));
assertTrue(sumIncludes.contains("//server6/include"));
assertTrue(sumIncludes.contains("/multiline/dir"));
assertTrue(sumIncludes.size() == 24);
}
public void testParsingSymbolDefinitions() {
@ -152,5 +142,22 @@ public class ScannerConfigConsoleParserTests extends TestCase {
assertTrue(sumSymbols.contains("MACRO13=\"value 13\""));
assertTrue(sumSymbols.contains("MULTILINE=TRUE"));
assertTrue(sumSymbols.contains("SUM(x, y) = (x) + (y)"));
assertTrue(sumSymbols.size() == 15);
}
public void testParsingSymbolDefinitions_bug80271() {
final ArrayList sumSymbols = new ArrayList();
// initialize it with the utility
clParser.startup(null, null, new IScannerInfoCollector() {
public void contributeToScannerConfig(IResource resource, List includes, List symbols, Map extraInfo) {
sumSymbols.addAll(symbols);
}
});
clParser.processLine("gcc -DMACRO1 -I ..\\inc -c ..\\source\\source.c"); // PR 80271
assertTrue(sumSymbols.contains("MACRO1"));
assertTrue(sumSymbols.size() == 1);
}
}