r231603 - Make Token a real POD type.
Benjamin Kramer
benny.kra at googlemail.com
Sun Mar 8 11:12:00 PDT 2015
Author: d0k
Date: Sun Mar 8 13:11:59 2015
New Revision: 231603
URL: http://llvm.org/viewvc/llvm-project?rev=231603&view=rev
Log:
Make Token a real POD type.
We copy them around a lot and skip construction in favor of startToken,
make the default construction trivial to reflect that.
Modified:
cfe/trunk/include/clang/Lex/Token.h
cfe/trunk/lib/Parse/ParseExprCXX.cpp
Modified: cfe/trunk/include/clang/Lex/Token.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Token.h?rev=231603&r1=231602&r2=231603&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Token.h (original)
+++ cfe/trunk/include/clang/Lex/Token.h Sun Mar 8 13:11:59 2015
@@ -35,8 +35,8 @@ class IdentifierInfo;
/// can be represented by a single typename annotation token that carries
/// information about the SourceRange of the tokens and the type object.
class Token {
- /// The location of the token.
- SourceLocation Loc;
+ /// The location of the token. This is actually a SourceLocation.
+ unsigned Loc;
// Conceptually these next two fields could be in a union. However, this
// causes gcc 4.2 to pessimize LexTokenInternal, a very performance critical
@@ -114,13 +114,15 @@ public:
/// \brief Return a source location identifier for the specified
/// offset in the current file.
- SourceLocation getLocation() const { return Loc; }
+ SourceLocation getLocation() const {
+ return SourceLocation::getFromRawEncoding(Loc);
+ }
unsigned getLength() const {
assert(!isAnnotation() && "Annotation tokens have no length field");
return UintData;
}
- void setLocation(SourceLocation L) { Loc = L; }
+ void setLocation(SourceLocation L) { Loc = L.getRawEncoding(); }
void setLength(unsigned Len) {
assert(!isAnnotation() && "Annotation tokens have no length field");
UintData = Len;
@@ -157,7 +159,7 @@ public:
Flags = 0;
PtrData = nullptr;
UintData = 0;
- Loc = SourceLocation();
+ Loc = SourceLocation().getRawEncoding();
}
IdentifierInfo *getIdentifierInfo() const {
@@ -285,6 +287,8 @@ public:
}
};
+static_assert(std::is_pod<Token>::value, "Token should be a POD type!");
+
/// \brief Information about the conditional stack (\#if directives)
/// currently active.
struct PPConditionalInfo {
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=231603&r1=231602&r2=231603&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Sun Mar 8 13:11:59 2015
@@ -118,6 +118,7 @@ void Parser::CheckForLParenAfterColonCol
// Eat the '('.
ConsumeParen();
Token RParen;
+ RParen.setLocation(SourceLocation());
// Do we have a ')' ?
NextTok = StarTok.is(tok::star) ? GetLookAheadToken(2) : GetLookAheadToken(1);
if (NextTok.is(tok::r_paren)) {
More information about the cfe-commits
mailing list