Skip to content

Instantly share code, notes, and snippets.

@piotrMocz
Created July 18, 2016 19:24
Show Gist options
  • Save piotrMocz/11614c103743429de76ffd512abe0110 to your computer and use it in GitHub Desktop.
Save piotrMocz/11614c103743429de76ffd512abe0110 to your computer and use it in GitHub Desktop.
New type hierarchy for scalajs_java
package scalajs_java.trees
sealed trait Type
// Type of statements
case object NoType extends Type
// Primitive types
trait PrimitiveType extends Type
case object BoolType extends PrimitiveType
case object CharType extends PrimitiveType
case object IntType extends PrimitiveType
case object LongType extends PrimitiveType
case object DoubleType extends PrimitiveType
case object FloatType extends PrimitiveType
// Reference types
trait ReferenceType {
val className: String
}
case object NullType extends ReferenceType {
override val className: String = "null"
}
case class ClassType(className: String) extends ReferenceType
case object StringType extends ReferenceType {
override val className: String = "java.lang.String"
}
case class ArrayType(elemType: Type, dims: Int) extends ReferenceType {
override val className: String = "array"
}
// Method/function type
case class FunctionType(className: String, argTypes: List[Type],
retType: Type) extends Type
// Generic type
case class GenericType(baseType: Type,
typeParams: List[Type]) extends Type
case class GenericTypeApp(genericType: GenericType,
appArgs: List[Type]) extends Type
// Wrappers for the AST
trait TypedTree {
def tp: Type
}
trait StatementTree extends TypedTree {
override def tp: Type = NoType
}
trait ExpressionTree extends TypedTree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment