1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Pushes commonalities of c and c++ into IBasicType, bug 231859.

This commit is contained in:
Markus Schorn 2009-10-08 16:13:54 +00:00
parent 8eafa2bdd7
commit 2bc7bae4a4
44 changed files with 776 additions and 760 deletions

View file

@ -18,7 +18,6 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
@ -98,14 +97,12 @@ 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.ICBasicType;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@ -6281,12 +6278,9 @@ public class AST2Tests extends AST2BaseTest {
}
}
boolean isLongLong(IType t) throws DOMException {
if (t instanceof ICBasicType) {
return ((ICBasicType) t).isLongLong();
}
if (t instanceof IGPPBasicType) {
return ((IGPPBasicType) t).isLongLong();
boolean isLongLong(IType t) {
if (t instanceof IBasicType) {
return ((IBasicType) t).isLongLong();
}
return false;
}

View file

@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
@ -1528,8 +1529,8 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
IBinding inst2= CPPTemplates.instantiate(tmplDef, inst.getTemplateArguments());
assertSame(inst, inst2);
IBinding charInst1= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateArgument(new CPPBasicType(IBasicType.t_char, 0))});
IBinding charInst2= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateArgument(new CPPBasicType(IBasicType.t_char, 0))});
IBinding charInst1= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateArgument(new CPPBasicType(Kind.eChar, 0))});
IBinding charInst2= CPPTemplates.instantiate(tmplDef, new ICPPTemplateArgument[] {new CPPTemplateArgument(new CPPBasicType(Kind.eChar, 0))});
assertSame(charInst1, charInst2);
}

View file

@ -18,8 +18,8 @@ import java.util.BitSet;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.core.dom.ast.c.ICPointerType;
import org.eclipse.cdt.core.dom.ast.c.ICQualifierType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
@ -32,10 +32,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPQualifierType;
import org.eclipse.cdt.core.parser.GCCKeywords;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
@ -99,7 +97,7 @@ public class ASTTypeUtil {
IType ultimateType = SemanticUtil.getNestedType(parameters[0].getType(), TDEF);
if (ultimateType instanceof IBasicType) {
if (((IBasicType) ultimateType).getType() == IBasicType.t_void) {
if (((IBasicType) ultimateType).getKind() == Kind.eVoid) {
return false;
}
}
@ -248,10 +246,10 @@ public class ASTTypeUtil {
result.append(Keywords.cpRBRACKET);
} else if (type instanceof IBasicType) {
IBasicType basicType= (IBasicType) type;
try {
final Kind kind = basicType.getKind();
if (basicType.isSigned()) {
// 3.9.1.2: signed integer types
if (!normalize || basicType.getType() == IBasicType.t_char) {
if (!normalize || kind == Kind.eChar) {
result.append(Keywords.SIGNED); needSpace = true;
}
} else if (basicType.isUnsigned()) {
@ -270,98 +268,61 @@ public class ASTTypeUtil {
result.append(SPACE); needSpace = false;
}
result.append(Keywords.SHORT); needSpace = true;
}
} catch (DOMException e) {
}
if (type instanceof IGPPBasicType) {
try {
if (((IGPPBasicType) type).isLongLong()) {
} else if (basicType.isLongLong()) {
if (needSpace) {
result.append(SPACE); needSpace = false;
}
result.append(Keywords.LONG_LONG); needSpace = true;
}
if (((IGPPBasicType) type).isComplex()) {
if (basicType.isComplex()) {
if (needSpace) {
result.append(SPACE); needSpace = false;
}
result.append(Keywords.c_COMPLEX); needSpace = true;
}
if (((IGPPBasicType) type).isImaginary()) {
if ((basicType).isImaginary()) {
if (needSpace) {
result.append(SPACE); needSpace = false;
}
result.append(Keywords.c_IMAGINARY); needSpace = true;
}
switch (((IGPPBasicType) type).getType()) {
case IGPPBasicType.t_typeof:
result.append(GCCKeywords.TYPEOF);
break;
}
} catch (DOMException e) {
}
} else if (type instanceof ICPPBasicType) {
try {
switch (((ICPPBasicType) type).getType()) {
case ICPPBasicType.t_bool:
result.append(Keywords.BOOL);
break;
case ICPPBasicType.t_wchar_t:
result.append(Keywords.WCHAR_T);
break;
}
} 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;
}
} catch (DOMException e) {
}
}
try {
switch (basicType.getType()) {
case IBasicType.t_char:
switch (kind) {
case eChar:
if (needSpace) result.append(SPACE);
result.append(Keywords.CHAR);
break;
case IBasicType.t_double:
case eDouble:
if (needSpace) result.append(SPACE);
result.append(Keywords.DOUBLE);
break;
case IBasicType.t_float:
case eFloat:
if (needSpace) result.append(SPACE);
result.append(Keywords.FLOAT);
break;
case IBasicType.t_int:
case eInt:
if (needSpace) result.append(SPACE);
result.append(Keywords.INT);
break;
case IBasicType.t_void:
case eVoid:
if (needSpace) result.append(SPACE);
result.append(Keywords.VOID);
break;
case eBoolean:
if (needSpace) result.append(SPACE);
if (basicType instanceof ICPPBasicType) {
result.append(Keywords.BOOL);
} else {
result.append(Keywords.c_BOOL);
}
} catch (DOMException e) {
break;
case eWChar:
if (needSpace) result.append(SPACE);
result.append(Keywords.WCHAR_T);
break;
case eUnspecified:
break;
}
} else if (type instanceof ICPPTemplateParameter) {
final ICPPTemplateParameter tpar = (ICPPTemplateParameter) type;

View file

@ -7,11 +7,14 @@
*
* Contributors:
* Doug Schaefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
/**
* This represents a decl specifier for a built-in type.
* This represents a declaration specifier for a built-in type.
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
@ -71,6 +74,12 @@ public interface IASTSimpleDeclSpecifier extends IASTDeclSpecifier {
*/
public void setType(int type);
/**
* Sets this declaration specifier to the type based on {@link IBasicType.Kind}.
* @since 5.2
*/
public void setType(Kind kind);
/**
* Is the type modified by the signed keyword?
*

View file

@ -18,13 +18,48 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IBasicType extends IType {
/**
* @since 5.2
*/
enum Kind {
eUnspecified, eVoid, eChar, eWChar, eInt, eFloat, eDouble, eBoolean
}
/**
* This returns the built-in type for the declaration. The type is
* then refined by qualifiers for signed/unsigned and short/long.
* The type could also be unspecified which usually means int.
*
* This returns the kind of basic type you are looking at. The type is
* then refined by qualifiers for signed/unsigned and short/long/long long.
* @since 5.2
*/
Kind getKind();
public boolean isSigned();
public boolean isUnsigned();
public boolean isShort();
public boolean isLong();
/**
* @since 5.2
*/
public boolean isLongLong();
/**
* Is complex number? e.g. _Complex t;
* @return true if it is a complex number, false otherwise
* @since 5.2
*/
public boolean isComplex();
/**
* Is imaginary number? e.g. _Imaginr
* @return true if it is an imaginary number, false otherwise
* @since 5.2
*/
public boolean isImaginary();
/**
* @deprecated, use the type-safe version getKind(), instead.
*/
@Deprecated
public int getType() throws DOMException;
/**
@ -33,15 +68,34 @@ public interface IBasicType extends IType {
@Deprecated
public IASTExpression getValue() throws DOMException;
/**
* @deprecated, use the type-safe version getKind(), instead.
*/
@Deprecated
public static final int t_unspecified = IASTSimpleDeclSpecifier.t_unspecified;
/**
* @deprecated, use the type-safe version getKind(), instead.
*/
@Deprecated
public static final int t_void = IASTSimpleDeclSpecifier.t_void;
/**
* @deprecated, use the type-safe version getKind(), instead.
*/
@Deprecated
public static final int t_char = IASTSimpleDeclSpecifier.t_char;
/**
* @deprecated, use the type-safe version getKind(), instead.
*/
@Deprecated
public static final int t_int = IASTSimpleDeclSpecifier.t_int;
/**
* @deprecated, use the type-safe version getKind(), instead.
*/
@Deprecated
public static final int t_float = IASTSimpleDeclSpecifier.t_float;
/**
* @deprecated, use the type-safe version getKind(), instead.
*/
@Deprecated
public static final int t_double = IASTSimpleDeclSpecifier.t_double;
public boolean isSigned() throws DOMException;
public boolean isUnsigned() throws DOMException;
public boolean isShort() throws DOMException;
public boolean isLong() throws DOMException;
}

View file

@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBasicType;
/**
@ -18,20 +17,9 @@ import org.eclipse.cdt.core.dom.ast.IBasicType;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICBasicType extends IBasicType {
// Extra types in C
/**
* @deprecated, use the type-safe version getKind(), instead.
*/
@Deprecated
public static final int t_Bool = ICASTSimpleDeclSpecifier.t_Bool;
/**
* 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,19 +22,26 @@ public interface ICPPBasicType extends IBasicType {
public static final int IS_SHORT = 1 << 1;
public static final int IS_SIGNED = 1 << 2;
public static final int IS_UNSIGNED = 1 << 3;
public static final int IS_COMPLEX = 1 << 4; // for gpp-types
public static final int IS_IMAGINARY = 1 << 5; // for gpp-types
public static final int IS_LONG_LONG = 1 << 6; // for gpp-types
public static final int IS_COMPLEX = 1 << 4;
public static final int IS_IMAGINARY = 1 << 5;
public static final int IS_LONG_LONG = 1 << 6;
public static final int LAST = IS_LONG_LONG;
// Extra types
public static final int t_bool = ICPPASTSimpleDeclSpecifier.t_bool;
public static final int t_wchar_t = ICPPASTSimpleDeclSpecifier.t_wchar_t;
/**
* @return a combination of qualifiers.
* @since 4.0
*/
public int getQualifierBits();
/**
* @deprecated, use the type-safe version getKind(), instead.
*/
@Deprecated
public static final int t_bool = ICPPASTSimpleDeclSpecifier.t_bool;
/**
* @deprecated, use the type-safe version getKind(), instead.
*/
@Deprecated
public static final int t_wchar_t = ICPPASTSimpleDeclSpecifier.t_wchar_t;
}

View file

@ -17,24 +17,21 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
/**
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
* @deprecated use {@link ICPPBasicType}, instead.
*/
@Deprecated
public interface IGPPBasicType extends ICPPBasicType {
/**
* @deprecated don't use this constant.
*/
@Deprecated
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
* @deprecated don't use this method.
*/
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;
@Deprecated
public IType getTypeofType() throws DOMException;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others.
* Copyright (c) 2005, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -13,10 +13,10 @@
package org.eclipse.cdt.internal.core.dom.parser;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType;
@ -37,9 +37,8 @@ public class CBuiltinSymbolProvider implements IBuiltinBindingsProvider {
static final private IType c_char;
static final private IType c_const_char_p;
static {
new CBasicType(IBasicType.t_unspecified, 0);
c_char = new CBasicType( IBasicType.t_char, 0 );
c_const_char_p = new CPointerType(new CQualifierType( c_char, true, false, false), 0);
c_char = new CBasicType(Kind.eChar, 0);
c_const_char_p = new CPointerType(new CQualifierType(c_char, true, false, false), 0);
}
private IBinding[] bindings=new IBinding[NUM_BUILTINS];

View file

@ -15,13 +15,13 @@ package org.eclipse.cdt.internal.core.dom.parser;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
@ -43,7 +43,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTypedef;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPPointerType;
import org.eclipse.core.runtime.PlatformObject;
@ -287,35 +286,35 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
static final private IType cpp_FILE_p_r; // implemented as void* restrict
static {
c_unspecified = new CBasicType(IBasicType.t_unspecified, 0);
c_char = new CBasicType(IBasicType.t_char, 0);
c_unspecified = new CBasicType(Kind.eUnspecified, 0);
c_char = new CBasicType(Kind.eChar, 0);
c_char_p = new CPointerType(c_char, 0);
c_char_p_r = new CPointerType(c_char, CPointerType.IS_RESTRICT);
c_const_char_p = new CPointerType(new CQualifierType(c_char, true, false, false), 0);
c_const_char_p_r = new CPointerType(new CQualifierType(c_char, true, false, false), CPointerType.IS_RESTRICT);
c_double = new CBasicType(IBasicType.t_double, 0);
c_double_complex = new CBasicType(IBasicType.t_double, CBasicType.IS_COMPLEX);
c_float = new CBasicType(IBasicType.t_float, 0);
c_float_complex = new CBasicType(IBasicType.t_float, CBasicType.IS_COMPLEX);
c_double = new CBasicType(Kind.eDouble, 0);
c_double_complex = new CBasicType(Kind.eDouble, CBasicType.IS_COMPLEX);
c_float = new CBasicType(Kind.eFloat, 0);
c_float_complex = new CBasicType(Kind.eFloat, CBasicType.IS_COMPLEX);
c_float_p = new CPointerType(c_float, 0);
c_int = new CBasicType(IBasicType.t_int, 0);
c_int = new CBasicType(Kind.eInt, 0);
c_int_p = new CPointerType(c_int, 0);
c_long_double = new CBasicType(IBasicType.t_double, CBasicType.IS_LONG);
c_long_double_complex = new CBasicType(IBasicType.t_double, CBasicType.IS_LONG | CBasicType.IS_COMPLEX);
c_long_double = new CBasicType(Kind.eDouble, CBasicType.IS_LONG);
c_long_double_complex = new CBasicType(Kind.eDouble, CBasicType.IS_LONG | CBasicType.IS_COMPLEX);
c_long_double_p = new CPointerType(c_long_double, 0);
c_long_int = new CBasicType(IBasicType.t_int, CBasicType.IS_LONG);
c_long_long_int = new CBasicType(IBasicType.t_int, CBasicType.IS_LONGLONG);
c_signed_long_int = new CBasicType(IBasicType.t_int, CBasicType.IS_LONG | CBasicType.IS_SIGNED);
c_unsigned_int = new CBasicType(IBasicType.t_int, CBasicType.IS_UNSIGNED);
c_unsigned_long = new CBasicType(IBasicType.t_int, CBasicType.IS_LONG | CBasicType.IS_UNSIGNED);
c_unsigned_long_long = new CBasicType(IBasicType.t_int, CBasicType.IS_LONGLONG | CBasicType.IS_UNSIGNED);
c_long_int = new CBasicType(Kind.eInt, CBasicType.IS_LONG);
c_long_long_int = new CBasicType(Kind.eInt, CBasicType.IS_LONGLONG);
c_signed_long_int = new CBasicType(Kind.eInt, CBasicType.IS_LONG | CBasicType.IS_SIGNED);
c_unsigned_int = new CBasicType(Kind.eInt, CBasicType.IS_UNSIGNED);
c_unsigned_long = new CBasicType(Kind.eInt, CBasicType.IS_LONG | CBasicType.IS_UNSIGNED);
c_unsigned_long_long = new CBasicType(Kind.eInt, CBasicType.IS_LONGLONG | CBasicType.IS_UNSIGNED);
c_va_list = new CFunctionType(c_char_p, new IType[0]); // assumed: char* va_list();
c_size_t = c_unsigned_long; // assumed unsigned long int
c_void = new CBasicType(IBasicType.t_void, 0);
c_void = new CBasicType(Kind.eVoid, 0);
c_void_p = new CPointerType(c_void, 0);
c_void_p_r = new CPointerType(c_void, CPointerType.IS_RESTRICT);
c_const_void_p = new CPointerType(new CQualifierType(c_void, true, false, false), 0);
@ -323,35 +322,35 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
c_FILE_p_r = c_void_p_r; // implemented as void* restrict
cpp_unspecified = new CPPBasicType(IBasicType.t_unspecified, 0);
cpp_char = new CPPBasicType(IBasicType.t_char, 0);
cpp_unspecified = new CPPBasicType(Kind.eUnspecified, 0);
cpp_char = new CPPBasicType(Kind.eChar, 0);
cpp_char_p = new CPPPointerType(cpp_char);
cpp_char_p_r = new GPPPointerType(cpp_char, false, false, true);
cpp_const_char_p = new CPPPointerType(new CPPQualifierType(cpp_char, true, false));
cpp_const_char_p_r = new GPPPointerType(new CPPQualifierType(cpp_char, true, false), false, false, true);
cpp_double = new CPPBasicType(IBasicType.t_double, 0);
cpp_double_complex = new GPPBasicType(IBasicType.t_double, ICPPBasicType.IS_COMPLEX, null);
cpp_float = new CPPBasicType(IBasicType.t_float, 0);
cpp_float_complex = new GPPBasicType(IBasicType.t_float, ICPPBasicType.IS_COMPLEX, null);
cpp_double = new CPPBasicType(Kind.eDouble, 0);
cpp_double_complex = new CPPBasicType(Kind.eDouble, ICPPBasicType.IS_COMPLEX, null);
cpp_float = new CPPBasicType(Kind.eFloat, 0);
cpp_float_complex = new CPPBasicType(Kind.eFloat, ICPPBasicType.IS_COMPLEX, null);
cpp_float_p = new CPPPointerType(cpp_float);
cpp_int = new CPPBasicType(IBasicType.t_int, 0);
cpp_int = new CPPBasicType(Kind.eInt, 0);
cpp_int_p = new CPPPointerType(cpp_int);
cpp_long_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG);
cpp_long_double = new CPPBasicType(IBasicType.t_double, ICPPBasicType.IS_LONG);
cpp_long_double_complex = new GPPBasicType(IBasicType.t_double, ICPPBasicType.IS_LONG | ICPPBasicType.IS_COMPLEX, null);
cpp_long_int = new CPPBasicType(Kind.eInt, ICPPBasicType.IS_LONG);
cpp_long_double = new CPPBasicType(Kind.eDouble, ICPPBasicType.IS_LONG);
cpp_long_double_complex = new CPPBasicType(Kind.eDouble, ICPPBasicType.IS_LONG | ICPPBasicType.IS_COMPLEX, null);
cpp_long_double_p = new CPPPointerType(cpp_long_double);
cpp_long_long_int = new GPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG_LONG, null);
cpp_signed_long_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_SIGNED);
cpp_long_long_int = new CPPBasicType(Kind.eInt, ICPPBasicType.IS_LONG_LONG, null);
cpp_signed_long_int = new CPPBasicType(Kind.eInt, ICPPBasicType.IS_LONG | ICPPBasicType.IS_SIGNED);
cpp_unsigned_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED);
cpp_unsigned_long = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED | ICPPBasicType.IS_LONG);
cpp_unsigned_long_long = new GPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED | ICPPBasicType.IS_LONG_LONG, null);
cpp_unsigned_int = new CPPBasicType(Kind.eInt, ICPPBasicType.IS_UNSIGNED);
cpp_unsigned_long = new CPPBasicType(Kind.eInt, ICPPBasicType.IS_UNSIGNED | ICPPBasicType.IS_LONG);
cpp_unsigned_long_long = new CPPBasicType(Kind.eInt, ICPPBasicType.IS_UNSIGNED | ICPPBasicType.IS_LONG_LONG, null);
cpp_size_t = cpp_unsigned_long; // assumed unsigned long int
cpp_va_list = new CPPFunctionType(cpp_char_p, new IType[0]); // assumed: char* va_list();
cpp_void = new CPPBasicType(IBasicType.t_void, 0);
cpp_void = new CPPBasicType(Kind.eVoid, 0);
cpp_void_p = new CPPPointerType(cpp_void);
cpp_void_p_r = new GPPPointerType(cpp_void, false, false, true);
cpp_const_void_p = new CPPPointerType(new CPPQualifierType(cpp_void, true, false));

View file

@ -16,9 +16,9 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
@ -137,9 +137,7 @@ public class CASTBinaryExpression extends ASTNode implements
case op_logicalOr:
case op_equals:
case op_notequals:
CBasicType basicType = new CBasicType(IBasicType.t_int, 0);
basicType.setValue(this);
return basicType;
return new CBasicType(Kind.eInt, 0, this);
case IASTBinaryExpression.op_plus:
IType t2 = getOperand2().getExpressionType();
if (CVisitor.unwrapTypedefs(t2) instanceof IPointerType) {

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@ -86,13 +87,13 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress
public IType getExpressionType() {
switch (getKind()) {
case IASTLiteralExpression.lk_char_constant:
return new CBasicType(IBasicType.t_char, 0, this);
return new CBasicType(IBasicType.Kind.eChar, 0, this);
case IASTLiteralExpression.lk_float_constant:
return classifyTypeOfFloatLiteral();
case IASTLiteralExpression.lk_integer_constant:
return classifyTypeOfIntLiteral();
case IASTLiteralExpression.lk_string_literal:
IType type = new CBasicType(IBasicType.t_char, 0, this);
IType type = new CBasicType(IBasicType.Kind.eChar, 0, this);
type = new CQualifierType(type, true, false, false);
return new CPointerType(type, 0);
}
@ -102,15 +103,14 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress
private IType classifyTypeOfFloatLiteral() {
final char[] lit= getValue();
final int len= lit.length;
int kind= IBasicType.t_double;
IBasicType.Kind kind= IBasicType.Kind.eDouble;
int flags= 0;
if (len > 0) {
switch (lit[len - 1]) {
case 'f': case 'F':
kind= IBasicType.t_float;
kind= Kind.eFloat;
break;
case 'l': case 'L':
kind= IBasicType.t_double;
flags |= CBasicType.IS_LONG;
break;
}
@ -151,7 +151,7 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress
} else if (makelong == 1) {
flags |= CBasicType.IS_LONG;
}
return new CBasicType(IBasicType.t_int, flags, this);
return new CBasicType(IBasicType.Kind.eInt, flags, this);
}

View file

@ -1,22 +1,21 @@
/*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others.
* Copyright (c) 2005, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* John Camelon (IBM Rational Software) - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
/**
* @author jcamelon
*/
public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements ICASTSimpleDeclSpecifier {
private int simpleType;
@ -72,6 +71,31 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
simpleType = type;
}
public void setType(Kind kind) {
setType(getType(kind));
}
private int getType(Kind kind) {
switch(kind) {
case eBoolean:
return t_Bool;
case eChar:
case eWChar:
return t_char;
case eDouble:
return t_double;
case eFloat:
return t_float;
case eInt:
return t_int;
case eUnspecified:
return t_unspecified;
case eVoid:
return t_void;
}
return t_unspecified;
}
public void setShort(boolean value) {
assertNotFrozen();
isShort = value;

View file

@ -6,115 +6,105 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Devin Steffler (IBM Rational Software) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
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.IASTSimpleDeclSpecifier;
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;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.internal.core.index.IIndexType;
/**
* @author dsteffle
*/
public class CBasicType implements ICBasicType {
static public final int IS_LONG = 1;
static public final int IS_LONGLONG = 1 << 1;
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;
public final static int IS_LONG = 1;
public final static int IS_LONGLONG = 1 << 1;
public final static int IS_SHORT = 1 << 2;
public final static int IS_SIGNED = 1 << 3;
public final static int IS_UNSIGNED = 1 << 4;
public final static int IS_COMPLEX = 1 << 5;
public final static int IS_IMAGINARY= 1 << 6;
private int type = 0;
private final Kind fKind;
private int qualifiers = 0;
private IASTExpression value = null;
/**
* keep a reference to the declaration specifier so that duplicate information isn't generated.
*
* @param sds the simple declaration specifier
*/
public CBasicType(Kind kind, int qualifiers, IASTExpression value ){
if (kind == Kind.eUnspecified) {
if ( (qualifiers & (IS_COMPLEX | IS_IMAGINARY)) != 0) {
fKind= Kind.eFloat;
} else {
fKind= Kind.eInt;
}
} else {
fKind= kind;
}
this.qualifiers = qualifiers;
this.value = value;
}
public CBasicType(Kind kind, int qualifiers) {
this(kind, qualifiers, null);
}
public CBasicType(ICASTSimpleDeclSpecifier sds) {
this.type = sds.getType();
this.qualifiers = ( sds.isLong() ? CBasicType.IS_LONG : 0 ) |
this (getKind(sds), getQualifiers(sds), null);
}
private static int getQualifiers(ICASTSimpleDeclSpecifier sds) {
return ( sds.isLong() ? CBasicType.IS_LONG : 0 ) |
( sds.isShort() ? CBasicType.IS_SHORT : 0 ) |
( sds.isSigned() ? CBasicType.IS_SIGNED: 0 ) |
( sds.isUnsigned()? CBasicType.IS_UNSIGNED : 0 ) |
( sds.isLongLong()? 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 {
type = IBasicType.t_int;
}
private static Kind getKind(ICASTSimpleDeclSpecifier sds) {
switch(sds.getType()) {
case ICASTSimpleDeclSpecifier.t_Bool:
return Kind.eBoolean;
case IASTSimpleDeclSpecifier.t_char:
return Kind.eChar;
case IASTSimpleDeclSpecifier.t_double:
return Kind.eDouble;
case IASTSimpleDeclSpecifier.t_float:
return Kind.eFloat;
case IASTSimpleDeclSpecifier.t_int:
return Kind.eInt;
case IASTSimpleDeclSpecifier.t_void:
return Kind.eVoid;
default:
return Kind.eUnspecified;
}
}
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 {
type = IBasicType.t_int;
}
}
public Kind getKind() {
return fKind;
}
public CBasicType( int type, int qualifiers, IASTExpression value ){
this.type = type;
this.qualifiers = qualifiers;
this.value = value;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBasicType#getType()
*/
public int getType() {
return type;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBasicType#isSigned()
*/
public boolean isSigned() {
return ( qualifiers & IS_SIGNED) != 0;
return (qualifiers & IS_SIGNED) != 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBasicType#isUnsigned()
*/
public boolean isUnsigned() {
return ( qualifiers & IS_UNSIGNED) != 0;
return (qualifiers & IS_UNSIGNED) != 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBasicType#isShort()
*/
public boolean isShort() {
return ( qualifiers & IS_SHORT) != 0;
return (qualifiers & IS_SHORT) != 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBasicType#isLong()
*/
public boolean isLong() {
return ( qualifiers & IS_LONG) != 0;
return (qualifiers & IS_LONG) != 0;
}
public boolean isLongLong() {
return ( qualifiers & IS_LONGLONG) != 0;
return (qualifiers & IS_LONGLONG) != 0;
}
public boolean isSameType(IType obj) {
@ -127,11 +117,11 @@ public class CBasicType implements ICBasicType {
CBasicType cObj = (CBasicType)obj;
if (type != cObj.type) {
if (fKind != cObj.fKind) {
return false;
}
if (type == IBasicType.t_int) {
if (fKind == Kind.eInt) {
//signed int and int are equivalent
return (qualifiers & ~IS_SIGNED) == (cObj.qualifiers & ~IS_SIGNED);
} else {
@ -155,10 +145,6 @@ public class CBasicType implements ICBasicType {
return value;
}
public void setValue( IASTExpression expression ){
this.value = expression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICBasicType#isComplex()
*/
@ -172,4 +158,26 @@ public class CBasicType implements ICBasicType {
public boolean isImaginary() {
return ( qualifiers & IS_IMAGINARY) != 0;
}
@Deprecated
public int getType() {
switch (fKind) {
case eBoolean:
return t_Bool;
case eChar:
case eWChar:
return t_char;
case eDouble:
return t_double;
case eFloat:
return t_float;
case eInt:
return t_int;
case eVoid:
return t_void;
case eUnspecified:
return t_unspecified;
}
return t_unspecified;
}
}

View file

@ -52,7 +52,6 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
@ -68,6 +67,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
@ -651,9 +651,7 @@ public class CVisitor extends ASTQueries {
} catch (DOMException e) {
}
CBasicType basicType = new CBasicType(IBasicType.t_int, CBasicType.IS_UNSIGNED | CBasicType.IS_LONG);
basicType.setValue(expr);
return basicType;
return new CBasicType(Kind.eInt, CBasicType.IS_UNSIGNED | CBasicType.IS_LONG, expr);
}
static IType getSize_T(IASTExpression expr) {
@ -665,7 +663,7 @@ public class CVisitor extends ASTQueries {
}
} catch (DOMException e) {
}
return new CBasicType(IBasicType.t_int, CBasicType.IS_LONG | CBasicType.IS_UNSIGNED);
return new CBasicType(Kind.eInt, CBasicType.IS_LONG | CBasicType.IS_UNSIGNED);
}
static IType unwrapTypedefs(IType type) {

View file

@ -8,6 +8,7 @@
* Contributors:
* John Camelon (IBM) - Initial API and implementation
* Mike Kucera (IBM)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -20,8 +21,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@ -204,9 +205,7 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
case IASTBinaryExpression.op_logicalOr:
case IASTBinaryExpression.op_equals:
case IASTBinaryExpression.op_notequals:
CPPBasicType basicType= new CPPBasicType(ICPPBasicType.t_bool, 0);
basicType.setFromExpression(this);
return basicType;
return new CPPBasicType(Kind.eBoolean, 0, this);
case IASTBinaryExpression.op_plus:
if (ultimateType2 instanceof IPointerType) {
return ultimateType2;

View file

@ -12,9 +12,9 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@ -96,7 +96,7 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
}
case lk_true:
case lk_false:
return new CPPBasicType(ICPPBasicType.t_bool, 0, this);
return new CPPBasicType(Kind.eBoolean, 0, this);
case lk_char_constant:
return new CPPBasicType(getCharType(), 0, this);
case lk_float_constant:
@ -111,19 +111,19 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
return null;
}
private int getCharType() {
return getValue()[0] == 'L' ? ICPPBasicType.t_wchar_t : IBasicType.t_char;
private Kind getCharType() {
return getValue()[0] == 'L' ? Kind.eWChar : Kind.eChar;
}
private IType classifyTypeOfFloatLiteral() {
final char[] lit= getValue();
final int len= lit.length;
int kind= IBasicType.t_double;
Kind kind= Kind.eDouble;
int flags= 0;
if (len > 0) {
switch (lit[len - 1]) {
case 'f': case 'F':
kind= IBasicType.t_float;
kind= Kind.eFloat;
break;
case 'l': case 'L':
flags |= ICPPBasicType.IS_LONG;
@ -162,15 +162,10 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
if (makelong > 1) {
flags |= ICPPBasicType.IS_LONG_LONG;
GPPBasicType result = new GPPBasicType(IBasicType.t_int, flags, null);
result.setFromExpression(this);
return result;
}
if (makelong == 1) {
} else if (makelong == 1) {
flags |= ICPPBasicType.IS_LONG;
}
return new CPPBasicType(IBasicType.t_int, flags, this);
return new CPPBasicType(Kind.eInt, flags, this);
}
/**

View file

@ -1,21 +1,20 @@
/*******************************************************************************
* Copyright (c) 2004, 2008 IBM Corporation and others.
* Copyright (c) 2004, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
/**
* @author jcamelon
*/
public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implements ICPPASTSimpleDeclSpecifier {
private int type;
@ -51,6 +50,32 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier implement
this.type = type;
}
public void setType(Kind kind) {
setType(getType(kind));
}
private int getType(Kind kind) {
switch(kind) {
case eBoolean:
return t_bool;
case eChar:
return t_char;
case eWChar:
return t_wchar_t;
case eDouble:
return t_double;
case eFloat:
return t_float;
case eInt:
return t_int;
case eUnspecified:
return t_unspecified;
case eVoid:
return t_void;
}
return t_unspecified;
}
public boolean isSigned() {
return isSigned;
}

View file

@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -97,6 +98,6 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements
}
public IType getExpressionType() {
return new CPPBasicType(st, 0);
return new CPPBasicType(CPPBasicType.getKind(st), 0);
}
}

View file

@ -13,12 +13,12 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
@ -62,11 +62,11 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
private void addBuiltinOperators(CPPScope theScope) {
// void
IType cpp_void = new CPPBasicType(IBasicType.t_void, 0);
IType cpp_void = new CPPBasicType(Kind.eVoid, 0);
// void *
IType cpp_void_p = new GPPPointerType(new CPPQualifierType(new CPPBasicType(IBasicType.t_void, 0), false, false), new GPPASTPointer());
IType cpp_void_p = new GPPPointerType(new CPPQualifierType(new CPPBasicType(Kind.eVoid, 0), false, false), new GPPASTPointer());
// size_t // assumed: unsigned long int
IType cpp_size_t = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG & ICPPBasicType.IS_UNSIGNED);
IType cpp_size_t = new CPPBasicType(Kind.eInt, ICPPBasicType.IS_LONG & ICPPBasicType.IS_UNSIGNED);
// void * operator new (std::size_t);
IBinding temp = null;

View file

@ -9,6 +9,7 @@
* John Camelon (IBM) - Initial API and implementation
* Sergey Prigogin (Google)
* Mike Kucera (IBM)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -30,9 +31,9 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@ -252,7 +253,7 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres
}
if(op == op_not) {
return new CPPBasicType(ICPPBasicType.t_bool, 0);
return new CPPBasicType(Kind.eBoolean, 0);
}
if (type instanceof CPPBasicType) {
((CPPBasicType) type).setFromExpression(this);

View file

@ -13,93 +13,143 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.internal.core.index.IIndexType;
/**
* Integral c++ type.
*/
public class CPPBasicType implements ICPPBasicType {
protected int qualifierBits = 0;
protected int type;
protected IASTExpression expression = null;
public static int UNIQUE_TYPE_QUALIFIER= -1;
private final Kind fKind;
private final int fQualifierBits;
private IASTExpression fExpression;
public CPPBasicType(int t, int bits) {
type = t;
qualifierBits = bits;
public CPPBasicType(Kind kind, int qualifiers, IASTExpression expression) {
if (kind == Kind.eUnspecified) {
if ( (qualifiers & (IS_COMPLEX | IS_IMAGINARY)) != 0) {
fKind= Kind.eFloat;
} else if ( (qualifiers & (IS_LONG | IS_SHORT | IS_SIGNED | IS_UNSIGNED | IS_LONG_LONG)) != 0 ) {
fKind= Kind.eInt;
} else {
fKind= Kind.eUnspecified;
}
} else {
fKind= kind;
}
fQualifierBits= qualifiers;
fExpression= expression;
}
if (type == IBasicType.t_unspecified &&
(qualifierBits & (IS_LONG | IS_SHORT | IS_SIGNED | IS_UNSIGNED)) != 0) {
type = IBasicType.t_int;
public CPPBasicType(Kind kind, int qualifiers) {
this(kind, qualifiers, null);
}
public CPPBasicType(ICPPASTSimpleDeclSpecifier sds) {
this (getKind(sds), getQualifiers(sds), null);
}
private static int getQualifiers(ICPPASTSimpleDeclSpecifier sds) {
int qualifiers=
( sds.isLong() ? ICPPBasicType.IS_LONG : 0 ) |
( sds.isShort() ? ICPPBasicType.IS_SHORT : 0 ) |
( sds.isSigned() ? ICPPBasicType.IS_SIGNED: 0 ) |
( sds.isUnsigned()? ICPPBasicType.IS_UNSIGNED : 0 );
if (sds instanceof IGPPASTSimpleDeclSpecifier) {
IGPPASTSimpleDeclSpecifier gsds= (IGPPASTSimpleDeclSpecifier) sds;
qualifiers |=
( gsds.isLongLong()? ICPPBasicType.IS_LONG_LONG : 0 ) |
( gsds.isComplex() ? ICPPBasicType.IS_COMPLEX : 0 ) |
( gsds.isImaginary()?ICPPBasicType.IS_IMAGINARY : 0 );
}
return qualifiers;
}
private static Kind getKind(ICPPASTSimpleDeclSpecifier sds) {
return getKind(sds.getType());
}
static Kind getKind(final int simpleDeclSpecType) {
switch(simpleDeclSpecType) {
case ICPPASTSimpleDeclSpecifier.t_bool:
return Kind.eBoolean;
case IASTSimpleDeclSpecifier.t_char:
return Kind.eChar;
case ICPPASTSimpleDeclSpecifier.t_wchar_t:
return Kind.eWChar;
case IASTSimpleDeclSpecifier.t_double:
return Kind.eDouble;
case IASTSimpleDeclSpecifier.t_float:
return Kind.eFloat;
case IASTSimpleDeclSpecifier.t_int:
return Kind.eInt;
case IASTSimpleDeclSpecifier.t_void:
return Kind.eVoid;
default:
return Kind.eUnspecified;
}
}
public CPPBasicType(int t, int bits, IASTExpression fromExpression) {
type = t;
qualifierBits = bits;
expression= fromExpression;
}
public boolean isSameType(IType object) {
if (object == this)
return true;
if (fQualifierBits == -1)
return false;
if (object instanceof ITypedef || object instanceof IIndexType)
return object.isSameType(this);
if (!(object instanceof CPPBasicType))
return false;
if (type == -1)
return false;
CPPBasicType t = (CPPBasicType) object;
if (type != t.type)
if (fKind != t.fKind)
return false;
if (type == IBasicType.t_int) {
if (fKind == Kind.eInt) {
//signed int and int are equivalent
return (qualifierBits & ~IS_SIGNED) == (t.qualifierBits & ~IS_SIGNED);
return (fQualifierBits & ~IS_SIGNED) == (t.fQualifierBits & ~IS_SIGNED);
}
return qualifierBits == t.qualifierBits;
return fQualifierBits == t.fQualifierBits;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBasicType#getType()
*/
public int getType() {
return type;
public Kind getKind() {
return fKind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBasicType#isSigned()
*/
public boolean isSigned() {
return (qualifierBits & IS_SIGNED) != 0;
return (fQualifierBits & IS_SIGNED) != 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBasicType#isUnsigned()
*/
public boolean isUnsigned() {
return (qualifierBits & IS_UNSIGNED) != 0;
return (fQualifierBits & IS_UNSIGNED) != 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBasicType#isShort()
*/
public boolean isShort() {
return (qualifierBits & IS_SHORT) != 0;
return (fQualifierBits & IS_SHORT) != 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBasicType#isLong()
*/
public boolean isLong() {
return (qualifierBits & IS_LONG) != 0;
return (fQualifierBits & IS_LONG) != 0;
}
public boolean isLongLong() {
return (fQualifierBits & IS_LONG_LONG) != 0;
}
public boolean isComplex() {
return (fQualifierBits & IS_COMPLEX) != 0;
}
public boolean isImaginary() {
return (fQualifierBits & IS_IMAGINARY) != 0;
}
@Override
@ -113,31 +163,53 @@ public class CPPBasicType implements ICPPBasicType {
return t;
}
/**
* @deprecated types don't have values
*/
@Deprecated
public IASTExpression getValue() {
return expression;
}
public void setFromExpression(IASTExpression val) {
expression = val;
fExpression = val;
}
/**
* Returns the expression the type was created for, or <code>null</code>.
*/
public IASTExpression getCreatedFromExpression() {
return expression;
return fExpression;
}
public int getQualifierBits() {
return qualifierBits;
return fQualifierBits;
}
@Override
public String toString() {
return ASTTypeUtil.getType(this);
}
@Deprecated
public int getType() {
switch (fKind) {
case eBoolean:
return t_bool;
case eChar:
return t_char;
case eWChar:
return t_wchar_t;
case eDouble:
return t_double;
case eFloat:
return t_float;
case eInt:
return t_int;
case eVoid:
return t_void;
case eUnspecified:
return t_unspecified;
}
return t_unspecified;
}
/**
* @deprecated types don't have values
*/
@Deprecated
public IASTExpression getValue() {
return fExpression;
}
}

View file

@ -31,12 +31,12 @@ import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
@ -133,7 +133,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
if (!ia.hasUserDeclaredDestructor()) {
//destructor: ~A()
ICPPFunctionType ft= CPPVisitor.createImplicitFunctionType(new CPPBasicType(IBasicType.t_unspecified, 0), voidPs, false, false);
ICPPFunctionType ft= CPPVisitor.createImplicitFunctionType(new CPPBasicType(Kind.eUnspecified, 0), voidPs, false, false);
char[] dtorName = CharArrayUtils.concat("~".toCharArray(), className); //$NON-NLS-1$
ICPPMethod m = new CPPImplicitMethod(this, dtorName, ft, voidPs);
implicits[i++] = m;

View file

@ -12,11 +12,11 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
@ -58,14 +58,13 @@ public class CPPFunctionType implements ICPPFunctionType {
else if (returnType != null && ! returnType.isSameType(ft.getReturnType()))
return false;
try {
if (parameters.length == 1 && fps.length == 0) {
IType p0= SemanticUtil.getNestedType(parameters[0], SemanticUtil.TDEF);
if (!(p0 instanceof IBasicType) || ((IBasicType) p0).getType() != IBasicType.t_void)
if (!(p0 instanceof IBasicType) || ((IBasicType) p0).getKind() != Kind.eVoid)
return false;
} else if (fps.length == 1 && parameters.length == 0) {
IType p0= SemanticUtil.getNestedType(fps[0], SemanticUtil.TDEF);
if (!(p0 instanceof IBasicType) || ((IBasicType) p0).getType() != IBasicType.t_void)
if (!(p0 instanceof IBasicType) || ((IBasicType) p0).getKind() != Kind.eVoid)
return false;
} else if (parameters.length != fps.length) {
return false;
@ -75,9 +74,6 @@ public class CPPFunctionType implements ICPPFunctionType {
return false;
}
}
} catch (DOMException e) {
return false;
}
if (isConst() != ft.isConst() || isVolatile() != ft.isVolatile()) {
return false;

View file

@ -11,9 +11,9 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
@ -29,7 +29,7 @@ public class CPPImplicitConstructor extends CPPImplicitMethod implements ICPPCon
}
private static ICPPFunctionType createFunctionType(ICPPClassScope scope, IParameter[] params) {
IType returnType= new CPPBasicType(IBasicType.t_unspecified, 0);
IType returnType= new CPPBasicType(Kind.eUnspecified, 0);
return CPPVisitor.createImplicitFunctionType(returnType, params, false, false);
}

View file

@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
@ -140,7 +141,7 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
if (params.length == 1) {
IType t1 = params[0];
ok = (t1 instanceof IBasicType)
&& ((IBasicType) t1).getType() == IBasicType.t_void;
&& ((IBasicType) t1).getKind() == Kind.eVoid;
}
}
} else {

View file

@ -38,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
@ -681,7 +682,7 @@ public class ClassTypeHelper {
return KIND_DEFAULT_CTOR;
if (params.length == 1) {
IType t= params[0];
if (t instanceof IBasicType && ((IBasicType) t).getType() == IBasicType.t_void)
if (t instanceof IBasicType && ((IBasicType) t).getKind() == Kind.eVoid)
return KIND_DEFAULT_CTOR;
if (isRefToConstClass(ct, t))

View file

@ -1,60 +0,0 @@
/*******************************************************************************
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
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;
/**
* @author aniefer
*/
public class GPPBasicType extends CPPBasicType implements IGPPBasicType {
private IType typeOf;
public GPPBasicType( int type, int bits, IType typeOf ){
super( type, bits );
this.typeOf = typeOf;
if( this.type == IBasicType.t_unspecified ){
if((qualifierBits & ( IS_COMPLEX | IS_IMAGINARY )) != 0 )
this.type = IBasicType.t_float;
else if( (qualifierBits & IS_LONG_LONG) != 0 )
this.type = IBasicType.t_int;
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType#isLongLong()
*/
public boolean isLongLong() {
return ( qualifierBits & IS_LONG_LONG ) != 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType#getTypeofType()
*/
public IType getTypeofType() {
if( type != IGPPASTSimpleDeclSpecifier.t_typeof )
return null;
return typeOf;
}
public boolean isComplex() {
return ( qualifierBits & IS_COMPLEX ) != 0;
}
public boolean isImaginary() {
return ( qualifierBits & IS_IMAGINARY ) != 0;
}
}

View file

@ -79,6 +79,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
@ -200,7 +201,7 @@ public class CPPSemantics {
public static final String EMPTY_NAME = ""; //$NON-NLS-1$
public static final char[] OPERATOR_ = new char[] {'o','p','e','r','a','t','o','r',' '};
private static final char[] CALL_FUNCTION = "call-function".toCharArray(); //$NON-NLS-1$
public static final IType VOID_TYPE = new CPPBasicType(IBasicType.t_void, 0);
public static final IType VOID_TYPE = new CPPBasicType(Kind.eVoid, 0);
// Set to true for debugging.
public static boolean traceBindingResolution = false;
@ -1918,7 +1919,7 @@ public class CPPSemantics {
final IType[] argTypes = data.getFunctionArgumentTypes();
if (argTypes.length == 1) {
IType t= getNestedType(argTypes[0], TDEF);
if (t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_void) {
if (t instanceof IBasicType && ((IBasicType)t).getKind() == Kind.eVoid) {
argumentCount= 0;
}
}
@ -1954,7 +1955,7 @@ public class CPPSemantics {
if (numArgs < 2 && numPars == 1) {
// check for void
IType t = getNestedType(parameterTypes[0], TDEF);
if (t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_void)
if (t instanceof IBasicType && ((IBasicType)t).getKind() == Kind.eVoid)
numPars= 0;
}

View file

@ -47,6 +47,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
@ -1624,7 +1625,7 @@ public class CPPTemplates {
if (parPos >= 0) {
ICPPTemplateArgument old= map.getArgument(parPos);
if (old == null) {
map.put(parPos, new CPPTemplateArgument(ps, new CPPBasicType(IBasicType.t_int, 0)));
map.put(parPos, new CPPTemplateArgument(ps, new CPPBasicType(Kind.eInt, 0)));
} else if (!ps.equals(old.getNonTypeValue())) {
return false;
}
@ -1769,7 +1770,7 @@ public class CPPTemplates {
if (param instanceof ICPPTemplateNonTypeParameter) {
args[i]= new CPPTemplateArgument(Value.unique(), ((ICPPTemplateNonTypeParameter) param).getType());
} else {
args[i] = new CPPTemplateArgument(new CPPBasicType(-1, 0));
args[i] = new CPPTemplateArgument(new CPPBasicType(Kind.eUnspecified, CPPBasicType.UNIQUE_TYPE_QUALIFIER));
}
}
return args;
@ -1933,7 +1934,7 @@ public class CPPTemplates {
@Override
public ICPPFunctionType getType() {
if (type == null) {
type = CPPVisitor.createImplicitFunctionType(new CPPBasicType(IBasicType.t_void, 0), functionParameters, false, false);
type = CPPVisitor.createImplicitFunctionType(new CPPBasicType(Kind.eVoid, 0), functionParameters, false, false);
}
return type;
}

View file

@ -60,7 +60,6 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
@ -76,6 +75,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
@ -162,7 +162,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedef;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPPointerToMemberType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
@ -1663,21 +1662,15 @@ public class CPPVisitor extends ASTQueries {
name = ((IASTEnumerationSpecifier)declSpec).getName();
} else if (declSpec instanceof ICPPASTSimpleDeclSpecifier) {
ICPPASTSimpleDeclSpecifier spec = (ICPPASTSimpleDeclSpecifier) declSpec;
int bits = (spec.isLong() ? ICPPBasicType.IS_LONG : 0) |
(spec.isShort() ? ICPPBasicType.IS_SHORT : 0) |
(spec.isSigned() ? ICPPBasicType.IS_SIGNED: 0) |
(spec.isUnsigned() ? ICPPBasicType.IS_UNSIGNED : 0);
if (spec instanceof IGPPASTSimpleDeclSpecifier) {
IGPPASTSimpleDeclSpecifier gspec = (IGPPASTSimpleDeclSpecifier) spec;
final IASTExpression typeofExpression = gspec.getTypeofExpression();
if (typeofExpression != null) {
type = typeofExpression.getExpressionType();
} else {
bits |= (gspec.isLongLong() ? ICPPBasicType.IS_LONG_LONG : 0);
type = new GPPBasicType(spec.getType(), bits, null);
}
} else {
type = new CPPBasicType(spec.getType(), bits);
}
if (type == null) {
type = new CPPBasicType(spec);
}
}
if (name != null) {
@ -1770,7 +1763,7 @@ public class CPPVisitor extends ASTQueries {
}
} catch (DOMException e) {
}
basicType= new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED);
basicType= new CPPBasicType(Kind.eInt, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED);
basicType.setFromExpression(binary);
return basicType;
}
@ -1790,7 +1783,7 @@ public class CPPVisitor extends ASTQueries {
}
} catch (DOMException e) {
}
return new CPPBasicType(IBasicType.t_int, 0);
return new CPPBasicType(Kind.eInt, 0);
}
public static IType get_SIZE_T(IASTNode sizeofExpr) {
@ -1802,7 +1795,7 @@ public class CPPVisitor extends ASTQueries {
}
} catch (DOMException e) {
}
return new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED);
return new CPPBasicType(Kind.eInt, ICPPBasicType.IS_LONG | ICPPBasicType.IS_UNSIGNED);
}
public static IASTProblem[] getProblems(IASTTranslationUnit tu) {

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
@ -365,8 +366,7 @@ public class Conversions {
// Select converting constructors
int j= 0;
ICPPConstructor[] convertingCtors= new ICPPConstructor[ctors.length];
for (int i = 0; i < ctors.length; i++) {
ICPPConstructor ctor= ctors[i];
for (ICPPConstructor ctor : ctors) {
if (!(ctor instanceof IProblemBinding) && !ctor.isExplicit())
convertingCtors[j++]= ctor;
}
@ -649,30 +649,32 @@ public class Conversions {
boolean canPromote= false;
if (trg instanceof IBasicType) {
IBasicType basicTgt = (IBasicType) trg;
final int tType = basicTgt.getType();
final Kind tKind = basicTgt.getKind();
if (src instanceof IBasicType) {
final IBasicType basicSrc = (IBasicType) src;
int sType = basicSrc.getType();
if (tType == IBasicType.t_int) {
switch (sType) {
case IBasicType.t_int: // short, and unsigned short
Kind sKind = basicSrc.getKind();
if (tKind == Kind.eInt) {
switch (sKind) {
case eInt: // short, and unsigned short
if (basicSrc.isShort()) {
canPromote= true;
}
break;
case IBasicType.t_char:
case ICPPBasicType.t_bool:
case ICPPBasicType.t_wchar_t:
case IBasicType.t_unspecified: // treat unspecified as int
case eChar:
case eBoolean:
case eWChar:
case eUnspecified: // treat unspecified as int
canPromote= true;
break;
default:
break;
}
} else if (tType == IBasicType.t_double && sType == IBasicType.t_float) {
} else if (tKind == Kind.eDouble && sKind == Kind.eFloat) {
canPromote= true;
}
} else if (src instanceof IEnumeration) {
if (tType == IBasicType.t_int || tType == IBasicType.t_unspecified) {
if (tKind == Kind.eInt || tKind == Kind.eUnspecified) {
if (trg instanceof ICPPBasicType) {
int qualifiers = getEnumIntType((IEnumeration) src);
if (qualifiers == ((ICPPBasicType) trg).getQualifierBits()) {
@ -714,8 +716,8 @@ public class Conversions {
return true;
}
// 4.12 pointer or pointer to member type can be converted to an rvalue of type bool
final int tgtType = ((IBasicType) t).getType();
if (tgtType == ICPPBasicType.t_bool && s instanceof IPointerType) {
final Kind tgtKind = ((IBasicType) t).getKind();
if (tgtKind == Kind.eBoolean && s instanceof IPointerType) {
cost.setRank(Rank.CONVERSION_PTR_BOOL);
return true;
}
@ -742,7 +744,7 @@ public class Conversions {
// 4.10-2 an rvalue of type "pointer to cv T", where T is an object type can be
// converted to an rvalue of type "pointer to cv void"
IType tgtPtrTgt= getNestedType(tgtPtr.getType(), TDEF | CVQ | REF);
if (tgtPtrTgt instanceof IBasicType && ((IBasicType) tgtPtrTgt).getType() == IBasicType.t_void) {
if (tgtPtrTgt instanceof IBasicType && ((IBasicType) tgtPtrTgt).getKind() == Kind.eVoid) {
cost.setRank(Rank.CONVERSION);
cost.setInheritanceDistance(Short.MAX_VALUE); // mstodo add distance to last base class
int cv= getCVQualifier(srcPtr.getType());

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* Bryan Wilkinson (QNX) - Initial API and implementation
* Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
@ -33,8 +34,6 @@ import org.eclipse.core.runtime.CoreException;
/**
* Determines the signatures and signature hashes for bindings that can have
* siblings with the same name.
*
* @author Bryan Wilkinson
*/
public class IndexCPPSignatureUtil {
@ -96,7 +95,7 @@ public class IndexCPPSignatureUtil {
IType[] types = fType.getParameterTypes();
if (types.length == 1) {
if (types[0] instanceof IBasicType) {
if (((IBasicType) types[0]).getType() == IBasicType.t_void) {
if (((IBasicType) types[0]).getKind() == Kind.eVoid) {
types = new IType[0];
}
}

View file

@ -180,13 +180,14 @@ public class PDOM extends PlatformObject implements IPDOM {
* #83.0# - unconditionally store name in PDOMInclude, bug 272815 - <<CDT 6.0>>
* 84.0 - storing free record pointers as (ptr>>3) and allocated pointers as (ptr-2)>>3 RECPTR_DENSE_VERSION
*
* CDT 7.0 development (versions not supported on the 6.0.x branch)
* CDT 6.1 development (versions not supported on the 6.0.x branch)
* 90.0 - support for array sizes, bug 269926
* 91.0 - storing unknown bindings other than unknown class types, bug 284686.
* 92.0 - simplification of basic types, bug 231859.
*/
private static final int MIN_SUPPORTED_VERSION= version(91, 0);
private static final int MAX_SUPPORTED_VERSION= version(91, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(91, 0);
private static final int MIN_SUPPORTED_VERSION= version(92, 0);
private static final int MAX_SUPPORTED_VERSION= version(92, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(92, 0);
private static int version(int major, int minor) {
return (major << 16) + minor;

View file

@ -18,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.db.Database;
@ -52,9 +51,8 @@ class PDOMCBasicType extends PDOMNode implements ICBasicType, IIndexType {
public PDOMCBasicType(PDOMLinkage linkage, PDOMNode parent, ICBasicType type) throws CoreException {
super(linkage, parent);
try {
Database db = getDB();
db.putChar(record + TYPE_ID, (char)type.getType());
db.putChar(record + TYPE_ID, (char)type.getKind().ordinal());
char flags = 0;
if (type.isLong()) flags |= IS_LONG;
@ -67,9 +65,6 @@ class PDOMCBasicType extends PDOMNode implements ICBasicType, IIndexType {
db.putChar(record + FLAGS, flags);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
@Override
@ -82,25 +77,49 @@ class PDOMCBasicType extends PDOMNode implements ICBasicType, IIndexType {
return IIndexCBindingConstants.CBASICTYPE;
}
public int getType() {
public Kind getKind() {
try {
return getDB().getChar(record + TYPE_ID);
int idx= getDB().getChar(record + TYPE_ID);
return Kind.values()[idx];
} catch (CoreException e) {
CCorePlugin.log(e);
return 0;
return Kind.eInt;
}
}
@Deprecated
public int getType() {
final Kind kind = getKind();
switch (kind) {
case eBoolean:
return t_Bool;
case eChar:
case eWChar:
return t_char;
case eDouble:
return t_double;
case eFloat:
return t_float;
case eInt:
return t_int;
case eVoid:
return t_void;
case eUnspecified:
return t_unspecified;
}
return t_unspecified;
}
@Deprecated
public IASTExpression getValue() throws DOMException {
return null;
}
public boolean isLong() throws DOMException { return flagSet(IS_LONG); }
public boolean isShort() throws DOMException { return flagSet(IS_SHORT); }
public boolean isSigned() throws DOMException { return flagSet(IS_SIGNED); }
public boolean isUnsigned() throws DOMException { return flagSet(IS_UNSIGNED); }
public boolean isLongLong() throws DOMException { return flagSet(IS_LONGLONG); }
public boolean isLong() { return flagSet(IS_LONG); }
public boolean isShort() { return flagSet(IS_SHORT); }
public boolean isSigned() { return flagSet(IS_SIGNED); }
public boolean isUnsigned() { return flagSet(IS_UNSIGNED); }
public boolean isLongLong() { return flagSet(IS_LONGLONG); }
public boolean isImaginary() { return flagSet(IS_IMAGINARY); }
public boolean isComplex() { return flagSet(IS_COMPLEX); }
@ -113,13 +132,7 @@ class PDOMCBasicType extends PDOMNode implements ICBasicType, IIndexType {
return false;
ICBasicType rhs1= (ICBasicType) rhs;
int type;
try {
type = this.getType();
if (type == -1 || type != rhs1.getType())
return false;
return (rhs1.getType() == this.getType()
return (rhs1.getKind() == getKind()
&& rhs1.isLong() == this.isLong()
&& rhs1.isShort() == this.isShort()
&& rhs1.isSigned() == this.isSigned()
@ -127,9 +140,6 @@ class PDOMCBasicType extends PDOMNode implements ICBasicType, IIndexType {
&& rhs1.isLongLong() == this.isLongLong()
&& rhs1.isComplex() == this.isComplex()
&& rhs1.isImaginary() == this.isImaginary());
} catch (DOMException e) {
return false;
}
}
@Override

View file

@ -18,12 +18,12 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexType;
@ -108,7 +108,6 @@ public class PDOMCFunctionType extends PDOMNode implements IIndexType, IFunction
return type.isSameType(this);
}
try {
if (type instanceof IFunctionType) {
IFunctionType ft = (IFunctionType) type;
IType rt1= getReturnType();
@ -123,11 +122,11 @@ public class PDOMCFunctionType extends PDOMNode implements IIndexType, IFunction
IType[] params2= ft.getParameterTypes();
if (params1.length == 1 && params2.length == 0) {
IType p0= SemanticUtil.getNestedType(params1[0], SemanticUtil.TDEF);
if (!(p0 instanceof IBasicType) || ((IBasicType) p0).getType() != IBasicType.t_void)
if (!(p0 instanceof IBasicType) || ((IBasicType) p0).getKind() != Kind.eVoid)
return false;
} else if (params2.length == 1 && params1.length == 0) {
IType p0= SemanticUtil.getNestedType(params2[0], SemanticUtil.TDEF);
if (!(p0 instanceof IBasicType) || ((IBasicType) p0).getType() != IBasicType.t_void)
if (!(p0 instanceof IBasicType) || ((IBasicType) p0).getKind() != Kind.eVoid)
return false;
} else if (params1.length != params2.length) {
return false;
@ -141,9 +140,6 @@ public class PDOMCFunctionType extends PDOMNode implements IIndexType, IFunction
return true;
}
return false;
} catch (DOMException e) {
}
return false;
}
public final IType[] getParameterTypes() {

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument;
@ -97,7 +98,7 @@ public class PDOMCPPArgumentList {
ICPPTemplateArgument[] result= new ICPPTemplateArgument[len];
for (int i=0; i<len; i++) {
final long typeRec= db.getRecPtr(rec);
final IType type= typeRec == 0 ? new CPPBasicType(-1,0) : (IType) linkage.getNode(typeRec);
final IType type= typeRec == 0 ? new CPPBasicType(Kind.eUnspecified,CPPBasicType.UNIQUE_TYPE_QUALIFIER) : (IType) linkage.getNode(typeRec);
final long nonTypeValRec= db.getRecPtr(rec+4);
if (nonTypeValRec != 0) {
final IValue val= PDOMValue.restore(db, linkage, nonTypeValRec);

View file

@ -16,7 +16,6 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
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;
@ -39,7 +38,7 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType {
private static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
protected short fFlags= -1;
protected short fType= -1;
private Kind fKind;
public PDOMCPPBasicType(PDOMLinkage linkage, long record) {
super(linkage, record);
@ -54,22 +53,12 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType {
fFlags= flags;
Database db = getDB();
db.putShort(record + TYPE_ID, getTypeCode(type));
db.putShort(record + TYPE_ID, (short) type.getKind().ordinal());
db.putShort(record + QUALIFIER_FLAGS, flags);
}
private short getTypeCode(ICPPBasicType type) {
short tc= IBasicType.t_unspecified;
try {
tc= (short) type.getType();
} catch (DOMException e) {
}
return tc;
}
protected static short encodeFlags(ICPPBasicType type) {
short flags = 0;
try {
if (type.isLong())
flags |= IS_LONG;
if (type.isShort())
@ -78,8 +67,12 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType {
flags |= IS_SIGNED;
if (type.isUnsigned())
flags |= IS_UNSIGNED;
} catch (DOMException e) {
}
if (type.isComplex())
flags |= IS_COMPLEX;
if (type.isImaginary())
flags |= IS_IMAGINARY;
if (type.isLongLong())
flags |= IS_LONG_LONG;
return flags;
}
@ -93,21 +86,21 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType {
return IIndexCPPBindingConstants.CPPBASICTYPE;
}
public int getType() {
if (fType == -1) {
try {
fType= getDB().getShort(record + TYPE_ID);
} catch (CoreException e) {
CCorePlugin.log(e);
fType= 0;
public Kind getKind() {
if (fKind == null) {
fKind= readKind();
}
}
return fType;
return fKind;
}
@Deprecated
public IASTExpression getValue() throws DOMException {
return null;
private Kind readKind() {
try {
int idx= getDB().getChar(record + TYPE_ID);
return Kind.values()[idx];
} catch (CoreException e) {
CCorePlugin.log(e);
return Kind.eInt;
}
}
public int getQualifierBits() {
@ -123,44 +116,51 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType {
return fFlags;
}
public boolean isLong() throws DOMException {
public boolean isLong() {
return (getQualifierBits() & IS_LONG) != 0;
}
public boolean isShort() throws DOMException {
public boolean isShort() {
return (getQualifierBits() & IS_SHORT) != 0;
}
public boolean isSigned() throws DOMException {
public boolean isSigned() {
return (getQualifierBits() & IS_SIGNED) != 0;
}
public boolean isUnsigned() throws DOMException {
public boolean isUnsigned() {
return (getQualifierBits() & IS_UNSIGNED) != 0;
}
public boolean isComplex() {
return (getQualifierBits() & IS_COMPLEX) != 0;
}
public boolean isImaginary() {
return (getQualifierBits() & IS_IMAGINARY) != 0;
}
public boolean isLongLong() {
return (getQualifierBits() & IS_LONG_LONG) != 0;
}
public boolean isSameType(IType rhs) {
if( rhs instanceof ITypedef )
return rhs.isSameType( this );
if (rhs instanceof ITypedef)
return rhs.isSameType(this);
if( !(rhs instanceof ICPPBasicType))
if (!(rhs instanceof ICPPBasicType))
return false;
ICPPBasicType rhs1= (ICPPBasicType) rhs;
int type;
try {
type = this.getType();
if (type == -1 || type != rhs1.getType())
ICPPBasicType rhs1 = (ICPPBasicType) rhs;
Kind kind = getKind();
if (kind != rhs1.getKind())
return false;
if( type == IBasicType.t_int ){
//signed int and int are equivalent
return (this.getQualifierBits() & ~ICPPBasicType.IS_SIGNED ) == (rhs1.getQualifierBits() & ~ICPPBasicType.IS_SIGNED );
}
return (this.getQualifierBits() == rhs1.getQualifierBits() );
} catch (DOMException e) {
return false;
if (kind == Kind.eInt) {
// signed int and int are equivalent
return (this.getQualifierBits() & ~ICPPBasicType.IS_SIGNED) == (rhs1.getQualifierBits() & ~ICPPBasicType.IS_SIGNED);
}
return (this.getQualifierBits() == rhs1.getQualifierBits());
}
@Override
@ -176,4 +176,33 @@ class PDOMCPPBasicType extends PDOMNode implements ICPPBasicType, IIndexType {
public String toString() {
return ASTTypeUtil.getType(this);
}
@Deprecated
public int getType() {
Kind kind= getKind();
switch (kind) {
case eBoolean:
return t_bool;
case eChar:
return t_char;
case eWChar:
return t_wchar_t;
case eDouble:
return t_double;
case eFloat:
return t_float;
case eInt:
return t_int;
case eVoid:
return t_void;
case eUnspecified:
return t_unspecified;
}
return t_unspecified;
}
@Deprecated
public IASTExpression getValue() throws DOMException {
return null;
}
}

View file

@ -12,9 +12,9 @@
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
@ -24,7 +24,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCFunctionType;
import org.eclipse.core.runtime.CoreException;
public class PDOMCPPFunctionType extends PDOMCFunctionType implements ICPPFunctionType {
private static IType FALLBACK_RETURN_TYPE= new CPPBasicType(IBasicType.t_void, 0);
private static IType FALLBACK_RETURN_TYPE= new CPPBasicType(Kind.eVoid, 0);
static ICPPFunctionType FALLBACK= new ICPPFunctionType() {
@Deprecated
public IPointerType getThisType() {

View file

@ -63,7 +63,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
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.IGPPBasicType;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
@ -686,18 +685,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
if (type instanceof IProblemBinding) {
return null;
}
if (type instanceof IGPPBasicType) {
IGPPBasicType gbt= (IGPPBasicType) type;
IType typeof;
try {
typeof = gbt.getTypeofType();
if (typeof != null) {
return addType(parent, typeof);
}
} catch (DOMException e) {
}
return new PDOMGPPBasicType(this, parent, gbt);
}
if (type instanceof ICPPBasicType) {
return new PDOMCPPBasicType(this, parent, (ICPPBasicType) type);
}
@ -754,7 +741,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
case CPP_USING_DECLARATION:
return new PDOMCPPUsingDeclaration(this, record);
case GPPBASICTYPE:
return new PDOMGPPBasicType(this, record);
return new PDOMCPPBasicType(this, record);
case CPPBASICTYPE:
return new PDOMCPPBasicType(this, record);
case CPPPARAMETER:

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
@ -105,7 +106,7 @@ public class PDOMCPPTemplateParameterMap {
for (int i=0; i<len; i++) {
final int parPos= db.getInt(rec);
final long typeRec= db.getRecPtr(rec+4);
final IType type= typeRec == 0 ? new CPPBasicType(-1, 0) : (IType) linkage.getNode(typeRec);
final IType type= typeRec == 0 ? new CPPBasicType(Kind.eUnspecified, CPPBasicType.UNIQUE_TYPE_QUALIFIER) : (IType) linkage.getNode(typeRec);
final long nonTypeValRec= db.getRecPtr(rec+8);
ICPPTemplateArgument arg;
if (nonTypeValRec != 0) {

View file

@ -1,66 +0,0 @@
/*******************************************************************************
* Copyright (c) 2007, 2009 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
class PDOMGPPBasicType extends PDOMCPPBasicType implements IGPPBasicType {
public PDOMGPPBasicType(PDOMLinkage linkage, long record) {
super(linkage, record);
}
public PDOMGPPBasicType(PDOMLinkage linkage, PDOMNode parent, IGPPBasicType type) throws CoreException {
super(linkage, parent, type, encodeGPPFlags(type));
}
@Override
public int getNodeType() {
return IIndexCPPBindingConstants.GPPBASICTYPE;
}
protected static short encodeGPPFlags(IGPPBasicType type) {
short flags = encodeFlags(type);
try {
if (type.isComplex())
flags |= IS_COMPLEX;
if (type.isImaginary())
flags |= IS_IMAGINARY;
if (type.isLongLong())
flags |= IS_LONG_LONG;
} catch (DOMException e) {
}
return flags;
}
public IType getTypeofType() throws DOMException {
return null;
}
public boolean isComplex() {
return (getQualifierBits() & IS_COMPLEX) != 0;
}
public boolean isImaginary() {
return (getQualifierBits() & IS_IMAGINARY) != 0;
}
public boolean isLongLong() throws DOMException {
return (getQualifierBits() & IS_LONG_LONG) != 0;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -29,10 +29,10 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
@ -115,12 +115,10 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
if(extractedNode instanceof IASTExpression) {
IType type = ((IASTExpression)extractedNode).getExpressionType();
if(type instanceof IBasicType) {
try {
return createSimpleDeclSpecifier(((IBasicType)type).getType());
} catch (DOMException e) {} //make it void
return createSimpleDeclSpecifier(((IBasicType)type).getKind());
}
}
return createSimpleDeclSpecifier(IASTSimpleDeclSpecifier.t_void);
return createSimpleDeclSpecifier(Kind.eVoid);
}
return declSpecifier.copy();
@ -129,17 +127,17 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
private IASTDeclSpecifier handleLiteralExpression(IASTLiteralExpression extractedNode) {
switch(extractedNode.getKind()){
case IASTLiteralExpression.lk_char_constant:
return createSimpleDeclSpecifier(IASTSimpleDeclSpecifier.t_char);
return createSimpleDeclSpecifier(Kind.eChar);
case IASTLiteralExpression.lk_float_constant:
return createSimpleDeclSpecifier(IASTSimpleDeclSpecifier.t_float);
return createSimpleDeclSpecifier(Kind.eFloat);
case IASTLiteralExpression.lk_integer_constant:
return createSimpleDeclSpecifier(IASTSimpleDeclSpecifier.t_int);
return createSimpleDeclSpecifier(Kind.eInt);
case IASTLiteralExpression.lk_string_literal:
return createSimpleDeclSpecifier(ICPPASTSimpleDeclSpecifier.t_wchar_t);
return createSimpleDeclSpecifier(Kind.eWChar);
case IASTLiteralExpression.lk_false:
//Like lk_true a boolean type
case IASTLiteralExpression.lk_true:
return createSimpleDeclSpecifier(ICPPASTSimpleDeclSpecifier.t_bool);
return createSimpleDeclSpecifier(Kind.eBoolean);
default:
return null;
}
@ -163,7 +161,7 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
/* We assume that these operations evaluate to bool and don't
* consider overriden operators from custom types for now.*/
return createSimpleDeclSpecifier(ICPPASTSimpleDeclSpecifier.t_bool);
return createSimpleDeclSpecifier(Kind.eBoolean);
case IASTBinaryExpression.op_plus:
case IASTBinaryExpression.op_plusAssign:
@ -207,7 +205,7 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
if (expressionType instanceof CPPBasicType) {
CPPBasicType basicType = (CPPBasicType) expressionType;
return createSimpleDeclSpecifier(basicType.getType());
return createSimpleDeclSpecifier(basicType.getKind());
} else if (expressionType instanceof CPPTypedef) {
@ -270,7 +268,7 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
return new CPPASTNamedTypeSpecifier(name.copy());
}
private static IASTDeclSpecifier createSimpleDeclSpecifier(int type) {
private static IASTDeclSpecifier createSimpleDeclSpecifier(IBasicType.Kind type) {
IASTSimpleDeclSpecifier declSpec = new CPPASTSimpleDeclSpecifier();
declSpec.setType(type);
return declSpec;

View file

@ -503,7 +503,7 @@ public class ASTManager {
if (t2 instanceof IBasicType) {
IBasicType a1= (IBasicType) t1;
IBasicType a2= (IBasicType) t2;
if (getBasicType(a1.getType()) != getBasicType(a2.getType())) {
if (a1.getKind() != a2.getKind()) {
return FALSE;
}
if (getSigned(a1) != getSigned(a2) || a1.isUnsigned() != a2.isUnsigned()) {
@ -598,21 +598,16 @@ public class ASTManager {
if (a2.isUnsigned()) {
return false;
}
switch(a2.getType()) {
case IBasicType.t_int:
case IBasicType.t_unspecified:
switch(a2.getKind()) {
case eInt:
case eUnspecified:
return true;
default:
break;
}
return false;
}
private static int getBasicType(int bc) {
if (bc== IBasicType.t_unspecified) {
bc= IBasicType.t_int;
}
return bc;
}
private static IType getRealType(IType t) {
while(t instanceof ITypedef) {
t= ((ITypedef) t).getType();