mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
org.eclipse.cdt.core
Updated Scanner to add ANSI built-in defined macros for C and C++. Updated GCCScannerExtension to add GCC specific defined macros for C++. Added factory infrastructure to allow for C/C++ dialect extensions to be added and contained. Added IASTExpressionExtension w/implementation to allow for GCC specific leniency on evaluating expressions. org.clipse.cdt.ui.tests Updated CompletionTest_SingleName_NoPrefix to include internal macro definitions.
This commit is contained in:
parent
8742531520
commit
6dbe39d0d0
26 changed files with 656 additions and 30 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2004-01-28 John Camelon
|
||||||
|
Updated Scanner to add ANSI built-in defined macros for C and C++.
|
||||||
|
Updated GCCScannerExtension to add GCC specific defined macros for C++.
|
||||||
|
Added factory infrastructure to allow for C/C++ dialect extensions to be added and contained.
|
||||||
|
Added IASTExpressionExtension w/implementation to allow for GCC specific leniency on evaluating expressions.
|
||||||
|
|
||||||
2004-01-28 Andrew Niefer
|
2004-01-28 Andrew Niefer
|
||||||
Fixed bug#50729: Visibility is incorrectly decided in inheritance
|
Fixed bug#50729: Visibility is incorrectly decided in inheritance
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ public interface IMacroDescriptor {
|
||||||
// function like - #define SYMBOL( parm1, parm2 ) TOKENS USING parms
|
// function like - #define SYMBOL( parm1, parm2 ) TOKENS USING parms
|
||||||
public static final MacroType FUNCTION_LIKE = new MacroType( 2 );
|
public static final MacroType FUNCTION_LIKE = new MacroType( 2 );
|
||||||
|
|
||||||
|
// built in internal macro who's value is dynamic
|
||||||
|
public static final MacroType INTERNAL_LIKE = new MacroType(3);
|
||||||
/**
|
/**
|
||||||
* @param enumValue
|
* @param enumValue
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,6 +10,15 @@ import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||||
*/
|
*/
|
||||||
public interface IScanner {
|
public interface IScanner {
|
||||||
|
|
||||||
|
public static final String __CPLUSPLUS = "__cplusplus";
|
||||||
|
public static final String __STDC_VERSION__ = "__STDC_VERSION__";
|
||||||
|
public static final String __STDC_HOSTED__ = "__STDC_HOSTED__";
|
||||||
|
public static final String __STDC__ = "__STDC__";
|
||||||
|
public static final String __FILE__ = "__FILE__";
|
||||||
|
public static final String __TIME__ = "__TIME__";
|
||||||
|
public static final String __DATE__ = "__DATE__";
|
||||||
|
public static final String __LINE__ = "__LINE__";
|
||||||
|
|
||||||
public static final int tPOUNDPOUND = -6;
|
public static final int tPOUNDPOUND = -6;
|
||||||
public static final int tPOUND = -7;
|
public static final int tPOUND = -7;
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,15 @@ package org.eclipse.cdt.core.parser;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||||
|
import org.eclipse.cdt.core.parser.extension.ExtensionDialect;
|
||||||
|
import org.eclipse.cdt.core.parser.extension.IParserExtensionFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.CompleteParser;
|
import org.eclipse.cdt.internal.core.parser.CompleteParser;
|
||||||
import org.eclipse.cdt.internal.core.parser.ContextualParser;
|
import org.eclipse.cdt.internal.core.parser.ContextualParser;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.ParserExtensionFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
||||||
import org.eclipse.cdt.internal.core.parser.QuickParser;
|
import org.eclipse.cdt.internal.core.parser.QuickParser;
|
||||||
import org.eclipse.cdt.internal.core.parser.StructuralParser;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.StructuralParseCallback;
|
import org.eclipse.cdt.internal.core.parser.StructuralParseCallback;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.StructuralParser;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.LineOffsetReconciler;
|
import org.eclipse.cdt.internal.core.parser.scanner.LineOffsetReconciler;
|
||||||
|
@ -32,12 +35,14 @@ import org.eclipse.cdt.internal.core.parser.scanner.Scanner;
|
||||||
*/
|
*/
|
||||||
public class ParserFactory {
|
public class ParserFactory {
|
||||||
|
|
||||||
|
private static IParserExtensionFactory extensionFactory = new ParserExtensionFactory( ExtensionDialect.GCC );
|
||||||
|
|
||||||
public static IASTFactory createASTFactory( ParserMode mode, ParserLanguage language )
|
public static IASTFactory createASTFactory( ParserMode mode, ParserLanguage language )
|
||||||
{
|
{
|
||||||
if( mode == ParserMode.QUICK_PARSE )
|
if( mode == ParserMode.QUICK_PARSE )
|
||||||
return new QuickParseASTFactory();
|
return new QuickParseASTFactory( extensionFactory.createASTExtensionFactory( ParserMode.QUICK_PARSE ) );
|
||||||
else
|
else
|
||||||
return new CompleteParseASTFactory( language, mode );
|
return new CompleteParseASTFactory( language, mode, extensionFactory.createASTExtensionFactory( ParserMode.COMPLETE_PARSE ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IParser createParser( IScanner scanner, ISourceElementRequestor callback, ParserMode mode, ParserLanguage language, IParserLogService log ) throws ParserFactoryError
|
public static IParser createParser( IScanner scanner, ISourceElementRequestor callback, ParserMode mode, ParserLanguage language, IParserLogService log ) throws ParserFactoryError
|
||||||
|
@ -68,7 +73,7 @@ public class ParserFactory {
|
||||||
IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
|
IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
|
||||||
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
||||||
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
|
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
|
||||||
IScanner s = new Scanner( input, fileName, config, ourRequestor, ourMode, language, logService );
|
IScanner s = new Scanner( input, fileName, config, ourRequestor, ourMode, language, logService, extensionFactory.createScannerExtension() );
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +86,7 @@ public class ParserFactory {
|
||||||
IParserLogService log = ( logService == null ) ? createDefaultLogService() : logService;
|
IParserLogService log = ( logService == null ) ? createDefaultLogService() : logService;
|
||||||
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode );
|
||||||
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
|
ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor );
|
||||||
IPreprocessor s = new Preprocessor( input, fileName, info, ourRequestor, ourMode, language, log );
|
IPreprocessor s = new Preprocessor( input, fileName, info, ourRequestor, ourMode, language, log, extensionFactory.createScannerExtension() );
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class ParserFactoryError extends Error {
|
||||||
public static final Kind NULL_CONFIG = new Kind( 3 );
|
public static final Kind NULL_CONFIG = new Kind( 3 );
|
||||||
public static final Kind NULL_LANGUAGE = new Kind( 4 );
|
public static final Kind NULL_LANGUAGE = new Kind( 4 );
|
||||||
public static final Kind NULL_SCANNER = new Kind( 5 );
|
public static final Kind NULL_SCANNER = new Kind( 5 );
|
||||||
|
public static final Kind BAD_DIALECT = new Kind( 6 );
|
||||||
|
|
||||||
protected Kind( int arg )
|
protected Kind( int arg )
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.core.parser.ast.extension;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
public interface IASTExpressionExtension {
|
||||||
|
|
||||||
|
public void setExpression(IASTExpression expression );
|
||||||
|
public int evaluateExpression() throws ASTExpressionEvaluationException;
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.core.parser.ast.extension;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
public interface IASTExtensionFactory {
|
||||||
|
|
||||||
|
public IASTExpressionExtension createExpressionExtension( ) throws ASTNotImplementedException;
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.core.parser.extension;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.Enum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*
|
||||||
|
* To change the template for this generated type comment go to
|
||||||
|
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||||
|
*/
|
||||||
|
public class ExtensionDialect extends Enum {
|
||||||
|
|
||||||
|
public static final ExtensionDialect GCC = new ExtensionDialect( 1 );
|
||||||
|
/**
|
||||||
|
* @param enumValue
|
||||||
|
*/
|
||||||
|
public ExtensionDialect(int enumValue) {
|
||||||
|
super(enumValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.core.parser.extension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
public interface IParserExtension {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.core.parser.extension;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
public interface IParserExtensionFactory {
|
||||||
|
|
||||||
|
public IScannerExtension createScannerExtension() throws ParserFactoryError;
|
||||||
|
public IASTExtensionFactory createASTExtensionFactory(ParserMode mode) throws ParserFactoryError;
|
||||||
|
public IParserExtension createParserExtension() throws ParserFactoryError;
|
||||||
|
}
|
|
@ -8,12 +8,23 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Rational Software - Initial API and implementation
|
* IBM Rational Software - Initial API and implementation
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.core.parser;
|
package org.eclipse.cdt.core.parser.extension;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public interface IScannerExtension {
|
public interface IScannerExtension extends Cloneable {
|
||||||
|
|
||||||
|
public void setScanner( IScanner scanner );
|
||||||
|
public Object clone( );
|
||||||
|
|
||||||
public String initializeMacroValue( String original );
|
public String initializeMacroValue( String original );
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void setupBuiltInMacros(ParserLanguage language);
|
||||||
}
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.parser;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ParserFactoryError;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory;
|
||||||
|
import org.eclipse.cdt.core.parser.extension.ExtensionDialect;
|
||||||
|
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.complete.extension.CompleteParseASTExtensionFactory;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.ast.quick.extension.QuickParseASTExtensionFactory;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner.GCCScannerExtension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
public class ParserExtensionFactory implements IParserExtensionFactory {
|
||||||
|
|
||||||
|
|
||||||
|
private final ExtensionDialect dialect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param dialect
|
||||||
|
*/
|
||||||
|
public ParserExtensionFactory(ExtensionDialect dialect) {
|
||||||
|
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#createASTExtensionFactory()
|
||||||
|
*/
|
||||||
|
public IASTExtensionFactory createASTExtensionFactory(ParserMode mode) throws ParserFactoryError {
|
||||||
|
if( dialect == ExtensionDialect.GCC )
|
||||||
|
{
|
||||||
|
if( mode == ParserMode.QUICK_PARSE )
|
||||||
|
return new QuickParseASTExtensionFactory();
|
||||||
|
return new CompleteParseASTExtensionFactory();
|
||||||
|
}
|
||||||
|
throw new ParserFactoryError( ParserFactoryError.Kind.BAD_DIALECT );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.extension.IParserExtensionFactory#createParserExtension()
|
||||||
|
*/
|
||||||
|
public IParserExtension createParserExtension() throws ParserFactoryError
|
||||||
|
{ // TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -68,6 +68,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescripto
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
|
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind;
|
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ForewardDeclaredSymbolExtension;
|
import org.eclipse.cdt.internal.core.parser.pst.ForewardDeclaredSymbolExtension;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
|
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
|
||||||
|
@ -99,6 +100,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private final static List SUBSCRIPT;
|
private final static List SUBSCRIPT;
|
||||||
|
private final IASTExtensionFactory extensionFactory;
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
SUBSCRIPT = new ArrayList();
|
SUBSCRIPT = new ArrayList();
|
||||||
|
@ -117,11 +120,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompleteParseASTFactory( ParserLanguage language, ParserMode mode )
|
public CompleteParseASTFactory( ParserLanguage language, ParserMode mode, IASTExtensionFactory factory )
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
pst = new ParserSymbolTable( language, mode );
|
pst = new ParserSymbolTable( language, mode );
|
||||||
|
extensionFactory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.ast.complete.extension;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExpressionExtension;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
public class CompleteParseASTExtensionFactory implements IASTExtensionFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public CompleteParseASTExtensionFactory() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory#createExpressionExtension(org.eclipse.cdt.core.parser.ast.IASTExpression)
|
||||||
|
*/
|
||||||
|
public IASTExpressionExtension createExpressionExtension()
|
||||||
|
throws ASTNotImplementedException {
|
||||||
|
throw new ASTNotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,18 +7,16 @@
|
||||||
package org.eclipse.cdt.internal.core.parser.ast.quick;
|
package org.eclipse.cdt.internal.core.parser.ast.quick;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
|
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
|
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExpressionExtension;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*
|
|
||||||
* To change the template for this generated type comment go to
|
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
||||||
*/
|
*/
|
||||||
public class ASTExpression implements IASTExpression {
|
public class ASTExpression implements IASTExpression {
|
||||||
|
|
||||||
|
@ -27,6 +25,7 @@ public class ASTExpression implements IASTExpression {
|
||||||
private final IASTTypeId typeId;
|
private final IASTTypeId typeId;
|
||||||
private final String literal, idExpression;
|
private final String literal, idExpression;
|
||||||
private final IASTNewExpressionDescriptor newDescriptor;
|
private final IASTNewExpressionDescriptor newDescriptor;
|
||||||
|
private final IASTExpressionExtension extension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param kind
|
* @param kind
|
||||||
|
@ -36,7 +35,7 @@ public class ASTExpression implements IASTExpression {
|
||||||
* @param typeId
|
* @param typeId
|
||||||
* @param literal
|
* @param literal
|
||||||
*/
|
*/
|
||||||
public ASTExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression third, IASTTypeId typeId, String idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
|
public ASTExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression third, IASTTypeId typeId, String idExpression, String literal, IASTNewExpressionDescriptor newDescriptor, IASTExpressionExtension extension) {
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
this.lhs =lhs;
|
this.lhs =lhs;
|
||||||
this.rhs = rhs;
|
this.rhs = rhs;
|
||||||
|
@ -45,6 +44,8 @@ public class ASTExpression implements IASTExpression {
|
||||||
this.literal = literal;
|
this.literal = literal;
|
||||||
this.newDescriptor = newDescriptor;
|
this.newDescriptor = newDescriptor;
|
||||||
this.idExpression = idExpression;
|
this.idExpression = idExpression;
|
||||||
|
this.extension = extension;
|
||||||
|
this.extension.setExpression(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -118,6 +119,7 @@ public class ASTExpression implements IASTExpression {
|
||||||
throw new ASTExpressionEvaluationException();
|
throw new ASTExpressionEvaluationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( getExpressionKind() == IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION )
|
if( getExpressionKind() == IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION )
|
||||||
return getLHSExpression().evaluateExpression();
|
return getLHSExpression().evaluateExpression();
|
||||||
// unary not
|
// unary not
|
||||||
|
@ -171,7 +173,7 @@ public class ASTExpression implements IASTExpression {
|
||||||
if( getExpressionKind() == IASTExpression.Kind.LOGICALOREXPRESSION )
|
if( getExpressionKind() == IASTExpression.Kind.LOGICALOREXPRESSION )
|
||||||
return( ( getLHSExpression().evaluateExpression() != 0 ) || ( getRHSExpression().evaluateExpression() != 0 ) ) ? 1 : 0 ;
|
return( ( getLHSExpression().evaluateExpression() != 0 ) || ( getRHSExpression().evaluateExpression() != 0 ) ) ? 1 : 0 ;
|
||||||
|
|
||||||
throw new ASTExpressionEvaluationException();
|
return extension.evaluateExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -15,6 +15,8 @@ import java.util.List;
|
||||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
|
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
|
||||||
|
@ -56,6 +58,8 @@ import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
|
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
|
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExpressionExtension;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,6 +69,14 @@ import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
|
||||||
*/
|
*/
|
||||||
public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory {
|
public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory {
|
||||||
|
|
||||||
|
private final IASTExtensionFactory extensionFactory;
|
||||||
|
|
||||||
|
public QuickParseASTFactory( IASTExtensionFactory extensionFactory )
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.extensionFactory = extensionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.ast.IASTFactory#createUsingDirective(org.eclipse.cdt.internal.core.parser.ast.IASTScope, org.eclipse.cdt.internal.core.parser.TokenDuple)
|
* @see org.eclipse.cdt.internal.core.parser.ast.IASTFactory#createUsingDirective(org.eclipse.cdt.internal.core.parser.ast.IASTScope, org.eclipse.cdt.internal.core.parser.TokenDuple)
|
||||||
*/
|
*/
|
||||||
|
@ -147,7 +159,18 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
|
||||||
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.ExpressionKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String)
|
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.ExpressionKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String)
|
||||||
*/
|
*/
|
||||||
public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
|
public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
|
||||||
return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor );
|
try {
|
||||||
|
return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor, extensionFactory.createExpressionExtension() );
|
||||||
|
} catch (ASTNotImplementedException e) {
|
||||||
|
return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor, new IASTExpressionExtension() {
|
||||||
|
|
||||||
|
public void setExpression(IASTExpression expression) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public int evaluateExpression() throws ASTExpressionEvaluationException {
|
||||||
|
throw new ASTExpressionEvaluationException();
|
||||||
|
} } );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.ast.quick.extension;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExpressionExtension;
|
||||||
|
|
||||||
|
|
||||||
|
public final class ASTExpressionExtension implements IASTExpressionExtension {
|
||||||
|
private IASTExpression expression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ASTExpression
|
||||||
|
*/
|
||||||
|
public ASTExpressionExtension() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public int evaluateExpression() throws ASTExpressionEvaluationException {
|
||||||
|
if( this.expression.getExpressionKind() == Kind.ID_EXPRESSION )
|
||||||
|
return 0;
|
||||||
|
throw new ASTExpressionEvaluationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.extension.IASTExpressionExtension#setExpression(org.eclipse.cdt.core.parser.ast.IASTExpression)
|
||||||
|
*/
|
||||||
|
public void setExpression(IASTExpression expression) {
|
||||||
|
this.expression = expression;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.ast.quick.extension;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExpressionExtension;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
public class QuickParseASTExtensionFactory implements IASTExtensionFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public QuickParseASTExtensionFactory() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory#createExpressionExtension(org.eclipse.cdt.core.parser.ast.IASTExpression)
|
||||||
|
*/
|
||||||
|
public IASTExpressionExtension createExpressionExtension() {
|
||||||
|
return new ASTExpressionExtension();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*
|
||||||
|
* To change the template for this generated type comment go to
|
||||||
|
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||||
|
*/
|
||||||
|
public class DynamicMacroDescriptor implements IMacroDescriptor {
|
||||||
|
|
||||||
|
private final List EMPTY_LIST = new ArrayList();
|
||||||
|
private final String name;
|
||||||
|
private final DynamicMacroEvaluator proxy;
|
||||||
|
|
||||||
|
public DynamicMacroDescriptor( String name, DynamicMacroEvaluator proxy )
|
||||||
|
{
|
||||||
|
this.proxy = proxy;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getMacroType()
|
||||||
|
*/
|
||||||
|
public MacroType getMacroType() {
|
||||||
|
return MacroType.INTERNAL_LIKE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getParameters()
|
||||||
|
*/
|
||||||
|
public List getParameters() {
|
||||||
|
return EMPTY_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getTokenizedExpansion()
|
||||||
|
*/
|
||||||
|
public List getTokenizedExpansion() {
|
||||||
|
return EMPTY_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getName()
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getCompleteSignature()
|
||||||
|
*/
|
||||||
|
public String getCompleteSignature() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#getExpansionSignature()
|
||||||
|
*/
|
||||||
|
public String getExpansionSignature() {
|
||||||
|
return proxy.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#compatible(org.eclipse.cdt.core.parser.IMacroDescriptor)
|
||||||
|
*/
|
||||||
|
public boolean compatible(IMacroDescriptor descriptor) {
|
||||||
|
if( getMacroType() != descriptor.getMacroType() ) return false;
|
||||||
|
if( !name.equals( descriptor.getName() )) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2000 - 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 Corporation - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
abstract class DynamicMacroEvaluator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
abstract String execute();
|
||||||
|
|
||||||
|
}
|
|
@ -10,20 +10,51 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerExtension;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
|
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public class GCCScannerExtension implements IScannerExtension {
|
public class GCCScannerExtension implements IScannerExtension {
|
||||||
|
|
||||||
|
private IScanner scanner;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.IScannerExtension#initializeMacroValue(java.lang.String)
|
* @see org.eclipse.cdt.core.parser.IScannerExtension#initializeMacroValue(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public String initializeMacroValue(String original) {
|
public String initializeMacroValue(String original) {
|
||||||
if( original == null || original.equals( "") )
|
if( original == null || original.trim().equals( "") )
|
||||||
return "1";
|
return "1";
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.IScannerExtension#setupBuiltInMacros()
|
||||||
|
*/
|
||||||
|
public void setupBuiltInMacros(ParserLanguage language) {
|
||||||
|
if( language == ParserLanguage.CPP )
|
||||||
|
if( scanner.getDefinition( IScanner.__CPLUSPLUS ) == null )
|
||||||
|
scanner.addDefinition( IScanner.__CPLUSPLUS, new ObjectMacroDescriptor( IScanner.__CPLUSPLUS, "1"));
|
||||||
|
if( scanner.getDefinition(IScanner.__STDC_HOSTED__) == null )
|
||||||
|
scanner.addDefinition(IScanner.__STDC_HOSTED__, new ObjectMacroDescriptor( IScanner.__STDC_HOSTED__, "0"));
|
||||||
|
if( scanner.getDefinition( IScanner.__STDC_VERSION__) == null )
|
||||||
|
scanner.addDefinition( IScanner.__STDC_VERSION__, new ObjectMacroDescriptor( IScanner.__STDC_VERSION__, "199001L"));
|
||||||
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#setScanner(org.eclipse.cdt.core.parser.IScanner)
|
||||||
|
*/
|
||||||
|
public void setScanner(IScanner scanner) {
|
||||||
|
this.scanner = scanner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object clone( ) {
|
||||||
|
try {
|
||||||
|
return super.clone();
|
||||||
|
} catch (CloneNotSupportedException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,14 @@ public class ObjectMacroDescriptor implements IMacroDescriptor {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final List tokenizedExpansion;
|
private final List tokenizedExpansion;
|
||||||
|
|
||||||
|
public ObjectMacroDescriptor( String name, String expansionSignature )
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.expansionSignature = expansionSignature;
|
||||||
|
fullSignature = "#define " + name + " " + expansionSignature;
|
||||||
|
tokenizedExpansion = EMPTY_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
public ObjectMacroDescriptor( String name, String signature, List tokenizedExpansion, String expansionSignature )
|
public ObjectMacroDescriptor( String name, String signature, List tokenizedExpansion, String expansionSignature )
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ScannerException;
|
import org.eclipse.cdt.core.parser.ScannerException;
|
||||||
|
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,8 +34,8 @@ public class Preprocessor extends Scanner implements IPreprocessor {
|
||||||
* @param filename
|
* @param filename
|
||||||
* @param defns
|
* @param defns
|
||||||
*/
|
*/
|
||||||
public Preprocessor(Reader reader, String filename, IScannerInfo info, ISourceElementRequestor requestor, ParserMode mode, ParserLanguage language, IParserLogService logService ) {
|
public Preprocessor(Reader reader, String filename, IScannerInfo info, ISourceElementRequestor requestor, ParserMode mode, ParserLanguage language, IParserLogService logService, IScannerExtension scannerExtension ) {
|
||||||
super(reader, filename, info, requestor, mode, language, logService );
|
super(reader, filename, info, requestor, mode, language, logService, scannerExtension );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process()
|
public void process()
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.EmptyStackException;
|
import java.util.EmptyStackException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
@ -33,7 +34,6 @@ import org.eclipse.cdt.core.parser.IParser;
|
||||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
import org.eclipse.cdt.core.parser.IProblem;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.IScannerExtension;
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
import org.eclipse.cdt.core.parser.IToken;
|
||||||
|
@ -52,6 +52,7 @@ import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||||
|
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
|
||||||
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
|
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.token.Token;
|
import org.eclipse.cdt.internal.core.parser.token.Token;
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ public class Scanner implements IScanner {
|
||||||
throw new ScannerException( problem );
|
throw new ScannerException( problem );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Scanner(Reader reader, String filename, IScannerInfo info, ISourceElementRequestor requestor, ParserMode parserMode, ParserLanguage language, IParserLogService log ) {
|
public Scanner(Reader reader, String filename, IScannerInfo info, ISourceElementRequestor requestor, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerExtension extension ) {
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.requestor = requestor;
|
this.requestor = requestor;
|
||||||
this.mode = parserMode;
|
this.mode = parserMode;
|
||||||
|
@ -104,8 +105,9 @@ public class Scanner implements IScanner {
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
this.language = language;
|
this.language = language;
|
||||||
|
|
||||||
//support GNU by default for now
|
|
||||||
scannerExtension = new GCCScannerExtension();
|
scannerExtension = extension;
|
||||||
|
scannerExtension.setScanner( this );
|
||||||
astFactory = ParserFactory.createASTFactory( mode, language );
|
astFactory = ParserFactory.createASTFactory( mode, language );
|
||||||
contextStack = new ContextStack( log );
|
contextStack = new ContextStack( log );
|
||||||
try {
|
try {
|
||||||
|
@ -162,10 +164,111 @@ public class Scanner implements IScanner {
|
||||||
else
|
else
|
||||||
log.traceLog("\t\tNo include paths specified.");
|
log.traceLog("\t\tNo include paths specified.");
|
||||||
|
|
||||||
|
setupBuiltInMacros();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupInitialContext()
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected void setupBuiltInMacros() {
|
||||||
|
|
||||||
|
scannerExtension.setupBuiltInMacros(language);
|
||||||
|
if( getDefinition(__STDC__) == null )
|
||||||
|
addDefinition( __STDC__, new ObjectMacroDescriptor( __STDC__, "1") );
|
||||||
|
|
||||||
|
if( language == ParserLanguage.C )
|
||||||
|
{
|
||||||
|
if( getDefinition(__STDC_HOSTED__) == null )
|
||||||
|
addDefinition( __STDC_HOSTED__, new ObjectMacroDescriptor( __STDC_HOSTED__, "0"));
|
||||||
|
if( getDefinition( __STDC_VERSION__) == null )
|
||||||
|
addDefinition( __STDC_VERSION__, new ObjectMacroDescriptor( __STDC_VERSION__, "199001L"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( getDefinition( __CPLUSPLUS ) == null )
|
||||||
|
addDefinition( __CPLUSPLUS, new ObjectMacroDescriptor( __CPLUSPLUS, "199711L"));
|
||||||
|
|
||||||
|
if( getDefinition(__FILE__) == null )
|
||||||
|
addDefinition( __FILE__,
|
||||||
|
new DynamicMacroDescriptor( __FILE__, new DynamicMacroEvaluator() {
|
||||||
|
public String execute() {
|
||||||
|
return contextStack.getMostRelevantFileContext().getFilename();
|
||||||
|
}
|
||||||
|
} ) );
|
||||||
|
|
||||||
|
if( getDefinition( __LINE__) == null )
|
||||||
|
addDefinition( __LINE__,
|
||||||
|
new DynamicMacroDescriptor( __LINE__, new DynamicMacroEvaluator() {
|
||||||
|
public String execute() {
|
||||||
|
return new Integer( contextStack.getCurrentLineNumber() ).toString();
|
||||||
|
}
|
||||||
|
} ) );
|
||||||
|
|
||||||
|
|
||||||
|
if( getDefinition( __DATE__ ) == null )
|
||||||
|
addDefinition( __DATE__,
|
||||||
|
new DynamicMacroDescriptor( __DATE__, new DynamicMacroEvaluator() {
|
||||||
|
|
||||||
|
public String getMonth()
|
||||||
|
{
|
||||||
|
if( Calendar.MONTH == Calendar.JANUARY ) return "Jan" ;
|
||||||
|
if( Calendar.MONTH == Calendar.FEBRUARY) return "Feb";
|
||||||
|
if( Calendar.MONTH == Calendar.MARCH) return "Mar";
|
||||||
|
if( Calendar.MONTH == Calendar.APRIL) return "Apr";
|
||||||
|
if( Calendar.MONTH == Calendar.MAY) return "May";
|
||||||
|
if( Calendar.MONTH == Calendar.JUNE) return "Jun";
|
||||||
|
if( Calendar.MONTH == Calendar.JULY) return "Jul";
|
||||||
|
if( Calendar.MONTH == Calendar.AUGUST) return "Aug";
|
||||||
|
if( Calendar.MONTH == Calendar.SEPTEMBER) return "Sep";
|
||||||
|
if( Calendar.MONTH == Calendar.OCTOBER) return "Oct";
|
||||||
|
if( Calendar.MONTH == Calendar.NOVEMBER) return "Nov";
|
||||||
|
if( Calendar.MONTH == Calendar.DECEMBER) return "Dec";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String execute() {
|
||||||
|
StringBuffer result = new StringBuffer();
|
||||||
|
result.append( getMonth() );
|
||||||
|
result.append(" ");
|
||||||
|
if( Calendar.DAY_OF_MONTH < 10 )
|
||||||
|
result.append(" ");
|
||||||
|
result.append(Calendar.DAY_OF_MONTH);
|
||||||
|
result.append(" ");
|
||||||
|
result.append( Calendar.YEAR );
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
} ) );
|
||||||
|
|
||||||
|
if( getDefinition( __TIME__) == null )
|
||||||
|
addDefinition( __TIME__,
|
||||||
|
new DynamicMacroDescriptor( __TIME__, new DynamicMacroEvaluator() {
|
||||||
|
|
||||||
|
|
||||||
|
public String execute() {
|
||||||
|
StringBuffer result = new StringBuffer();
|
||||||
|
if( Calendar.AM_PM == Calendar.PM )
|
||||||
|
result.append( Calendar.HOUR + 12 );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( Calendar.HOUR < 10 )
|
||||||
|
result.append( '0');
|
||||||
|
result.append(Calendar.HOUR);
|
||||||
|
}
|
||||||
|
result.append(':');
|
||||||
|
if( Calendar.MINUTE < 10 )
|
||||||
|
result.append( '0');
|
||||||
|
result.append(Calendar.MINUTE);
|
||||||
|
result.append(':');
|
||||||
|
if( Calendar.SECOND < 10 )
|
||||||
|
result.append( '0');
|
||||||
|
result.append(Calendar.SECOND);
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
} ) );
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupInitialContext()
|
||||||
{
|
{
|
||||||
String resolvedFilename = filename == null ? TEXT : filename;
|
String resolvedFilename = filename == null ? TEXT : filename;
|
||||||
IScannerContext context = null;
|
IScannerContext context = null;
|
||||||
|
@ -2158,7 +2261,7 @@ public class Scanner implements IScanner {
|
||||||
new ScannerInfo(definitions, originalConfig.getIncludePaths()),
|
new ScannerInfo(definitions, originalConfig.getIncludePaths()),
|
||||||
new NullSourceElementRequestor(),
|
new NullSourceElementRequestor(),
|
||||||
mode,
|
mode,
|
||||||
language, nullLogService );
|
language, nullLogService, (IScannerExtension)(scannerExtension.clone()) );
|
||||||
helperScanner.setForInclusion( true );
|
helperScanner.setForInclusion( true );
|
||||||
IToken t = null;
|
IToken t = null;
|
||||||
|
|
||||||
|
@ -2563,7 +2666,7 @@ public class Scanner implements IScanner {
|
||||||
|
|
||||||
protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException {
|
protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException {
|
||||||
|
|
||||||
Scanner tokenizer = new Scanner(new StringReader(params), TEXT, new ScannerInfo( definitions, originalConfig.getIncludePaths() ), new NullSourceElementRequestor(), mode, language, nullLogService );
|
Scanner tokenizer = new Scanner(new StringReader(params), TEXT, new ScannerInfo( definitions, originalConfig.getIncludePaths() ), new NullSourceElementRequestor(), mode, language, nullLogService, (IScannerExtension)scannerExtension.clone() );
|
||||||
tokenizer.setThrowExceptionOnBadCharacterRead(false);
|
tokenizer.setThrowExceptionOnBadCharacterRead(false);
|
||||||
Vector parameterValues = new Vector();
|
Vector parameterValues = new Vector();
|
||||||
Token t = null;
|
Token t = null;
|
||||||
|
@ -2646,7 +2749,7 @@ public class Scanner implements IScanner {
|
||||||
{
|
{
|
||||||
// All the tokens generated by the macro expansion
|
// All the tokens generated by the macro expansion
|
||||||
// will have dimensions (offset and length) equal to the expanding symbol.
|
// will have dimensions (offset and length) equal to the expanding symbol.
|
||||||
if ( expansion.getMacroType() == MacroType.OBJECT_LIKE ) {
|
if ( expansion.getMacroType() == MacroType.OBJECT_LIKE || expansion.getMacroType() == MacroType.INTERNAL_LIKE ) {
|
||||||
String replacementValue = expansion.getExpansionSignature();
|
String replacementValue = expansion.getExpansionSignature();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -2814,7 +2917,8 @@ public class Scanner implements IScanner {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
StringBuffer logMessage = new StringBuffer( "Unexpected type of MacroDescriptor stored in definitions table: " );
|
StringBuffer logMessage = new StringBuffer( "Unexpected type of MacroDescriptor stored in definitions table: " );
|
||||||
logMessage.append( expansion.getMacroType() );
|
logMessage.append( expansion.getMacroType() );
|
||||||
log.traceLog( logMessage.toString() );
|
log.traceLog( logMessage.toString() );
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
2004-01-28 John Camelon
|
||||||
|
Updated CompletionTest_SingleName_NoPrefix to include internal macro definitions.
|
||||||
|
|
||||||
2004-01-27 John Camelon
|
2004-01-27 John Camelon
|
||||||
Updated COMPLETION_PARSE clients to use SINGLE_NAME_REFERENCE rather than STATEMENT_START.
|
Updated COMPLETION_PARSE clients to use SINGLE_NAME_REFERENCE rather than STATEMENT_START.
|
||||||
Renamed and updated CompletionTest_StatementStart_NoPrefix to CompletionTest_SingleName_Method_NoPrefix.
|
Renamed and updated CompletionTest_StatementStart_NoPrefix to CompletionTest_SingleName_Method_NoPrefix.
|
||||||
|
|
|
@ -54,6 +54,14 @@ public class CompletionTest_SingleName_NoPrefix extends CompletionProposalsBase
|
||||||
"xFirstEnum",
|
"xFirstEnum",
|
||||||
"xSecondEnum",
|
"xSecondEnum",
|
||||||
"xThirdEnum",
|
"xThirdEnum",
|
||||||
|
"__cplusplus",
|
||||||
|
"__DATE__",
|
||||||
|
"__FILE__",
|
||||||
|
"__LINE__",
|
||||||
|
"__STDC__",
|
||||||
|
"__STDC_HOSTED__",
|
||||||
|
"__STDC_VERSION__",
|
||||||
|
"__TIME__",
|
||||||
"AMacro(x)",
|
"AMacro(x)",
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
"XMacro(x,y)"
|
"XMacro(x,y)"
|
||||||
|
|
Loading…
Add table
Reference in a new issue