• Tobias Tebbi's avatar
    [torque] add typeswitch statement · 91ef86f9
    Tobias Tebbi authored
    This adds a typeswitch statement
    
    typeswitch (e)
    case (x1 : Type1) {
      ...
    } case (x2 : Type2) {
    
    } ...
    ... case (xn : TypeN) {
      ...
    }
    
    This checks to which of the given types the result of evaluating e can
    be cast, in the order in which they are listed. So if an earlier
    type matches, a value of this type won't reach a later case.
    
    The type-checks are performed by calling the cast<T>() macro.
    The type of the argument passed to the cast macro is dependent on the
    case and excludes all types checked earlier. For example, in
    
    const x : Object = ...
    typeswitch (x)
    case (x : Smi) {
      ...
    } case (x : HeapNumber) {
      ...
    } case (x : HeapObject) {
      ...
    }
    
    there will be calls to cast<Smi>(Object) and
    cast<HeapNumber>(HeapObject), because after the Smi check we know that
    x has to be a HeapObject. With the refactored base.tq definition of
    cast, this will generate efficient code and avoid repeating the Smi
    check in the second case.
    
    The type system ensures that all cases are reachable and that the type
    given to the last case is safe without a runtime check (in other words,
    the union of all checked types covers the type of e).
    
    The cases can also be written as
    case (Type) { ... }
    , in which case the switched value is not re-bound with the checked
    type.
    
    Bug: v8:7793
    Change-Id: Iea4aed7465d62b445e3ae0d33f52921912e095e3
    Reviewed-on: https://chromium-review.googlesource.com/1156506
    Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
    Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#54958}
    91ef86f9
Name
Last commit
Last update
..
ast.h Loading commit data...
contextual.h Loading commit data...
declarable.cc Loading commit data...
declarable.h Loading commit data...
declaration-visitor.cc Loading commit data...
declaration-visitor.h Loading commit data...
declarations.cc Loading commit data...
declarations.h Loading commit data...
earley-parser.cc Loading commit data...
earley-parser.h Loading commit data...
file-visitor.cc Loading commit data...
file-visitor.h Loading commit data...
global-context.h Loading commit data...
implementation-visitor.cc Loading commit data...
implementation-visitor.h Loading commit data...
parameter-difference.h Loading commit data...
scope.cc Loading commit data...
scope.h Loading commit data...
source-positions.cc Loading commit data...
source-positions.h Loading commit data...
torque-parser.cc Loading commit data...
torque-parser.h Loading commit data...
torque.cc Loading commit data...
type-oracle.cc Loading commit data...
type-oracle.h Loading commit data...
types.cc Loading commit data...
types.h Loading commit data...
utils.cc Loading commit data...
utils.h Loading commit data...