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

Follow up for bug 209614.

This commit is contained in:
Markus Schorn 2008-01-10 15:27:18 +00:00
parent a9013f9b08
commit 9ee52fed6a
5 changed files with 41 additions and 37 deletions

View file

@ -31,9 +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.IncludeFileContent;
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.parser.scanner.IncludeFileContent.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;
@ -85,7 +85,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
return ParserUtil.createReader(path, null); return ParserUtil.createReader(path, null);
} }
public FileInclusionHandling getInclusionHandling(String path) { public IncludeFileContent getContentForInclusion(String path) {
IIndexFileLocation ifl= fPathResolver.resolveIncludeFile(path); IIndexFileLocation ifl= fPathResolver.resolveIncludeFile(path);
if (ifl == null) { if (ifl == null) {
return null; return null;
@ -94,7 +94,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
// include files once, only. // include files once, only.
if (!fIncludedFiles.add(ifl)) { if (!fIncludedFiles.add(ifl)) {
return new FileInclusionHandling(path, InclusionKind.SKIP_FILE); return new IncludeFileContent(path, InclusionKind.SKIP_FILE);
} }
try { try {
@ -108,7 +108,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
allMacros.addAll(Arrays.asList(entry.getValue())); allMacros.addAll(Arrays.asList(entry.getValue()));
fIncludedFiles.add(entry.getKey()); fIncludedFiles.add(entry.getKey());
} }
return new FileInclusionHandling(path, allMacros); return new IncludeFileContent(path, allMacros);
} }
catch (NeedToParseException e) { catch (NeedToParseException e) {
} }
@ -120,7 +120,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
CodeReader codeReader= createCodeReaderForInclusion(path); CodeReader codeReader= createCodeReaderForInclusion(path);
if (codeReader != null) { if (codeReader != null) {
return new FileInclusionHandling(codeReader); return new IncludeFileContent(codeReader);
} }
return null; return null;
} }

View file

@ -206,7 +206,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, fLexOptions);
fCodeReaderFactory= wrapReaderFactory(readerFactory); fCodeReaderFactory= wrapReaderFactory(readerFactory);
setupMacroDictionary(configuration, info, language); setupMacroDictionary(configuration, info, language);
@ -233,10 +233,10 @@ public class CPreprocessor implements ILexerLog, IScanner {
public CodeReader createCodeReaderForInclusion(String path) { public CodeReader createCodeReaderForInclusion(String path) {
return readerFactory.createCodeReaderForInclusion(path); return readerFactory.createCodeReaderForInclusion(path);
} }
public FileInclusionHandling getInclusionHandling(String path) { public IncludeFileContent getContentForInclusion(String path) {
CodeReader reader= readerFactory.createCodeReaderForInclusion(path); CodeReader reader= readerFactory.createCodeReaderForInclusion(path);
if (reader != null) { if (reader != null) {
return new FileInclusionHandling(reader); return new IncludeFileContent(reader);
} }
return null; return null;
} }
@ -777,9 +777,9 @@ public class CPreprocessor implements ILexerLog, IScanner {
} }
} }
private FileInclusionHandling findInclusion(final String filename, final boolean quoteInclude, private IncludeFileContent findInclusion(final String filename, final boolean quoteInclude,
final boolean includeNext, final File currentDir) { final boolean includeNext, final File currentDir) {
return (FileInclusionHandling) findInclusion(filename, quoteInclude, includeNext, currentDir, createCodeReaderTester); return (IncludeFileContent) findInclusion(filename, quoteInclude, includeNext, currentDir, createCodeReaderTester);
} }
private Object findInclusion(final String filename, final boolean quoteInclude, private Object findInclusion(final String filename, final boolean quoteInclude,
@ -863,9 +863,9 @@ public class CPreprocessor implements ILexerLog, IScanner {
fLocationMap.encounterProblem(id, arg, offset, endOffset); fLocationMap.encounterProblem(id, arg, offset, endOffset);
} }
private FileInclusionHandling createReader(String path, String fileName){ private IncludeFileContent createReader(String path, String fileName){
String finalPath = ScannerUtility.createReconciledPath(path, fileName); String finalPath = ScannerUtility.createReconciledPath(path, fileName);
return fCodeReaderFactory.getInclusionHandling(finalPath); return fCodeReaderFactory.getContentForInclusion(finalPath);
} }
@ -1068,7 +1068,7 @@ public class CPreprocessor implements ILexerLog, IScanner {
} }
else { else {
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 FileInclusionHandling fi= findInclusion(new String(headerName), userInclude, include_next, currentDir); final IncludeFileContent fi= findInclusion(new String(headerName), userInclude, include_next, currentDir);
if (fi != null) { if (fi != null) {
path= fi.getFileLocation(); path= fi.getFileLocation();
switch(fi.getKind()) { switch(fi.getKind()) {
@ -1100,7 +1100,7 @@ public class CPreprocessor implements ILexerLog, IScanner {
} }
} }
private void processInclusionFromIndex(String path, FileInclusionHandling fi) { private void processInclusionFromIndex(String path, IncludeFileContent fi) {
List<IIndexMacro> mdefs= fi.getMacroDefinitions(); List<IIndexMacro> mdefs= fi.getMacroDefinitions();
for (IIndexMacro macro : mdefs) { for (IIndexMacro macro : mdefs) {
addMacroDefinition(macro); addMacroDefinition(macro);

View file

@ -25,8 +25,9 @@ public interface IIndexBasedCodeReaderFactory extends ICodeReaderFactory {
boolean hasFileBeenIncludedInCurrentTranslationUnit(String path); boolean hasFileBeenIncludedInCurrentTranslationUnit(String path);
/** /**
* Create include information object for the given location. * Create an InclusionContent object for the given location.
* @see FileInclusionHandling * return an inclusion content or <code>null</code> if the location does not exist.
* @see IncludeFileContent
*/ */
public FileInclusionHandling getInclusionHandling(String fileLocation); public IncludeFileContent getContentForInclusion(String fileLocation);
} }

View file

@ -19,7 +19,7 @@ import org.eclipse.cdt.core.parser.CodeReader;
* Instructs the preprocessor on how to handle a file-inclusion. * Instructs the preprocessor on how to handle a file-inclusion.
* @since 5.0 * @since 5.0
*/ */
public class FileInclusionHandling { public class IncludeFileContent {
public enum InclusionKind { public enum InclusionKind {
/** /**
* Instruct the preprocessor to skip this inclusion. * Instruct the preprocessor to skip this inclusion.
@ -48,7 +48,7 @@ public class FileInclusionHandling {
* @throws IllegalArgumentException if fileLocation is <code>null</code> or the kind value is illegal for * @throws IllegalArgumentException if fileLocation is <code>null</code> or the kind value is illegal for
* this constructor. * this constructor.
*/ */
public FileInclusionHandling(String fileLocation, InclusionKind kind) throws IllegalArgumentException { public IncludeFileContent(String fileLocation, InclusionKind kind) throws IllegalArgumentException {
if (fileLocation == null || kind != InclusionKind.SKIP_FILE) { if (fileLocation == null || kind != InclusionKind.SKIP_FILE) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@ -63,7 +63,7 @@ public class FileInclusionHandling {
* @param codeReader the code reader for the inclusion. * @param codeReader the code reader for the inclusion.
* @throws IllegalArgumentException in case the codeReader or its location is <code>null</code>. * @throws IllegalArgumentException in case the codeReader or its location is <code>null</code>.
*/ */
public FileInclusionHandling(CodeReader codeReader) throws IllegalArgumentException { public IncludeFileContent(CodeReader codeReader) throws IllegalArgumentException {
if (codeReader == null) { if (codeReader == null) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@ -82,7 +82,7 @@ public class FileInclusionHandling {
* @param macroDefinitions a list of macro definitions * @param macroDefinitions a list of macro definitions
* @throws IllegalArgumentException in case the fileLocation or the macroDefinitions are <code>null</code>. * @throws IllegalArgumentException in case the fileLocation or the macroDefinitions are <code>null</code>.
*/ */
public FileInclusionHandling(String fileLocation, List<IIndexMacro> macroDefinitions) { public IncludeFileContent(String fileLocation, List<IIndexMacro> macroDefinitions) {
fKind= InclusionKind.FOUND_IN_INDEX; fKind= InclusionKind.FOUND_IN_INDEX;
fFileLocation= fileLocation; fFileLocation= fileLocation;
fCodeReader= null; fCodeReader= null;

View file

@ -134,10 +134,10 @@ public class MacroExpander {
private int fStartOffset; private int fStartOffset;
private int fEndOffset; private int fEndOffset;
public MacroExpander(ILexerLog log, CharArrayObjectMap dict, LocationMap locationMap, MacroDefinitionParser mdp, LexerOptions lexOptions) { public MacroExpander(ILexerLog log, CharArrayObjectMap dict, LocationMap locationMap, LexerOptions lexOptions) {
fDictionary= dict; fDictionary= dict;
fLocationMap= locationMap; fLocationMap= locationMap;
fDefinitionParser= mdp; fDefinitionParser= new MacroDefinitionParser();
fLexOptions= lexOptions; fLexOptions= lexOptions;
fLog= log; fLog= log;
} }
@ -217,12 +217,13 @@ public class MacroExpander {
result.append(t); result.append(t);
} }
else { else {
if (fLocationMap != null) {
ImageLocationInfo info= null; ImageLocationInfo info= null;
if (fLexOptions.fCreateImageLocations) { if (fLexOptions.fCreateImageLocations) {
info = createImageLocationInfo(t); info = createImageLocationInfo(t);
} }
fImplicitMacroExpansions.add(fLocationMap.encounterImplicitMacroExpansion(macro, info)); fImplicitMacroExpansions.add(fLocationMap.encounterImplicitMacroExpansion(macro, info));
}
TokenList replacement= new TokenList(); TokenList replacement= new TokenList();
addSpacemarker(l, t, replacement); // start expansion addSpacemarker(l, t, replacement); // start expansion
@ -243,6 +244,7 @@ public class MacroExpander {
} }
private ImageLocationInfo createImageLocationInfo(Token t) { private ImageLocationInfo createImageLocationInfo(Token t) {
if (fLocationMap != null) {
final Object s= t.fSource; final Object s= t.fSource;
if (s instanceof ObjectStyleMacro) { if (s instanceof ObjectStyleMacro) {
return new MacroImageLocationInfo((ObjectStyleMacro) s, t.getOffset(), t.getEndOffset()); return new MacroImageLocationInfo((ObjectStyleMacro) s, t.getOffset(), t.getEndOffset());
@ -252,6 +254,7 @@ public class MacroExpander {
int sequenceEndNumber= fLocationMap.getSequenceNumberForOffset(t.getEndOffset()); int sequenceEndNumber= fLocationMap.getSequenceNumberForOffset(t.getEndOffset());
return new ParameterImageLocationInfo(sequenceNumber, sequenceEndNumber); return new ParameterImageLocationInfo(sequenceNumber, sequenceEndNumber);
} }
}
return null; return null;
} }