#include "clang/Basic/LangOptions.h"
using namespace clang;
+//===----------------------------------------------------------------------===//
+// Token Implementation
+//===----------------------------------------------------------------------===//
+
+/// isObjCAtKeyword - Return true if we have an ObjC keyword identifier.
+bool Token::isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const {
+ return getKind() == tok::identifier &&
+ getIdentifierInfo()->getObjCKeywordID() == objcKey;
+}
+
+/// getObjCKeywordID - Return the ObjC keyword kind.
+tok::ObjCKeywordKind Token::getObjCKeywordID() const {
+ IdentifierInfo *specId = getIdentifierInfo();
+ return specId ? specId->getObjCKeywordID() : tok::objc_not_keyword;
+}
+
//===----------------------------------------------------------------------===//
// IdentifierInfo Implementation
//===----------------------------------------------------------------------===//
Parser::DeclTy *Parser::ParseObjCAtDirectives() {
SourceLocation AtLoc = ConsumeToken(); // the "@"
- IdentifierInfo *II = Tok.getIdentifierInfo();
- switch (II ? II->getObjCKeywordID() : tok::objc_not_keyword) {
+ switch (Tok.getObjCKeywordID()) {
case tok::objc_class:
return ParseObjCAtClassDeclaration(AtLoc);
case tok::objc_interface:
///
Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
SourceLocation atLoc, AttributeList *attrList) {
- assert((Tok.getKind() == tok::identifier &&
- Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_interface) &&
+ assert(Tok.isObjCAtKeyword(tok::objc_interface) &&
"ParseObjCAtInterfaceDeclaration(): Expected @interface");
ConsumeToken(); // the "interface" identifier
ParseObjCInterfaceDeclList(0/*FIXME*/);
// The @ sign was already consumed by ParseObjCInterfaceDeclList().
- if (Tok.getKind() == tok::identifier &&
- Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_end) {
+ if (Tok.isObjCAtKeyword(tok::objc_end)) {
ConsumeToken(); // the "end" identifier
return 0;
}
ParseObjCInterfaceDeclList(0/*FIXME*/);
// The @ sign was already consumed by ParseObjCInterfaceDeclList().
- if (Tok.getKind() == tok::identifier &&
- Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_end) {
+ if (Tok.isObjCAtKeyword(tok::objc_end)) {
ConsumeToken(); // the "end" identifier
return 0;
}
while (1) {
if (Tok.getKind() == tok::at) {
SourceLocation AtLoc = ConsumeToken(); // the "@"
- tok::ObjCKeywordKind ocKind = Tok.getIdentifierInfo()->getObjCKeywordID();
+ tok::ObjCKeywordKind ocKind = Tok.getObjCKeywordID();
if (ocKind == tok::objc_end) { // terminate list
return;
tok::ObjCKeywordKind visibility = tok::objc_private;
if (Tok.getKind() == tok::at) { // parse objc-visibility-spec
ConsumeToken(); // eat the @ sign
- IdentifierInfo *specId = Tok.getIdentifierInfo();
- switch (specId->getObjCKeywordID()) {
+ switch (Tok.getObjCKeywordID()) {
case tok::objc_private:
case tok::objc_public:
case tok::objc_protected:
case tok::objc_package:
- visibility = specId->getObjCKeywordID();
+ visibility = Tok.getObjCKeywordID();
ConsumeToken();
continue;
default:
/// semicolon in the first alternative if objc-protocol-refs are omitted.
Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {
- assert((Tok.getKind() == tok::identifier &&
- Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_protocol) &&
+ assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
"ParseObjCAtProtocolDeclaration(): Expected @protocol");
ConsumeToken(); // the "protocol" identifier
ParseObjCInterfaceDeclList(0/*FIXME*/);
// The @ sign was already consumed by ParseObjCInterfaceDeclList().
- if (Tok.getKind() == tok::identifier &&
- Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_end) {
+ if (Tok.isObjCAtKeyword(tok::objc_end)) {
ConsumeToken(); // the "end" identifier
return 0;
}
/// objc-encode-expression:
/// @encode ( type-name )
Parser::ExprResult Parser::ParseObjCEncodeExpression() {
- assert(Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_encode &&
- "Not an @encode expression!");
+ assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!");
SourceLocation EncLoc = ConsumeToken();