Factor out parsing and allocation of IdentifierLoc objects.

llvm-svn: 189833
This commit is contained in:
Richard Smith 2013-09-03 18:01:40 +00:00
parent b225be2729
commit feefaf5724
4 changed files with 24 additions and 13 deletions

View File

@ -1891,6 +1891,7 @@ private:
IdentifierInfo *ScopeName, IdentifierInfo *ScopeName,
SourceLocation ScopeLoc, SourceLocation ScopeLoc,
AttributeList::Syntax Syntax); AttributeList::Syntax Syntax);
IdentifierLoc *ParseIdentifierLoc();
void MaybeParseCXX11Attributes(Declarator &D) { void MaybeParseCXX11Attributes(Declarator &D) {
if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {

View File

@ -46,10 +46,12 @@ struct AvailabilityChange {
}; };
/// \brief Wraps an identifier and optional source location for the identifier. /// \brief Wraps an identifier and optional source location for the identifier.
/// It is expected that these will be created from the ASTContext memory pool.
struct IdentifierLoc { struct IdentifierLoc {
SourceLocation Loc; SourceLocation Loc;
IdentifierInfo *Ident; IdentifierInfo *Ident;
static IdentifierLoc *create(ASTContext &Ctx, SourceLocation Loc,
IdentifierInfo *Ident);
}; };
/// \brief A union of the various pointer types that can be passed to an /// \brief A union of the various pointer types that can be passed to an

View File

@ -13,7 +13,6 @@
#include "clang/Parse/Parser.h" #include "clang/Parse/Parser.h"
#include "RAIIObjectsForParser.h" #include "RAIIObjectsForParser.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclTemplate.h" #include "clang/AST/DeclTemplate.h"
#include "clang/Basic/AddressSpaces.h" #include "clang/Basic/AddressSpaces.h"
#include "clang/Basic/CharInfo.h" #include "clang/Basic/CharInfo.h"
@ -187,6 +186,15 @@ static bool attributeHasExprArgs(const IdentifierInfo &II) {
.Default(false); .Default(false);
} }
IdentifierLoc *Parser::ParseIdentifierLoc() {
assert(Tok.is(tok::identifier) && "expected an identifier");
IdentifierLoc *IL = IdentifierLoc::create(Actions.Context,
Tok.getLocation(),
Tok.getIdentifierInfo());
ConsumeToken();
return IL;
}
/// Parse the arguments to a parameterized GNU attribute or /// Parse the arguments to a parameterized GNU attribute or
/// a C++11 attribute in "gnu" namespace. /// a C++11 attribute in "gnu" namespace.
void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName, void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
@ -259,10 +267,7 @@ void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
if (attributeHasExprArgs(*AttrName)) if (attributeHasExprArgs(*AttrName))
break; break;
IdentifierLoc *Param = ::new (Actions.Context) IdentifierLoc; ArgExprs.push_back(ParseIdentifierLoc());
Param->Ident = Tok.getIdentifierInfo();
Param->Loc = ConsumeToken();
ArgExprs.push_back(Param);
} break; } break;
default: default:
@ -828,10 +833,7 @@ void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability,
SkipUntil(tok::r_paren); SkipUntil(tok::r_paren);
return; return;
} }
IdentifierLoc *Platform = ParseIdentifierLoc();
IdentifierLoc *Platform = new (Actions.Context) IdentifierLoc;
Platform->Ident = Tok.getIdentifierInfo();
Platform->Loc = ConsumeToken();
// Parse the ',' following the platform name. // Parse the ',' following the platform name.
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::r_paren)) if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::r_paren))
@ -1202,9 +1204,7 @@ void Parser::ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName,
T.skipToEnd(); T.skipToEnd();
return; return;
} }
IdentifierLoc *ArgumentKind = new (Actions.Context) IdentifierLoc; IdentifierLoc *ArgumentKind = ParseIdentifierLoc();
ArgumentKind->Ident = Tok.getIdentifierInfo();
ArgumentKind->Loc = ConsumeToken();
if (Tok.isNot(tok::comma)) { if (Tok.isNot(tok::comma)) {
Diag(Tok, diag::err_expected_comma); Diag(Tok, diag::err_expected_comma);

View File

@ -19,6 +19,14 @@
#include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/StringSwitch.h"
using namespace clang; using namespace clang;
IdentifierLoc *IdentifierLoc::create(ASTContext &Ctx, SourceLocation Loc,
IdentifierInfo *Ident) {
IdentifierLoc *Result = new (Ctx) IdentifierLoc;
Result->Loc = Loc;
Result->Ident = Ident;
return Result;
}
size_t AttributeList::allocated_size() const { size_t AttributeList::allocated_size() const {
if (IsAvailability) return AttributeFactory::AvailabilityAllocSize; if (IsAvailability) return AttributeFactory::AvailabilityAllocSize;
else if (IsTypeTagForDatatype) else if (IsTypeTagForDatatype)