mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-21 07:05:58 +02:00
CORE
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) Fixed Bug 45476 : preprocessor macro "defined" not handled correctly Fixed Bug 45477 : macro redefines prevent further parsing TESTS Added testBug45476() to ScannerTestCase. Added testBug45477() to ScannerTestCase. 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:
parent
d8b28329bd
commit
7a757e55c1
35 changed files with 822 additions and 293 deletions
|
@ -1,3 +1,16 @@
|
|||
2003-10-24 John Camelon
|
||||
Added testBug45476() to ScannerTestCase.
|
||||
Added testBug45477() to ScannerTestCase.
|
||||
|
||||
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-21 John Camelon
|
||||
Moved testBug40007() from ASTFailedTests to QuickParseASTTests.
|
||||
Added QuickParseASTTests::testBug40759().
|
||||
|
|
|
@ -36,30 +36,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
|
||||
{
|
||||
assertCodeFailsParse("_Pragma(\"foobar\")");
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
@ -916,4 +917,58 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
|
|||
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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
|
@ -1412,4 +1412,87 @@ public class ScannerTestCase extends BaseScannerTest
|
|||
validateEOF();
|
||||
}
|
||||
|
||||
public void testBug45476() throws Exception
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "#define X 5\n");
|
||||
buffer.append( "#if defined X\n");
|
||||
buffer.append( "#define Y 10\n");
|
||||
buffer.append( "#endif");
|
||||
initializeScanner( buffer.toString() );
|
||||
validateEOF();
|
||||
validateDefinition( "Y", "10");
|
||||
}
|
||||
|
||||
public void testBug45477() throws Exception
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "#define D\n" );
|
||||
buffer.append( "#define D\n" );
|
||||
buffer.append( "#define sum(x,y) x+y\n" );
|
||||
buffer.append( "#define E 3\n" );
|
||||
buffer.append( "#define E 3\n" );
|
||||
buffer.append( "#define sum(x,y) x+y\n");
|
||||
buffer.append( "#if defined(D)\n" );
|
||||
buffer.append( "printf\n" );
|
||||
buffer.append( "#endif\n" );
|
||||
buffer.append( "#if defined(sum)\n" );
|
||||
buffer.append( "scanf\n" );
|
||||
buffer.append( "#endif\n" );
|
||||
buffer.append( "#if defined(E)\n" );
|
||||
buffer.append( "sprintf\n" );
|
||||
buffer.append( "#endif\n" );
|
||||
initializeScanner( buffer.toString() );
|
||||
validateIdentifier( "printf" );
|
||||
validateIdentifier( "scanf");
|
||||
validateIdentifier( "sprintf" );
|
||||
validateEOF();
|
||||
|
||||
for( int i = 0; i < 5; ++i)
|
||||
{
|
||||
|
||||
buffer = new StringBuffer();
|
||||
|
||||
buffer.append( "#define D blah\n" );
|
||||
|
||||
switch( i )
|
||||
{
|
||||
case 0:
|
||||
buffer.append( "#define D\n");
|
||||
break;
|
||||
case 1:
|
||||
buffer.append( "#define D( x ) echo\n");
|
||||
break;
|
||||
case 2:
|
||||
buffer.append( "#define D ACDC\n");
|
||||
break;
|
||||
case 3:
|
||||
buffer.append( "#define D defined( D )\n");
|
||||
break;
|
||||
case 4:
|
||||
buffer.append( "#define D blahh\n");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
initializeScanner( buffer.toString() );
|
||||
try
|
||||
{
|
||||
validateEOF();
|
||||
fail( "Should not reach here");
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
assertEquals( se.getErrorCode(), ScannerException.ErrorCode.ATTEMPTED_REDEFINITION );
|
||||
}
|
||||
}
|
||||
|
||||
buffer = new StringBuffer();
|
||||
buffer.append( "#define X 5\n");
|
||||
buffer.append( "#define Y 7\n");
|
||||
buffer.append( "#define SUMXY X _+ Y");
|
||||
buffer.append( "#define SUMXY X + Y");
|
||||
initializeScanner(buffer.toString());
|
||||
validateEOF();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
2003-10-24 John Camelon
|
||||
Fixed Bug 45476 : preprocessor macro "defined" not handled correctly
|
||||
Fixed Bug 45477 : macro redefines prevent further parsing
|
||||
|
||||
2003-10-24 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
|
||||
|
|
|
@ -15,4 +15,5 @@ public interface IMacroDescriptor {
|
|||
List getTokenizedExpansion();
|
||||
String getName();
|
||||
String getSignature();
|
||||
boolean compatible(IMacroDescriptor descriptor);
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
|
|
@ -78,14 +78,12 @@ public class ScannerException extends Exception {
|
|||
return true;
|
||||
if( mode == ParserMode.COMPLETE_PARSE )
|
||||
if( this == ErrorCode.POUND_ERROR ||
|
||||
this == ErrorCode.DEFINITION_NOT_FOUND ||
|
||||
this == ErrorCode.UNBALANCED_CONDITIONALS ||
|
||||
this == ErrorCode.MALFORMED_MACRO_DEFN ||
|
||||
this == ErrorCode.UNEXPECTED_EOF ||
|
||||
this == ErrorCode.MACRO_USAGE_ERROR ||
|
||||
this == ErrorCode.MACRO_PASTING_ERROR ||
|
||||
this == ErrorCode.EXPRESSION_EVALUATION_ERROR ||
|
||||
this == ErrorCode.ATTEMPTED_REDEFINITION )
|
||||
this == ErrorCode.EXPRESSION_EVALUATION_ERROR )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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 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 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 IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier );
|
||||
|
||||
public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset ) throws 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 ) ;
|
||||
|
||||
public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms ) throws Exception;
|
||||
public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset ) ;
|
||||
|
||||
public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset)throws Exception;
|
||||
public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, String identifier, String defaultValue, IASTParameterDeclaration parameter, List parms ) ;
|
||||
|
||||
public IASTTemplateSpecialization createTemplateSpecialization(IASTScope scope, int startingOffset)throws Exception;
|
||||
public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset);
|
||||
|
||||
public IASTTypedefDeclaration createTypedef( IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset, int nameEndOffset ) throws ASTSemanticException, Exception;
|
||||
public IASTTemplateSpecialization createTemplateSpecialization(IASTScope scope, int startingOffset);
|
||||
|
||||
public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration( IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate template, int startingOffset, int endingOffset)throws Exception;
|
||||
public IASTTypedefDeclaration createTypedef( IASTScope scope, String name, IASTAbstractDeclaration mapping, int startingOffset, int nameOffset, int nameEndOffset ) throws ASTSemanticException;
|
||||
|
||||
public boolean queryIsTypeName( IASTScope scope, ITokenDuple nameInQuestion ) throws Exception;
|
||||
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);
|
||||
|
||||
|
||||
}
|
|
@ -25,6 +25,8 @@ public interface IASTInitializerClause extends ISourceElementCallbackDelegate{
|
|||
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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,4 +107,20 @@ public class MacroDescriptor implements IMacroDescriptor {
|
|||
return signature;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IMacroDescriptor#compatible(org.eclipse.cdt.core.parser.IMacroDescriptor)
|
||||
*/
|
||||
public boolean compatible(IMacroDescriptor descriptor) {
|
||||
if( descriptor.getName() == null ) return false;
|
||||
if( descriptor.getTokenizedExpansion() == null ) return false;
|
||||
if( descriptor.getParameters() == null ) return false;
|
||||
if( ! name.equals( descriptor.getName() )) return false;
|
||||
if( descriptor.getParameters().size() != identifierParameters.size() ) return false;
|
||||
if( descriptor.getTokenizedExpansion().size() != tokenizedExpansion.size() ) return false;
|
||||
|
||||
if( ! (descriptor.getParameters().containsAll( identifierParameters ) )) return false;
|
||||
if( ! (descriptor.getTokenizedExpansion().containsAll( tokenizedExpansion ))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,6 +1493,13 @@ 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);
|
||||
|
@ -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,8 +1585,6 @@ public class Parser implements IParser
|
|||
case IToken.t_class :
|
||||
case IToken.t_struct :
|
||||
case IToken.t_union :
|
||||
if (!parm )
|
||||
{
|
||||
try
|
||||
{
|
||||
classSpecifier(sdw);
|
||||
|
@ -1578,16 +1597,7 @@ public class Parser implements IParser
|
|||
flags.setEncounteredTypename(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
elaboratedTypeSpecifier(sdw);
|
||||
flags.setEncounteredTypename(true);
|
||||
break;
|
||||
}
|
||||
case IToken.t_enum :
|
||||
if (!parm )
|
||||
{
|
||||
try
|
||||
{
|
||||
enumSpecifier(sdw);
|
||||
|
@ -1601,13 +1611,6 @@ public class Parser implements IParser
|
|||
flags.setEncounteredTypename(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
elaboratedTypeSpecifier(sdw);
|
||||
flags.setEncounteredTypename(true);
|
||||
break;
|
||||
}
|
||||
default :
|
||||
break declSpecifiers;
|
||||
}
|
||||
|
@ -1883,13 +1886,24 @@ 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
|
||||
|
@ -1897,7 +1911,7 @@ public class Parser implements IParser
|
|||
{
|
||||
consume(IToken.tLPAREN); // EAT IT!
|
||||
IASTExpression astExpression = null;
|
||||
astExpression = expression(sdw.getScope());
|
||||
astExpression = expression(d.getDeclarationWrapper().getScope());
|
||||
consume(IToken.tRPAREN);
|
||||
d.setConstructorExpression(astExpression);
|
||||
} catch( Backtrack bt )
|
||||
|
@ -1906,8 +1920,85 @@ public class Parser implements IParser
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
@ -2119,12 +2119,8 @@ public class Scanner implements IScanner {
|
|||
String key = getNextIdentifier();
|
||||
int offset = contextStack.getCurrentContext().getOffset() - key.length() - contextStack.getCurrentContext().undoStackSize();
|
||||
|
||||
if (mode == ParserMode.COMPLETE_PARSE) {
|
||||
String checkForRedefinition = (String) definitions.get(key);
|
||||
if (checkForRedefinition != null) {
|
||||
throw new ScannerException( ScannerException.ErrorCode.ATTEMPTED_REDEFINITION, key, getCurrentFile(), getCurrentOffset());
|
||||
}
|
||||
}
|
||||
// store the previous definition to check against later
|
||||
Object previousDefinition = definitions.get( key );
|
||||
|
||||
// get the next character
|
||||
// the C++ standard says that macros must not put
|
||||
|
@ -2217,11 +2213,14 @@ public class Scanner implements IScanner {
|
|||
parameterIdentifiers,
|
||||
macroReplacementTokens,
|
||||
key + "(" + parameters + ")");
|
||||
|
||||
checkValidMacroRedefinition(key, previousDefinition, descriptor);
|
||||
addDefinition(key, descriptor);
|
||||
|
||||
}
|
||||
else if ((c == '\n') || (c == '\r'))
|
||||
{
|
||||
checkValidMacroRedefinition(key, previousDefinition, "");
|
||||
addDefinition( key, "" );
|
||||
}
|
||||
else if ((c == ' ') || (c == '\t') ) {
|
||||
|
@ -2230,6 +2229,8 @@ public class Scanner implements IScanner {
|
|||
|
||||
// get what we are to map the name to and add it to the definitions list
|
||||
String value = getRestOfPreprocessorLine();
|
||||
|
||||
checkValidMacroRedefinition(key, previousDefinition, value);
|
||||
addDefinition( key, value );
|
||||
|
||||
} else if (c == '/') {
|
||||
|
@ -2238,15 +2239,19 @@ public class Scanner implements IScanner {
|
|||
if (c == '/') // one line comment
|
||||
{
|
||||
skipOverSinglelineComment();
|
||||
checkValidMacroRedefinition(key, previousDefinition, "");
|
||||
addDefinition(key, "");
|
||||
} else if (c == '*') // multi-line comment
|
||||
{
|
||||
if (skipOverMultilineComment()) {
|
||||
// we have gone over a newline
|
||||
// therefore, this symbol was defined to an empty string
|
||||
checkValidMacroRedefinition(key, previousDefinition, "");
|
||||
addDefinition(key, "");
|
||||
} else {
|
||||
String value = getRestOfPreprocessorLine();
|
||||
|
||||
checkValidMacroRedefinition(key, previousDefinition, "");
|
||||
addDefinition(key, value);
|
||||
}
|
||||
} else {
|
||||
|
@ -2271,6 +2276,75 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void checkValidMacroRedefinition(
|
||||
String key,
|
||||
Object previousDefinition,
|
||||
Object newDefinition )
|
||||
throws ScannerException
|
||||
{
|
||||
if( mode == ParserMode.COMPLETE_PARSE && previousDefinition != null )
|
||||
{
|
||||
if( newDefinition instanceof IMacroDescriptor )
|
||||
{
|
||||
if( previousDefinition instanceof IMacroDescriptor )
|
||||
{
|
||||
if( ((IMacroDescriptor)previousDefinition).compatible( (IMacroDescriptor) newDefinition ) )
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if( newDefinition instanceof String )
|
||||
{
|
||||
|
||||
if( previousDefinition instanceof String )
|
||||
{
|
||||
Scanner previous = new Scanner( new StringReader( (String)previousDefinition ), "redef-test", new ScannerInfo(), null, null, new NullSourceElementRequestor(),
|
||||
mode, language );
|
||||
Scanner current = new Scanner( new StringReader( (String)newDefinition ), "redef-test", new ScannerInfo(), null, null, new NullSourceElementRequestor(),
|
||||
mode, language );
|
||||
for ( ; ; )
|
||||
{
|
||||
IToken p = null;
|
||||
IToken c = null;
|
||||
try
|
||||
{
|
||||
p = previous.nextToken();
|
||||
c = current.nextToken();
|
||||
|
||||
if ( c.equals( p ) ) continue;
|
||||
break;
|
||||
|
||||
}
|
||||
catch( EndOfFile eof )
|
||||
{
|
||||
if( ( p != null ) && ( c == null ) )
|
||||
break;
|
||||
if( p == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
c = current.nextToken();
|
||||
break;
|
||||
}
|
||||
catch( EndOfFile eof2 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new ScannerException(
|
||||
ScannerException.ErrorCode.ATTEMPTED_REDEFINITION,
|
||||
key,
|
||||
getCurrentFile(),
|
||||
getCurrentOffset());
|
||||
}
|
||||
}
|
||||
|
||||
protected Vector getMacroParameters (String params, boolean forStringizing) throws ScannerException {
|
||||
|
||||
Scanner tokenizer = new Scanner(new StringReader(params), TEXT, new ScannerInfo( definitions, originalConfig.getIncludePaths() ), problemReporter, translationResult, new NullSourceElementRequestor(), mode, language);
|
||||
|
@ -2465,23 +2539,21 @@ public class Scanner implements IScanner {
|
|||
|
||||
int c = getChar();
|
||||
|
||||
if (c != '(') {
|
||||
String definitionIdentifier = null;
|
||||
if (c == '(') {
|
||||
|
||||
definitionIdentifier = getNextIdentifier();
|
||||
skipOverWhitespace();
|
||||
c = getChar();
|
||||
if (c != ')')
|
||||
if (throwExceptionOnBadMacroExpansion)
|
||||
throw new ScannerException( ScannerException.ErrorCode.MACRO_USAGE_ERROR, "defined()", getCurrentFile(), getCurrentOffset() );
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
c = getChar();
|
||||
while ((c != NOCHAR) && (c != ')')) {
|
||||
buffer.append((char) c);
|
||||
c = getChar();
|
||||
else
|
||||
{
|
||||
ungetChar(c);
|
||||
definitionIdentifier = getNextIdentifier();
|
||||
}
|
||||
if (c == NOCHAR) {
|
||||
if (throwExceptionOnBadMacroExpansion)
|
||||
throw new ScannerException( ScannerException.ErrorCode.MACRO_USAGE_ERROR, "defined()", getCurrentFile(), getCurrentOffset() );
|
||||
}
|
||||
|
||||
String definitionIdentifier = buffer.toString().trim();
|
||||
|
||||
if (definitions.get(definitionIdentifier) != null)
|
||||
return "1";
|
||||
|
|
|
@ -152,4 +152,20 @@ public class Token implements IToken {
|
|||
image = i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object other) {
|
||||
if( other == null ) return false;
|
||||
if( !( other instanceof IToken ) )
|
||||
return false;
|
||||
if( !(((IToken)other).getImage().equals( image )))
|
||||
return false;
|
||||
if( ((IToken)other).getType() != type )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.ast;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class ASTInitializerClause implements IASTInitializerClause {
|
||||
|
||||
private final IASTInitializerClause.Kind kind;
|
||||
private final IASTExpression assignmentExpression;
|
||||
private final List initializerClauses;
|
||||
/**
|
||||
* @param kind
|
||||
* @param assignmentExpression
|
||||
* @param initializerClauses
|
||||
*/
|
||||
public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses) {
|
||||
this.kind = kind;
|
||||
this.assignmentExpression = assignmentExpression;
|
||||
this.initializerClauses = initializerClauses;
|
||||
}
|
||||
|
||||
/* (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 initializerClause = (IASTInitializerClause)i.next();
|
||||
initializerClause.acceptElement(requestor);
|
||||
}
|
||||
if( assignmentExpression != null )
|
||||
assignmentExpression.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)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -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() );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -24,6 +24,8 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
|
|||
*/
|
||||
public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
|
||||
{
|
||||
private final boolean imaginary;
|
||||
private final boolean complex;
|
||||
private final boolean isTypename;
|
||||
private final Type kind;
|
||||
private final String typeName;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue