mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 451082 - Added support for 'alignof'
This commit is contained in:
parent
8e7e750522
commit
2c9a404d44
5 changed files with 64 additions and 46 deletions
|
@ -9024,6 +9024,52 @@ public class AST2CPPTests extends AST2TestBase {
|
|||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// template <bool> struct B {};
|
||||
// template <>
|
||||
// struct B<true> {
|
||||
// void waldo();
|
||||
// };
|
||||
// typedef char& one;
|
||||
// void test() {
|
||||
// B<sizeof(one) == 1> b;
|
||||
// b.waldo();
|
||||
// }
|
||||
public void testSizeofReference_397342() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// struct A {
|
||||
// char a[100];
|
||||
// };
|
||||
// struct B {
|
||||
// A& b;
|
||||
// };
|
||||
// A* p;
|
||||
public void testSizeofStructWithReferenceField_397342() throws Exception {
|
||||
BindingAssertionHelper bh = getAssertionHelper();
|
||||
IASTName nameB = bh.findName("B");
|
||||
IASTName namep = bh.findName("p");
|
||||
ICPPClassType B = (ICPPClassType) nameB.resolveBinding();
|
||||
IPointerType ptrToA = (IPointerType) ((ICPPVariable) namep.resolveBinding()).getType();
|
||||
long pointerSize = SizeofCalculator.getSizeAndAlignment(ptrToA, namep).size;
|
||||
long BSize = SizeofCalculator.getSizeAndAlignment(B, nameB).size;
|
||||
assertEquals(pointerSize, BSize);
|
||||
}
|
||||
|
||||
// template <bool> struct B {};
|
||||
// template <>
|
||||
// struct B<true> {
|
||||
// void waldo();
|
||||
// };
|
||||
// typedef char& one;
|
||||
// void test() {
|
||||
// B<alignof(one) == 1> b;
|
||||
// b.waldo();
|
||||
// }
|
||||
public void testAlignof_451082() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// void f(int);
|
||||
// void f(unsigned int);
|
||||
// void test() {
|
||||
|
@ -10589,38 +10635,6 @@ public class AST2CPPTests extends AST2TestBase {
|
|||
assertEquals(1 /*true */, var.getInitialValue().numericalValue().longValue());
|
||||
}
|
||||
|
||||
// template <bool> struct B{};
|
||||
// template <>
|
||||
// struct B<true> {
|
||||
// void waldo();
|
||||
// };
|
||||
// typedef char& one;
|
||||
// int main() {
|
||||
// B<sizeof(one) == 1> b;
|
||||
// b.waldo();
|
||||
// }
|
||||
public void testSizeofReference_397342() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// struct A {
|
||||
// char a[100];
|
||||
// };
|
||||
// struct B {
|
||||
// A& b;
|
||||
// };
|
||||
// A* p;
|
||||
public void testSizeofStructWithReferenceField_397342() throws Exception {
|
||||
BindingAssertionHelper bh = getAssertionHelper();
|
||||
IASTName nameB = bh.findName("B");
|
||||
IASTName namep = bh.findName("p");
|
||||
ICPPClassType B = (ICPPClassType) nameB.resolveBinding();
|
||||
IPointerType ptrToA = (IPointerType) ((ICPPVariable) namep.resolveBinding()).getType();
|
||||
long pointerSize = SizeofCalculator.getSizeAndAlignment(ptrToA, namep).size;
|
||||
long BSize = SizeofCalculator.getSizeAndAlignment(B, nameB).size;
|
||||
assertEquals(pointerSize, BSize);
|
||||
}
|
||||
|
||||
// namespace NS {
|
||||
// class Enclosing {
|
||||
// class Inner {};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2010 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2015 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
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
|
@ -95,6 +96,8 @@ public interface IToken {
|
|||
*/
|
||||
int tGT_in_SHIFTR= 5201;
|
||||
|
||||
/** @since 5.9 */ int t_alignas = 5900;
|
||||
/** @since 5.9 */ int t_alignof = 5901;
|
||||
/** @deprecated use {@link #tAND} */ @Deprecated int t_and = 54;
|
||||
/** @deprecated use {@link #tAMPERASSIGN} */ @Deprecated int t_and_eq = 55;
|
||||
int t_asm = 56;
|
||||
|
@ -106,10 +109,8 @@ public interface IToken {
|
|||
int t_case = 62;
|
||||
int t_catch = 63;
|
||||
int t_char = 64;
|
||||
/** @since 5.2 */
|
||||
int t_char16_t= 5202;
|
||||
/** @since 5.2 */
|
||||
int t_char32_t= 5203;
|
||||
/** @since 5.2 */ int t_char16_t= 5202;
|
||||
/** @since 5.2 */ int t_char32_t= 5203;
|
||||
int t_class = 65;
|
||||
/** @deprecated use {@link #tBITCOMPLEMENT} */ @Deprecated int tCOMPL= tBITCOMPLEMENT;
|
||||
/** @deprecated use {@link #tBITCOMPLEMENT} */ @Deprecated int t_compl = 66;
|
||||
|
@ -118,8 +119,7 @@ public interface IToken {
|
|||
/** @since 5.4 */ int t_constexpr = 5400;
|
||||
int t_const_cast = 69;
|
||||
int t_continue = 70;
|
||||
/** @since 5.2 */
|
||||
int t_decltype= 5204;
|
||||
/** @since 5.2 */ int t_decltype= 5204;
|
||||
int t_default = 71;
|
||||
int t_delete = 72;
|
||||
int t_do = 73;
|
||||
|
@ -158,8 +158,7 @@ public interface IToken {
|
|||
int t_short = 104;
|
||||
int t_sizeof = 105;
|
||||
int t_static = 106;
|
||||
/** @since 5.2 */
|
||||
int t_static_assert = 5205;
|
||||
/** @since 5.2 */ int t_static_assert = 5205;
|
||||
int t_static_cast = 107;
|
||||
int t_signed = 108;
|
||||
int t_struct = 109;
|
||||
|
@ -226,7 +225,6 @@ public interface IToken {
|
|||
FINAL
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2012 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2015 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
|
||||
|
@ -9,6 +9,7 @@
|
|||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
* Thomas Corbat (IFS)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
@ -306,7 +307,7 @@ public class Keywords {
|
|||
public static final char[] cVA_ARGS= "__VA_ARGS__".toCharArray();
|
||||
|
||||
|
||||
// preprocessor extensions (supported by GCC)
|
||||
// Preprocessor extensions (supported by GCC).
|
||||
public static final char[] cINCLUDE_NEXT = "include_next".toCharArray();
|
||||
public static final char[] cIMPORT = "import".toCharArray();
|
||||
public static final char[] cIDENT = "ident".toCharArray();
|
||||
|
@ -327,6 +328,8 @@ public class Keywords {
|
|||
|
||||
private static void addCommon(CharArrayIntMap words) {
|
||||
words.put(Keywords._Pragma, IToken.t_PRAGMA);
|
||||
words.put(Keywords.cALIGNAS, IToken.t_alignas);
|
||||
words.put(Keywords.cALIGNOF, IToken.t_alignof);
|
||||
words.put(Keywords.cAUTO, IToken.t_auto);
|
||||
words.put(Keywords.cBREAK, IToken.t_break);
|
||||
words.put(Keywords.cCASE, IToken.t_case);
|
||||
|
@ -363,7 +366,7 @@ public class Keywords {
|
|||
words.put(Keywords.cASM, IToken.t_asm);
|
||||
}
|
||||
|
||||
// ANSI C keywords
|
||||
// ANSI C keywords
|
||||
private static void addC(CharArrayIntMap ckeywords) {
|
||||
ckeywords.put(Keywords.cRESTRICT, IToken.t_restrict);
|
||||
ckeywords.put(Keywords.c_BOOL, IToken.t__Bool);
|
||||
|
|
|
@ -612,6 +612,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
case IToken.t_sizeof:
|
||||
return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
|
||||
IASTTypeIdExpression.op_sizeof, IASTUnaryExpression.op_sizeof, ctx, strat);
|
||||
case IToken.t_alignof:
|
||||
case IGCCToken.t___alignof__:
|
||||
return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
|
||||
IASTTypeIdExpression.op_alignof, IASTUnaryExpression.op_alignOf, ctx, strat);
|
||||
|
|
|
@ -326,7 +326,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (!haveName || destructorOffset >= 0 || keywordTemplate) {
|
||||
throwBacktrack(LA(1));
|
||||
}
|
||||
nameSpec= (ICPPASTName) nodeFactory.newName(CharArrayUtils.EMPTY);
|
||||
nameSpec= nodeFactory.newName(CharArrayUtils.EMPTY);
|
||||
if (qname != null) {
|
||||
addNameSpecifier(qname, nameSpec);
|
||||
}
|
||||
|
@ -593,6 +593,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
case IToken.t_new:
|
||||
case IToken.t_delete:
|
||||
case IToken.t_sizeof:
|
||||
case IToken.t_alignof:
|
||||
case IGCCToken.t___alignof__:
|
||||
return NO_TEMPLATE_ID;
|
||||
|
||||
|
@ -1404,6 +1405,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
|
||||
IASTTypeIdExpression.op_sizeof, IASTUnaryExpression.op_sizeof, ctx, strat);
|
||||
case IToken.t_alignof:
|
||||
case IGCCToken.t___alignof__:
|
||||
return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
|
||||
IASTTypeIdExpression.op_alignof, IASTUnaryExpression.op_alignOf, ctx, strat);
|
||||
|
|
Loading…
Add table
Reference in a new issue