mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Goodbye IScannerExtension.
Hello IScannerConfiguration.
This commit is contained in:
parent
656d059c25
commit
46150fa029
13 changed files with 193 additions and 307 deletions
|
@ -29,9 +29,7 @@ import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.extension.ExtensionDialect;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserExtensionFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration;
|
||||
|
@ -85,7 +83,7 @@ public class BaseScanner2Test extends TestCase {
|
|||
configuration = new GCCScannerConfiguration();
|
||||
else
|
||||
configuration = new GPPScannerConfiguration();
|
||||
return new Scanner2( code, config, ourRequestor, ourMode, language, logService, new ParserExtensionFactory( ExtensionDialect.GCC ).createScannerExtension(), workingCopies, configuration );
|
||||
return new Scanner2( code, config, ourRequestor, ourMode, language, logService, workingCopies, configuration );
|
||||
}
|
||||
|
||||
public int fullyTokenize() throws Exception
|
||||
|
|
|
@ -19,8 +19,6 @@ import org.eclipse.cdt.core.parser.ParserFactoryError;
|
|||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.extension.ExtensionDialect;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserExtensionFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration;
|
||||
|
@ -91,7 +89,7 @@ public class SpeedTest2 extends TestCase {
|
|||
configuration = new GCCScannerConfiguration();
|
||||
else
|
||||
configuration = new GPPScannerConfiguration();
|
||||
return new Scanner2( code, config, ourRequestor, ourMode, language, logService, new ParserExtensionFactory( ExtensionDialect.GCC ).createScannerExtension(), workingCopies, configuration );
|
||||
return new Scanner2( code, config, ourRequestor, ourMode, language, logService, workingCopies, configuration );
|
||||
}
|
||||
|
||||
private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor();
|
||||
|
|
|
@ -93,7 +93,7 @@ public class ParserFactory {
|
|||
else
|
||||
configuration = new GPPScannerConfiguration();
|
||||
|
||||
return new Scanner2( code, config, ourRequestor, ourMode, language, logService, extensionFactory.createScannerExtension(), workingCopies, configuration );
|
||||
return new Scanner2( code, config, ourRequestor, ourMode, language, logService, workingCopies, configuration );
|
||||
}
|
||||
|
||||
public static IScanner createScanner( String fileName, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError, IOException
|
||||
|
|
|
@ -18,8 +18,7 @@ import org.eclipse.cdt.core.parser.ParserMode;
|
|||
* @author jcamelon
|
||||
*/
|
||||
public interface IParserExtensionFactory {
|
||||
|
||||
public IScannerExtension createScannerExtension() throws ParserFactoryError;
|
||||
|
||||
public IParserExtension createParserExtension() throws ParserFactoryError;
|
||||
public IASTFactoryExtension createASTExtension(ParserMode mode);
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.core.parser.extension;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerData;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public interface IScannerExtension {
|
||||
|
||||
public void setupBuiltInMacros(IScannerData scannerData);
|
||||
|
||||
public boolean isExtensionKeyword(ParserLanguage language, char[] tokenImage);
|
||||
public boolean isExtensionOperator(ParserLanguage language, char[] query);
|
||||
|
||||
public IToken createExtensionToken(IScannerData scannerData, char[] image);
|
||||
|
||||
}
|
|
@ -16,9 +16,7 @@ import org.eclipse.cdt.core.parser.extension.ExtensionDialect;
|
|||
import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension;
|
||||
import org.eclipse.cdt.core.parser.extension.IParserExtension;
|
||||
import org.eclipse.cdt.core.parser.extension.IParserExtensionFactory;
|
||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.GCCASTExtension;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtension;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -34,15 +32,6 @@ public class ParserExtensionFactory implements IParserExtensionFactory {
|
|||
this.dialect = dialect;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IParserExtensionFactory#createScannerExtension()
|
||||
*/
|
||||
public IScannerExtension createScannerExtension() throws ParserFactoryError {
|
||||
if( dialect == ExtensionDialect.GCC )
|
||||
return new GCCScannerExtension();
|
||||
throw new ParserFactoryError( ParserFactoryError.Kind.BAD_DIALECT );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IParserExtensionFactory#createParserExtension()
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.eclipse.cdt.core.parser.IParserLogService;
|
|||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -27,16 +26,15 @@ public class DOMScanner extends Scanner2 {
|
|||
/**
|
||||
* @param reader
|
||||
* @param info
|
||||
* @param requestor
|
||||
* @param parserMode
|
||||
* @param language
|
||||
* @param log
|
||||
* @param extension
|
||||
* @param workingCopies
|
||||
* @param requestor
|
||||
*/
|
||||
public DOMScanner(CodeReader reader, IScannerInfo info, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerExtension extension, List workingCopies, IScannerConfiguration configuration) {
|
||||
super(reader, info, null, parserMode, language, log, extension,
|
||||
workingCopies, configuration);
|
||||
public DOMScanner(CodeReader reader, IScannerInfo info, ParserMode parserMode, ParserLanguage language, IParserLogService log, List workingCopies, IScannerConfiguration configuration) {
|
||||
super(reader, info, null, parserMode, language, log, workingCopies,
|
||||
configuration);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -10,7 +10,10 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import org.eclipse.cdt.core.parser.GCCKeywords;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -23,13 +26,48 @@ public class GCCScannerConfiguration extends GNUScannerConfiguration implements
|
|||
public boolean supportMinAndMaxOperators() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final FunctionStyleMacro _Pragma = new FunctionStyleMacro(
|
||||
"_Pragma".toCharArray(), //$NON-NLS-1$
|
||||
emptyCharArray,
|
||||
new char[][] { "arg".toCharArray() } ); //$NON-NLS-1$
|
||||
|
||||
private final DynamicFunctionStyleMacro __builtin_choose_expr =
|
||||
new DynamicFunctionStyleMacro( "__builtin_choose_expr".toCharArray(), //$NON-NLS-1$
|
||||
new char[][] { "const_exp".toCharArray(), "exp1".toCharArray(), "exp2".toCharArray() } ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
{
|
||||
public char [] execute( CharArrayObjectMap argmap ){
|
||||
ExpressionEvaluator evaluator = new ExpressionEvaluator();
|
||||
char[] const_exp = (char[]) argmap.get( arglist[0] );
|
||||
long exp = 0;
|
||||
if( const_exp != null)
|
||||
exp = evaluator.evaluate( const_exp, 0, const_exp.length, CharArrayObjectMap.EMPTY_MAP );
|
||||
|
||||
if( exp != 0 )
|
||||
return (char[])argmap.get( arglist[1] );
|
||||
return (char[])argmap.get( arglist[2] );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros()
|
||||
*/
|
||||
public CharArrayObjectMap getAdditionalMacros() {
|
||||
CharArrayObjectMap result = super.getAdditionalMacros();
|
||||
result.put(_Pragma.name, _Pragma );
|
||||
result.put( __builtin_choose_expr.name, __builtin_choose_expr );
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalKeywords()
|
||||
*/
|
||||
public CharArrayIntMap getAdditionalKeywords() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
CharArrayIntMap result = new CharArrayIntMap( 4, -1 );
|
||||
result.put( GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ );
|
||||
result.put( GCCKeywords.cpTYPEOF, IGCCToken.t_typeof );
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,215 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2004 IBM Rational Software and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import org.eclipse.cdt.core.parser.GCCKeywords;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.internal.core.parser.token.ImagedToken;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class GCCScannerExtension implements IScannerExtension {
|
||||
|
||||
private static final String [] simpleIdentifiersDeclSpec;
|
||||
private static final String [] simpleIdentifiersAttribute;
|
||||
static
|
||||
{
|
||||
simpleIdentifiersDeclSpec = new String[ 1 ];
|
||||
simpleIdentifiersDeclSpec[0]= "x"; //$NON-NLS-1$
|
||||
|
||||
simpleIdentifiersAttribute = new String[ 1 ];
|
||||
simpleIdentifiersAttribute[0] = "xyz"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
private static final char [] emptyCharArray = "".toCharArray(); //$NON-NLS-1$
|
||||
// gcc built-ins
|
||||
private static final ObjectStyleMacro __inline__
|
||||
= new ObjectStyleMacro("__inline__".toCharArray(), "inline".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final ObjectStyleMacro __extension__
|
||||
= new ObjectStyleMacro("__extension__".toCharArray(), emptyCharArray); //$NON-NLS-1$
|
||||
private static final ObjectStyleMacro __asm__
|
||||
= new ObjectStyleMacro("__asm__".toCharArray(), "asm".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final ObjectStyleMacro __restrict__
|
||||
= new ObjectStyleMacro("__restrict__".toCharArray(), "restrict".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final ObjectStyleMacro __restrict
|
||||
= new ObjectStyleMacro("__restrict".toCharArray(), "restrict".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final ObjectStyleMacro __volatile__
|
||||
= new ObjectStyleMacro("__volatile__".toCharArray(), "volatile".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final ObjectStyleMacro __const__
|
||||
= new ObjectStyleMacro("__const__".toCharArray(), "const".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final ObjectStyleMacro __const
|
||||
= new ObjectStyleMacro("__const".toCharArray(), "const".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final ObjectStyleMacro __signed__
|
||||
= new ObjectStyleMacro("__signed__".toCharArray(), "signed".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final ObjectStyleMacro __cdecl = new
|
||||
ObjectStyleMacro( "__cdecl".toCharArray(), emptyCharArray ); //$NON-NLS-1$
|
||||
private static final ObjectStyleMacro __complex__ =
|
||||
new ObjectStyleMacro( "__complex__".toCharArray(), "_Complex".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final ObjectStyleMacro __real__ =
|
||||
new ObjectStyleMacro( "__real__".toCharArray(), "(int)".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final ObjectStyleMacro __imag__ =
|
||||
new ObjectStyleMacro( "__imag__".toCharArray(), "(int)".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
|
||||
private static final FunctionStyleMacro __attribute__
|
||||
= new FunctionStyleMacro(
|
||||
"__attribute__".toCharArray(), //$NON-NLS-1$
|
||||
emptyCharArray,
|
||||
new char[][] { "arg".toCharArray() }); //$NON-NLS-1$
|
||||
private static final FunctionStyleMacro __declspec
|
||||
= new FunctionStyleMacro(
|
||||
"__declspec".toCharArray(), //$NON-NLS-1$
|
||||
emptyCharArray,
|
||||
new char[][] { "arg".toCharArray() }); //$NON-NLS-1$
|
||||
|
||||
private static final FunctionStyleMacro _Pragma = new FunctionStyleMacro(
|
||||
"_Pragma".toCharArray(), //$NON-NLS-1$
|
||||
emptyCharArray,
|
||||
new char[][] { "arg".toCharArray() } ); //$NON-NLS-1$
|
||||
|
||||
private static final FunctionStyleMacro __builtin_va_arg
|
||||
= new FunctionStyleMacro(
|
||||
"__builtin_va_arg".toCharArray(), //$NON-NLS-1$
|
||||
"*(type *)ap".toCharArray(), //$NON-NLS-1$
|
||||
new char[][] { "ap".toCharArray(), "type".toCharArray() } ); //$NON-NLS-1$//$NON-NLS-2$
|
||||
|
||||
private static final FunctionStyleMacro __builtin_constant_p
|
||||
= new FunctionStyleMacro(
|
||||
"__builtin_constant_p".toCharArray(), //$NON-NLS-1$
|
||||
"0".toCharArray(), //$NON-NLS-1$
|
||||
new char[][] {"exp".toCharArray()} ); //$NON-NLS-1$//$NON-NLS-2$
|
||||
|
||||
private final DynamicFunctionStyleMacro __builtin_choose_expr =
|
||||
new DynamicFunctionStyleMacro( "__builtin_choose_expr".toCharArray(), //$NON-NLS-1$
|
||||
new char[][] { "const_exp".toCharArray(), "exp1".toCharArray(), "exp2".toCharArray() } ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
{
|
||||
public char [] execute( CharArrayObjectMap argmap ){
|
||||
ExpressionEvaluator evaluator = new ExpressionEvaluator();
|
||||
char[] const_exp = (char[]) argmap.get( arglist[0] );
|
||||
long exp = 0;
|
||||
if( const_exp != null)
|
||||
exp = evaluator.evaluate( const_exp, 0, const_exp.length, CharArrayObjectMap.EMPTY_MAP );
|
||||
|
||||
if( exp != 0 )
|
||||
return (char[])argmap.get( arglist[1] );
|
||||
return (char[])argmap.get( arglist[2] );
|
||||
}
|
||||
};
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScannerExtension#setupBuiltInMacros()
|
||||
*/
|
||||
public void setupBuiltInMacros(IScannerData scannerData) {
|
||||
// gcc extensions
|
||||
CharArrayObjectMap realDefinitions = scannerData.getRealDefinitions();
|
||||
realDefinitions.put(__inline__.name, __inline__);
|
||||
realDefinitions.put(__cdecl.name, __cdecl );
|
||||
realDefinitions.put( __const__.name, __const__ );
|
||||
realDefinitions.put( __const.name, __const );
|
||||
realDefinitions.put(__extension__.name, __extension__);
|
||||
realDefinitions.put(__attribute__.name, __attribute__);
|
||||
realDefinitions.put( __declspec.name, __declspec );
|
||||
realDefinitions.put(__restrict__.name, __restrict__);
|
||||
realDefinitions.put(__restrict.name, __restrict);
|
||||
realDefinitions.put(__volatile__.name, __volatile__);
|
||||
realDefinitions.put(__signed__.name, __signed__ );
|
||||
realDefinitions.put(__complex__.name, __complex__ );
|
||||
realDefinitions.put(__imag__.name, __imag__ );
|
||||
realDefinitions.put(__real__.name, __real__ );
|
||||
realDefinitions.put( __builtin_va_arg.name, __builtin_va_arg );
|
||||
realDefinitions.put( __builtin_constant_p.name, __builtin_constant_p );
|
||||
if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
realDefinitions.put(__asm__.name, __asm__);
|
||||
else{
|
||||
realDefinitions.put(_Pragma.name, _Pragma );
|
||||
realDefinitions.put( __builtin_choose_expr.name, __builtin_choose_expr );
|
||||
}
|
||||
}
|
||||
|
||||
private static final CharArrayIntMap additionalCPPKeywords;
|
||||
private static final CharArrayIntMap additionalCKeywords;
|
||||
private static final CharArrayIntMap additionalCPPOperators;
|
||||
private static final CharArrayIntMap additionalCOperators;
|
||||
private static final char [] MAX_OPERATOR = ">?".toCharArray(); //$NON-NLS-1$
|
||||
private static final char [] MIN_OPERATOR = "<?".toCharArray(); //$NON-NLS-1$
|
||||
|
||||
static
|
||||
{
|
||||
additionalCKeywords = new CharArrayIntMap( 2, -1 );
|
||||
additionalCKeywords.put( GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ );
|
||||
additionalCKeywords.put( GCCKeywords.cpTYPEOF, IGCCToken.t_typeof );
|
||||
additionalCPPKeywords = new CharArrayIntMap( 4, -1 );
|
||||
additionalCPPKeywords.put( GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ );
|
||||
additionalCPPKeywords.put( GCCKeywords.cpTYPEOF, IGCCToken.t_typeof );
|
||||
additionalCPPKeywords.put( Keywords.cRESTRICT, IToken.t_restrict );
|
||||
additionalCPPKeywords.put( Keywords.c_COMPLEX, IToken.t__Complex );
|
||||
additionalCPPKeywords.put( Keywords.c_IMAGINARY, IToken.t__Imaginary );
|
||||
|
||||
additionalCOperators = new CharArrayIntMap(2, -1);
|
||||
additionalCPPOperators = new CharArrayIntMap( 2, -1);
|
||||
additionalCPPOperators.put( MAX_OPERATOR, IGCCToken.tMAX );
|
||||
additionalCPPOperators.put( MIN_OPERATOR, IGCCToken.tMIN );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isExtensionKeyword()
|
||||
*/
|
||||
public boolean isExtensionKeyword(ParserLanguage language, char[] tokenImage) {
|
||||
if( language == ParserLanguage.CPP )
|
||||
return ( additionalCPPKeywords.containsKey( tokenImage ) );
|
||||
else if( language == ParserLanguage.C )
|
||||
return ( additionalCKeywords.containsKey( tokenImage ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#createExtensionToken()
|
||||
*/
|
||||
public IToken createExtensionToken(IScannerData scannerData, char[] image) {
|
||||
int get = -1;
|
||||
if( scannerData.getLanguage() == ParserLanguage.CPP )
|
||||
{
|
||||
get = additionalCPPKeywords.get( image );
|
||||
if( get == -1 )
|
||||
get = additionalCPPOperators.get( image );
|
||||
}
|
||||
else if( scannerData.getLanguage() == ParserLanguage.C )
|
||||
{
|
||||
get = additionalCKeywords.get( image );
|
||||
if( get == -1 )
|
||||
get = additionalCOperators.get( image );
|
||||
}
|
||||
if( get == -1 ) return null;
|
||||
int o = scannerData.getCurrentOffset() + 1;
|
||||
IToken i = new ImagedToken(get, image, o, scannerData.getCurrentFilename(), scannerData.getLineNumber( o ));
|
||||
return i;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isExtensionOperator(java.lang.String)
|
||||
*/
|
||||
public boolean isExtensionOperator(ParserLanguage language, char[] query) {
|
||||
if( language == ParserLanguage.CPP )
|
||||
return ( additionalCPPOperators.containsKey( query ) );
|
||||
else if (language == ParserLanguage.C )
|
||||
return ( additionalCOperators.containsKey( query ));
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,10 +10,14 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class GNUScannerConfiguration {
|
||||
public abstract class GNUScannerConfiguration implements IScannerConfiguration {
|
||||
|
||||
protected static final char[] emptyCharArray = "".toCharArray(); //$NON-NLS-1$
|
||||
|
||||
public boolean initializeMacroValuesTo1() {
|
||||
return true;
|
||||
|
@ -27,4 +31,84 @@ public class GNUScannerConfiguration {
|
|||
return "ij".toCharArray(); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
private static final ObjectStyleMacro __inline__ = new ObjectStyleMacro(
|
||||
"__inline__".toCharArray(), "inline".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private static final ObjectStyleMacro __extension__ = new ObjectStyleMacro(
|
||||
"__extension__".toCharArray(), emptyCharArray); //$NON-NLS-1$
|
||||
|
||||
|
||||
private static final ObjectStyleMacro __restrict__ = new ObjectStyleMacro(
|
||||
"__restrict__".toCharArray(), "restrict".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private static final ObjectStyleMacro __restrict = new ObjectStyleMacro(
|
||||
"__restrict".toCharArray(), "restrict".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private static final ObjectStyleMacro __volatile__ = new ObjectStyleMacro(
|
||||
"__volatile__".toCharArray(), "volatile".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private static final ObjectStyleMacro __const__ = new ObjectStyleMacro(
|
||||
"__const__".toCharArray(), "const".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private static final ObjectStyleMacro __const = new ObjectStyleMacro(
|
||||
"__const".toCharArray(), "const".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private static final ObjectStyleMacro __signed__ = new ObjectStyleMacro(
|
||||
"__signed__".toCharArray(), "signed".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private static final ObjectStyleMacro __cdecl = new ObjectStyleMacro(
|
||||
"__cdecl".toCharArray(), emptyCharArray); //$NON-NLS-1$
|
||||
|
||||
private static final ObjectStyleMacro __complex__ = new ObjectStyleMacro(
|
||||
"__complex__".toCharArray(), "_Complex".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private static final ObjectStyleMacro __real__ = new ObjectStyleMacro(
|
||||
"__real__".toCharArray(), "(int)".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private static final ObjectStyleMacro __imag__ = new ObjectStyleMacro(
|
||||
"__imag__".toCharArray(), "(int)".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
private static final FunctionStyleMacro __attribute__ = new FunctionStyleMacro(
|
||||
"__attribute__".toCharArray(), //$NON-NLS-1$
|
||||
emptyCharArray, new char[][] { "arg".toCharArray() }); //$NON-NLS-1$
|
||||
|
||||
private static final FunctionStyleMacro __declspec = new FunctionStyleMacro(
|
||||
"__declspec".toCharArray(), //$NON-NLS-1$
|
||||
emptyCharArray, new char[][] { "arg".toCharArray() }); //$NON-NLS-1$
|
||||
|
||||
|
||||
private static final FunctionStyleMacro __builtin_va_arg = new FunctionStyleMacro(
|
||||
"__builtin_va_arg".toCharArray(), //$NON-NLS-1$
|
||||
"*(type *)ap".toCharArray(), //$NON-NLS-1$
|
||||
new char[][] { "ap".toCharArray(), "type".toCharArray() }); //$NON-NLS-1$//$NON-NLS-2$
|
||||
|
||||
private static final FunctionStyleMacro __builtin_constant_p = new FunctionStyleMacro(
|
||||
"__builtin_constant_p".toCharArray(), //$NON-NLS-1$
|
||||
"0".toCharArray(), //$NON-NLS-1$
|
||||
new char[][] { "exp".toCharArray() }); //$NON-NLS-1$//$NON-NLS-2$
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public CharArrayObjectMap getAdditionalMacros() {
|
||||
CharArrayObjectMap realDefinitions = new CharArrayObjectMap(16);
|
||||
realDefinitions.put(__inline__.name, __inline__);
|
||||
realDefinitions.put(__cdecl.name, __cdecl);
|
||||
realDefinitions.put(__const__.name, __const__);
|
||||
realDefinitions.put(__const.name, __const);
|
||||
realDefinitions.put(__extension__.name, __extension__);
|
||||
realDefinitions.put(__attribute__.name, __attribute__);
|
||||
realDefinitions.put(__declspec.name, __declspec);
|
||||
realDefinitions.put(__restrict__.name, __restrict__);
|
||||
realDefinitions.put(__restrict.name, __restrict);
|
||||
realDefinitions.put(__volatile__.name, __volatile__);
|
||||
realDefinitions.put(__signed__.name, __signed__);
|
||||
realDefinitions.put(__complex__.name, __complex__);
|
||||
realDefinitions.put(__imag__.name, __imag__);
|
||||
realDefinitions.put(__real__.name, __real__);
|
||||
realDefinitions.put(__builtin_va_arg.name, __builtin_va_arg);
|
||||
realDefinitions.put(__builtin_constant_p.name, __builtin_constant_p);
|
||||
return realDefinitions;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,12 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import org.eclipse.cdt.core.parser.GCCKeywords;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -29,8 +34,25 @@ public class GPPScannerConfiguration extends GNUScannerConfiguration implements
|
|||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalKeywords()
|
||||
*/
|
||||
public CharArrayIntMap getAdditionalKeywords() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
CharArrayIntMap additionalCPPKeywords = new CharArrayIntMap( 8, -1 );
|
||||
additionalCPPKeywords.put( GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ );
|
||||
additionalCPPKeywords.put( GCCKeywords.cpTYPEOF, IGCCToken.t_typeof );
|
||||
additionalCPPKeywords.put( Keywords.cRESTRICT, IToken.t_restrict );
|
||||
additionalCPPKeywords.put( Keywords.c_COMPLEX, IToken.t__Complex );
|
||||
additionalCPPKeywords.put( Keywords.c_IMAGINARY, IToken.t__Imaginary );
|
||||
return additionalCPPKeywords;
|
||||
}
|
||||
|
||||
private static final ObjectStyleMacro __asm__ = new ObjectStyleMacro(
|
||||
"__asm__".toCharArray(), "asm".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros()
|
||||
*/
|
||||
public CharArrayObjectMap getAdditionalMacros() {
|
||||
CharArrayObjectMap result = super.getAdditionalMacros();
|
||||
result.put( __asm__.name, __asm__ );
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -20,8 +21,9 @@ public interface IScannerConfiguration {
|
|||
public boolean initializeMacroValuesTo1();
|
||||
public boolean support$InIdentifiers();
|
||||
public boolean supportMinAndMaxOperators();
|
||||
|
||||
public CharArrayIntMap getAdditionalKeywords();
|
||||
|
||||
public char [] supportAdditionalNumericLiteralSuffixes();
|
||||
|
||||
|
||||
public CharArrayObjectMap getAdditionalMacros();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Map;
|
|||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IMacro;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
|
@ -38,7 +39,6 @@ import org.eclipse.cdt.core.parser.ParserMode;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
@ -94,7 +94,6 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
|
||||
private ParserLanguage language;
|
||||
private IParserLogService log;
|
||||
private IScannerExtension scannerExtension;
|
||||
|
||||
private CharArrayObjectMap definitions = new CharArrayObjectMap(512);
|
||||
private String[] includePaths;
|
||||
|
@ -139,7 +138,9 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
private Iterator preIncludeFiles = EmptyIterator.EMPTY_ITERATOR;
|
||||
private boolean isInitialized = false;
|
||||
private final char [] suffixes;
|
||||
boolean support$Initializers = false;
|
||||
private final boolean support$Initializers;
|
||||
private final boolean supportMinAndMax;
|
||||
private final CharArrayIntMap additionalKeywords;
|
||||
|
||||
|
||||
public Scanner2(CodeReader reader,
|
||||
|
@ -148,10 +149,9 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
ParserMode parserMode,
|
||||
ParserLanguage language,
|
||||
IParserLogService log,
|
||||
IScannerExtension extension,
|
||||
List workingCopies, IScannerConfiguration configuration) {
|
||||
List workingCopies,
|
||||
IScannerConfiguration configuration) {
|
||||
|
||||
this.scannerExtension = extension;
|
||||
this.requestor = requestor;
|
||||
this.parserMode = parserMode;
|
||||
this.language = language;
|
||||
|
@ -164,16 +164,19 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
else
|
||||
suffixes = EMPTY_CHAR_ARRAY;
|
||||
support$Initializers = configuration.support$InIdentifiers();
|
||||
supportMinAndMax = configuration.supportMinAndMaxOperators();
|
||||
|
||||
if( language == ParserLanguage.C )
|
||||
keywords = ckeywords;
|
||||
else
|
||||
keywords = cppkeywords;
|
||||
|
||||
additionalKeywords = configuration.getAdditionalKeywords();
|
||||
|
||||
if (reader.filename != null)
|
||||
fileCache.put(reader.filename, reader);
|
||||
|
||||
setupBuiltInMacros();
|
||||
setupBuiltInMacros(configuration);
|
||||
|
||||
if (info.getDefinedSymbols() != null) {
|
||||
Map symbols = info.getDefinedSymbols();
|
||||
|
@ -859,15 +862,10 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
++bufferPos[bufferStackPos];
|
||||
return newToken(IToken.tSHIFTL );
|
||||
}
|
||||
else
|
||||
else if( buffer[pos+1] == '?' && supportMinAndMax )
|
||||
{
|
||||
char [] queryCharArray = CharArrayUtils.extract( buffer, pos, 2 );
|
||||
if( scannerExtension.isExtensionOperator( language, queryCharArray ) )
|
||||
{
|
||||
++bufferPos[ bufferStackPos ];
|
||||
return scannerExtension.createExtensionToken( this, queryCharArray );
|
||||
}
|
||||
|
||||
++bufferPos[bufferStackPos];
|
||||
return newToken( IGCCToken.tMIN, CharArrayUtils.extract( buffer, pos, 2 ) );
|
||||
}
|
||||
}
|
||||
return newToken(IToken.tLT );
|
||||
|
@ -887,15 +885,12 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
++bufferPos[bufferStackPos];
|
||||
return newToken(IToken.tSHIFTR);
|
||||
}
|
||||
else
|
||||
else if( buffer[pos+1] == '?' && supportMinAndMax )
|
||||
{
|
||||
char [] queryCharArray = CharArrayUtils.extract( buffer, pos, 2 );
|
||||
if( scannerExtension.isExtensionOperator( language, queryCharArray ) )
|
||||
{
|
||||
++bufferPos[ bufferStackPos ];
|
||||
return scannerExtension.createExtensionToken( this, queryCharArray );
|
||||
}
|
||||
++bufferPos[bufferStackPos];
|
||||
return newToken( IGCCToken.tMAX, CharArrayUtils.extract( buffer, pos, 2 ) );
|
||||
}
|
||||
|
||||
}
|
||||
return newToken(IToken.tGT );
|
||||
|
||||
|
@ -1026,14 +1021,20 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
|
||||
|
||||
char [] result = escapedNewline ? removedEscapedNewline( buffer, start, len ) : CharArrayUtils.extract( buffer, start, len );
|
||||
if( scannerExtension.isExtensionKeyword( language, result))
|
||||
return scannerExtension.createExtensionToken( this, result );
|
||||
int tokenType = escapedNewline ? keywords.get(result, 0, result.length)
|
||||
: keywords.get(buffer, start, len );
|
||||
|
||||
if (tokenType == keywords.undefined){
|
||||
tokenType = escapedNewline ? additionalKeywords.get(result, 0, result.length)
|
||||
: additionalKeywords.get(buffer, start, len );
|
||||
|
||||
if( tokenType == additionalKeywords.undefined )
|
||||
{
|
||||
result = (result != null) ? result : CharArrayUtils.extract( buffer, start, len );
|
||||
return newToken(IToken.tIDENTIFIER, result );
|
||||
}
|
||||
result = (result != null) ? result : CharArrayUtils.extract( buffer, start, len );
|
||||
return newToken(IToken.tIDENTIFIER, result );
|
||||
return newToken(tokenType, result );
|
||||
}
|
||||
return newToken(tokenType);
|
||||
}
|
||||
|
@ -3153,7 +3154,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
|
||||
private int offsetBoundary = -1;
|
||||
|
||||
protected void setupBuiltInMacros() {
|
||||
protected void setupBuiltInMacros( IScannerConfiguration config ) {
|
||||
|
||||
definitions.put(__STDC__.name, __STDC__);
|
||||
definitions.put(__FILE__.name, __FILE__);
|
||||
|
@ -3168,9 +3169,10 @@ public class Scanner2 implements IScanner, IScannerData {
|
|||
definitions.put( __STDC_HOSTED__.name, __STDC_HOSTED__ );
|
||||
definitions.put( __STDC_VERSION__.name, __STDC_VERSION__ );
|
||||
}
|
||||
|
||||
scannerExtension.setupBuiltInMacros( this );
|
||||
|
||||
|
||||
CharArrayObjectMap toAdd = config.getAdditionalMacros();
|
||||
for( int i = 0; i < toAdd.size(); ++i )
|
||||
definitions.put( toAdd.keyAt( i ), toAdd.getAt(i) );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue