mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Allow to configure empty macro definitions, bug 215789.
This commit is contained in:
parent
06ad4b31a5
commit
d8ed4e7b96
9 changed files with 81 additions and 66 deletions
|
@ -1,6 +1,5 @@
|
|||
package org.eclipse.cdt.make.builder.tests;
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2002, 2008 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -10,6 +9,7 @@ package org.eclipse.cdt.make.builder.tests;
|
|||
* QNX Software Systems - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.builder.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.scannerdiscovery;
|
||||
|
||||
|
@ -51,7 +51,7 @@ public abstract class BaseBOPConsoleParserTests extends BaseTestCase {
|
|||
|
||||
public void testParsingSymbolDefinitions() {
|
||||
fOutputParser.processLine("gcc -DMACRO1 -D MACRO2=value2 -c test.c"); // simple definitions //$NON-NLS-1$
|
||||
fOutputParser.processLine("gcc -D -DMACRO3 -c test.c"); // empty -D //$NON-NLS-1$
|
||||
fOutputParser.processLine("gcc -D -DMACRO3= -c test.c"); // empty -D //$NON-NLS-1$
|
||||
fOutputParser.processLine("gcc -D MACRO4='value4' -D 'MACRO5=value5' '-D MACRO6 = value6' -c test.c"); // single quotes //$NON-NLS-1$
|
||||
fOutputParser.processLine("gcc -D'MACRO7=\"value 7\"' -D MACRO8='\"value 8\"' -c test.c"); // single quotes //$NON-NLS-1$
|
||||
fOutputParser.processLine("gcc -DMACRO9=\"value9\" -D \"MACRO10=value10\" \"-D MACRO11 = value11\" -c test.c"); // double quotes //$NON-NLS-1$
|
||||
|
@ -62,9 +62,9 @@ public abstract class BaseBOPConsoleParserTests extends BaseTestCase {
|
|||
fOutputParser.processLine("gcc -D 'SUM(x, y) = (x) + (y)' -c test.c"); // more complex macro definition //$NON-NLS-1$
|
||||
|
||||
List sumSymbols = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
||||
assertTrue(sumSymbols.contains("MACRO1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("MACRO1=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("MACRO2=value2")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("MACRO3")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("MACRO3=")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("MACRO4=value4")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("MACRO5=value5")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("MACRO6 = value6")); //$NON-NLS-1$
|
||||
|
@ -84,7 +84,7 @@ public abstract class BaseBOPConsoleParserTests extends BaseTestCase {
|
|||
fOutputParser.processLine("gcc -DMACRO1 -I ..\\inc -c ..\\perfilescdtest\\source.c"); // PR 80271 //$NON-NLS-1$
|
||||
|
||||
List sumSymbols = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
||||
assertTrue(sumSymbols.contains("MACRO1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("MACRO1=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.size() == 1);
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ public abstract class BaseBOPConsoleParserTests extends BaseTestCase {
|
|||
fOutputParser.processLine("gcc -DBUG186065_IS_FIXED test.c"); //$NON-NLS-1$
|
||||
|
||||
List sumSymbols = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
||||
assertTrue(sumSymbols.contains("BUG186065_IS_FIXED")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("BUG186065_IS_FIXED=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.size() == 1);
|
||||
}
|
||||
|
||||
|
@ -106,12 +106,12 @@ public abstract class BaseBOPConsoleParserTests extends BaseTestCase {
|
|||
fOutputParser.processLine("/usr/gcc/something_else -DF test6.c"); //$NON-NLS-1$
|
||||
|
||||
List sumSymbols = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
||||
assertTrue(sumSymbols.contains("A")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("B")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("C")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("D")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("E")); //$NON-NLS-1$
|
||||
assertFalse(sumSymbols.contains("F")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("A=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("B=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("C=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("D=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("E=1")); //$NON-NLS-1$
|
||||
assertFalse(sumSymbols.contains("F=1")); //$NON-NLS-1$
|
||||
assertEquals(5, sumSymbols.size());
|
||||
}
|
||||
|
||||
|
@ -120,10 +120,10 @@ public abstract class BaseBOPConsoleParserTests extends BaseTestCase {
|
|||
fOutputParser.processLine("nix -DC; gcc -DD test2.c"); //$NON-NLS-1$
|
||||
|
||||
List sumSymbols = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
||||
assertTrue(sumSymbols.contains("A")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("B")); //$NON-NLS-1$
|
||||
assertFalse(sumSymbols.contains("C")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("D")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("A=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("B=1")); //$NON-NLS-1$
|
||||
assertFalse(sumSymbols.contains("C=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("D=1")); //$NON-NLS-1$
|
||||
assertEquals(3, sumSymbols.size());
|
||||
}
|
||||
|
||||
|
@ -140,16 +140,16 @@ public abstract class BaseBOPConsoleParserTests extends BaseTestCase {
|
|||
fOutputParser.processLine("sh -c 'nix -DCC; gcc -DDD test2.c'"); //$NON-NLS-1$
|
||||
|
||||
List sumSymbols = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
||||
assertTrue(sumSymbols.contains("A")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("B")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("C")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("D")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("E")); //$NON-NLS-1$
|
||||
assertFalse(sumSymbols.contains("F")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("AA")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("BB")); //$NON-NLS-1$
|
||||
assertFalse(sumSymbols.contains("CC")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("DD")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("A=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("B=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("C=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("D=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("E=1")); //$NON-NLS-1$
|
||||
assertFalse(sumSymbols.contains("F=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("AA=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("BB=1")); //$NON-NLS-1$
|
||||
assertFalse(sumSymbols.contains("CC=1")); //$NON-NLS-1$
|
||||
assertTrue(sumSymbols.contains("DD=1")); //$NON-NLS-1$
|
||||
assertEquals(8, sumSymbols.size());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -42,6 +42,7 @@ public class GCCPerFileBOPConsoleParserUtility extends AbstractGCCBOPConsolePars
|
|||
private int workingDirsN = 0;
|
||||
private int commandsN = 0;
|
||||
private int filesN = 0;
|
||||
private String fDefaultMacroDefinitionValue= "1"; //$NON-NLS-1$
|
||||
|
||||
|
||||
/**
|
||||
|
@ -160,13 +161,14 @@ public class GCCPerFileBOPConsoleParserUtility extends AbstractGCCBOPConsolePars
|
|||
continue;
|
||||
}
|
||||
for (int j = SCDOptionsEnum.MIN; j <= SCDOptionsEnum.MAX; ++j) {
|
||||
if (token.startsWith(SCDOptionsEnum.getSCDOptionsEnum(j).toString())) {
|
||||
final SCDOptionsEnum optionKind = SCDOptionsEnum.getSCDOptionsEnum(j);
|
||||
if (token.startsWith(optionKind.toString())) {
|
||||
String option = token.substring(
|
||||
SCDOptionsEnum.getSCDOptionsEnum(j).toString().length()).trim();
|
||||
optionKind.toString().length()).trim();
|
||||
if (option.length() > 0) {
|
||||
// ex. -I/dir
|
||||
}
|
||||
else if (SCDOptionsEnum.getSCDOptionsEnum(j).equals(SCDOptionsEnum.IDASH)) {
|
||||
else if (optionKind.equals(SCDOptionsEnum.IDASH)) {
|
||||
for (Iterator iter=includes.iterator(); iter.hasNext(); ) {
|
||||
option = (String)iter.next();
|
||||
KVStringPair pair = new KVStringPair(SCDOptionsEnum.IQUOTE.toString(), option);
|
||||
|
@ -183,24 +185,31 @@ public class GCCPerFileBOPConsoleParserUtility extends AbstractGCCBOPConsolePars
|
|||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
if (option.length() > 0 && (
|
||||
SCDOptionsEnum.getSCDOptionsEnum(j).equals(SCDOptionsEnum.INCLUDE) ||
|
||||
SCDOptionsEnum.getSCDOptionsEnum(j).equals(SCDOptionsEnum.INCLUDE_FILE) ||
|
||||
SCDOptionsEnum.getSCDOptionsEnum(j).equals(SCDOptionsEnum.IMACROS_FILE) ||
|
||||
SCDOptionsEnum.getSCDOptionsEnum(j).equals(SCDOptionsEnum.IDIRAFTER) ||
|
||||
SCDOptionsEnum.getSCDOptionsEnum(j).equals(SCDOptionsEnum.ISYSTEM) ||
|
||||
SCDOptionsEnum.getSCDOptionsEnum(j).equals(SCDOptionsEnum.IQUOTE) )) {
|
||||
optionKind.equals(SCDOptionsEnum.INCLUDE) ||
|
||||
optionKind.equals(SCDOptionsEnum.INCLUDE_FILE) ||
|
||||
optionKind.equals(SCDOptionsEnum.IMACROS_FILE) ||
|
||||
optionKind.equals(SCDOptionsEnum.IDIRAFTER) ||
|
||||
optionKind.equals(SCDOptionsEnum.ISYSTEM) ||
|
||||
optionKind.equals(SCDOptionsEnum.IQUOTE) )) {
|
||||
option = (getAbsolutePath(option)).toString();
|
||||
}
|
||||
if (SCDOptionsEnum.getSCDOptionsEnum(j).equals(SCDOptionsEnum.IDIRAFTER)) {
|
||||
|
||||
if (optionKind.equals(SCDOptionsEnum.IDIRAFTER)) {
|
||||
KVStringPair pair = new KVStringPair(SCDOptionsEnum.INCLUDE.toString(), option);
|
||||
dirafter.add(pair);
|
||||
}
|
||||
else if (SCDOptionsEnum.getSCDOptionsEnum(j).equals(SCDOptionsEnum.INCLUDE)) {
|
||||
else if (optionKind.equals(SCDOptionsEnum.INCLUDE)) {
|
||||
includes.add(option);
|
||||
}
|
||||
else { // add the pair
|
||||
KVStringPair pair = new KVStringPair(SCDOptionsEnum.getSCDOptionsEnum(j).toString(), option);
|
||||
if (optionKind.equals(SCDOptionsEnum.DEFINE)) {
|
||||
if (option.indexOf('=') == -1) {
|
||||
option += '='+ fDefaultMacroDefinitionValue;
|
||||
}
|
||||
}
|
||||
KVStringPair pair = new KVStringPair(optionKind.toString(), option);
|
||||
command.addSCOption(pair);
|
||||
}
|
||||
break;
|
||||
|
@ -219,7 +228,13 @@ public class GCCPerFileBOPConsoleParserUtility extends AbstractGCCBOPConsolePars
|
|||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
public void setDefaultMacroDefinitionValue(String val) {
|
||||
if (val != null) {
|
||||
fDefaultMacroDefinitionValue= val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filePath : String
|
||||
* @return filePath : IPath - not <code>null</code>
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -36,6 +36,7 @@ import org.eclipse.core.runtime.Path;
|
|||
public class GCCScannerInfoConsoleParser extends AbstractGCCBOPConsoleParser {
|
||||
|
||||
private ScannerInfoConsoleParserUtility fUtil = null;
|
||||
private String fDefaultMacroDefinitionValue= "1"; //$NON-NLS-1$
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser#startup(org.eclipse.core.resources.IProject, org.eclipse.core.runtime.IPath, org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector, org.eclipse.cdt.core.IMarkerGenerator)
|
||||
|
@ -111,6 +112,9 @@ public class GCCScannerInfoConsoleParser extends AbstractGCCBOPConsoleParser {
|
|||
}
|
||||
}
|
||||
if (candidate != null && candidate.length() > 0) {
|
||||
if (candidate.indexOf('=') == -1) {
|
||||
candidate+= '='+ fDefaultMacroDefinitionValue;
|
||||
}
|
||||
if (!symbols.contains(candidate)) {
|
||||
symbols.add(candidate);
|
||||
}
|
||||
|
@ -200,4 +204,10 @@ public class GCCScannerInfoConsoleParser extends AbstractGCCBOPConsoleParser {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setDefaultMacroDefinitionValue(String val) {
|
||||
if (val != null) {
|
||||
fDefaultMacroDefinitionValue= val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -44,8 +44,8 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration#initializeMacroValuesTo1()
|
||||
/**
|
||||
* @deprecated see {@link IScannerExtensionConfiguration#initializeMacroValuesTo1()}
|
||||
*/
|
||||
public boolean initializeMacroValuesTo1() {
|
||||
return false;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -47,11 +47,6 @@ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerEx
|
|||
return sAdditionalMacros;
|
||||
}
|
||||
|
||||
|
||||
public boolean initializeMacroValuesTo1() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean support$InIdentifiers() {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -36,6 +36,8 @@ public interface IScannerExtensionConfiguration {
|
|||
|
||||
/**
|
||||
* @return <code>true</code>, if macros should be initialized to 1
|
||||
* @deprecated empty macros are taken as they are. It is the task of configuration to provide the correct values.
|
||||
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=215789
|
||||
*/
|
||||
public boolean initializeMacroValuesTo1();
|
||||
|
||||
|
|
|
@ -276,19 +276,12 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
addMacroDefinition(macro.getSignature(), macro.getExpansion());
|
||||
}
|
||||
|
||||
// macros provided on command-line (-D)
|
||||
final boolean initEmptyMacros= config.initializeMacroValuesTo1();
|
||||
final Map<String, String> macroDict= info.getDefinedSymbols();
|
||||
if (macroDict != null) {
|
||||
for (Map.Entry<String, String> entry : macroDict.entrySet()) {
|
||||
final String key= entry.getKey();
|
||||
final String value= entry.getValue().trim();
|
||||
if (initEmptyMacros && value.length() == 0) {
|
||||
addMacroDefinition(key.toCharArray(), ONE);
|
||||
}
|
||||
else {
|
||||
addMacroDefinition(key.toCharArray(), value.toCharArray());
|
||||
}
|
||||
addMacroDefinition(key.toCharArray(), value.toCharArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,7 +8,6 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.callhierarchy;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
@ -214,6 +213,7 @@ public class CallHierarchyAcrossProjectsTest extends CallHierarchyBaseTest {
|
|||
IFile sourceFile2= createFile(getProject(), "testMethods2.cpp", source2);
|
||||
|
||||
CEditor editor= openFile(sourceFile1);
|
||||
waitForIndexer(fIndex, sourceFile1, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||
waitForIndexer(fIndex, sourceFile2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||
|
||||
editor.selectAndReveal(source1.indexOf("method3"), 2);
|
||||
|
|
Loading…
Add table
Reference in a new issue