[cfe-commits] r42845 - in /cfe/trunk: Sema/Sema.cpp Sema/Sema.h Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/Basic/DiagnosticKinds.def test/Sema/id_not_builtin.m
Steve Naroff
snaroff at apple.com
Wed Oct 10 16:24:43 PDT 2007
Author: snaroff
Date: Wed Oct 10 18:24:43 2007
New Revision: 42845
URL: http://llvm.org/viewvc/llvm-project?rev=42845&view=rev
Log:
Refinements to Sema::GetObjcIdType()...
- Cache the typedef, not the type (avoids importing AST/Type.h).
- Emit an error if "id" cannot be found.
- Comment the routine and add a FIXME to reconsider how we emulate GCC's new fangled behavior. This isn't a priority for now, since almost no code depends on having "id" built-in.
- Add a test.
Added:
cfe/trunk/test/Sema/id_not_builtin.m
Modified:
cfe/trunk/Sema/Sema.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
Modified: cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.cpp?rev=42845&r1=42844&r2=42845&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/trunk/Sema/Sema.cpp Wed Oct 10 18:24:43 2007
@@ -23,17 +23,25 @@
TUScope = S;
}
-QualType Sema::GetObjcIdType() {
+/// GetObjcIdType - The following method assumes that "id" is imported
+/// via <objc/objc.h>. This is the way GCC worked for almost 20 years.
+/// In GCC 4.0, "id" is now a built-in type. Unfortunately, typedefs *cannot* be
+/// redefined (even if they are identical). To allow a built-in types to coexist
+/// with <objc/objc.h>, GCC has a special hack on decls (DECL_IN_SYSTEM_HEADER).
+/// For now, we will *not* install id as a built-in. FIXME: reconsider this.
+QualType Sema::GetObjcIdType(SourceLocation Loc) {
assert(TUScope && "GetObjcIdType(): Top-level scope is null");
- if (ObjcIdType.isNull()) {
+ if (!ObjcIdTypedef) {
IdentifierInfo *IdIdent = &Context.Idents.get("id");
ScopedDecl *IdDecl = LookupScopedDecl(IdIdent, Decl::IDNS_Ordinary,
SourceLocation(), TUScope);
- TypedefDecl *IdTypedef = dyn_cast_or_null<TypedefDecl>(IdDecl);
- assert(IdTypedef && "GetObjcIdType(): Couldn't find 'id' type");
- ObjcIdType = Context.getTypedefType(IdTypedef);
+ ObjcIdTypedef = dyn_cast_or_null<TypedefDecl>(IdDecl);
+ if (!ObjcIdTypedef) {
+ Diag(Loc, diag::err_missing_id_definition);
+ return QualType();
+ }
}
- return ObjcIdType;
+ return Context.getTypedefType(ObjcIdTypedef);
}
@@ -56,7 +64,7 @@
KnownFunctionIDs[ id_vprintf ] = &IT.get("vprintf");
TUScope = 0;
- ObjcIdType = QualType();
+ ObjcIdTypedef = 0;
}
void Sema::DeleteExpr(ExprTy *E) {
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=42845&r1=42844&r2=42845&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Wed Oct 10 18:24:43 2007
@@ -19,7 +19,6 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
-#include "clang/AST/Type.h"
#include <vector>
#include <string>
@@ -119,8 +118,8 @@
/// For example, user-defined classes, built-in "id" type, etc.
Scope *TUScope;
- /// ObjcIdType - built-in type for "id".
- QualType ObjcIdType;
+ /// ObjcIdTypedef - built-in typedef for "id".
+ TypedefDecl *ObjcIdTypedef;
public:
Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
@@ -257,7 +256,7 @@
const ObjcMethodDecl *PrevMethod);
/// GetObjcIdType - Getter for the build-in "id" type.
- QualType GetObjcIdType();
+ QualType GetObjcIdType(SourceLocation Loc = SourceLocation());
//===--------------------------------------------------------------------===//
// Statement Parsing Callbacks: SemaStmt.cpp.
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42845&r1=42844&r2=42845&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Oct 10 18:24:43 2007
@@ -1779,7 +1779,7 @@
if (ArgTypes[i])
argType = QualType::getFromOpaquePtr(ArgTypes[i]);
else
- argType = GetObjcIdType();
+ argType = GetObjcIdType(MethodLoc);
ParmVarDecl* Param = new ParmVarDecl(SourceLocation(/*FIXME*/), ArgNames[i],
argType, VarDecl::None, 0);
Params.push_back(Param);
@@ -1789,7 +1789,7 @@
if (ReturnType)
resultDeclType = QualType::getFromOpaquePtr(ReturnType);
else // get the type for "id".
- resultDeclType = GetObjcIdType();
+ resultDeclType = GetObjcIdType(MethodLoc);
ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc, Sel,
resultDeclType, 0, -1, AttrList,
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=42845&r1=42844&r2=42845&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Wed Oct 10 18:24:43 2007
@@ -739,7 +739,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=42845&r1=42844&r2=42845&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Oct 10 18:24:43 2007
@@ -444,6 +444,8 @@
"previous declaration is here")
DIAG(err_undeclared_protocol, ERROR,
"cannot find protocol declaration for '%0'")
+DIAG(err_missing_id_definition, ERROR,
+ "cannot find definition of 'id'")
//===----------------------------------------------------------------------===//
Added: cfe/trunk/test/Sema/id_not_builtin.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/id_not_builtin.m?rev=42845&view=auto
==============================================================================
--- cfe/trunk/test/Sema/id_not_builtin.m (added)
+++ cfe/trunk/test/Sema/id_not_builtin.m Wed Oct 10 18:24:43 2007
@@ -0,0 +1,9 @@
+// RUN: clang %s -parse-ast -verify
+
+id obj; // expected-error{{expected '=', ',', ';', 'asm', or '__attribute__' after declarator}}
+
+ at interface Foo
+
+- defaultToId; // expected-error{{cannot find definition of 'id'}}
+
+ at end
More information about the cfe-commits
mailing list