}
}
+ObjcIvarDecl *ObjcInterfaceDecl::lookupInstanceVariable(
+ IdentifierInfo *ID, ObjcInterfaceDecl *&clsDeclared) {
+ ObjcInterfaceDecl* ClassDecl = this;
+ while (ClassDecl != NULL) {
+ ObjcIvarDecl **ivars = ClassDecl->getInstanceVariables();
+ int ivarCount = ClassDecl->getNumInstanceVariables();
+ for (int i = 0; i < ivarCount; ++i) {
+ if (ivars[i]->getIdentifier() == ID) {
+ clsDeclared = ClassDecl;
+ return ivars[i];
+ }
+ }
+ ClassDecl = ClassDecl->getSuperClass();
+ }
+ return NULL;
+}
+
// lookupInstanceMethod - This method returns an instance method by looking in
// the class, it's categories, and it's super classes (using a linear search).
ObjcMethodDecl *ObjcInterfaceDecl::lookupInstanceMethod(Selector &Sel) {
SynthesizeObjcInternalStruct(RCDecl, Result);
}
- int NumIvars = CDecl->getIntfDeclNumIvars();
+ int NumIvars = CDecl->getNumInstanceVariables();
// If no ivars and no root or if its root, directly or indirectly,
// have no ivars (thus not synthesized) then no need to synthesize this class.
if (NumIvars <= 0 && (!RCDecl || !ObjcSynthesizedStructs.count(RCDecl)))
// Build _objc_ivar_list metadata for classes ivars if needed
int NumIvars = IDecl->getImplDeclNumIvars() > 0
? IDecl->getImplDeclNumIvars()
- : (CDecl ? CDecl->getIntfDeclNumIvars() : 0);
+ : (CDecl ? CDecl->getNumInstanceVariables() : 0);
SynthesizeObjcInternalStruct(CDecl, Result);
ObjcIvarDecl **Ivars = IDecl->getImplDeclIVars()
? IDecl->getImplDeclIVars()
- : CDecl->getIntfDeclIvars();
+ : CDecl->getInstanceVariables();
Result += "\t,{{\"";
Result += Ivars[0]->getName();
Result += "\", \"";
assert(FD == CurFunctionDecl && "Function parsing confused");
} else if (ObjcMethodDecl *MD = dyn_cast<ObjcMethodDecl>(dcl)) {
MD->setBody((Stmt*)Body);
+ CurMethodDecl = 0;
}
+ // This is unconditional, since methods have a corresponding function decl.
CurFunctionDecl = 0;
// Verify and clean out per-function state.
/// ObjcActOnStartOfMethodDef - This routine sets up parameters; invisible
/// and user declared, in the method definition's AST.
void Sema::ObjcActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
- assert(CurFunctionDecl == 0 && "Function parsing confused");
+ assert(CurFunctionDecl == 0 && "Method parsing confused");
ObjcMethodDecl *MDecl = dyn_cast<ObjcMethodDecl>(static_cast<Decl *>(D));
-
assert(MDecl != 0 && "Not a method declarator!");
Scope *GlobalScope = FnBodyScope->getParent();
Name += MDecl->getSelector().getName();
Name += "]";
IdentifierInfo *II = &Context.Idents.get(Name);
- assert (II && "ObjcActOnMethodDefinition - selector name is missing");
+ assert (II && "ObjcActOnStartOfMethodDef - selector name is missing");
QualType R = ObjcGetTypeForMethodDefinition(MDecl, GlobalScope);
- assert(!R.isNull() && "ObjcGetTypeForMethodDefinition() returned null type");
+ assert(!R.isNull() && "ObjcActOnStartOfMethodDef() returned null type");
FunctionDecl *NewFD = new FunctionDecl(MDecl->getLocation(), II, R,
FunctionDecl::Static, false, 0);
II->setFETokenInfo(NewFD);
GlobalScope->AddDecl(NewFD);
AddTopLevelDecl(NewFD, 0);
+
+ // Allow all of Sema to see that we are entering a method definition.
+ CurMethodDecl = MDecl;
CurFunctionDecl = NewFD;
// Create Decl objects for each parameter, adding them to the FunctionDecl.
llvm::SmallVector<ParmVarDecl*, 16> Params;
struct DeclaratorChunk::ParamInfo PI;
+ // Insert the invisible arguments, self and _cmd!
PI.Ident = &Context.Idents.get("self");
- PI.IdentLoc = SourceLocation(/*FIXME*/);
-
- // Insert the invisible arguments!
+ PI.IdentLoc = SourceLocation(); // synthesized vars have a null location.
if (MDecl->isInstance()) {
QualType selfTy = Context.getObjcInterfaceType(MDecl->getClassInterface());
selfTy = Context.getPointerType(selfTy);
PI.TypeInfo = selfTy.getAsOpaquePtr();
} else
PI.TypeInfo = Context.getObjcIdType().getAsOpaquePtr();
-
Params.push_back(ParseParamDeclarator(PI, FnBodyScope));
PI.Ident = &Context.Idents.get("_cmd");
- PI.IdentLoc = SourceLocation(/*FIXME*/);
PI.TypeInfo = Context.getObjcSelType().getAsOpaquePtr();
Params.push_back(ParseParamDeclarator(PI, FnBodyScope));
for (int i = 0; i < MDecl->getNumParams(); i++) {
ParmVarDecl *PDecl = MDecl->getParamDecl(i);
PI.Ident = PDecl->getIdentifier();
- PI.IdentLoc = PDecl->getLocation();
+ PI.IdentLoc = PDecl->getLocation(); // user vars have a real location.
PI.TypeInfo = PDecl->getType().getAsOpaquePtr();
Params.push_back(ParseParamDeclarator(PI, FnBodyScope));
}
// Check interface's Ivar list against those in the implementation.
// names and types must match.
//
- ObjcIvarDecl** IntfIvars = IDecl->getIntfDeclIvars();
- int IntfNumIvars = IDecl->getIntfDeclNumIvars();
+ ObjcIvarDecl** IntfIvars = IDecl->getInstanceVariables();
+ int IntfNumIvars = IDecl->getNumInstanceVariables();
unsigned j = 0;
bool err = false;
while (numIvars > 0 && IntfNumIvars > 0) {
}
int getNumIntfRefProtocols() const { return NumReferencedProtocols; }
- ObjcIvarDecl **getIntfDeclIvars() const { return Ivars; }
- int getIntfDeclNumIvars() const { return NumIvars; }
+ ObjcIvarDecl **getInstanceVariables() const { return Ivars; }
+ int getNumInstanceVariables() const { return NumIvars; }
ObjcMethodDecl** getInstanceMethods() const { return InstanceMethods; }
int getNumInstanceMethods() const { return NumInstanceMethods; }
void setCategoryList(ObjcCategoryDecl *category) {
CategoryList = category;
}
+ ObjcIvarDecl *lookupInstanceVariable(IdentifierInfo *ivarName,
+ ObjcInterfaceDecl *&clsDeclared);
ObjcMethodDecl *lookupInstanceMethod(Selector &Sel);
ObjcMethodDecl *lookupClassMethod(Selector &Sel);