1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +02:00

Bug 553794 - Add support for the __integer_pack builtin

Change-Id: Idc978d1d0b44cfe326283a0c3779969fdc3f3599
This commit is contained in:
Nathan Ridge 2020-01-26 03:06:52 -05:00
parent d11f7216a4
commit cd2ed18cd6
8 changed files with 52 additions and 1 deletions

View file

@ -11385,4 +11385,19 @@ public class AST2TemplateTests extends AST2CPPTestBase {
public void testStringLiteralOperatorTemplate_536986() throws Exception {
parseAndCheckImplicitNameBindings();
}
// template <int...>
// struct integer_sequence {};
//
// template <int N>
// using make_integer_sequence = integer_sequence<__integer_pack(N)...>;
//
// using type1 = integer_sequence<0, 1, 2>;
// using type2 = make_integer_sequence<3>;
public void testIntegerPack_553794() throws Exception {
BindingAssertionHelper helper = getAssertionHelper();
ITypedef type1 = helper.assertNonProblem("type1");
ITypedef type2 = helper.assertNonProblem("type2");
assertSameType(type1, type2);
}
}

View file

@ -134,6 +134,12 @@ public interface IASTUnaryExpression extends IASTExpression {
*/
public static final int op_labelReference = 18;
/**
* For GCC parsers in C++ mode, only: '__integer_pack ( expression )'
* @since 6.10
*/
public static final int op_integerPack = 19;
/**
* {@code OPERAND} represents the relationship between an {@code IASTUnaryExpression} and
* it's nested {@code IASTExpression}.

View file

@ -175,6 +175,7 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
}
if (version >= VERSION_8_0) {
addKeyword(GCCKeywords.cp__is_constructible, IGCCToken.tTT_is_constructible);
addKeyword(GCCKeywords.cp__integer_pack, IGCCToken.tTT_integer_pack);
}
} else if (compiler == CompilerType.Clang) {
// As documented at
@ -201,6 +202,7 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
addKeyword(GCCKeywords.cp__is_trivially_constructible, IGCCToken.tTT_is_trivially_constructible);
addKeyword(GCCKeywords.cp__is_trivially_assignable, IGCCToken.tTT_is_trivially_assignable);
addKeyword(GCCKeywords.cp__is_constructible, IGCCToken.tTT_is_constructible);
addKeyword(GCCKeywords.cp__integer_pack, IGCCToken.tTT_integer_pack);
} else if (compiler == CompilerType.MSVC) {
// As documented at
// https://docs.microsoft.com/en-us/cpp/extensions/compiler-support-for-type-traits-cpp-component-extensions?view=vs-2017

View file

@ -90,4 +90,7 @@ public class GCCKeywords {
/** @since 6.6 */
public static final char[] cp__is_constructible = "__is_constructible".toCharArray();
/** @since 6.10 */
public static final char[] cp__integer_pack = "__integer_pack".toCharArray();
}

View file

@ -93,4 +93,7 @@ public interface IGCCToken extends IToken {
/** @since 6.6 */
int tTT_is_constructible = FIRST_RESERVED_IGCCToken + 35;
/** @since 6.10 */
int tTT_integer_pack = FIRST_RESERVED_IGCCToken + 36;
}

View file

@ -1540,7 +1540,8 @@ 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_integer_pack:
return unaryExpression(IASTUnaryExpression.op_integerPack, ctx, strat);
case IGCCToken.tTT_has_nothrow_assign:
case IGCCToken.tTT_has_nothrow_constructor:
case IGCCToken.tTT_has_nothrow_copy:

View file

@ -19,6 +19,7 @@ import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_alignOf;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_amper;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_bracketedPrimary;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_integerPack;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_minus;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_noexcept;
import static org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_not;
@ -156,6 +157,8 @@ public class EvalUnary extends CPPDependentEvaluation {
return fArgument.referencesTemplateParameter();
case op_throw:
return false;
case op_integerPack:
return true;
default:
return fArgument.isValueDependent();
}
@ -242,6 +245,8 @@ public class EvalUnary extends CPPDependentEvaluation {
return CPPVisitor.get_type_info();
case op_throw:
return CPPSemantics.VOID_TYPE;
case op_integerPack:
return fArgument.getType();
case op_amper:
if (fAddressOfQualifiedNameBinding instanceof ICPPMember) {
ICPPMember member = (ICPPMember) fAddressOfQualifiedNameBinding;
@ -394,6 +399,10 @@ public class EvalUnary extends CPPDependentEvaluation {
@Override
public ICPPEvaluation instantiate(InstantiationContext context, int maxDepth) {
if (fOperator == op_integerPack && context.getPackOffset() != -1) {
return new EvalFixed(getType(), ValueCategory.PRVALUE, IntegralValue.create(context.getPackOffset()));
}
ICPPEvaluation argument = fArgument.instantiate(context, maxDepth);
IBinding binding = fAddressOfQualifiedNameBinding;
if (binding instanceof ICPPUnknownBinding) {
@ -520,6 +529,15 @@ public class EvalUnary extends CPPDependentEvaluation {
@Override
public int determinePackSize(ICPPTemplateParameterMap tpMap) {
if (fOperator == op_integerPack) {
ICPPEvaluation instantiatedArg = fArgument.instantiate(new InstantiationContext(tpMap),
IntegralValue.MAX_RECURSION_DEPTH);
IValue value = instantiatedArg.getValue();
if (value.numberValue() != null) {
return (int) value.numberValue().longValue();
}
return CPPTemplates.PACK_SIZE_DEFER;
}
return fArgument.determinePackSize(tpMap);
}

View file

@ -2322,6 +2322,9 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
addTypeTraitPrimitive("is_trivially_copyable", GCCKeywords.cp__is_trivially_copyable);
addTypeTraitPrimitive("is_union", GCCKeywords.cp__is_union);
addTypeTraitPrimitive("underlying_type", GCCKeywords.cp__underlying_type);
// TODO: If at some point we add support for __has_builtin, "__integer_pack"
// should be added to the list of supported builtins.
}
return sSupportedFeatures;
}