Skip to content

Commit

Permalink
Remove typ field from VarRef
Browse files Browse the repository at this point in the history
  • Loading branch information
ysthakur committed Dec 1, 2024
1 parent 886c7c6 commit c27b212
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 42 deletions.
4 changes: 3 additions & 1 deletion src/main/scala/fred/AST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ case class StringLiteral(value: String, span: Span) extends Expr {

sealed trait LHSExpr extends Expr

case class VarRef(name: String, typ: Option[Type], span: Span) extends LHSExpr
case class VarRef(name: String, span: Span) extends LHSExpr {
override def typ: Option[Type] = None
}

case class FieldAccess(obj: Expr, field: Spanned[String], typ: Option[Type])
extends LHSExpr {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/fred/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object Parser {
.? ~ P.index)
.map {
case (start -> name -> None -> end) =>
VarRef(name, None, Span(start, start + name.length))
VarRef(name, Span(start, start + name.length))
case (start -> name -> Some(Right(args)) -> end) =>
FnCall(
Spanned(name, Span(start, start + name.length)),
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/fred/Translator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ object Translator {
case IntLiteral(value, _) => ("", value.toString, "")
case StringLiteral(value, _) =>
("", s"\"${value.replace("\"", "\\\"")}\"", "")
case VarRef(name, _, _) =>
case VarRef(name, _) =>
("", mangledVars.getOrElse(bindings.vars(name), name), "")
case SetFieldExpr(obj, field, value, span) =>
val (valSetup, valTranslated, valTeardown) = exprToC(value)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/fred/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ object Typer {
case StringLiteral(_, _) =>
types.put(expr, BuiltinType.Str)
BuiltinType.Str
case varRef @ VarRef(_, _, _) =>
case varRef @ VarRef(_, _) =>
val typ = bindings.getVar(varRef).typ
types.put(expr, typ)
typ
case SetFieldExpr(obj, field, value, span) =>
val objType =
bindings.getVar(VarRef(obj.value, None, obj.span)).typ match {
bindings.getVar(VarRef(obj.value, obj.span)).typ match {
case td: TypeDef => td
case builtinType =>
throw new CompileError(
Expand Down
6 changes: 3 additions & 3 deletions src/test/resources/snapshot/parser/basic-expr-q8p3hfe.scala

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/test/resources/snapshot/parser/if-expr-asp8eyof7.scala

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/test/resources/snapshot/parser/match-expr-qpw8jf.scala

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/test/resources/snapshot/parser/set-d8ulsb.scala

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions src/test/resources/snapshot/typer/aslid7fy.scala

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/test/resources/snapshot/typer/scope-li8ae4.scala

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/test/scala/fred/FuzzTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FuzzTests
case Some(vars) =>
Gen
.oneOf(vars.keySet)
.map(field.name -> VarRef(_, None, Span.synth))
.map(field.name -> VarRef(_, Span.synth))
case None =>
Gen.const(
field.name -> CtorCall(
Expand Down Expand Up @@ -90,7 +90,7 @@ class FuzzTests
List(
(
Spanned(GenerateTypes.SomeField, Span.synth),
VarRef(ref, None, Span.synth)
VarRef(ref, Span.synth)
)
),
Span.synth
Expand Down

0 comments on commit c27b212

Please sign in to comment.