From 3c10d0917e78ce66fd0f45ff3dc84b1b3a015326 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Tue, 8 Jan 2008 11:41:04 +0000 Subject: [PATCH] Cleanup for the interface between fast indexer and preprocessor, bug 209614. --- .../tests/scanner/FileCodeReaderFactory.java | 5 +- .../tests/scanner/PortedScannerTests.java | 12 +- .../tests/scanner/PreprocessorTestsBase.java | 11 +- .../cdt/core/dom/ICodeReaderFactory.java | 7 +- .../eclipse/cdt/core/dom/IMacroCollector.java | 34 ---- .../cdt/core/parser/ExtendedScannerInfo.java | 13 +- .../org/eclipse/cdt/core/parser/IScanner.java | 7 +- .../eclipse/cdt/core/parser/IScannerInfo.java | 7 +- .../eclipse/cdt/core/parser/ScannerInfo.java | 31 ++-- .../index/IndexBasedCodeReaderFactory.java | 59 +++--- ...tandaloneIndexerFallbackReaderFactory.java | 7 +- .../parser/scanner/ASTPreprocessorNode.java | 6 +- .../core/parser/scanner/ASTProblem.java | 12 +- .../core/parser/scanner/CPreprocessor.java | 172 ++++++++++-------- .../parser/scanner/FileInclusionHandling.java | 94 ++++++++++ .../scanner/IIndexBasedCodeReaderFactory.java | 8 +- .../core/parser/scanner/LocationCtx.java | 12 +- .../parser/scanner/LocationCtxContainer.java | 39 ++-- .../scanner/LocationCtxMacroExpansion.java | 5 +- .../core/parser/scanner/LocationMap.java | 63 +++---- .../parser/scanner/MacroDefinitionParser.java | 6 +- .../core/parser/scanner/MacroExpander.java | 20 +- .../parser/scanner/PreprocessorMacro.java | 3 +- .../core/parser/scanner/ScannerContext.java | 8 +- .../core/dom/NullCodeReaderFactory.java | 7 +- .../PartialWorkingCopyCodeReaderFactory.java | 13 +- .../core/dom/SavedCodeReaderFactory.java | 9 +- 27 files changed, 384 insertions(+), 286 deletions(-) delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IMacroCollector.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/FileInclusionHandling.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/FileCodeReaderFactory.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/FileCodeReaderFactory.java index 8018813ecbb..fad45cc8a31 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/FileCodeReaderFactory.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/FileCodeReaderFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,7 +11,6 @@ package org.eclipse.cdt.core.parser.tests.scanner; import org.eclipse.cdt.core.dom.ICodeReaderFactory; -import org.eclipse.cdt.core.dom.IMacroCollector; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.ICodeReaderCache; @@ -51,7 +50,7 @@ public class FileCodeReaderFactory implements ICodeReaderFactory { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(org.eclipse.cdt.core.dom.ICodeReaderFactoryCallback, java.lang.String) */ - public CodeReader createCodeReaderForInclusion(IMacroCollector scanner, String path) { + public CodeReader createCodeReaderForInclusion(String path) { return cache.get(path); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PortedScannerTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PortedScannerTests.java index 11505ed54e7..65e900592e2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PortedScannerTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PortedScannerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1853,19 +1853,19 @@ public class PortedScannerTests extends PreprocessorTestsBase { fullyTokenize(); validateProblemCount(0); - Map defs = fScanner.getDefinitions(); + Map defs = fScanner.getMacroDefinitions(); assertTrue(defs.containsKey("debug")); assertTrue(defs.containsKey("showlist")); assertTrue(defs.containsKey("report")); - IMacroBinding debug = (IMacroBinding) defs.get("debug"); + IMacroBinding debug = defs.get("debug"); assertTrue(new String(debug.getParameterPlaceholderList()[0]).equals("__VA_ARGS__")); assertEquals("fprintf(stderr, __VA_ARGS__)", new String(debug.getExpansion())); - IMacroBinding showlist = (IMacroBinding) defs.get("showlist"); + IMacroBinding showlist = defs.get("showlist"); assertTrue(new String(showlist.getParameterPlaceholderList()[0]).equals("__VA_ARGS__")); assertTrue(new String(showlist.getExpansion()) .equals("puts(#__VA_ARGS__)")); - IMacroBinding report = (IMacroBinding) defs.get("report"); + IMacroBinding report = defs.get("report"); assertTrue(new String(report.getParameterPlaceholderList()[0]).equals("test")); assertTrue(new String(report.getParameterPlaceholderList()[1]).equals("__VA_ARGS__")); assertTrue(new String(report.getExpansion()) @@ -1891,7 +1891,7 @@ public class PortedScannerTests extends PreprocessorTestsBase { fullyTokenize(); validateProblemCount(0); - Map defs = fScanner.getDefinitions(); + Map defs = fScanner.getMacroDefinitions(); assertTrue(defs.containsKey("debug")); assertTrue(defs.containsKey("showlist")); assertTrue(defs.containsKey("report")); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java index 19a58f748eb..c2b51145270 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -74,7 +74,7 @@ public abstract class PreprocessorTestsBase extends BaseTestCase { } fScanner= new CPreprocessor(input, scannerInfo, lang, NULL_LOG, scannerConfig, readerFactory); - fLocationResolver= (ILocationResolver) fScanner.getAdapter(ILocationResolver.class); + fLocationResolver= fScanner.getLocationMap(); } protected void initializeScanner() throws Exception { @@ -147,10 +147,9 @@ public abstract class PreprocessorTestsBase extends BaseTestCase { } protected void validateDefinition(String name, String value) { - Object expObject = fScanner.getDefinitions().get(name); + IMacroBinding expObject = fScanner.getMacroDefinitions().get(name); assertNotNull(expObject); - assertTrue(expObject instanceof IMacroBinding); - assertCharArrayEquals(value.toCharArray(), ((IMacroBinding)expObject).getExpansion()); + assertCharArrayEquals(value.toCharArray(), expObject.getExpansion()); } protected void validateDefinition(String name, int value) { @@ -158,7 +157,7 @@ public abstract class PreprocessorTestsBase extends BaseTestCase { } protected void validateAsUndefined(String name) { - assertNull(fScanner.getDefinitions().get(name.toCharArray())); + assertNull(fScanner.getMacroDefinitions().get(name.toCharArray())); } protected void validateProblemCount(int count) throws Exception { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ICodeReaderFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ICodeReaderFactory.java index 936775f9c4f..a905f92411d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ICodeReaderFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ICodeReaderFactory.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom; @@ -42,7 +43,7 @@ public interface ICodeReaderFactory { * @param path * @return CodeReader for contents at that path. */ - public CodeReader createCodeReaderForInclusion(IMacroCollector callback, String path); + public CodeReader createCodeReaderForInclusion(String path); /** * Returns the ICodeReaderCache used for this ICodeReaderFacotry. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IMacroCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IMacroCollector.java deleted file mode 100644 index 628e2c2d561..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IMacroCollector.java +++ /dev/null @@ -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. - * - *

- * EXPERIMENTAL. 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. - *

- - * - * @since 4.0 - * - */ -// mstodo get rid of this interface -public interface IMacroCollector { - - public void addMacroDefinition(IIndexMacro macro); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ExtendedScannerInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ExtendedScannerInfo.java index e82e101255d..17efc76afe7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ExtendedScannerInfo.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ExtendedScannerInfo.java @@ -1,20 +1,21 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser; import java.util.Map; /** - * @author jcamelon - * + * Implementation for the {@link IExtendedScannerInfo} interface. Allows to configure + * the preprocessor. */ public class ExtendedScannerInfo extends ScannerInfo implements IExtendedScannerInfo { @@ -25,12 +26,12 @@ public class ExtendedScannerInfo extends ScannerInfo implements IExtendedScanner { } - public ExtendedScannerInfo( Map d, String [] incs ) + public ExtendedScannerInfo( Map d, String [] incs ) { super(d,incs); } - public ExtendedScannerInfo( Map d, String [] incs, String [] macros, String [] includes ) + public ExtendedScannerInfo( Map d, String [] incs, String [] macros, String [] includes ) { super(d,incs); m = macros; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java index 202d307cdb7..5a9b68fb0c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2007 IBM Corporation and others. + * Copyright (c) 2003, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,7 +13,6 @@ package org.eclipse.cdt.core.parser; import java.util.Map; -import org.eclipse.cdt.core.dom.IMacroCollector; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver; import org.eclipse.cdt.internal.core.parser.scanner.Lexer; @@ -27,7 +26,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.Lexer; * consulting with the CDT team. *

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