r189833 - Factor out parsing and allocation of IdentifierLoc objects.

Richard Smith richard-llvm at metafoo.co.uk
Tue Sep 3 11:01:41 PDT 2013


Author: rsmith
Date: Tue Sep  3 13:01:40 2013
New Revision: 189833

URL: http://llvm.org/viewvc/llvm-project?rev=189833&view=rev
Log:
Factor out parsing and allocation of IdentifierLoc objects.

Modified:
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/include/clang/Sema/AttributeList.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Sema/AttributeList.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=189833&r1=189832&r2=189833&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Sep  3 13:01:40 2013
@@ -1891,6 +1891,7 @@ private:
                              IdentifierInfo *ScopeName,
                              SourceLocation ScopeLoc,
                              AttributeList::Syntax Syntax);
+  IdentifierLoc *ParseIdentifierLoc();
 
   void MaybeParseCXX11Attributes(Declarator &D) {
     if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {

Modified: cfe/trunk/include/clang/Sema/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=189833&r1=189832&r2=189833&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/AttributeList.h (original)
+++ cfe/trunk/include/clang/Sema/AttributeList.h Tue Sep  3 13:01:40 2013
@@ -46,10 +46,12 @@ struct AvailabilityChange {
 };
 
 /// \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 {
   SourceLocation Loc;
   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

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=189833&r1=189832&r2=189833&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Sep  3 13:01:40 2013
@@ -13,7 +13,6 @@
 
 #include "clang/Parse/Parser.h"
 #include "RAIIObjectsForParser.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/AddressSpaces.h"
 #include "clang/Basic/CharInfo.h"
@@ -187,6 +186,15 @@ static bool attributeHasExprArgs(const I
            .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
 /// a C++11 attribute in "gnu" namespace.
 void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName,
@@ -259,10 +267,7 @@ void Parser::ParseGNUAttributeArgs(Ident
     if (attributeHasExprArgs(*AttrName))
       break;
 
-    IdentifierLoc *Param = ::new (Actions.Context) IdentifierLoc;
-    Param->Ident = Tok.getIdentifierInfo();
-    Param->Loc = ConsumeToken();
-    ArgExprs.push_back(Param);
+    ArgExprs.push_back(ParseIdentifierLoc());
   } break;
 
   default:
@@ -828,10 +833,7 @@ void Parser::ParseAvailabilityAttribute(
     SkipUntil(tok::r_paren);
     return;
   }
-
-  IdentifierLoc *Platform = new (Actions.Context) IdentifierLoc;
-  Platform->Ident = Tok.getIdentifierInfo();
-  Platform->Loc = ConsumeToken();
+  IdentifierLoc *Platform = ParseIdentifierLoc();
 
   // Parse the ',' following the platform name.
   if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::r_paren))
@@ -1202,9 +1204,7 @@ void Parser::ParseTypeTagForDatatypeAttr
     T.skipToEnd();
     return;
   }
-  IdentifierLoc *ArgumentKind = new (Actions.Context) IdentifierLoc;
-  ArgumentKind->Ident = Tok.getIdentifierInfo();
-  ArgumentKind->Loc = ConsumeToken();
+  IdentifierLoc *ArgumentKind = ParseIdentifierLoc();
 
   if (Tok.isNot(tok::comma)) {
     Diag(Tok, diag::err_expected_comma);

Modified: cfe/trunk/lib/Sema/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AttributeList.cpp?rev=189833&r1=189832&r2=189833&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AttributeList.cpp (original)
+++ cfe/trunk/lib/Sema/AttributeList.cpp Tue Sep  3 13:01:40 2013
@@ -19,6 +19,14 @@
 #include "llvm/ADT/StringSwitch.h"
 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 {
   if (IsAvailability) return AttributeFactory::AvailabilityAllocSize;
   else if (IsTypeTagForDatatype)





More information about the cfe-commits mailing list