]> granicus.if.org Git - clang/commitdiff
More infrastructure to recognize objective-c's type qualifiers (in,inout, etc.)
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 31 Oct 2007 21:59:43 +0000 (21:59 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 31 Oct 2007 21:59:43 +0000 (21:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43580 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseDecl.cpp
Parse/ParseObjc.cpp
Parse/Parser.cpp
clang.xcodeproj/project.pbxproj
include/clang/Parse/DeclSpec.h
include/clang/Parse/Parser.h

index aeecdb787226035121b8f3bbf65cd534c47a9aac..0437c202f32e731c78fa34fff094ebc38dd5268f 100644 (file)
@@ -552,6 +552,58 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
   }
 }
 
+/// ParseObjcTypeQualifierList - This routine parses the objective-c's type
+/// qualifier list and builds their bitmask representation in the input
+/// argument.
+void Parser::ParseObjcTypeQualifierList(ObjcDeclSpec &DS) {
+  bool found = true;
+  while (found) {
+    found = false;
+    if (Tok.is(tok::identifier)) {
+      const IdentifierInfo *II = Tok.getIdentifierInfo();
+      unsigned i;
+      for (i = 0; i < objc_NumQuals; ++i) {
+        if (II == ObjcTypeQuals[i]) {
+          switch (i) {
+            case objc_in:
+              DS.setObjcDeclQualifier(ObjcDeclSpec::DQ_In);
+              ConsumeToken();
+              found = true;
+              break;
+            case objc_out:
+              DS.setObjcDeclQualifier(ObjcDeclSpec::DQ_Out);
+              ConsumeToken();
+              found = true;
+              break;
+            case objc_inout:
+              DS.setObjcDeclQualifier(ObjcDeclSpec::DQ_Inout);
+              ConsumeToken();
+              found = true;
+              break;
+            case objc_oneway:
+              DS.setObjcDeclQualifier(ObjcDeclSpec::DQ_Oneway);
+              ConsumeToken();
+              found = true;
+              break;
+            case objc_bycopy:
+              DS.setObjcDeclQualifier(ObjcDeclSpec::DQ_Bycopy);
+              ConsumeToken();
+              found = true;
+              break;
+            case objc_byref:
+              DS.setObjcDeclQualifier(ObjcDeclSpec::DQ_Byref);
+              ConsumeToken();
+              found = true;
+              break;
+          }
+          if (found)
+            break;
+        }
+      }
+    }
+  }
+}
+
 /// ParseTag - Parse "struct-or-union-or-class-or-enum identifier[opt]", where
 /// the first token has already been read and has been turned into an instance
 /// of DeclSpec::TST (TagType).  This returns true if there is an error parsing,
index ea48704c01642e2459cc31c6701ab48c6d6af415..579c48cf452b68879f93a8cd7b7a1cdcb1d10c14 100644 (file)
@@ -451,18 +451,6 @@ IdentifierInfo *Parser::ParseObjCSelector(SourceLocation &SelectorLoc) {
   }
 }
 
-///   objc-type-qualifier: one of
-///     in out inout bycopy byref oneway
-///
-bool Parser::isObjCTypeQualifier() {
-  if (Tok.is(tok::identifier)) {
-    const IdentifierInfo *II = Tok.getIdentifierInfo();
-    for (unsigned i = 0; i < objc_NumQuals; ++i)
-      if (II == ObjcTypeQuals[i]) return true;
-  }
-  return false;
-}
-
 ///  property-attrlist: one of
 ///    readonly getter setter assign retain copy nonatomic
 ///
@@ -489,8 +477,9 @@ Parser::TypeTy *Parser::ParseObjCTypeName() {
   SourceLocation LParenLoc = ConsumeParen(), RParenLoc;
   TypeTy *Ty = 0;
   
-  while (isObjCTypeQualifier())
-    ConsumeToken();
+  // Parse type qualifiers, in, inout, etc.
+  ObjcDeclSpec DS;
+  ParseObjcTypeQualifierList(DS);
 
   if (isTypeSpecifierQualifier()) {
     Ty = ParseTypeName();
index 543aed8855d74caaeda90179cc9320304b66f367..8040eb8ebc4b0fdffa324e8bb41b6e4c726ddd04 100644 (file)
@@ -235,7 +235,7 @@ void Parser::Initialize() {
     Diag(Tok, diag::ext_empty_source_file);
   
   // Initialization for Objective-C context sensitive keywords recognition.
-  // Referenced in Parser::isObjCTypeQualifier.
+  // Referenced in Parser::ParseObjcTypeQualifierList.
   if (getLang().ObjC1) {
     ObjcTypeQuals[objc_in] = &PP.getIdentifierTable().get("in");
     ObjcTypeQuals[objc_out] = &PP.getIdentifierTable().get("out");
index de41b4628d0c47ae944965792f26798c623eb63f..fe4cf8d85be8296188b8454e3723b21a50eb5906 100644 (file)
                08FB7793FE84155DC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
+                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
                        projectDirPath = "";
index 79a67741bdff8795c91bf5f8f386450a71d1e1fa..6c636e7ca894b5b7ae2dbe4f2a356d328f4e6002 100644 (file)
@@ -277,7 +277,30 @@ private:
   }
 };
 
-
+/// ObjcDeclSpec - This class captures information about 
+/// "declaration specifiers" specific to objective-c
+class ObjcDeclSpec {
+public:
+  /// ObjcDeclQualifier - Qualifier used on types in method declarations
+  enum ObjcDeclQualifier {
+    DQ_None = 0x0,
+    DQ_In = 0x1,
+    DQ_Inout = 0x2,
+    DQ_Out = 0x4,
+    DQ_Bycopy = 0x8,
+    DQ_Byref = 0x10,
+    DQ_Oneway = 0x20
+  };
+  
+  ObjcDeclSpec() : objcDeclQualifier(DQ_None) {}
+  ObjcDeclQualifier getObjcDeclQualifier() const { return objcDeclQualifier; }
+  void setObjcDeclQualifier(ObjcDeclQualifier DQVal) 
+    { objcDeclQualifier = (ObjcDeclQualifier) (objcDeclQualifier | DQVal); }
+  
+private:
+  ObjcDeclQualifier objcDeclQualifier : 6;
+};
+  
 /// DeclaratorChunk - One instance of this struct is used for each type in a
 /// declarator that is parsed.
 ///
index 3c4767be5bf91c85afd8dbb4e63ce4a598752d9b..0a5295cedbcd469491a952693a42e85c1ce10143 100644 (file)
@@ -19,6 +19,7 @@
 
 namespace clang {
   class DeclSpec;
+  class ObjcDeclSpec;
   class Declarator;
   class AttributeList;
   class Scope;
@@ -284,7 +285,6 @@ private:
     objc_NumQuals
   };
   IdentifierInfo *ObjcTypeQuals[objc_NumQuals];
-  bool isObjCTypeQualifier();
   // Definitions for ObjC2's @property attributes.
   enum ObjCPropertyAttr {
     objc_readonly=0, objc_getter, objc_setter, objc_assign, 
@@ -399,6 +399,8 @@ private:
   DeclTy *ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D);
   void ParseDeclarationSpecifiers(DeclSpec &DS);
   void ParseSpecifierQualifierList(DeclSpec &DS);
+  
+  void ParseObjcTypeQualifierList(ObjcDeclSpec &DS);
 
   bool ParseTag(DeclTy *&Decl, unsigned TagType, SourceLocation StartLoc);
   void ParseEnumSpecifier(DeclSpec &DS);