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