Revision: 16222
Author:   [email protected]
Date:     Mon Aug 19 14:46:35 2013 UTC
Log:      Add FINAL and OVERRIDE macros for C++11 final/override.

We also use new the constant naming scheme for Yield::Kind values to avoid
clash with the FINAL macro.

[email protected]

Review URL: https://codereview.chromium.org/23098004
http://code.google.com/p/v8/source/detail?r=16222

Modified:
 /branches/bleeding_edge/src/arm/full-codegen-arm.cc
 /branches/bleeding_edge/src/ast.h
 /branches/bleeding_edge/src/globals.h
 /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
 /branches/bleeding_edge/src/mips/full-codegen-mips.cc
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/src/x64/full-codegen-x64.cc

=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Tue Aug 6 13:34:51 2013 UTC +++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Mon Aug 19 14:46:35 2013 UTC
@@ -1986,12 +1986,12 @@
   VisitForStackValue(expr->expression());

   switch (expr->yield_kind()) {
-    case Yield::SUSPEND:
+    case Yield::kSuspend:
       // Pop value from top-of-stack slot; box result into result register.
       EmitCreateIteratorResult(false);
       __ push(result_register());
       // Fall through.
-    case Yield::INITIAL: {
+    case Yield::kInitial: {
       Label suspend, continuation, post_runtime, resume;

       __ jmp(&suspend);
@@ -2023,7 +2023,7 @@
       break;
     }

-    case Yield::FINAL: {
+    case Yield::kFinal: {
       VisitForAccumulatorValue(expr->generator_object());
__ mov(r1, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)));
       __ str(r1, FieldMemOperand(result_register(),
@@ -2035,7 +2035,7 @@
       break;
     }

-    case Yield::DELEGATING: {
+    case Yield::kDelegating: {
       VisitForStackValue(expr->generator_object());

       // Initial stack layout is as follows:
=======================================
--- /branches/bleeding_edge/src/ast.h   Tue Aug  6 13:34:51 2013 UTC
+++ /branches/bleeding_edge/src/ast.h   Mon Aug 19 14:46:35 2013 UTC
@@ -2144,10 +2144,10 @@
   DECLARE_NODE_TYPE(Yield)

   enum Kind {
- INITIAL, // The initial yield that returns the unboxed generator object.
-    SUSPEND,     // A normal yield: { value: EXPRESSION, done: false }
-    DELEGATING,  // A yield*.
-    FINAL        // A return: { value: EXPRESSION, done: true }
+ kInitial, // The initial yield that returns the unboxed generator object
+    kSuspend,     // A normal yield: { value: EXPRESSION, done: false }
+    kDelegating,  // A yield*.
+    kFinal        // A return: { value: EXPRESSION, done: true }
   };

   Expression* generator_object() const { return generator_object_; }
@@ -2159,11 +2159,11 @@
   // locates the catch handler in the handler table, and is equivalent to
   // TryCatchStatement::index().
   int index() const {
-    ASSERT(yield_kind() == DELEGATING);
+    ASSERT(yield_kind() == kDelegating);
     return index_;
   }
   void set_index(int index) {
-    ASSERT(yield_kind() == DELEGATING);
+    ASSERT(yield_kind() == kDelegating);
     index_ = index;
   }

=======================================
--- /branches/bleeding_edge/src/globals.h       Wed Jul 31 07:51:46 2013 UTC
+++ /branches/bleeding_edge/src/globals.h       Mon Aug 19 14:46:35 2013 UTC
@@ -328,6 +328,50 @@
 F FUNCTION_CAST(Address addr) {
   return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
 }
+
+
+// Compiler feature detection.
+#if defined(__clang__)
+
+// Compatibility with older clang versions.
+# ifndef __has_extension
+# define __has_extension __has_feature
+# endif
+
+# if __has_extension(cxx_override_control)
+#  define V8_HAVE_CXX11_FINAL
+#  define V8_HAVE_CXX11_OVERRIDE
+# endif
+
+#elif defined(__GNUC__)
+
+// g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality
+// without warnings (functionality used by the macros below).  These modes
+// are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or,
+// more standardly, by checking whether __cplusplus has a C++11 or greater
+// value. Current versions of g++ do not correctly set __cplusplus, so we check
+// both for forward compatibility.
+# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
+#  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
+#   define V8_HAVE_CXX11_OVERRIDE
+#   define V8_HAVE_CXX11_FINAL
+#  endif
+# else
+// '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655.
+#  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
+#   define V8_HAVE_GXX_FINAL
+#  endif
+# endif
+
+#elif defined(_MSC_VER)
+
+# if _MSC_VER >= 1400
+#  define V8_HAVE_CXX11_OVERRIDE
+// MSVC currently spells "final" as "sealed".
+#  define V8_HAVE_MSVC_SEALED
+# endif
+
+#endif


 #if __cplusplus >= 201103L
@@ -375,6 +419,33 @@
 #endif


+// Annotate a virtual method indicating it must be overriding a virtual
+// method in the parent class.
+// Use like:
+//   virtual void bar() OVERRIDE;
+#if defined(V8_HAVE_CXX11_OVERRIDE)
+#define OVERRIDE override
+#else
+#define OVERRIDE
+#endif
+
+
+// Annotate a virtual method indicating that subclasses must not override it,
+// or annotate a class to indicate that it cannot be subclassed.
+// Use like:
+//   class B FINAL : public A {};
+//   virtual void bar() FINAL;
+#if defined(V8_HAVE_CXX11_FINAL)
+#define FINAL final
+#elif defined(V8_HAVE_GXX_FINAL)
+#define FINAL __final
+#elif defined(V8_HAVE_MSVC_SEALED)
+#define FINAL sealed
+#else
+#define FINAL
+#endif
+
+
 #if defined(__GNUC__) && __GNUC__ >= 4
 #define MUST_USE_RESULT __attribute__ ((warn_unused_result))
 #else
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Tue Aug 6 13:34:51 2013 UTC +++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Mon Aug 19 14:46:35 2013 UTC
@@ -1945,12 +1945,12 @@
   VisitForStackValue(expr->expression());

   switch (expr->yield_kind()) {
-    case Yield::SUSPEND:
+    case Yield::kSuspend:
       // Pop value from top-of-stack slot; box result into result register.
       EmitCreateIteratorResult(false);
       __ push(result_register());
       // Fall through.
-    case Yield::INITIAL: {
+    case Yield::kInitial: {
       Label suspend, continuation, post_runtime, resume;

       __ jmp(&suspend);
@@ -1983,7 +1983,7 @@
       break;
     }

-    case Yield::FINAL: {
+    case Yield::kFinal: {
       VisitForAccumulatorValue(expr->generator_object());
       __ mov(FieldOperand(result_register(),
                           JSGeneratorObject::kContinuationOffset),
@@ -1995,7 +1995,7 @@
       break;
     }

-    case Yield::DELEGATING: {
+    case Yield::kDelegating: {
       VisitForStackValue(expr->generator_object());

       // Initial stack layout is as follows:
=======================================
--- /branches/bleeding_edge/src/mips/full-codegen-mips.cc Tue Aug 6 13:34:51 2013 UTC +++ /branches/bleeding_edge/src/mips/full-codegen-mips.cc Mon Aug 19 14:46:35 2013 UTC
@@ -1993,12 +1993,12 @@
   VisitForStackValue(expr->expression());

   switch (expr->yield_kind()) {
-    case Yield::SUSPEND:
+    case Yield::kSuspend:
       // Pop value from top-of-stack slot; box result into result register.
       EmitCreateIteratorResult(false);
       __ push(result_register());
       // Fall through.
-    case Yield::INITIAL: {
+    case Yield::kInitial: {
       Label suspend, continuation, post_runtime, resume;

       __ jmp(&suspend);
@@ -2029,7 +2029,7 @@
       break;
     }

-    case Yield::FINAL: {
+    case Yield::kFinal: {
       VisitForAccumulatorValue(expr->generator_object());
__ li(a1, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)));
       __ sw(a1, FieldMemOperand(result_register(),
@@ -2041,7 +2041,7 @@
       break;
     }

-    case Yield::DELEGATING: {
+    case Yield::kDelegating: {
       VisitForStackValue(expr->generator_object());

       // Initial stack layout is as follows:
=======================================
--- /branches/bleeding_edge/src/parser.cc       Tue Aug  6 13:34:51 2013 UTC
+++ /branches/bleeding_edge/src/parser.cc       Mon Aug 19 14:46:35 2013 UTC
@@ -2319,7 +2319,7 @@
     Expression* generator = factory()->NewVariableProxy(
         current_function_state_->generator_object_variable());
     Expression* yield = factory()->NewYield(
-        generator, return_value, Yield::FINAL, RelocInfo::kNoPosition);
+        generator, return_value, Yield::kFinal, RelocInfo::kNoPosition);
     result = factory()->NewExpressionStatement(yield);
   } else {
     result = factory()->NewReturnStatement(return_value);
@@ -2997,13 +2997,13 @@
   int position = scanner().peek_location().beg_pos;
   Expect(Token::YIELD, CHECK_OK);
   Yield::Kind kind =
-      Check(Token::MUL) ? Yield::DELEGATING : Yield::SUSPEND;
+      Check(Token::MUL) ? Yield::kDelegating : Yield::kSuspend;
   Expression* generator_object = factory()->NewVariableProxy(
       current_function_state_->generator_object_variable());
   Expression* expression = ParseAssignmentExpression(false, CHECK_OK);
   Yield* yield =
       factory()->NewYield(generator_object, expression, kind, position);
-  if (kind == Yield::DELEGATING) {
+  if (kind == Yield::kDelegating) {
     yield->set_index(current_function_state_->NextHandlerIndex());
   }
   return yield;
@@ -4484,7 +4484,7 @@
         VariableProxy* get_proxy = factory()->NewVariableProxy(
             current_function_state_->generator_object_variable());
         Yield* yield = factory()->NewYield(
-            get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition);
+ get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition);
         body->Add(factory()->NewExpressionStatement(yield), zone());
       }

@@ -4496,7 +4496,7 @@
         Expression *undefined = factory()->NewLiteral(
             isolate()->factory()->undefined_value());
         Yield* yield = factory()->NewYield(
-            get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition);
+            get_proxy, undefined, Yield::kFinal, RelocInfo::kNoPosition);
         body->Add(factory()->NewExpressionStatement(yield), zone());
       }

=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Tue Aug 6 13:34:51 2013 UTC +++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Mon Aug 19 14:46:35 2013 UTC
@@ -1967,12 +1967,12 @@
   VisitForStackValue(expr->expression());

   switch (expr->yield_kind()) {
-    case Yield::SUSPEND:
+    case Yield::kSuspend:
       // Pop value from top-of-stack slot; box result into result register.
       EmitCreateIteratorResult(false);
       __ push(result_register());
       // Fall through.
-    case Yield::INITIAL: {
+    case Yield::kInitial: {
       Label suspend, continuation, post_runtime, resume;

       __ jmp(&suspend);
@@ -2006,7 +2006,7 @@
       break;
     }

-    case Yield::FINAL: {
+    case Yield::kFinal: {
       VisitForAccumulatorValue(expr->generator_object());
       __ Move(FieldOperand(result_register(),
                            JSGeneratorObject::kContinuationOffset),
@@ -2018,7 +2018,7 @@
       break;
     }

-    case Yield::DELEGATING: {
+    case Yield::kDelegating: {
       VisitForStackValue(expr->generator_object());

       // Initial stack layout is as follows:

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to