1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

Implemented IASTTranslationUnit#getIncludeDirectives() for both C & C++.

Implemented IASTTranslationUnit#getMacroDefinitions() for both C & C++.
This commit is contained in:
John Camelon 2005-01-25 20:42:19 +00:00
parent 30b41b6da1
commit ae4dff5290
16 changed files with 548 additions and 162 deletions

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -145,6 +146,10 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
assertSoleFileLocation(FOO, assertSoleFileLocation(FOO,
"foo.h", foo.indexOf("int"), foo.indexOf(";") + 1); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ "foo.h", foo.indexOf("int"), foo.indexOf(";") + 1); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IASTPreprocessorIncludeStatement [] incs = tu.getIncludeDirectives();
assertNotNull( incs );
assertEquals( incs.length, 1 );
assertSoleFileLocation( incs[0], "code.cpp", code.indexOf( "#inc"), code.indexOf( ".h\"\n") + ".h\"".length() - code.indexOf( "#inc") ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
} }
} }
@ -168,6 +173,10 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
assertSoleFileLocation(FOO, assertSoleFileLocation(FOO,
"foo.h", foo.indexOf("int"), foo.indexOf(";") + 1 - foo.indexOf( "int")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ "foo.h", foo.indexOf("int"), foo.indexOf(";") + 1 - foo.indexOf( "int")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
assertSoleFileLocation( byob, "code.cpp", code.indexOf( "float"), code.indexOf( "b;") + 2 - code.indexOf( "float") ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ assertSoleFileLocation( byob, "code.cpp", code.indexOf( "float"), code.indexOf( "b;") + 2 - code.indexOf( "float") ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
IASTPreprocessorIncludeStatement [] incs = tu.getIncludeDirectives();
assertNotNull( incs );
assertEquals( incs.length, 1 );
assertSoleFileLocation( incs[0], "code.cpp", code.indexOf( "#inc"), code.indexOf( ".h\"\n") + ".h\"".length() - code.indexOf( "#inc") ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
} }
} }

View file

@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -88,6 +89,21 @@ public class DOMLocationTests extends AST2BaseTest {
} }
} }
public void testSimpleMacroDefinition() throws Exception {
String code ="/* hi */\n#define FOOT 0x01\n\n"; //$NON-NLS-1$
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
: null) {
IASTTranslationUnit tu = parse(code, p);
IASTDeclaration[] declarations = tu.getDeclarations();
assertEquals(declarations.length, 0);
IASTPreprocessorMacroDefinition [] macros = tu.getMacroDefinitions();
assertNotNull( macros );
assertEquals( macros.length, 1 );
assertSoleLocation( macros[0], code.indexOf( "#"), code.indexOf( "0x01") + 4 - code.indexOf( "#")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
/** /**
* @param declarator * @param declarator
* @param offset * @param offset

View file

@ -13,8 +13,9 @@ package org.eclipse.cdt.core.dom.ast;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public interface IASTFunctionStyleMacroDefinition extends IASTMacroDefinition { public interface IASTFunctionStyleMacroParameter extends IASTNode {
public String getParameter();
public void setParameter( String value );
public String [] getParameters();
public void addParameter( String parm );
} }

View file

@ -20,7 +20,7 @@ public interface IASTMacroExpansion extends IASTNodeLocation {
* *
* @return * @return
*/ */
public IASTMacroDefinition getMacroDefinition(); public IASTPreprocessorMacroDefinition getMacroDefinition();
/** /**
* The source locations for for the macro expansion. These are the locations * The source locations for for the macro expansion. These are the locations

View file

@ -0,0 +1,21 @@
/**********************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.core.dom.ast;
/**
* @author jcamelon
*/
public interface IASTPreprocessorFunctionStyleMacroDefinition extends IASTPreprocessorMacroDefinition {
public IASTFunctionStyleMacroParameter [] getParameters();
public void addParameter( IASTFunctionStyleMacroParameter parm );
}

View file

@ -16,4 +16,6 @@ package org.eclipse.cdt.core.dom.ast;
public interface IASTPreprocessorIncludeStatement extends public interface IASTPreprocessorIncludeStatement extends
IASTPreprocessorStatement { IASTPreprocessorStatement {
public String getPath();
} }

View file

@ -15,7 +15,7 @@ package org.eclipse.cdt.core.dom.ast;
* *
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IASTMacroDefinition extends IASTPreprocessorStatement { public interface IASTPreprocessorMacroDefinition extends IASTPreprocessorStatement {
public static final ASTNodeProperty MACRO_NAME = new ASTNodeProperty( "Macro Name"); //$NON-NLS-1$ public static final ASTNodeProperty MACRO_NAME = new ASTNodeProperty( "Macro Name"); //$NON-NLS-1$
public IASTName getName(); public IASTName getName();

View file

@ -13,6 +13,6 @@ package org.eclipse.cdt.core.dom.ast;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public interface IASTObjectStyleMacroDefinition extends IASTMacroDefinition { public interface IASTPreprocessorObjectStyleMacroDefinition extends IASTPreprocessorMacroDefinition {
} }

View file

@ -10,7 +10,6 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
/** /**
* The translation unit represents a compilable unit of source. * The translation unit represents a compilable unit of source.
* *
@ -18,8 +17,12 @@ package org.eclipse.cdt.core.dom.ast;
*/ */
public interface IASTTranslationUnit extends IASTNode { public interface IASTTranslationUnit extends IASTNode {
public static final ASTNodeProperty OWNED_DECLARATION = new ASTNodeProperty( "Owned" ); //$NON-NLS-1$ public static final ASTNodeProperty OWNED_DECLARATION = new ASTNodeProperty(
public static final ASTNodeProperty SCANNER_PROBLEM = new ASTNodeProperty( "Scanner Problem"); //$NON-NLS-1$ "Owned"); //$NON-NLS-1$
public static final ASTNodeProperty SCANNER_PROBLEM = new ASTNodeProperty(
"Scanner Problem"); //$NON-NLS-1$
public static final ASTNodeProperty PREPROCESSOR_STATEMENT = new ASTNodeProperty(
"Inclusion"); //$NON-NLS-1$
/** /**
* A translation unit contains an ordered sequence of declarations. * A translation unit contains an ordered sequence of declarations.
@ -28,7 +31,7 @@ public interface IASTTranslationUnit extends IASTNode {
*/ */
public IASTDeclaration[] getDeclarations(); public IASTDeclaration[] getDeclarations();
public void addDeclaration( IASTDeclaration declaration ); public void addDeclaration(IASTDeclaration declaration);
/** /**
* This returns the global scope for the translation unit. * This returns the global scope for the translation unit.
@ -48,23 +51,28 @@ public interface IASTTranslationUnit extends IASTNode {
/** /**
* Returns the list of references in this translation unit to the given * Returns the list of references in this translation unit to the given
* binding. This list contains the IASTName nodes that represent a use of * binding. This list contains the IASTName nodes that represent a use of the
* the binding. * binding.
* *
* @param binding * @param binding
* @return List of IASTName nodes representing uses of the binding * @return List of IASTName nodes representing uses of the binding
*/ */
public IASTName[] getReferences(IBinding binding); public IASTName[] getReferences(IBinding binding);
public IASTNodeLocation getLocationInfo( int offset ); public IASTNodeLocation getLocationInfo(int offset);
public IASTNodeLocation [] getLocationInfo( int offset, int length );
public IASTNode[] selectNodesForLocation( String path, int offset, int length ); public IASTNodeLocation[] getLocationInfo(int offset, int length);
public IASTNode[] selectNodesForLocation( int offset, int length );
public IASTMacroDefinition [] getMacroDefinitions(); public IASTNode[] selectNodesForLocation(String path, int offset, int length);
public IASTPreprocessorIncludeStatement [] getIncludeDirectives();
public IASTPreprocessorStatement [] getAllPreprocessorStatements(); public IASTNode[] selectNodesForLocation(int offset, int length);
public IASTProblem [] getPreprocesorProblems();
public IASTPreprocessorMacroDefinition[] getMacroDefinitions();
public IASTPreprocessorIncludeStatement[] getIncludeDirectives();
public IASTPreprocessorStatement[] getAllPreprocessorStatements();
public IASTProblem[] getPreprocesorProblems();
} }

View file

@ -10,8 +10,9 @@
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
@ -39,7 +40,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
private ILocationResolver resolver; private ILocationResolver resolver;
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0]; private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0]; private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0];
private static final IASTMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTMacroDefinition[0]; private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0]; private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0];
private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0]; private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0];
@ -142,9 +143,11 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
*/ */
public IASTMacroDefinition[] getMacroDefinitions() { public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
if( resolver == null ) return EMPTY_PREPROCESSOR_MACRODEF_ARRAY; if( resolver == null ) return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
return resolver.getMacroDefinitions(this); IASTPreprocessorMacroDefinition [] result = resolver.getMacroDefinitions();
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT );
return result;
} }
@ -153,7 +156,22 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
*/ */
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() { public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
if( resolver == null ) return EMPTY_PREPROCESSOR_INCLUSION_ARRAY; if( resolver == null ) return EMPTY_PREPROCESSOR_INCLUSION_ARRAY;
return resolver.getIncludeDirectives(this); IASTPreprocessorIncludeStatement [] result = resolver.getIncludeDirectives();
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT );
return result;
}
/**
* @param result
* @param preprocessor_statement
*/
protected void setParentRelationship(IASTNode[] result, ASTNodeProperty property ) {
for( int i = 0; i < result.length; ++i )
{
result[i].setParent( this );
result[i].setPropertyInParent( property );
}
} }
@ -162,7 +180,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
*/ */
public IASTPreprocessorStatement[] getAllPreprocessorStatements() { public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
if( resolver == null ) return EMPTY_PREPROCESSOR_STATEMENT_ARRAY; if( resolver == null ) return EMPTY_PREPROCESSOR_STATEMENT_ARRAY;
return resolver.getAllPreprocessorStatements(this); return resolver.getAllPreprocessorStatements();
} }

View file

@ -10,8 +10,9 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
@ -50,7 +51,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0]; private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0];
private static final IASTMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTMacroDefinition[0]; private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0]; private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0];
@ -168,10 +169,11 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
* *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
*/ */
public IASTMacroDefinition[] getMacroDefinitions() { public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
if (resolver == null) if( resolver == null ) return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
return EMPTY_PREPROCESSOR_MACRODEF_ARRAY; IASTPreprocessorMacroDefinition [] result = resolver.getMacroDefinitions();
return resolver.getMacroDefinitions(this); setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT );
return result;
} }
/* /*
@ -180,9 +182,22 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives()
*/ */
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() { public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
if (resolver == null) if( resolver == null ) return EMPTY_PREPROCESSOR_INCLUSION_ARRAY;
return EMPTY_PREPROCESSOR_INCLUSION_ARRAY; IASTPreprocessorIncludeStatement [] result = resolver.getIncludeDirectives();
return resolver.getIncludeDirectives(this); setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT );
return result;
}
/**
* @param result
* @param preprocessor_statement
*/
protected void setParentRelationship(IASTNode[] result, ASTNodeProperty property ) {
for( int i = 0; i < result.length; ++i )
{
result[i].setParent( this );
result[i].setPropertyInParent( property );
}
} }
/* /*
@ -193,7 +208,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
public IASTPreprocessorStatement[] getAllPreprocessorStatements() { public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
if (resolver == null) if (resolver == null)
return EMPTY_PREPROCESSOR_STATEMENT_ARRAY; return EMPTY_PREPROCESSOR_STATEMENT_ARRAY;
return resolver.getAllPreprocessorStatements(this); return resolver.getAllPreprocessorStatements();
} }
/* /*

View file

@ -4302,6 +4302,14 @@ abstract class BaseScanner implements IScanner {
return language; return language;
} }
protected CodeReader getMainReader()
{
if (bufferData != null && bufferData[0] != null
&& bufferData[0] instanceof CodeReader)
return ((CodeReader) bufferData[0]);
return null;
}
public char[] getMainFilename() { public char[] getMainFilename() {
if (bufferData != null && bufferData[0] != null if (bufferData != null && bufferData[0] != null
&& bufferData[0] instanceof CodeReader) && bufferData[0] instanceof CodeReader)

View file

@ -114,10 +114,10 @@ public class DOMScanner extends BaseScanner {
int textEnd, int endingLine, IMacro macro) { int textEnd, int endingLine, IMacro macro) {
if (macro instanceof ObjectStyleMacro) if (macro instanceof ObjectStyleMacro)
locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro, locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
startingLineNumber, idstart, idend, textEnd); startingOffset, idstart, idend, textEnd);
else if (macro instanceof FunctionStyleMacro) else if (macro instanceof FunctionStyleMacro)
locationMap.defineFunctionStyleMacro((FunctionStyleMacro) macro, locationMap.defineFunctionStyleMacro((FunctionStyleMacro) macro,
startingLineNumber, idstart, idend, textEnd); startingOffset, idstart, idend, textEnd);
} }
@ -146,7 +146,7 @@ public class DOMScanner extends BaseScanner {
} }
DOMInclusion inc = ((DOMInclusion) ((InclusionData) data).inclusion); DOMInclusion inc = ((DOMInclusion) ((InclusionData) data).inclusion);
globalCounter += getCurrentOffset(); globalCounter += getCurrentOffset();
locationMap.startInclusion(inc.pt, inc.o, globalCounter); locationMap.startInclusion(((InclusionData)data).reader, inc.o, globalCounter);
contextDelta = 0; contextDelta = 0;
} }
super.pushContext(buffer, data); super.pushContext(buffer, data);
@ -263,7 +263,7 @@ public class DOMScanner extends BaseScanner {
*/ */
protected void postConstructorSetup(CodeReader reader, IScannerInfo info) { protected void postConstructorSetup(CodeReader reader, IScannerInfo info) {
super.postConstructorSetup(reader, info); super.postConstructorSetup(reader, info);
locationMap.startTranslationUnit(getMainFilename()); locationMap.startTranslationUnit(getMainReader());
} }
/* /*

View file

@ -10,8 +10,7 @@
**********************************************************************/ **********************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner2; package org.eclipse.cdt.internal.core.parser.scanner2;
import org.eclipse.cdt.core.dom.ast.IASTMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
@ -22,9 +21,9 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
*/ */
public interface ILocationResolver { public interface ILocationResolver {
public IASTMacroDefinition [] getMacroDefinitions(IASTNode parent); public IASTPreprocessorMacroDefinition [] getMacroDefinitions();
public IASTPreprocessorIncludeStatement [] getIncludeDirectives(IASTNode parent); public IASTPreprocessorIncludeStatement [] getIncludeDirectives();
public IASTPreprocessorStatement [] getAllPreprocessorStatements(IASTNode parent); public IASTPreprocessorStatement [] getAllPreprocessorStatements();
public IASTNodeLocation [] getLocations( int offset, int length ); public IASTNodeLocation [] getLocations( int offset, int length );
public IASTNodeLocation getLocation( int offset ); public IASTNodeLocation getLocation( int offset );

View file

@ -11,16 +11,17 @@
package org.eclipse.cdt.internal.core.parser.scanner2; package org.eclipse.cdt.internal.core.parser.scanner2;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.parser.CodeReader;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public interface IScannerPreprocessorLog { public interface IScannerPreprocessorLog {
public void startTranslationUnit( char [] filename ); public void startTranslationUnit( CodeReader tu_reader );
public void endTranslationUnit(int offset); public void endTranslationUnit(int offset);
public void startInclusion(char[] includePath, int offset, int endOffset); public void startInclusion(CodeReader reader, int offset, int endOffset);
public void endInclusion(int offset); public void endInclusion(int offset);
public void enterObjectStyleMacroExpansion(char[] name, char[] expansion, public void enterObjectStyleMacroExpansion(char[] name, char[] expansion,
@ -36,13 +37,13 @@ public interface IScannerPreprocessorLog {
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset, public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
int nameOffset, int nameEndOffset, int endOffset); int nameOffset, int nameEndOffset, int endOffset);
public void encounterPoundIf(int startOffset, int endOffset); public void encounterPoundIf(int startOffset, int endOffset, boolean taken);
public void encounterPoundPragma(int startOffset, int endOffset); public void encounterPoundPragma(int startOffset, int endOffset);
public void encounterPoundError(int startOffset, int endOffset); public void encounterPoundError(int startOffset, int endOffset);
public void encounterPoundIfdef(int startOffset, int endOffset); public void encounterPoundIfdef(int startOffset, int endOffset, boolean taken);
public void encounterPoundUndef(int startOffset, int endOffset); public void encounterPoundUndef(int startOffset, int endOffset);
public void encounterPoundElse(int startOffset, int endOffset); public void encounterPoundElse(int startOffset, int endOffset);
public void encounterPoundElif(int startOffset, int endOffset); public void encounterPoundElif(int startOffset, int endOffset, boolean taken);
public void encounterPoundEndIf(int startOffset, int endOffset); public void encounterPoundEndIf(int startOffset, int endOffset);
public void encounterProblem( IASTProblem problem ); public void encounterProblem( IASTProblem problem );

View file

@ -14,19 +14,218 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorObjectStyleMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
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.IBinding;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/**
* @author jcamelon
*/
protected static class _InclusionStatement extends ScannerASTNode implements
IASTPreprocessorIncludeStatement {
private final char[] path;
/**
* @param cs
*/
public _InclusionStatement(char[] cs) {
this.path = cs;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement#getPath()
*/
public String getPath() {
return new String( path );
}
}
/**
* @author jcamelon
*/
public static class ASTFunctionMacro extends ScannerASTNode implements
IASTPreprocessorFunctionStyleMacroDefinition {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroDefinition#getParameters()
*/
public IASTFunctionStyleMacroParameter[] getParameters() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroDefinition#addParameter(org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter)
*/
public void addParameter(IASTFunctionStyleMacroParameter parm) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getName()
*/
public IASTName getName() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setName(org.eclipse.cdt.core.dom.ast.IASTName)
*/
public void setName(IASTName name) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getExpansion()
*/
public String getExpansion() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setExpansion(java.lang.String)
*/
public void setExpansion(String exp) {
// TODO Auto-generated method stub
}
}
public static class ScannerASTNode extends ASTNode
{
private IASTNode parent;
private ASTNodeProperty property;
public IASTNode getParent() {
return parent;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent()
*/
public ASTNodeProperty getPropertyInParent() {
return property;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void setParent(IASTNode parent) {
this.parent = parent;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.IASTNodeProperty)
*/
public void setPropertyInParent(ASTNodeProperty property) {
this.property = property;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit()
*/
public IASTTranslationUnit getTranslationUnit() {
if( this instanceof IASTTranslationUnit ) return (IASTTranslationUnit) this;
IASTNode node = getParent();
while( ! (node instanceof IASTTranslationUnit ) && node != null )
{
node = node.getParent();
}
return (IASTTranslationUnit) node;
}
}
/**
* @author jcamelon
*/
public static class ScannerASTName extends ScannerASTNode implements IASTName {
private final char[] name;
public ScannerASTName( char [] n )
{
this.name = n;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding()
*/
public IBinding resolveBinding() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTName#toCharArray()
*/
public char[] toCharArray() {
return name;
}
}
/**
* @author jcamelon
*/
public static class ASTObjectMacro extends ScannerASTNode implements
IASTPreprocessorObjectStyleMacroDefinition {
private IASTName name;
private String expansion;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getName()
*/
public IASTName getName() {
return name;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setName(org.eclipse.cdt.core.dom.ast.IASTName)
*/
public void setName(IASTName name) {
this.name = name;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getExpansion()
*/
public String getExpansion() {
return expansion;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setExpansion(java.lang.String)
*/
public void setExpansion(String exp) {
this.expansion = exp;
}
}
public static class Location implements IASTNodeLocation { public static class Location implements IASTNodeLocation {
private final int nodeOffset; private final int nodeOffset;
private final int nodeLength; private final int nodeLength;
@ -60,9 +259,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
} }
/**
* @author jcamelon
*/
public static class FileLocation extends Location implements public static class FileLocation extends Location implements
IASTFileLocation { IASTFileLocation {
@ -90,33 +286,31 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
} }
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0]; protected static class _Context {
private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
public static class Context {
/** /**
* @param startOffset * @param startOffset
* @param endOffset * @param endOffset
*/ */
public Context(CompositeContext parent, int startOffset, int endOffset) { public _Context(_CompositeContext parent, int startOffset, int endOffset) {
this.context_directive_start = startOffset; this.context_directive_start = startOffset;
this.context_directive_end = endOffset; this.context_directive_end = endOffset;
this.context_ends = endOffset;
this.parent = parent; this.parent = parent;
} }
public final int context_directive_start; public final int context_directive_start;
public final int context_directive_end; public final int context_directive_end;
public int context_ends = -1; public int context_ends;
private final CompositeContext parent; private final _CompositeContext parent;
public CompositeContext getParent() { public _CompositeContext getParent() {
return parent; return parent;
} }
} }
public static class CompositeContext extends Context { protected static class _CompositeContext extends _Context {
public CompositeContext(CompositeContext parent, int startOffset, public _CompositeContext(_CompositeContext parent, int startOffset,
int endOffset) { int endOffset) {
super(parent, startOffset, endOffset); super(parent, startOffset, endOffset);
} }
@ -129,7 +323,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
return subContexts; return subContexts;
} }
public void addSubContext(Context c) { public void addSubContext(_Context c) {
if (subContexts == Collections.EMPTY_LIST) if (subContexts == Collections.EMPTY_LIST)
subContexts = new ArrayList(DEFAULT_SUBCONTEXT_ARRAY_SIZE); subContexts = new ArrayList(DEFAULT_SUBCONTEXT_ARRAY_SIZE);
subContexts.add(c); subContexts.add(c);
@ -144,30 +338,83 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
} }
public static class Inclusion extends CompositeContext { protected static class _Inclusion extends _CompositeContext {
public final char[] path; public final CodeReader reader;
public Inclusion(CompositeContext parent, char[] path, int startOffset, public _Inclusion(_CompositeContext parent, CodeReader reader, int startOffset,
int endOffset) { int endOffset) {
super(parent, startOffset, endOffset); super(parent, startOffset, endOffset);
this.path = path; this.reader = reader;
} }
} }
public static class TranslationUnit extends CompositeContext { protected static class _TranslationUnit extends _CompositeContext {
public final char[] path; public final CodeReader reader;
/** /**
* @param startOffset * @param startOffset
* @param endOffset * @param endOffset
*/ */
public TranslationUnit(char[] path) { public _TranslationUnit(CodeReader reader) {
super(null, 0, 0); super(null, 0, 0);
this.path = path; this.reader = reader;
} }
} }
public static class Problem extends Context { protected static class _MacroDefinition extends _Context
{
/**
* @param parent
* @param startOffset
* @param endOffset
* @param nameOffset TODO
*/
public _MacroDefinition(_CompositeContext parent, int startOffset, int endOffset, char[] name, int nameOffset, char[] expansion) {
super(parent, startOffset, endOffset);
this.name = name;
this.expansion = expansion;
this.nameOffset = nameOffset;
}
public final char [] name;
public final char [] expansion;
public final int nameOffset;
}
protected static class _ObjectMacroDefinition extends _MacroDefinition
{
/**
* @param parent
* @param startOffset
* @param endOffset
* @param name TODO
* @param expansion TODO
*/
public _ObjectMacroDefinition(_CompositeContext parent, int startOffset, int endOffset, char[] name, int nameOffset, char[] expansion) {
super(parent, startOffset, endOffset, name, nameOffset, expansion);
}
}
protected static class _FunctionMacroDefinition extends _MacroDefinition
{
public final char [] [] parms;
/**
* @param parent
* @param startOffset
* @param endOffset
* @param parameters
*/
public _FunctionMacroDefinition(_CompositeContext parent, int startOffset, int endOffset, char [] name, int nameOffset, char [] expansion, char[][] parameters ) {
super(parent, startOffset, endOffset, name, nameOffset, expansion);
this.parms = parameters;
}
}
protected static class _Problem extends _Context {
public final IASTProblem problem; public final IASTProblem problem;
/** /**
@ -175,7 +422,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param startOffset * @param startOffset
* @param endOffset * @param endOffset
*/ */
public Problem(CompositeContext parent, int startOffset, int endOffset, public _Problem(_CompositeContext parent, int startOffset, int endOffset,
IASTProblem problem) { IASTProblem problem) {
super(parent, startOffset, endOffset); super(parent, startOffset, endOffset);
this.problem = problem; this.problem = problem;
@ -183,8 +430,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
} }
protected TranslationUnit tu; protected _TranslationUnit tu;
protected CompositeContext currentContext; protected _CompositeContext currentContext;
/** /**
* *
@ -192,25 +440,63 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
public LocationMap() { public LocationMap() {
} }
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
private static final IASTPreprocessorMacroDefinition[] EMPTY_MACRO_DEFINITIONS_ARRAY = new IASTPreprocessorMacroDefinition[0];
private static final IASTPreprocessorIncludeStatement[] EMPTY_INCLUDES_ARRAY = new IASTPreprocessorIncludeStatement[0];
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions() * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
*/ */
public IASTMacroDefinition[] getMacroDefinitions(IASTNode parent) { public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
// TODO Auto-generated method stub List contexts = new ArrayList(8);
return null; LocationMap.collectContexts(V_MACRODEFS, tu, contexts);
if (contexts.isEmpty())
return EMPTY_MACRO_DEFINITIONS_ARRAY;
IASTPreprocessorMacroDefinition[] result = new IASTPreprocessorMacroDefinition[contexts.size()];
for (int i = 0; i < contexts.size(); ++i)
{
_MacroDefinition d = (_MacroDefinition) contexts.get(i);
IASTPreprocessorMacroDefinition r = null;
if( d instanceof _ObjectMacroDefinition )
r = new ASTObjectMacro();
else if ( d instanceof _FunctionMacroDefinition )
{
IASTPreprocessorFunctionStyleMacroDefinition f = new ASTFunctionMacro();
//TODO parms
r = f;
} }
IASTName name = new ScannerASTName( d.name );
name.setPropertyInParent( IASTPreprocessorMacroDefinition.MACRO_NAME );
name.setParent( r );
r.setName( name );
r.setExpansion( new String( ((_ObjectMacroDefinition)d).expansion ) );
((ScannerASTNode)r).setOffsetAndLength( d.context_directive_start, d.context_directive_end - d.context_directive_start );
result[i] = r;
}
return result; }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getIncludeDirectives() * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getIncludeDirectives()
*/ */
public IASTPreprocessorIncludeStatement[] getIncludeDirectives( public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
IASTNode newParam) { List contexts = new ArrayList(8);
// TODO Auto-generated method stub collectContexts( V_INCLUSIONS, tu, contexts );
return null; if( contexts.isEmpty() ) return EMPTY_INCLUDES_ARRAY;
IASTPreprocessorIncludeStatement [] result = new IASTPreprocessorIncludeStatement[ contexts.size() ];
for( int i = 0; i < contexts.size(); ++i )
{
_Inclusion inc = ((_Inclusion)contexts.get(i));
result[i] = new _InclusionStatement( inc.reader.filename );
((ScannerASTNode)result[i]).setOffsetAndLength( inc.context_directive_start, inc.context_directive_end - inc.context_directive_start );
}
return result;
} }
/* /*
@ -218,8 +504,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* *
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getAllPreprocessorStatements() * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getAllPreprocessorStatements()
*/ */
public IASTPreprocessorStatement[] getAllPreprocessorStatements( public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
IASTNode newParam) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
@ -233,7 +518,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
public IASTNodeLocation[] getLocations(int offset, int length) { public IASTNodeLocation[] getLocations(int offset, int length) {
if (tu == null) if (tu == null)
return EMPTY_LOCATION_ARRAY; return EMPTY_LOCATION_ARRAY;
Context c = findContextForOffset(offset); _Context c = findContextForOffset(offset);
if (c.context_ends >= offset + length) if (c.context_ends >= offset + length)
return createSoleLocation(c, offset, length); return createSoleLocation(c, offset, length);
@ -246,17 +531,17 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param length * @param length
* @return * @return
*/ */
protected IASTNodeLocation[] createSoleLocation(Context c, int offset, protected IASTNodeLocation[] createSoleLocation(_Context c, int offset,
int length) { int length) {
IASTNodeLocation[] result = new IASTNodeLocation[1]; IASTNodeLocation[] result = new IASTNodeLocation[1];
if (c instanceof TranslationUnit) { if (c instanceof _TranslationUnit) {
result[0] = new FileLocation(((TranslationUnit) c).path, reconcileOffset( c, offset ), result[0] = new FileLocation(((_TranslationUnit) c).reader.filename, reconcileOffset( c, offset ),
length); length);
return result; return result;
} }
if( c instanceof Inclusion ) if( c instanceof _Inclusion )
{ {
result[0] = new FileLocation(((Inclusion) c).path, reconcileOffset( c, offset ), result[0] = new FileLocation(((_Inclusion) c).reader.filename, reconcileOffset( c, offset ),
length); length);
return result; return result;
} }
@ -268,14 +553,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param offset * @param offset
* @return * @return
*/ */
protected static int reconcileOffset(Context c, int offset) { protected static int reconcileOffset(_Context c, int offset) {
int subtractOff = 0; int subtractOff = 0;
if( c instanceof CompositeContext ) if( c instanceof _CompositeContext )
{ {
List subs = ((CompositeContext)c).getSubContexts(); List subs = ((_CompositeContext)c).getSubContexts();
for( int i = 0; i < subs.size(); ++i ) for( int i = 0; i < subs.size(); ++i )
{ {
Context subC = (Context) subs.get(i); _Context subC = (_Context) subs.get(i);
if( subC.context_ends < offset ) if( subC.context_ends < offset )
subtractOff += subC.context_ends - subC.context_directive_end; subtractOff += subC.context_ends - subC.context_directive_end;
else else
@ -289,11 +574,11 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @param offset * @param offset
* @return * @return
*/ */
protected Context findContextForOffset(int offset) { protected _Context findContextForOffset(int offset) {
return findContextForOffset(tu, offset); return findContextForOffset(tu, offset);
} }
protected static Context findContextForOffset(CompositeContext context, protected static _Context findContextForOffset(_CompositeContext context,
int offset) { int offset) {
if (!context.hasSubContexts() ) if (!context.hasSubContexts() )
{ {
@ -303,12 +588,12 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
} }
List subContexts = context.getSubContexts(); List subContexts = context.getSubContexts();
//check first //check first
Context bestContext = (Context) subContexts.get(0); _Context bestContext = (_Context) subContexts.get(0);
if (bestContext.context_directive_end > offset) if (bestContext.context_directive_end > offset)
return context; return context;
for (int i = 1; i < subContexts.size(); ++i) { for (int i = 1; i < subContexts.size(); ++i) {
Context nextContext = (Context) subContexts.get(i); _Context nextContext = (_Context) subContexts.get(i);
if (nextContext.context_directive_end < offset) if (nextContext.context_directive_end < offset)
bestContext = nextContext; bestContext = nextContext;
else else
@ -318,8 +603,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
if ( bestContext.context_ends < offset ) if ( bestContext.context_ends < offset )
return context; return context;
if (bestContext instanceof CompositeContext) if (bestContext instanceof _CompositeContext)
return findContextForOffset((CompositeContext) bestContext, offset); return findContextForOffset((_CompositeContext) bestContext, offset);
return bestContext; return bestContext;
} }
@ -338,8 +623,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* *
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit() * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
*/ */
public void startTranslationUnit(char[] filename) { public void startTranslationUnit(CodeReader tu_reader) {
tu = new TranslationUnit(filename); tu = new _TranslationUnit(tu_reader);
currentContext = tu; currentContext = tu;
} }
@ -358,8 +643,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startInclusion(char[], * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startInclusion(char[],
* int) * int)
*/ */
public void startInclusion(char[] includePath, int offset, int endOffset) { public void startInclusion(CodeReader reader, int offset, int endOffset) {
Inclusion i = new Inclusion(currentContext, includePath, offset, _Inclusion i = new _Inclusion(currentContext, reader, offset,
endOffset); endOffset);
currentContext.addSubContext(i); currentContext.addSubContext(i);
currentContext = i; currentContext = i;
@ -372,7 +657,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* int) * int)
*/ */
public void endInclusion(int offset) { public void endInclusion(int offset) {
((Inclusion) currentContext).context_ends = offset; ((_Inclusion) currentContext).context_ends = offset;
currentContext = currentContext.getParent(); currentContext = currentContext.getParent();
} }
@ -430,8 +715,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/ */
public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset, public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset,
int nameOffset, int nameEndOffset, int endOffset) { int nameOffset, int nameEndOffset, int endOffset) {
// TODO Auto-generated method stub currentContext.addSubContext(new _ObjectMacroDefinition( currentContext, startOffset, endOffset, m.name, nameOffset, m.expansion ));
} }
/* /*
@ -442,8 +726,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/ */
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset, public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
int nameOffset, int nameEndOffset, int endOffset) { int nameOffset, int nameEndOffset, int endOffset) {
// TODO Auto-generated method stub currentContext.addSubContext(new _FunctionMacroDefinition( currentContext, startOffset, endOffset, m.name, nameOffset, m.expansion, m.arglist ));
} }
/* /*
@ -452,7 +735,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIf(int, * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIf(int,
* int) * int)
*/ */
public void encounterPoundIf(int startOffset, int endOffset) { public void encounterPoundIf(int startOffset, int endOffset, boolean taken) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@ -485,7 +768,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfdef(int, * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfdef(int,
* int) * int)
*/ */
public void encounterPoundIfdef(int startOffset, int endOffset) { public void encounterPoundIfdef(int startOffset, int endOffset, boolean taken) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@ -518,7 +801,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElif(int, * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElif(int,
* int) * int)
*/ */
public void encounterPoundElif(int startOffset, int endOffset) { public void encounterPoundElif(int startOffset, int endOffset, boolean taken) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@ -540,7 +823,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getTranslationUnitPath() * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getTranslationUnitPath()
*/ */
public String getTranslationUnitPath() { public String getTranslationUnitPath() {
return new String(tu.path); return new String(tu.reader.filename);
} }
/* /*
@ -564,7 +847,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
return EMPTY_PROBLEMS_ARRAY; return EMPTY_PROBLEMS_ARRAY;
IASTProblem[] result = new IASTProblem[contexts.size()]; IASTProblem[] result = new IASTProblem[contexts.size()];
for (int i = 0; i < contexts.size(); ++i) for (int i = 0; i < contexts.size(); ++i)
result[i] = ((Problem) contexts.get(i)).problem; result[i] = ((_Problem) contexts.get(i)).problem;
return result; return result;
} }
@ -576,7 +859,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
*/ */
public void encounterProblem(IASTProblem problem) { public void encounterProblem(IASTProblem problem) {
ScannerASTProblem p = (ScannerASTProblem) problem; ScannerASTProblem p = (ScannerASTProblem) problem;
Problem pr = new Problem(currentContext, p.getOffset(), p.getOffset() _Problem pr = new _Problem(currentContext, p.getOffset(), p.getOffset()
+ p.getLength(), problem); + p.getLength(), problem);
pr.context_ends = p.getOffset() + p.getLength(); pr.context_ends = p.getOffset() + p.getLength();
} }
@ -584,25 +867,30 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
protected static final int V_ALL = 1; protected static final int V_ALL = 1;
protected static final int V_INCLUSIONS = 2; protected static final int V_INCLUSIONS = 2;
protected static final int V_PROBLEMS = 3; protected static final int V_PROBLEMS = 3;
protected static final int V_MACRODEFS = 4;
protected static void collectContexts(int key, Context source, List result) { protected static void collectContexts(int key, _Context source, List result) {
switch (key) { switch (key) {
case V_ALL: case V_ALL:
result.add(source); result.add(source);
break; break;
case V_INCLUSIONS: case V_INCLUSIONS:
if (source instanceof Inclusion) if (source instanceof _Inclusion)
result.add(source); result.add(source);
break; break;
case V_PROBLEMS: case V_PROBLEMS:
if (source instanceof Problem) if (source instanceof _Problem)
result.add(source);
break;
case V_MACRODEFS:
if( source instanceof _MacroDefinition )
result.add(source); result.add(source);
break; break;
} }
if (source instanceof CompositeContext) { if (source instanceof _CompositeContext) {
List l = ((CompositeContext) source).getSubContexts(); List l = ((_CompositeContext) source).getSubContexts();
for (int i = 0; i < l.size(); ++i) for (int i = 0; i < l.size(); ++i)
collectContexts(key, (Context) l.get(i), result); collectContexts(key, (_Context) l.get(i), result);
} }
} }