1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00
Fixed Bug 39542 : Parser fails on 'struct' parameter types 
	Fixed Bug 39549 : Designated initializers are not supported (ANSI C99) 
	Fixed Bug 39551 : Complex and imaginary numbers are not supported (ANSI C99) 

TESTS
	Moved testBug39542() from ASTFailedTests to QuickParseASTTests.
	Moved testBug39549() from ASTFailedTests to QuickParseASTTests.
	Added testCDesignatedInitializers() to CompleteParseASTTests.
	Moved testBug39551A() from ASTFailedTests to QuickParseASTTests. 
	Moved testBug39551B() from ASTFailedTests to QuickParseASTTests. 
	Added testCBool() to QuickParseASTTests.  
	Added testBug39551A(), testBug39551B() and testCBool to CompleteParseTests.
This commit is contained in:
John Camelon 2003-10-24 17:49:22 +00:00
parent 303306e897
commit 5be9f16c62
33 changed files with 889 additions and 184 deletions

View file

@ -1,3 +1,12 @@
2003-10-24 John Camelon
Moved testBug39542() from ASTFailedTests to QuickParseASTTests.
Moved testBug39549() from ASTFailedTests to QuickParseASTTests.
Added testCDesignatedInitializers() to CompleteParseASTTests.
Moved testBug39551A() from ASTFailedTests to QuickParseASTTests.
Moved testBug39551B() from ASTFailedTests to QuickParseASTTests.
Added testCBool() to QuickParseASTTests.
Added testBug39551A(), testBug39551B() and testCBool to CompleteParseTests.
2003-10-22 Hoda Amer
Added offset checking in CModelElementsTest

View file

@ -35,30 +35,6 @@ public class ASTFailedTests extends BaseASTTest
{
assertCodeFailsParse("FUNCTION_MACRO( 1, a )\n int i;");
}
public void testBug39542() throws Exception
{
assertCodeFailsParse("void f(int a, struct {int b[a];} c) {}");
}
//Here starts C99-specific section
public void testBug39549() throws Exception
{
assertCodeFailsParse("struct X x = { .b = 40, .z = {} };");
}
public void testBug39551A() throws Exception
{
IASTFunction function = (IASTFunction)parse("extern float _Complex conjf (float _Complex);").getDeclarations().next();
assertEquals( function.getName(), "conjf");
}
public void testBug39551B() throws Exception
{
IASTVariable variable = (IASTVariable)parse("_Imaginary double id = 99.99 * __I__;").getDeclarations().next();
assertEquals( variable.getName(), "id");
}
public void testBug39554() throws Exception
{

View file

@ -72,11 +72,16 @@ public class BaseASTTest extends TestCase
}
protected IASTDeclaration assertSoleDeclaration( String code ) throws ParserException
{
return assertSoleDeclaration( code, ParserLanguage.CPP );
}
protected IASTDeclaration assertSoleDeclaration( String code, ParserLanguage language ) throws ParserException
{
Iterator declarationIter = null;
try
{
declarationIter = parse(code).getDeclarations();
declarationIter = parse(code, true, true, language).getDeclarations();
}
catch (ASTNotImplementedException e1)
{
@ -90,10 +95,15 @@ public class BaseASTTest extends TestCase
return returnValue;
}
public void assertCodeFailsParse(String code) {
public void assertCodeFailsParse( String code )
{
assertCodeFailsParse( code, true, true, ParserLanguage.CPP );
}
public void assertCodeFailsParse(String code, boolean quick, boolean throwOnError, ParserLanguage CPP ) {
boolean testPassed = false;
try {
parse(code);
parse(code, quick, throwOnError, CPP );
testPassed = true;
fail( "We should not reach this point");
} catch (Throwable e) {

View file

@ -14,6 +14,7 @@ import java.io.StringWriter;
import java.io.Writer;
import java.util.Iterator;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
@ -915,5 +916,59 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
IASTMethod constructor = (IASTMethod) i.next();
assertEquals( constructor.getName(), "B" );
assertTrue( constructor.previouslyDeclared() );
}
}
public void testCDesignatedInitializers() throws Exception
{
StringBuffer buffer = new StringBuffer();
buffer.append( "struct Inner { int a,b,c; };");
buffer.append( "struct A { int x; int y[]; struct Inner innerArray[]; int z []; };");
buffer.append( "struct A myA = { .x = 4, .y[3] = 4, .y[4] = 3, .innerArray[0].a = 3, .innerArray[1].b = 5, .innerArray[2].c=6, .z = { 1,4,5} };");
Iterator i = parse( buffer.toString(), true, ParserLanguage.C ).getDeclarations();
IASTClassSpecifier Inner = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
Iterator members = getDeclarations(Inner);
IASTField a = (IASTField)members.next();
IASTField b = (IASTField)members.next();
IASTField c = (IASTField)members.next();
assertFalse( members.hasNext());
IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
members = getDeclarations( A );
IASTField x = (IASTField)members.next();
IASTField y = (IASTField)members.next();
IASTField innerArray = (IASTField)members.next();
IASTField z = (IASTField)members.next();
assertFalse( members.hasNext() );
IASTVariable myA = (IASTVariable)i.next();
assertFalse( i.hasNext() );
assertAllReferences( 12, createTaskList( new Task( A ),
new Task( x ),
new Task( y, 2 ),
new Task( Inner ),
new Task( innerArray, 3),
new Task( a ),
new Task( b ),
new Task( c ),
new Task( z ) ) );
}
public void testBug39551A() throws Exception
{
IASTFunction function = (IASTFunction)parse("extern float _Complex conjf (float _Complex);", true, ParserLanguage.C).getDeclarations().next();
assertEquals( function.getName(), "conjf");
assertTrue( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).isComplex() );
}
public void testBug39551B() throws Exception
{
IASTVariable variable = (IASTVariable)parse("_Imaginary double id = 99.99 * __I__;", true, ParserLanguage.C).getDeclarations().next();
assertEquals( variable.getName(), "id");
assertTrue( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).isImaginary() );
}
public void testCBool() throws Exception
{
IASTVariable variable = (IASTVariable)parse( "_Bool x;", true, ParserLanguage.C ).getDeclarations().next();
assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type._BOOL );
}
}

View file

@ -669,14 +669,20 @@ public class CompleteParseBaseTest extends TestCase
protected IASTScope parse( String code ) throws ParserException
{
return parse( code, true );
return parse( code, true, ParserLanguage.CPP );
}
protected IASTScope parse(String code, boolean throwOnError) throws ParserException
protected IASTScope parse( String code, boolean throwOnError ) throws ParserException
{
return parse( code, throwOnError, ParserLanguage.CPP );
}
protected IASTScope parse(String code, boolean throwOnError, ParserLanguage language) throws ParserException
{
callback = new FullParseCallback();
IParser parser = ParserFactory.createParser(
ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(),
ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, callback ), callback, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP
ParserMode.COMPLETE_PARSE, language, callback ), callback, ParserMode.COMPLETE_PARSE, language
);
if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE");
return callback.getCompilationUnit();
@ -836,6 +842,27 @@ public class CompleteParseBaseTest extends TestCase
return result;
}
protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7)
{
List result = createTaskList( task, task2, task3, task4, task5, task6 );
result.add( task7 );
return result;
}
protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7, Task task8 )
{
List result = createTaskList( task, task2, task3, task4, task5, task6, task7 );
result.add( task8 );
return result;
}
protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7, Task task8, Task task9 )
{
List result = createTaskList( task, task2, task3, task4, task5, task6, task7, task8 );
result.add( task9 );
return result;
}
public boolean qualifiedNamesEquals( String [] fromAST, String [] theTruth)
{
if( fromAST == null || theTruth == null ) return false;

View file

@ -1975,5 +1975,37 @@ public class QuickParseASTTests extends BaseASTTest
parse("template<class E> class X { inline X<E>(int); };");
}
public void testBug39542() throws Exception
{
parse("void f(int a, struct {int b[a];} c) {}");
}
//Here starts C99-specific section
public void testBug39549() throws Exception
{
parse("struct X x = { .b = 40, .z = { sizeof(X), 42 }, .t[3] = 2, .t.f[3].x = A * B };", true, true, ParserLanguage.C);
// with trailing commas
parse("struct X x = { .b = 40, .z = { sizeof(X), 42,}, .t[3] = 2, .t.f[3].x = A * B ,};", true, true, ParserLanguage.C);
}
public void testBug39551A() throws Exception
{
IASTFunction function = (IASTFunction)parse("extern float _Complex conjf (float _Complex);", true, true, ParserLanguage.C).getDeclarations().next();
assertEquals( function.getName(), "conjf");
assertTrue( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).isComplex() );
}
public void testBug39551B() throws Exception
{
IASTVariable variable = (IASTVariable)parse("_Imaginary double id = 99.99 * __I__;", true, true, ParserLanguage.C).getDeclarations().next();
assertEquals( variable.getName(), "id");
assertTrue( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).isImaginary() );
}
public void testCBool() throws Exception
{
IASTVariable variable = (IASTVariable)assertSoleDeclaration( "_Bool x;", ParserLanguage.C );
assertSimpleType( variable, IASTSimpleTypeSpecifier.Type._BOOL );
}
}

View file

@ -1,3 +1,8 @@
2003-10-22 John Camelon
Fixed Bug 39542 : Parser fails on 'struct' parameter types
Fixed Bug 39549 : Designated initializers are not supported (ANSI C99)
Fixed Bug 39551 : Complex and imaginary numbers are not supported (ANSI C99)
2003-10-21 John Camelon
Fixed Bug 40007 : Parser reports success when it fails
Fixed Bug 44305 : Scanner/preprocessor fails on conditionals using hexidecimal

View file

@ -10,6 +10,7 @@
***********************************************************************/
package org.eclipse.cdt.core.parser;
import java.util.Iterator;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
/**
* @author jcamelon

View file

@ -0,0 +1,40 @@
/**********************************************************************
* 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.ast;
import org.eclipse.cdt.core.parser.Enum;
/**
* @author jcamelon
*
*/
public interface IASTDesignator
{
public static class DesignatorKind extends Enum
{
public static final DesignatorKind FIELD = new DesignatorKind( 0 );
public static final DesignatorKind SUBSCRIPT = new DesignatorKind( 1 );
/**
* @param enumValue
*/
protected DesignatorKind(int enumValue)
{
super(enumValue);
// TODO Auto-generated constructor stub
}
}
public DesignatorKind getKind();
public IASTExpression arraySubscriptExpression();
public String fieldName();
public int fieldOffset();
}

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.core.parser.ast;
import java.util.List;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
@ -24,32 +25,32 @@ public interface IASTFactory
String name,
int startingOffset,
int nameOffset,
int nameEndOffset, int endingOffset) throws Exception;
int nameEndOffset, int endingOffset) ;
public IASTInclusion createInclusion(
String name,
String fileName,
boolean local,
int startingOffset,
int nameOffset,
int nameEndOffset, int endingOffset) throws Exception;
int nameEndOffset, int endingOffset) ;
public IASTUsingDirective createUsingDirective(
IASTScope scope,
ITokenDuple duple, int startingOffset, int endingOffset)
throws ASTSemanticException, Exception;
throws ASTSemanticException;
public IASTUsingDeclaration createUsingDeclaration(
IASTScope scope,
boolean isTypeName,
ITokenDuple name, int startingOffset, int endingOffset) throws ASTSemanticException, Exception;
ITokenDuple name, int startingOffset, int endingOffset) throws ASTSemanticException;
public IASTASMDefinition createASMDefinition(
IASTScope scope,
String assembly,
int first,
int last)throws Exception;
int last);
public IASTNamespaceDefinition createNamespaceDefinition(
IASTScope scope,
String identifier,
int startingOffset,
int nameOffset, int nameEndOffset) throws ASTSemanticException, Exception;
int nameOffset, int nameEndOffset) throws ASTSemanticException;
public IASTNamespaceAlias createNamespaceAlias(
IASTScope scope,
@ -57,12 +58,12 @@ public interface IASTFactory
ITokenDuple alias,
int startingOffset,
int nameOffset,
int nameEndOffset, int endOffset ) throws ASTSemanticException, Exception;
int nameEndOffset, int endOffset ) throws ASTSemanticException;
public IASTCompilationUnit createCompilationUnit() throws Exception;
public IASTCompilationUnit createCompilationUnit() ;
public IASTLinkageSpecification createLinkageSpecification(
IASTScope scope,
String spec, int startingOffset) throws Exception;
String spec, int startingOffset) ;
public IASTClassSpecifier createClassSpecifier(
IASTScope scope,
ITokenDuple name,
@ -70,7 +71,7 @@ public interface IASTFactory
ClassNameType type,
ASTAccessVisibility access,
int startingOffset,
int nameOffset, int nameEndOffset) throws ASTSemanticException, Exception;
int nameOffset, int nameEndOffset) throws ASTSemanticException;
/**
* @param astClassSpec
* @param isVirtual
@ -81,21 +82,21 @@ public interface IASTFactory
IASTClassSpecifier astClassSpec,
boolean isVirtual,
ASTAccessVisibility visibility,
ITokenDuple parentClassName) throws ASTSemanticException, Exception;
ITokenDuple parentClassName) throws ASTSemanticException;
public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier(
IASTScope scope,
ASTClassKind elaboratedClassKind,
ITokenDuple typeName,
int startingOffset, int endOffset, boolean isForewardDecl) throws ASTSemanticException, Exception;
int startingOffset, int endOffset, boolean isForewardDecl) throws ASTSemanticException;
public IASTEnumerationSpecifier createEnumerationSpecifier(
IASTScope scope,
String name,
int startingOffset, int nameOffset, int nameEndOffset) throws ASTSemanticException, Exception;
int startingOffset, int nameOffset, int nameEndOffset) throws ASTSemanticException;
public void addEnumerator(
IASTEnumerationSpecifier enumeration,
String string,
int startingOffset,
int nameOffset, int nameEndOffset, int endingOffset, IASTExpression initialValue)throws ASTSemanticException, Exception;
int nameOffset, int nameEndOffset, int endingOffset, IASTExpression initialValue)throws ASTSemanticException;
public IASTExpression createExpression(
IASTScope scope,
IASTExpression.Kind kind,
@ -103,17 +104,17 @@ public interface IASTFactory
IASTExpression rhs,
IASTExpression thirdExpression,
IASTTypeId typeId,
ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException, Exception;
public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions)throws Exception;
ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException;
public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions);
public IASTInitializerClause createInitializerClause(
IASTScope scope,
IASTInitializerClause.Kind kind,
IASTExpression assignmentExpression,
List initializerClauses) throws Exception;
public IASTExceptionSpecification createExceptionSpecification(IASTScope scope, List typeIds) throws ASTSemanticException, Exception;
IASTExpression assignmentExpression, List initializerClauses, List designators) ;
public IASTExceptionSpecification createExceptionSpecification(IASTScope scope, List typeIds) throws ASTSemanticException;
/**
* @param exp
*/
public IASTArrayModifier createArrayModifier(IASTExpression exp) throws Exception;
public IASTArrayModifier createArrayModifier(IASTExpression exp) ;
/**
* @param duple
* @param expressionList
@ -121,7 +122,7 @@ public interface IASTFactory
*/
public IASTConstructorMemberInitializer createConstructorMemberInitializer(
IASTScope scope,
ITokenDuple duple, IASTExpression expressionList) throws ASTSemanticException, Exception;
ITokenDuple duple, IASTExpression expressionList) throws ASTSemanticException;
public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(
IASTScope scope,
IASTSimpleTypeSpecifier.Type kind,
@ -129,7 +130,7 @@ public interface IASTFactory
boolean isShort,
boolean isLong,
boolean isSigned,
boolean isUnsigned, boolean isTypename) throws ASTSemanticException, Exception;
boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary) throws ASTSemanticException;
public IASTFunction createFunction(
IASTScope scope,
ITokenDuple name,
@ -147,12 +148,12 @@ public interface IASTFactory
boolean isVolatile,
boolean isVirtual,
boolean isExplicit,
boolean isPureVirtual, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock ) throws ASTSemanticException, Exception;
boolean isPureVirtual, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock ) throws ASTSemanticException;
public IASTAbstractDeclaration createAbstractDeclaration(
boolean isConst,
boolean isVolatile,
IASTTypeSpecifier typeSpecifier,
List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOperator)throws Exception;
List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOperator);
public IASTMethod createMethod(
IASTScope scope,
String name,
@ -170,28 +171,30 @@ public interface IASTFactory
boolean isVolatile,
boolean isVirtual,
boolean isExplicit,
boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock) throws ASTSemanticException, Exception;
boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock) throws ASTSemanticException;
public IASTVariable createVariable(IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression,
IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset, int nameEndOffset, IASTExpression constructorExpression ) throws ASTSemanticException, Exception;
IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset, int nameEndOffset, IASTExpression constructorExpression ) throws ASTSemanticException;
public IASTField createField( IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset, int nameEndOffset, IASTExpression constructorExpression, ASTAccessVisibility visibility) throws ASTSemanticException, Exception;
public IASTParameterDeclaration createParameterDeclaration( boolean isConst, boolean isVolatile, IASTTypeSpecifier getTypeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOp, String parameterName, IASTInitializerClause initializerClause, int startingOffset, int nameOffset, int nameEndOffset, int endingOffset ) throws Exception;
public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset ) throws Exception;
public IASTField createField( IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset, int nameEndOffset, IASTExpression constructorExpression, ASTAccessVisibility visibility) throws ASTSemanticException;
public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms ) throws Exception;
public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier );
public IASTParameterDeclaration createParameterDeclaration( boolean isConst, boolean isVolatile, IASTTypeSpecifier getTypeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOp, String parameterName, IASTInitializerClause initializerClause, int startingOffset, int nameOffset, int nameEndOffset, int endingOffset ) ;
public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset ) ;
public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset)throws Exception;
public IASTTemplateSpecialization createTemplateSpecialization(IASTScope scope, int startingOffset)throws Exception;
public IASTTypedefDeclaration createTypedef( IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset, int nameEndOffset ) throws ASTSemanticException, Exception;
public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms ) ;
public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration( IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate template, int startingOffset, int endingOffset)throws Exception;
public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset);
public boolean queryIsTypeName( IASTScope scope, ITokenDuple nameInQuestion ) throws Exception;
public IASTTemplateSpecialization createTemplateSpecialization(IASTScope scope, int startingOffset);
public IASTTypedefDeclaration createTypedef( IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset, int nameEndOffset ) throws ASTSemanticException;
public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration( IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate template, int startingOffset, int endingOffset);
public boolean queryIsTypeName( IASTScope scope, ITokenDuple nameInQuestion ) ;
static final String DOUBLE_COLON = "::";
static final String TELTA = "~";
@ -199,14 +202,14 @@ public interface IASTFactory
* @param scope
* @return
*/
public IASTCodeScope createNewCodeBlock(IASTScope scope)throws Exception;
public IASTCodeScope createNewCodeBlock(IASTScope scope);
public IASTTypeId createTypeId( IASTScope scope, IASTSimpleTypeSpecifier.Type kind, boolean isConst, boolean isVolatile, boolean isShort,
boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods ) throws ASTSemanticException, Exception;
boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods ) throws ASTSemanticException;
/**
* @param astClassSpecifier
*/
public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier) throws Exception;
public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier);
}

View file

@ -22,9 +22,11 @@ public interface IASTInitializerClause extends ISourceElementCallbackDelegate{
public class Kind extends Enum
{
public static final Kind ASSIGNMENT_EXPRESSION = new Kind( 1 );
public static final Kind ASSIGNMENT_EXPRESSION = new Kind( 1 );
public static final Kind INITIALIZER_LIST = new Kind( 2 );
public static final Kind EMPTY = new Kind( 3 );
public static final Kind DESIGNATED_INITIALIZER_LIST = new Kind( 4 );
public static final Kind DESIGNATED_ASSIGNMENT_EXPRESSION = new Kind( 5 );
/**
* @param enumValue
@ -37,5 +39,9 @@ public interface IASTInitializerClause extends ISourceElementCallbackDelegate{
public Kind getKind();
public Iterator getInitializers();
public IASTExpression getAssigmentExpression();
public Iterator getDesignators();
public void setOwnerVariableDeclaration( IASTVariable declaration );
public IASTVariable getOwnerVariableDeclaration();
}

View file

@ -20,7 +20,7 @@ public interface IASTSimpleTypeSpecifier extends IASTTypeSpecifier
{
public static class Type extends Enum
{
public static final Type UNSPECIFIED = new Type( 1 );
public static final Type UNSPECIFIED = new Type( 1 );
public static final Type CHAR = new Type( 1 );
public static final Type WCHAR_T = new Type( 2 );
public static final Type BOOL = new Type( 3 );
@ -30,7 +30,7 @@ public interface IASTSimpleTypeSpecifier extends IASTTypeSpecifier
public static final Type VOID = new Type( 7 );
public static final Type CLASS_OR_TYPENAME = new Type( 8 );
public static final Type TEMPLATE = new Type( 9 );
public static final Type _BOOL = new Type( 10 );
/**
* @param enumValue
*/
@ -49,6 +49,8 @@ public interface IASTSimpleTypeSpecifier extends IASTTypeSpecifier
public boolean isSigned();
public boolean isUnsigned();
public boolean isTypename();
public boolean isComplex();
public boolean isImaginary();
public IASTTypeSpecifier getTypeSpecifier() throws ASTNotImplementedException;
}

View file

@ -37,6 +37,7 @@ import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
*/
public class DeclarationWrapper implements IDeclaratorOwner
{
private boolean imaginary, complex;
private boolean restrict;
private int endOffset;
private ITokenDuple name;
@ -773,5 +774,35 @@ public class DeclarationWrapper implements IDeclaratorOwner
{
return restrict;
}
/**
* @param b
*/
public void setImaginary(boolean b)
{
imaginary = b;
}
/**
* @return
*/
public boolean isComplex()
{
return complex;
}
/**
* @return
*/
public boolean isImaginary()
{
return imaginary;
}
/**
* @param b
*/
public void setComplex(boolean b)
{
complex = b;
}
}

View file

@ -38,6 +38,7 @@ import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTDesignator;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
@ -72,6 +73,7 @@ import org.eclipse.cdt.internal.core.model.Util;
*/
public class Parser implements IParser
{
private static final List EMPTY_LIST = new ArrayList();
private static int DEFAULT_OFFSET = -1;
// sentinel initial value for offsets
private int firstErrorOffset = DEFAULT_OFFSET;
@ -943,7 +945,7 @@ public class Parser implements IParser
sdw.isShort(),
sdw.isLong(),
sdw.isSigned(),
sdw.isUnsigned(), sdw.isTypeNamed()));
sdw.isUnsigned(), sdw.isTypeNamed(), sdw.isComplex(), sdw.isImaginary()));
}
catch (Exception e1)
{
@ -1182,7 +1184,7 @@ public class Parser implements IParser
sdw.isShort(),
sdw.isLong(),
sdw.isSigned(),
sdw.isUnsigned(), sdw.isTypeNamed()));
sdw.isUnsigned(), sdw.isTypeNamed(), sdw.isComplex(), sdw.isImaginary()));
}
catch (ASTSemanticException e)
{
@ -1455,6 +1457,20 @@ public class Parser implements IParser
sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT);
sdw.setLong(true);
break;
case IToken.t__Complex :
consume( IToken.t__Complex );
if (typeNameBegin == null)
typeNameBegin = LA(1);
typeNameEnd = LA(1);
sdw.setComplex( true );
break;
case IToken.t__Imaginary :
consume( IToken.t__Imaginary );
if (typeNameBegin == null)
typeNameBegin = LA(1);
typeNameEnd = LA(1);
sdw.setImaginary( true );
break;
case IToken.t_char :
if (typeNameBegin == null)
typeNameBegin = LA(1);
@ -1477,13 +1493,20 @@ public class Parser implements IParser
callbackSimpleDeclToken(flags);
sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.BOOL);
break;
case IToken.t__Bool:
if (typeNameBegin == null)
typeNameBegin = LA(1);
typeNameEnd = LA(1);
callbackSimpleDeclToken(flags);
sdw.setSimpleType(IASTSimpleTypeSpecifier.Type._BOOL);
break;
case IToken.t_int :
if (typeNameBegin == null)
typeNameBegin = LA(1);
typeNameEnd = LA(1);
callbackSimpleDeclToken(flags);
sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT);
break;
break;
case IToken.t_float :
if (typeNameBegin == null)
typeNameBegin = LA(1);
@ -1523,10 +1546,8 @@ public class Parser implements IParser
break;
case IToken.tCOLONCOLON :
consume(IToken.tCOLONCOLON);
// handle nested later:
case IToken.tIDENTIFIER :
// TODO - Kludgy way to handle constructors/destructors
// handle nested later:
if (flags.haveEncounteredRawType())
{
if (typeNameBegin != null)
@ -1564,46 +1585,28 @@ public class Parser implements IParser
case IToken.t_class :
case IToken.t_struct :
case IToken.t_union :
if (!parm )
try
{
try
{
classSpecifier(sdw);
flags.setEncounteredTypename(true);
break;
}
catch (Backtrack bt)
{
elaboratedTypeSpecifier(sdw);
flags.setEncounteredTypename(true);
break;
}
classSpecifier(sdw);
flags.setEncounteredTypename(true);
break;
}
else
catch (Backtrack bt)
{
elaboratedTypeSpecifier(sdw);
flags.setEncounteredTypename(true);
break;
}
case IToken.t_enum :
if (!parm )
try
{
try
{
enumSpecifier(sdw);
flags.setEncounteredTypename(true);
break;
}
catch (Backtrack bt)
{
// this is an elaborated class specifier
elaboratedTypeSpecifier(sdw);
flags.setEncounteredTypename(true);
break;
}
enumSpecifier(sdw);
flags.setEncounteredTypename(true);
break;
}
else
catch (Backtrack bt)
{
// this is an elaborated class specifier
elaboratedTypeSpecifier(sdw);
flags.setEncounteredTypename(true);
break;
@ -1883,31 +1886,119 @@ public class Parser implements IParser
throws Backtrack
{
Declarator d = declarator(sdw, sdw.getScope(), strategy );
// handle = initializerClause
if( language == ParserLanguage.CPP )
optionalCPPInitializer(d);
else if( language == ParserLanguage.C )
optionalCInitializer(d);
sdw.addDeclarator(d);
return d;
}
protected void optionalCPPInitializer(Declarator d)
throws EndOfFile, Backtrack
{
// handle initializer
if (LT(1) == IToken.tASSIGN)
{
consume(IToken.tASSIGN);
d.setInitializerClause(initializerClause(sdw.getScope()));
d.setInitializerClause(initializerClause(d.getDeclarationWrapper().getScope()));
}
else if (LT(1) == IToken.tLPAREN)
else if (LT(1) == IToken.tLPAREN )
{
IToken mark = mark();
// initializer in constructor
try
{
consume(IToken.tLPAREN); // EAT IT!
IASTExpression astExpression = null;
astExpression = expression(sdw.getScope());
consume(IToken.tRPAREN);
d.setConstructorExpression(astExpression);
consume(IToken.tLPAREN); // EAT IT!
IASTExpression astExpression = null;
astExpression = expression(d.getDeclarationWrapper().getScope());
consume(IToken.tRPAREN);
d.setConstructorExpression(astExpression);
} catch( Backtrack bt )
{
backup( mark );
throw bt;
}
}
sdw.addDeclarator(d);
return d;
}
protected void optionalCInitializer( Declarator d ) throws Backtrack
{
if( LT(1) == IToken.tASSIGN )
{
consume( IToken.tASSIGN );
d.setInitializerClause( cInitializerClause(d.getDeclarationWrapper().getScope(), EMPTY_LIST ) );
}
}
/**
* @param scope
* @return
*/
protected IASTInitializerClause cInitializerClause(
IASTScope scope,
List designators)
throws Backtrack
{
if (LT(1) == IToken.tLBRACE)
{
consume(IToken.tLBRACE);
List initializerList = new ArrayList();
for (;;)
{
// required at least one initializer list
// get designator list
List newDesignators = designatorList(scope);
if( newDesignators.size() != 0 )
consume( IToken.tASSIGN );
IASTInitializerClause initializer =
cInitializerClause(scope, newDesignators );
initializerList.add(initializer);
// can end with just a '}'
if (LT(1) == IToken.tRBRACE)
break;
// can end with ", }"
if (LT(1) == IToken.tCOMMA)
consume(IToken.tCOMMA);
if (LT(1) == IToken.tRBRACE)
break;
// otherwise, its another initializer in the list
}
// consume the closing brace
consume(IToken.tRBRACE);
return astFactory.createInitializerClause(
scope,
(
( designators.size() == 0 ) ?
IASTInitializerClause.Kind.INITIALIZER_LIST :
IASTInitializerClause.Kind.DESIGNATED_INITIALIZER_LIST ),
null, initializerList, designators );
}
// if we get this far, it means that we have not yet succeeded
// try this now instead
// assignmentExpression
try
{
IASTExpression assignmentExpression = assignmentExpression(scope);
try
{
return astFactory.createInitializerClause(
scope,
(
( designators.size() == 0 ) ?
IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION :
IASTInitializerClause.Kind.DESIGNATED_ASSIGNMENT_EXPRESSION ),
assignmentExpression, null, designators );
}
catch (Exception e)
{
throw backtrack;
}
}
catch (Backtrack b)
{
// do nothing
}
throw backtrack;
}
/**
*
@ -1924,16 +2015,17 @@ public class Parser implements IParser
try
{
return astFactory.createInitializerClause(
scope,
IASTInitializerClause.Kind.EMPTY,
null,
null);
null, null, EMPTY_LIST );
}
catch (Exception e)
{
throw backtrack;
}
}
// otherwise it is a list of initializers
// otherwise it is a list of initializer clauses
List initializerClauses = new ArrayList();
for (;;)
{
@ -1947,17 +2039,19 @@ public class Parser implements IParser
try
{
return astFactory.createInitializerClause(
scope,
IASTInitializerClause.Kind.INITIALIZER_LIST,
null,
initializerClauses);
null, initializerClauses, EMPTY_LIST );
}
catch (Exception e)
{
throw backtrack;
}
}
// if we get this far, it means that we did not
// try this now instead
// assignmentExpression || { initializerList , } || { }
// assignmentExpression
try
{
IASTExpression assignmentExpression =
@ -1966,9 +2060,9 @@ public class Parser implements IParser
try
{
return astFactory.createInitializerClause(
scope,
IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION,
assignmentExpression,
null);
assignmentExpression, null, EMPTY_LIST );
}
catch (Exception e)
{
@ -1981,6 +2075,43 @@ public class Parser implements IParser
}
throw backtrack;
}
protected List designatorList(IASTScope scope) throws EndOfFile, Backtrack
{
List designatorList = new ArrayList();
// designated initializers for C
if( LT(1) == IToken.tDOT || LT(1) == IToken.tLBRACKET )
{
while( LT(1) == IToken.tDOT || LT(1) == IToken.tLBRACKET )
{
IToken id = null;
IASTExpression constantExpression = null;
IASTDesignator.DesignatorKind kind = null;
if( LT(1) == IToken.tDOT )
{
consume( IToken.tDOT );
id = identifier();
kind = IASTDesignator.DesignatorKind.FIELD;
}
else if( LT(1) == IToken.tLBRACKET )
{
consume( IToken.tLBRACKET );
constantExpression = expression( scope );
consume( IToken.tRBRACKET );
kind = IASTDesignator.DesignatorKind.SUBSCRIPT;
}
IASTDesignator d =
astFactory.createDesignator( kind, constantExpression, id );
designatorList.add( d );
}
}
return designatorList;
}
/**
* Parse a declarator, as according to the ANSI C++ specification.
*

View file

@ -36,8 +36,8 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITranslationOptions;
import org.eclipse.cdt.core.parser.ITranslationResult;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.core.parser.ast.ExpressionEvaluationException;

View file

@ -0,0 +1,88 @@
/**********************************************************************
* 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.internal.core.parser.ast;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTDesignator;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
/**
* @author jcamelon
*
*/
public class ASTDesignator implements IASTDesignator
{
/**
* @param kind
* @param constantExpression
* @param string
*/
public ASTDesignator(DesignatorKind kind, IASTExpression constantExpression, String fieldName, int fieldOffset )
{
this.fieldName = fieldName;
this.constantExpression = constantExpression;
this.kind = kind;
this.fieldOffset = fieldOffset;
}
private int fieldOffset;
private final String fieldName;
private final IASTExpression constantExpression;
private final DesignatorKind kind;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTDesignator#getKind()
*/
public DesignatorKind getKind()
{
return kind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTDesignator#arraySubscriptExpression()
*/
public IASTExpression arraySubscriptExpression()
{
return constantExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTDesignator#fieldName()
*/
public String fieldName()
{
return fieldName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
if( constantExpression != null )
constantExpression.acceptElement(requestor);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void enterScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void exitScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTDesignator#fieldOffset()
*/
public int fieldOffset()
{
return fieldOffset;
}
}

View file

@ -12,14 +12,16 @@ package org.eclipse.cdt.internal.core.parser.ast;
import java.util.List;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
import org.eclipse.cdt.core.parser.ast.IASTDesignator;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.core.parser.ast.IASTMacro;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTDesignator.DesignatorKind;
/**
@ -49,15 +51,17 @@ public class BaseASTFactory {
return new ASTAbstractDeclaration( isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOperator );
}
public IASTInitializerClause createInitializerClause(IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses)
{
return new ASTInitializerClause( kind, assignmentExpression, initializerClauses );
}
public IASTArrayModifier createArrayModifier(IASTExpression exp)
{
return new ASTArrayModifier( exp );
}
public IASTDesignator createDesignator(DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier)
{
return new ASTDesignator( kind, constantExpression,
fieldIdentifier == null ? "" : fieldIdentifier.getImage(),
fieldIdentifier == null ? -1 : fieldIdentifier.getOffset() );
}
}

View file

@ -0,0 +1,130 @@
/**********************************************************************
* 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.internal.core.parser.ast.complete;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
/**
* @author jcamelon
*
*/
public class ASTInitializerClause implements IASTInitializerClause
{
private List references = new ArrayList();
private IASTVariable ownerDeclaration = null;
private final IASTInitializerClause.Kind kind;
private final IASTExpression assignmentExpression;
private final List initializerClauses;
private final List designators;
/**
* @param kind
* @param assignmentExpression
* @param initializerClauses
* @param designators
*/
public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators)
{
this.kind = kind;
this.assignmentExpression = assignmentExpression;
this.initializerClauses = initializerClauses;
this.designators = designators;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getKind()
*/
public Kind getKind() {
return kind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializerList()
*/
public Iterator getInitializers() {
if( initializerClauses == null )
return new EmptyIterator();
return initializerClauses.iterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression()
*/
public IASTExpression getAssigmentExpression() {
return assignmentExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
Iterator i = getInitializers();
while( i.hasNext() )
((IASTInitializerClause)i.next()).acceptElement(requestor);
if( assignmentExpression != null )
assignmentExpression.acceptElement( requestor );
ASTReferenceStore store = new ASTReferenceStore( getReferences() );
store.processReferences(requestor);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void enterScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void exitScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getDesignators()
*/
public Iterator getDesignators()
{
return designators.iterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#setOwnerDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration)
*/
public void setOwnerVariableDeclaration(IASTVariable declaration)
{
ownerDeclaration = declaration;
Iterator subInitializers = getInitializers();
while( subInitializers.hasNext() )
((IASTInitializerClause)subInitializers.next()).setOwnerVariableDeclaration(declaration);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getOwnerDeclaration()
*/
public IASTVariable getOwnerVariableDeclaration()
{
return ownerDeclaration;
}
public List getReferences()
{
return references;
}
}

View file

@ -63,6 +63,8 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
return IASTSimpleTypeSpecifier.Type.VOID;
if( symbol.getType() == TypeInfo.t_wchar_t)
return IASTSimpleTypeSpecifier.Type.WCHAR_T;
if( symbol.getType() == TypeInfo.t__Bool )
return IASTSimpleTypeSpecifier.Type._BOOL;
return IASTSimpleTypeSpecifier.Type.UNSPECIFIED;
@ -130,4 +132,20 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
return (IASTTypeSpecifier)getSymbol().getTypeSymbol().getASTExtension().getPrimaryDeclaration();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isComplex()
*/
public boolean isComplex()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isComplex );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isImaginary()
*/
public boolean isImaginary()
{
return symbol.getTypeInfo().checkBit( TypeInfo.isImaginary );
}
}

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
import org.eclipse.cdt.core.parser.ast.IASTConstructorMemberInitializer;
import org.eclipse.cdt.core.parser.ast.IASTDesignator;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
@ -90,6 +91,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
*
*/
private final static List SUBSCRIPT;
static
{
SUBSCRIPT = new ArrayList();
SUBSCRIPT.add( TypeInfo.OperatorExpression.subscript );
}
public CompleteParseASTFactory( ParserLanguage language )
{
super();
@ -1333,42 +1341,26 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
boolean isShort,
boolean isLong,
boolean isSigned,
boolean isUnsigned, boolean isTypename) throws ASTSemanticException
boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary) throws ASTSemanticException
{
TypeInfo.eType type = null;
if( kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME )
{
type = TypeInfo.t_type;
}
else if( kind == IASTSimpleTypeSpecifier.Type.BOOL )
{
type = TypeInfo.t_bool;
}
else if( kind == IASTSimpleTypeSpecifier.Type.CHAR )
{
type = TypeInfo.t_char;
}
else if( kind == IASTSimpleTypeSpecifier.Type.DOUBLE )
{
else if( kind == IASTSimpleTypeSpecifier.Type.DOUBLE ||kind == IASTSimpleTypeSpecifier.Type.FLOAT )
type = TypeInfo.t_double;
}
else if( kind == IASTSimpleTypeSpecifier.Type.FLOAT )
{
type = TypeInfo.t_double;
}
else if( kind == IASTSimpleTypeSpecifier.Type.INT )
{
type = TypeInfo.t_int;
}
else if( kind == IASTSimpleTypeSpecifier.Type.VOID )
{
type = TypeInfo.t_void;
}
else if( kind == IASTSimpleTypeSpecifier.Type.WCHAR_T)
{
type = TypeInfo.t_wchar_t;
}
else if( kind == IASTSimpleTypeSpecifier.Type._BOOL )
type = TypeInfo.t__Bool;
List references = new ArrayList();
ISymbol s = pst.newSymbol( "", type );
@ -1405,10 +1397,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
s.setTypeSymbol( typeSymbol );
}
s.getTypeInfo().setBit( isLong, TypeInfo.isLong );
s.getTypeInfo().setBit( isShort, TypeInfo.isShort);
s.getTypeInfo().setBit( isUnsigned, TypeInfo.isUnsigned );
s.getTypeInfo().setBit( isComplex, TypeInfo.isComplex );
s.getTypeInfo().setBit( isImaginary, TypeInfo.isImaginary );
return new ASTSimpleTypeSpecifier( s, false, typeName.toString(), references );
@ -1441,7 +1434,6 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
IContainerSymbol ownerScope = scopeToSymbol( scope );
// check if this is a method in a body file
Iterator tokenizer = name.iterator();
if(name.length() > 1){
IContainerSymbol parentScope = (IContainerSymbol)
lookupQualifiedName(
@ -1898,7 +1890,6 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
}
String fieldName = oneToken;
String parentName = name.substring(0, name.lastIndexOf(DOUBLE_COLON));
int numOfTokens = 1;
int offset = nameOffset;
@ -1968,6 +1959,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
}
ASTVariable variable = new ASTVariable( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, nameEndOffset, references, constructorExpression, previouslyDeclared );
if( variable.getInitializerClause() != null )
{
variable.getInitializerClause().setOwnerVariableDeclaration(variable);
addDesignatorReferences( (ASTInitializerClause)variable.getInitializerClause() );
}
try
{
attachSymbolExtension(newSymbol, variable );
@ -1978,6 +1975,72 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
}
return variable;
}
/**
* @param clause
*/
protected void addDesignatorReferences( ASTInitializerClause clause )
{
if( clause.getKind() == IASTInitializerClause.Kind.DESIGNATED_INITIALIZER_LIST ||
clause.getKind() == IASTInitializerClause.Kind.DESIGNATED_ASSIGNMENT_EXPRESSION )
{
ISymbol variableSymbol = ((ASTVariable)clause.getOwnerVariableDeclaration()).getSymbol();
ISymbol currentSymbol = variableSymbol.getTypeSymbol();
TypeInfo currentTypeInfo = new TypeInfo( currentSymbol.getTypeInfo() );
Iterator designators = clause.getDesignators();
while( designators.hasNext() )
{
IASTDesignator designator = (IASTDesignator)designators.next();
if( designator.getKind() == IASTDesignator.DesignatorKind.FIELD )
{
ISymbol lookup = null;
if( ! ( currentSymbol instanceof IContainerSymbol ) )
break;
try
{
lookup = ((IContainerSymbol)currentSymbol).lookup( designator.fieldName() );
}
catch (ParserSymbolTableException e){
break;
}
if( lookup == null || lookup.getContainingSymbol() != currentSymbol )
break;
try
{
clause.getReferences().add( createReference( lookup, designator.fieldName(), designator.fieldOffset() ));
}
catch (ASTSemanticException e1)
{
// error
}
// we have found the correct field
currentTypeInfo = new TypeInfo( lookup.getTypeInfo() );
if( lookup.getTypeInfo() == null )
break;
currentSymbol = lookup.getTypeSymbol();
}
else if( designator.getKind() == IASTDesignator.DesignatorKind.SUBSCRIPT )
currentTypeInfo.applyOperatorExpressions( SUBSCRIPT );
}
}
if( clause.getKind() == IASTInitializerClause.Kind.DESIGNATED_INITIALIZER_LIST ||
clause.getKind() == IASTInitializerClause.Kind.INITIALIZER_LIST )
{
Iterator subInitializers = clause.getInitializers();
while( subInitializers.hasNext() )
addDesignatorReferences( (ASTInitializerClause)subInitializers.next() );
}
}
protected void setVariableTypeInfoBits(
boolean isAuto,
IASTAbstractDeclaration abstractDeclaration,
@ -2016,8 +2079,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
}
else if( abstractDeclaration.getTypeSpecifier() instanceof ASTElaboratedTypeSpecifier )
{
ASTElaboratedTypeSpecifier elab = ((ASTElaboratedTypeSpecifier)abstractDeclaration.getTypeSpecifier());
symbolToBeCloned = pst.newSymbol(name, TypeInfo.t_type);
symbolToBeCloned.setTypeSymbol(((ASTElaboratedTypeSpecifier)abstractDeclaration.getTypeSpecifier()).getSymbol());
symbolToBeCloned.setTypeSymbol(elab.getSymbol());
references.add( createReference( elab.getSymbol(), elab.getName(), elab.getNameOffset()) );
}
newSymbol = (ISymbol) symbolToBeCloned.clone();
newSymbol.setName( name );
@ -2464,4 +2529,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
// do nothing, this is best effort
}
}
public IASTInitializerClause createInitializerClause(IASTScope scope, IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators)
{
return new ASTInitializerClause( kind, assignmentExpression, initializerClauses, designators );
}
}

View file

@ -8,7 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast;
package org.eclipse.cdt.internal.core.parser.ast.quick;
import java.util.Iterator;
import java.util.List;
@ -16,6 +16,8 @@ import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
/**
* @author jcamelon
@ -25,15 +27,18 @@ public class ASTInitializerClause implements IASTInitializerClause {
private final IASTInitializerClause.Kind kind;
private final IASTExpression assignmentExpression;
private final List initializerClauses;
private final List designators;
private IASTVariable ownerDeclaration = null;
/**
* @param kind
* @param assignmentExpression
* @param initializerClauses
*/
public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses) {
public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators ) {
this.kind = kind;
this.assignmentExpression = assignmentExpression;
this.initializerClauses = initializerClauses;
this.designators = designators;
}
/* (non-Javadoc)
@ -64,14 +69,6 @@ public class ASTInitializerClause implements IASTInitializerClause {
*/
public void acceptElement(ISourceElementRequestor requestor)
{
Iterator i = getInitializers();
while( i.hasNext() )
{
IASTInitializerClause initializerClause = (IASTInitializerClause)i.next();
initializerClause.acceptElement(requestor);
}
if( assignmentExpression != null )
assignmentExpression.acceptElement( requestor );
}
/* (non-Javadoc)
@ -88,4 +85,28 @@ public class ASTInitializerClause implements IASTInitializerClause {
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getDesignators()
*/
public Iterator getDesignators()
{
return designators.iterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#setOwnerDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration)
*/
public void setOwnerVariableDeclaration(IASTVariable declaration)
{
ownerDeclaration = declaration;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getOwnerDeclaration()
*/
public IASTVariable getOwnerVariableDeclaration()
{
return ownerDeclaration;
}
}

View file

@ -18,7 +18,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.internal.core.parser.ast.*;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
/**

View file

@ -12,7 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.quick;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTScopedTypeSpecifier;
import org.eclipse.cdt.internal.core.parser.ast.*;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
/**
* @author jcamelon

View file

@ -24,7 +24,9 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
*/
public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
{
private final boolean isTypename;
private final boolean imaginary;
private final boolean complex;
private final boolean isTypename;
private final Type kind;
private final String typeName;
private final boolean isLong, isShort, isSigned, isUnsigned;
@ -40,12 +42,13 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
nameMap.put( Type.INT, "int");
nameMap.put( Type.VOID, "void" );
nameMap.put( Type.WCHAR_T, "wchar_t" );
nameMap.put( Type._BOOL, "_Bool");
}
/**
* @param kind
* @param typeName
*/
public ASTSimpleTypeSpecifier(Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename)
public ASTSimpleTypeSpecifier(Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary )
{
this.kind = kind;
this.isLong = isLong;
@ -53,7 +56,8 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
this.isSigned = isSigned;
this.isUnsigned = isUnsigned;
this.isTypename = isTypename;
this.complex = isComplex;
this.imaginary = isImaginary;
StringBuffer type = new StringBuffer();
if( this.kind == IASTSimpleTypeSpecifier.Type.CHAR || this.kind == IASTSimpleTypeSpecifier.Type.WCHAR_T )
@ -62,7 +66,7 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
type.append("unsigned ");
type.append( (String)nameMap.get( this.kind ));
}
else if( this.kind == Type.BOOL || this.kind == Type.FLOAT || this.kind == Type.VOID )
else if( this.kind == Type.BOOL || this.kind == Type.VOID || this.kind == Type._BOOL )
{
type.append( (String) nameMap.get( this.kind ));
}
@ -76,11 +80,23 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
type.append("long ");
type.append( (String)nameMap.get( this.kind ));
}
else if( this.kind == Type.FLOAT )
{
type.append( (String)nameMap.get( this.kind ));
if( isComplex() )
type.append( "_Complex" );
else if( isImaginary() )
type.append( "_Imaginary" );
}
else if( this.kind == Type.DOUBLE )
{
if (isLong())
type.append("long ");
type.append( (String)nameMap.get( this.kind ));
if( isComplex() )
type.append( "_Complex" );
else if( isImaginary() )
type.append( "_Imaginary" );
}
else if( this.kind == Type.CLASS_OR_TYPENAME || this.kind == Type.TEMPLATE )
{
@ -160,4 +176,20 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
{
throw new ASTNotImplementedException();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isComplex()
*/
public boolean isComplex()
{
return complex;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isImaginary()
*/
public boolean isImaginary()
{
return imaginary;
}
}

View file

@ -14,7 +14,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.internal.core.parser.ast.*;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
/**

View file

@ -16,7 +16,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.internal.core.parser.ast.*;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
/**
@ -58,6 +58,8 @@ public class ASTVariable extends ASTDeclaration implements IASTVariable
setStartingOffset(startingOffset);
setNameOffset(nameOffset);
setNameEndOffset( nameEndOffset );
if( initializerClause != null )
initializerClause.setOwnerVariableDeclaration(this);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isAuto()

View file

@ -176,9 +176,9 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.SimpleType, org.eclipse.cdt.core.parser.ITokenDuple)
*/
public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename )
public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary )
{
return new ASTSimpleTypeSpecifier( kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename );
return new ASTSimpleTypeSpecifier( kind, typeName, isShort, isLong, isSigned, isUnsigned, isTypename, isComplex, isImaginary);
}
/* (non-Javadoc)
@ -210,7 +210,8 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
*/
public IASTField createField(IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int nameOffset, int nameEndOffset, IASTExpression constructorExpression, ASTAccessVisibility visibility)
{
return new ASTField(scope, name, isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern, isRegister, isStatic, startingOffset, nameOffset, nameEndOffset, constructorExpression, visibility);
final ASTField field = new ASTField(scope, name, isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern, isRegister, isStatic, startingOffset, nameOffset, nameEndOffset, constructorExpression, visibility);
return field;
}
/* (non-Javadoc)
@ -309,4 +310,10 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier)
{
}
public IASTInitializerClause createInitializerClause(IASTScope scope, IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators)
{
return new ASTInitializerClause( kind, assignmentExpression, initializerClauses, designators );
}
}

View file

@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension.ExtensionException;
/**
* @author jcamelon

View file

@ -10,8 +10,8 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst;
import java.util.Map;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.TemplateInstance;
/**

View file

@ -16,6 +16,7 @@ import java.util.List;
import java.util.NoSuchElementException;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension.ExtensionException;
/**
* @author jcamelon

View file

@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension.ExtensionException;
/**

View file

@ -70,7 +70,7 @@ public class TypeInfo {
_hasDefaultValue = info._hasDefaultValue;
}
public static final int typeMask = 0x001f;
public static final int typeMask = 0x001f;
public static final int isAuto = 0x0020;
public static final int isRegister = 0x0040;
public static final int isStatic = 0x0080;
@ -87,6 +87,8 @@ public class TypeInfo {
public static final int isShort = 0x40000;
public static final int isLong = 0x80000;
public static final int isForward = 0x100000;
public static final int isComplex = 0x200000;
public static final int isImaginary= 0x400000;
// Types (maximum type is typeMask
// Note that these should be considered ordered and if you change
@ -113,6 +115,7 @@ public class TypeInfo {
public static final TypeInfo.eType t_template = new TypeInfo.eType( 18 );
public static final TypeInfo.eType t_asm = new TypeInfo.eType( 19 );
public static final TypeInfo.eType t_linkage = new TypeInfo.eType( 20 );
public static final TypeInfo.eType t__Bool = new TypeInfo.eType( 21 );
//public static final eType t_templateParameter = new eType( 18 );
public static class eType implements Comparable{

View file

@ -24,7 +24,6 @@ import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.internal.core.parser.ast.ASTArrayModifier;
/**
* This is a utility class to help convert AST elements to Strings.
@ -172,7 +171,7 @@ public class ASTUtil {
StringBuffer arrayString = new StringBuffer();
Iterator i = declaration.getArrayModifiers();
while (i.hasNext()){
ASTArrayModifier q = (ASTArrayModifier) i.next();
i.next();
arrayString.append("[]");
}
return arrayString.toString();