[cfe-commits] r39214 - in /cfe/cfe/trunk: Lex/IdentifierTable.cpp Lex/Preprocessor.cpp include/clang/Basic/TokenKinds.def include/clang/Lex/IdentifierTable.h test/Preprocessor/cxx_and.cpp test/Preprocessor/cxx_bitand.cpp test/Preprocessor/cxx_bitor.cpp test/Preprocessor/cxx_compl.cpp test/Preprocessor/cxx_not.cpp test/Preprocessor/cxx_not_eq.cpp test/Preprocessor/cxx_or.cpp test/Preprocessor/cxx_xor.cpp
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:41:19 PDT 2007
Author: sabre
Date: Wed Jul 11 11:41:18 2007
New Revision: 39214
URL: http://llvm.org/viewvc/llvm-project?rev=39214&view=rev
Log:
Add support for C++ operator keywords. Patch by Bill Wendling.
Added:
cfe/cfe/trunk/test/Preprocessor/cxx_and.cpp (with props)
cfe/cfe/trunk/test/Preprocessor/cxx_bitand.cpp (with props)
cfe/cfe/trunk/test/Preprocessor/cxx_bitor.cpp (with props)
cfe/cfe/trunk/test/Preprocessor/cxx_compl.cpp (with props)
cfe/cfe/trunk/test/Preprocessor/cxx_not.cpp (with props)
cfe/cfe/trunk/test/Preprocessor/cxx_not_eq.cpp (with props)
cfe/cfe/trunk/test/Preprocessor/cxx_or.cpp (with props)
cfe/cfe/trunk/test/Preprocessor/cxx_xor.cpp (with props)
Modified:
cfe/cfe/trunk/Lex/IdentifierTable.cpp
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h
Modified: cfe/cfe/trunk/Lex/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/IdentifierTable.cpp?rev=39214&r1=39213&r2=39214&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/IdentifierTable.cpp (original)
+++ cfe/cfe/trunk/Lex/IdentifierTable.cpp Wed Jul 11 11:41:18 2007
@@ -31,6 +31,7 @@
IsExtension = false;
IsPoisoned = false;
IsOtherTargetMacro = false;
+ IsCPPOperatorKeyword = false;
FETokenInfo = 0;
}
@@ -85,6 +86,16 @@
Table.get(Name, Name+NameLen).setPPKeywordID(PPID);
}
+/// AddCXXOperatorKeyword - Register a C++ operator keyword alternative
+/// representations.
+static void AddCXXOperatorKeyword(const char *Keyword, unsigned KWLen,
+ tok::TokenKind TokenCode,
+ IdentifierTable &Table) {
+ IdentifierInfo &Info = Table.get(Keyword, Keyword + KWLen);
+ Info.setTokenID(TokenCode);
+ Info.setIsCPlusplusOperatorKeyword();
+}
+
/// AddObjCKeyword - Register an Objective-C @keyword like "class" "selector" or
/// "property".
static void AddObjCKeyword(tok::ObjCKeywordKind ObjCID,
@@ -119,6 +130,9 @@
AddKeyword(NAME, strlen(NAME), tok::kw_ ## TOK, 0, 0, 0, LangOpts, *this);
#define PPKEYWORD(NAME) \
AddPPKeyword(tok::pp_##NAME, #NAME, strlen(#NAME), *this);
+#define CXX_KEYWORD_OPERATOR(NAME, ALIAS) \
+ if (LangOpts.CPlusPlus) \
+ AddCXXOperatorKeyword(#NAME, strlen(#NAME), tok::ALIAS, *this);
#define OBJC1_AT_KEYWORD(NAME) \
if (LangOpts.ObjC1) \
AddObjCKeyword(tok::objc_##NAME, #NAME, strlen(#NAME), *this);
@@ -173,5 +187,3 @@
// Compute statistics about the memory allocated for identifiers.
HashTable.getAllocator().PrintStats();
}
-
-
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=39214&r1=39213&r2=39214&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:41:18 2007
@@ -967,6 +967,12 @@
}
+ // C++ 2.11p2: If this is an alternative representation of a C++ operator,
+ // then we act as if it is the actual operator and not the textual
+ // representation of it.
+ if (II.isCPlusPlusOperatorKeyword())
+ Identifier.setIdentifierInfo(0);
+
// Change the kind of this identifier to the appropriate token kind, e.g.
// turning "for" into a keyword.
Identifier.setKind(II.getTokenID());
Modified: cfe/cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=39214&r1=39213&r2=39214&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/TokenKinds.def Wed Jul 11 11:41:18 2007
@@ -26,6 +26,9 @@
#ifndef PPKEYWORD
#define PPKEYWORD(X)
#endif
+#ifndef CXX_KEYWORD_OPERATOR
+#define CXX_KEYWORD_OPERATOR(X,Y)
+#endif
#ifndef OBJC1_AT_KEYWORD
#define OBJC1_AT_KEYWORD(X)
#endif
@@ -222,7 +225,7 @@
KEYWORD(__FUNCTION__ , EXTC90|EXTC99|EXTCPP) // GCC Extension.
KEYWORD(__PRETTY_FUNCTION__ , EXTC90|EXTC99|EXTCPP) // GCC Extension.
-// C++
+// C++ 2.11p1: Keywords.
KEYWORD(asm , EXTC90|EXTC99) // Exts in C90/C99
KEYWORD(catch , NOTC90|NOTC99)
KEYWORD(class , NOTC90|NOTC99)
@@ -253,6 +256,19 @@
KEYWORD(virtual , NOTC90|NOTC99)
KEYWORD(wchar_t , NOTC90|NOTC99)
+// C++ 2.5p2: Alternative Representations.
+CXX_KEYWORD_OPERATOR(and , ampamp)
+CXX_KEYWORD_OPERATOR(and_eq , ampequal)
+CXX_KEYWORD_OPERATOR(bitand , amp)
+CXX_KEYWORD_OPERATOR(bitor , pipe)
+CXX_KEYWORD_OPERATOR(compl , tilde)
+CXX_KEYWORD_OPERATOR(not , exclaim)
+CXX_KEYWORD_OPERATOR(not_eq , exclaimequal)
+CXX_KEYWORD_OPERATOR(or , pipepipe)
+CXX_KEYWORD_OPERATOR(or_eq , pipeequal)
+CXX_KEYWORD_OPERATOR(xor , caret)
+CXX_KEYWORD_OPERATOR(xor_eq , caretequal)
+
// GNU Extensions.
KEYWORD(_Decimal32 , EXTC90|EXTC99|EXTCPP)
KEYWORD(_Decimal64 , EXTC90|EXTC99|EXTCPP)
@@ -329,6 +345,7 @@
#undef OBJC2_AT_KEYWORD
#undef OBJC1_AT_KEYWORD
+#undef CXX_KEYWORD_OPERATOR
#undef PPKEYWORD
#undef ALIAS
#undef KEYWORD
Modified: cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h?rev=39214&r1=39213&r2=39214&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h Wed Jul 11 11:41:18 2007
@@ -36,6 +36,7 @@
bool IsExtension : 1; // True if identifier is a lang extension.
bool IsPoisoned : 1; // True if identifier is poisoned.
bool IsOtherTargetMacro : 1; // True if ident is macro on another target.
+ bool IsCPPOperatorKeyword : 1; // True if ident is a C++ operator keyword.
void *FETokenInfo; // Managed by the language front-end.
IdentifierInfo(const IdentifierInfo&); // NONCOPYABLE.
public:
@@ -90,7 +91,13 @@
/// is seen as being a macro on some other target.
void setIsOtherTargetMacro(bool Val = true) { IsOtherTargetMacro = Val; }
bool isOtherTargetMacro() const { return IsOtherTargetMacro; }
-
+
+ /// isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether
+ /// this identifier is a C++ alternate representation of an operator.
+ void setIsCPlusplusOperatorKeyword(bool Val = true)
+ { IsCPPOperatorKeyword = Val; }
+ bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
+
/// getFETokenInfo/setFETokenInfo - The language front-end is allowed to
/// associate arbitrary metadata with this token.
template<typename T>
Added: cfe/cfe/trunk/test/Preprocessor/cxx_and.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Preprocessor/cxx_and.cpp?rev=39214&view=auto
==============================================================================
--- cfe/cfe/trunk/test/Preprocessor/cxx_and.cpp (added)
+++ cfe/cfe/trunk/test/Preprocessor/cxx_and.cpp Wed Jul 11 11:41:18 2007
@@ -0,0 +1,17 @@
+// RUN: clang -DA -DB -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -DB -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if defined(A) and defined(B)
+#define X 37
+#else
+#define X 927
+#endif
+
+#if defined(A) && defined(B)
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_and.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_and.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: cfe/cfe/trunk/test/Preprocessor/cxx_bitand.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Preprocessor/cxx_bitand.cpp?rev=39214&view=auto
==============================================================================
--- cfe/cfe/trunk/test/Preprocessor/cxx_bitand.cpp (added)
+++ cfe/cfe/trunk/test/Preprocessor/cxx_bitand.cpp Wed Jul 11 11:41:18 2007
@@ -0,0 +1,16 @@
+// RUN: clang -DA=1 -DB=2 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -DA=1 -DB=1 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if A bitand B
+#define X 37
+#else
+#define X 927
+#endif
+
+#if A & B
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_bitand.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_bitand.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: cfe/cfe/trunk/test/Preprocessor/cxx_bitor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Preprocessor/cxx_bitor.cpp?rev=39214&view=auto
==============================================================================
--- cfe/cfe/trunk/test/Preprocessor/cxx_bitor.cpp (added)
+++ cfe/cfe/trunk/test/Preprocessor/cxx_bitor.cpp Wed Jul 11 11:41:18 2007
@@ -0,0 +1,18 @@
+// RUN: clang -DA=1 -DB=1 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA=0 -DB=1 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA=1 -DB=0 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA=0 -DB=0 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if A bitor B
+#define X 37
+#else
+#define X 927
+#endif
+
+#if A | B
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_bitor.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_bitor.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: cfe/cfe/trunk/test/Preprocessor/cxx_compl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Preprocessor/cxx_compl.cpp?rev=39214&view=auto
==============================================================================
--- cfe/cfe/trunk/test/Preprocessor/cxx_compl.cpp (added)
+++ cfe/cfe/trunk/test/Preprocessor/cxx_compl.cpp Wed Jul 11 11:41:18 2007
@@ -0,0 +1,16 @@
+// RUN: clang -DA=1 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA=0 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if compl 0 bitand A
+#define X 37
+#else
+#define X 927
+#endif
+
+#if ~0 & A
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_compl.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_compl.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: cfe/cfe/trunk/test/Preprocessor/cxx_not.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Preprocessor/cxx_not.cpp?rev=39214&view=auto
==============================================================================
--- cfe/cfe/trunk/test/Preprocessor/cxx_not.cpp (added)
+++ cfe/cfe/trunk/test/Preprocessor/cxx_not.cpp Wed Jul 11 11:41:18 2007
@@ -0,0 +1,15 @@
+// RUN: clang -DA=1 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 37 == 37'
+#if not defined(A)
+#define X 37
+#else
+#define X 927
+#endif
+
+#if ! defined(A)
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_not.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_not.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: cfe/cfe/trunk/test/Preprocessor/cxx_not_eq.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Preprocessor/cxx_not_eq.cpp?rev=39214&view=auto
==============================================================================
--- cfe/cfe/trunk/test/Preprocessor/cxx_not_eq.cpp (added)
+++ cfe/cfe/trunk/test/Preprocessor/cxx_not_eq.cpp Wed Jul 11 11:41:18 2007
@@ -0,0 +1,16 @@
+// RUN: clang -DA=1 -DB=1 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -DA=1 -DB=2 -E %s | grep 'int a = 37 == 37'
+#if A not_eq B
+#define X 37
+#else
+#define X 927
+#endif
+
+#if A != B
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_not_eq.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_not_eq.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: cfe/cfe/trunk/test/Preprocessor/cxx_or.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Preprocessor/cxx_or.cpp?rev=39214&view=auto
==============================================================================
--- cfe/cfe/trunk/test/Preprocessor/cxx_or.cpp (added)
+++ cfe/cfe/trunk/test/Preprocessor/cxx_or.cpp Wed Jul 11 11:41:18 2007
@@ -0,0 +1,17 @@
+// RUN: clang -DA -DB -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DB -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if defined(A) or defined(B)
+#define X 37
+#else
+#define X 927
+#endif
+
+#if defined(A) || defined(B)
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_or.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_or.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: cfe/cfe/trunk/test/Preprocessor/cxx_xor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Preprocessor/cxx_xor.cpp?rev=39214&view=auto
==============================================================================
--- cfe/cfe/trunk/test/Preprocessor/cxx_xor.cpp (added)
+++ cfe/cfe/trunk/test/Preprocessor/cxx_xor.cpp Wed Jul 11 11:41:18 2007
@@ -0,0 +1,18 @@
+// RUN: clang -DA=1 -DB=1 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -DA=0 -DB=1 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA=1 -DB=0 -E %s | grep 'int a = 37 == 37' &&
+// RUN: clang -DA=0 -DB=0 -E %s | grep 'int a = 927 == 927' &&
+// RUN: clang -E %s | grep 'int a = 927 == 927'
+#if A xor B
+#define X 37
+#else
+#define X 927
+#endif
+
+#if A ^ B
+#define Y 37
+#else
+#define Y 927
+#endif
+
+int a = X == Y;
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_xor.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/test/Preprocessor/cxx_xor.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
More information about the cfe-commits
mailing list