mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 02:36:01 +02:00
Bug 342683: Support for built-in type-traits.
This commit is contained in:
parent
b0574975ec
commit
eda84b573e
13 changed files with 352 additions and 77 deletions
|
@ -70,24 +70,6 @@ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerEx
|
|||
addKeyword(GCCKeywords.cp__TYPEOF, IGCCToken.t_typeof);
|
||||
addKeyword(GCCKeywords.cp__TYPEOF__, IGCCToken.t_typeof);
|
||||
addKeyword(GCCKeywords.cpTYPEOF, IGCCToken.t_typeof );
|
||||
|
||||
// Type-traits
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_assign, IGCCToken.tTT_has_nothrow_assign);
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_constructor, IGCCToken.tTT_has_nothrow_constructor);
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_copy, IGCCToken.tTT_has_nothrow_copy);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_assign, IGCCToken.tTT_has_trivial_assign);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_constructor, IGCCToken.tTT_has_trivial_constructor);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_copy, IGCCToken.tTT_has_trivial_copy);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_destructor, IGCCToken.tTT_has_trivial_destructor);
|
||||
addKeyword(GCCKeywords.cp__has_virtual_destructor, IGCCToken.tTT_has_virtual_destructor);
|
||||
addKeyword(GCCKeywords.cp__is_abstract, IGCCToken.tTT_is_abstract);
|
||||
addKeyword(GCCKeywords.cp__is_base_of, IGCCToken.tTT_is_base_of);
|
||||
addKeyword(GCCKeywords.cp__is_class, IGCCToken.tTT_is_class);
|
||||
addKeyword(GCCKeywords.cp__is_empty, IGCCToken.tTT_is_empty);
|
||||
addKeyword(GCCKeywords.cp__is_enum, IGCCToken.tTT_is_enum);
|
||||
addKeyword(GCCKeywords.cp__is_pod, IGCCToken.tTT_is_pod);
|
||||
addKeyword(GCCKeywords.cp__is_polymorphic, IGCCToken.tTT_is_polymorphic);
|
||||
addKeyword(GCCKeywords.cp__is_union, IGCCToken.tTT_is_union);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
package org.eclipse.cdt.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.parser.GNUScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.GCCKeywords;
|
||||
import org.eclipse.cdt.core.parser.IGCCToken;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
|
||||
|
@ -37,6 +39,24 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
|
|||
addMacro("__builtin_offsetof(T,m)", "(reinterpret_cast <size_t>(&reinterpret_cast <const volatile char &>(static_cast<T*> (0)->m)))");
|
||||
addKeyword(Keywords.c_COMPLEX, IToken.t__Complex);
|
||||
addKeyword(Keywords.c_IMAGINARY, IToken.t__Imaginary);
|
||||
|
||||
// Type-traits
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_assign, IGCCToken.tTT_has_nothrow_assign);
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_constructor, IGCCToken.tTT_has_nothrow_constructor);
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_copy, IGCCToken.tTT_has_nothrow_copy);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_assign, IGCCToken.tTT_has_trivial_assign);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_constructor, IGCCToken.tTT_has_trivial_constructor);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_copy, IGCCToken.tTT_has_trivial_copy);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_destructor, IGCCToken.tTT_has_trivial_destructor);
|
||||
addKeyword(GCCKeywords.cp__has_virtual_destructor, IGCCToken.tTT_has_virtual_destructor);
|
||||
addKeyword(GCCKeywords.cp__is_abstract, IGCCToken.tTT_is_abstract);
|
||||
addKeyword(GCCKeywords.cp__is_base_of, IGCCToken.tTT_is_base_of);
|
||||
addKeyword(GCCKeywords.cp__is_class, IGCCToken.tTT_is_class);
|
||||
addKeyword(GCCKeywords.cp__is_empty, IGCCToken.tTT_is_empty);
|
||||
addKeyword(GCCKeywords.cp__is_enum, IGCCToken.tTT_is_enum);
|
||||
addKeyword(GCCKeywords.cp__is_pod, IGCCToken.tTT_is_pod);
|
||||
addKeyword(GCCKeywords.cp__is_polymorphic, IGCCToken.tTT_is_polymorphic);
|
||||
addKeyword(GCCKeywords.cp__is_union, IGCCToken.tTT_is_union);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2011 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
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||
* Ed Swartz (Nokia)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
|
@ -15,32 +16,53 @@ package org.eclipse.cdt.core.parser;
|
|||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
public class GCCKeywords {
|
||||
public static final String TYPEOF = "typeof";
|
||||
public static final String __ALIGNOF__ = "__alignof__";
|
||||
public static final String __ATTRIBUTE__ = "__attribute__";
|
||||
public static final String __DECLSPEC = "__declspec";
|
||||
|
||||
public static final String TYPEOF = "typeof"; //$NON-NLS-1$
|
||||
public static final String __ALIGNOF__ = "__alignof__"; //$NON-NLS-1$
|
||||
public static final String __ATTRIBUTE__ = "__attribute__"; //$NON-NLS-1$
|
||||
public static final String __DECLSPEC = "__declspec"; //$NON-NLS-1$
|
||||
public static final char []
|
||||
cpTYPEOF = TYPEOF.toCharArray(),
|
||||
cp__ALIGNOF__ = __ALIGNOF__.toCharArray(),
|
||||
cp__ATTRIBUTE__ = __ATTRIBUTE__.toCharArray(),
|
||||
cp__DECLSPEC = __DECLSPEC.toCharArray(),
|
||||
cp__ALIGNOF = "__alignof".toCharArray(),
|
||||
cp__ATTRIBUTE = "__attribute".toCharArray(),
|
||||
cp__ASM= "__asm".toCharArray(),
|
||||
cp__ASM__= "__asm__".toCharArray(),
|
||||
cp__CONST= "__const".toCharArray(),
|
||||
cp__CONST__= "__const__".toCharArray(),
|
||||
cp__INLINE= "__inline".toCharArray(),
|
||||
cp__INLINE__= "__inline__".toCharArray(),
|
||||
cp__RESTRICT= "__restrict".toCharArray(),
|
||||
cp__RESTRICT__= "__restrict__".toCharArray(),
|
||||
cp__VOLATILE= "__volatile".toCharArray(),
|
||||
cp__VOLATILE__= "__volatile__".toCharArray(),
|
||||
cp__SIGNED= "__signed".toCharArray(),
|
||||
cp__SIGNED__= "__signed__".toCharArray(),
|
||||
cp__TYPEOF= "__typeof".toCharArray(),
|
||||
cp__TYPEOF__= "__typeof__".toCharArray();
|
||||
|
||||
public static final char [] cpTYPEOF = TYPEOF.toCharArray();
|
||||
public static final char [] cp__ALIGNOF__ = __ALIGNOF__.toCharArray();
|
||||
public static final char [] cp__ATTRIBUTE__ = __ATTRIBUTE__.toCharArray();
|
||||
public static final char [] cp__DECLSPEC = __DECLSPEC.toCharArray();
|
||||
|
||||
public static final char [] cp__ALIGNOF = "__alignof".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__ATTRIBUTE = "__attribute".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__ASM= "__asm".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__ASM__= "__asm__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__CONST= "__const".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__CONST__= "__const__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__INLINE= "__inline".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__INLINE__= "__inline__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__RESTRICT= "__restrict".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__RESTRICT__= "__restrict__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__VOLATILE= "__volatile".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__VOLATILE__= "__volatile__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__SIGNED= "__signed".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__SIGNED__= "__signed__".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__TYPEOF= "__typeof".toCharArray(); //$NON-NLS-1$
|
||||
public static final char [] cp__TYPEOF__= "__typeof__".toCharArray(); //$NON-NLS-1$
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
public static final char []
|
||||
cp__has_nothrow_assign= "__has_nothrow_assign".toCharArray(),
|
||||
cp__has_nothrow_copy= "__has_nothrow_copy".toCharArray(),
|
||||
cp__has_nothrow_constructor= "__has_nothrow_constructor".toCharArray(),
|
||||
cp__has_trivial_assign= "__has_trivial_assign".toCharArray(),
|
||||
cp__has_trivial_copy= "__has_trivial_copy".toCharArray(),
|
||||
cp__has_trivial_constructor= "__has_trivial_constructor".toCharArray(),
|
||||
cp__has_trivial_destructor= "__has_trivial_destructor".toCharArray(),
|
||||
cp__has_virtual_destructor= "__has_virtual_destructor".toCharArray(),
|
||||
cp__is_abstract= "__is_abstract".toCharArray(),
|
||||
cp__is_base_of= "__is_base_of".toCharArray(),
|
||||
cp__is_class= "__is_class".toCharArray(),
|
||||
cp__is_empty= "__is_empty".toCharArray(),
|
||||
cp__is_enum= "__is_enum".toCharArray(),
|
||||
cp__is_pod= "__is_pod".toCharArray(),
|
||||
cp__is_polymorphic= "__is_polymorphic".toCharArray(),
|
||||
cp__is_union= "__is_union".toCharArray();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2011 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
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||
* Ed Swartz (Nokia)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
@ -17,12 +18,27 @@ package org.eclipse.cdt.core.parser;
|
|||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface IGCCToken extends IToken {
|
||||
|
||||
public static final int t_typeof = FIRST_RESERVED_IGCCToken;
|
||||
public static final int t___alignof__ = FIRST_RESERVED_IGCCToken + 1;
|
||||
public static final int tMAX = FIRST_RESERVED_IGCCToken + 2;
|
||||
public static final int tMIN = FIRST_RESERVED_IGCCToken + 3;
|
||||
public static final int t__attribute__ = FIRST_RESERVED_IGCCToken + 4;
|
||||
public static final int t__declspec = FIRST_RESERVED_IGCCToken + 5;
|
||||
|
||||
public static final int t_typeof = FIRST_RESERVED_IGCCToken;
|
||||
public static final int t___alignof__ = FIRST_RESERVED_IGCCToken + 1;
|
||||
public static final int tMAX = FIRST_RESERVED_IGCCToken + 2;
|
||||
public static final int tMIN = FIRST_RESERVED_IGCCToken + 3;
|
||||
public static final int t__attribute__ = FIRST_RESERVED_IGCCToken + 4;
|
||||
public static final int t__declspec = FIRST_RESERVED_IGCCToken + 5;
|
||||
// Type traits used by g++
|
||||
/** @since 5.3 */ int tTT_has_nothrow_assign= FIRST_RESERVED_IGCCToken + 6;
|
||||
/** @since 5.3 */ int tTT_has_nothrow_copy= FIRST_RESERVED_IGCCToken + 7;
|
||||
/** @since 5.3 */ int tTT_has_nothrow_constructor= FIRST_RESERVED_IGCCToken + 8;
|
||||
/** @since 5.3 */ int tTT_has_trivial_assign= FIRST_RESERVED_IGCCToken + 9;
|
||||
/** @since 5.3 */ int tTT_has_trivial_copy= FIRST_RESERVED_IGCCToken + 10;
|
||||
/** @since 5.3 */ int tTT_has_trivial_constructor= FIRST_RESERVED_IGCCToken + 11;
|
||||
/** @since 5.3 */ int tTT_has_trivial_destructor= FIRST_RESERVED_IGCCToken + 12;
|
||||
/** @since 5.3 */ int tTT_has_virtual_destructor= FIRST_RESERVED_IGCCToken + 13;
|
||||
/** @since 5.3 */ int tTT_is_abstract= FIRST_RESERVED_IGCCToken + 14;
|
||||
/** @since 5.3 */ int tTT_is_base_of= FIRST_RESERVED_IGCCToken + 15;
|
||||
/** @since 5.3 */ int tTT_is_class= FIRST_RESERVED_IGCCToken + 16;
|
||||
/** @since 5.3 */ int tTT_is_empty= FIRST_RESERVED_IGCCToken + 17;
|
||||
/** @since 5.3 */ int tTT_is_enum= FIRST_RESERVED_IGCCToken + 18;
|
||||
/** @since 5.3 */ int tTT_is_pod= FIRST_RESERVED_IGCCToken + 19;
|
||||
/** @since 5.3 */ int tTT_is_polymorphic= FIRST_RESERVED_IGCCToken + 20;
|
||||
/** @since 5.3 */ int tTT_is_union= FIRST_RESERVED_IGCCToken + 21;
|
||||
}
|
||||
|
|
|
@ -14,10 +14,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE;
|
||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromFunctionCall;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromFunctionCall;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
|
@ -26,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
@ -337,7 +333,7 @@ public class CPPASTBinaryExpression extends ASTNode implements ICPPASTBinaryExpr
|
|||
case IASTBinaryExpression.op_logicalOr:
|
||||
case IASTBinaryExpression.op_equals:
|
||||
case IASTBinaryExpression.op_notequals:
|
||||
return new CPPBasicType(Kind.eBoolean, 0, this);
|
||||
return CPPBasicType.BOOLEAN;
|
||||
|
||||
case IASTBinaryExpression.op_plus:
|
||||
if (type1 instanceof IPointerType) {
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2011 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:
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE;
|
||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
|
||||
|
||||
public class CPPASTBinaryTypeIdExpression extends ASTNode implements IASTBinaryTypeIdExpression {
|
||||
private Operator fOperator;
|
||||
private IASTTypeId fOperand1;
|
||||
private IASTTypeId fOperand2;
|
||||
|
||||
public CPPASTBinaryTypeIdExpression() {
|
||||
}
|
||||
|
||||
public CPPASTBinaryTypeIdExpression(Operator op, IASTTypeId typeId1, IASTTypeId typeId2) {
|
||||
fOperator = op;
|
||||
setOperand1(typeId1);
|
||||
setOperand2(typeId2);
|
||||
}
|
||||
|
||||
public CPPASTBinaryTypeIdExpression copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
public CPPASTBinaryTypeIdExpression copy(CopyStyle style) {
|
||||
CPPASTBinaryTypeIdExpression copy = new CPPASTBinaryTypeIdExpression(fOperator,
|
||||
fOperand1 == null ? null : fOperand1.copy(),
|
||||
fOperand2 == null ? null : fOperand2.copy());
|
||||
copy.setOffsetAndLength(this);
|
||||
if (style == CopyStyle.withLocations) {
|
||||
copy.setCopyLocation(this);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Operator getOperator() {
|
||||
return fOperator;
|
||||
}
|
||||
|
||||
public void setOperator(Operator value) {
|
||||
assertNotFrozen();
|
||||
fOperator = value;
|
||||
}
|
||||
|
||||
public void setOperand1(IASTTypeId typeId) {
|
||||
assertNotFrozen();
|
||||
fOperand1 = typeId;
|
||||
if (typeId != null) {
|
||||
typeId.setParent(this);
|
||||
typeId.setPropertyInParent(OPERAND1);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOperand2(IASTTypeId typeId) {
|
||||
assertNotFrozen();
|
||||
fOperand2 = typeId;
|
||||
if (typeId != null) {
|
||||
typeId.setParent(this);
|
||||
typeId.setPropertyInParent(OPERAND2);
|
||||
}
|
||||
}
|
||||
|
||||
public IASTTypeId getOperand1() {
|
||||
return fOperand1;
|
||||
}
|
||||
|
||||
public IASTTypeId getOperand2() {
|
||||
return fOperand2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitExpressions) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fOperand1 != null && !fOperand1.accept(action))
|
||||
return false;
|
||||
if (fOperand2 != null && !fOperand2.accept(action))
|
||||
return false;
|
||||
|
||||
if (action.shouldVisitExpressions && action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public IType getExpressionType() {
|
||||
switch (getOperator()) {
|
||||
case __is_base_of:
|
||||
return CPPBasicType.BOOLEAN;
|
||||
}
|
||||
return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
|
||||
}
|
||||
|
||||
public boolean isLValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ValueCategory getValueCategory() {
|
||||
return isLValue() ? LVALUE : PRVALUE;
|
||||
}
|
||||
}
|
|
@ -112,7 +112,7 @@ public class CPPASTLiteralExpression extends ASTNode implements ICPPASTLiteralEx
|
|||
}
|
||||
case lk_true:
|
||||
case lk_false:
|
||||
return new CPPBasicType(Kind.eBoolean, 0, this);
|
||||
return CPPBasicType.BOOLEAN;
|
||||
case lk_char_constant:
|
||||
return new CPPBasicType(getCharType(), 0, this);
|
||||
case lk_float_constant:
|
||||
|
|
|
@ -98,6 +98,21 @@ public class CPPASTTypeIdExpression extends ASTNode implements ICPPASTTypeIdExpr
|
|||
return CPPVisitor.get_SIZE_T(this);
|
||||
case op_typeid:
|
||||
return CPPVisitor.get_type_info(this);
|
||||
case op_has_nothrow_copy:
|
||||
case op_has_nothrow_constructor:
|
||||
case op_has_trivial_assign:
|
||||
case op_has_trivial_constructor:
|
||||
case op_has_trivial_copy:
|
||||
case op_has_trivial_destructor:
|
||||
case op_has_virtual_destructor:
|
||||
case op_is_abstract:
|
||||
case op_is_class:
|
||||
case op_is_empty:
|
||||
case op_is_enum:
|
||||
case op_is_pod:
|
||||
case op_is_polymorphic:
|
||||
case op_is_union:
|
||||
return CPPBasicType.BOOLEAN;
|
||||
}
|
||||
return CPPVisitor.createType(getTypeId());
|
||||
}
|
||||
|
|
|
@ -15,10 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE;
|
||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.glvalueType;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.prvalueType;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromFunctionCall;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromFunctionCall;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.*;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF;
|
||||
|
@ -32,7 +29,6 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
|
@ -56,8 +52,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
|||
* Unary expression in c++
|
||||
*/
|
||||
public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpression, IASTAmbiguityParent {
|
||||
private static final CPPBasicType BOOLEAN_TYPE = new CPPBasicType(Kind.eBoolean, 0);
|
||||
|
||||
private int op;
|
||||
private IASTExpression operand;
|
||||
|
||||
|
@ -275,7 +269,7 @@ public class CPPASTUnaryExpression extends ASTNode implements ICPPASTUnaryExpres
|
|||
|
||||
switch (op) {
|
||||
case op_not:
|
||||
return BOOLEAN_TYPE;
|
||||
return CPPBasicType.BOOLEAN;
|
||||
case op_postFixDecr:
|
||||
case op_postFixIncr:
|
||||
typeOfOperand= prvalueType(typeOfOperand);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2010 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2011 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
|
||||
|
@ -27,6 +27,8 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* Integral c++ type.
|
||||
*/
|
||||
public class CPPBasicType implements ICPPBasicType, ISerializableType {
|
||||
public static final CPPBasicType BOOLEAN = new CPPBasicType(Kind.eBoolean, 0, null);
|
||||
|
||||
private final Kind fKind;
|
||||
private final int fModifiers;
|
||||
private IASTExpression fExpression;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2010 IBM Corporation and others.
|
||||
* Copyright (c) 2006, 2011 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,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression.Operator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
|
@ -157,6 +158,10 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
|
|||
return new CPPASTBinaryExpression(op, expr1, expr2);
|
||||
}
|
||||
|
||||
public IASTExpression newBinaryTypeIdExpression(Operator op, IASTTypeId type1, IASTTypeId type2) {
|
||||
return new CPPASTBinaryTypeIdExpression(op, type1, type2);
|
||||
}
|
||||
|
||||
public IASTBreakStatement newBreakStatement() {
|
||||
return new CPPASTBreakStatement();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression.Operator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
|
@ -1291,12 +1293,109 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
case IGCCToken.t___alignof__:
|
||||
return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
|
||||
IASTTypeIdExpression.op_alignof, IASTUnaryExpression.op_alignOf, ctx, strat);
|
||||
|
||||
case IGCCToken.tTT_has_nothrow_assign:
|
||||
case IGCCToken.tTT_has_nothrow_constructor:
|
||||
case IGCCToken.tTT_has_nothrow_copy:
|
||||
case IGCCToken.tTT_has_trivial_assign:
|
||||
case IGCCToken.tTT_has_trivial_constructor:
|
||||
case IGCCToken.tTT_has_trivial_copy:
|
||||
case IGCCToken.tTT_has_trivial_destructor:
|
||||
case IGCCToken.tTT_has_virtual_destructor:
|
||||
case IGCCToken.tTT_is_abstract:
|
||||
case IGCCToken.tTT_is_base_of:
|
||||
case IGCCToken.tTT_is_class:
|
||||
case IGCCToken.tTT_is_empty:
|
||||
case IGCCToken.tTT_is_enum:
|
||||
case IGCCToken.tTT_is_pod:
|
||||
case IGCCToken.tTT_is_polymorphic:
|
||||
case IGCCToken.tTT_is_union:
|
||||
return parseTypeTrait();
|
||||
|
||||
default:
|
||||
return postfixExpression(ctx, strat);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
private IASTExpression parseTypeTrait() throws EndOfFileException, BacktrackException {
|
||||
IToken first= consume();
|
||||
final boolean isBinary= isBinaryTrait(first);
|
||||
|
||||
consume(IToken.tLPAREN);
|
||||
IASTTypeId typeId= typeId(DeclarationOptions.TYPEID);
|
||||
IASTTypeId secondTypeId= null;
|
||||
if (isBinary) {
|
||||
consumeOrEOC(IToken.tCOMMA);
|
||||
if (LT(1) != IToken.tEOC) {
|
||||
secondTypeId= typeId(DeclarationOptions.TYPEID);
|
||||
}
|
||||
}
|
||||
int endOffset= consumeOrEOC(IToken.tRPAREN).getEndOffset();
|
||||
IASTExpression result;
|
||||
if (isBinary) {
|
||||
result= nodeFactory.newBinaryTypeIdExpression(getBinaryTypeTraitOperator(first), typeId, secondTypeId);
|
||||
} else {
|
||||
result= nodeFactory.newTypeIdExpression(getUnaryTypeTraitOperator(first), typeId);
|
||||
}
|
||||
return setRange(result, first.getOffset(), endOffset);
|
||||
}
|
||||
|
||||
private boolean isBinaryTrait(IToken first) {
|
||||
switch(first.getType()) {
|
||||
case IGCCToken.tTT_is_base_of:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Operator getBinaryTypeTraitOperator(IToken first) {
|
||||
switch(first.getType()) {
|
||||
case IGCCToken.tTT_is_base_of:
|
||||
return IASTBinaryTypeIdExpression.Operator.__is_base_of;
|
||||
}
|
||||
|
||||
assert false;
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getUnaryTypeTraitOperator(IToken first) {
|
||||
switch(first.getType()) {
|
||||
case IGCCToken.tTT_has_nothrow_assign:
|
||||
return IASTTypeIdExpression.op_has_nothrow_assign;
|
||||
case IGCCToken.tTT_has_nothrow_constructor:
|
||||
return IASTTypeIdExpression.op_has_nothrow_constructor;
|
||||
case IGCCToken.tTT_has_nothrow_copy:
|
||||
return IASTTypeIdExpression.op_has_nothrow_copy;
|
||||
case IGCCToken.tTT_has_trivial_assign:
|
||||
return IASTTypeIdExpression.op_has_trivial_assign;
|
||||
case IGCCToken.tTT_has_trivial_constructor:
|
||||
return IASTTypeIdExpression.op_has_trivial_constructor;
|
||||
case IGCCToken.tTT_has_trivial_copy:
|
||||
return IASTTypeIdExpression.op_has_trivial_copy;
|
||||
case IGCCToken.tTT_has_trivial_destructor:
|
||||
return IASTTypeIdExpression.op_has_trivial_destructor;
|
||||
case IGCCToken.tTT_has_virtual_destructor:
|
||||
return IASTTypeIdExpression.op_has_virtual_destructor;
|
||||
case IGCCToken.tTT_is_abstract:
|
||||
return IASTTypeIdExpression.op_is_abstract;
|
||||
case IGCCToken.tTT_is_class:
|
||||
return IASTTypeIdExpression.op_is_class;
|
||||
case IGCCToken.tTT_is_empty:
|
||||
return IASTTypeIdExpression.op_is_abstract;
|
||||
case IGCCToken.tTT_is_enum:
|
||||
return IASTTypeIdExpression.op_is_abstract;
|
||||
case IGCCToken.tTT_is_pod:
|
||||
return IASTTypeIdExpression.op_is_abstract;
|
||||
case IGCCToken.tTT_is_polymorphic:
|
||||
return IASTTypeIdExpression.op_is_abstract;
|
||||
case IGCCToken.tTT_is_union:
|
||||
return IASTTypeIdExpression.op_is_abstract;
|
||||
}
|
||||
assert false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* postfix-expression:
|
||||
* [gnu-extension, compound literals in c++]
|
||||
* ( type-name ) { initializer-list }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2010, 2011 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
|
||||
|
@ -57,7 +57,6 @@ class BuiltinOperators {
|
|||
private static final ICPPFunction[] EMPTY = {};
|
||||
private static final int FIRST = 0;
|
||||
private static final int SECOND = 1;
|
||||
private static final IType BOOL = new CPPBasicType(Kind.eBoolean, 0);
|
||||
private static final IType PTR_DIFF = new CPPBasicType(Kind.eInt, 0);
|
||||
|
||||
public static ICPPFunction[] create(OverloadableOperator operator, IASTInitializerClause[] args, IASTTranslationUnit tu, Object[] globCandidates) {
|
||||
|
@ -213,11 +212,11 @@ class BuiltinOperators {
|
|||
|
||||
case AND:
|
||||
case OR:
|
||||
addFunction(BOOL, BOOL, BOOL);
|
||||
addFunction(CPPBasicType.BOOLEAN, CPPBasicType.BOOLEAN, CPPBasicType.BOOLEAN);
|
||||
break;
|
||||
|
||||
case NOT:
|
||||
addFunction(BOOL, BOOL);
|
||||
addFunction(CPPBasicType.BOOLEAN, CPPBasicType.BOOLEAN);
|
||||
break;
|
||||
|
||||
case CONDITIONAL_OPERATOR:
|
||||
|
@ -393,7 +392,7 @@ class BuiltinOperators {
|
|||
IType rt= null;
|
||||
switch(rstrat) {
|
||||
case USE_BOOL:
|
||||
rt= BOOL;
|
||||
rt= CPPBasicType.BOOLEAN;
|
||||
break;
|
||||
case USE_FIRST:
|
||||
rt= t1;
|
||||
|
@ -475,7 +474,7 @@ class BuiltinOperators {
|
|||
for (IType type : types) {
|
||||
type= SemanticUtil.getNestedType(type, TDEF|REF|CVTYPE);
|
||||
if (isPointer(type) || isEnumeration(type) || (!ordered && isPointerToMember(type))) {
|
||||
addFunction(BOOL, type, type);
|
||||
addFunction(CPPBasicType.BOOLEAN, type, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue