1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Add more C++ builtins

Add __has_unique_object_representations
    __is_aggregate
    __is_assignable
    __is_nothrow_assignable
    __is_nothrow_constructible
This commit is contained in:
Igor V. Kovalenko 2023-02-14 22:18:35 +03:00 committed by Jonah Graham
parent ab721eed87
commit 8f2342e842
12 changed files with 102 additions and 7 deletions

View file

@ -35,6 +35,10 @@ public interface IASTBinaryTypeIdExpression extends IASTExpression {
* @since 7.1
*/
__is_same,
/** @since 8.1 */
__is_assignable,
/** @since 8.1 */
__is_nothrow_assignable,
}
/**

View file

@ -167,6 +167,18 @@ public interface IASTTypeIdExpression extends IASTExpression {
*/
public static final int op_is_trivially_copyable = 24;
/**
* Built-in type trait of g++.
* @since 8.1
*/
public static final int op_has_unique_object_representations = 25;
/**
* Built-in type trait of g++.
* @since 8.1
*/
public static final int op_is_aggregate = 26;
/**
* Returns the operator for the expression.
*

View file

@ -30,7 +30,9 @@ public interface ICPPASTNaryTypeIdExpression extends ICPPASTExpression {
public static enum Operator {
__is_trivially_constructible,
/** @since 6.6 */
__is_constructible
__is_constructible,
/** @since 8.1 */
__is_nothrow_constructible,
}
/**

View file

@ -43,6 +43,7 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
private static final int VERSION_6_0 = version(6, 0);
private static final int VERSION_8_0 = version(8, 0);
private static final int VERSION_10_0 = version(10, 0);
private static final int VERSION_11_1 = version(11, 1);
private static GPPScannerExtensionConfiguration CONFIG = new GPPScannerExtensionConfiguration();
private static GPPScannerExtensionConfiguration CONFIG_4_2 = new GPPScannerExtensionConfiguration(VERSION_4_2);
private static GPPScannerExtensionConfiguration CONFIG_4_3 = new GPPScannerExtensionConfiguration(VERSION_4_3);
@ -52,6 +53,7 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
private static GPPScannerExtensionConfiguration CONFIG_6_0 = new GPPScannerExtensionConfiguration(VERSION_6_0);
private static GPPScannerExtensionConfiguration CONFIG_8_0 = new GPPScannerExtensionConfiguration(VERSION_8_0);
private static GPPScannerExtensionConfiguration CONFIG_10_0 = new GPPScannerExtensionConfiguration(VERSION_10_0);
private static GPPScannerExtensionConfiguration CONFIG_11_1 = new GPPScannerExtensionConfiguration(VERSION_11_1);
private static GPPScannerExtensionConfiguration CONFIG_CLANG = new GPPScannerExtensionConfiguration(
CompilerType.Clang, 0 /* version is ignored for now */);
private static GPPScannerExtensionConfiguration CONFIG_CLANG_CL = new GPPScannerExtensionConfiguration(
@ -89,6 +91,9 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
int major = Integer.valueOf(definedSymbols.get("__GNUC__")); //$NON-NLS-1$
int minor = Integer.valueOf(definedSymbols.get("__GNUC_MINOR__")); //$NON-NLS-1$
int version = version(major, minor);
if (version >= VERSION_11_1) {
return CONFIG_11_1;
}
if (version >= VERSION_10_0) {
return CONFIG_10_0;
}
@ -192,12 +197,20 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
addKeyword(GCCKeywords.cp__is_same_as, IGCCToken.tTT_is_same);
}
if (version >= VERSION_8_0) {
addKeyword(GCCKeywords.cp__has_unique_object_representations,
IGCCToken.tTT_has_unique_object_representations);
addKeyword(GCCKeywords.cp__is_aggregate, IGCCToken.tTT_is_aggregate);
addKeyword(GCCKeywords.cp__is_assignable, IGCCToken.tTT_is_assignable);
addKeyword(GCCKeywords.cp__is_constructible, IGCCToken.tTT_is_constructible);
addKeyword(GCCKeywords.cp__integer_pack, IGCCToken.tTT_integer_pack);
}
if (version >= VERSION_10_0) {
addKeyword(GCCKeywords.cp__is_same, IGCCToken.tTT_is_same);
}
if (version >= VERSION_11_1) {
addKeyword(GCCKeywords.cp__is_nothrow_assignable, IGCCToken.tTT_is_nothrow_assignable);
addKeyword(GCCKeywords.cp__is_nothrow_constructible, IGCCToken.tTT_is_nothrow_constructible);
}
} else if (compiler == CompilerType.Clang || compiler == CompilerType.ClangCl) {
// As documented at
// http://clang.llvm.org/docs/LanguageExtensions.html#checks-for-type-trait-primitives.
@ -212,13 +225,14 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
addKeyword(GCCKeywords.cp__has_trivial_copy, IGCCToken.tTT_has_trivial_copy);
addKeyword(GCCKeywords.cp__has_trivial_constructor, IGCCToken.tTT_has_trivial_constructor);
addKeyword(GCCKeywords.cp__has_trivial_destructor, IGCCToken.tTT_has_trivial_destructor);
// __has_unique_object_representations
addKeyword(GCCKeywords.cp__has_unique_object_representations,
IGCCToken.tTT_has_unique_object_representations);
addKeyword(GCCKeywords.cp__has_virtual_destructor, IGCCToken.tTT_has_virtual_destructor);
addKeyword(GCCKeywords.cp__is_abstract, IGCCToken.tTT_is_abstract);
// __is_aggregate
addKeyword(GCCKeywords.cp__is_aggregate, IGCCToken.tTT_is_aggregate);
// __is_arithmetic
// __is_array
// __is_assignable
addKeyword(GCCKeywords.cp__is_assignable, IGCCToken.tTT_is_assignable);
addKeyword(GCCKeywords.cp__is_base_of, IGCCToken.tTT_is_base_of);
addKeyword(GCCKeywords.cp__is_class, IGCCToken.tTT_is_class);
// __is_complete_type
@ -242,8 +256,8 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
// __is_member_object_pointer
// __is_member_function_pointer
// __is_member_pointer
// __is_nothrow_assignable
// __is_nothrow_constructible
addKeyword(GCCKeywords.cp__is_nothrow_assignable, IGCCToken.tTT_is_nothrow_assignable);
addKeyword(GCCKeywords.cp__is_nothrow_constructible, IGCCToken.tTT_is_nothrow_constructible);
// __is_nothrow_destructible
// __is_object
addKeyword(GCCKeywords.cp__is_pod, IGCCToken.tTT_is_pod);

View file

@ -104,4 +104,14 @@ public class GCCKeywords {
* @since 7.1
*/
public static final char[] cp__is_same = "__is_same".toCharArray(), cp__is_same_as = "__is_same_as".toCharArray();
/** @since 8.1 */
public static final char[] cp__has_unique_object_representations = "__has_unique_object_representations"
.toCharArray();
/** @since 8.1 */
public static final char[] cp__is_aggregate = "__is_aggregate".toCharArray(),
cp__is_assignable = "__is_assignable".toCharArray(),
cp__is_nothrow_assignable = "__is_nothrow_assignable".toCharArray(),
cp__is_nothrow_constructible = "__is_nothrow_constructible".toCharArray();
}

View file

@ -101,4 +101,15 @@ public interface IGCCToken extends IToken {
* @since 7.1
*/
int tTT_is_same = FIRST_RESERVED_IGCCToken + 37;
/** @since 8.1 */
int tTT_is_aggregate = FIRST_RESERVED_IGCCToken + 38;
/** @since 8.1 */
int tTT_is_assignable = FIRST_RESERVED_IGCCToken + 39;
/** @since 8.1 */
int tTT_is_nothrow_assignable = FIRST_RESERVED_IGCCToken + 40;
/** @since 8.1 */
int tTT_is_nothrow_constructible = FIRST_RESERVED_IGCCToken + 41;
/** @since 8.1 */
int tTT_has_unique_object_representations = FIRST_RESERVED_IGCCToken + 42;
}

View file

@ -22,8 +22,10 @@ import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_a
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_constructor;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_copy;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_destructor;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_unique_object_representations;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_virtual_destructor;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_abstract;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_aggregate;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_class;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_empty;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_enum;
@ -445,11 +447,16 @@ public class ValueFactory {
!(type instanceof ICPPClassType) || TypeTraits.hasTrivialCopyCtor((ICPPClassType) type) ? 1 : 0);
case op_has_trivial_destructor:
break; // TODO(sprigogin): Implement
case op_has_unique_object_representations:
break; // TODO: Implement
case op_has_virtual_destructor:
break; // TODO(sprigogin): Implement
case op_is_abstract:
return IntegralValue
.create(type instanceof ICPPClassType && TypeTraits.isAbstract((ICPPClassType) type) ? 1 : 0);
case op_is_aggregate:
return IntegralValue
.create(type instanceof ICPPClassType && TypeTraits.isAggregateClass((ICPPClassType) type) ? 1 : 0);
case op_is_class:
return IntegralValue.create(
type instanceof ICompositeType && ((ICompositeType) type).getKey() != ICompositeType.k_union ? 1
@ -629,6 +636,10 @@ public class ValueFactory {
return IntegralValue.create(1);
}
return IntegralValue.create(0);
case __is_assignable:
return IntegralValue.UNKNOWN; // TODO: Implement.
case __is_nothrow_assignable:
return IntegralValue.UNKNOWN; // TODO: Implement.
case __is_same:
if (type1.isSameType(type2)) {
return IntegralValue.create(1);
@ -654,6 +665,8 @@ public class ValueFactory {
return IntegralValue.create(
TypeTraits.isConstructible(typeToConstruct, argumentTypes, pointOfDefinition, checkTrivial) ? 1
: 0);
case __is_nothrow_constructible:
return IntegralValue.UNKNOWN; // TODO: Implement
}
return IntegralValue.UNKNOWN;
}

View file

@ -1789,8 +1789,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
case IGCCToken.tTT_has_trivial_constructor:
case IGCCToken.tTT_has_trivial_copy:
case IGCCToken.tTT_has_trivial_destructor:
case IGCCToken.tTT_has_unique_object_representations:
case IGCCToken.tTT_has_virtual_destructor:
case IGCCToken.tTT_is_abstract:
case IGCCToken.tTT_is_aggregate:
case IGCCToken.tTT_is_base_of:
case IGCCToken.tTT_is_class:
case IGCCToken.tTT_is_empty:
@ -1807,6 +1809,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
case IGCCToken.tTT_is_trivially_assignable:
case IGCCToken.tTT_is_constructible:
case IGCCToken.tTT_is_same:
case IGCCToken.tTT_is_assignable:
case IGCCToken.tTT_is_nothrow_assignable:
case IGCCToken.tTT_is_nothrow_constructible:
return parseTypeTrait();
default:
@ -1857,6 +1862,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private boolean isBinaryTrait(IToken first) {
switch (first.getType()) {
case IGCCToken.tTT_is_base_of:
case IGCCToken.tTT_is_assignable:
case IGCCToken.tTT_is_nothrow_assignable:
case IGCCToken.tTT_is_trivially_assignable:
case IGCCToken.tTT_is_same:
return true;
@ -1868,6 +1875,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
switch (operatorToken.getType()) {
case IGCCToken.tTT_is_trivially_constructible:
case IGCCToken.tTT_is_constructible:
case IGCCToken.tTT_is_nothrow_constructible:
return true;
}
return false;
@ -1877,6 +1885,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
switch (first.getType()) {
case IGCCToken.tTT_is_base_of:
return IASTBinaryTypeIdExpression.Operator.__is_base_of;
case IGCCToken.tTT_is_assignable:
return IASTBinaryTypeIdExpression.Operator.__is_assignable;
case IGCCToken.tTT_is_nothrow_assignable:
return IASTBinaryTypeIdExpression.Operator.__is_nothrow_assignable;
case IGCCToken.tTT_is_trivially_assignable:
return IASTBinaryTypeIdExpression.Operator.__is_trivially_assignable;
case IGCCToken.tTT_is_same:
@ -1893,6 +1905,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return ICPPASTNaryTypeIdExpression.Operator.__is_trivially_constructible;
case IGCCToken.tTT_is_constructible:
return ICPPASTNaryTypeIdExpression.Operator.__is_constructible;
case IGCCToken.tTT_is_nothrow_constructible:
return ICPPASTNaryTypeIdExpression.Operator.__is_nothrow_constructible;
}
assert false;
@ -1915,10 +1929,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return IASTTypeIdExpression.op_has_trivial_copy;
case IGCCToken.tTT_has_trivial_destructor:
return IASTTypeIdExpression.op_has_trivial_destructor;
case IGCCToken.tTT_has_unique_object_representations:
return IASTTypeIdExpression.op_has_unique_object_representations;
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_aggregate:
return IASTTypeIdExpression.op_is_aggregate;
case IGCCToken.tTT_is_class:
return IASTTypeIdExpression.op_is_class;
case IGCCToken.tTT_is_empty:

View file

@ -79,9 +79,13 @@ public class EvalBinaryTypeId extends CPPDependentEvaluation {
public IType getType() {
switch (fOperator) {
case __is_base_of:
case __is_assignable:
case __is_nothrow_assignable:
case __is_trivially_assignable:
case __is_same:
return CPPBasicType.BOOLEAN;
default:
break;
}
return ProblemType.UNKNOWN_FOR_EXPRESSION;
}

View file

@ -101,6 +101,7 @@ public class EvalNaryTypeId extends CPPDependentEvaluation {
switch (fOperator) {
case __is_trivially_constructible:
case __is_constructible:
case __is_nothrow_constructible:
return CPPBasicType.BOOLEAN;
}
return ProblemType.UNKNOWN_FOR_EXPRESSION;

View file

@ -23,8 +23,10 @@ import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_a
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_constructor;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_copy;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_trivial_destructor;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_unique_object_representations;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_has_virtual_destructor;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_abstract;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_aggregate;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_class;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_empty;
import static org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression.op_is_enum;
@ -112,8 +114,10 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation {
case op_has_trivial_constructor:
case op_has_trivial_copy:
case op_has_trivial_destructor:
case op_has_unique_object_representations:
case op_has_virtual_destructor:
case op_is_abstract:
case op_is_aggregate:
case op_is_class:
case op_is_empty:
case op_is_enum:
@ -173,8 +177,10 @@ public class EvalUnaryTypeID extends CPPDependentEvaluation {
case op_has_trivial_constructor:
case op_has_trivial_copy:
case op_has_trivial_destructor:
case op_has_unique_object_representations:
case op_has_virtual_destructor:
case op_is_abstract:
case op_is_aggregate:
case op_is_class:
case op_is_empty:
case op_is_enum:

View file

@ -2352,7 +2352,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
// missing: is_interface_class
// missing: is_literal
// missing: is_nothrow_assignable
// missing: is_nothrow_constructible
addTypeTraitPrimitive("is_nothrow_constructible", GCCKeywords.cp__is_nothrow_constructible);
// missing: is_nothrow_destructible
addTypeTraitPrimitive("is_pod", GCCKeywords.cp__is_pod);
addTypeTraitPrimitive("is_polymorphic", GCCKeywords.cp__is_polymorphic);