Class

org.scalajs.core.compiler.GenJSCode

JSCodePhase

Related Doc: package GenJSCode

Permalink

class JSCodePhase extends StdPhase with JSExportsPhase

Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. JSCodePhase
  2. JSExportsPhase
  3. StdPhase
  4. GlobalPhase
  5. Phase
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new JSCodePhase(prev: Phase)

    Permalink

Type Members

  1. class CancelGenMethodAsJSFunction extends Throwable with ControlThrowable

    Permalink
  2. type Id = Int

    Permalink
    Definition Classes
    Phase

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. object MaybeAsInstanceOf

    Permalink
  5. lazy val ReflectArrayModuleClass: scala.tools.nsc.Global.Symbol

    Permalink
  6. lazy val UtilArraysModuleClass: scala.tools.nsc.Global.Symbol

    Permalink
  7. object WrapArray

    Permalink
  8. def apply(cunit: scala.tools.nsc.Global.CompilationUnit): Unit

    Permalink

    Generates the Scala.js IR for a compilation unit This method iterates over all the class and interface definitions found in the compilation unit and emits their IR (.sjsir).

    Generates the Scala.js IR for a compilation unit This method iterates over all the class and interface definitions found in the compilation unit and emits their IR (.sjsir).

    Some classes are never actually emitted:

    • Classes representing primitive types
    • The scala.Array class
    • Implementation classes for raw JS traits

    Some classes representing anonymous functions are not actually emitted. Instead, a temporary representation of their apply method is built and recorded, so that it can be inlined as a JavaScript anonymous function in the method that instantiates it.

    Other ClassDefs are emitted according to their nature: * Scala.js-defined JS class -> genScalaJSDefinedJSClass() * Other raw JS type (<: js.Any) -> genRawJSClassData() * Interface -> genInterface() * Implementation class -> genImplClass() * Normal class -> genClass()

    Definition Classes
    JSCodePhase → GlobalPhase
  9. final def applyPhase(unit: scala.tools.nsc.Global.CompilationUnit): Unit

    Permalink
    Definition Classes
    GlobalPhase
  10. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  11. def cancelled(unit: scala.tools.nsc.Global.CompilationUnit): Boolean

    Permalink
    Definition Classes
    GlobalPhase
  12. def checkable: Boolean

    Permalink
    Definition Classes
    Phase
  13. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. val countsOfReturnsToMatchEnd: Map[scala.tools.nsc.Global.Symbol, Int]

    Permalink
  15. val currentClassSym: ScopedVar[scala.tools.nsc.Global.Symbol]

    Permalink
  16. val currentMethodSym: ScopedVar[scala.tools.nsc.Global.Symbol]

    Permalink
  17. def description: String

    Permalink
    Definition Classes
    JSCodePhase → Phase
  18. val enclosingLabelDefParams: ScopedVar[Map[scala.tools.nsc.Global.Symbol, List[scala.tools.nsc.Global.Symbol]]]

    Permalink
  19. def ensureBoxed(expr: Tree, tpeEnteringPosterasure: scala.tools.nsc.Global.Type)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Ensures that the value of the given tree is boxed.

    Ensures that the value of the given tree is boxed.

    expr

    Tree to be boxed if needed.

    tpeEnteringPosterasure

    The type of expr as it was entering the posterasure phase.

  20. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  21. def equals(other: Any): Boolean

    Permalink
    Definition Classes
    Phase → AnyRef → Any
  22. def erasedTypes: Boolean

    Permalink
    Definition Classes
    JSCodePhase → GlobalPhase → Phase
  23. def exprToStat(tree: Tree): Tree

    Permalink

    Turn a JavaScript expression of type Unit into a statement

  24. val fakeTailJumpParamRepl: ScopedVar[(scala.tools.nsc.Global.Symbol, scala.tools.nsc.Global.Symbol)]

    Permalink
  25. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  26. def flagMask: Long

    Permalink
    Definition Classes
    Phase
  27. def flatClasses: Boolean

    Permalink
    Definition Classes
    GlobalPhase → Phase
  28. val fmask: Long

    Permalink
    Definition Classes
    Phase
  29. def fromAny(expr: Tree, tpeEnteringPosterasure: scala.tools.nsc.Global.Type)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Extracts a value typed as Any to the given type after posterasure.

    Extracts a value typed as Any to the given type after posterasure.

    expr

    Tree to be extracted.

    tpeEnteringPosterasure

    The type of expr as it was entering the posterasure phase.

  30. def genAndRecordRawJSFunctionClass(cd: scala.tools.nsc.Global.ClassDef): Unit

    Permalink

    Gen and record JS code for a raw JS function class.

    Gen and record JS code for a raw JS function class.

    This is called when emitting a ClassDef that represents an anonymous class extending js.FunctionN. These are generated by the SAM synthesizer when the target type is a js.FunctionN. Since JS functions are not classes, we deconstruct the ClassDef, then reconstruct it to be a genuine Closure.

    Compared to tryGenAndRecordAnonFunctionClass(), this function must always succeed, because we really cannot afford keeping them as anonymous classes. The good news is that it can do so, because the body of SAM lambdas is hoisted in the enclosing class. Hence, the apply() method is just a forwarder to calling that hoisted method.

    From a class looking like this:

    final class <anon>(outer, capture1, ..., captureM) extends js.FunctionN[...] { def apply(param1, ..., paramN) = { outer.lambdaImpl(param1, ..., paramN, capture1, ..., captureM) } } new <anon>(o, c1, ..., cM)

    we generate a function maker that emits:

    lambda<o, c1, ..., cM>[notype]( outer, capture1, ..., captureM, param1, ..., paramN) { outer.lambdaImpl(param1, ..., paramN, capture1, ..., captureM) }

    The function maker is recorded in translatedAnonFunctions to be fetched later by the translation for New.

  31. def genApply(tree: scala.tools.nsc.Global.Apply, isStat: Boolean): Tree

    Permalink

    Gen JS code for an Apply node (method call)

    Gen JS code for an Apply node (method call)

    There's a whole bunch of varieties of Apply nodes: regular method calls, super calls, constructor calls, isInstanceOf/asInstanceOf, primitives, JS calls, etc. They are further dispatched in here.

  32. def genApplyJSClassMethod(receiver: Tree, method: scala.tools.nsc.Global.Symbol, arguments: List[Tree])(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink
  33. def genApplyMethod(receiver: Tree, methodIdent: Ident, arguments: List[Tree], resultType: Type)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen JS code for a call to a Scala method.

    Gen JS code for a call to a Scala method. This also registers that the given method is called by the current method in the method info builder.

  34. def genApplyMethod(receiver: Tree, methodSym: scala.tools.nsc.Global.Symbol, arguments: List[Tree])(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen JS code for a call to a Scala method.

    Gen JS code for a call to a Scala method. This also registers that the given method is called by the current method in the method info builder.

  35. def genApplyMethodStatically(receiver: Tree, method: scala.tools.nsc.Global.Symbol, arguments: List[Tree])(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink
  36. def genApplyStatic(cls: String, methodIdent: Ident, arguments: List[Tree], resultType: Type)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink
  37. def genApplyStatic(method: scala.tools.nsc.Global.Symbol, arguments: List[Tree])(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink
  38. def genArrayValue(tree: scala.tools.nsc.Global.Tree): Tree

    Permalink

    Gen JS code for an array literal.

  39. def genAsInstanceOf(value: Tree, to: scala.tools.nsc.Global.Type)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen JS code for an asInstanceOf cast (for reference types only)

  40. def genClass(cd: scala.tools.nsc.Global.ClassDef): ClassDef

    Permalink

    Gen the IR ClassDef for a class definition (maybe a module class).

  41. def genClassFields(cd: scala.tools.nsc.Global.ClassDef): List[FieldDef]

    Permalink

    Gen definitions for the fields of a class.

    Gen definitions for the fields of a class. The fields are initialized with the zero of their types.

  42. def genConstructorExports(classSym: scala.tools.nsc.Global.Symbol): List[ConstructorExportDef]

    Permalink
    Definition Classes
    JSExportsPhase
  43. def genConversion(from: GenJSCode.TypeKind, to: GenJSCode.TypeKind, value: Tree)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen JS code for a conversion between primitive value types

  44. def genEqEqPrimitive(ltpe: scala.tools.nsc.Global.Type, rtpe: scala.tools.nsc.Global.Type, lsrc: Tree, rsrc: Tree)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen JS code for a call to Any.==

  45. def genExpr(tree: scala.tools.nsc.Global.Tree): Tree

    Permalink

    Gen JS code for a tree in expression position (in the IR).

  46. def genImplClass(cd: scala.tools.nsc.Global.ClassDef): ClassDef

    Permalink

    Gen the IR ClassDef for an implementation class (of a trait).

  47. def genInterface(cd: scala.tools.nsc.Global.ClassDef): ClassDef

    Permalink

    Gen the IR ClassDef for an interface definition.

  48. def genIsInstanceOf(value: Tree, to: scala.tools.nsc.Global.Type)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen JS code for an isInstanceOf test (for reference types only)

  49. def genJSClassConstructor(classSym: scala.tools.nsc.Global.Symbol, constructorTrees: List[scala.tools.nsc.Global.DefDef]): Tree

    Permalink
  50. def genJSClassDispatchers(classSym: scala.tools.nsc.Global.Symbol, dispatchMethodsNames: List[String]): List[Tree]

    Permalink
    Definition Classes
    JSExportsPhase
  51. def genJSClassExports(classSym: scala.tools.nsc.Global.Symbol): List[JSClassExportDef]

    Permalink
    Definition Classes
    JSExportsPhase
  52. def genJSConstructorExport(alts: List[scala.tools.nsc.Global.Symbol]): MethodDef

    Permalink
    Definition Classes
    JSExportsPhase
  53. def genLabelDef(tree: scala.tools.nsc.Global.LabelDef): Tree

    Permalink

    Gen JS code for LabelDef The only LabelDefs that can reach here are the desugaring of while and do..while loops.

    Gen JS code for LabelDef The only LabelDefs that can reach here are the desugaring of while and do..while loops. All other LabelDefs (for tail calls or matches) are caught upstream and transformed in ad hoc ways.

    So here we recognize all the possible forms of trees that can result of while or do..while loops, and we reconstruct the loop for emission to JS.

  54. def genLoadModule(sym0: scala.tools.nsc.Global.Symbol)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Generate loading of a module value Can be given either the module symbol, or its module class symbol.

  55. def genMatch(tree: scala.tools.nsc.Global.Tree, isStat: Boolean): Tree

    Permalink

    Gen JS code for a Match, i.e., a switch-able pattern match Eventually, this is compiled into a JS switch construct.

    Gen JS code for a Match, i.e., a switch-able pattern match Eventually, this is compiled into a JS switch construct. But because we can be in expression position, and a JS switch cannot be given a meaning in expression position, we emit a JS "match" construct (which does not need the breaks in each case. JSDesugaring will transform that in a switch.

    Some caveat here. It may happen that there is a guard in here, despite the fact that switches cannot have guards (in the JVM nor in JS). The JVM backend emits a jump to the default clause when a guard is not fulfilled. We cannot do that. Instead, currently we duplicate the body of the default case in the else branch of the guard test.

  56. def genMemberExportOrDispatcher(classSym: scala.tools.nsc.Global.Symbol, jsName: String, isProp: Boolean, alts: List[scala.tools.nsc.Global.Symbol], isDispatcher: Boolean): Tree

    Permalink
    Definition Classes
    JSExportsPhase
  57. def genMemberExports(classSym: scala.tools.nsc.Global.Symbol, decldExports: List[scala.tools.nsc.Global.Symbol]): List[Tree]

    Permalink

    Generate exporter methods for a class

    Generate exporter methods for a class

    classSym

    symbol of class we export for

    decldExports

    symbols exporter methods that have been encountered in the class' tree. This is not the same as classSym.info.delcs since inherited concrete methods from traits should be in this param, too

    Definition Classes
    JSExportsPhase
  58. def genMethod(dd: scala.tools.nsc.Global.DefDef): Option[MethodDef]

    Permalink
  59. def genMethodDef(static: Boolean, methodName: PropertyName, paramsSyms: List[scala.tools.nsc.Global.Symbol], resultIRType: Type, tree: scala.tools.nsc.Global.Tree, optimizerHints: OptimizerHints): MethodDef

    Permalink

    Generates the MethodDef of a (non-constructor) method

    Generates the MethodDef of a (non-constructor) method

    Most normal methods are emitted straightforwardly. If the result type is Unit, then the body is emitted as a statement. Otherwise, it is emitted as an expression.

    The additional complexity of this method handles the transformation of a peculiarity of recursive tail calls: the local ValDef that replaces this.

  60. def genMethodWithCurrentLocalNameScope(dd: scala.tools.nsc.Global.DefDef): Option[MethodDef]

    Permalink

    Gen JS code for a method definition in a class or in an impl class.

    Gen JS code for a method definition in a class or in an impl class. On the JS side, method names are mangled to encode the full signature of the Scala method, as described in JSEncoding, to support overloading.

    Some methods are not emitted at all: * Primitives, since they are never actually called (with exceptions) * Abstract methods * Constructors of hijacked classes * Methods with the

    @JavaDefaultMethod

    annotation mixed in classes.

    Constructors are emitted by generating their body as a statement.

    Interface methods with the

    @JavaDefaultMethod

    annotation produce default methods forwarding to the trait impl class method.

    Other (normal) methods are emitted with genMethodBody().

    @JavaDefaultMethod }}} default methods forwarding to the trait impl class method.

    Other (normal) methods are emitted with genMethodBody().

    @JavaDefaultMethod }}}

    Constructors are emitted by generating their body as a statement.

    Interface methods with the

    @JavaDefaultMethod

    annotation produce default methods forwarding to the trait impl class method.

    Other (normal) methods are emitted with genMethodBody().

    @JavaDefaultMethod }}} default methods forwarding to the trait impl class method.

    Other (normal) methods are emitted with genMethodBody().

  61. def genModuleAccessorExports(classSym: scala.tools.nsc.Global.Symbol): List[ModuleExportDef]

    Permalink
    Definition Classes
    JSExportsPhase
  62. def genNamedExporterDef(dd: scala.tools.nsc.Global.DefDef): MethodDef

    Permalink

    Generate the exporter proxy for a named export

    Generate the exporter proxy for a named export

    Definition Classes
    JSExportsPhase
  63. def genNew(clazz: scala.tools.nsc.Global.Symbol, ctor: scala.tools.nsc.Global.Symbol, arguments: List[Tree])(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen JS code for a call to a Scala class constructor.

    Gen JS code for a call to a Scala class constructor.

    This also registers that the given class is instantiated by the current method, and that the given constructor is called, in the method info builder.

  64. def genNewArray(arrayType: ArrayType, arguments: List[Tree])(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen JS code for creating a new Array: new Array[T](length) For multidimensional arrays (dimensions > 1), the arguments can specify up to dimensions lengths for the first dimensions of the array.

  65. def genOptimizedLabeled(label: Ident, tpe: Type, translatedCases: List[Tree], returnCount: Int)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen JS code for a Labeled block from a pattern match, while trying to optimize it away as an If chain.

    Gen JS code for a Labeled block from a pattern match, while trying to optimize it away as an If chain.

    It is important to do so at compile-time because, when successful, the resulting IR can be much better optimized by the optimizer.

    The optimizer also does something similar, but *after* it has processed the body of the Labeled block, at which point it has already lost any information about stack-allocated values.

    !!! There is quite of bit of code duplication with OptimizerCore.tryOptimizePatternMatch.

  66. def genRawJSClassData(cd: scala.tools.nsc.Global.ClassDef): ClassDef

    Permalink

    Gen the IR ClassDef for a raw JS class or trait.

  67. def genScalaJSDefinedJSClass(cd: scala.tools.nsc.Global.ClassDef): ClassDef

    Permalink

    Gen the IR ClassDef for a Scala.js-defined JS class.

  68. def genStat(tree: scala.tools.nsc.Global.Tree): Tree

    Permalink

    Gen JS code for a tree in statement position (in the IR).

  69. def genStatOrExpr(tree: scala.tools.nsc.Global.Tree, isStat: Boolean): Tree

    Permalink

    Gen JS code for a tree in statement or expression position (in the IR).

    Gen JS code for a tree in statement or expression position (in the IR).

    This is the main transformation method. Each node of the Scala AST is transformed into an equivalent portion of the JS AST.

  70. def genTraitImplApply(method: scala.tools.nsc.Global.Symbol, arguments: List[Tree])(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink
  71. def genTranslatedMatch(cases: List[scala.tools.nsc.Global.LabelDef], matchEnd: scala.tools.nsc.Global.LabelDef)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen JS code for a translated match

    Gen JS code for a translated match

    This implementation relies heavily on the patterns of trees emitted by the current pattern match phase (as of Scala 2.10).

    The trees output by the pattern matcher are assumed to follow these rules: * Each case LabelDef (in cases) must not take any argument. * The last one must be a catch-all (case _ =>) that never falls through. * Jumps to the matchEnd are allowed anywhere in the body of the corresponding case label-defs, but not outside. * Jumps to case label-defs are restricted to jumping to the very next case, and only in positions denoted by <jump> in: <case-body> ::= If(_, <case-body>, <case-body>) | Block(_, <case-body>) | <jump> | _ These restrictions, together with the fact that we are in statement position (thanks to the above transformation), mean that they can be simply replaced by skip.

    To implement jumps to matchEnd, which have one argument which is the result of the match, we enclose all the cases in one big labeled block. Jumps are then compiled as returns out of the block.

  72. def genTry(tree: scala.tools.nsc.Global.Try, isStat: Boolean): Tree

    Permalink

    Gen JS code for a try..catch or try..finally block

    Gen JS code for a try..catch or try..finally block

    try..finally blocks are compiled straightforwardly to try..finally blocks of JS.

    try..catch blocks are a bit more subtle, as JS does not have type-based selection of exceptions to catch. We thus encode explicitly the type tests, like in:

    try { ... } catch (e) { if (e.isInstanceOf[IOException]) { ... } else if (e.isInstanceOf[Exception]) { ... } else { throw e; // default, re-throw } }

  73. def genZeroOf(tpe: scala.tools.nsc.Global.Type)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Generate a literal "zero" for the requested type

  74. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  75. def hasNext: Boolean

    Permalink
    Definition Classes
    Phase
  76. def hashCode(): Int

    Permalink
    Definition Classes
    Phase → AnyRef → Any
  77. val id: Id

    Permalink
    Definition Classes
    Phase
  78. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  79. var isModuleInitialized: Boolean

    Permalink
  80. def iterator: Iterator[Phase]

    Permalink
    Definition Classes
    Phase
  81. def keepsTypeParams: Boolean

    Permalink
    Definition Classes
    Phase
  82. def makePrimitiveBox(expr: Tree, tpe: scala.tools.nsc.Global.Type)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen a boxing operation (tpe is the primitive type)

  83. def makePrimitiveUnbox(expr: Tree, tpe: scala.tools.nsc.Global.Type)(implicit pos: scala.tools.nsc.Global.Position): Tree

    Permalink

    Gen an unboxing operation (tpe is the primitive type)

  84. val mutableLocalVars: ScopedVar[Set[scala.tools.nsc.Global.Symbol]]

    Permalink
  85. val mutatedLocalVars: ScopedVar[Set[scala.tools.nsc.Global.Symbol]]

    Permalink
  86. def name: String

    Permalink
    Definition Classes
    JSCodePhase → StdPhase → Phase
  87. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  88. def newFlags: Long

    Permalink
    Definition Classes
    StdPhase → Phase
  89. def next: Phase

    Permalink
    Definition Classes
    Phase
  90. def nextFlags: Long

    Permalink
    Definition Classes
    StdPhase → Phase
  91. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  92. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  93. val paramAccessorLocals: ScopedVar[Map[scala.tools.nsc.Global.Symbol, ParamDef]]

    Permalink
  94. val prev: Phase

    Permalink
    Definition Classes
    Phase
  95. def refChecked: Boolean

    Permalink
    Definition Classes
    GlobalPhase → Phase
  96. def run(): Unit

    Permalink
    Definition Classes
    JSCodePhase → GlobalPhase → Phase
  97. def specialized: Boolean

    Permalink
    Definition Classes
    GlobalPhase → Phase
  98. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  99. val thisLocalVarIdent: ScopedVar[Option[Ident]]

    Permalink
  100. def toString(): String

    Permalink
    Definition Classes
    Phase → AnyRef → Any
  101. val tryingToGenMethodAsJSFunction: ScopedVar[Boolean]

    Permalink
  102. val unexpectedMutatedFields: ScopedVar[Set[scala.tools.nsc.Global.Symbol]]

    Permalink
  103. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  104. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  105. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  106. final def withCurrentUnit(unit: scala.tools.nsc.Global.CompilationUnit)(task: ⇒ Unit): Unit

    Permalink
    Definition Classes
    GlobalPhase

Inherited from GenJSCode.JSExportsPhase

Inherited from GenJSCode.StdPhase

Inherited from GlobalPhase

Inherited from Phase

Inherited from AnyRef

Inherited from Any

Ungrouped