mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Further progress into AST as a service.
This commit is contained in:
parent
e5ffb20068
commit
04cef746c8
13 changed files with 623 additions and 56 deletions
|
@ -11,19 +11,24 @@
|
|||
package org.eclipse.cdt.core.dom;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface IASTServiceProvider {
|
||||
|
||||
public static class UnsupportedDialectException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
public String getName();
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit();
|
||||
public IASTTranslationUnit getTranslationUnit( IFile fileToParse) throws UnsupportedDialectException;
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit( ICodeReaderFactory fileCreator );
|
||||
public IASTTranslationUnit getTranslationUnit( IFile fileToParse, ICodeReaderFactory fileCreator )throws UnsupportedDialectException;
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit( ICodeReaderFactory fileCreator, IParserConfiguration configuration );
|
||||
public IASTTranslationUnit getTranslationUnit( IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration )throws UnsupportedDialectException;
|
||||
|
||||
public String [] getSupportedDialects();
|
||||
}
|
||||
|
|
|
@ -16,10 +16,8 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
|
|||
* @author jcamelon
|
||||
*/
|
||||
public interface IParserConfiguration {
|
||||
/**
|
||||
*/
|
||||
|
||||
public IScannerInfo getScannerInfo();
|
||||
/**
|
||||
*/
|
||||
public String getParserDialectName();
|
||||
public String getParserDialect();
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -38,4 +39,6 @@ public interface IScanner {
|
|||
public CharArrayObjectMap getRealDefinitions();
|
||||
public void cancel();
|
||||
public char[] getMainFilename();
|
||||
|
||||
public ILocationResolver getLocationResolver();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||
|
||||
/**
|
||||
|
@ -19,7 +21,11 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
|||
*/
|
||||
public interface ILocationResolver {
|
||||
|
||||
public IASTMacroDefinition[] getAllMacroDefinitions();
|
||||
public IASTPreprocessorStatement [] getPreprocessorStatements();
|
||||
public IASTNodeLocation [] getLocations( int offset, int length );
|
||||
public IASTMacroDefinition [] getMacroDefinitions(IASTNode parent);
|
||||
public IASTPreprocessorIncludeStatement [] getIncludeDirectives(IASTNode parent);
|
||||
public IASTPreprocessorStatement [] getAllPreprocessorStatements(IASTNode parent);
|
||||
|
||||
public IASTNodeLocation [] getLocations( int offset, int length );
|
||||
public IASTNodeLocation getLocation( int offset );
|
||||
|
||||
}
|
||||
|
|
|
@ -16,17 +16,42 @@ package org.eclipse.cdt.internal.core.parser.scanner2;
|
|||
public interface IScannerPreprocessorLog {
|
||||
|
||||
public void startTranslationUnit();
|
||||
public void endTranslationUnit( int finalOffset );
|
||||
|
||||
public void startInclusion( char [] includePath, int offset );
|
||||
public void endInclusion( char [] includePath, int offset );
|
||||
|
||||
public void enterObjectStyleMacroExpansion( char [] name, char [] expansion, int offset );
|
||||
public void exitObjectStyleMacroExpansion( char [] name, int offset );
|
||||
|
||||
public void enterFunctionStyleExpansion( char [] name, char [][] parameters, char [] expansion, int offset );
|
||||
public void exitFunctionStyleExpansion( char [] name, int offset );
|
||||
|
||||
public void defineObjectStyleMacro( ObjectStyleMacro m, int startOffset, int nameOffset, int nameEndOffset, int endOffset );
|
||||
public void defineFunctionStyleMacro( FunctionStyleMacro m, int startOffset, int nameOffset, int nameEndOffset, int endOffset );
|
||||
}
|
||||
|
||||
public void endTranslationUnit(int finalOffset);
|
||||
|
||||
public void startInclusion(char[] includePath, int offset);
|
||||
|
||||
public void endInclusion(char[] includePath, int offset);
|
||||
|
||||
public void enterObjectStyleMacroExpansion(char[] name, char[] expansion,
|
||||
int offset);
|
||||
|
||||
public void exitObjectStyleMacroExpansion(char[] name, int offset);
|
||||
|
||||
public void enterFunctionStyleExpansion(char[] name, char[][] parameters,
|
||||
char[] expansion, int offset);
|
||||
|
||||
public void exitFunctionStyleExpansion(char[] name, int offset);
|
||||
|
||||
public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset,
|
||||
int nameOffset, int nameEndOffset, int endOffset);
|
||||
|
||||
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
|
||||
int nameOffset, int nameEndOffset, int endOffset);
|
||||
|
||||
public void encounterPoundIf(int startOffset, int endOffset);
|
||||
|
||||
public void encounterPoundPragma(int startOffset, int endOffset);
|
||||
|
||||
public void encounterPoundError(int startOffset, int endOffset);
|
||||
|
||||
public void encounterPoundIfdef(int startOffset, int endOffset);
|
||||
|
||||
public void encounterPoundUndef(int startOffset, int endOffset);
|
||||
|
||||
public void encounterPoundElse(int startOffset, int endOffset);
|
||||
|
||||
public void encounterPoundElif(int startOffset, int endOffset);
|
||||
|
||||
public void encounterPoundEndIf(int startOffset, int endOffset);
|
||||
}
|
|
@ -0,0 +1,212 @@
|
|||
/**********************************************************************
|
||||
* 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.internal.core.parser.scanner2;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
|
||||
*/
|
||||
public IASTMacroDefinition[] getMacroDefinitions(IASTNode parent) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getIncludeDirectives()
|
||||
*/
|
||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives(IASTNode newParam) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getAllPreprocessorStatements()
|
||||
*/
|
||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements(IASTNode newParam) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getLocations(int, int)
|
||||
*/
|
||||
public IASTNodeLocation[] getLocations(int offset, int length) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getLocation(int)
|
||||
*/
|
||||
public IASTNodeLocation getLocation(int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
|
||||
*/
|
||||
public void startTranslationUnit() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endTranslationUnit(int)
|
||||
*/
|
||||
public void endTranslationUnit(int finalOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startInclusion(char[], int)
|
||||
*/
|
||||
public void startInclusion(char[] includePath, int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endInclusion(char[], int)
|
||||
*/
|
||||
public void endInclusion(char[] includePath, int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#enterObjectStyleMacroExpansion(char[], char[], int)
|
||||
*/
|
||||
public void enterObjectStyleMacroExpansion(char[] name, char[] expansion,
|
||||
int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#exitObjectStyleMacroExpansion(char[], int)
|
||||
*/
|
||||
public void exitObjectStyleMacroExpansion(char[] name, int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#enterFunctionStyleExpansion(char[], char[][], char[], int)
|
||||
*/
|
||||
public void enterFunctionStyleExpansion(char[] name, char[][] parameters,
|
||||
char[] expansion, int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#exitFunctionStyleExpansion(char[], int)
|
||||
*/
|
||||
public void exitFunctionStyleExpansion(char[] name, int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#defineObjectStyleMacro(org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro, int, int, int, int)
|
||||
*/
|
||||
public void defineObjectStyleMacro(ObjectStyleMacro m, int startOffset,
|
||||
int nameOffset, int nameEndOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#defineFunctionStyleMacro(org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro, int, int, int, int)
|
||||
*/
|
||||
public void defineFunctionStyleMacro(FunctionStyleMacro m, int startOffset,
|
||||
int nameOffset, int nameEndOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIf(int, int)
|
||||
*/
|
||||
public void encounterPoundIf(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundPragma(int, int)
|
||||
*/
|
||||
public void encounterPoundPragma(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundError(int, int)
|
||||
*/
|
||||
public void encounterPoundError(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfdef(int, int)
|
||||
*/
|
||||
public void encounterPoundIfdef(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundUndef(int, int)
|
||||
*/
|
||||
public void encounterPoundUndef(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElse(int, int)
|
||||
*/
|
||||
public void encounterPoundElse(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElif(int, int)
|
||||
*/
|
||||
public void encounterPoundElif(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundEndIf(int, int)
|
||||
*/
|
||||
public void encounterPoundEndIf(int startOffset, int endOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -3461,6 +3461,14 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
buffer.append( getLineNumber( getCurrentOffset()));
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver()
|
||||
*/
|
||||
public ILocationResolver getLocationResolver() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/**********************************************************************
|
||||
* 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.internal.core.parser2;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface IRequiresLocationInformation {
|
||||
|
||||
/**
|
||||
* @param locationResolver
|
||||
*/
|
||||
void setLocationResolver(ILocationResolver resolver);
|
||||
|
||||
}
|
|
@ -20,11 +20,13 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
|
||||
import org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit {
|
||||
public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit, IRequiresLocationInformation {
|
||||
|
||||
|
||||
private IASTDeclaration [] decls = null;
|
||||
|
@ -33,6 +35,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
|||
|
||||
//Binding
|
||||
private CScope compilationUnit = null;
|
||||
private ILocationResolver resolver;
|
||||
|
||||
public void addDeclaration( IASTDeclaration d )
|
||||
{
|
||||
|
@ -108,8 +111,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int)
|
||||
*/
|
||||
public IASTNodeLocation getLocationInfo(int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return resolver.getLocation(offset);
|
||||
}
|
||||
|
||||
|
||||
|
@ -117,8 +119,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, int)
|
||||
*/
|
||||
public IASTNodeLocation[] getLocationInfo(int offset, int length) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return resolver.getLocations(offset,length);
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,8 +136,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
|
||||
*/
|
||||
public IASTMacroDefinition[] getMacroDefinitions() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return resolver.getMacroDefinitions(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -144,8 +144,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives()
|
||||
*/
|
||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return resolver.getIncludeDirectives(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,7 +152,14 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
|
||||
*/
|
||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return resolver.getAllPreprocessorStatements(this);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation#setLocationResolver(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver)
|
||||
*/
|
||||
public void setLocationResolver(ILocationResolver resolver) {
|
||||
this.resolver = resolver;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,16 +22,19 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
|
||||
import org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTTranslationUnit extends CPPASTNode implements
|
||||
IASTTranslationUnit {
|
||||
IASTTranslationUnit, IRequiresLocationInformation {
|
||||
private IASTDeclaration [] decls = null;
|
||||
private ICPPScope scope = null;
|
||||
private static final int DEFAULT_CHILDREN_LIST_SIZE = 8;
|
||||
private int currentIndex = 0;
|
||||
private ILocationResolver resolver;
|
||||
|
||||
public void addDeclaration( IASTDeclaration d )
|
||||
{
|
||||
|
@ -107,8 +110,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int)
|
||||
*/
|
||||
public IASTNodeLocation getLocationInfo(int offset) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return resolver.getLocation(offset);
|
||||
}
|
||||
|
||||
|
||||
|
@ -116,8 +118,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, int)
|
||||
*/
|
||||
public IASTNodeLocation[] getLocationInfo(int offset, int length) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return resolver.getLocations(offset,length);
|
||||
}
|
||||
|
||||
|
||||
|
@ -134,8 +135,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
|
||||
*/
|
||||
public IASTMacroDefinition[] getMacroDefinitions() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return resolver.getMacroDefinitions(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -143,8 +143,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives()
|
||||
*/
|
||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return resolver.getIncludeDirectives(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -152,7 +151,14 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
|
||||
*/
|
||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return resolver.getAllPreprocessorStatements(this);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation#setLocationResolver(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver)
|
||||
*/
|
||||
public void setLocationResolver(ILocationResolver resolver) {
|
||||
this.resolver = resolver;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
package org.eclipse.cdt.core.dom;
|
||||
import org.eclipse.cdt.core.dom.IASTServiceProvider;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.internal.core.dom.InternalASTServiceProvider;
|
||||
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -18,22 +20,23 @@ import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
|||
* This class serves as the manager of the AST/DOM mechanisms for the CDT.
|
||||
* It should be eventually added to CCorePlugin for startup.
|
||||
*/
|
||||
public class DOM {
|
||||
public class CDOM {
|
||||
|
||||
private IASTServiceProvider [] services = { new InternalASTServiceProvider() };
|
||||
|
||||
public IASTServiceProvider[] getASTFactories() {
|
||||
//TODO stub
|
||||
return null;
|
||||
public IASTServiceProvider[] getASTServices() {
|
||||
return services;
|
||||
}
|
||||
|
||||
public IASTServiceProvider getDefaultASTFactory() {
|
||||
IASTServiceProvider [] factories = getASTFactories();
|
||||
public IASTServiceProvider getDefaultASTService() {
|
||||
IASTServiceProvider [] factories = getASTServices();
|
||||
if( factories != null && factories.length > 0 )
|
||||
return factories[0];
|
||||
return null;
|
||||
}
|
||||
|
||||
public IASTServiceProvider getASTFactoryByName(String name) {
|
||||
IASTServiceProvider [] factories = getASTFactories();
|
||||
public IASTServiceProvider getASTServiceByName(String name) {
|
||||
IASTServiceProvider [] factories = getASTServices();
|
||||
if( factories == null || factories.length == 0 )
|
||||
return null;
|
||||
for( int i = 0; i < factories.length; ++i )
|
||||
|
@ -41,6 +44,23 @@ public class DOM {
|
|||
return factories[i];
|
||||
return null;
|
||||
}
|
||||
|
||||
public IASTServiceProvider getASTServiceByDialect( String dialect )
|
||||
{
|
||||
IASTServiceProvider [] factories = getASTServices();
|
||||
if( factories == null || factories.length == 0 )
|
||||
return null;
|
||||
for( int i = 0; i < factories.length; ++i )
|
||||
if( factories[i] != null )
|
||||
{
|
||||
String [] dialects = factories[i].getSupportedDialects();
|
||||
if( dialects != null )
|
||||
for( int j = 0; j < dialects.length; ++j )
|
||||
if( dialects[j].equals( dialect ))
|
||||
return factories[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final int PARSE_SAVED_RESOURCES = 0;
|
||||
public static final int PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS = 1;
|
||||
|
@ -51,7 +71,7 @@ public class DOM {
|
|||
switch( key )
|
||||
{
|
||||
case PARSE_SAVED_RESOURCES:
|
||||
return null; //TODO
|
||||
return SavedCodeReaderFactory.getInstance();
|
||||
case PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS:
|
||||
return null; //TODO
|
||||
case PARSE_WORKING_COPY_WHENEVER_POSSIBLE:
|
|
@ -0,0 +1,198 @@
|
|||
/**********************************************************************
|
||||
* 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.internal.core.dom;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IASTServiceProvider;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.IParserConfiguration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.filetype.ICFileType;
|
||||
import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.internal.core.parser2.IProblemRequestor;
|
||||
import org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation;
|
||||
import org.eclipse.cdt.internal.core.parser2.ISourceCodeParser;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.ANSICParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.GCCParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.GNUCSourceParser;
|
||||
import org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser2.cpp.ANSICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser2.cpp.GNUCPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser2.cpp.GNUCPPSourceParser;
|
||||
import org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||
|
||||
private static final String[] dialects = { "C99", //$NON-NLS-1$
|
||||
"C++98", //$NON-NLS-1$
|
||||
"GNUC", //$NON-NLS-1$
|
||||
"GNUC++" }; //$NON-NLS-1$
|
||||
private static final ISourceElementRequestor NULL_REQUESTOR = new NullSourceElementRequestor();
|
||||
private static final IProblemRequestor PROBLEM_REQUESTOR = new IProblemRequestor() {
|
||||
|
||||
public boolean acceptProblem(IProblem problem) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return "CDT AST Service"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit()
|
||||
*/
|
||||
public IASTTranslationUnit getTranslationUnit(IFile fileToParse) throws UnsupportedDialectException {
|
||||
return getTranslationUnit( fileToParse, SavedCodeReaderFactory.getInstance(), null );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.cdt.core.dom.ICodeReaderFactory)
|
||||
*/
|
||||
public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
||||
return getTranslationUnit( fileToParse, fileCreator, null );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.cdt.core.dom.ICodeReaderFactory, org.eclipse.cdt.core.dom.IParserConfiguration)
|
||||
*/
|
||||
public IASTTranslationUnit getTranslationUnit(
|
||||
IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration) throws UnsupportedDialectException {
|
||||
//Get the scanner info
|
||||
IProject currentProject = fileToParse.getProject();
|
||||
IScannerInfo scanInfo = null;
|
||||
|
||||
if( configuration == null )
|
||||
{
|
||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject);
|
||||
if (provider != null){
|
||||
IScannerInfo buildScanInfo = provider.getScannerInformation(fileToParse);
|
||||
if (buildScanInfo != null){
|
||||
scanInfo = buildScanInfo;
|
||||
}
|
||||
else
|
||||
scanInfo = new ScannerInfo();
|
||||
}
|
||||
}
|
||||
else
|
||||
scanInfo = configuration.getScannerInfo();
|
||||
|
||||
|
||||
CodeReader reader = fileCreator.createCodeReaderForTranslationUnit( fileToParse.getLocation().toOSString() );
|
||||
IScanner scanner = null;
|
||||
ISourceCodeParser parser = null;
|
||||
|
||||
if( configuration == null )
|
||||
{
|
||||
ParserLanguage l = getLanguage(fileToParse);
|
||||
scanner = ParserFactory.createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
|
||||
l, NULL_REQUESTOR,
|
||||
ParserUtil.getScannerLogService(), Collections.EMPTY_LIST);
|
||||
//assume GCC
|
||||
if( l == ParserLanguage.C )
|
||||
parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), new GCCParserExtensionConfiguration() );
|
||||
else
|
||||
parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), new GNUCPPParserExtensionConfiguration() );
|
||||
}
|
||||
else
|
||||
{
|
||||
String dialect = configuration.getParserDialect();
|
||||
if( dialect.equals( dialects[0]) || dialect.equals( dialects[2]))
|
||||
scanner = ParserFactory.createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
|
||||
ParserLanguage.C, NULL_REQUESTOR,
|
||||
ParserUtil.getScannerLogService(), Collections.EMPTY_LIST);
|
||||
else if( dialect.equals( dialects[1] ) || dialect.equals( dialects[3] ))
|
||||
scanner = ParserFactory.createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
|
||||
ParserLanguage.CPP, NULL_REQUESTOR,
|
||||
ParserUtil.getScannerLogService(), Collections.EMPTY_LIST);
|
||||
else
|
||||
throw new UnsupportedDialectException();
|
||||
|
||||
if( dialect.equals( dialects[0]))
|
||||
{
|
||||
ICParserExtensionConfiguration config = new ANSICParserExtensionConfiguration();
|
||||
parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), config );
|
||||
}
|
||||
else if( dialect.equals( dialects[1] ))
|
||||
{
|
||||
ICPPParserExtensionConfiguration config = new ANSICPPParserExtensionConfiguration();
|
||||
parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), config );
|
||||
}
|
||||
else if( dialect.equals( dialects[2]))
|
||||
{
|
||||
ICParserExtensionConfiguration config = new GCCParserExtensionConfiguration();
|
||||
parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), config );
|
||||
}
|
||||
else if( dialect.equals( dialects[3]))
|
||||
{
|
||||
ICPPParserExtensionConfiguration config = new GNUCPPParserExtensionConfiguration();
|
||||
parser = new GNUCPPSourceParser( scanner, ParserMode.COMPLETE_PARSE, PROBLEM_REQUESTOR, ParserUtil.getParserLogService(), config );
|
||||
}
|
||||
}
|
||||
IASTTranslationUnit tu = parser.parse();
|
||||
if( tu instanceof IRequiresLocationInformation )
|
||||
((IRequiresLocationInformation)tu).setLocationResolver( scanner.getLocationResolver() );
|
||||
return tu;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getSupportedDialects()
|
||||
*/
|
||||
public String[] getSupportedDialects() {
|
||||
return dialects;
|
||||
}
|
||||
|
||||
private ParserLanguage getLanguage( IResource resource )
|
||||
{
|
||||
IProject project = resource.getProject();
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(project, resource.getLocation().lastSegment());
|
||||
String lid = type.getLanguage().getId();
|
||||
if( lid != null )
|
||||
{
|
||||
if( lid.equals(ICFileTypeConstants.LANG_C ))
|
||||
return ParserLanguage.C;
|
||||
if( lid.equals(ICFileTypeConstants.LANG_CXX))
|
||||
return ParserLanguage.CPP;
|
||||
}
|
||||
try {
|
||||
if( project.hasNature( CCProjectNature.CC_NATURE_ID ))
|
||||
return ParserLanguage.CPP;
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
return ParserLanguage.C;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/**********************************************************************
|
||||
* 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.internal.core.dom;
|
||||
|
||||
import org.eclipse.cdt.core.dom.CDOM;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class SavedCodeReaderFactory implements ICodeReaderFactory {
|
||||
|
||||
public static SavedCodeReaderFactory getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static SavedCodeReaderFactory instance = new SavedCodeReaderFactory();
|
||||
|
||||
private SavedCodeReaderFactory()
|
||||
{
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#getUniqueIdentifier()
|
||||
*/
|
||||
public int getUniqueIdentifier() {
|
||||
return CDOM.PARSE_SAVED_RESOURCES;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForTranslationUnit(java.lang.String)
|
||||
*/
|
||||
public CodeReader createCodeReaderForTranslationUnit(String path) {
|
||||
return ParserUtil.createReader( path, EmptyIterator.EMPTY_ITERATOR );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String)
|
||||
*/
|
||||
public CodeReader createCodeReaderForInclusion(String path) {
|
||||
return ParserUtil.createReader( path, EmptyIterator.EMPTY_ITERATOR );
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue