Bug 1459845 - Part 2: Make IfThenElseEmitter::State an enum class. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Thu, 31 May 2018 15:15:49 +0900
changeset 420665 15f3eea9a5bb926e9d8ba33ead448ae628130203
parent 420664 51e2c8aea2e19f263fb43cb91f8b810048ee9f37
child 420666 1bf4b8c47cbef84ebac166046f5e61ec71cb7962
push id34077
push usernerli@mozilla.com
push dateThu, 31 May 2018 21:51:59 +0000
treeherdermozilla-central@42880a726964 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1459845
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1459845 - Part 2: Make IfThenElseEmitter::State an enum class. r=Yoric
js/src/frontend/BytecodeEmitter.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -2002,17 +2002,17 @@ class MOZ_STACK_CLASS IfThenElseEmitter
     //        |  |                                         |
     //        |  |                                         |
     //        |  |                                         |
     //        |  | emitIfElse +--------+ emitElse +------+ |
     //        |  +----------->| IfElse |--------->| Else |-+
     //        |               +--------+          +------+ |
     //        |                                            |
     //        +--------------------------------------------+
-    enum State {
+    enum class State {
         // The initial state.
         Start,
 
         // After calling emitIf.
         If,
 
         // After calling emitCond.
         Cond,
@@ -2031,44 +2031,57 @@ class MOZ_STACK_CLASS IfThenElseEmitter
   public:
     explicit IfThenElseEmitter(BytecodeEmitter* bce)
       : bce_(bce),
         thenDepth_(0),
 #ifdef DEBUG
         pushed_(0),
         calculatedPushed_(false),
 #endif
-        state_(Start)
+        state_(State::Start)
     {}
 
     ~IfThenElseEmitter()
     {}
 
   private:
     bool emitIf(State nextState) {
-        MOZ_ASSERT(state_ == Start || state_ == Else);
-        MOZ_ASSERT(nextState == If || nextState == IfElse || nextState == Cond);
+        MOZ_ASSERT(state_ == State::Start || state_ == State::Else);
+        MOZ_ASSERT(nextState == State::If || nextState == State::IfElse ||
+                   nextState == State::Cond);
 
         // Clear jumpAroundThen_ offset that points previous JSOP_IFEQ.
-        if (state_ == Else)
+        if (state_ == State::Else)
             jumpAroundThen_ = JumpList();
 
         // Emit an annotated branch-if-false around the then part.
-        SrcNoteType type = nextState == If ? SRC_IF : nextState == IfElse ? SRC_IF_ELSE : SRC_COND;
+        SrcNoteType type;
+        switch (nextState) {
+          case State::If:
+            type = SRC_IF;
+            break;
+          case State::IfElse:
+            type = SRC_IF_ELSE;
+            break;
+          default:
+            MOZ_ASSERT(nextState == State::Cond);
+            type = SRC_COND;
+            break;
+        }
         if (!bce_->newSrcNote(type))
             return false;
         if (!bce_->emitJump(JSOP_IFEQ, &jumpAroundThen_))
             return false;
 
         // To restore stack depth in else part, save depth of the then part.
 #ifdef DEBUG
         // If DEBUG, this is also necessary to calculate |pushed_|.
         thenDepth_ = bce_->stackDepth;
 #else
-        if (nextState == IfElse || nextState == Cond)
+        if (nextState == State::IfElse || nextState == State::Cond)
             thenDepth_ = bce_->stackDepth;
 #endif
         state_ = nextState;
         return true;
     }
 
     void calculateOrCheckPushed() {
 #ifdef DEBUG
@@ -2078,64 +2091,64 @@ class MOZ_STACK_CLASS IfThenElseEmitter
         } else {
             MOZ_ASSERT(pushed_ == bce_->stackDepth - thenDepth_);
         }
 #endif
     }
 
   public:
     bool emitIf() {
-        return emitIf(If);
+        return emitIf(State::If);
     }
 
     bool emitCond() {
-        return emitIf(Cond);
+        return emitIf(State::Cond);
     }
 
     bool emitIfElse() {
-        return emitIf(IfElse);
+        return emitIf(State::IfElse);
     }
 
     bool emitElse() {
-        MOZ_ASSERT(state_ == IfElse || state_ == Cond);
+        MOZ_ASSERT(state_ == State::IfElse || state_ == State::Cond);
 
         calculateOrCheckPushed();
 
         // Emit a jump from the end of our then part around the else part. The
         // patchJumpsToTarget call at the bottom of this function will fix up
         // the offset with jumpsAroundElse value.
         if (!bce_->emitJump(JSOP_GOTO, &jumpsAroundElse_))
             return false;
 
         // Ensure the branch-if-false comes here, then emit the else.
         if (!bce_->emitJumpTargetAndPatch(jumpAroundThen_))
             return false;
 
         // Restore stack depth of the then part.
         bce_->stackDepth = thenDepth_;
-        state_ = Else;
+        state_ = State::Else;
         return true;
     }
 
     bool emitEnd() {
-        MOZ_ASSERT(state_ == If || state_ == Else);
+        MOZ_ASSERT(state_ == State::If || state_ == State::Else);
 
         calculateOrCheckPushed();
 
-        if (state_ == If) {
+        if (state_ == State::If) {
             // No else part, fixup the branch-if-false to come here.
             if (!bce_->emitJumpTargetAndPatch(jumpAroundThen_))
                 return false;
         }
 
         // Patch all the jumps around else parts.
         if (!bce_->emitJumpTargetAndPatch(jumpsAroundElse_))
             return false;
 
-        state_ = End;
+        state_ = State::End;
         return true;
     }
 
 #ifdef DEBUG
     // Returns the number of values pushed onto the value stack inside
     // `then_block` and `else_block`.
     // Can be used in assertion after emitting if-then-else.
     int32_t pushed() const {