diff options
author | Sergey Prigogin | 2015-01-21 22:33:16 +0000 |
---|---|---|
committer | Sergey Prigogin | 2015-01-21 22:38:05 +0000 |
commit | 0cdcaa2a492f315c42a9f2ad656d6dc98e185211 (patch) | |
tree | 5f4b1bcc874a9c7dcb6eb32b8da63b0d35d96637 | |
parent | 9c47c59447a907002109450ea42edadc2b78fa50 (diff) | |
download | org.eclipse.cdt-0cdcaa2a492f315c42a9f2ad656d6dc98e185211.tar.gz org.eclipse.cdt-0cdcaa2a492f315c42a9f2ad656d6dc98e185211.tar.xz org.eclipse.cdt-0cdcaa2a492f315c42a9f2ad656d6dc98e185211.zip |
Bug 451082 - Added support for 'alignof'
5 files changed, 64 insertions, 46 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 255c355c3cb..cc0da496320 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -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 {}; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java index f90daa171ca..f81fb853d2c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java @@ -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. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Keywords.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Keywords.java index 52284de7bd2..3bc04c44b06 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Keywords.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/Keywords.java @@ -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); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 33756577651..1bc652fac09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -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); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 1edb957f6cc..d80e7421d13 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -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); |