mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 17:35:35 +02:00
Cleanup for the interface between fast indexer and preprocessor, bug 209614.
This commit is contained in:
parent
ef7458bcf9
commit
3c10d0917e
27 changed files with 384 additions and 286 deletions
|
@ -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
|
||||
|
@ -11,7 +11,6 @@
|
|||
package org.eclipse.cdt.core.parser.tests.scanner;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.IMacroCollector;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
|
@ -51,7 +50,7 @@ public class FileCodeReaderFactory implements ICodeReaderFactory {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(org.eclipse.cdt.core.dom.ICodeReaderFactoryCallback, java.lang.String)
|
||||
*/
|
||||
public CodeReader createCodeReaderForInclusion(IMacroCollector scanner, String path) {
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
return cache.get(path);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -1853,19 +1853,19 @@ public class PortedScannerTests extends PreprocessorTestsBase {
|
|||
fullyTokenize();
|
||||
validateProblemCount(0);
|
||||
|
||||
Map defs = fScanner.getDefinitions();
|
||||
Map<String, IMacroBinding> defs = fScanner.getMacroDefinitions();
|
||||
assertTrue(defs.containsKey("debug"));
|
||||
assertTrue(defs.containsKey("showlist"));
|
||||
assertTrue(defs.containsKey("report"));
|
||||
IMacroBinding debug = (IMacroBinding) defs.get("debug");
|
||||
IMacroBinding debug = defs.get("debug");
|
||||
assertTrue(new String(debug.getParameterPlaceholderList()[0]).equals("__VA_ARGS__"));
|
||||
assertEquals("fprintf(stderr, __VA_ARGS__)", new String(debug.getExpansion()));
|
||||
|
||||
IMacroBinding showlist = (IMacroBinding) defs.get("showlist");
|
||||
IMacroBinding showlist = defs.get("showlist");
|
||||
assertTrue(new String(showlist.getParameterPlaceholderList()[0]).equals("__VA_ARGS__"));
|
||||
assertTrue(new String(showlist.getExpansion())
|
||||
.equals("puts(#__VA_ARGS__)"));
|
||||
IMacroBinding report = (IMacroBinding) defs.get("report");
|
||||
IMacroBinding report = defs.get("report");
|
||||
assertTrue(new String(report.getParameterPlaceholderList()[0]).equals("test"));
|
||||
assertTrue(new String(report.getParameterPlaceholderList()[1]).equals("__VA_ARGS__"));
|
||||
assertTrue(new String(report.getExpansion())
|
||||
|
@ -1891,7 +1891,7 @@ public class PortedScannerTests extends PreprocessorTestsBase {
|
|||
fullyTokenize();
|
||||
validateProblemCount(0);
|
||||
|
||||
Map defs = fScanner.getDefinitions();
|
||||
Map defs = fScanner.getMacroDefinitions();
|
||||
assertTrue(defs.containsKey("debug"));
|
||||
assertTrue(defs.containsKey("showlist"));
|
||||
assertTrue(defs.containsKey("report"));
|
||||
|
|
|
@ -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
|
||||
|
@ -74,7 +74,7 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
|
|||
}
|
||||
|
||||
fScanner= new CPreprocessor(input, scannerInfo, lang, NULL_LOG, scannerConfig, readerFactory);
|
||||
fLocationResolver= (ILocationResolver) fScanner.getAdapter(ILocationResolver.class);
|
||||
fLocationResolver= fScanner.getLocationMap();
|
||||
}
|
||||
|
||||
protected void initializeScanner() throws Exception {
|
||||
|
@ -147,10 +147,9 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
|
|||
}
|
||||
|
||||
protected void validateDefinition(String name, String value) {
|
||||
Object expObject = fScanner.getDefinitions().get(name);
|
||||
IMacroBinding expObject = fScanner.getMacroDefinitions().get(name);
|
||||
assertNotNull(expObject);
|
||||
assertTrue(expObject instanceof IMacroBinding);
|
||||
assertCharArrayEquals(value.toCharArray(), ((IMacroBinding)expObject).getExpansion());
|
||||
assertCharArrayEquals(value.toCharArray(), expObject.getExpansion());
|
||||
}
|
||||
|
||||
protected void validateDefinition(String name, int value) {
|
||||
|
@ -158,7 +157,7 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
|
|||
}
|
||||
|
||||
protected void validateAsUndefined(String name) {
|
||||
assertNull(fScanner.getDefinitions().get(name.toCharArray()));
|
||||
assertNull(fScanner.getMacroDefinitions().get(name.toCharArray()));
|
||||
}
|
||||
|
||||
protected void validateProblemCount(int count) throws Exception {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom;
|
||||
|
||||
|
@ -42,7 +43,7 @@ public interface ICodeReaderFactory {
|
|||
* @param path
|
||||
* @return CodeReader for contents at that path.
|
||||
*/
|
||||
public CodeReader createCodeReaderForInclusion(IMacroCollector callback, String path);
|
||||
public CodeReader createCodeReaderForInclusion(String path);
|
||||
|
||||
/**
|
||||
* Returns the ICodeReaderCache used for this ICodeReaderFacotry.
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 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
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||
|
||||
/**
|
||||
* Allows an ICodeReaderFactory to retrieve macro definitions from the index,
|
||||
* and then add these definitions to the scanner.
|
||||
*
|
||||
* <p>
|
||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
|
||||
* part of a work in progress. There is no guarantee that this API will
|
||||
* work or that it will remain the same. Please do not use this API without
|
||||
* consulting with the CDT team.
|
||||
* </p>
|
||||
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
// mstodo get rid of this interface
|
||||
public interface IMacroCollector {
|
||||
|
||||
public void addMacroDefinition(IIndexMacro macro);
|
||||
}
|
|
@ -1,20 +1,21 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 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 Rational Software - Initial API and implementation
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
* Implementation for the {@link IExtendedScannerInfo} interface. Allows to configure
|
||||
* the preprocessor.
|
||||
*/
|
||||
public class ExtendedScannerInfo extends ScannerInfo implements IExtendedScannerInfo {
|
||||
|
||||
|
@ -25,12 +26,12 @@ public class ExtendedScannerInfo extends ScannerInfo implements IExtendedScanner
|
|||
{
|
||||
}
|
||||
|
||||
public ExtendedScannerInfo( Map d, String [] incs )
|
||||
public ExtendedScannerInfo( Map<String, String> d, String [] incs )
|
||||
{
|
||||
super(d,incs);
|
||||
}
|
||||
|
||||
public ExtendedScannerInfo( Map d, String [] incs, String [] macros, String [] includes )
|
||||
public ExtendedScannerInfo( Map<String, String> d, String [] incs, String [] macros, String [] includes )
|
||||
{
|
||||
super(d,incs);
|
||||
m = macros;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2003, 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
|
||||
|
@ -13,7 +13,6 @@ package org.eclipse.cdt.core.parser;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IMacroCollector;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.Lexer;
|
||||
|
@ -27,7 +26,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.Lexer;
|
|||
* consulting with the CDT team.
|
||||
* </p>
|
||||
*/
|
||||
public interface IScanner extends IMacroCollector {
|
||||
public interface IScanner {
|
||||
|
||||
/**
|
||||
* Puts the scanner into content assist mode.
|
||||
|
@ -52,7 +51,7 @@ public interface IScanner extends IMacroCollector {
|
|||
* all the definitions that are defined at the current point in the
|
||||
* process of scanning.
|
||||
*/
|
||||
public Map getDefinitions();
|
||||
public Map<String, IMacroBinding> getMacroDefinitions();
|
||||
|
||||
/**
|
||||
* Returns next token for the parser. String literals are concatenated.
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 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 Rational Software - Initial API and implementation
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
|
@ -26,7 +27,7 @@ public interface IScannerInfo {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
public Map getDefinedSymbols();
|
||||
public Map<String, String> getDefinedSymbols();
|
||||
|
||||
/**
|
||||
* Answers a <code>String</code> array containing the union of all the
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 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 Rational Software - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
|
@ -15,39 +16,35 @@ import java.util.Collections;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
* Implementation of the {@link IScannerInfo} interface. Allows to configure the preprocessor.
|
||||
*/
|
||||
public class ScannerInfo implements IScannerInfo
|
||||
{
|
||||
private Map definedSymbols = Collections.EMPTY_MAP;
|
||||
private Map<String, String> definedSymbols = Collections.emptyMap();
|
||||
private String [] includePaths = {};
|
||||
|
||||
public ScannerInfo()
|
||||
{
|
||||
}
|
||||
|
||||
public ScannerInfo( Map d, String [] incs )
|
||||
public ScannerInfo(Map<String, String> macroDefinitions, String[] includeSearchPath)
|
||||
{
|
||||
if (d != null) {
|
||||
definedSymbols = d;
|
||||
if (macroDefinitions != null) {
|
||||
definedSymbols = macroDefinitions;
|
||||
}
|
||||
if (incs != null) {
|
||||
includePaths = incs;
|
||||
if (includeSearchPath != null) {
|
||||
includePaths = includeSearchPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param definitions
|
||||
*/
|
||||
public ScannerInfo(Map definitions) {
|
||||
this(definitions, (String [])null);
|
||||
public ScannerInfo(Map<String, String> macroDefinitions) {
|
||||
this(macroDefinitions, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScannerInfo#getDefinedSymbols()
|
||||
*/
|
||||
public Map getDefinedSymbols()
|
||||
public Map<String, String> getDefinedSymbols()
|
||||
{
|
||||
return definedSymbols;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2005, 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
|
||||
|
@ -14,15 +14,15 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.IMacroCollector;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
|
@ -31,7 +31,9 @@ import org.eclipse.cdt.core.index.IIndexMacro;
|
|||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.FileInclusionHandling;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.IIndexBasedCodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.FileInclusionHandling.InclusionKind;
|
||||
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
|
||||
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -42,21 +44,17 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderFactory {
|
||||
private static final class NeedToParseException extends Exception {}
|
||||
private final static char[] EMPTY_CHARS = new char[0];
|
||||
|
||||
private final IIndex fIndex;
|
||||
private int fLinkage;
|
||||
private Set fIncludedFiles= new HashSet();
|
||||
private Set<IIndexFileLocation> fIncludedFiles= new HashSet<IIndexFileLocation>();
|
||||
/** The fall-back code reader factory used in case a header file is not indexed */
|
||||
private final ICodeReaderFactory fFallBackFactory;
|
||||
private final ASTFilePathResolver fPathResolver;
|
||||
private final AbstractIndexerTask fRelatedIndexerTask;
|
||||
|
||||
public IndexBasedCodeReaderFactory(IIndex index, ASTFilePathResolver pathResolver, int linkage) {
|
||||
this(index, pathResolver, linkage, null);
|
||||
}
|
||||
|
||||
public IndexBasedCodeReaderFactory(IIndex index, ASTFilePathResolver pathResolver, int linkage, ICodeReaderFactory fallbackFactory) {
|
||||
public IndexBasedCodeReaderFactory(IIndex index, ASTFilePathResolver pathResolver, int linkage,
|
||||
ICodeReaderFactory fallbackFactory) {
|
||||
this(index, pathResolver, linkage, fallbackFactory, null);
|
||||
}
|
||||
|
||||
|
@ -74,10 +72,20 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
|
|||
}
|
||||
|
||||
public CodeReader createCodeReaderForTranslationUnit(String path) {
|
||||
if (fFallBackFactory != null) {
|
||||
return fFallBackFactory.createCodeReaderForTranslationUnit(path);
|
||||
}
|
||||
return ParserUtil.createReader(path, null);
|
||||
}
|
||||
|
||||
public CodeReader createCodeReaderForInclusion(IMacroCollector scanner, String path) {
|
||||
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
if (fFallBackFactory != null) {
|
||||
return fFallBackFactory.createCodeReaderForInclusion(path);
|
||||
}
|
||||
return ParserUtil.createReader(path, null);
|
||||
}
|
||||
|
||||
public FileInclusionHandling getInclusionHandling(String path) {
|
||||
IIndexFileLocation ifl= fPathResolver.resolveIncludeFile(path);
|
||||
if (ifl == null) {
|
||||
return null;
|
||||
|
@ -86,25 +94,21 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
|
|||
|
||||
// include files once, only.
|
||||
if (!fIncludedFiles.add(ifl)) {
|
||||
return new CodeReader(path, EMPTY_CHARS);
|
||||
return new FileInclusionHandling(path, InclusionKind.SKIP_FILE);
|
||||
}
|
||||
|
||||
try {
|
||||
IIndexFile file= fIndex.getFile(fLinkage, ifl);
|
||||
if (file != null) {
|
||||
try {
|
||||
LinkedHashMap macroMap= new LinkedHashMap();
|
||||
LinkedHashMap<IIndexFileLocation, IIndexMacro[]> macroMap= new LinkedHashMap<IIndexFileLocation, IIndexMacro[]>();
|
||||
collectMacros(file, macroMap, false);
|
||||
for (Iterator iterator = macroMap.entrySet().iterator(); iterator.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) iterator.next();
|
||||
IIndexFileLocation includedIFL = (IIndexFileLocation) entry.getKey();
|
||||
IIndexMacro[] macros = (IIndexMacro[]) entry.getValue();
|
||||
for (int i = 0; i < macros.length; ++i) {
|
||||
scanner.addMacroDefinition(macros[i]);
|
||||
}
|
||||
fIncludedFiles.add(includedIFL);
|
||||
ArrayList<IIndexMacro> allMacros= new ArrayList<IIndexMacro>();
|
||||
for (Map.Entry<IIndexFileLocation,IIndexMacro[]> entry : macroMap.entrySet()) {
|
||||
allMacros.addAll(Arrays.asList(entry.getValue()));
|
||||
fIncludedFiles.add(entry.getKey());
|
||||
}
|
||||
return new CodeReader(path, EMPTY_CHARS);
|
||||
return new FileInclusionHandling(path, allMacros);
|
||||
}
|
||||
catch (NeedToParseException e) {
|
||||
}
|
||||
|
@ -114,10 +118,11 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
|
|||
CCorePlugin.log(e);
|
||||
}
|
||||
|
||||
if (fFallBackFactory != null) {
|
||||
return fFallBackFactory.createCodeReaderForInclusion(scanner, path);
|
||||
CodeReader codeReader= createCodeReaderForInclusion(path);
|
||||
if (codeReader != null) {
|
||||
return new FileInclusionHandling(codeReader);
|
||||
}
|
||||
return ParserUtil.createReader(path, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
||||
|
@ -125,7 +130,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
|
|||
return fIncludedFiles.contains(ifl);
|
||||
}
|
||||
|
||||
private void collectMacros(IIndexFile file, LinkedHashMap macroMap, boolean checkIncluded) throws CoreException, NeedToParseException {
|
||||
private void collectMacros(IIndexFile file, LinkedHashMap<IIndexFileLocation, IIndexMacro[]> macroMap, boolean checkIncluded) throws CoreException, NeedToParseException {
|
||||
IIndexFileLocation ifl= file.getLocation();
|
||||
if (macroMap.containsKey(ifl) || (checkIncluded && fIncludedFiles.contains(ifl))) {
|
||||
return;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2007, 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
|
||||
* IBM - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.indexer;
|
||||
|
@ -15,7 +15,6 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.IMacroCollector;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
|
||||
|
@ -33,7 +32,7 @@ import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
|||
*/
|
||||
public class StandaloneIndexerFallbackReaderFactory implements ICodeReaderFactory {
|
||||
|
||||
public CodeReader createCodeReaderForInclusion(IMacroCollector callback, String path) {
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
try {
|
||||
if (!new File(path).exists())
|
||||
return null;
|
||||
|
|
|
@ -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
|
||||
|
@ -394,9 +394,9 @@ class ASTInclusionNode implements IASTInclusionNode {
|
|||
|
||||
public IASTInclusionNode[] getNestedInclusions() {
|
||||
if (fInclusions == null) {
|
||||
ArrayList result= new ArrayList();
|
||||
ArrayList<IASTInclusionNode> result= new ArrayList<IASTInclusionNode>();
|
||||
fLocationCtx.getInclusions(result);
|
||||
fInclusions= (IASTInclusionNode[]) result.toArray(new IASTInclusionNode[result.size()]);
|
||||
fInclusions= result.toArray(new IASTInclusionNode[result.size()]);
|
||||
}
|
||||
return fInclusions;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* 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)
|
||||
* IBM - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
|
@ -53,7 +53,7 @@ class ASTProblem extends ASTPreprocessorNode implements IASTProblem {
|
|||
if (message != null)
|
||||
return message;
|
||||
|
||||
String msg = (String) errorMessages.get(new Integer(id));
|
||||
String msg = errorMessages.get(new Integer(id));
|
||||
if (msg == null)
|
||||
msg = ""; //$NON-NLS-1$
|
||||
|
||||
|
@ -85,9 +85,9 @@ class ASTProblem extends ASTPreprocessorNode implements IASTProblem {
|
|||
}
|
||||
|
||||
|
||||
protected static final Map errorMessages;
|
||||
protected static final Map<Integer, String> errorMessages;
|
||||
static {
|
||||
errorMessages = new HashMap();
|
||||
errorMessages = new HashMap<Integer, String>();
|
||||
errorMessages
|
||||
.put(
|
||||
new Integer(IASTProblem.PREPROCESSOR_POUND_ERROR),
|
||||
|
|
|
@ -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
|
||||
|
@ -14,19 +14,21 @@ package org.eclipse.cdt.internal.core.parser.scanner;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IMacro;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
|
@ -156,7 +158,7 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
};
|
||||
|
||||
final private IParserLogService fLog;
|
||||
final private ICodeReaderFactory fCodeReaderFactory;
|
||||
final private IIndexBasedCodeReaderFactory fCodeReaderFactory;
|
||||
private final ExpressionEvaluator fExpressionEvaluator;
|
||||
private final MacroDefinitionParser fMacroDefinitionParser;
|
||||
private final MacroExpander fMacroExpander;
|
||||
|
@ -178,7 +180,7 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
private final LocationMap fLocationMap = new LocationMap();
|
||||
|
||||
/** Set of already included files */
|
||||
private final HashSet fAllIncludedFiles= new HashSet();
|
||||
private final HashSet<String> fAllIncludedFiles= new HashSet<String>();
|
||||
|
||||
private final Lexer fRootLexer;
|
||||
private final ScannerContext fRootContext;
|
||||
|
@ -205,7 +207,7 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
fExpressionEvaluator= new ExpressionEvaluator();
|
||||
fMacroDefinitionParser= new MacroDefinitionParser();
|
||||
fMacroExpander= new MacroExpander(this, fMacroDictionary, fLocationMap, fMacroDefinitionParser, fLexOptions);
|
||||
fCodeReaderFactory= readerFactory;
|
||||
fCodeReaderFactory= wrapReaderFactory(readerFactory);
|
||||
|
||||
setupMacroDictionary(configuration, info, language);
|
||||
|
||||
|
@ -220,7 +222,37 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
}
|
||||
}
|
||||
|
||||
public void setComputeImageLocations(boolean val) {
|
||||
private IIndexBasedCodeReaderFactory wrapReaderFactory(final ICodeReaderFactory readerFactory) {
|
||||
if (readerFactory instanceof IIndexBasedCodeReaderFactory) {
|
||||
return (IIndexBasedCodeReaderFactory) readerFactory;
|
||||
}
|
||||
return new IIndexBasedCodeReaderFactory() {
|
||||
public CodeReader createCodeReaderForTranslationUnit(String path) {
|
||||
return readerFactory.createCodeReaderForTranslationUnit(path);
|
||||
}
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
return readerFactory.createCodeReaderForInclusion(path);
|
||||
}
|
||||
public FileInclusionHandling getInclusionHandling(String path) {
|
||||
CodeReader reader= readerFactory.createCodeReaderForInclusion(path);
|
||||
if (reader != null) {
|
||||
return new FileInclusionHandling(reader);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
||||
return fAllIncludedFiles.contains(path);
|
||||
}
|
||||
public ICodeReaderCache getCodeReaderCache() {
|
||||
return readerFactory.getCodeReaderCache();
|
||||
}
|
||||
public int getUniqueIdentifier() {
|
||||
return readerFactory.getUniqueIdentifier();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void setComputeImageLocations(boolean val) {
|
||||
fLexOptions.fCreateImageLocations= val;
|
||||
}
|
||||
|
||||
|
@ -229,6 +261,13 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
fRootLexer.setContentAssistMode(offset);
|
||||
}
|
||||
|
||||
public void setScanComments(boolean val) {
|
||||
}
|
||||
|
||||
public ILocationResolver getLocationResolver() {
|
||||
return fLocationMap;
|
||||
}
|
||||
|
||||
private void configureKeywords(ParserLanguage language, IScannerExtensionConfiguration configuration) {
|
||||
Keywords.addKeywordsPreprocessor(fPPKeywords);
|
||||
if (language == ParserLanguage.C) {
|
||||
|
@ -286,17 +325,17 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
|
||||
IMacro[] toAdd = config.getAdditionalMacros();
|
||||
for (int i = 0; i < toAdd.length; i++) {
|
||||
addDefinition(toAdd[i]);
|
||||
final IMacro macro = toAdd[i];
|
||||
addMacroDefinition(macro.getSignature(), macro.getExpansion());
|
||||
}
|
||||
|
||||
// macros provided on command-line (-D)
|
||||
final boolean initEmptyMacros= config.initializeMacroValuesTo1();
|
||||
final Map macroDict= info.getDefinedSymbols();
|
||||
final Map<String, String> macroDict= info.getDefinedSymbols();
|
||||
if (macroDict != null) {
|
||||
for (Iterator iterator = macroDict.entrySet().iterator(); iterator.hasNext();) {
|
||||
final Map.Entry entry = (Map.Entry) iterator.next();
|
||||
final String key= (String) entry.getKey();
|
||||
final String value= ((String) entry.getValue()).trim();
|
||||
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);
|
||||
}
|
||||
|
@ -373,12 +412,12 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
}
|
||||
}
|
||||
|
||||
public Map getDefinitions() {
|
||||
public Map<String, IMacroBinding> getMacroDefinitions() {
|
||||
final CharArrayObjectMap objMap= fMacroDictionary;
|
||||
int size = objMap.size();
|
||||
Map hashMap = new HashMap(size);
|
||||
Map<String, IMacroBinding> hashMap = new HashMap<String, IMacroBinding>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
hashMap.put(String.valueOf(objMap.keyAt(i)), objMap.getAt(i));
|
||||
hashMap.put(String.valueOf(objMap.keyAt(i)), (IMacroBinding) objMap.getAt(i));
|
||||
}
|
||||
|
||||
return hashMap;
|
||||
|
@ -738,9 +777,9 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
}
|
||||
}
|
||||
|
||||
private CodeReader findInclusion(final String filename, final boolean quoteInclude,
|
||||
private FileInclusionHandling findInclusion(final String filename, final boolean quoteInclude,
|
||||
final boolean includeNext, final File currentDir) {
|
||||
return (CodeReader) findInclusion(filename, quoteInclude, includeNext, currentDir, createCodeReaderTester);
|
||||
return (FileInclusionHandling) findInclusion(filename, quoteInclude, includeNext, currentDir, createCodeReaderTester);
|
||||
}
|
||||
|
||||
private Object findInclusion(final String filename, final boolean quoteInclude,
|
||||
|
@ -800,7 +839,7 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
}
|
||||
|
||||
|
||||
public void addMacroDefinition(IIndexMacro macro) {
|
||||
private void addMacroDefinition(IIndexMacro macro) {
|
||||
try {
|
||||
PreprocessorMacro result= fMacroDefinitionParser.parseMacroDefinition(macro.getNameCharArray(), macro.getParameterList(), macro.getExpansionImage());
|
||||
final IASTFileLocation loc= macro.getFileLocation();
|
||||
|
@ -824,10 +863,9 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
fLocationMap.encounterProblem(id, arg, offset, endOffset);
|
||||
}
|
||||
|
||||
private CodeReader createReader(String path, String fileName){
|
||||
private FileInclusionHandling createReader(String path, String fileName){
|
||||
String finalPath = ScannerUtility.createReconciledPath(path, fileName);
|
||||
CodeReader reader = fCodeReaderFactory.createCodeReaderForInclusion(this, finalPath);
|
||||
return reader;
|
||||
return fCodeReaderFactory.getInclusionHandling(finalPath);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1019,47 +1057,56 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
|
||||
String path= null;
|
||||
boolean reported= false;
|
||||
if (active) {
|
||||
|
||||
if (!active) {
|
||||
// test if the include is inactive just because it was included before (bug 167100)
|
||||
final File currentDir= userInclude || include_next ? new File(String.valueOf(getCurrentFilename())).getParentFile() : null;
|
||||
final CodeReader reader= findInclusion(new String(headerName), userInclude, include_next, currentDir);
|
||||
if (reader != null) {
|
||||
path= new String(reader.filename);
|
||||
if (!isCircularInclusion(path)) {
|
||||
reported= true;
|
||||
fAllIncludedFiles.add(path);
|
||||
ILocationCtx ctx= fLocationMap.pushInclusion(poundOffset, nameOffsets[0], nameOffsets[1], condEndOffset, reader.buffer, path, headerName, userInclude);
|
||||
ScannerContext fctx= new ScannerContext(ctx, fCurrentContext, new Lexer(reader.buffer, fLexOptions, this, this));
|
||||
fCurrentContext= fctx;
|
||||
final String resolved= (String) findInclusion(new String(headerName), userInclude, include_next, currentDir, createPathTester);
|
||||
if (resolved != null && fCodeReaderFactory.hasFileBeenIncludedInCurrentTranslationUnit(resolved)) {
|
||||
path= resolved;
|
||||
}
|
||||
}
|
||||
else {
|
||||
final File currentDir= userInclude || include_next ? new File(String.valueOf(getCurrentFilename())).getParentFile() : null;
|
||||
final FileInclusionHandling fi= findInclusion(new String(headerName), userInclude, include_next, currentDir);
|
||||
if (fi != null) {
|
||||
path= fi.getFileLocation();
|
||||
switch(fi.getKind()) {
|
||||
case FOUND_IN_INDEX:
|
||||
processInclusionFromIndex(path, fi);
|
||||
break;
|
||||
case USE_CODE_READER:
|
||||
CodeReader reader= fi.getCodeReader();
|
||||
if (reader != null && !isCircularInclusion(path)) {
|
||||
reported= true;
|
||||
fAllIncludedFiles.add(path);
|
||||
ILocationCtx ctx= fLocationMap.pushInclusion(poundOffset, nameOffsets[0], nameOffsets[1], condEndOffset, reader.buffer, path, headerName, userInclude);
|
||||
ScannerContext fctx= new ScannerContext(ctx, fCurrentContext, new Lexer(reader.buffer, fLexOptions, this, this));
|
||||
fCurrentContext= fctx;
|
||||
}
|
||||
break;
|
||||
|
||||
case SKIP_FILE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, headerName, poundOffset, condEndOffset);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// test if the include is inactive just because it was included before (bug 167100)
|
||||
final File currentDir= userInclude || include_next ? new File(String.valueOf(getCurrentFilename())).getParentFile() : null;
|
||||
path= (String) findInclusion(new String(headerName), userInclude, include_next, currentDir, createPathTester);
|
||||
if (path != null) {
|
||||
if (fCodeReaderFactory instanceof IIndexBasedCodeReaderFactory) {
|
||||
// fast indexer
|
||||
if (!((IIndexBasedCodeReaderFactory) fCodeReaderFactory).hasFileBeenIncludedInCurrentTranslationUnit(path)) {
|
||||
path= null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// full indexer
|
||||
if (!fAllIncludedFiles.contains(path)) {
|
||||
path= null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!reported) {
|
||||
fLocationMap.encounterPoundInclude(poundOffset, nameOffsets[0], nameOffsets[1], condEndOffset, headerName, path, userInclude, active);
|
||||
}
|
||||
}
|
||||
|
||||
private void processInclusionFromIndex(String path, FileInclusionHandling fi) {
|
||||
ArrayList<IIndexMacro> mdefs= fi.getMacroDefinitions();
|
||||
for (IIndexMacro macro : mdefs) {
|
||||
addMacroDefinition(macro);
|
||||
}
|
||||
}
|
||||
|
||||
private char[] extractHeaderName(final char[] image, final char startDelim, final char endDelim, int[] offsets) {
|
||||
char[] headerName;
|
||||
int start= 0;
|
||||
|
@ -1372,29 +1419,4 @@ public class CPreprocessor implements ILexerLog, IScanner {
|
|||
fCurrentContext= new ScannerContext(ctx, fCurrentContext, replacement);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object getAdapter(Class adapter) {
|
||||
if (adapter.isAssignableFrom(fLocationMap.getClass())) {
|
||||
return fLocationMap;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// old scanner, remove this.
|
||||
public CharArrayObjectMap getRealDefinitions() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public void addDefinition(IMacro macro) {
|
||||
if (macro instanceof IIndexMacro) {
|
||||
addMacroDefinition((IIndexMacro) macro);
|
||||
}
|
||||
else {
|
||||
addMacroDefinition(macro.getSignature(), macro.getExpansion());
|
||||
}
|
||||
}
|
||||
public void setScanComments(boolean val) {
|
||||
}
|
||||
public ILocationResolver getLocationResolver() {
|
||||
return fLocationMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
|
||||
/**
|
||||
* Instructs the preprocessor on how to handle a file-inclusion.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class FileInclusionHandling {
|
||||
public enum InclusionKind {
|
||||
/**
|
||||
* Instruct the preprocessor to skip this inclusion.
|
||||
*/
|
||||
SKIP_FILE,
|
||||
/**
|
||||
* The file and its dependents are indexed, required information is read
|
||||
* from there.
|
||||
*/
|
||||
FOUND_IN_INDEX,
|
||||
/**
|
||||
* The file has to be scanned, a code reader is provided.
|
||||
*/
|
||||
USE_CODE_READER
|
||||
}
|
||||
|
||||
private InclusionKind fKind;
|
||||
private CodeReader fCodeReader;
|
||||
private ArrayList<IIndexMacro> fMacroDefinitions;
|
||||
private String fFileLocation;
|
||||
|
||||
public FileInclusionHandling(String fileLocation, InclusionKind kind) {
|
||||
assert kind == InclusionKind.SKIP_FILE;
|
||||
fFileLocation= fileLocation;
|
||||
fKind= kind;
|
||||
}
|
||||
|
||||
public FileInclusionHandling(CodeReader codeReader) {
|
||||
assert codeReader != null;
|
||||
fKind= InclusionKind.USE_CODE_READER;
|
||||
fCodeReader= codeReader;
|
||||
if (codeReader != null) {
|
||||
fFileLocation= codeReader.getPath();
|
||||
}
|
||||
}
|
||||
|
||||
public FileInclusionHandling(String fileLocation, ArrayList<IIndexMacro> macroDefinitions) {
|
||||
fKind= InclusionKind.FOUND_IN_INDEX;
|
||||
fFileLocation= fileLocation;
|
||||
fMacroDefinitions= macroDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the kind
|
||||
*/
|
||||
public InclusionKind getKind() {
|
||||
return fKind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid with {@link InclusionKind#USE_CODE_READER}.
|
||||
* @return the codeReader
|
||||
*/
|
||||
public CodeReader getCodeReader() {
|
||||
return fCodeReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid with {@link InclusionKind#FOUND_IN_INDEX}.
|
||||
* @return the macroDefinitions
|
||||
*/
|
||||
public ArrayList<IIndexMacro> getMacroDefinitions() {
|
||||
return fMacroDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the location of the file to be included.
|
||||
*/
|
||||
public String getFileLocation() {
|
||||
return fFileLocation;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
@ -23,4 +23,10 @@ public interface IIndexBasedCodeReaderFactory extends ICodeReaderFactory {
|
|||
* Returns whether or not the file has been included.
|
||||
*/
|
||||
boolean hasFileBeenIncludedInCurrentTranslationUnit(String path);
|
||||
|
||||
/**
|
||||
* Create include information object for the given location.
|
||||
* @see FileInclusionHandling
|
||||
*/
|
||||
public FileInclusionHandling getInclusionHandling(String fileLocation);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -15,6 +15,8 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
|
||||
|
||||
/**
|
||||
* Various location contexts which are suitable for interpreting local offsets. These offsets are
|
||||
|
@ -116,12 +118,12 @@ abstract class LocationCtx implements ILocationCtx {
|
|||
* Returns the sequence of file locations spanning the given range.
|
||||
* Assumes that the range starts within this context.
|
||||
*/
|
||||
public abstract boolean collectLocations(int sequenceNumber, int length, ArrayList sofar);
|
||||
public abstract boolean collectLocations(int sequenceNumber, int length, ArrayList<IASTNodeLocation> sofar);
|
||||
|
||||
/**
|
||||
* Support for the dependency tree, add inclusion statements found in this context.
|
||||
*/
|
||||
public void getInclusions(ArrayList target) {
|
||||
public void getInclusions(ArrayList<IASTInclusionNode> result) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,7 +133,7 @@ abstract class LocationCtx implements ILocationCtx {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Collection getChildren() {
|
||||
return Collections.EMPTY_SET;
|
||||
public Collection<LocationCtx> getChildren() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -17,6 +17,8 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
|
||||
|
||||
/**
|
||||
* Base class for all location contexts that can contain children.
|
||||
|
@ -29,7 +31,7 @@ class LocationCtxContainer extends LocationCtx {
|
|||
*/
|
||||
private int fChildSequenceLength;
|
||||
|
||||
private ArrayList fChildren;
|
||||
private ArrayList<LocationCtx> fChildren;
|
||||
private char[] fSource;
|
||||
private int[] fLineOffsets;
|
||||
|
||||
|
@ -38,13 +40,18 @@ class LocationCtxContainer extends LocationCtx {
|
|||
fSource= source;
|
||||
}
|
||||
|
||||
public Collection getChildren() {
|
||||
return fChildren == null ? Collections.EMPTY_LIST : fChildren;
|
||||
public Collection<LocationCtx> getChildren() {
|
||||
if (fChildren == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
else {
|
||||
return fChildren;
|
||||
}
|
||||
}
|
||||
|
||||
public void addChild(LocationCtx locationCtx) {
|
||||
if (fChildren == null) {
|
||||
fChildren= new ArrayList();
|
||||
fChildren= new ArrayList<LocationCtx>();
|
||||
}
|
||||
fChildren.add(locationCtx);
|
||||
}
|
||||
|
@ -65,7 +72,7 @@ class LocationCtxContainer extends LocationCtx {
|
|||
int result= fSequenceNumber + fChildSequenceLength + offset;
|
||||
if (checkChildren && fChildren != null) {
|
||||
for (int i= fChildren.size()-1; i >= 0; i--) {
|
||||
final LocationCtx child= (LocationCtx) fChildren.get(i);
|
||||
final LocationCtx child= fChildren.get(i);
|
||||
if (child.fEndOffsetInParent > offset) { // child was inserted behind the offset, adjust sequence number
|
||||
result-= child.getSequenceLength();
|
||||
}
|
||||
|
@ -109,12 +116,12 @@ class LocationCtxContainer extends LocationCtx {
|
|||
return super.findMappedFileLocation(sequenceNumber, length);
|
||||
}
|
||||
|
||||
public boolean collectLocations(int sequenceNumber, final int length, ArrayList locations) {
|
||||
public boolean collectLocations(int sequenceNumber, final int length, ArrayList<IASTNodeLocation> locations) {
|
||||
final int endSequenceNumber= sequenceNumber+length;
|
||||
if (fChildren != null) {
|
||||
int childIdx= Math.max(0, findChildIdxLessOrEqualThan(sequenceNumber, false));
|
||||
for (; childIdx < fChildren.size(); childIdx++) {
|
||||
final LocationCtx child= (LocationCtx) fChildren.get(childIdx);
|
||||
final LocationCtx child= fChildren.get(childIdx);
|
||||
|
||||
// create the location between start and the child
|
||||
if (sequenceNumber < child.fSequenceNumber) {
|
||||
|
@ -151,7 +158,7 @@ class LocationCtxContainer extends LocationCtx {
|
|||
return false;
|
||||
}
|
||||
|
||||
private ArrayList addFileLocation(int offset, int length, ArrayList sofar) {
|
||||
private ArrayList<IASTNodeLocation> addFileLocation(int offset, int length, ArrayList<IASTNodeLocation> sofar) {
|
||||
IASTFileLocation loc= createFileLocation(offset, length);
|
||||
if (loc != null) {
|
||||
sofar.add(loc);
|
||||
|
@ -171,7 +178,7 @@ class LocationCtxContainer extends LocationCtx {
|
|||
int lower= 0;
|
||||
while (upper > lower) {
|
||||
int middle= (upper+lower)/2;
|
||||
LocationCtx child= (LocationCtx) fChildren.get(middle);
|
||||
LocationCtx child= fChildren.get(middle);
|
||||
int childSequenceNumber= child.fSequenceNumber;
|
||||
if (beforeReplacedChars) {
|
||||
childSequenceNumber-= child.fEndOffsetInParent-child.fOffsetInParent;
|
||||
|
@ -188,13 +195,13 @@ class LocationCtxContainer extends LocationCtx {
|
|||
|
||||
final LocationCtx findChildLessOrEqualThan(final int sequenceNumber, boolean beforeReplacedChars) {
|
||||
final int idx= findChildIdxLessOrEqualThan(sequenceNumber, beforeReplacedChars);
|
||||
return idx >= 0 ? (LocationCtx) fChildren.get(idx) : null;
|
||||
return idx >= 0 ? fChildren.get(idx) : null;
|
||||
}
|
||||
|
||||
public void getInclusions(ArrayList result) {
|
||||
public void getInclusions(ArrayList<IASTInclusionNode> result) {
|
||||
if (fChildren != null) {
|
||||
for (Iterator iterator = fChildren.iterator(); iterator.hasNext();) {
|
||||
LocationCtx ctx= (LocationCtx) iterator.next();
|
||||
for (Iterator<LocationCtx> iterator = fChildren.iterator(); iterator.hasNext();) {
|
||||
LocationCtx ctx= iterator.next();
|
||||
if (ctx.getInclusionStatement() != null) {
|
||||
result.add(new ASTInclusionNode(ctx));
|
||||
}
|
||||
|
@ -217,7 +224,7 @@ class LocationCtxContainer extends LocationCtx {
|
|||
}
|
||||
|
||||
private int[] computeLineOffsets() {
|
||||
ArrayList offsets= new ArrayList();
|
||||
ArrayList<Integer> offsets= new ArrayList<Integer>();
|
||||
for (int i = 0; i < fSource.length; i++) {
|
||||
if (fSource[i] == '\n') {
|
||||
offsets.add(new Integer(i));
|
||||
|
@ -225,7 +232,7 @@ class LocationCtxContainer extends LocationCtx {
|
|||
}
|
||||
int[] result= new int[offsets.size()];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i]= ((Integer) offsets.get(i)).intValue();
|
||||
result[i]= offsets.get(i).intValue();
|
||||
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -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
|
||||
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser.scanner;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
|
||||
|
@ -39,7 +40,7 @@ class LocationCtxMacroExpansion extends LocationCtx {
|
|||
return fLength;
|
||||
}
|
||||
|
||||
public boolean collectLocations(int start, int length, ArrayList locations) {
|
||||
public boolean collectLocations(int start, int length, ArrayList<IASTNodeLocation> locations) {
|
||||
final int offset= start-fSequenceNumber;
|
||||
assert offset >= 0 && length >= 0;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
@ -43,18 +44,18 @@ public class LocationMap implements ILocationResolver {
|
|||
private String fTranslationUnitPath;
|
||||
private IASTTranslationUnit fTranslationUnit;
|
||||
|
||||
private ArrayList fDirectives= new ArrayList();
|
||||
private ArrayList fProblems= new ArrayList();
|
||||
private ArrayList fComments= new ArrayList();
|
||||
private ArrayList fBuiltinMacros= new ArrayList();
|
||||
private IdentityHashMap fMacroReferences= new IdentityHashMap();
|
||||
private ArrayList<ASTPreprocessorNode> fDirectives= new ArrayList<ASTPreprocessorNode>();
|
||||
private ArrayList<ASTProblem> fProblems= new ArrayList<ASTProblem>();
|
||||
private ArrayList<ASTComment> fComments= new ArrayList<ASTComment>();
|
||||
private ArrayList<ASTObjectStyleMacroDefinition> fBuiltinMacros= new ArrayList<ASTObjectStyleMacroDefinition>();
|
||||
private IdentityHashMap<IMacroBinding, List<IASTName>> fMacroReferences= new IdentityHashMap<IMacroBinding, List<IASTName>>();
|
||||
|
||||
private LocationCtxFile fRootContext= null;
|
||||
private LocationCtx fCurrentContext= null;
|
||||
private int fLastChildInsertionOffset;
|
||||
|
||||
// stuff computed on demand
|
||||
private IdentityHashMap fMacroDefinitionMap= null;
|
||||
private IdentityHashMap<IBinding, IASTPreprocessorMacroDefinition> fMacroDefinitionMap= null;
|
||||
|
||||
|
||||
|
||||
|
@ -171,9 +172,9 @@ public class LocationMap implements ILocationResolver {
|
|||
}
|
||||
|
||||
private void addMacroReference(IMacroBinding macro, IASTName name) {
|
||||
List list= (List) fMacroReferences.get(macro);
|
||||
List<IASTName> list= fMacroReferences.get(macro);
|
||||
if (list == null) {
|
||||
list= new ArrayList();
|
||||
list= new ArrayList<IASTName>();
|
||||
fMacroReferences.put(macro, list);
|
||||
}
|
||||
list.add(name);
|
||||
|
@ -362,9 +363,9 @@ public class LocationMap implements ILocationResolver {
|
|||
}
|
||||
|
||||
public IASTNodeLocation[] getLocations(int sequenceNumber, int length) {
|
||||
ArrayList result= new ArrayList();
|
||||
ArrayList<IASTNodeLocation> result= new ArrayList<IASTNodeLocation>();
|
||||
fRootContext.collectLocations(sequenceNumber, length, result);
|
||||
return (IASTNodeLocation[]) result.toArray(new IASTNodeLocation[result.size()]);
|
||||
return result.toArray(new IASTNodeLocation[result.size()]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -373,12 +374,12 @@ public class LocationMap implements ILocationResolver {
|
|||
}
|
||||
|
||||
public IASTImageLocation getImageLocation(int sequenceNumber, int length) {
|
||||
ArrayList result= new ArrayList();
|
||||
ArrayList<IASTNodeLocation> result= new ArrayList<IASTNodeLocation>();
|
||||
fRootContext.collectLocations(sequenceNumber, length, result);
|
||||
if (result.size() != 1) {
|
||||
return null;
|
||||
}
|
||||
IASTNodeLocation loc= (IASTNodeLocation) result.get(0);
|
||||
IASTNodeLocation loc= result.get(0);
|
||||
if (loc instanceof IASTFileLocation) {
|
||||
IASTFileLocation floc= (IASTFileLocation) loc;
|
||||
return new ASTImageLocation(IASTImageLocation.REGULAR_CODE,
|
||||
|
@ -396,7 +397,7 @@ public class LocationMap implements ILocationResolver {
|
|||
int upper= fDirectives.size()-1;
|
||||
while(lower <= upper) {
|
||||
int middle= (lower+upper)/2;
|
||||
ASTPreprocessorNode node= (ASTPreprocessorNode) fDirectives.get(middle);
|
||||
ASTPreprocessorNode node= fDirectives.get(middle);
|
||||
final int nodeSequenceNumber= node.getOffset();
|
||||
if (nodeSequenceNumber <= sequenceNumber) {
|
||||
final int nodeEndSequenceNumber= nodeSequenceNumber + node.getLength();
|
||||
|
@ -428,7 +429,7 @@ public class LocationMap implements ILocationResolver {
|
|||
public int getSequenceNumberForFileOffset(String filePath, int fileOffset) {
|
||||
LocationCtx ctx= fRootContext;
|
||||
if (filePath != null) {
|
||||
LinkedList contexts= new LinkedList();
|
||||
LinkedList<LocationCtx> contexts= new LinkedList<LocationCtx>();
|
||||
while(ctx != null) {
|
||||
if (ctx instanceof LocationCtxFile) {
|
||||
if (filePath.equals(ctx.getFilePath())) {
|
||||
|
@ -440,7 +441,7 @@ public class LocationMap implements ILocationResolver {
|
|||
ctx= null;
|
||||
}
|
||||
else {
|
||||
ctx= (LocationCtx) contexts.removeFirst();
|
||||
ctx= contexts.removeFirst();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -471,41 +472,41 @@ public class LocationMap implements ILocationResolver {
|
|||
|
||||
|
||||
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
|
||||
ArrayList result= new ArrayList();
|
||||
for (Iterator iterator = fDirectives.iterator(); iterator.hasNext();) {
|
||||
ArrayList<Object> result= new ArrayList<Object>();
|
||||
for (Iterator<ASTPreprocessorNode> iterator = fDirectives.iterator(); iterator.hasNext();) {
|
||||
Object directive= iterator.next();
|
||||
if (directive instanceof IASTPreprocessorMacroDefinition) {
|
||||
result.add(directive);
|
||||
}
|
||||
}
|
||||
return (IASTPreprocessorMacroDefinition[]) result.toArray(new IASTPreprocessorMacroDefinition[result.size()]);
|
||||
return result.toArray(new IASTPreprocessorMacroDefinition[result.size()]);
|
||||
}
|
||||
|
||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
||||
ArrayList result= new ArrayList();
|
||||
for (Iterator iterator = fDirectives.iterator(); iterator.hasNext();) {
|
||||
ArrayList<Object> result= new ArrayList<Object>();
|
||||
for (Iterator<ASTPreprocessorNode> iterator = fDirectives.iterator(); iterator.hasNext();) {
|
||||
Object directive= iterator.next();
|
||||
if (directive instanceof IASTPreprocessorIncludeStatement) {
|
||||
result.add(directive);
|
||||
}
|
||||
}
|
||||
return (IASTPreprocessorIncludeStatement[]) result.toArray(new IASTPreprocessorIncludeStatement[result.size()]);
|
||||
return result.toArray(new IASTPreprocessorIncludeStatement[result.size()]);
|
||||
}
|
||||
|
||||
public IASTComment[] getComments() {
|
||||
return (IASTComment[]) fComments.toArray(new IASTComment[fComments.size()]);
|
||||
return fComments.toArray(new IASTComment[fComments.size()]);
|
||||
}
|
||||
|
||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||
return (IASTPreprocessorStatement[]) fDirectives.toArray(new IASTPreprocessorStatement[fDirectives.size()]);
|
||||
return fDirectives.toArray(new IASTPreprocessorStatement[fDirectives.size()]);
|
||||
}
|
||||
|
||||
public IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
|
||||
return (IASTPreprocessorMacroDefinition[]) fBuiltinMacros.toArray(new IASTPreprocessorMacroDefinition[fBuiltinMacros.size()]);
|
||||
return fBuiltinMacros.toArray(new IASTPreprocessorMacroDefinition[fBuiltinMacros.size()]);
|
||||
}
|
||||
|
||||
public IASTProblem[] getScannerProblems() {
|
||||
return (IASTProblem[]) fProblems.toArray(new IASTProblem[fProblems.size()]);
|
||||
return fProblems.toArray(new IASTProblem[fProblems.size()]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -516,9 +517,9 @@ public class LocationMap implements ILocationResolver {
|
|||
|
||||
IASTPreprocessorMacroDefinition getMacroDefinition(IMacroBinding binding) {
|
||||
if (fMacroDefinitionMap == null) {
|
||||
fMacroDefinitionMap= new IdentityHashMap();
|
||||
fMacroDefinitionMap= new IdentityHashMap<IBinding, IASTPreprocessorMacroDefinition>();
|
||||
for (int i = 0; i < fBuiltinMacros.size(); i++) {
|
||||
final IASTPreprocessorMacroDefinition def = (IASTPreprocessorMacroDefinition) fBuiltinMacros.get(i);
|
||||
final IASTPreprocessorMacroDefinition def = fBuiltinMacros.get(i);
|
||||
final IASTName name = def.getName();
|
||||
if (name != null) {
|
||||
fMacroDefinitionMap.put(name.getBinding(), def);
|
||||
|
@ -533,15 +534,15 @@ public class LocationMap implements ILocationResolver {
|
|||
}
|
||||
}
|
||||
}
|
||||
return (IASTPreprocessorMacroDefinition) fMacroDefinitionMap.get(binding);
|
||||
return fMacroDefinitionMap.get(binding);
|
||||
}
|
||||
|
||||
public IASTName[] getReferences(IMacroBinding binding) {
|
||||
List list= (List) fMacroReferences.get(binding);
|
||||
List<IASTName> list= fMacroReferences.get(binding);
|
||||
if (list == null) {
|
||||
return EMPTY_NAMES;
|
||||
}
|
||||
return (IASTName[]) list.toArray(new IASTName[list.size()]);
|
||||
return list.toArray(new IASTName[list.size()]);
|
||||
}
|
||||
|
||||
public IDependencyTree getDependencyTree() {
|
||||
|
|
|
@ -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
|
||||
|
@ -200,7 +200,7 @@ public class MacroDefinitionParser {
|
|||
if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) {
|
||||
return null;
|
||||
}
|
||||
ArrayList paramList= new ArrayList();
|
||||
ArrayList<char[]> paramList= new ArrayList<char[]>();
|
||||
IToken next= null;
|
||||
do {
|
||||
final Token param= lex.nextToken();
|
||||
|
@ -239,7 +239,7 @@ public class MacroDefinitionParser {
|
|||
}
|
||||
next= lex.nextToken(); // consume the closing parenthesis
|
||||
|
||||
return (char[][]) paramList.toArray(new char[paramList.size()][]);
|
||||
return paramList.toArray(new char[paramList.size()][]);
|
||||
}
|
||||
|
||||
public void parseExpansion(final Lexer lexer, final ILexerLog log, final char[] name, final char[][] paramList,
|
||||
|
|
|
@ -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
|
||||
|
@ -55,7 +55,7 @@ public class MacroExpander {
|
|||
return "{" + (fIsStart ? '+' : '-') + fMacro.getName() + '}'; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void execute(IdentityHashMap forbidden) {
|
||||
public void execute(IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden) {
|
||||
if (fIsStart) {
|
||||
forbidden.put(fMacro, fMacro);
|
||||
}
|
||||
|
@ -128,8 +128,8 @@ public class MacroExpander {
|
|||
private final CharArrayObjectMap fDictionary;
|
||||
private final LocationMap fLocationMap;
|
||||
private final LexerOptions fLexOptions;
|
||||
private ArrayList fImplicitMacroExpansions= new ArrayList();
|
||||
private ArrayList fImageLocationInfos= new ArrayList();
|
||||
private ArrayList<IASTName> fImplicitMacroExpansions= new ArrayList<IASTName>();
|
||||
private ArrayList<ImageLocationInfo> fImageLocationInfos= new ArrayList<ImageLocationInfo>();
|
||||
private boolean fCompletionMode;
|
||||
private int fStartOffset;
|
||||
private int fEndOffset;
|
||||
|
@ -153,7 +153,7 @@ public class MacroExpander {
|
|||
fEndOffset= identifier.getEndOffset();
|
||||
fCompletionMode= completionMode;
|
||||
|
||||
IdentityHashMap forbidden= new IdentityHashMap();
|
||||
IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden= new IdentityHashMap<PreprocessorMacro, PreprocessorMacro>();
|
||||
|
||||
// setup input sequence
|
||||
TokenSource input= new TokenSource(lexer, stopAtNewline);
|
||||
|
@ -173,7 +173,7 @@ public class MacroExpander {
|
|||
* with boundary markers in the result token list.
|
||||
* Returns the last token of the expansion.
|
||||
*/
|
||||
private Token expandOne(Token lastConsumed, PreprocessorMacro macro, IdentityHashMap forbidden, TokenSource input, TokenList result)
|
||||
private Token expandOne(Token lastConsumed, PreprocessorMacro macro, IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden, TokenSource input, TokenList result)
|
||||
throws OffsetLimitReachedException {
|
||||
result.append(new ExpansionBoundary(macro, true));
|
||||
if (macro.isFunctionStyle()) {
|
||||
|
@ -196,7 +196,7 @@ public class MacroExpander {
|
|||
return lastConsumed;
|
||||
}
|
||||
|
||||
private TokenList expandAll(TokenSource input, IdentityHashMap forbidden) throws OffsetLimitReachedException {
|
||||
private TokenList expandAll(TokenSource input, IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden) throws OffsetLimitReachedException {
|
||||
final TokenList result= new TokenList();
|
||||
Token l= null;
|
||||
Token t= input.removeFirst();
|
||||
|
@ -275,7 +275,7 @@ public class MacroExpander {
|
|||
* @param forbidden
|
||||
* @throws OffsetLimitReachedException
|
||||
*/
|
||||
private Token parseArguments(TokenSource input, FunctionStyleMacro macro, IdentityHashMap forbidden, TokenSource[] result) throws OffsetLimitReachedException {
|
||||
private Token parseArguments(TokenSource input, FunctionStyleMacro macro, IdentityHashMap<PreprocessorMacro, PreprocessorMacro> forbidden, TokenSource[] result) throws OffsetLimitReachedException {
|
||||
final int argCount= macro.getParameterPlaceholderList().length;
|
||||
final boolean hasVarargs= macro.hasVarArgs() != FunctionStyleMacro.NO_VAARGS;
|
||||
final int requiredArgs= hasVarargs ? argCount-1 : argCount;
|
||||
|
@ -645,13 +645,13 @@ public class MacroExpander {
|
|||
}
|
||||
|
||||
public IASTName[] clearImplicitExpansions() {
|
||||
IASTName[] result= (IASTName[]) fImplicitMacroExpansions.toArray(new IASTName[fImplicitMacroExpansions.size()]);
|
||||
IASTName[] result= fImplicitMacroExpansions.toArray(new IASTName[fImplicitMacroExpansions.size()]);
|
||||
fImplicitMacroExpansions.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
public ImageLocationInfo[] clearImageLocationInfos() {
|
||||
ImageLocationInfo[] result= (ImageLocationInfo[]) fImageLocationInfos.toArray(new ImageLocationInfo[fImageLocationInfos.size()]);
|
||||
ImageLocationInfo[] result= fImageLocationInfos.toArray(new ImageLocationInfo[fImageLocationInfos.size()]);
|
||||
fImageLocationInfos.clear();
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -57,6 +57,7 @@ abstract class PreprocessorMacro implements IMacroBinding {
|
|||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getAdapter(Class clazz) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -15,8 +15,6 @@ import java.util.ArrayList;
|
|||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Represents part of the input to the preprocessor. This may be a file or the result of a macro expansion.
|
||||
* @since 5.0
|
||||
|
@ -32,7 +30,7 @@ final class ScannerContext {
|
|||
private final ILocationCtx fLocationCtx;
|
||||
private final ScannerContext fParent;
|
||||
private final Lexer fLexer;
|
||||
private ArrayList fBranches= null;
|
||||
private ArrayList<Integer> fBranches= null;
|
||||
|
||||
private Token fTokens;
|
||||
|
||||
|
@ -81,7 +79,7 @@ final class ScannerContext {
|
|||
*/
|
||||
public final boolean changeBranch(Integer branchKind) {
|
||||
if (fBranches == null) {
|
||||
fBranches= new ArrayList();
|
||||
fBranches= new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
// an if starts a new conditional construct
|
||||
|
|
|
@ -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
|
||||
|
@ -11,7 +11,6 @@
|
|||
package org.eclipse.cdt.internal.core.dom;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.IMacroCollector;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
|
||||
|
@ -34,9 +33,9 @@ public class NullCodeReaderFactory implements ICodeReaderFactory {
|
|||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(org.eclipse.cdt.core.dom.ICodeReaderFactoryCallback, java.lang.String)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String)
|
||||
*/
|
||||
public CodeReader createCodeReaderForInclusion(IMacroCollector scanner, String path) {
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
return new CodeReader(path, EMPTY_CHARS);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
* IBM - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom;
|
||||
|
||||
|
@ -15,8 +15,8 @@ import java.util.Iterator;
|
|||
|
||||
import org.eclipse.cdt.core.dom.CDOM;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.IMacroCollector;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopyProvider;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
|
@ -70,16 +70,17 @@ public class PartialWorkingCopyCodeReaderFactory
|
|||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(org.eclipse.cdt.core.dom.ICodeReaderFactoryCallback, java.lang.String)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String)
|
||||
*/
|
||||
public CodeReader createCodeReaderForInclusion(IMacroCollector scanner, String path) {
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
return cache.get( path );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected Iterator createWorkingCopyIterator() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Iterator<IWorkingCopy> createWorkingCopyIterator() {
|
||||
if( provider == null ) return EmptyIterator.EMPTY_ITERATOR;
|
||||
return Arrays.asList( provider.getWorkingCopies() ).iterator();
|
||||
}
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
* IBM - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.CDOM;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.IMacroCollector;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.CodeReaderCache;
|
||||
|
@ -84,9 +83,9 @@ public class SavedCodeReaderFactory implements ICodeReaderFactory {
|
|||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(org.eclipse.cdt.core.dom.ICodeReaderFactoryCallback, java.lang.String)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String)
|
||||
*/
|
||||
public CodeReader createCodeReaderForInclusion(IMacroCollector scanner, String path) {
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
return cache.get(path);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue