[cfe-commits] r71067 - in /cfe/trunk: include/clang/Parse/DeclSpec.h lib/Parse/DeclSpec.cpp lib/Parse/ParseDecl.cpp test/Parser/cxx-friend.cpp
Anders Carlsson
andersca at mac.com
Tue May 5 21:46:28 PDT 2009
Author: andersca
Date: Tue May 5 23:46:28 2009
New Revision: 71067
URL: http://llvm.org/viewvc/llvm-project?rev=71067&view=rev
Log:
Add parsing of friend specifiers.
Added:
cfe/trunk/test/Parser/cxx-friend.cpp
Modified:
cfe/trunk/include/clang/Parse/DeclSpec.h
cfe/trunk/lib/Parse/DeclSpec.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=71067&r1=71066&r2=71067&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Tue May 5 23:46:28 2009
@@ -123,6 +123,9 @@
bool FS_virtual_specified : 1;
bool FS_explicit_specified : 1;
+ // friend-specifier
+ bool Friend_specified : 1;
+
/// TypeRep - This contains action-specific information about a specific TST.
/// For example, for a typedef or struct, it might contain the declaration for
/// these.
@@ -145,6 +148,7 @@
SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc;
SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc;
SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc;
+ SourceLocation FriendLoc;
bool BadSpecifier(TST T, const char *&PrevSpec);
bool BadSpecifier(TQ T, const char *&PrevSpec);
@@ -168,6 +172,7 @@
FS_inline_specified(false),
FS_virtual_specified(false),
FS_explicit_specified(false),
+ Friend_specified(false),
TypeRep(0),
AttrList(0),
ProtocolQualifiers(0),
@@ -277,6 +282,8 @@
bool SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec);
bool SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec);
+ bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec);
+
/// AddAttributes - contatenates two attribute lists.
/// The GCC attribute syntax allows for the following:
///
Modified: cfe/trunk/lib/Parse/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/DeclSpec.cpp?rev=71067&r1=71066&r2=71067&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Parse/DeclSpec.cpp Tue May 5 23:46:28 2009
@@ -294,6 +294,16 @@
return false;
}
+bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec) {
+ if (Friend_specified) {
+ PrevSpec = "friend";
+ return true;
+ }
+
+ Friend_specified = true;
+ FriendLoc = Loc;
+ return false;
+}
/// Finish - This does final analysis of the declspec, rejecting things like
/// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=71067&r1=71066&r2=71067&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue May 5 23:46:28 2009
@@ -597,6 +597,8 @@
/// [C99] 'inline'
/// [C++] 'virtual'
/// [C++] 'explicit'
+/// 'friend': [C++ dcl.friend]
+
///
void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
TemplateParameterLists *TemplateParams,
@@ -846,6 +848,11 @@
isInvalid = DS.SetFunctionSpecExplicit(Loc, PrevSpec);
break;
+ // friend
+ case tok::kw_friend:
+ isInvalid = DS.SetFriendSpec(Loc, PrevSpec);
+ break;
+
// type-specifier
case tok::kw_short:
isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec);
Added: cfe/trunk/test/Parser/cxx-friend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-friend.cpp?rev=71067&view=auto
==============================================================================
--- cfe/trunk/test/Parser/cxx-friend.cpp (added)
+++ cfe/trunk/test/Parser/cxx-friend.cpp Tue May 5 23:46:28 2009
@@ -0,0 +1,5 @@
+// RUN: clang-cc -fsyntax-only %s
+
+class C {
+ friend class D;
+};
More information about the cfe-commits
mailing list