diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2007-10-31 21:59:43 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2007-10-31 21:59:43 +0000 |
commit | 19d74e1494fe399f0e2a94e9419c095f8214851b (patch) | |
tree | 071e9d42118902ae072cfc4b2e26f97577a7275c | |
parent | 9544ff2d96a5630b4219bbda41bb7476f01d9bf1 (diff) |
More infrastructure to recognize objective-c's type qualifiers (in,inout, etc.)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43580 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Parse/ParseDecl.cpp | 52 | ||||
-rw-r--r-- | Parse/ParseObjc.cpp | 17 | ||||
-rw-r--r-- | Parse/Parser.cpp | 2 | ||||
-rw-r--r-- | clang.xcodeproj/project.pbxproj | 1 | ||||
-rw-r--r-- | include/clang/Parse/DeclSpec.h | 25 | ||||
-rw-r--r-- | include/clang/Parse/Parser.h | 4 |
6 files changed, 84 insertions, 17 deletions
diff --git a/Parse/ParseDecl.cpp b/Parse/ParseDecl.cpp index aeecdb7872..0437c202f3 100644 --- a/Parse/ParseDecl.cpp +++ b/Parse/ParseDecl.cpp @@ -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, diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index ea48704c01..579c48cf45 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -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(); diff --git a/Parse/Parser.cpp b/Parse/Parser.cpp index 543aed8855..8040eb8ebc 100644 --- a/Parse/Parser.cpp +++ b/Parse/Parser.cpp @@ -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"); diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index de41b4628d..fe4cf8d85b 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -756,6 +756,7 @@ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */; + compatibilityVersion = "Xcode 2.4"; hasScannedForEncodings = 1; mainGroup = 08FB7794FE84155DC02AAC07 /* clang */; projectDirPath = ""; diff --git a/include/clang/Parse/DeclSpec.h b/include/clang/Parse/DeclSpec.h index 79a67741bd..6c636e7ca8 100644 --- a/include/clang/Parse/DeclSpec.h +++ b/include/clang/Parse/DeclSpec.h @@ -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. /// diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 3c4767be5b..0a5295cedb 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -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); |