JSCodeGen

dotty.tools.backend.sjs.JSCodeGen
See theJSCodeGen companion object
class JSCodeGen()(using genCtx: Context)

Main codegen for Scala.js IR.

GenSJSIR creates one instance of JSCodeGen per compilation unit. The run() method processes the whole compilation unit and generates .sjsir files for it.

There are 4 main levels of translation:

  • genCompilationUnit() iterates through all the type definitions in the compilation unit. Each generated js.ClassDef is serialized to an .sjsir file.
  • genScalaClass() and other similar methods generate the skeleton of classes.
  • genMethod() and similar methods generate the declarations of methods.
  • genStatOrExpr() and everything else generate the bodies of methods.

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Concrete methods

def box(expr: Tree, tpeEnteringElimErasedValueType: Type)(implicit pos: Position): Tree

Boxes a value of the given type before elimErasedValueType.

Boxes a value of the given type before elimErasedValueType.

This should be used when sending values to a JavaScript context, which is erased/boxed at the IR level, although it is not erased at the dotty/JVM level.

Attributes

expr

Tree to be boxed if needed.

tpeEnteringElimErasedValueType

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

def freshLocalIdent(base: String)(implicit pos: Position): LocalIdent

Returns a new fresh local identifier.

Returns a new fresh local identifier.

Attributes

def genApplyJSClassMethod(receiver: Tree, method: Symbol, arguments: List[Tree])(implicit pos: Position): Tree

Gen a call to a non-exposed method of a non-native JS class.

Gen a call to a non-exposed method of a non-native JS class.

Attributes

def genApplyMethod(receiver: Tree, method: Symbol, arguments: List[Tree])(implicit pos: Position): Tree

Gen a dynamically linked call to a Scala method.

Gen a dynamically linked call to a Scala method.

Attributes

def genApplyMethodMaybeStatically(receiver: Tree, method: Symbol, arguments: List[Tree])(implicit pos: Position): Tree

Gen a statically linked call to an instance method.

Gen a statically linked call to an instance method.

Attributes

def genApplyMethodStatically(receiver: Tree, method: Symbol, arguments: List[Tree])(implicit pos: Position): Tree

Gen a statically linked call to an instance method.

Gen a statically linked call to an instance method.

Attributes

def genExpr(name: JSName)(implicit pos: SourcePosition): Tree

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

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

Attributes

def genIsInstanceOf(value: Tree, to: Type)(implicit pos: SourcePosition): Tree

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

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

Attributes

def genJSArrayToVarArgs(arrayRef: Tree)(implicit pos: SourcePosition): Tree

Wraps a js.Array to use as varargs.

Wraps a js.Array to use as varargs.

Attributes

Generates the JSNativeMemberDef.

Generates the JSNativeMemberDef.

Attributes

def genLoadModule(sym: Symbol)(implicit pos: SourcePosition): Tree

Generate loading of a module value.

Generate loading of a module value.

Can be given either the module symbol or its module class symbol.

If the module we load refers to the global scope (i.e., it is annotated with @JSGlobalScope), report a compile error specifying that a global scope object should only be used as the qualifier of a .-selection.

Attributes

Generate loading of a module value or the global scope.

Generate loading of a module value or the global scope.

Can be given either the module symbol of its module class symbol.

Unlike genLoadModule, this method does not fail if the module we load refers to the global scope.

Attributes

def genMatch(tree: Tree, isStat: Boolean): Tree

Gen JS code for a switch-Match, which is translated into an IR js.Match.

Gen JS code for a switch-Match, which is translated into an IR js.Match.

Attributes

Gen the static forwarders to the members of a class or interface for methods of its companion object.

Gen the static forwarders to the members of a class or interface for methods of its companion object.

This is only done if there exists a companion object and it is not a JS type.

Precondition: isCandidateForForwarders(sym) is true

Attributes

def genStaticForwardersFromModuleClass(existingMembers: List[MemberDef], moduleClass: Symbol)(implicit pos: SourcePosition): List[MemberDef]

Gen the static forwarders for the methods of a module class.

Gen the static forwarders for the methods of a module class.

Precondition: isCandidateForForwarders(moduleClass) is true

Attributes

Is the given Scala class, interface or module class a candidate for static forwarders?

Is the given Scala class, interface or module class a candidate for static forwarders?

  • the flag -XnoForwarders is not set to true, and
  • the symbol is static, and
  • either of both of the following is true:
    • the flag -scalajsGenStaticForwardersForNonTopLevelObjects is set to true, or
    • the symbol was originally at the package level

Other than the Scala.js-specific flag, and the fact that we also consider interfaces, this performs the same tests as the JVM back-end.

Attributes

def run(): Unit
def unbox(expr: Tree, tpeEnteringElimErasedValueType: Type)(implicit pos: Position): Tree

Unboxes a value typed as Any to the given type before elimErasedValueType.

Unboxes a value typed as Any to the given type before elimErasedValueType.

This should be used when receiving values from a JavaScript context, which is erased/boxed at the IR level, although it is not erased at the dotty/JVM level.

Attributes

expr

Tree to be extracted.

tpeEnteringElimErasedValueType

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

def withNewLocalNameScope[A](body: => A): A

Implicits

Implicits

Implicitly materializes the current local name generator.

Implicitly materializes the current local name generator.

Attributes