[cfe-commits] r42764 - in /cfe/trunk: Driver/ASTConsumers.cpp Parse/ParseObjc.cpp include/clang/AST/DeclObjC.h include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h
Fariborz Jahanian
fjahanian at apple.com
Mon Oct 8 11:53:38 PDT 2007
Author: fjahanian
Date: Mon Oct 8 13:53:38 2007
New Revision: 42764
URL: http://llvm.org/viewvc/llvm-project?rev=42764&view=rev
Log:
Several small patches to do pretty printing for objective-c top-level decls
(minimal printing), Derive ObjcClassDecl from Decl. Ted may want to
take note of the change I made to CFGRecStmtDeclVisitor.h
Modified:
cfe/trunk/Driver/ASTConsumers.cpp
cfe/trunk/Parse/ParseObjc.cpp
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h
Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=42764&r1=42763&r2=42764&view=diff
==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Mon Oct 8 13:53:38 2007
@@ -79,6 +79,26 @@
// FIXME: implement the rest...
}
+static void PrintObjcProtocolDecl(ObjcProtocolDecl *PID) {
+ std::string S = PID->getName();
+ fprintf(stderr, "@protocol %s;\n", S.c_str());
+ // FIXME: implement the rest...
+}
+
+static void PrintObjcCategoryImplDecl(ObjcCategoryImplDecl *PID) {
+ std::string S = PID->getName();
+ std::string I = PID->getClassInterface()->getName();
+ fprintf(stderr, "@implementation %s(%s);\n", I.c_str(), S.c_str());
+ // FIXME: implement the rest...
+}
+
+static void PrintObjcCategoryDecl(ObjcCategoryDecl *PID) {
+ std::string S = PID->getName();
+ std::string I = PID->getClassInterface()->getName();
+ fprintf(stderr, "@interface %s(%s);\n", I.c_str(), S.c_str());
+ // FIXME: implement the rest...
+}
+
namespace {
class ASTPrinter : public ASTConsumer {
virtual void HandleTopLevelDecl(Decl *D) {
@@ -92,10 +112,10 @@
}
} else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
PrintTypeDefDecl(TD);
- } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
- fprintf(stderr, "Read top-level variable decl: '%s'\n", SD->getName());
} else if (ObjcInterfaceDecl *OID = dyn_cast<ObjcInterfaceDecl>(D)) {
PrintObjcInterfaceDecl(OID);
+ } else if (ObjcProtocolDecl *PID = dyn_cast<ObjcProtocolDecl>(D)) {
+ PrintObjcProtocolDecl(PID);
} else if (ObjcForwardProtocolDecl *OFPD =
dyn_cast<ObjcForwardProtocolDecl>(D)) {
fprintf(stderr, "@protocol ");
@@ -109,8 +129,16 @@
dyn_cast<ObjcImplementationDecl>(D)) {
fprintf(stderr, "@implementation %s [printing todo]\n",
OID->getName());
+ } else if (ObjcCategoryImplDecl *OID =
+ dyn_cast<ObjcCategoryImplDecl>(D)) {
+ PrintObjcCategoryImplDecl(OID);
+ } else if (ObjcCategoryDecl *OID =
+ dyn_cast<ObjcCategoryDecl>(D)) {
+ PrintObjcCategoryDecl(OID);
} else if (isa<ObjcClassDecl>(D)) {
fprintf(stderr, "@class [printing todo]\n");
+ } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
+ fprintf(stderr, "Read top-level variable decl: '%s'\n", SD->getName());
} else {
assert(0 && "Unknown decl type!");
}
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=42764&r1=42763&r2=42764&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Mon Oct 8 13:53:38 2007
@@ -163,7 +163,7 @@
// The @ sign was already consumed by ParseObjCInterfaceDeclList().
if (Tok.isObjCAtKeyword(tok::objc_end)) {
ConsumeToken(); // the "end" identifier
- return 0;
+ return CategoryType;
}
Diag(Tok, diag::err_objc_missing_end);
return 0;
@@ -803,7 +803,7 @@
// The @ sign was already consumed by ParseObjCInterfaceDeclList().
if (Tok.isObjCAtKeyword(tok::objc_end)) {
ConsumeToken(); // the "end" identifier
- return 0;
+ return ProtoType;
}
Diag(Tok, diag::err_objc_missing_end);
return 0;
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=42764&r1=42763&r2=42764&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Oct 8 13:53:38 2007
@@ -347,12 +347,12 @@
///
/// @class NSCursor, NSImage, NSPasteboard, NSWindow;
///
-class ObjcClassDecl : public TypeDecl {
+class ObjcClassDecl : public Decl {
ObjcInterfaceDecl **ForwardDecls;
unsigned NumForwardDecls;
public:
ObjcClassDecl(SourceLocation L, ObjcInterfaceDecl **Elts, unsigned nElts)
- : TypeDecl(ObjcClass, L, 0, 0) {
+ : Decl(ObjcClass, L) {
if (nElts) {
ForwardDecls = new ObjcInterfaceDecl*[nElts];
memcpy(ForwardDecls, Elts, nElts*sizeof(ObjcInterfaceDecl*));
Modified: cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h?rev=42764&r1=42763&r2=42764&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h (original)
+++ cfe/trunk/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h Mon Oct 8 13:53:38 2007
@@ -64,7 +64,6 @@
DISPATCH_CASE(Class,RecordDecl) // FIXME: Refine.
DISPATCH_CASE(Enum,EnumDecl)
DISPATCH_CASE(ObjcInterface,ObjcInterfaceDecl)
- DISPATCH_CASE(ObjcClass,ObjcClassDecl)
DISPATCH_CASE(ObjcProtocol,ObjcProtocolDecl)
default:
assert(false && "Subtype of ScopedDecl not handled.");
More information about the cfe-commits
mailing list