[cfe-commits] r89919 - in /cfe/trunk: include/clang/Frontend/LangStandard.h include/clang/Frontend/LangStandards.def lib/Frontend/CMakeLists.txt lib/Frontend/LangStandards.cpp tools/clang-cc/Options.cpp
Daniel Dunbar
daniel at zuster.org
Wed Nov 25 18:14:31 PST 2009
Author: ddunbar
Date: Wed Nov 25 20:14:31 2009
New Revision: 89919
URL: http://llvm.org/viewvc/llvm-project?rev=89919&view=rev
Log:
Factor out a LangStandard class and coalesce the information about the standards into LangStandards.def
- I'd appreciate another pair of eyeballs to double check this.
Added:
cfe/trunk/include/clang/Frontend/LangStandard.h
cfe/trunk/include/clang/Frontend/LangStandards.def
cfe/trunk/lib/Frontend/LangStandards.cpp
Modified:
cfe/trunk/lib/Frontend/CMakeLists.txt
cfe/trunk/tools/clang-cc/Options.cpp
Added: cfe/trunk/include/clang/Frontend/LangStandard.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/LangStandard.h?rev=89919&view=auto
==============================================================================
--- cfe/trunk/include/clang/Frontend/LangStandard.h (added)
+++ cfe/trunk/include/clang/Frontend/LangStandard.h Wed Nov 25 20:14:31 2009
@@ -0,0 +1,77 @@
+//===--- LangStandard.h -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_FRONTEND_LANGSTANDARD_H
+#define LLVM_CLANG_FRONTEND_LANGSTANDARD_H
+
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+
+namespace frontend {
+
+enum LangFeatures {
+ BCPLComment = (1 << 0),
+ C99 = (1 << 1),
+ CPlusPlus = (1 << 2),
+ CPlusPlus0x = (1 << 3),
+ Digraphs = (1 << 4),
+ GNUMode = (1 << 5),
+ HexFloat = (1 << 6),
+ ImplicitInt = (1 << 7)
+};
+
+}
+
+/// LangStandard - Information about the properties of a particular language
+/// standard.
+struct LangStandard {
+ enum Kind {
+#define LANGSTANDARD(id, name, desc, features) \
+ lang_##id,
+#include "clang/Frontend/LangStandards.def"
+ lang_unspecified
+ };
+
+ const char *ShortName;
+ const char *Description;
+ unsigned Flags;
+
+public:
+ /// hasBCPLComments - Language supports '//' comments.
+ bool hasBCPLComments() const { return Flags & frontend::BCPLComment; }
+
+ /// isC99 - Language is a superset of C99.
+ bool isC99() const { return Flags & frontend::C99; }
+
+ /// isCPlusPlus - Language is a C++ variant.
+ bool isCPlusPlus() const { return Flags & frontend::CPlusPlus; }
+
+ /// isCPlusPlus0x - Language is a C++0x variant.
+ bool isCPlusPlus0x() const { return Flags & frontend::CPlusPlus0x; }
+
+ /// hasDigraphs - Language supports diagrphs.
+ bool hasDigraphs() const { return Flags & frontend::Digraphs; }
+
+ /// isGNUMode - Language includes GNU extensions.
+ bool isGNUMode() const { return Flags & frontend::GNUMode; }
+
+ /// hasHexFloats - Language supports hexadecimal float constants.
+ bool hasHexFloats() const { return Flags & frontend::HexFloat; }
+
+ /// hasImplicitInt - Language allows variables to be typed as int implicitly.
+ bool hasImplicitInt() const { return Flags & frontend::ImplicitInt; }
+
+ static const LangStandard &getLangStandardForKind(Kind K);
+ static const LangStandard *getLangStandardForName(llvm::StringRef Name);
+};
+
+} // end namespace clang
+
+#endif
Added: cfe/trunk/include/clang/Frontend/LangStandards.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/LangStandards.def?rev=89919&view=auto
==============================================================================
--- cfe/trunk/include/clang/Frontend/LangStandards.def (added)
+++ cfe/trunk/include/clang/Frontend/LangStandards.def Wed Nov 25 20:14:31 2009
@@ -0,0 +1,83 @@
+//===-- LangStandards.def - Language Standard Data --------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LANGSTANDARD
+#error "LANGSTANDARD must be defined before including this file"
+#endif
+
+/// LANGSTANDARD(IDENT, NAME, DESC, FEATURES)
+///
+/// \param IDENT - The name of the standard as a C++ identifier.
+/// \param NAME - The name of the standard.
+/// \param DESC - A short description of the standard.
+/// \param FEATURES - The standard features as flags, these are enums from the
+/// clang::frontend namespace, which is assumed to be be available.
+
+// C89-ish modes.
+LANGSTANDARD(c89, "c89",
+ "ISO C 1990",
+ ImplicitInt)
+LANGSTANDARD(c90, "c90",
+ "ISO C 1990",
+ ImplicitInt)
+LANGSTANDARD(iso9899_1990, "iso9899:1990",
+ "ISO C 1990",
+ ImplicitInt)
+
+LANGSTANDARD(c94, "iso9899:199409",
+ "ISO C 1990 with amendment 1",
+ Digraphs | ImplicitInt)
+
+LANGSTANDARD(gnu89, "gnu89",
+ "ISO C 1990 with GNU extensions",
+ BCPLComment | Digraphs | GNUMode | ImplicitInt)
+
+// C99-ish modes
+LANGSTANDARD(c99, "c99",
+ "ISO C 1999",
+ BCPLComment | C99 | Digraphs | HexFloat)
+LANGSTANDARD(c9x, "c9x",
+ "ISO C 1999",
+ BCPLComment | C99 | Digraphs | HexFloat)
+LANGSTANDARD(iso9899_1999,
+ "iso9899:1999", "ISO C 1999",
+ BCPLComment | C99 | Digraphs | HexFloat)
+LANGSTANDARD(iso9899_199x,
+ "iso9899:199x", "ISO C 1999",
+ BCPLComment | C99 | Digraphs | HexFloat)
+
+LANGSTANDARD(gnu99, "gnu99",
+ "ISO C 1999 with GNU extensions",
+ BCPLComment | C99 | Digraphs | GNUMode | HexFloat | Digraphs)
+LANGSTANDARD(gnu9x, "gnu9x",
+ "ISO C 1999 with GNU extensions",
+ BCPLComment | C99 | Digraphs | GNUMode | HexFloat)
+
+// C++ modes
+LANGSTANDARD(cxx98, "c++98",
+ "ISO C++ 1998 with amendments",
+ BCPLComment | CPlusPlus | Digraphs)
+LANGSTANDARD(gnucxx98, "gnu++98",
+ "ISO C++ 1998 with " "amendments and GNU extensions",
+ BCPLComment | CPlusPlus | Digraphs | GNUMode)
+
+LANGSTANDARD(cxx0x, "c++0x",
+ "Upcoming ISO C++ 200x with amendments",
+ BCPLComment | CPlusPlus | CPlusPlus0x | Digraphs)
+LANGSTANDARD(gnucxx0x, "gnu++0x",
+ "Upcoming ISO C++ 200x with amendments and GNU extensions",
+ BCPLComment | CPlusPlus | CPlusPlus0x | Digraphs | GNUMode)
+
+// OpenCL
+
+LANGSTANDARD(opencl, "cl",
+ "OpenCL 1.0",
+ BCPLComment | C99 | Digraphs | HexFloat)
+
+#undef LANGSTANDARD
Modified: cfe/trunk/lib/Frontend/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CMakeLists.txt?rev=89919&r1=89918&r2=89919&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CMakeLists.txt (original)
+++ cfe/trunk/lib/Frontend/CMakeLists.txt Wed Nov 25 20:14:31 2009
@@ -21,6 +21,7 @@
HTMLPrint.cpp
InitHeaderSearch.cpp
InitPreprocessor.cpp
+ LangStandards.cpp
PCHReader.cpp
PCHReaderDecl.cpp
PCHReaderStmt.cpp
Added: cfe/trunk/lib/Frontend/LangStandards.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/LangStandards.cpp?rev=89919&view=auto
==============================================================================
--- cfe/trunk/lib/Frontend/LangStandards.cpp (added)
+++ cfe/trunk/lib/Frontend/LangStandards.cpp Wed Nov 25 20:14:31 2009
@@ -0,0 +1,44 @@
+//===--- LangStandards.cpp - Language Standard Definitions ----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Frontend/LangStandard.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/ErrorHandling.h"
+using namespace clang;
+using namespace clang::frontend;
+
+#define LANGSTANDARD(id, name, desc, features) \
+ static LangStandard Lang_##id = { name, desc, features };
+#include "clang/Frontend/LangStandards.def"
+
+const LangStandard &LangStandard::getLangStandardForKind(Kind K) {
+ switch (K) {
+ default:
+ llvm::llvm_unreachable("Invalid language kind!");
+ case lang_unspecified:
+ llvm::llvm_report_error("getLangStandardForKind() on unspecified kind");
+#define LANGSTANDARD(id, name, desc, features) \
+ case lang_##id: return Lang_##id;
+#include "clang/Frontend/LangStandards.def"
+ }
+}
+
+const LangStandard *LangStandard::getLangStandardForName(llvm::StringRef Name) {
+ Kind K = llvm::StringSwitch<Kind>(Name)
+#define LANGSTANDARD(id, name, desc, features) \
+ .Case(name, lang_##id)
+#include "clang/Frontend/LangStandards.def"
+ .Default(lang_unspecified);
+ if (K == lang_unspecified)
+ return 0;
+
+ return &getLangStandardForKind(K);
+}
+
+
Modified: cfe/trunk/tools/clang-cc/Options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Options.cpp?rev=89919&r1=89918&r2=89919&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/Options.cpp (original)
+++ cfe/trunk/tools/clang-cc/Options.cpp Wed Nov 25 20:14:31 2009
@@ -21,6 +21,7 @@
#include "clang/Frontend/DiagnosticOptions.h"
#include "clang/Frontend/FrontendOptions.h"
#include "clang/Frontend/HeaderSearchOptions.h"
+#include "clang/Frontend/LangStandard.h"
#include "clang/Frontend/PCHReader.h"
#include "clang/Frontend/PreprocessorOptions.h"
#include "clang/Frontend/PreprocessorOutputOptions.h"
@@ -436,6 +437,8 @@
namespace langoptions {
+using namespace clang::frontend;
+
static llvm::cl::opt<bool>
NoBuiltin("fno-builtin",
llvm::cl::desc("Disable implicit builtin knowledge of functions"));
@@ -481,42 +484,12 @@
llvm::cl::desc("Generate output compatible with the standard GNU "
"Objective-C runtime"));
-/// LangStds - Language standards we support.
-enum LangStds {
- lang_unspecified,
- lang_c89, lang_c94, lang_c99,
- lang_gnu89, lang_gnu99,
- lang_cxx98, lang_gnucxx98,
- lang_cxx0x, lang_gnucxx0x
-};
-static llvm::cl::opt<LangStds>
+static llvm::cl::opt<LangStandard::Kind>
LangStd("std", llvm::cl::desc("Language standard to compile for"),
- llvm::cl::init(lang_unspecified),
- llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
- clEnumValN(lang_c89, "c90", "ISO C 1990"),
- clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
- clEnumValN(lang_c94, "iso9899:199409",
- "ISO C 1990 with amendment 1"),
- clEnumValN(lang_c99, "c99", "ISO C 1999"),
- clEnumValN(lang_c99, "c9x", "ISO C 1999"),
- clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
- clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
- clEnumValN(lang_gnu89, "gnu89",
- "ISO C 1990 with GNU extensions"),
- clEnumValN(lang_gnu99, "gnu99",
- "ISO C 1999 with GNU extensions (default for C)"),
- clEnumValN(lang_gnu99, "gnu9x",
- "ISO C 1999 with GNU extensions"),
- clEnumValN(lang_cxx98, "c++98",
- "ISO C++ 1998 with amendments"),
- clEnumValN(lang_gnucxx98, "gnu++98",
- "ISO C++ 1998 with amendments and GNU "
- "extensions (default for C++)"),
- clEnumValN(lang_cxx0x, "c++0x",
- "Upcoming ISO C++ 200x with amendments"),
- clEnumValN(lang_gnucxx0x, "gnu++0x",
- "Upcoming ISO C++ 200x with amendments and GNU "
- "extensions"),
+ llvm::cl::init(LangStandard::lang_unspecified), llvm::cl::values(
+#define LANGSTANDARD(id, name, desc, features) \
+ clEnumValN(LangStandard::lang_##id, name, desc),
+#include "clang/Frontend/LangStandards.def"
clEnumValEnd));
static llvm::cl::opt<bool>
@@ -1111,87 +1084,43 @@
Options.setVisibilityMode(SymbolVisibility);
Options.OverflowChecking = OverflowChecking;
- if (LangStd == lang_unspecified) {
+ if (LangStd == LangStandard::lang_unspecified) {
// Based on the base language, pick one.
switch (IK) {
case FrontendOptions::IK_None:
case FrontendOptions::IK_AST:
assert(0 && "Invalid input kind!");
case FrontendOptions::IK_OpenCL:
- LangStd = lang_c99;
+ LangStd = LangStandard::lang_opencl;
break;
case FrontendOptions::IK_Asm:
case FrontendOptions::IK_C:
case FrontendOptions::IK_PreprocessedC:
case FrontendOptions::IK_ObjC:
case FrontendOptions::IK_PreprocessedObjC:
- LangStd = lang_gnu99;
+ LangStd = LangStandard::lang_gnu99;
break;
case FrontendOptions::IK_CXX:
case FrontendOptions::IK_PreprocessedCXX:
case FrontendOptions::IK_ObjCXX:
case FrontendOptions::IK_PreprocessedObjCXX:
- LangStd = lang_gnucxx98;
+ LangStd = LangStandard::lang_gnucxx98;
break;
}
}
- switch (LangStd) {
- default: assert(0 && "Unknown language standard!");
+ const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
+ Options.BCPLComment = Std.hasBCPLComments();
+ Options.C99 = Std.isC99();
+ Options.CPlusPlus = Std.isCPlusPlus();
+ Options.CPlusPlus0x = Std.isCPlusPlus0x();
+ Options.Digraphs = Std.hasDigraphs();
+ Options.GNUMode = Std.isGNUMode();
+ Options.HexFloats = Std.hasHexFloats();
+ Options.ImplicitInt = Std.hasImplicitInt();
- // Fall through from newer standards to older ones. This isn't really right.
- // FIXME: Enable specifically the right features based on the language stds.
- case lang_gnucxx0x:
- case lang_cxx0x:
- Options.CPlusPlus0x = 1;
- // FALL THROUGH
- case lang_gnucxx98:
- case lang_cxx98:
- Options.CPlusPlus = 1;
+ if (Options.CPlusPlus)
Options.CXXOperatorNames = !NoOperatorNames;
- // FALL THROUGH.
- case lang_gnu99:
- case lang_c99:
- Options.C99 = 1;
- Options.HexFloats = 1;
- // FALL THROUGH.
- case lang_gnu89:
- Options.BCPLComment = 1; // Only for C99/C++.
- // FALL THROUGH.
- case lang_c94:
- Options.Digraphs = 1; // C94, C99, C++.
- // FALL THROUGH.
- case lang_c89:
- break;
- }
-
- // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
- switch (LangStd) {
- default: assert(0 && "Unknown language standard!");
- case lang_gnucxx0x:
- case lang_gnucxx98:
- case lang_gnu99:
- case lang_gnu89:
- Options.GNUMode = 1;
- break;
- case lang_cxx0x:
- case lang_cxx98:
- case lang_c99:
- case lang_c94:
- case lang_c89:
- Options.GNUMode = 0;
- break;
- }
-
- if (Options.CPlusPlus) {
- Options.C99 = 0;
- Options.HexFloats = 0;
- }
-
- if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
- Options.ImplicitInt = 1;
- else
- Options.ImplicitInt = 0;
// Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
// is specified, or -std is set to a conforming mode.
@@ -1242,7 +1171,7 @@
Options.ElideConstructors = !NoElideConstructors;
// OpenCL and C++ both have bool, true, false keywords.
- Options.Bool = Options.OpenCL | Options.CPlusPlus;
+ Options.Bool = Options.OpenCL || Options.CPlusPlus;
Options.MathErrno = !NoMathErrno;
More information about the cfe-commits
mailing list