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

Fixed Bug 39686 - GCC complex numbers are not supported (GCC)

This commit is contained in:
John Camelon 2004-09-21 23:42:47 +00:00
parent 1715e6bb76
commit 1b1480e7ba
6 changed files with 54 additions and 20 deletions

View file

@ -72,25 +72,7 @@ public class ASTFailedTests extends BaseASTTest
"The expected error did not occur.",
typedef.getName().equals( "name" ) );
}
public void testBug39686() throws Exception
{
Writer code = new StringWriter();
try
{
code.write("__complex__ double x; // complex double\n");
code.write("__complex__ short int a; // complex short int\n");
code.write("x = 2.5fi; // 2.5 imaginary float literal\n");
code.write("a = 3i; // imaginary integer literal\n");
code.write("double v = __real__ x; // real part of expression\n");
code.write(
"double w = __imag__ x; // imaginary part of expression\n");
}
catch (IOException ioe)
{
}
assertCodeFailsParse(code.toString());
}
public void testBug39687() throws Exception
{
assertCodeFailsParse("struct entry tester (int len; char data[len][len], int len) {}");

View file

@ -165,4 +165,16 @@ public class GCCCompleteParseExtensionsTest extends CompleteParseBaseTest {
parse( writer.toString() );
}
public void testBug39686() throws Exception
{
Writer code = new StringWriter();
code.write("__complex__ double x; // complex double\n"); //$NON-NLS-1$
code.write("__complex__ short int a; // complex short int\n"); //$NON-NLS-1$
code.write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); //$NON-NLS-1$
code.write("__complex__ int z = 3i; // imaginary intege r literal\n"); //$NON-NLS-1$
code.write("double v = __real__ x; // real part of expression\n"); //$NON-NLS-1$
code.write("double w = __imag__ x; // imaginary part of expression\n"); //$NON-NLS-1$
parse(code.toString());
}
}

View file

@ -105,4 +105,16 @@ public class GCCQuickParseExtensionsTest extends BaseASTTest {
IASTFunction f = (IASTFunction)assertSoleDeclaration("int func2 (void) __attribute__((dllexport));"); //$NON-NLS-1$
assertEquals( f.getName(), "func2"); //$NON-NLS-1$
}
public void testBug39686() throws Exception
{
Writer code = new StringWriter();
code.write("__complex__ double x; // complex double\n"); //$NON-NLS-1$
code.write("__complex__ short int a; // complex short int\n"); //$NON-NLS-1$
code.write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); //$NON-NLS-1$
code.write("__complex__ int a = 3i; // imaginary intege r literal\n"); //$NON-NLS-1$
code.write("double v = __real__ x; // real part of expression\n"); //$NON-NLS-1$
code.write("double w = __imag__ x; // imaginary part of expression\n"); //$NON-NLS-1$
parse(code.toString());
}
}

View file

@ -30,4 +30,5 @@ public interface IScannerExtension {
public boolean isValidIdentifierStartCharacter(int c);
public boolean isValidIdentifierCharacter( int c );
public boolean isExtensionOperator(ParserLanguage language, char[] query);
public boolean isValidNumericLiteralSuffix(char c);
}

View file

@ -66,6 +66,12 @@ public class GCCScannerExtension implements IScannerExtension {
= new ObjectStyleMacro("__signed__".toCharArray(), "signed".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
private static final ObjectStyleMacro __cdecl = new
ObjectStyleMacro( "__cdecl".toCharArray(), emptyCharArray ); //$NON-NLS-1$
private static final ObjectStyleMacro __complex__ =
new ObjectStyleMacro( "__complex__".toCharArray(), "_Complex".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
private static final ObjectStyleMacro __real__ =
new ObjectStyleMacro( "__real__".toCharArray(), "(int)".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
private static final ObjectStyleMacro __imag__ =
new ObjectStyleMacro( "__imag__".toCharArray(), "(int)".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
private static final FunctionStyleMacro __attribute__
@ -100,6 +106,9 @@ public class GCCScannerExtension implements IScannerExtension {
scannerData.getRealDefinitions().put(__restrict.name, __restrict);
scannerData.getRealDefinitions().put(__volatile__.name, __volatile__);
scannerData.getRealDefinitions().put(__signed__.name, __signed__ );
scannerData.getRealDefinitions().put(__complex__.name, __complex__ );
scannerData.getRealDefinitions().put(__imag__.name, __imag__ );
scannerData.getRealDefinitions().put(__real__.name, __real__ );
if( scannerData.getLanguage() == ParserLanguage.CPP )
scannerData.getRealDefinitions().put(__asm__.name, __asm__);
else
@ -148,6 +157,8 @@ public class GCCScannerExtension implements IScannerExtension {
additionalCPPKeywords.put( GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ );
additionalCPPKeywords.put( GCCKeywords.cpTYPEOF, IGCCToken.t_typeof );
additionalCPPKeywords.put( Keywords.cRESTRICT, IToken.t_restrict );
additionalCPPKeywords.put( Keywords.c_COMPLEX, IToken.t__Complex );
additionalCPPKeywords.put( Keywords.c_IMAGINARY, IToken.t__Imaginary );
additionalCOperators = new CharArrayIntMap(2, -1);
additionalCPPOperators = new CharArrayIntMap( 2, -1);
@ -200,4 +211,18 @@ public class GCCScannerExtension implements IScannerExtension {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isValidNumericLiteralSuffix(char)
*/
public boolean isValidNumericLiteralSuffix(char c) {
switch( c )
{
case 'i':
case 'j':
return true;
default:
return false;
}
}
}

View file

@ -1227,7 +1227,7 @@ public class Scanner2 implements IScanner, IScannerData {
// must be float suffix
++bufferPos[bufferStackPos];
break;
continue;
case 'p':
case 'P':
@ -1290,6 +1290,8 @@ public class Scanner2 implements IScanner, IScannerData {
break;
default:
if( scannerExtension.isValidNumericLiteralSuffix( buffer[pos] ))
continue;
// not part of our number
}