[cfe-commits] r50387 - in /cfe/trunk: Driver/clang.cpp include/clang/Basic/LangOptions.h lib/Basic/LangOptions.cpp
Ted Kremenek
kremenek at apple.com
Mon Apr 28 21:37:03 PDT 2008
Author: kremenek
Date: Mon Apr 28 23:37:03 2008
New Revision: 50387
URL: http://llvm.org/viewvc/llvm-project?rev=50387&view=rev
Log:
Add -fobjc-gc and -fobjc-gc-only options to the driver.
Add corresponding enum in LangOptions.
Modified:
cfe/trunk/Driver/clang.cpp
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/lib/Basic/LangOptions.cpp
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=50387&r1=50386&r2=50387&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Mon Apr 28 23:37:03 2008
@@ -283,7 +283,7 @@
NoPreprocess = true;
// FALLTHROUGH
case langkind_objc:
- Options.ObjC1 = Options.ObjC2 = 1;
+ Options.ObjC1 = Options.ObjC2 = 1;
break;
case langkind_objcxx_cpp:
NoPreprocess = true;
@@ -358,6 +358,7 @@
llvm::cl::desc("Allow implicit conversions between vectors"
" with a different number of elements or "
"different element types."));
+
// FIXME: add:
// -ansi
// -trigraphs
@@ -425,6 +426,23 @@
Options.LaxVectorConversions = LaxVectorConversions;
}
+static llvm::cl::opt<bool>
+ObjCExclusiveGC("fobjc-gc-only",
+ llvm::cl::desc("Use GC exclusively for Objective-C related "
+ "memory management."));
+
+static llvm::cl::opt<bool>
+ObjCEnableGC("fobjc-gc",
+ llvm::cl::desc("Enable Objective-C garbage collection."));
+
+void InitializeGCMode(LangOptions &Options) {
+ if (ObjCExclusiveGC)
+ Options.setGCMode(LangOptions::GCOnly);
+ else if (ObjCEnableGC)
+ Options.setGCMode(LangOptions::HybridGC);
+}
+
+
//===----------------------------------------------------------------------===//
// Our DiagnosticClient implementation
//===----------------------------------------------------------------------===//
@@ -1399,6 +1417,7 @@
LangKind LK = GetLanguage(InFile);
InitializeLangOptions(LangInfo, LK);
InitializeLanguageStandard(LangInfo, LK);
+ InitializeGCMode(LangInfo);
// Process the -I options and set them in the HeaderInfo.
HeaderSearch HeaderInfo(FileMgr);
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=50387&r1=50386&r2=50387&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Mon Apr 28 23:37:03 2008
@@ -21,6 +21,7 @@
/// LangOptions - This class keeps track of the various options that can be
/// enabled, which controls the dialect of C that is accepted.
struct LangOptions {
+
unsigned Trigraphs : 1; // Trigraphs in source files.
unsigned BCPLComment : 1; // BCPL-style '//' comments.
unsigned DollarIdents : 1; // '$' allowed in identifiers.
@@ -34,23 +35,34 @@
unsigned NoExtensions : 1; // All extensions are disabled, strict mode.
unsigned CXXOperatorNames : 1; // Treat C++ operator names as keywords.
- unsigned ObjC1 : 1; // Objective C 1 support enabled.
- unsigned ObjC2 : 1; // Objective C 2 support enabled.
-
+ unsigned ObjC1 : 1; // Objective-C 1 support enabled.
+ unsigned ObjC2 : 1; // Objective-C 2 support enabled.
+
unsigned PascalStrings : 1; // Allow Pascal strings
unsigned Boolean : 1; // Allow bool/true/false
unsigned WritableStrings : 1; // Allow writable strings
unsigned LaxVectorConversions : 1;
-
+
+private:
+ unsigned GC : 2; // Objective-C Garbage Collection modes. We declare
+ // this enum as unsigned because MSVC insists on making enums
+ // signed. Set/Query this value using accessors.
+public:
+
+ enum GCMode { NonGC, GCOnly, HybridGC };
+
LangOptions() {
Trigraphs = BCPLComment = DollarIdents = ImplicitInt = Digraphs = 0;
HexFloats = 0;
- ObjC1 = ObjC2 = 0;
+ GC = ObjC1 = ObjC2 = 0;
C99 = Microsoft = CPlusPlus = CPlusPlus0x = NoExtensions = 0;
CXXOperatorNames = PascalStrings = Boolean = WritableStrings = 0;
LaxVectorConversions = 0;
}
+ GCMode getGCMode() const { return (GCMode) GC; }
+ void setGCMode(GCMode m) { GC = (unsigned) m; }
+
/// Emit - Emit this LangOptions object to bitcode.
void Emit(llvm::Serializer& S) const;
Modified: cfe/trunk/lib/Basic/LangOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/LangOptions.cpp?rev=50387&r1=50386&r2=50387&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/LangOptions.cpp (original)
+++ cfe/trunk/lib/Basic/LangOptions.cpp Mon Apr 28 23:37:03 2008
@@ -30,7 +30,8 @@
S.EmitBool((bool) NoExtensions);
S.EmitBool((bool) CXXOperatorNames);
S.EmitBool((bool) ObjC1);
- S.EmitBool((bool) ObjC2);
+ S.EmitBool((bool) ObjC2);
+ S.EmitBool((unsigned) GC);
S.EmitBool((bool) PascalStrings);
S.EmitBool((bool) Boolean);
S.EmitBool((bool) WritableStrings);
@@ -51,6 +52,7 @@
CXXOperatorNames = D.ReadBool() ? 1 : 0;
ObjC1 = D.ReadBool() ? 1 : 0;
ObjC2 = D.ReadBool() ? 1 : 0;
+ GC = D.ReadInt();
PascalStrings = D.ReadBool() ? 1 : 0;
Boolean = D.ReadBool() ? 1 : 0;
WritableStrings = D.ReadBool() ? 1 : 0;
More information about the cfe-commits
mailing list