diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index c73a5465641..7da0c22488f 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,6 @@ +2004-04-15 John Camelon + Added CompleteParseASTTest::testBug39697(). + 2004-04-15 Andrew Niefer added parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.testBug57791() diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java index 15eae19ae06..d6b9d8e56a3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java @@ -1511,4 +1511,43 @@ public class CompleteParseASTTest extends CompleteParseBaseTest assertEquals( f_SD_01.getName(), "f_SD_01"); assertAllReferences( 1, createTaskList( new Task( SD_01 ))); } + + public void testBug39697() throws Exception + { + Writer writer = new StringWriter(); + writer.write( "__asm__( \"CODE\" );\n" ); + writer.write( "__inline__ int foo() { return 4; }\n"); + writer.write( "__const__ int constInt;\n"); + writer.write( "__volatile__ int volInt;\n"); + writer.write( "__signed__ int signedInt;\n"); + Iterator i = parse( writer.toString() ).getDeclarations(); + IASTASMDefinition asmDefinition = (IASTASMDefinition) i.next(); + assertEquals( asmDefinition.getBody(), "CODE"); + IASTFunction foo = (IASTFunction) i.next(); + assertTrue( foo.isInline() ); + IASTVariable constInt = (IASTVariable) i.next(); + assertTrue( constInt.getAbstractDeclaration().isConst()); + IASTVariable volInt = (IASTVariable) i.next(); + assertTrue( volInt.getAbstractDeclaration().isVolatile() ); + IASTVariable signedInt = (IASTVariable) i.next(); + assertTrue( ((IASTSimpleTypeSpecifier) signedInt.getAbstractDeclaration().getTypeSpecifier()).isSigned() ); + assertFalse( i.hasNext() ); + writer = new StringWriter(); + writer.write( "int * __restrict__ resPointer1;\n"); + writer.write( "int * __restrict resPointer2;\n"); + i = parse( writer.toString(), true, ParserLanguage.C ).getDeclarations(); + int count = 0; + while( i.hasNext() ) + { + ++count; + IASTVariable resPointer = (IASTVariable) i.next(); + Iterator pOps = resPointer.getAbstractDeclaration().getPointerOperators(); + assertTrue( pOps.hasNext() ); + ASTPointerOperator op = (ASTPointerOperator) pOps.next(); + assertFalse( pOps.hasNext() ); + assertEquals( op, ASTPointerOperator.RESTRICT_POINTER ); + } + + assertEquals( count, 2 ); + } } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog-parser b/core/org.eclipse.cdt.core/parser/ChangeLog-parser index 7e3af0e43fe..814d3ee614e 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog-parser +++ b/core/org.eclipse.cdt.core/parser/ChangeLog-parser @@ -1,3 +1,6 @@ +2004-04-15 John Camelon + Partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=39697 + 2004-04-15 John Camelon Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=58175 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java index 775ffd58362..df386091d86 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/GCCScannerExtension.java @@ -18,6 +18,7 @@ import java.util.Set; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IScanner; +import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ast.IASTInclusion; import org.eclipse.cdt.core.parser.extension.IScannerExtension; @@ -30,16 +31,29 @@ import org.eclipse.cdt.internal.core.parser.util.TraceUtil; public class GCCScannerExtension implements IScannerExtension { + private static final String __CONST__ = "__const__"; //$NON-NLS-1$ + private static final String __INLINE__ = "__inline__"; //$NON-NLS-1$ + private static final String __VOLATILE__ = "__volatile__"; //$NON-NLS-1$ + private static final String __SIGNED__ = "__signed__"; //$NON-NLS-1$ + private static final String __RESTRICT = "__restrict"; //$NON-NLS-1$ + private static final String __RESTRICT__ = "__restrict__"; //$NON-NLS-1$ + private static final String __ASM__ = "__asm__"; //$NON-NLS-1$ + private IScannerData scannerData; - private static final String __ATTRIBUTE__ = "__attribute__"; - private static final String __DECLSPEC = "__declspec"; + private static final String __ATTRIBUTE__ = "__attribute__"; //$NON-NLS-1$ + private static final String __DECLSPEC = "__declspec"; //$NON-NLS-1$ private static final List EMPTY_LIST = new ArrayList(); - private static final List simpleIdentifiers; + private static final List simpleIdentifiersDeclSpec; + private static final List simpleIdentifiersAttribute; + static { - simpleIdentifiers = new ArrayList(); - simpleIdentifiers.add( "x" ); //$NON-NLS-1 + simpleIdentifiersDeclSpec = new ArrayList( 1 ); + simpleIdentifiersDeclSpec.add( "x" ); //$NON-NLS-1$ + + simpleIdentifiersAttribute = new ArrayList( 1 ); + simpleIdentifiersAttribute.add( "xyz"); //$NON-NLS-1$ } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.IScannerExtension#initializeMacroValue(java.lang.String) @@ -56,23 +70,42 @@ public class GCCScannerExtension implements IScannerExtension { public void setupBuiltInMacros(ParserLanguage language) { if( scannerData.getScanner().getDefinition( __ATTRIBUTE__) == null ) - { - scannerData.getScanner().addDefinition( __ATTRIBUTE__, new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiers, EMPTY_LIST, "" )); //$NON-NLS-1$ $NON-NLS-2$ - } + scannerData.getScanner().addDefinition( __ATTRIBUTE__, new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, EMPTY_LIST, "" )); //$NON-NLS-1$ $NON-NLS-2$ if( scannerData.getScanner().getDefinition( __DECLSPEC) == null ) - { - scannerData.getScanner().addDefinition( __DECLSPEC, new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiers, EMPTY_LIST, "" )); //$NON-NLS-1$ $NON-NLS-2$ - } - + scannerData.getScanner().addDefinition( __DECLSPEC, new FunctionMacroDescriptor( __ATTRIBUTE__, simpleIdentifiersDeclSpec, EMPTY_LIST, "" )); //$NON-NLS-1$ $NON-NLS-2$ if( language == ParserLanguage.CPP ) if( scannerData.getScanner().getDefinition( IScanner.__CPLUSPLUS ) == null ) scannerData.getScanner().addDefinition( IScanner.__CPLUSPLUS, new ObjectMacroDescriptor( IScanner.__CPLUSPLUS, "1")); //$NON-NLS-1$ + if( scannerData.getScanner().getDefinition(IScanner.__STDC_HOSTED__) == null ) scannerData.getScanner().addDefinition(IScanner.__STDC_HOSTED__, new ObjectMacroDescriptor( IScanner.__STDC_HOSTED__, "0")); //$NON-NLS-1$ if( scannerData.getScanner().getDefinition( IScanner.__STDC_VERSION__) == null ) scannerData.getScanner().addDefinition( IScanner.__STDC_VERSION__, new ObjectMacroDescriptor( IScanner.__STDC_VERSION__, "199001L")); //$NON-NLS-1$ + + setupAlternativeKeyword(__CONST__, Keywords.CONST); + setupAlternativeKeyword(__INLINE__, Keywords.INLINE); + setupAlternativeKeyword(__SIGNED__, Keywords.SIGNED); + setupAlternativeKeyword(__VOLATILE__, Keywords.VOLATILE); + if( language == ParserLanguage.C ) + { + setupAlternativeKeyword( __RESTRICT, Keywords.RESTRICT); + setupAlternativeKeyword( __RESTRICT__, Keywords.RESTRICT); + } + else + setupAlternativeKeyword( __ASM__, Keywords.ASM ); + + } + + /** + * + */ + protected void setupAlternativeKeyword(String keyword, String mapping) { + // alternate keyword forms + // TODO - make this more efficient - update TokenFactory to avoid a context push for these token to token cases + if( scannerData.getScanner().getDefinition( keyword ) == null ) + scannerData.getScanner().addDefinition( keyword, new ObjectMacroDescriptor( __CONST__, mapping )); //$NON-NLS-1$ } public void setScannerData(IScannerData scannerData) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java index 61225eb3711..fdadb7b8ad9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ObjectMacroDescriptor.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.core.parser.IToken; */ public class ObjectMacroDescriptor implements IMacroDescriptor { - private static final ArrayList EMPTY_LIST = new ArrayList(); + private static final ArrayList EMPTY_LIST = new ArrayList(0); private final String expansionSignature; private final String name; private final IToken token;