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

Fix for PR 94500: [Path Entry] Problem marker: Invalid project path: DISCOVERED_SCANNER_INFO

Fix for infinite loop in LocationMap.createSoleLocation(..). Courtesy of John C.
This commit is contained in:
Vladimir Hirsl 2005-05-10 20:04:50 +00:00
parent 540081b263
commit 51467c7d3c
14 changed files with 209 additions and 109 deletions

View file

@ -42,26 +42,4 @@ public interface IScannerInfoCollector2 extends IScannerInfoCollector {
*/
public IDiscoveredPathInfo createPathInfoObject();
// /**
// * Answers a map of collected defines that the the compiler uses by default.
// * The symbols are defined in the map as a (macro, value) pair as follows
// * <p><p><code>-DFOO</code> will be stored as ("FOO","")
// * <p><code>-DFOO=BAR</code> will be stored as ("FOO","BAR")
// * <p><p>Duplicates will not be stored in the map and any whitespaces in
// * the macro or value will be trimmed out.
// *
// * @return a <code>Map</code> of defined symbols and values
// */
// public Map getDefinedSymbols();
//
//
// /**
// * Answers a <code>List</code> of unique built-in includes paths that have been
// * collected for the receiver. The paths are stored as <code>String</code> in the proper
// * format for the host tools.
// *
// * @return a <code>List</code> of built-in compiler include search paths.
// */
// public List getIncludePaths();
}

View file

@ -17,11 +17,12 @@ package org.eclipse.cdt.make.core.scannerconfig;
*/
public class ScannerInfoTypes {
public static final ScannerInfoTypes COMPILER_COMMAND = new ScannerInfoTypes(1); // CCommandDSC
public static final ScannerInfoTypes INCLUDE_PATHS = new ScannerInfoTypes(2);
public static final ScannerInfoTypes QUOTE_INCLUDE_PATHS = new ScannerInfoTypes(3);
public static final ScannerInfoTypes SYMBOL_DEFINITIONS = new ScannerInfoTypes(4);
public static final ScannerInfoTypes TARGET_SPECIFIC_OPTION = new ScannerInfoTypes(5) ;
public static final ScannerInfoTypes COMPILER_VERSION_INFO = new ScannerInfoTypes(6);
public static final ScannerInfoTypes UNDISCOVERED_COMPILER_COMMAND = new ScannerInfoTypes(2); // CCommandDSC whose SI has not been resolved
public static final ScannerInfoTypes INCLUDE_PATHS = new ScannerInfoTypes(10);
public static final ScannerInfoTypes QUOTE_INCLUDE_PATHS = new ScannerInfoTypes(11);
public static final ScannerInfoTypes SYMBOL_DEFINITIONS = new ScannerInfoTypes(12);
public static final ScannerInfoTypes TARGET_SPECIFIC_OPTION = new ScannerInfoTypes(13) ;
public static final ScannerInfoTypes COMPILER_VERSION_INFO = new ScannerInfoTypes(14);
private final int _enum;

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigScope;
import org.eclipse.cdt.make.internal.core.MakeMessages;
import org.eclipse.cdt.make.internal.core.scannerconfig2.SCProfileInstance;
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
@ -170,7 +171,8 @@ public class DiscoveredPathManager implements IDiscoveredPathManager, IResourceC
if (changedResources != null) {
List changeDelta = new ArrayList(changedResources.size());
for (Iterator i = changedResources.iterator(); i.hasNext(); ) {
IPath path = (IPath) i.next();
IFile file = (IFile) i.next();
IPath path = file.getFullPath();
changeDelta.add(new PathEntryContainerChanged(path, 3)); // both include paths and symbols changed
}
CoreModel.pathEntryContainerUpdates(container,

View file

@ -61,7 +61,7 @@ public abstract class AbstractGCCBOPConsoleParser implements IScannerInfoConsole
bMultiline = false;
sMultiline = ""; //$NON-NLS-1$
}
TraceUtil.outputTrace("AbstractGCCBOPConsoleParser parsing line:", TraceUtil.EOL, line); //$NON-NLS-1$ //$NON-NLS-2$
TraceUtil.outputTrace("AbstractGCCBOPConsoleParser parsing line: [", line, "]"); //$NON-NLS-1$ //$NON-NLS-2$
// make\[[0-9]*\]: error_desc
int firstColon= line.indexOf(':');
String make = line.substring(0, firstColon + 1);

View file

@ -123,18 +123,18 @@ public class GCCPerFileBOPConsoleParser extends AbstractGCCBOPConsoleParser {
}
if (fUtil != null) {
IPath pFilePath = fUtil.getAbsolutePath(filePath);
String longFileName = pFilePath.toString();
String shortFileName = pFilePath.removeFileExtension().lastSegment();
String genericLine = line.replaceAll(filePath, "LONG_NAME"); //$NON-NLS-1$
genericLine = genericLine.replaceAll(shortFileName+"\\.", "SHORT_NAME\\."); //$NON-NLS-1$ //$NON-NLS-2$
CCommandDSC cmd = fUtil.getNewCCommandDSC(genericLine, extensionsIndex > 0);
List cmdList = new ArrayList();
cmdList.add(cmd);
Map sc = new HashMap(1);
sc.put(ScannerInfoTypes.COMPILER_COMMAND, cmdList);
if (getProject().getLocation().isPrefixOf(pFilePath)) {
IPath relPath = pFilePath.removeFirstSegments(getProject().getLocation().segmentCount());
List cmdList = new ArrayList();
cmdList.add(cmd);
Map sc = new HashMap(1);
sc.put(ScannerInfoTypes.COMPILER_COMMAND, cmdList);
IPath relPath = pFilePath.removeFirstSegments(getProject().getLocation().segmentCount());
IFile file = getProject().getFile(relPath);
getCollector().contributeToScannerConfig(file, sc);
}

View file

@ -39,7 +39,6 @@ public class GCCPerFileSIPConsoleParser implements IScannerInfoConsoleParser {
private final static int QUOTE_INCLUDES = 1;
private final static int INCLUDES = 2;
private IProject fProject = null;
private IScannerInfoCollector fCollector = null;
private int expectingIncludes = NO_INCLUDES;
@ -52,7 +51,6 @@ public class GCCPerFileSIPConsoleParser implements IScannerInfoConsoleParser {
* @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)
*/
public void startup(IProject project, IPath workingDirectory, IScannerInfoCollector collector, IMarkerGenerator markerGenerator) {
this.fProject = project;
this.fCollector = collector;
}
@ -61,7 +59,7 @@ public class GCCPerFileSIPConsoleParser implements IScannerInfoConsoleParser {
*/
public boolean processLine(String line) {
boolean rc = false;
TraceUtil.outputTrace("GCCPerFileSIPConsoleParser parsing line:", TraceUtil.EOL, line); //$NON-NLS-1$ //$NON-NLS-2$
TraceUtil.outputTrace("GCCPerFileSIPConsoleParser parsing line: [", line, "]"); //$NON-NLS-1$//$NON-NLS-2$
if (line.startsWith(COMMAND_ID_BEGIN)) {
commandId = Integer.parseInt(line.substring(COMMAND_ID_BEGIN.length()));

View file

@ -54,7 +54,7 @@ public class GCCSpecsConsoleParser implements IScannerInfoConsoleParser {
*/
public boolean processLine(String line) {
boolean rc = false;
TraceUtil.outputTrace("GCCSpecsConsoleParser parsing line:", TraceUtil.EOL, line); //$NON-NLS-1$ //$NON-NLS-2$
TraceUtil.outputTrace("GCCSpecsConsoleParser parsing line: [", line, "]"); //$NON-NLS-1$ //$NON-NLS-2$
// contribution of -dD option
if (line.startsWith(DEFINE)) {

View file

@ -44,7 +44,7 @@ public class TraceUtil {
public static void outputTrace(String prefix, String msg, String postfix) {
if (isTracing()) {
System.out.println();
//System.out.println();
System.out.println(prefix + ' ' + msg + ' ' + postfix);
}
}
@ -66,7 +66,7 @@ public class TraceUtil {
*/
public static void outputTrace(String title, String subtitle1, List item1, List item1new, String subtitle2, List item2) {
if (isTracing()) {
System.out.println();
//System.out.println();
System.out.println(title);
final String prefix = " "; //$NON-NLS-1$
final String doublePrefix = " "; //$NON-NLS-1$

View file

@ -123,6 +123,7 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
IFile file = project.getFile(fileName);
addCompilerCommand(file, command);
}
applyFileDeltas();
}
}
}
@ -149,7 +150,9 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
private ScannerInfoData sid; // scanner info data
private List siChangedForFileList; // list of files for which scanner info has changed
// private List siChangedForFileList; // list of files for which scanner info has changed
private Map siChangedForFileMap; // (file, comandId) map for deltas
private List siChangedForCommandIdList; // list of command ids for which scanner info has changed
private SortedSet freeCommandIdPool; // sorted set of free command ids
private int commandIdCounter = 0;
@ -162,8 +165,10 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
public PerFileSICollector() {
sid = new ScannerInfoData();
siChangedForFileList = new ArrayList();
// siChangedForFileList = new ArrayList();
siChangedForFileMap = new HashMap();
siChangedForCommandIdList = new ArrayList();
freeCommandIdPool = new TreeSet();
siAvailable = false;
}
@ -267,38 +272,103 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
cmd.setCommandId(commandId);
sid.commandIdCommandMap.put(cmd.getCommandIdAsInteger(), cmd);
}
Integer commandId = cmd.getCommandIdAsInteger();
// update sid.commandIdToFilesMap
Set fileSet = (Set) sid.commandIdToFilesMap.get(commandId);
if (fileSet == null) {
fileSet = new HashSet();
sid.commandIdToFilesMap.put(commandId, fileSet);
}
if (fileSet.add(file)) {
// update fileToCommandIdsMap
boolean change = true;
Integer oldCommandId = (Integer) sid.fileToCommandIdMap.get(file);
if (oldCommandId != null) {
if (oldCommandId.equals(commandId)) {
change = false;
}
else {
Set oldFileSet = (Set) sid.commandIdToFilesMap.get(oldCommandId);
oldFileSet.remove(file);
}
}
if (change) {
sid.fileToCommandIdMap.put(file, commandId);
// TODO generate change event for this resource
IPath path = file.getFullPath();
if (!siChangedForFileList.contains(path)) {
siChangedForFileList.add(path);
}
}
}
generateFileDelta(file, cmd);
// updateFileForCommand(file, cmd);
// Integer commandId = cmd.getCommandIdAsInteger();
// // update sid.commandIdToFilesMap
// Set fileSet = (Set) sid.commandIdToFilesMap.get(commandId);
// if (fileSet == null) {
// fileSet = new HashSet();
// sid.commandIdToFilesMap.put(commandId, fileSet);
// }
// if (fileSet.add(file)) {
// // update fileToCommandIdsMap
// boolean change = true;
// Integer oldCommandId = (Integer) sid.fileToCommandIdMap.get(file);
// if (oldCommandId != null) {
// if (oldCommandId.equals(commandId)) {
// change = false;
// }
// else {
// Set oldFileSet = (Set) sid.commandIdToFilesMap.get(oldCommandId);
// oldFileSet.remove(file);
// }
// }
// if (change) {
// sid.fileToCommandIdMap.put(file, commandId);
// // TODO generate change event for this resource
// IPath path = file.getFullPath();
// if (!siChangedForFileList.contains(path)) {
// siChangedForFileList.add(path);
// }
// }
// }
}
private void removeUnusedCommands() {
/**
* @param file
* @param cmd
*/
private void generateFileDelta(IFile file, CCommandDSC cmd) {
Integer commandId = cmd.getCommandIdAsInteger();
Integer oldCommandId = (Integer) sid.fileToCommandIdMap.get(file);
if (oldCommandId != null && oldCommandId.equals(commandId)) {
// already exists; remove form delta
siChangedForFileMap.remove(file);
}
else {
// new (file, commandId) pair
siChangedForFileMap.put(file, commandId);
}
}
/**
* @param file
* @param cmd
*/
private void applyFileDeltas() {
for (Iterator i = siChangedForFileMap.keySet().iterator(); i.hasNext(); ) {
IFile file = (IFile) i.next();
Integer commandId = (Integer) siChangedForFileMap.get(file);
if (commandId != null) {
// update sid.commandIdToFilesMap
Set fileSet = (Set) sid.commandIdToFilesMap.get(commandId);
if (fileSet == null) {
fileSet = new HashSet();
sid.commandIdToFilesMap.put(commandId, fileSet);
}
if (fileSet.add(file)) {
// update fileToCommandIdsMap
boolean change = true;
Integer oldCommandId = (Integer) sid.fileToCommandIdMap.get(file);
if (oldCommandId != null) {
if (oldCommandId.equals(commandId)) {
change = false;
}
else {
Set oldFileSet = (Set) sid.commandIdToFilesMap.get(oldCommandId);
oldFileSet.remove(file);
}
}
if (change) {
sid.fileToCommandIdMap.put(file, commandId);
// TODO generate change event for this resource
// IPath path = file.getFullPath();
// if (!siChangedForFileList.contains(path)) {
// siChangedForFileList.add(path);
// }
}
}
}
}
}
private void removeUnusedCommands() {
for (Iterator i = sid.commandIdToFilesMap.entrySet().iterator(); i.hasNext(); ) {
Entry entry = (Entry) i.next();
Integer cmdId = (Integer) entry.getKey();
@ -341,25 +411,29 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
monitor = new NullProgressMonitor();
}
monitor.beginTask(MakeMessages.getString("ScannerInfoCollector.Processing"), 100); //$NON-NLS-1$
removeUnusedCommands();
// removeUnusedCommands();
monitor.subTask(MakeMessages.getString("ScannerInfoCollector.Processing")); //$NON-NLS-1$
if (!siChangedForFileList.isEmpty()) {
// MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(project);
// DiscoveredScannerInfoStore.getInstance().loadDiscoveredScannerInfoFromState(project, this);
if (scannerInfoChanged()) {
applyFileDeltas();
removeUnusedCommands();
monitor.worked(50);
monitor.subTask(MakeMessages.getString("ScannerInfoCollector.Updating") + project.getName()); //$NON-NLS-1$
try {
// update scanner configuration
// MakeCorePlugin.getDefault().getDiscoveryManager().
// updateDiscoveredInfo(createPathInfoObject(), siChangedForFileList);
MakeCorePlugin.getDefault().getDiscoveryManager().
updateDiscoveredInfo(createPathInfoObject(), siChangedForFileList);
// DiscoveredScannerInfoStore.getInstance().saveDiscoveredScannerInfoToState(project, this);
updateDiscoveredInfo(createPathInfoObject(), new ArrayList(siChangedForFileMap.keySet()));
monitor.worked(50);
} catch (CoreException e) {
MakeCorePlugin.log(e);
}
siChangedForFileList.clear();
}
monitor.done();
// siChangedForFileList.clear();
siChangedForFileMap.clear();
siChangedForCommandIdList.clear();
monitor.done();
}
/* (non-Javadoc)
@ -369,11 +443,16 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
return new PerFileDiscoveredPathInfo();
}
private boolean scannerInfoChanged() {
// return !siChangedForFileList.isEmpty();
return !siChangedForFileMap.isEmpty();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#getCollectedScannerInfo(java.lang.Object, org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes)
*/
public List getCollectedScannerInfo(Object resource, ScannerInfoTypes type) {
List rv = null;
List rv = new ArrayList();
// check the resource
String errorMessage = null;
if (resource == null) {
@ -394,7 +473,6 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
}
else if (project.equals(((IResource)resource).getProject())) {
if (type.equals(ScannerInfoTypes.COMPILER_COMMAND)) {
rv = new ArrayList();
for (Iterator i = sid.commandIdCommandMap.keySet().iterator(); i.hasNext(); ) {
Integer cmdId = (Integer) i.next();
Set fileSet = (Set) sid.commandIdToFilesMap.get(cmdId);
@ -403,6 +481,30 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
}
}
}
else if (type.equals(ScannerInfoTypes.UNDISCOVERED_COMPILER_COMMAND)) {
// if (!siChangedForFileList.isEmpty()) {
if (scannerInfoChanged()) {
if (siChangedForCommandIdList.isEmpty()) {
// for (Iterator i = siChangedForFileList.iterator(); i.hasNext(); ) {
for (Iterator i = siChangedForFileMap.keySet().iterator(); i.hasNext(); ) {
// IPath path = (IPath) i.next();
IFile file = (IFile) i.next();
Integer cmdId = (Integer) siChangedForFileMap.get(file);
if (cmdId != null) {
if (!siChangedForCommandIdList.contains(cmdId)) {
siChangedForCommandIdList.add(cmdId);
}
}
}
}
Collections.sort(siChangedForCommandIdList);
for (Iterator i = siChangedForCommandIdList.iterator(); i.hasNext(); ) {
Integer cmdId = (Integer) i.next();
CCommandDSC command = (CCommandDSC) sid.commandIdCommandMap.get(cmdId);
rv.add(command);
}
}
}
}
return rv;
}
@ -444,17 +546,20 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
*/
public void deleteAll(IResource resource) {
if (resource.equals(project)) {
siChangedForFileList = new ArrayList();
// siChangedForFileList = new ArrayList();
siChangedForFileMap.clear();
Set changedFiles = sid.fileToCommandIdMap.keySet();
for (Iterator i = changedFiles.iterator(); i.hasNext(); ) {
IFile file = (IFile) i.next();
IPath path = file.getFullPath();
siChangedForFileList.add(path);
// IPath path = file.getFullPath();
// siChangedForFileList.add(path);
siChangedForFileMap.put(file, null);
}
sid = new ScannerInfoData();
freeCommandIdPool = new TreeSet();
commandIdCounter = 0;
freeCommandIdPool.clear();
siAvailable = false;
}
}
@ -621,23 +726,27 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
return sid;
}
/**
* @param path
* @return
*/
private CCommandDSC getCommand(IPath path) {
CCommandDSC cmd = null;
IFile file = project.getWorkspace().getRoot().getFile(path);
if (file != null) {
Integer cmdId = (Integer) sid.fileToCommandIdMap.get(file);
if (cmdId != null) {
// get the command
cmd = (CCommandDSC) sid.commandIdCommandMap.get(cmdId);
}
}
return cmd;
}
}
/**
* @param path
* @return
*/
private CCommandDSC getCommand(IPath path) {
IFile file = project.getWorkspace().getRoot().getFile(path);
return getCommand(file);
}
private CCommandDSC getCommand(IFile file) {
CCommandDSC cmd = null;
if (file != null) {
Integer cmdId = (Integer) sid.fileToCommandIdMap.get(file);
if (cmdId != null) {
// get the command
cmd = (CCommandDSC) sid.commandIdCommandMap.get(cmdId);
}
}
return cmd;
}
}

View file

@ -60,7 +60,7 @@ public class SCDMakefileGenerator extends DefaultRunSIProvider {
if (collector instanceof IScannerInfoCollector2) {
IScannerInfoCollector2 collector2 = (IScannerInfoCollector2) collector;
List commands = collector2.getCollectedScannerInfo(
resource.getProject(), ScannerInfoTypes.COMPILER_COMMAND);
resource.getProject(), ScannerInfoTypes.UNDISCOVERED_COMPILER_COMMAND);
if (commands != null && commands.size() > 0) {
StringBuffer buffer = new StringBuffer();

View file

@ -279,7 +279,9 @@ public class DiscoveryOptionsBlock extends AbstractDiscoveryOptionsBlock {
}
getBuildInfo().save();
if (isProfileDifferentThenPersisted()) {
changeDiscoveryContainer(project);
if (project != null) {
changeDiscoveryContainer(project);
}
updatePersistedProfile();
}
}

View file

@ -1,3 +1,12 @@
2005-05-10 Vladimir Hirsl
Fix for PR 94500: [Path Entry] Problem marker: Invalid project path: DISCOVERED_SCANNER_INFO
* model/org/eclipse/cdt/internal/core/model/PathEntryUtil.java
Fix for infinite loop in LocationMap.createSoleLocation(..). Courtesy of John C.
* parser/org/eclipse/cdt/internal/core/parser/scanner2/LoactionMap.java
2005-05-02 Vladimir Hirsl
Fix for PR 92599: [Indexer] Remove annotation markers preference from DOMIndexer & friends
Removed indexer problem markers property page block for DOMIndexer.

View file

@ -424,7 +424,8 @@ public class PathEntryUtil {
boolean recurseInContainers) {
IProject project = cProject.getProject();
IPath path = entry.getPath();
if (entry.getEntryKind() != IPathEntry.CDT_PROJECT) {
if (entry.getEntryKind() != IPathEntry.CDT_PROJECT &&
entry.getEntryKind() != IPathEntry.CDT_CONTAINER) {
if (!isValidWorkspacePath(project, path)) {
return new CModelStatus(
ICModelStatusConstants.INVALID_PATHENTRY,

View file

@ -1740,7 +1740,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
if (c.containsInDirective(offset, length)) {
_CompositeContext parent = c.parent;
while (!(parent instanceof _CompositeFileContext))
parent = c.parent;
parent = parent.parent;
_CompositeFileContext fc = (_CompositeFileContext) parent;
return new FileLocation(fc.reader.filename, reconcileOffset(fc,
c, offset), length);
@ -1758,7 +1758,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
{
_CompositeContext parent = c.parent;
while (!(parent instanceof _CompositeFileContext))
parent = c.parent;
parent = parent.parent;
_CompositeFileContext fc = (_CompositeFileContext) parent;
return new FileLocation(fc.reader.filename, reconcileOffset(fc,
c, offset), length);