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
This commit is contained in:
Fariborz Jahanian 2007-10-31 21:59:43 +00:00
Родитель 9544ff2d96
Коммит 19d74e1494
6 изменённых файлов: 84 добавлений и 17 удалений

Просмотреть файл

@ -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,

Просмотреть файл

@ -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();

Просмотреть файл

@ -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");

Просмотреть файл

@ -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 = "";

Просмотреть файл

@ -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.
///

Просмотреть файл

@ -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);