1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

Patch for Andrew Niefer

This patch provides handling of the C types _Complex, _Imaginary, _Bool & 
long long int in the parser symbol table. (bug45573)

Core:
        modified ParserSymbolTable.promotion() & conversion()
        added TypeInfo.isLongLong
        modified TypeInfo.canHold()

Core.tests:
        Added ParserSymbolTableTest.testLongLong() 
        Added ParserSymbolTableTest.testComplex() 
        Added ParserSymbolTableTest.test_Bool()
This commit is contained in:
John Camelon 2004-01-27 02:36:30 +00:00
parent b5d5e34e25
commit 8e6d3ded24
5 changed files with 135 additions and 6 deletions

View file

@ -2,6 +2,11 @@
Updated clients to use new Scanner logging service.
Added ScannerTestCase.testBug46402().
2004-01-26 Andrew Niefer
Added ParserSymbolTableTest.testLongLong()
Added ParserSymbolTableTest.testComplex()
Added ParserSymbolTableTest.test_Bool()
2004-01-22 John Camelon
Updated Scanner tests for package updates in the core.

View file

@ -3555,5 +3555,117 @@ public class ParserSymbolTableTest extends TestCase {
assertFalse( iter.hasNext() );
}
/**
* void f( long long int ){} //#1
* void f( long int ) {} //#2
*
* f( 1L ); //#2
* f( 1LL ); //#1
*
* @throws Exception
*/
public void testLongLong() throws Exception{
newTable();
IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
f1.addParameter( TypeInfo.t_int, TypeInfo.isLongLong, null, false );
table.getCompilationUnit().addSymbol( f1 );
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
f2.addParameter( TypeInfo.t_int, TypeInfo.isLong, null, false );
table.getCompilationUnit().addSymbol( f2 );
List params = new LinkedList();
params.add( new TypeInfo( TypeInfo.t_int, TypeInfo.isLong, null ) );
IParameterizedSymbol lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
assertEquals( lookup, f2 );
params.clear();
params.add( new TypeInfo( TypeInfo.t_int, TypeInfo.isLongLong, null ) );
lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
assertEquals( lookup, f1 );
}
/**
* void f( float _Complex ){}
* void g( float ) {}
*
* float _Complex c;
* float fl;
* float _Imaginary i;
*
* f( c );
* f( fl );
* g( c );
* g( i );
* @throws Exception
*/
public void testComplex() throws Exception{
newTable();
IParameterizedSymbol f = table.newParameterizedSymbol( "f", TypeInfo.t_function );
f.addParameter( TypeInfo.t_float, TypeInfo.isComplex, null, false );
table.getCompilationUnit().addSymbol( f );
IParameterizedSymbol g = table.newParameterizedSymbol( "g", TypeInfo.t_function );
g.addParameter( TypeInfo.t_float, 0, null, false );
table.getCompilationUnit().addSymbol( g );
List params = new LinkedList();
params.add( new TypeInfo( TypeInfo.t_float, TypeInfo.isComplex, null ) );
IParameterizedSymbol lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
assertEquals( lookup, f );
params.clear();
params.add( new TypeInfo( TypeInfo.t_float, 0, null ) );
lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
assertEquals( lookup, f );
params.clear();
params.add( new TypeInfo( TypeInfo.t_float, TypeInfo.isComplex, null ) );
lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "g", params );
assertEquals( lookup, g );
params.clear();
params.add( new TypeInfo( TypeInfo.t_float, TypeInfo.isImaginary, null ) );
lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "g", params );
assertEquals( lookup, g );
lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
assertEquals( lookup, f );
}
public void test_Bool() throws Exception{
newTable();
IParameterizedSymbol f = table.newParameterizedSymbol( "f", TypeInfo.t_function );
f.addParameter( TypeInfo.t__Bool, 0, null, false );
table.getCompilationUnit().addSymbol( f );
IParameterizedSymbol g = table.newParameterizedSymbol( "g", TypeInfo.t_function );
g.addParameter( TypeInfo.t_int, 0, null, false );
table.getCompilationUnit().addSymbol( g );
List params = new LinkedList();
params.add( new TypeInfo( TypeInfo.t__Bool, 0, null ) );
IParameterizedSymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
assertEquals( look, f );
look = table.getCompilationUnit().unqualifiedFunctionLookup( "g", params );
assertEquals( look, g );
params.clear();
params.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
assertEquals( look, f );
}
}

View file

@ -4,6 +4,12 @@
Added beginning of IScannerExtension and GCCScannerExtension support for gcc specific aspects.
Added separate Scanner log category for tracing and updated clients to use it.
2004-01-26 Andrew Niefer
Handle the C types _Complex, _Imaginary, _Bool, & long long int:
modified ParserSymbolTable.promotion() & conversion()
added TypeInfo.isLongLong
modified TypeInfo.canHold()
2004-01-23 John Camelon
Added support for content assist in the scanner..

View file

@ -1495,9 +1495,9 @@ public class ParserSymbolTable {
TypeInfo src = cost.source;
TypeInfo trg = cost.target;
int mask = TypeInfo.isShort | TypeInfo.isLong | TypeInfo.isUnsigned;
int mask = TypeInfo.isShort | TypeInfo.isLong | TypeInfo.isUnsigned | TypeInfo.isLongLong;
if( (src.isType( TypeInfo.t_bool, TypeInfo.t_float ) || src.isType( TypeInfo.t_enumeration )) &&
if( (src.isType( TypeInfo.t__Bool, TypeInfo.t_float ) || src.isType( TypeInfo.t_enumeration )) &&
(trg.isType( TypeInfo.t_int ) || trg.isType( TypeInfo.t_double )) )
{
if( src.getType() == trg.getType() && (( src.getTypeInfo() & mask) == (trg.getTypeInfo() & mask)) ){
@ -1594,11 +1594,11 @@ public class ParserSymbolTable {
} else if( !src.hasPtrOperators() ) {
//4.7 An rvalue of an integer type can be converted to an rvalue of another integer type.
//An rvalue of an enumeration type can be converted to an rvalue of an integer type.
if( src.isType( TypeInfo.t_bool, TypeInfo.t_int ) ||
if( src.isType( TypeInfo.t__Bool, TypeInfo.t_int ) ||
src.isType( TypeInfo.t_float, TypeInfo.t_double ) ||
src.isType( TypeInfo.t_enumeration ) )
{
if( trg.isType( TypeInfo.t_bool, TypeInfo.t_int ) ||
if( trg.isType( TypeInfo.t__Bool, TypeInfo.t_int ) ||
trg.isType( TypeInfo.t_float, TypeInfo.t_double ) )
{
cost.rank = Cost.CONVERSION_RANK;

View file

@ -88,6 +88,7 @@ public class TypeInfo {
public static final int isForward = 0x100000;
public static final int isComplex = 0x200000;
public static final int isImaginary= 0x400000;
public static final int isLongLong = 0x800000;
// Types (maximum type is typeMask
// Note that these should be considered ordered and if you change
@ -450,13 +451,18 @@ public class TypeInfo {
* canHold
* @param type
* @return boolean
* return true is the our type can hold all the values of the passed in
* return true if our type can hold all the values of the passed in
* type.
* TODO, for now return true if our type is "larger" (based on ordering of
* the type values)
*/
public boolean canHold( TypeInfo type ){
return getType().compareTo( type.getType() ) >= 0;
if( getType().compareTo( type.getType()) > 0 ){
return true;
} else {
int mask = TypeInfo.isShort | TypeInfo.isLong | TypeInfo.isLongLong;
return ( getTypeInfo() & mask ) >= ( type.getTypeInfo() & mask );
}
}
public boolean equals( Object t ){