mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Per file scanner info collector and container now support -include and -imacros command line options.
Adding discovered include paths as system paths to so that they can be properly retrieved from IScannerInfo implementation. Parser needs to be updated to ask IScannerInfoExtension implementation for both user and system include paths. Fix for ClassCastException in CPPClassType binding.
This commit is contained in:
parent
cc1cf61ddf
commit
7abf1397a2
11 changed files with 133 additions and 88 deletions
|
@ -147,7 +147,7 @@ public class MakeScannerProvider extends ScannerProvider {
|
|||
}
|
||||
}
|
||||
for (int i = 0; i < includes.length; i++) {
|
||||
IIncludeEntry include = CoreModel.newIncludeEntry(info.getProject().getFullPath(), null, new Path(includes[i]));
|
||||
IIncludeEntry include = CoreModel.newIncludeEntry(info.getProject().getFullPath(), null, new Path(includes[i]), true);
|
||||
if (!cPaths.contains(include)) {
|
||||
cPaths.add(include);
|
||||
}
|
||||
|
|
|
@ -25,26 +25,31 @@ public interface IDiscoveredPathManager {
|
|||
|
||||
/**
|
||||
* Get include paths for the whole project
|
||||
* @return
|
||||
*/
|
||||
IPath[] getIncludePaths();
|
||||
/**
|
||||
* Get defined symbols for the whole project
|
||||
* @return
|
||||
*/
|
||||
Map getSymbols();
|
||||
|
||||
/**
|
||||
* Get include paths for the specific path (file)
|
||||
* @return
|
||||
*/
|
||||
IPath[] getIncludePaths(IPath path);
|
||||
/**
|
||||
* Get defined symbols for the specific path (file)
|
||||
* @return
|
||||
*/
|
||||
Map getSymbols(IPath path);
|
||||
|
||||
/**
|
||||
* Get include files (gcc option -include) for the specific path (file)
|
||||
*/
|
||||
IPath[] getIncludeFiles(IPath path);
|
||||
/**
|
||||
* Get macro files (gcc option -imacros) for the specific path (file)
|
||||
*/
|
||||
IPath[] getMacroFiles(IPath path);
|
||||
|
||||
IDiscoveredScannerInfoSerializable getSerializable();
|
||||
ScannerConfigScope getScope();
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ public abstract class AbstractDiscoveredPathContainer implements IPathEntryConta
|
|||
Map syms = info.getSymbols();
|
||||
List entries = new ArrayList(includes.length + syms.size());
|
||||
for (int i = 0; i < includes.length; i++) {
|
||||
entries.add(CoreModel.newIncludeEntry(Path.EMPTY, Path.EMPTY, includes[i])); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
entries.add(CoreModel.newIncludeEntry(Path.EMPTY, Path.EMPTY, includes[i], true)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
Iterator iter = syms.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
|
|
|
@ -218,6 +218,20 @@ public class DiscoveredPathInfo implements IDiscoveredPathInfo, IDiscoveredScann
|
|||
return new HashMap(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getIncludeFiles(org.eclipse.core.runtime.IPath)
|
||||
*/
|
||||
public IPath[] getIncludeFiles(IPath path) {
|
||||
return new IPath[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getMacroFiles(org.eclipse.core.runtime.IPath)
|
||||
*/
|
||||
public IPath[] getMacroFiles(IPath path) {
|
||||
return new IPath[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getSerializable()
|
||||
*/
|
||||
|
@ -231,5 +245,5 @@ public class DiscoveredPathInfo implements IDiscoveredPathInfo, IDiscoveredScann
|
|||
public ScannerConfigScope getScope() {
|
||||
return ScannerConfigScope.PROJECT_SCOPE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.IIncludeEntry;
|
||||
import org.eclipse.cdt.core.model.IMacroEntry;
|
||||
import org.eclipse.cdt.core.model.IPathEntry;
|
||||
import org.eclipse.cdt.core.model.IPathEntryContainerExtension;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
|
@ -71,40 +69,38 @@ public class PerFileDiscoveredPathContainer extends AbstractDiscoveredPathContai
|
|||
public IPathEntry[] getPathEntries(IPath path, int mask) {
|
||||
IDiscoveredPathInfo info;
|
||||
ArrayList entries = new ArrayList();
|
||||
if ((mask & IPathEntry.CDT_INCLUDE_FILE) != 0) {
|
||||
// TODO: not implemented
|
||||
}
|
||||
if ((mask & IPathEntry.CDT_INCLUDE) != 0) {
|
||||
// TODO: Vlad how do we differentiate local includes from system includes
|
||||
try {
|
||||
info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject);
|
||||
try {
|
||||
info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject);
|
||||
if ((mask & IPathEntry.CDT_INCLUDE) != 0) {
|
||||
// TODO: Vlad how do we differentiate local includes from system includes
|
||||
IPath[] includes = info.getIncludePaths(path);
|
||||
for (int i = 0; i < includes.length; i++) {
|
||||
entries.add(CoreModel.newIncludeEntry(path, Path.EMPTY, includes[i], true));
|
||||
}
|
||||
return (IIncludeEntry[])entries.toArray(new IIncludeEntry[entries.size()]);
|
||||
}
|
||||
catch (CoreException e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
if ((mask & IPathEntry.CDT_MACRO_FILE) != 0) {
|
||||
// TODO: not implemented
|
||||
}
|
||||
if ((mask & IPathEntry.CDT_MACRO) != 0) {
|
||||
try {
|
||||
info = MakeCorePlugin.getDefault().getDiscoveryManager().getDiscoveredInfo(fProject);
|
||||
}
|
||||
if ((mask & IPathEntry.CDT_MACRO) != 0) {
|
||||
Map syms = info.getSymbols(path);
|
||||
for (Iterator iter = syms.entrySet().iterator(); iter.hasNext(); ) {
|
||||
Entry entry = (Entry)iter.next();
|
||||
entries.add(CoreModel.newMacroEntry(path, (String)entry.getKey(), (String)entry.getValue())); //$NON-NLS-1$
|
||||
}
|
||||
return (IMacroEntry[])entries.toArray(new IMacroEntry[entries.size()]);
|
||||
}
|
||||
catch (CoreException e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((mask & IPathEntry.CDT_INCLUDE_FILE) != 0) {
|
||||
IPath[] includeFiles = info.getIncludeFiles(path);
|
||||
for (int i = 0; i < includeFiles.length; i++) {
|
||||
entries.add(CoreModel.newIncludeFileEntry(path, includeFiles[i]));
|
||||
}
|
||||
}
|
||||
if ((mask & IPathEntry.CDT_MACRO_FILE) != 0) {
|
||||
IPath[] imacrosFiles = info.getMacroFiles(path);
|
||||
for (int i = 0; i < imacrosFiles.length; i++) {
|
||||
entries.add(CoreModel.newMacroFileEntry(path, imacrosFiles[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (CoreException e) {
|
||||
//
|
||||
}
|
||||
return (IPathEntry[]) entries.toArray(new IPathEntry[entries.size()]);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
@ -106,9 +108,10 @@ public class CCommandDSC {
|
|||
commandAsString += optionPair.getValue() + SINGLE_SPACE;
|
||||
}
|
||||
else {
|
||||
// if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString()) ||
|
||||
// optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString()))
|
||||
// continue;
|
||||
// skip -include and -imacros options
|
||||
if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString()) ||
|
||||
optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString()))
|
||||
continue;
|
||||
commandAsString += optionPair.getKey() + SINGLE_SPACE +
|
||||
optionPair.getValue() + SINGLE_SPACE;
|
||||
}
|
||||
|
@ -116,26 +119,26 @@ public class CCommandDSC {
|
|||
return commandAsString.trim();
|
||||
}
|
||||
|
||||
public String[] getImacrosFile() {
|
||||
public IPath[] getImacrosFile() {
|
||||
List imacrosFiles = new ArrayList();
|
||||
for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
|
||||
KVStringPair optionPair = (KVStringPair)i.next();
|
||||
if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString())) {
|
||||
imacrosFiles.add(optionPair.getValue());
|
||||
imacrosFiles.add(new Path(optionPair.getValue()));
|
||||
}
|
||||
}
|
||||
return (String[]) imacrosFiles.toArray(new String[imacrosFiles.size()]);
|
||||
return (IPath[]) imacrosFiles.toArray(new IPath[imacrosFiles.size()]);
|
||||
}
|
||||
|
||||
public String[] getIncludeFile() {
|
||||
public IPath[] getIncludeFile() {
|
||||
List includeFiles = new ArrayList();
|
||||
for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
|
||||
KVStringPair optionPair = (KVStringPair)i.next();
|
||||
if (optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString())) {
|
||||
includeFiles.add(optionPair.getValue());
|
||||
includeFiles.add(new Path(optionPair.getValue()));
|
||||
}
|
||||
}
|
||||
return (String[]) includeFiles.toArray(new String[includeFiles.size()]);
|
||||
return (IPath[]) includeFiles.toArray(new IPath[includeFiles.size()]);
|
||||
}
|
||||
|
||||
// public List getFilesList() {
|
||||
|
|
|
@ -549,21 +549,15 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
|
|||
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getIncludePaths(org.eclipse.core.runtime.IPath)
|
||||
*/
|
||||
public IPath[] getIncludePaths(IPath path) {
|
||||
IFile file = project.getWorkspace().getRoot().getFile(path);
|
||||
if (file != null) {
|
||||
Integer cmdId = (Integer) sid.fileToCommandIdMap.get(file);
|
||||
if (cmdId != null) {
|
||||
// get the command
|
||||
CCommandDSC cmd = (CCommandDSC) sid.commandIdCommandMap.get(cmdId);
|
||||
if (cmd != null && cmd.isDiscovered()) {
|
||||
List includes = cmd.getIncludes();
|
||||
List includePaths = new ArrayList(includes.size());
|
||||
for (Iterator i = includes.iterator(); i.hasNext(); ) {
|
||||
includePaths.add(new Path((String) i.next()));
|
||||
}
|
||||
return (IPath[])includePaths.toArray(new IPath[includePaths.size()]);
|
||||
}
|
||||
// get the command
|
||||
CCommandDSC cmd = getCommand(path);
|
||||
if (cmd != null && cmd.isDiscovered()) {
|
||||
List includes = cmd.getIncludes();
|
||||
List includePaths = new ArrayList(includes.size());
|
||||
for (Iterator i = includes.iterator(); i.hasNext(); ) {
|
||||
includePaths.add(new Path((String) i.next()));
|
||||
}
|
||||
return (IPath[])includePaths.toArray(new IPath[includePaths.size()]);
|
||||
}
|
||||
return new IPath[0];
|
||||
}
|
||||
|
@ -572,28 +566,46 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
|
|||
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getSymbols(org.eclipse.core.runtime.IPath)
|
||||
*/
|
||||
public Map getSymbols(IPath path) {
|
||||
IFile file = project.getFile(path);
|
||||
if (file != null) {
|
||||
Integer cmdId = (Integer) sid.fileToCommandIdMap.get(file);
|
||||
if (cmdId != null) {
|
||||
// get the command
|
||||
CCommandDSC cmd = (CCommandDSC) sid.commandIdCommandMap.get(cmdId);
|
||||
if (cmd != null && cmd.isDiscovered()) {
|
||||
List symbols = cmd.getSymbols();
|
||||
Map definedSymbols = new HashMap(symbols.size());
|
||||
for (Iterator i = symbols.iterator(); i.hasNext(); ) {
|
||||
String symbol = (String) i.next();
|
||||
String key = ScannerConfigUtil.getSymbolKey(symbol);
|
||||
String value = ScannerConfigUtil.getSymbolValue(symbol);
|
||||
definedSymbols.put(key, value);
|
||||
}
|
||||
return definedSymbols;
|
||||
}
|
||||
// get the command
|
||||
CCommandDSC cmd = getCommand(path);
|
||||
if (cmd != null && cmd.isDiscovered()) {
|
||||
List symbols = cmd.getSymbols();
|
||||
Map definedSymbols = new HashMap(symbols.size());
|
||||
for (Iterator i = symbols.iterator(); i.hasNext(); ) {
|
||||
String symbol = (String) i.next();
|
||||
String key = ScannerConfigUtil.getSymbolKey(symbol);
|
||||
String value = ScannerConfigUtil.getSymbolValue(symbol);
|
||||
definedSymbols.put(key, value);
|
||||
}
|
||||
return definedSymbols;
|
||||
}
|
||||
return new HashMap(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getIncludeFiles(org.eclipse.core.runtime.IPath)
|
||||
*/
|
||||
public IPath[] getIncludeFiles(IPath path) {
|
||||
// get the command
|
||||
CCommandDSC cmd = getCommand(path);
|
||||
if (cmd != null) {
|
||||
return cmd.getIncludeFile();
|
||||
}
|
||||
return new IPath[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getMacroFiles(org.eclipse.core.runtime.IPath)
|
||||
*/
|
||||
public IPath[] getMacroFiles(IPath path) {
|
||||
// get the command
|
||||
CCommandDSC cmd = getCommand(path);
|
||||
if (cmd != null) {
|
||||
return cmd.getImacrosFile();
|
||||
}
|
||||
return new IPath[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager.IDiscoveredPathInfo#getSerializable()
|
||||
*/
|
||||
|
@ -608,6 +620,23 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
|
|||
return ScannerConfigScope.FILE_SCOPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException;
|
|||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
|
@ -41,15 +42,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
/**
|
||||
* A DOMSourceIndexerRunner indexes source files using the DOMAST. The following items are indexed:
|
||||
* Declarations:
|
||||
* - Classes
|
||||
* - Structs
|
||||
* - Unions
|
||||
* References:
|
||||
* - Classes
|
||||
* - Structs
|
||||
* - Unions
|
||||
* A DOMSourceIndexerRunner indexes source files using the DOM AST.
|
||||
*
|
||||
* @author vhirsl
|
||||
*/
|
||||
|
@ -221,6 +214,11 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
|
|||
IProblemBinding problemBinding = (IProblemBinding) name.resolveBinding();
|
||||
errorMessage = problemBinding.getMessage();
|
||||
location = name.getNodeLocations()[0];
|
||||
IASTNode node = problemBinding.getASTNode();
|
||||
// if (node != null && !name.equals(node)) {
|
||||
// // TODO may require further processing - looking at the IProblemBinding id
|
||||
// location = node.getNodeLocations()[0];
|
||||
// }
|
||||
}
|
||||
}
|
||||
if (location != null) {
|
||||
|
|
|
@ -217,7 +217,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
|
|||
for (int i = 0; i < containers.length; ++i) {
|
||||
if (containers[i] instanceof IPathEntryContainerExtension) {
|
||||
IPathEntryContainerExtension extension = (IPathEntryContainerExtension)containers[i];
|
||||
IMacroEntry[] incs = (IMacroEntry[])extension.getPathEntries(resPath, IPathEntry.CDT_MACRO);
|
||||
IPathEntry[] incs = (IPathEntry[])extension.getPathEntries(resPath, IPathEntry.CDT_MACRO);
|
||||
macroList.addAll(Arrays.asList(incs));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -582,7 +582,7 @@ public class CPPClassType implements ICPPClassType, ICPPInternalBinding {
|
|||
}
|
||||
}
|
||||
} else if( members[i] instanceof IASTFunctionDefinition ){
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)members[i]).getDeclSpecifier();
|
||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)members[i]).getDeclSpecifier();
|
||||
if( declSpec.isFriend() ){
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition)members[i]).getDeclarator();
|
||||
resultSet.put( dtor.getName().resolveBinding() );
|
||||
|
|
|
@ -98,11 +98,11 @@ public class ScannerProvider extends AbstractCExtension implements IScannerInfoP
|
|||
}
|
||||
String[] localIncludes = new String[localCount];
|
||||
String[] systemIncludes = new String[systemCount];
|
||||
for (int i = 0; i < includeEntries.length; ++i) {
|
||||
for (int i = 0, j = 0, k = 0; i < includeEntries.length; ++i) {
|
||||
if (includeEntries[i].isSystemInclude()) {
|
||||
systemIncludes[i] = includeEntries[i].getFullIncludePath().toOSString();
|
||||
systemIncludes[j++] = includeEntries[i].getFullIncludePath().toOSString();
|
||||
} else {
|
||||
localIncludes[i] = includeEntries[i].getFullIncludePath().toOSString();
|
||||
localIncludes[k++] = includeEntries[i].getFullIncludePath().toOSString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue