[cfe-commits] r43346 - in /cfe/trunk: Driver/RewriteTest.cpp clang.xcodeproj/project.pbxproj
Chris Lattner
sabre at nondot.org
Thu Oct 25 10:07:24 PDT 2007
Author: lattner
Date: Thu Oct 25 12:07:24 2007
New Revision: 43346
URL: http://llvm.org/viewvc/llvm-project?rev=43346&view=rev
Log:
Convert one type of metadata to use std::string instead of
printf as an example.
Modified:
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/clang.xcodeproj/project.pbxproj
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=43346&r1=43345&r2=43346&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Thu Oct 25 12:07:24 2007
@@ -17,7 +17,9 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/IdentifierTable.h"
+#include "llvm/ADT/StringExtras.h"
using namespace clang;
+using llvm::utostr;
namespace {
class RewriteTest : public ASTConsumer {
@@ -70,7 +72,8 @@
int NumMethods,
bool IsInstanceMethod,
const char *prefix,
- const char *ClassName);
+ const char *ClassName,
+ std::string &Result);
void RewriteObjcProtocolsMetaData(ObjcProtocolDecl **Protocols,
int NumProtocols,
@@ -360,7 +363,8 @@
int NumMethods,
bool IsInstanceMethod,
const char *prefix,
- const char *ClassName) {
+ const char *ClassName,
+ std::string &Result) {
static bool objc_impl_method = false;
if (NumMethods > 0 && !objc_impl_method) {
/* struct _objc_method {
@@ -369,11 +373,11 @@
void *_imp;
}
*/
- printf("\nstruct _objc_method {\n");
- printf("\tSEL _cmd;\n");
- printf("\tchar *method_types;\n");
- printf("\tvoid *_imp;\n");
- printf("};\n");
+ Result += "\nstruct _objc_method {\n";
+ Result += "\tSEL _cmd;\n";
+ Result += "\tchar *method_types;\n";
+ Result += "\tvoid *_imp;\n";
+ Result += "};\n";
objc_impl_method = true;
}
// Build _objc_method_list for class's methods if needed
@@ -384,21 +388,27 @@
struct _objc_method method_list[method_count];
}
*/
- printf("\nstatic struct {\n");
- printf("\tstruct _objc_method_list *next_method;\n");
- printf("\tint method_count;\n");
- printf("\tstruct _objc_method method_list[%d];\n", NumMethods);
- printf("} _OBJC_%s%s_METHODS_%s "
- "__attribute__ ((section (\"__OBJC, __%s_meth\")))= "
- "{\n\t0, %d\n", prefix, IsInstanceMethod ? "INSTANCE" : "CLASS",
- ClassName, IsInstanceMethod ? "inst" : "cls", NumMethods);
- for (int i = 0; i < NumMethods; i++)
+ Result += "\nstatic struct {\n";
+ Result += "\tstruct _objc_method_list *next_method;\n";
+ Result += "\tint method_count;\n";
+ Result += "\tstruct _objc_method method_list[" + utostr(NumMethods) +"];\n";
+ Result += "} _OBJC_";
+ Result += prefix;
+ Result += IsInstanceMethod ? "INSTANCE" : "CLASS";
+ Result += "_METHODS_";
+ Result += ClassName;
+ Result += " __attribute__ ((section (\"__OBJC, __";
+ Result += IsInstanceMethod ? "inst" : "cls";
+ Result += "_meth\")))= {\n\t0, " + utostr(NumMethods) + "\n";
+
+ for (int i = 0; i < NumMethods; i++) {
// TODO: 1) method selector name may hav to go into their own section
// 2) encode method types for use here (which may have to go into
// __meth_var_types section, 3) Need method address as 3rd initializer.
- printf("\t,(SEL)\"%s\", \"\", 0\n",
- Methods[i]->getSelector().getName().c_str());
- printf("};\n");
+ Result += "\t,(SEL)\"" + Methods[i]->getSelector().getName() +
+ "\", \"\", 0\n";
+ }
+ Result += "};\n";
}
}
@@ -545,17 +555,23 @@
strlen(ClassDecl->getName()) + strlen(IDecl->getName()) + 2);
sprintf(FullCategoryName, "%s_%s", ClassDecl->getName(), IDecl->getName());
+ std::string ResultStr;
+
// Build _objc_method_list for class's instance methods if needed
RewriteObjcMethodsMetaData(IDecl->getInstanceMethods(),
IDecl->getNumInstanceMethods(),
true,
- "CATEGORY_", FullCategoryName);
+ "CATEGORY_", FullCategoryName, ResultStr);
// Build _objc_method_list for class's class methods if needed
RewriteObjcMethodsMetaData(IDecl->getClassMethods(),
IDecl->getNumClassMethods(),
false,
- "CATEGORY_", FullCategoryName);
+ "CATEGORY_", FullCategoryName, ResultStr);
+
+ // For now just print the string out. It should be passed to the other
+ // functions to collect all metadata info into the string.
+ printf("%s", ResultStr.c_str());
// Protocols referenced in class declaration?
RewriteObjcProtocolsMetaData(CDecl->getReferencedProtocols(),
@@ -666,18 +682,22 @@
printf("};\n");
}
+ std::string ResultStr;
+
// Build _objc_method_list for class's instance methods if needed
RewriteObjcMethodsMetaData(IDecl->getInstanceMethods(),
IDecl->getNumInstanceMethods(),
- true,
- "", IDecl->getName());
+ true, "", IDecl->getName(), ResultStr);
// Build _objc_method_list for class's class methods if needed
RewriteObjcMethodsMetaData(IDecl->getClassMethods(),
IDecl->getNumClassMethods(),
- false,
- "", IDecl->getName());
-
+ false, "", IDecl->getName(), ResultStr);
+
+ // For now just print the string out. It should be passed to the other
+ // functions to collect all metadata info into the string.
+ printf("%s", ResultStr.c_str());
+
// Protocols referenced in class declaration?
RewriteObjcProtocolsMetaData(CDecl->getReferencedProtocols(),
CDecl->getNumIntfRefProtocols(),
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=43346&r1=43345&r2=43346&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Thu Oct 25 12:07:24 2007
@@ -753,7 +753,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
More information about the cfe-commits
mailing list