[cfe-commits] r68871 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp
Chris Lattner
sabre at nondot.org
Sat Apr 11 11:57:04 PDT 2009
Author: lattner
Date: Sat Apr 11 13:57:04 2009
New Revision: 68871
URL: http://llvm.org/viewvc/llvm-project?rev=68871&view=rev
Log:
change the interface to ActOnMethodDeclaration to pass down argument
information in a little struct instead of individually. While we're
at it, add per-argument loc info and attribute info.
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=68871&r1=68870&r2=68871&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Sat Apr 11 13:57:04 2009
@@ -1405,6 +1405,18 @@
IdentifierInfo *propertyIvar) { // name of the ivar
return DeclPtrTy();
}
+
+ struct ObjCArgInfo {
+ IdentifierInfo *Name;
+ SourceLocation NameLoc;
+ // The Type is null if no type was specified, and the DeclSpec is invalid
+ // in this case.
+ TypeTy *Type;
+ ObjCDeclSpec DeclSpec;
+
+ /// ArgAttrs - Attribute list for this argument.
+ AttributeList *ArgAttrs;
+ };
// ActOnMethodDeclaration - called for all method declarations.
virtual DeclPtrTy ActOnMethodDeclaration(
@@ -1415,11 +1427,9 @@
ObjCDeclSpec &ReturnQT, // for return type's in inout etc.
TypeTy *ReturnType, // the method return type.
Selector Sel, // a unique name for the method.
- ObjCDeclSpec *ArgQT, // for arguments' in inout etc.
- TypeTy **ArgTypes, // non-zero when Sel.getNumArgs() > 0
- IdentifierInfo **ArgNames, // non-zero when Sel.getNumArgs() > 0
+ ObjCArgInfo *ArgInfo, // ArgInfo: Has 'Sel.getNumArgs()' entries.
llvm::SmallVectorImpl<Declarator> &Cdecls, // c-style args
- AttributeList *AttrList, // optional
+ AttributeList *MethodAttrList, // optional
// tok::objc_not_keyword, tok::objc_optional, tok::objc_required
tok::ObjCKeywordKind impKind,
bool isVariadic = false) {
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=68871&r1=68870&r2=68871&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Sat Apr 11 13:57:04 2009
@@ -699,18 +699,15 @@
Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
mType, IDecl, DSRet, ReturnType, Sel,
- 0, 0, 0, CargNames,
+ 0, CargNames,
MethodAttrs, MethodImplKind);
}
llvm::SmallVector<IdentifierInfo *, 12> KeyIdents;
- llvm::SmallVector<Action::TypeTy *, 12> KeyTypes;
- llvm::SmallVector<ObjCDeclSpec, 12> ArgTypeQuals;
- llvm::SmallVector<IdentifierInfo *, 12> ArgNames;
+ llvm::SmallVector<Action::ObjCArgInfo, 12> ArgInfos;
- Action::TypeTy *TypeInfo;
while (1) {
- KeyIdents.push_back(SelIdent);
+ Action::ObjCArgInfo ArgInfo;
// Each iteration parses a single keyword argument.
if (Tok.isNot(tok::colon)) {
@@ -718,25 +715,28 @@
break;
}
ConsumeToken(); // Eat the ':'.
- ObjCDeclSpec DSType;
- if (Tok.is(tok::l_paren)) // Parse the argument type.
- TypeInfo = ParseObjCTypeName(DSType);
- else
- TypeInfo = 0;
- KeyTypes.push_back(TypeInfo);
- ArgTypeQuals.push_back(DSType);
+ ArgInfo.Type = 0;
+ if (Tok.is(tok::l_paren)) // Parse the argument type if present.
+ ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec);
+
// If attributes exist before the argument name, parse them.
+ ArgInfo.ArgAttrs = 0;
if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
- ParseAttributes(); // FIXME: pass attributes through.
+ ArgInfo.ArgAttrs = ParseAttributes();
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident); // missing argument name.
break;
}
- ArgNames.push_back(Tok.getIdentifierInfo());
+
+ ArgInfo.Name = Tok.getIdentifierInfo();
+ ArgInfo.NameLoc = Tok.getLocation();
ConsumeToken(); // Eat the identifier.
+ ArgInfos.push_back(ArgInfo);
+ KeyIdents.push_back(SelIdent);
+
// Check for another keyword selector.
SourceLocation Loc;
SelIdent = ParseObjCSelectorPiece(Loc);
@@ -773,8 +773,7 @@
&KeyIdents[0]);
return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
mType, IDecl, DSRet, ReturnType, Sel,
- &ArgTypeQuals[0], &KeyTypes[0],
- &ArgNames[0], CargNames,
+ &ArgInfos[0], CargNames,
MethodAttrs,
MethodImplKind, isVariadic);
}
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=68871&r1=68870&r2=68871&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sat Apr 11 13:57:04 2009
@@ -2125,7 +2125,7 @@
Selector Sel,
// optional arguments. The number of types/arguments is obtained
// from the Sel.getNumArgs().
- ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
+ ObjCArgInfo *ArgInfo,
llvm::SmallVectorImpl<Declarator> &Cdecls,
AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
bool isVariadic = false);
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=68871&r1=68870&r2=68871&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sat Apr 11 13:57:04 2009
@@ -1394,12 +1394,14 @@
Selector Sel,
// optional arguments. The number of types/arguments is obtained
// from the Sel.getNumArgs().
- ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
+ ObjCArgInfo *ArgInfo,
llvm::SmallVectorImpl<Declarator> &Cdecls,
AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind,
bool isVariadic) {
Decl *ClassDecl = classDecl.getAs<Decl>();
+ // FIXME: Param attributes.
+
// Make sure we can establish a context for the method.
if (!ClassDecl) {
Diag(MethodLoc, diag::error_missing_method_context);
@@ -1435,38 +1437,40 @@
// FIXME: arg->AttrList must be stored too!
QualType argType, originalArgType;
- if (ArgTypes[i]) {
- argType = QualType::getFromOpaquePtr(ArgTypes[i]);
+ if (ArgInfo[i].Type == 0) {
+ argType = Context.getObjCIdType();
+ } else {
+ argType = QualType::getFromOpaquePtr(ArgInfo[i].Type);
// Perform the default array/function conversions (C99 6.7.5.3p[7,8]).
if (argType->isArrayType()) { // (char *[]) -> (char **)
originalArgType = argType;
argType = Context.getArrayDecayedType(argType);
- }
- else if (argType->isFunctionType())
+ } else if (argType->isFunctionType())
argType = Context.getPointerType(argType);
else if (argType->isObjCInterfaceType()) {
- // FIXME! provide more precise location for the parameter
+ // FIXME: improve message to include type!
Diag(MethodLoc, diag::err_object_cannot_be_by_value)
<< "passed";
ObjCMethod->setInvalidDecl();
return DeclPtrTy();
}
- } else
- argType = Context.getObjCIdType();
+ }
+
ParmVarDecl* Param;
if (originalArgType.isNull())
Param = ParmVarDecl::Create(Context, ObjCMethod,
SourceLocation(/*FIXME*/),
- ArgNames[i], argType,
+ ArgInfo[i].Name, argType,
VarDecl::None, 0);
else
Param = OriginalParmVarDecl::Create(Context, ObjCMethod,
SourceLocation(/*FIXME*/),
- ArgNames[i], argType, originalArgType,
+ ArgInfo[i].Name, argType,
+ originalArgType,
VarDecl::None, 0);
Param->setObjCDeclQualifier(
- CvtQTToAstBitMask(ArgQT[i].getObjCDeclQualifier()));
+ CvtQTToAstBitMask(ArgInfo[i].DeclSpec.getObjCDeclQualifier()));
Params.push_back(Param);
}
More information about the cfe-commits
mailing list