[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] C types in the parser symbol table (bug45573)
|
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()
tested on windows & linux
-Andrew
Index: parser/ChangeLog-parser
===================================================================
retrieving revision 1.28
diff -u -r1.28 ChangeLog-parser
--- parser/ChangeLog-parser 23 Jan 2004 21:04:23 -0000 1.28
+++ parser/ChangeLog-parser 26 Jan 2004 19:30:57 -0000
@@ -1,3 +1,9 @@
+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..
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
===================================================================
retrieving revision 1.36
diff -u -r1.36 ParserSymbolTable.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java 17 Jan 2004 00:18:24 -0000 1.36
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java 26 Jan 2004 19:31:00 -0000
@@ -1495,9 +1495,9 @@
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 @@
} 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;
Index: parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java
===================================================================
retrieving revision 1.8
diff -u -r1.8 TypeInfo.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java 10 Dec 2003 00:07:26 -0000 1.8
+++ parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java 26 Jan 2004 19:31:01 -0000
@@ -88,6 +88,7 @@
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 @@
* 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 ){
Index: ChangeLog
===================================================================
retrieving revision 1.171
diff -u -r1.171 ChangeLog
--- ChangeLog 22 Jan 2004 20:15:31 -0000 1.171
+++ ChangeLog 26 Jan 2004 19:27:26 -0000
@@ -1,3 +1,8 @@
+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.
Index: parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java
===================================================================
retrieving revision 1.33
diff -u -r1.33 ParserSymbolTableTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java 20 Jan 2004 02:21:30 -0000 1.33
+++ parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java 26 Jan 2004 19:27:30 -0000
@@ -3555,5 +3555,117 @@
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 );
+
+ }
}