Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala3 migration2 #122

Merged
merged 17 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions compiler/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

name := "fpp-compiler"
ThisBuild / organization := "gov.nasa.jpl"
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "3.1.2"

lazy val settings = Seq(
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-Xfatal-warnings"
),
libraryDependencies ++= dependencies,
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oNCXELOPQRM"),
)

lazy val dependencies = Seq(
"com.github.scopt" %% "scopt" % "4.0.1",
"org.scala-lang.modules" %% "scala-parser-combinators" % "2.0.0",
"org.scala-lang.modules" %% "scala-xml" % "2.0.1",
"org.scalatest" % "scalatest_2.13" % "3.1.0" % "test",
"org.scala-lang.modules" %% "scala-parser-combinators" % "2.1.1",
"org.scala-lang.modules" %% "scala-xml" % "2.1.0",
"org.scalatest" %% "scalatest" % "3.2.12" % "test",
)

lazy val root = (project in file("."))
Expand Down
5 changes: 4 additions & 1 deletion compiler/install
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# FPP_SBT_FLAGS
# ----------------------------------------------------------------------

scala_version="3.1.2"

if test $# -gt 1
then
echo 'usage: install dest-dir' 1>&2
Expand Down Expand Up @@ -61,7 +63,8 @@ mkdir -p $dest
echo "Installing tools at $dest"
for tool in $tools
do
jar=`find tools/$tool -name "*$name*assembly*.jar"`
jar=`find tools/$tool -name "*$name*assembly*.jar" | grep "target/scala-$scala_version"`
echo " $jar"
cp $jar $dest/$tool.jar
echo '#!/bin/sh

Expand Down
8 changes: 4 additions & 4 deletions compiler/lib/src/main/scala/analysis/Analysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@ object Analysis {
def checkForDuplicateStructMember[T]
(getName: T => Name.Unqualified)
(nodes: List[AstNode[T]]): Result.Result[Unit] =
checkForDuplicateNode (getName) (SemanticError.DuplicateStructMember) (nodes)
checkForDuplicateNode (getName) (SemanticError.DuplicateStructMember.apply) (nodes)

/** Check for duplicate parameter */
def checkForDuplicateParameter(nodes: Ast.FormalParamList): Result.Result[Unit] = {
def getName(param: Ast.FormalParam) = param.name
checkForDuplicateNode (getName) (SemanticError.DuplicateParameter) (nodes.map(_._2))
checkForDuplicateNode (getName) (SemanticError.DuplicateParameter.apply) (nodes.map(_._2))
}

/** Check that int value is nonnegative */
Expand Down Expand Up @@ -413,7 +413,7 @@ object Analysis {
}

/** Gets the number of ref params in a formal param list */
def getNumRefParams(params: Ast.FormalParamList) =
def getNumRefParams(params: Ast.FormalParamList): Int =
params.filter(aNode => {
val param = aNode._2.data
param.kind == Ast.FormalParam.Ref
Expand All @@ -424,7 +424,7 @@ object Analysis {
queueFullOpt.getOrElse(Ast.QueueFull.Assert)

/** Displays an ID value */
def displayIdValue(value: Int) = {
def displayIdValue(value: Int): String = {
val dec = value.toString
val hex = Integer.toString(value, 16).toUpperCase
s"($dec dec, $hex hex)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait TypeExpressionAnalyzer
with TopologyAnalyzer
{

def defEnumConstantAnnotatedNode(a: Analysis, node: Ast.Annotated[AstNode[Ast.DefEnumConstant]]) = {
def defEnumConstantAnnotatedNode(a: Analysis, node: Ast.Annotated[AstNode[Ast.DefEnumConstant]]): Result = {
val (_, node1, _) = node
val data = node1.data
opt(exprNode)(a, data.value)
Expand Down Expand Up @@ -42,9 +42,9 @@ trait TypeExpressionAnalyzer
} yield a
}

def typeNameNode(a: Analysis, node: AstNode[Ast.TypeName]) = matchTypeNameNode(a, node)
def typeNameNode(a: Analysis, node: AstNode[Ast.TypeName]): Result = matchTypeNameNode(a, node)

override def typeNameStringNode(a: Analysis, node: AstNode[Ast.TypeName], tn: Ast.TypeNameString): Out =
override def typeNameStringNode(a: Analysis, node: AstNode[Ast.TypeName], tn: Ast.TypeNameString) =
opt(exprNode)(a, tn.size)

override def defArrayAnnotatedNode(a: Analysis, node: Ast.Annotated[AstNode[Ast.DefArray]]) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fpp.compiler.util._
* and default values */
object CheckExprTypes extends UseAnalyzer {

override def constantUse(a: Analysis, node: AstNode[Ast.Expr], use: Name.Qualified) =
override def constantUse(a: Analysis, node: AstNode[Ast.Expr], use: Name.Qualified) =
visitUse(a, node)

override def defArrayAnnotatedNode(a: Analysis, aNode: Ast.Annotated[AstNode[Ast.DefArray]]) = {
Expand Down Expand Up @@ -255,7 +255,7 @@ object CheckExprTypes extends UseAnalyzer {
override def structTypeMemberAnnotatedNode(
a: Analysis,
aNode: Ast.Annotated[AstNode[Ast.StructTypeMember]]
): Result = {
) = {
val (_, node, _) = aNode
val data = node.data
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fpp.compiler.util._
/** Check for use-def cycles */
object CheckUseDefCycles extends UseAnalyzer {

override def constantUse(a: Analysis, node: AstNode[Ast.Expr], use: Name.Qualified): Result =
override def constantUse(a: Analysis, node: AstNode[Ast.Expr], use: Name.Qualified) =
visitUse(a, node, use)

override def defArrayAnnotatedNode(a: Analysis, node: Ast.Annotated[AstNode[Ast.DefArray]]) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object FinalizeTypeDefs
extends TypeExpressionAnalyzer
{

override def exprNode(a: Analysis, node: AstNode[Ast.Expr]): Result = default(a)
override def exprNode(a: Analysis, node: AstNode[Ast.Expr]) = default(a)

override def typeNameNode(a: Analysis, node: AstNode[Ast.TypeName]) = {
val t1 = a.typeMap(node.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object ComputeFrameworkDependencies extends AstStateVisitor {
}
}

override def transUnit(s: State, tu: Ast.TransUnit) =
override def transUnit(s: State, tu: Ast.TransUnit) =
visitList(s, tu.members, matchTuMember)

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object FrameworkDependency {
FwComp
).zipWithIndex.toMap

def sort(s: Seq[FrameworkDependency]) =
def sort(s: Seq[FrameworkDependency]): Seq[FrameworkDependency] =
s.sortWith((a, b) => orderMap(a) < orderMap(b))

}
14 changes: 7 additions & 7 deletions compiler/lib/src/main/scala/analysis/Semantics/Command.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sealed trait Command {

}

final object Command {
object Command {

type Opcode = Int

Expand All @@ -23,11 +23,11 @@ final object Command {
aNode: Ast.Annotated[AstNode[Ast.SpecCommand]],
kind: NonParam.Kind
) extends Command {
def getLoc = Locations.get(aNode._2.id)
def getName = aNode._2.data.name
override def getLoc = Locations.get(aNode._2.id)
override def getName = aNode._2.data.name
}

final object NonParam {
object NonParam {

sealed trait Kind
case class Async(
Expand All @@ -44,8 +44,8 @@ final object Command {
aNode: Ast.Annotated[AstNode[Ast.SpecParam]],
kind: Param.Kind,
) extends Command {
def getLoc = Locations.get(aNode._2.id)
def getName = {
override def getLoc = Locations.get(aNode._2.id)
override def getName = {
val paramName = aNode._2.data.name.toUpperCase
kind match {
case Param.Get => s"${paramName}_PARAM_GET"
Expand All @@ -54,7 +54,7 @@ final object Command {
}
}

final object Param {
object Param {

sealed trait Kind
case object Get extends Kind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ case class Component(
}

/** Complete a component definition */
def complete = for {
def complete: Either[Error,Component] = for {
c <- this.constructPortMatchingList
_ <- c.checkValidity
} yield c
Expand Down Expand Up @@ -422,7 +422,7 @@ object Component {
override def toString = s"match $instance1 with $instance2"

/** Gets the location of a port matching */
def getLoc = Locations.get(aNode._2.id)
def getLoc: Location = Locations.get(aNode._2.id)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ case class Connection(
}

/** Compare two connections */
def compare(that: Connection) = {
override def compare(that: Connection) = {
val fromCompare = this.from.compare(that.from)
if (fromCompare != 0) fromCompare
else this.to.compare(that.to)
Expand All @@ -60,7 +60,7 @@ case class Connection(
def getLoc: Location = from.loc

/** Get this endpoint of a port connection at a port instance */
def getThisEndpoint(pi: PortInstance) = {
def getThisEndpoint(pi: PortInstance): Connection.Endpoint = {
import PortInstance.Direction._
pi.getDirection.get match {
case Input => to
Expand All @@ -69,7 +69,7 @@ case class Connection(
}

/** Get the other endpoint of a port connection at a port instance */
def getOtherEndpoint(pi: PortInstance) = {
def getOtherEndpoint(pi: PortInstance): Connection.Endpoint = {
import PortInstance.Direction._
pi.getDirection.get match {
case Input => from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ case class ConnectionPattern(
targets: Set[(ComponentInstance, Location)]
) {

def getLoc = Locations.get(aNode._2.id)
def getLoc: Location = Locations.get(aNode._2.id)

}

Expand Down
4 changes: 2 additions & 2 deletions compiler/lib/src/main/scala/analysis/Semantics/Event.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ final case class Event(
def getName = aNode._2.data.name

/** Gets the location of the event */
def getLoc = Locations.get(aNode._2.id)
def getLoc: Location = Locations.get(aNode._2.id)

}

final object Event {
object Event {

type Id = Int

Expand Down
5 changes: 3 additions & 2 deletions compiler/lib/src/main/scala/analysis/Semantics/Format.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Format {
sealed trait Field extends Positional {
def isInteger = false
def isRational = false
final def isNumeric = isInteger || isRational
final def isNumeric: Boolean = isInteger || isRational
}

object Field {
Expand Down Expand Up @@ -89,7 +89,8 @@ object Format {
case prefix ~ fields => Format(prefix, fields.map({ case field ~ string => (field, string) }))
}

def parseAllInput[T](p: Parser[T]) = new Parser[T] {
def parseAllInput[T](p: Parser[T]): parseAllInput[T] = new parseAllInput[T](p)
class parseAllInput[T](p: Parser[T]) extends Parser[T] {
def dropWhile(in: Input, p: Char => Boolean): Input = {
if (in.atEnd) in
else if (p(in.first)) dropWhile(in.rest, p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final case class InitSpecifier(
) {

/** Gets the location for this init specifier */
def getLoc = Locations.get(aNode._2.id)
def getLoc: Location = Locations.get(aNode._2.id)

}

Expand Down
10 changes: 5 additions & 5 deletions compiler/lib/src/main/scala/analysis/Semantics/Name.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object Name {
}

/** Convert a qualified name to an identifier list */
def toIdentList = (base :: qualifier).reverse
def toIdentList: List[Unqualified] = (base :: qualifier).reverse

/** Computes a short qualified name
* Deletes the longest prefix provided by the enclosing scope */
Expand All @@ -46,21 +46,21 @@ object Name {
object Qualified {

/** Create a qualified name from a string */
def fromString(s: String) = fromIdentList(s.split(".").toList)
def fromString(s: String): Qualified = fromIdentList(s.split(".").toList)

/** Create a qualified name A.B.C from an identifer list [ A, B, C ] */
def fromIdentList(il: List[Ast.Ident]) = {
def fromIdentList(il: List[Ast.Ident]): Qualified = {
il.reverse match {
case head :: tail => Qualified(tail.reverse, head)
case _ => throw new InternalError("empty identifier list")
}
}

/** Create a qualified name from an identifier */
def fromIdent(id: Ast.Ident) = Qualified(Nil, id)
def fromIdent(id: Ast.Ident): Qualified = Qualified(Nil, id)

/** Create a qualified name from a qualified identifier */
def fromQualIdent(qualIdent: Ast.QualIdent) =
def fromQualIdent(qualIdent: Ast.QualIdent): Qualified =
fromIdentList(qualIdent.toIdentList)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object NameGroup {
case object Type extends NameGroup
case object Value extends NameGroup

val groups = List(
val groups: List[NameGroup] = List(
ComponentInstance,
Component,
Port,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ private case class NameSymbolMapImpl(map: Map[Name.Unqualified,Symbol] = Map())
extends NameSymbolMap
{

def apply(name: Name.Unqualified) = map(name)
override def apply(name: Name.Unqualified) = map(name)

def put(name: Name.Unqualified, symbol: Symbol) = {
override def put(name: Name.Unqualified, symbol: Symbol) = {
map.get(name) match {
case Some(prevSymbol) => {
val loc = symbol.getLoc
Expand All @@ -41,6 +41,6 @@ private case class NameSymbolMapImpl(map: Map[Name.Unqualified,Symbol] = Map())
}
}

def get(name: Name.Unqualified) = map.get(name)
override def get(name: Name.Unqualified) = map.get(name)

}
Loading