1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-16 13:35:22 +02:00

Bug 451082 - Lexer support for the C11 keywords _Alignof and _Alignas

This also corrects a mistake where the C parser would recognize the
C++11 forms (alignof and alignas) as keywords, and parse alignof.

Change-Id: Iab878670f6deb912a637af2220a1a24a5d81c18d
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2015-03-12 21:59:36 -04:00 committed by Sergey Prigogin
parent 02972325cc
commit a7b52f139b
4 changed files with 19 additions and 3 deletions

View file

@ -194,6 +194,8 @@ public interface IToken {
/** @since 5.1 */ int tUTF16CHAR = 5002;
/** @since 5.1 */ int tUTF32CHAR = 5003;
/** @since 5.10 */ int t__Alignas = 51000;
/** @since 5.10 */ int t__Alignof = 51001;
int t__Bool = 134;
int t__Complex = 135;
int t__Imaginary = 136;

View file

@ -31,6 +31,10 @@ public class Keywords {
public static final String _BOOL = "_Bool";
public static final String _COMPLEX = "_Complex";
public static final String _IMAGINARY = "_Imaginary";
/** @since 5.10 */
public static final String _ALIGNAS = "_Alignas";
/** @since 5.10 */
public static final String _ALIGNOF = "_Alignof";
public static final String AND = "and";
public static final String AND_EQ = "and_eq";
public static final String ASM = "asm";
@ -132,6 +136,10 @@ public class Keywords {
public static final char[] c_BOOL = "_Bool".toCharArray();
public static final char[] c_COMPLEX = "_Complex".toCharArray();
public static final char[] c_IMAGINARY = "_Imaginary".toCharArray();
/** @since 5.10 */
public static final char[] c_ALIGNAS = _ALIGNAS.toCharArray();
/** @since 5.10 */
public static final char[] c_ALIGNOF = _ALIGNOF.toCharArray();
/** @since 5.4 */
public static final char[] cALIGNAS = "alignas".toCharArray();
/** @since 5.3 */
@ -328,8 +336,6 @@ 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);
@ -369,12 +375,16 @@ public class Keywords {
// ANSI C keywords
private static void addC(CharArrayIntMap ckeywords) {
ckeywords.put(Keywords.cRESTRICT, IToken.t_restrict);
ckeywords.put(Keywords.c_ALIGNAS, IToken.t__Alignas);
ckeywords.put(Keywords.c_ALIGNOF, IToken.t__Alignof);
ckeywords.put(Keywords.c_BOOL, IToken.t__Bool);
ckeywords.put(Keywords.c_COMPLEX, IToken.t__Complex);
ckeywords.put(Keywords.c_IMAGINARY, IToken.t__Imaginary);
}
private static void addCpp(CharArrayIntMap cppkeywords) {
cppkeywords.put(Keywords.cALIGNAS, IToken.t_alignas);
cppkeywords.put(Keywords.cALIGNOF, IToken.t_alignof);
cppkeywords.put(Keywords.cBOOL, IToken.t_bool);
cppkeywords.put(Keywords.cCATCH, IToken.t_catch);
cppkeywords.put(Keywords.cCHAR16_T, IToken.t_char16_t);

View file

@ -612,7 +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 IToken.t__Alignof:
case IGCCToken.t___alignof__:
return parseTypeidInParenthesisOrUnaryExpression(false, consume().getOffset(),
IASTTypeIdExpression.op_alignof, IASTUnaryExpression.op_alignOf, ctx, strat);

View file

@ -370,6 +370,8 @@ public class KeywordSets {
ALL_C.add(Keywords.VOID);
ALL_C.add(Keywords.VOLATILE);
ALL_C.add(Keywords.WHILE);
ALL_C.add(Keywords._ALIGNAS);
ALL_C.add(Keywords._ALIGNOF);
ALL_C.add(Keywords._BOOL);
ALL_C.add(Keywords._COMPLEX);
ALL_C.add(Keywords._IMAGINARY);
@ -577,6 +579,8 @@ public class KeywordSets {
KEYWORDS_C.add(Keywords.UNION);
KEYWORDS_C.add(Keywords.VOLATILE);
KEYWORDS_C.add(Keywords.WHILE);
KEYWORDS_C.add(Keywords._ALIGNAS);
KEYWORDS_C.add(Keywords._ALIGNOF);
}
private static final Map<ParserLanguage, Set<String>> KEYWORDS_TABLE;