1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

Patch from Devin Steffler with modifications (bug 95757)

This commit is contained in:
Andrew Niefer 2005-05-27 15:44:57 +00:00
parent 349c1e2627
commit 52ae549c9f
18 changed files with 269 additions and 84 deletions

View file

@ -87,6 +87,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType;
import org.eclipse.cdt.core.parser.ParserLanguage;
@ -4429,6 +4430,20 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame(state, col.getName(9).resolveBinding());
}
public void testBug95757() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("float _Complex x;\n"); //$NON-NLS-1$
buffer.append("double _Complex y;\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP, true, true );
IASTDeclaration[] decls = tu.getDeclarations();
assertTrue(((IGPPASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[0]).getDeclSpecifier()).isComplex());
assertEquals(((IGPPASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[0]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_float);
assertTrue(((IGPPASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).isComplex());
assertEquals(((IGPPASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_double);
}
public void testTypedefQualified() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("class _A { \n"); //$NON-NLS-1$

View file

@ -72,6 +72,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
@ -3093,6 +3094,20 @@ public class AST2Tests extends AST2BaseTest {
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
}
public void testBug95757() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("float _Complex x;\n"); //$NON-NLS-1$
buffer.append("double _Complex y;\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, true );
IASTDeclaration[] decls = tu.getDeclarations();
assertTrue(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[0]).getDeclSpecifier()).isComplex());
assertEquals(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[0]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_float);
assertTrue(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).isComplex());
assertEquals(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_double);
}
public void testBug93980() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("int foo(); \n"); //$NON-NLS-1$

View file

@ -133,7 +133,7 @@ public class AST2UtilTests extends AST2BaseTest {
// verify types
isTypeEqual( ((IASTTypeIdExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId(), "int"); //$NON-NLS-1$
isTypeEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "union Squaw"); //$NON-NLS-1$
isTypeEqual( ((IASTCastExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId() , "short"); //$NON-NLS-1$
isTypeEqual( ((IASTCastExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId() , "short int"); //$NON-NLS-1$
}
public void testKnRC() throws Exception {

View file

@ -433,17 +433,13 @@ public class ASTSignatureUtil {
// handle complex cases
if (declSpec instanceof IGPPASTSimpleDeclSpecifier) {
if (((IGPPASTSimpleDeclSpecifier)declSpec).isLongLong()) result.append(Keywords.LONG_LONG);
if (((IGPPASTSimpleDeclSpecifier)declSpec).isComplex()) { if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_COMPLEX); needSpace=true; }
if (((IGPPASTSimpleDeclSpecifier)declSpec).isImaginary()) { if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_IMAGINARY); needSpace=true; }
switch(((IGPPASTSimpleDeclSpecifier)declSpec).getType()) {
case IGPPASTSimpleDeclSpecifier.t_typeof:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(GCCKeywords.TYPEOF); needSpace=true;
break;
case IGPPASTSimpleDeclSpecifier.t_Complex:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_COMPLEX); needSpace=true;
break;
case IGPPASTSimpleDeclSpecifier.t_Imaginary:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_IMAGINARY); needSpace=true;
break;
}
}
@ -460,17 +456,13 @@ public class ASTSignatureUtil {
if (declSpec instanceof ICASTSimpleDeclSpecifier) {
if (((ICASTSimpleDeclSpecifier)declSpec).isLongLong()) { if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.LONG_LONG); needSpace=true; }
if (((ICASTSimpleDeclSpecifier)declSpec).isComplex()) { if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_COMPLEX); needSpace=true; }
if (((ICASTSimpleDeclSpecifier)declSpec).isImaginary()) { if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_IMAGINARY); needSpace=true; }
switch(((ICASTSimpleDeclSpecifier)declSpec).getType()) {
case ICASTSimpleDeclSpecifier.t_Bool:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_BOOL); needSpace=true;
break;
case ICASTSimpleDeclSpecifier.t_Complex:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_COMPLEX); needSpace=true;
break;
case ICASTSimpleDeclSpecifier.t_Imaginary:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_IMAGINARY); needSpace=true;
break;
}
}

View file

@ -119,14 +119,10 @@ public class ASTTypeUtil {
if (type instanceof IGPPBasicType) {
try {
if (((IGPPBasicType)type).isLongLong()) { if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.LONG_LONG); needSpace=true; }
if (((IGPPBasicType)type).isComplex()) { if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_COMPLEX); needSpace=true; }
if (((IGPPBasicType)type).isImaginary()) { if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_IMAGINARY); needSpace=true; }
switch (((IGPPBasicType)type).getType()) {
case IGPPBasicType.t_Complex:
result.append(Keywords.c_COMPLEX);
break;
case IGPPBasicType.t_Imaginary:
result.append(Keywords.c_IMAGINARY);
break;
case IGPPBasicType.t_typeof:
result.append(GCCKeywords.TYPEOF);
break;
@ -145,21 +141,20 @@ public class ASTTypeUtil {
} catch (DOMException e) {}
} else if (type instanceof ICBasicType) {
try {
if (((ICBasicType)type).isComplex()) { if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_COMPLEX); needSpace=true; }
if (((ICBasicType)type).isImaginary()) { if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.c_IMAGINARY); needSpace=true; }
switch (((ICBasicType)type).getType()) {
case ICBasicType.t_Bool:
result.append(Keywords.c_BOOL);
break;
case ICBasicType.t_Complex:
result.append(Keywords.c_COMPLEX);
break;
case ICBasicType.t_Imaginary:
result.append(Keywords.c_IMAGINARY);
break;
}
} catch (DOMException e) {}
}
try {
if( needSpace )
result.append( SPACE );
switch (((IBasicType)type).getType()) {
case IBasicType.t_char:
result.append(Keywords.CHAR);

View file

@ -26,21 +26,35 @@ public interface ICASTSimpleDeclSpecifier extends IASTSimpleDeclSpecifier,
*/
public static final int t_Bool = IASTSimpleDeclSpecifier.t_last + 1;
/**
* <code>t_Complex</code> complex number. e.g. _Complex t;
*/
public static final int t_Complex = IASTSimpleDeclSpecifier.t_last + 2;
/**
* <code>t_Imaginary</code> complex imaginary number. e.g. _Imaginr
*/
public static final int t_Imaginary = IASTSimpleDeclSpecifier.t_last + 3;
/**
* <code>t_last</code> is defined for sub-interfaces.
*/
public static final int t_last = t_Imaginary;
public static final int t_last = t_Bool;
/**
* Is complex number? e.g. _Complex t;
* @return true if it is a complex number, false otherwise
*/
public boolean isComplex();
/**
* Set the number to be complex.
* @param value true if it is a complex number, false otherwise
*/
public void setComplex(boolean value);
/**
* Is imaginary number? e.g. _Imaginr
* @return true if it is an imaginary number, false otherwise
*/
public boolean isImaginary();
/**
* Set the number to be imaginary.
* @param value true if it is an imaginary number, false otherwise
*/
public void setImaginary(boolean value);
// allow for long long's
/**
* Is long long?

View file

@ -23,9 +23,17 @@ public interface ICBasicType extends IBasicType {
// Extra types in C
public static final int t_Bool = ICASTSimpleDeclSpecifier.t_Bool;
public static final int t_Complex = ICASTSimpleDeclSpecifier.t_Complex;
public static final int t_Imaginary = ICASTSimpleDeclSpecifier.t_Imaginary;
/**
* Is complex number? e.g. _Complex t;
* @return true if it is a complex number, false otherwise
*/
public boolean isComplex();
/**
* Is imaginary number? e.g. _Imaginr
* @return true if it is an imaginary number, false otherwise
*/
public boolean isImaginary();
public boolean isLongLong() throws DOMException;
}

View file

@ -22,26 +22,40 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
public interface IGPPASTSimpleDeclSpecifier extends IGPPASTDeclSpecifier,
ICPPASTSimpleDeclSpecifier {
/**
* <code>t_Complex</code> represents a _Complex type.
*/
public static final int t_Complex = ICPPASTSimpleDeclSpecifier.t_last + 1;
/**
* <code>t_Imaginary</code> represents an _Imaginary type.
*/
public static final int t_Imaginary = ICPPASTSimpleDeclSpecifier.t_last + 2;
/**
* <code>t_typeof</code> represents a typeof() expression type.
*/
public static final int t_typeof = ICPPASTSimpleDeclSpecifier.t_last + 3;
public static final int t_typeof = ICPPASTSimpleDeclSpecifier.t_last + 1;
/**
* <code>t_last</code> is for subinterfaces to extend these types.
*/
public static final int t_last = t_typeof;
/**
* Is complex number? e.g. _Complex t;
* @return true if it is a complex number, false otherwise
*/
public boolean isComplex();
/**
* Set the number to be complex.
* @param value true if it is a complex number, false otherwise
*/
public void setComplex(boolean value);
/**
* Is imaginary number? e.g. _Imaginr
* @return true if it is an imaginary number, false otherwise
*/
public boolean isImaginary();
/**
* Set the number to be imaginary.
* @param value true if it is an imaginary number, false otherwise
*/
public void setImaginary(boolean value);
/**
* <code>TYPEOF_EXPRESSION</code> represents the relationship between the
* decl spec & the expression for typeof().

View file

@ -22,12 +22,20 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
*/
public interface IGPPBasicType extends ICPPBasicType {
public static final int t_Complex = IGPPASTSimpleDeclSpecifier.t_Complex;
public static final int t_Imaginary = IGPPASTSimpleDeclSpecifier.t_Imaginary;
public static final int t_typeof = IGPPASTSimpleDeclSpecifier.t_typeof;
/**
* Is complex number? e.g. _Complex t;
* @return true if it is a complex number, false otherwise
*/
public boolean isComplex();
/**
* Is imaginary number? e.g. _Imaginr
* @return true if it is an imaginary number, false otherwise
*/
public boolean isImaginary();
public boolean isLongLong() throws DOMException;
public IType getTypeofType() throws DOMException;

View file

@ -1076,17 +1076,22 @@ public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider {
private void __builtin_conj() {
IBinding temp = null;
ICASTSimpleDeclSpecifier complexSds = new CASTSimpleDeclSpecifier();
complexSds.setType(ICASTSimpleDeclSpecifier.t_Complex);
IType c_double_complex = new CBasicType(complexSds);
IType cpp_double_complex = new CPPBasicType(IGPPBasicType.t_Complex, 0);
IType c_float_complex = c_double_complex;
IType cpp_float_complex = cpp_double_complex;
ICASTSimpleDeclSpecifier doubleComplexSds = new CASTSimpleDeclSpecifier();
doubleComplexSds.setType(IASTSimpleDeclSpecifier.t_double);
doubleComplexSds.setComplex(true);
ICASTSimpleDeclSpecifier floatComplexSds = new CASTSimpleDeclSpecifier();
floatComplexSds.setType(IASTSimpleDeclSpecifier.t_float);
floatComplexSds.setComplex(true);
IType c_double_complex = new CBasicType(doubleComplexSds);
IType cpp_double_complex = new GPPBasicType(IGPPBasicType.t_double, GPPBasicType.IS_COMPLEX, null);
IType c_float_complex = new CBasicType(floatComplexSds);
IType cpp_float_complex = new GPPBasicType(IGPPBasicType.t_float, GPPBasicType.IS_COMPLEX, null);
ICASTSimpleDeclSpecifier longDoubleComplexSds = new CASTSimpleDeclSpecifier();
longDoubleComplexSds.setType(ICASTSimpleDeclSpecifier.t_Complex);
longDoubleComplexSds.setType(IASTSimpleDeclSpecifier.t_double);
longDoubleComplexSds.setComplex(true);
longDoubleComplexSds.setLong(true);
IType c_long_double_complex = new CBasicType(longDoubleComplexSds);
IType cpp_long_double_complex = new CPPBasicType(IGPPBasicType.t_Complex, CPPBasicType.IS_LONG);
IType cpp_long_double_complex = new GPPBasicType(IGPPBasicType.t_double, CPPBasicType.IS_LONG & GPPBasicType.IS_COMPLEX, null);
// double complex __builtin_conj(double complex)
if (lang == ParserLanguage.C) {
@ -1153,17 +1158,22 @@ public class GCCBuiltinSymbolProvider implements IASTBuiltinSymbolProvider {
private void __builtin_creal_cimag() {
IBinding temp = null;
ICASTSimpleDeclSpecifier complexSds = new CASTSimpleDeclSpecifier();
complexSds.setType(ICASTSimpleDeclSpecifier.t_Complex);
IType c_double_complex = new CBasicType(complexSds);
IType cpp_double_complex = new CPPBasicType(IGPPBasicType.t_Complex, 0);
IType c_float_complex = c_double_complex;
IType cpp_float_complex = cpp_double_complex;
ICASTSimpleDeclSpecifier doubleComplexSds = new CASTSimpleDeclSpecifier();
doubleComplexSds.setType(IASTSimpleDeclSpecifier.t_double);
doubleComplexSds.setComplex(true);
ICASTSimpleDeclSpecifier floatComplexSds = new CASTSimpleDeclSpecifier();
floatComplexSds.setType(IASTSimpleDeclSpecifier.t_float);
floatComplexSds.setComplex(true);
IType c_double_complex = new CBasicType(doubleComplexSds);
IType cpp_double_complex = new GPPBasicType(IGPPBasicType.t_double, GPPBasicType.IS_COMPLEX, null);
IType c_float_complex = new CBasicType(floatComplexSds);
IType cpp_float_complex = new GPPBasicType(IGPPBasicType.t_float, GPPBasicType.IS_COMPLEX, null);
ICASTSimpleDeclSpecifier longDoubleComplexSds = new CASTSimpleDeclSpecifier();
longDoubleComplexSds.setType(ICASTSimpleDeclSpecifier.t_Complex);
longDoubleComplexSds.setType(IASTSimpleDeclSpecifier.t_double);
longDoubleComplexSds.setComplex(true);
longDoubleComplexSds.setLong(true);
IType c_long_double_complex = new CBasicType(longDoubleComplexSds);
IType cpp_long_double_complex = new CPPBasicType(IGPPBasicType.t_Complex, CPPBasicType.IS_LONG);
IType cpp_long_double_complex = new GPPBasicType(IGPPBasicType.t_double, CPPBasicType.IS_LONG & GPPBasicType.IS_COMPLEX, null);
ICASTSimpleDeclSpecifier doubleSds = new CASTSimpleDeclSpecifier();
doubleSds.setType(IASTSimpleDeclSpecifier.t_double);
IType c_double = new CBasicType(doubleSds);

View file

@ -23,7 +23,8 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
private boolean isShort;
private boolean isLong;
private boolean longlong;
private boolean complex=false;
private boolean imaginary=false;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#getType()
@ -120,4 +121,32 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier#isComplex()
*/
public boolean isComplex() {
return complex;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier#setComplex(boolean)
*/
public void setComplex(boolean value) {
this.complex = value;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier#isImaginary()
*/
public boolean isImaginary() {
return imaginary;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier#setImaginary(boolean)
*/
public void setImaginary(boolean value) {
this.imaginary = value;
}
}

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
@ -25,6 +26,8 @@ public class CBasicType implements ICBasicType {
static public final int IS_SHORT = 1 << 2;
static public final int IS_SIGNED = 1 << 3;
static public final int IS_UNSIGNED = 1 << 4;
static public final int IS_COMPLEX = 1 << 5;
static public final int IS_IMAGINARY= 1 << 6;
private int type = 0;
private int qualifiers = 0;
@ -41,12 +44,28 @@ public class CBasicType implements ICBasicType {
( sds.isShort() ? CBasicType.IS_SHORT : 0 ) |
( sds.isSigned() ? CBasicType.IS_SIGNED: 0 ) |
( sds.isUnsigned()? CBasicType.IS_UNSIGNED : 0 ) |
( sds.isUnsigned()? CBasicType.IS_LONGLONG : 0 );
( sds.isUnsigned()? CBasicType.IS_LONGLONG : 0 ) |
( sds.isComplex() ? CBasicType.IS_COMPLEX : 0 ) |
( sds.isImaginary()?CBasicType.IS_IMAGINARY : 0 );
if( type == IBasicType.t_unspecified ){
if( (qualifiers & ( IS_COMPLEX | IS_IMAGINARY )) != 0 )
type = IBasicType.t_float;
else if( (qualifiers & ~( IS_COMPLEX | IS_IMAGINARY )) != 0 )
type = IBasicType.t_int;
}
}
public CBasicType( int type, int qualifiers ){
this.type = type;
this.qualifiers = qualifiers;
if( type == IBasicType.t_unspecified ){
if( (qualifiers & ( IS_COMPLEX | IS_IMAGINARY )) != 0 )
type = IBasicType.t_float;
else if( (qualifiers & ~( IS_COMPLEX | IS_IMAGINARY )) != 0 )
type = IBasicType.t_int;
}
}
public CBasicType( int type, int qualifiers, IASTExpression value ){
@ -109,7 +128,9 @@ public class CBasicType implements ICBasicType {
&& cObj.isShort() == this.isShort()
&& cObj.isSigned() == this.isSigned()
&& cObj.isUnsigned() == this.isUnsigned()
&& cObj.isLongLong() == this.isLongLong());
&& cObj.isLongLong() == this.isLongLong()
&& cObj.isComplex() == this.isComplex()
&& cObj.isImaginary() == this.isImaginary());
}
public Object clone(){
@ -132,4 +153,18 @@ public class CBasicType implements ICBasicType {
public void setValue( IASTExpression expression ){
this.value = expression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICBasicType#isComplex()
*/
public boolean isComplex() {
return ( qualifiers & IS_COMPLEX) != 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICBasicType#isImaginary()
*/
public boolean isImaginary() {
return ( qualifiers & IS_IMAGINARY) != 0;
}
}

View file

@ -1337,6 +1337,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
boolean isInline = false;
boolean isConst = false, isRestrict = false, isVolatile = false;
boolean isShort = false, isLong = false, isUnsigned = false, isIdentifier = false, isSigned = false, isLongLong = false;
boolean isComplex = false, isImaginary = false;
int simpleType = IASTSimpleDeclSpecifier.t_unspecified;
IToken identifier = null;
IASTCompositeTypeSpecifier structSpec = null;
@ -1446,11 +1447,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
break;
case IToken.t__Complex:
last = consume(IToken.t__Complex);
simpleType = ICASTSimpleDeclSpecifier.t_Complex;
isComplex=true;
break;
case IToken.t__Imaginary:
last = consume(IToken.t__Imaginary);
simpleType = ICASTSimpleDeclSpecifier.t_Imaginary;
isImaginary=true;
break;
case IToken.tIDENTIFIER:
@ -1617,6 +1618,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
declSpec.setUnsigned(isUnsigned);
declSpec.setSigned(isSigned);
declSpec.setShort(isShort);
declSpec.setComplex(isComplex);
declSpec.setImaginary(isImaginary);
if( typeofExpression != null && last == null ){
((ASTNode)declSpec).setOffsetAndLength( (ASTNode)typeofExpression );
} else {

View file

@ -14,6 +14,7 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
@ -35,6 +36,11 @@ public class CPPBasicType implements ICPPBasicType {
public CPPBasicType( int t, int bits ){
type = t;
qualifierBits = bits;
if( type == IBasicType.t_unspecified ){
if( (qualifierBits & ( IS_LONG | IS_SHORT | IS_SIGNED | IS_UNSIGNED )) != 0 )
type = IBasicType.t_int;
}
}
public CPPBasicType( int t, int bits, IASTExpression val ){

View file

@ -2708,7 +2708,8 @@ public class CPPSemantics {
if( src instanceof IBasicType && trg instanceof IBasicType ){
int sType = ((IBasicType)src).getType();
int tType = ((IBasicType)trg).getType();
if( ( tType == IBasicType.t_int && ( sType == IBasicType.t_char ||
if( ( tType == IBasicType.t_int && ( sType == IBasicType.t_int || //short, long , unsigned etc
sType == IBasicType.t_char ||
sType == ICPPBasicType.t_bool ||
sType == ICPPBasicType.t_wchar_t ||
sType == IBasicType.t_unspecified ) ) || //treat unspecified as int

View file

@ -3169,6 +3169,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
boolean isInline = false, isVirtual = false, isExplicit = false, isFriend = false;
boolean isConst = false, isVolatile = false, isRestrict = false;
boolean isLong = false, isShort = false, isUnsigned = false, isSigned = false, isLongLong = false;
boolean isComplex = false, isImaginary = false;
boolean isTypename = false;
int storageClass = IASTDeclSpecifier.sc_unspecified;
@ -3271,7 +3272,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
- la.getOffset());
}
last = consume(IToken.t__Complex);
simpleType = IGPPASTSimpleDeclSpecifier.t_Complex;
isComplex=true;
break;
case IToken.t__Imaginary:
if (!supportComplex) {
@ -3279,7 +3280,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
throwBacktrack(la.getOffset(), la.getLength());
}
last = consume(IToken.t__Imaginary);
simpleType = IGPPASTSimpleDeclSpecifier.t_Imaginary;
isImaginary=true;
break;
case IToken.t_char:
simpleType = IASTSimpleDeclSpecifier.t_char;
@ -3487,10 +3488,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return nameSpec;
}
ICPPASTSimpleDeclSpecifier simpleDeclSpec = null;
if (isLongLong || typeofExpression != null) {
if (isComplex || isImaginary || isLongLong || typeofExpression != null) {
simpleDeclSpec = createGPPSimpleDeclSpecifier();
((IGPPASTSimpleDeclSpecifier) simpleDeclSpec)
.setLongLong(isLongLong);
((IGPPASTSimpleDeclSpecifier) simpleDeclSpec)
.setComplex(isComplex);
((IGPPASTSimpleDeclSpecifier) simpleDeclSpec)
.setImaginary(isImaginary);
if (typeofExpression != null) {
((IGPPASTSimpleDeclSpecifier) simpleDeclSpec)
.setTypeofExpression(typeofExpression);
@ -3524,7 +3529,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
simpleDeclSpec.setShort(isShort);
simpleDeclSpec.setUnsigned(isUnsigned);
simpleDeclSpec.setSigned(isSigned);
return simpleDeclSpec;
}

View file

@ -22,6 +22,8 @@ public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier
private boolean longLong;
private boolean restrict;
private boolean complex=false;
private boolean imaginary=false;
private IASTExpression typeOfExpression;
/* (non-Javadoc)
@ -79,4 +81,20 @@ public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier
return true;
}
public boolean isComplex() {
return complex;
}
public void setComplex(boolean value) {
this.complex = value;
}
public boolean isImaginary() {
return imaginary;
}
public void setImaginary(boolean value) {
this.imaginary = value;
}
}

View file

@ -13,6 +13,7 @@
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType;
@ -22,12 +23,20 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType;
*/
public class GPPBasicType extends CPPBasicType implements IGPPBasicType {
public static final int IS_LONGLONG = LAST << 1;
public static final int IS_COMPLEX = LAST << 2;
public static final int IS_IMAGINARY = LAST << 3;
private IType typeOf;
public GPPBasicType( int type, int bits, IType typeOf ){
super( type, bits );
this.typeOf = typeOf;
if( type == IBasicType.t_unspecified ){
if((qualifierBits & ( IS_COMPLEX | IS_IMAGINARY )) != 0 )
type = IBasicType.t_float;
else if( (qualifierBits & IS_LONGLONG) != 0 )
type = IBasicType.t_int;
}
}
/* (non-Javadoc)
@ -46,4 +55,12 @@ public class GPPBasicType extends CPPBasicType implements IGPPBasicType {
return typeOf;
}
public boolean isComplex() {
return ( qualifierBits & IS_COMPLEX ) != 0;
}
public boolean isImaginary() {
return ( qualifierBits & IS_IMAGINARY ) != 0;
}
}