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;
|
package org.eclipse.cdt.core.dom;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public interface IASTServiceProvider {
|
public interface IASTServiceProvider {
|
||||||
|
|
||||||
|
public static class UnsupportedDialectException extends Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public String getName();
|
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();
|
public String [] getSupportedDialects();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,8 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public interface IParserConfiguration {
|
public interface IParserConfiguration {
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public IScannerInfo getScannerInfo();
|
public IScannerInfo getScannerInfo();
|
||||||
/**
|
public String getParserDialect();
|
||||||
*/
|
|
||||||
public String getParserDialectName();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
|
@ -38,4 +39,6 @@ public interface IScanner {
|
||||||
public CharArrayObjectMap getRealDefinitions();
|
public CharArrayObjectMap getRealDefinitions();
|
||||||
public void cancel();
|
public void cancel();
|
||||||
public char[] getMainFilename();
|
public char[] getMainFilename();
|
||||||
|
|
||||||
|
public ILocationResolver getLocationResolver();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,9 @@
|
||||||
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.IASTMacroDefinition;
|
||||||
|
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.IASTPreprocessorStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,7 +21,11 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
*/
|
*/
|
||||||
public interface ILocationResolver {
|
public interface ILocationResolver {
|
||||||
|
|
||||||
public IASTMacroDefinition[] getAllMacroDefinitions();
|
public IASTMacroDefinition [] getMacroDefinitions(IASTNode parent);
|
||||||
public IASTPreprocessorStatement [] getPreprocessorStatements();
|
public IASTPreprocessorIncludeStatement [] getIncludeDirectives(IASTNode parent);
|
||||||
public IASTNodeLocation [] getLocations( int offset, int length );
|
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 interface IScannerPreprocessorLog {
|
||||||
|
|
||||||
public void startTranslationUnit();
|
public void startTranslationUnit();
|
||||||
public void endTranslationUnit( int finalOffset );
|
|
||||||
|
|
||||||
public void startInclusion( char [] includePath, int offset );
|
public void endTranslationUnit(int finalOffset);
|
||||||
public void endInclusion( char [] includePath, int offset );
|
|
||||||
|
|
||||||
public void enterObjectStyleMacroExpansion( char [] name, char [] expansion, int offset );
|
public void startInclusion(char[] includePath, int offset);
|
||||||
public void exitObjectStyleMacroExpansion( char [] name, int offset );
|
|
||||||
|
|
||||||
public void enterFunctionStyleExpansion( char [] name, char [][] parameters, char [] expansion, int offset );
|
public void endInclusion(char[] includePath, int offset);
|
||||||
public void exitFunctionStyleExpansion( char [] name, int offset );
|
|
||||||
|
|
||||||
public void defineObjectStyleMacro( ObjectStyleMacro m, int startOffset, int nameOffset, int nameEndOffset, int endOffset );
|
public void enterObjectStyleMacroExpansion(char[] name, char[] expansion,
|
||||||
public void defineFunctionStyleMacro( FunctionStyleMacro m, int startOffset, int nameOffset, int nameEndOffset, int endOffset );
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3462,5 +3462,13 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
return buffer.toString();
|
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.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
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
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit {
|
public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit, IRequiresLocationInformation {
|
||||||
|
|
||||||
|
|
||||||
private IASTDeclaration [] decls = null;
|
private IASTDeclaration [] decls = null;
|
||||||
|
@ -33,6 +35,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
||||||
|
|
||||||
//Binding
|
//Binding
|
||||||
private CScope compilationUnit = null;
|
private CScope compilationUnit = null;
|
||||||
|
private ILocationResolver resolver;
|
||||||
|
|
||||||
public void addDeclaration( IASTDeclaration d )
|
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)
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int)
|
||||||
*/
|
*/
|
||||||
public IASTNodeLocation getLocationInfo(int offset) {
|
public IASTNodeLocation getLocationInfo(int offset) {
|
||||||
// TODO Auto-generated method stub
|
return resolver.getLocation(offset);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,8 +119,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, int)
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, int)
|
||||||
*/
|
*/
|
||||||
public IASTNodeLocation[] getLocationInfo(int offset, int length) {
|
public IASTNodeLocation[] getLocationInfo(int offset, int length) {
|
||||||
// TODO Auto-generated method stub
|
return resolver.getLocations(offset,length);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,8 +136,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
|
||||||
*/
|
*/
|
||||||
public IASTMacroDefinition[] getMacroDefinitions() {
|
public IASTMacroDefinition[] getMacroDefinitions() {
|
||||||
// TODO Auto-generated method stub
|
return resolver.getMacroDefinitions(this);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,8 +144,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives()
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives()
|
||||||
*/
|
*/
|
||||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
||||||
// TODO Auto-generated method stub
|
return resolver.getIncludeDirectives(this);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,7 +152,14 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
|
||||||
*/
|
*/
|
||||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||||
// TODO Auto-generated method stub
|
return resolver.getAllPreprocessorStatements(this);
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (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.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
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
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public class CPPASTTranslationUnit extends CPPASTNode implements
|
public class CPPASTTranslationUnit extends CPPASTNode implements
|
||||||
IASTTranslationUnit {
|
IASTTranslationUnit, IRequiresLocationInformation {
|
||||||
private IASTDeclaration [] decls = null;
|
private IASTDeclaration [] decls = null;
|
||||||
private ICPPScope scope = null;
|
private ICPPScope scope = null;
|
||||||
private static final int DEFAULT_CHILDREN_LIST_SIZE = 8;
|
private static final int DEFAULT_CHILDREN_LIST_SIZE = 8;
|
||||||
private int currentIndex = 0;
|
private int currentIndex = 0;
|
||||||
|
private ILocationResolver resolver;
|
||||||
|
|
||||||
public void addDeclaration( IASTDeclaration d )
|
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)
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int)
|
||||||
*/
|
*/
|
||||||
public IASTNodeLocation getLocationInfo(int offset) {
|
public IASTNodeLocation getLocationInfo(int offset) {
|
||||||
// TODO Auto-generated method stub
|
return resolver.getLocation(offset);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,8 +118,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, int)
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, int)
|
||||||
*/
|
*/
|
||||||
public IASTNodeLocation[] getLocationInfo(int offset, int length) {
|
public IASTNodeLocation[] getLocationInfo(int offset, int length) {
|
||||||
// TODO Auto-generated method stub
|
return resolver.getLocations(offset,length);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,8 +135,7 @@ 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 IASTMacroDefinition[] getMacroDefinitions() {
|
||||||
// TODO Auto-generated method stub
|
return resolver.getMacroDefinitions(this);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,8 +143,7 @@ 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() {
|
||||||
// TODO Auto-generated method stub
|
return resolver.getIncludeDirectives(this);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +151,14 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
|
||||||
*/
|
*/
|
||||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||||
// TODO Auto-generated method stub
|
return resolver.getAllPreprocessorStatements(this);
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (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;
|
package org.eclipse.cdt.core.dom;
|
||||||
import org.eclipse.cdt.core.dom.IASTServiceProvider;
|
import org.eclipse.cdt.core.dom.IASTServiceProvider;
|
||||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
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
|
* @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.
|
* This class serves as the manager of the AST/DOM mechanisms for the CDT.
|
||||||
* It should be eventually added to CCorePlugin for startup.
|
* It should be eventually added to CCorePlugin for startup.
|
||||||
*/
|
*/
|
||||||
public class DOM {
|
public class CDOM {
|
||||||
|
|
||||||
public IASTServiceProvider[] getASTFactories() {
|
private IASTServiceProvider [] services = { new InternalASTServiceProvider() };
|
||||||
//TODO stub
|
|
||||||
return null;
|
public IASTServiceProvider[] getASTServices() {
|
||||||
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTServiceProvider getDefaultASTFactory() {
|
public IASTServiceProvider getDefaultASTService() {
|
||||||
IASTServiceProvider [] factories = getASTFactories();
|
IASTServiceProvider [] factories = getASTServices();
|
||||||
if( factories != null && factories.length > 0 )
|
if( factories != null && factories.length > 0 )
|
||||||
return factories[0];
|
return factories[0];
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTServiceProvider getASTFactoryByName(String name) {
|
public IASTServiceProvider getASTServiceByName(String name) {
|
||||||
IASTServiceProvider [] factories = getASTFactories();
|
IASTServiceProvider [] factories = getASTServices();
|
||||||
if( factories == null || factories.length == 0 )
|
if( factories == null || factories.length == 0 )
|
||||||
return null;
|
return null;
|
||||||
for( int i = 0; i < factories.length; ++i )
|
for( int i = 0; i < factories.length; ++i )
|
||||||
|
@ -42,6 +45,23 @@ public class DOM {
|
||||||
return null;
|
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_SAVED_RESOURCES = 0;
|
||||||
public static final int PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS = 1;
|
public static final int PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS = 1;
|
||||||
public static final int PARSE_WORKING_COPY_WHENEVER_POSSIBLE = 2;
|
public static final int PARSE_WORKING_COPY_WHENEVER_POSSIBLE = 2;
|
||||||
|
@ -51,7 +71,7 @@ public class DOM {
|
||||||
switch( key )
|
switch( key )
|
||||||
{
|
{
|
||||||
case PARSE_SAVED_RESOURCES:
|
case PARSE_SAVED_RESOURCES:
|
||||||
return null; //TODO
|
return SavedCodeReaderFactory.getInstance();
|
||||||
case PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS:
|
case PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS:
|
||||||
return null; //TODO
|
return null; //TODO
|
||||||
case PARSE_WORKING_COPY_WHENEVER_POSSIBLE:
|
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